summaryrefslogtreecommitdiffstats
path: root/libass/ass_cache.c
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2009-07-19 08:38:49 +0200
committerGrigori Goronzy <greg@blackbox>2009-07-19 15:56:23 +0200
commit3fd039c16184d5864c8a3be561c8b547b52ddf83 (patch)
tree4b7bc7aade51fece064d32276188278d9c6aae68 /libass/ass_cache.c
parent7690af4af50fda163ed724e8d0f3ce5d9a9ec552 (diff)
downloadlibass-3fd039c16184d5864c8a3be561c8b547b52ddf83.tar.bz2
libass-3fd039c16184d5864c8a3be561c8b547b52ddf83.tar.xz
Introduce simple cache memory management
libass' cache was basically unmanaged; it would grow without any limits, depending on how complex the subtitles are. Introduce a simple limiting that resets the cache if certain limits are exceeded. The bitmap cache is limited to approx. 50 MB size by default, while the glyph cache allows storing up to 1000 glyphs by default. A few tests with rather heavily softsubbed fansubs show that these limits are fine. The API was extended with the function ass_set_cache_limits which allows modification of these limits.
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r--libass/ass_cache.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c
index 4c7a3fa..524a1c8 100644
--- a/libass/ass_cache.c
+++ b/libass/ass_cache.c
@@ -223,6 +223,12 @@ static void bitmap_hash_dtor(void *key, size_t key_size, void *value,
void *cache_add_bitmap(hashmap_t *bitmap_cache, bitmap_hash_key_t *key,
bitmap_hash_val_t *val)
{
+ // Note: this is only an approximation
+ if (val->bm_o)
+ bitmap_cache->cache_size += val->bm_o->w * val->bm_o->h * 3;
+ else
+ bitmap_cache->cache_size += val->bm->w * val->bm->h * 3;
+
return hashmap_insert(bitmap_cache, key, val);
}