diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-20 21:03:20 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-20 21:03:20 +0400 |
commit | 808ac6debf45952974c5723bf93a83b1107d6e61 (patch) | |
tree | 36cac1c201f137f373f03b8c626e8263bf26e507 /source/blender/blenkernel/intern/movieclip.c | |
parent | 09a604561d39db04330da1c1833be3b6fa1329b6 (diff) |
Prefetching for movie clips
This commit basically implements frames prefetching for
movie clip datablock.
Number of frames to be prefetched is controlled in User
Preferences, System tab, Prefetch Frames option.
Currently prefetching is destructive-less for movie cache,
meaning mo frames will be removed from the cache when while
prefetching. This is because it's half of simplier to
implement, but it also makes sense from tracking point of
view -- we could want to playback in both directions and
removing frames from behind time cursor is not always a
good idea.
Anyway, smarter prefetching strategy could be developed
later.
Some implementation notes:
- Added MEM_CacheLimiter_get_memory_in_use function to get
memory usage of specified memory limiter.
- Fixed prototype of MEM_CacheLimiter_get_maximum which
was simply wrong (used wrong data type for output).
- Added some utility functions to movie clip and movie
cache for direct cache interaction and obtaining cache
statistics.
- Prefetching is implemented using general jobs system.
which is invoking from clip draw function.
- Prefetcing will stop as soon other job or playback starts.
This is done from performance point of view. Jobs will
likely require lots of CPU power and better to provide
whole CPU to it.
Playback is a bit more complicated case. For jpeg sequence
playback prefetching while paying back is nice. But trying
to prefetch heavy exr images and doing color space
conversion slows down both playback and prefetching.
TODO:
- Think of better policy of dealing with already cached frames
(like when cached frames from other clips prevents frames
from current clip to be prefetched)
- Currently a bit funky redraw notification happens from
prefetch job. Perhaps own ND_ is better to have here.
- Hiding clip while prefetch is active in theory shall stop
prefetching job.
- Having multiple clips opened on file load will prefetch
frames for only one of them.
Diffstat (limited to 'source/blender/blenkernel/intern/movieclip.c')
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 821c8fe3bda..49a64d8e478 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -457,7 +457,29 @@ static ImBuf *get_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag) return NULL; } -static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag) +static int has_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag) +{ + if (clip->cache) { + MovieClipImBufCacheKey key; + + key.framenr = user->framenr; + + if (flag & MCLIP_USE_PROXY) { + key.proxy = rendersize_to_proxy(user, flag); + key.render_flag = user->render_flag; + } + else { + key.proxy = IMB_PROXY_NONE; + key.render_flag = 0; + } + + return IMB_moviecache_has_frame(clip->cache->moviecache, &key); + } + + return FALSE; +} + +static bool put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int flag, bool destructive) { MovieClipImBufCacheKey key; @@ -489,7 +511,13 @@ static void put_imbuf_cache(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, i key.render_flag = 0; } - IMB_moviecache_put(clip->cache->moviecache, &key, ibuf); + if (destructive) { + IMB_moviecache_put(clip->cache->moviecache, &key, ibuf); + return true; + } + else { + return IMB_moviecache_put_if_possible(clip->cache->moviecache, &key, ibuf); + } } /*********************** common functions *************************/ @@ -814,7 +842,7 @@ static ImBuf *movieclip_get_postprocessed_ibuf(MovieClip *clip, MovieClipUser *u } if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0) - put_imbuf_cache(clip, user, ibuf, flag); + put_imbuf_cache(clip, user, ibuf, flag, true); } if (ibuf) { @@ -1111,6 +1139,7 @@ void BKE_movieclip_reload(MovieClip *clip) free_buffers(clip); clip->tracking.stabilization.ok = FALSE; + clip->prefetch_ok = FALSE; /* update clip source */ detect_clip_source(clip); @@ -1420,13 +1449,58 @@ float BKE_movieclip_remap_clip_to_scene_frame(MovieClip *clip, float framenr) return framenr + (float) clip->start_frame - 1.0f; } -void BKE_movieclip_filename_for_frame(MovieClip *clip, int framenr, char *name) +void BKE_movieclip_filename_for_frame(MovieClip *clip, MovieClipUser *user, char *name) { - if (clip->source != MCLIP_SRC_MOVIE) { - get_sequence_fname(clip, framenr, name); + if (clip->source == MCLIP_SRC_SEQUENCE) { + int use_proxy; + + use_proxy = (clip->flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL; + + if (use_proxy) { + int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT; + get_proxy_fname(clip, user->render_size, undistort, user->framenr, name); + } + else { + get_sequence_fname(clip, user->framenr, name); + } } else { BLI_strncpy(name, clip->name, FILE_MAX); BLI_path_abs(name, ID_BLEND_PATH(G.main, &clip->id)); } } + +ImBuf *BKE_movieclip_anim_ibuf_for_frame(MovieClip *clip, MovieClipUser *user) +{ + ImBuf *ibuf = NULL; + + if (clip->source == MCLIP_SRC_MOVIE) { + BLI_lock_thread(LOCK_MOVIECLIP); + ibuf = movieclip_load_movie_file(clip, user, user->framenr, clip->flag); + BLI_unlock_thread(LOCK_MOVIECLIP); + } + + return ibuf; +} + +int BKE_movieclip_has_cached_frame(MovieClip *clip, MovieClipUser *user) +{ + int has_frame = FALSE; + + BLI_lock_thread(LOCK_MOVIECLIP); + has_frame = has_imbuf_cache(clip, user, clip->flag); + BLI_unlock_thread(LOCK_MOVIECLIP); + + return has_frame; +} + +int BKE_movieclip_put_frame_if_possible(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf) +{ + bool result; + + BLI_lock_thread(LOCK_MOVIECLIP); + result = put_imbuf_cache(clip, user, ibuf, clip->flag, false); + BLI_unlock_thread(LOCK_MOVIECLIP); + + return result; +} |