diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-07-10 18:43:50 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-07-10 18:43:50 +0400 |
commit | 76ee9783a13ed9e1eb0d4415239ffebdab0a10b7 (patch) | |
tree | 3f58d4624596e5d20d0df12c53fab3f81ad563ad /source/blender/blenkernel | |
parent | a41dc719bf52f462ddabbb8cb1f8fb882f4affc9 (diff) |
Improved cache management for movie clips from tomato branch
Replace pseudo-LRU approach of determining which buffer
to remove when running out of space allowed for cache
with approach which would remove the frame which is most
far away from newly added frame.
This is still a bit tricky because it's impossible to
distinguish which frame to delete in situation of:
CCCC...CC
^
it's either user wants to extend left segment of cached
frames and buffers from right segment should be removed
or he wants to join this two segments and in that case
buffers from right segment should be removed.
Would need a bit more investigation which situation
is more common in general usecase.
Additional changes:
- Cleanup some memutil files (which are familiar to cache limiter)
- Add option to make moviecache verbose. If DEBUG_MESSAGES is
defined in moviecache.c detailed logs would be printed to the
console.
- Movie caches are now named which helps reading debug messages.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 44 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/seqcache.c | 6 |
2 files changed, 44 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 2d83a748767..de367b6b4d0 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -340,6 +340,10 @@ typedef struct MovieClipImBufCacheKey { short render_flag; } MovieClipImBufCacheKey; +typedef struct MovieClipCachePriorityData { + int framenr; +} MovieClipCachePriorityData; + static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) { MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey; @@ -380,6 +384,32 @@ static int moviecache_hashcmp(const void *av, const void *bv) return 0; } +void *moviecache_getprioritydata(void *key_v) +{ + MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *) key_v; + MovieClipCachePriorityData *priority_data; + + priority_data = MEM_callocN(sizeof(priority_data), "movie cache clip priority data"); + priority_data->framenr = key->framenr; + + return priority_data; +} + +int moviecache_getitempriority(void *last_userkey_v, void *priority_data_v) +{ + MovieClipImBufCacheKey *last_userkey = (MovieClipImBufCacheKey *) last_userkey_v; + MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *) priority_data_v; + + return -abs(last_userkey->framenr - priority_data->framenr); +} + +void moviecache_prioritydeleter(void *priority_data_v) +{ + MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *) priority_data_v; + + MEM_freeN(priority_data); +} + static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag) { if (clip->cache) { @@ -407,10 +437,20 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i MovieClipImBufCacheKey key; if (!clip->cache) { + struct MovieCache *moviecache; + + // char cache_name[64]; + // BLI_snprintf(cache_name, sizeof(cache_name), "movie %s", clip->id.name); + clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache"); - clip->cache->moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash, - moviecache_hashcmp, moviecache_keydata); + moviecache = IMB_moviecache_create("movieclip", sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp); + + IMB_moviecache_set_getdata_callback(moviecache, moviecache_keydata); + IMB_moviecache_set_priority_callback(moviecache, moviecache_getprioritydata, moviecache_getitempriority, + moviecache_prioritydeleter); + + clip->cache->moviecache = moviecache; } key.framenr = user->framenr; diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index 582034ae623..0d91dcb7faa 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -98,8 +98,7 @@ void seq_stripelem_cache_cleanup(void) { if (moviecache) { IMB_moviecache_free(moviecache); - moviecache = IMB_moviecache_create(sizeof(SeqCacheKey), seqcache_hashhash, - seqcache_hashcmp, NULL); + moviecache = IMB_moviecache_create("seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp); } } @@ -133,8 +132,7 @@ void seq_stripelem_cache_put( } if (!moviecache) { - moviecache = IMB_moviecache_create(sizeof(SeqCacheKey), seqcache_hashhash, - seqcache_hashcmp, NULL); + moviecache = IMB_moviecache_create("seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp); } key.seq = seq; |