Page MenuHome

VSE: Remove skip_disk_cache argument
ClosedPublic

Authored by Richard Antalik (ISS) on Dec 30 2020, 1:53 AM.

Details

Summary

This argument was used to prevent infinite loop in lookups between disk
and RAM cache.

Code was refactored, so this can be handled internally in cache.

Diff Detail

Repository
rB Blender
Branch
cleanup-skip-disk-cache (branched from master)
Build Status
Buildable 11917
Build 11917: arc lint + arc unit

Event Timeline

Richard Antalik (ISS) requested review of this revision.Dec 30 2020, 1:53 AM
Richard Antalik (ISS) created this revision.
Sybren A. Stüvel (sybren) requested changes to this revision.Jan 11 2021, 11:57 AM

Nice patch, I really like it when such a boolean "pass-me-around-everywhere" parameter can be removed. I've added some comments, and added @Sergey Sharybin (sergey) as reviewer as he's the module owner.

source/blender/sequencer/intern/image_cache.c
830–840

This entire block can be a separate function that determines the correct flags. That way it's clearly marked as its own little block of functionality, gets a clear name and explicit input/output, and you can then declare const int flag = whateverthefunctionisnamed() to indicate that after the flag value has been determined, it won't be modified.

The code itself will also be easier to understand, as you can replace some assignment to the mutable variable flag with a return statement to indicate that that's the final value.

834

Bits should not be set to zero by subtracting, but with a bitwise-AND operator. Use flag &= ~(SEQ_CACHE_STORE_FINAL_OUT); or something along those lines.

835

These comments don't make much sense. What I read is: "this flag is invalid, but enable it anyway in some situations". This is not acceptable.

1131

timeline_frame and type can be declared const

1146

timeline_frame and type can be declared const

This revision now requires changes to proceed.Jan 11 2021, 11:57 AM
Richard Antalik (ISS) marked 5 inline comments as done.
  • Address inlines
source/blender/sequencer/intern/image_cache.c
835

This code is from initial commit, and it is actually nonsensical.

SEQ_CACHE_STORE_FINAL_OUT can not be even set for seq->cache_flag so I have removed flag -= key->seq->cache_flag & SEQ_CACHE_STORE_FINAL_OUT; completely.
Otherwise that would belong to versioning code.

I am not sure why I have used substraction there. Quite possibly a mistake.

Code-wise it looks good. How do I test?

  • Apply clang-format

Code-wise it looks good. How do I test?

The bool was used to prevent endless loop since seq_cache_get would call seq_cache_put with bool to skip disk cache, because otherwise it would call seq_cache_get to check disk cache to prevent reinserting image that would call seq_cache_put again and so on.

So if sequencer doesn't freeze, that means this works.

Here is setup for usual test case and few methods how to check if things are working as they should:

Setup:
Enable disk cache, chose directory, load some slow-to play video in sequencer, save test file file.
You can see cache status visually when you turn on developer extras, and enable in sequencer timeline View > Show Cache > all options.
Under sequencer timeline, in Playback popover menu set Sync to Play Every Frame to make sure playhead doesn't jump around randomly.

Test without any tools or possibility to change code:
With test file play footage for few frames, make sure file caches by visual indication, playback should be slow.
Press Ctrl+R to wipe RAM cache
Rewind playhead to start
Play again, playback should be much faster due to having footage cached on disk.

You can also inspect disk cache folder to see if files are created if something goes wrong.
Refer to format for more info:

/* <cache type>-<resolution X>x<resolution Y>-<rendersize>%(<view_id>)-<frame no>.dcf */
#define DCACHE_FNAME_FORMAT "%d-%dx%d-%d%%(%d)-%d.dcf"

Though there are things that I may need to clarify, for example you may wonder, why the red line (raw images) is not there on replay - This is because if final image is found, there is no need to read any more images
To test raw images you can invalidate "final" images by changing property of strip, for example transform it a bit., change opacity or move on timeline.
And it seems that drawing of raw cache level is a bit broken, I need to look into it why.

Test with debug prints:

diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index f6795b15f7c..e7f747f3128 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -1365,9 +1365,12 @@ struct ImBuf *seq_cache_get(const SeqRenderData *context,
     BLI_mutex_unlock(&cache->disk_cache->read_write_mutex);

     if (ibuf == NULL) {
+      printf("image not found in disk cache\n");
       return NULL;
     }

+    printf("frame from disk cache read successfully\n");
+
     /* Store read image in RAM. Only recycle item for final type. */
     if (key.type != SEQ_CACHE_STORE_FINAL_OUT || seq_cache_recycle_item(scene)) {
       SeqCacheKey *new_key = seq_cache_allocate_key(cache, context, seq, timeline_frame, type);

I should have probably added more info there such as what type is being read vs what is requested, but key for cache items is relatively big - there is lot of data so it depends what you are looking for exactly

If none of above would provide meaningful insight, I would step in debugger and look at variables to see what's going on.

Thanks for the test instructions, it seems to work well. I'll defer to @Sergey Sharybin (sergey) for the final accept as module owner.

This revision is now accepted and ready to land.Jan 12 2021, 3:40 PM
This revision was automatically updated to reflect the committed changes.