[Bf-blender-cvs] [b6475099133] master: Fix T93844: High memory usage during VSE preview

Richard Antalik noreply at git.blender.org
Tue Dec 14 00:44:25 CET 2021


Commit: b64750991334517a0d0cfc94c21d7276d5e5e833
Author: Richard Antalik
Date:   Tue Dec 14 00:18:24 2021 +0100
Branches: master
https://developer.blender.org/rBb64750991334517a0d0cfc94c21d7276d5e5e833

Fix T93844: High memory usage during VSE preview

Since 88c02bf826df FFmpeg handles are freed if image is not displayed.
This change did not work correctly if strips are inside meta strip,
because overlap did not consider meta strip boundary, only strips inside
of meta strip.

Pass frame range to `sequencer_all_free_anim_ibufs`, if strip is inside
of meta strip, frame range is reduced to fit meta strip boundary, but if
meta strip is being edited, range must be set to +/-`MAXFRAME`,
otherwise playback performance would be too bad.

===================================================================

M	source/blender/sequencer/SEQ_relations.h
M	source/blender/sequencer/intern/strip_relations.c

===================================================================

diff --git a/source/blender/sequencer/SEQ_relations.h b/source/blender/sequencer/SEQ_relations.h
index 3c3fe2fdd83..9571e826759 100644
--- a/source/blender/sequencer/SEQ_relations.h
+++ b/source/blender/sequencer/SEQ_relations.h
@@ -54,6 +54,9 @@ void SEQ_relations_invalidate_cache_in_range(struct Scene *scene,
                                              struct Sequence *seq,
                                              struct Sequence *range_mask,
                                              int invalidate_types);
+/**
+ * Release FFmpeg handles of strips that are not currently displayed to minimize memory usage.
+ */
 void SEQ_relations_free_all_anim_ibufs(struct Scene *scene, int timeline_frame);
 /**
  * A debug and development function which checks whether sequences have unique UUIDs.
diff --git a/source/blender/sequencer/intern/strip_relations.c b/source/blender/sequencer/intern/strip_relations.c
index 7baae5afabd..7e7fc9e6bf7 100644
--- a/source/blender/sequencer/intern/strip_relations.c
+++ b/source/blender/sequencer/intern/strip_relations.c
@@ -29,6 +29,7 @@
 
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_math.h"
 #include "BLI_session_uuid.h"
 
 #include "BKE_main.h"
@@ -281,14 +282,31 @@ void SEQ_relations_free_imbuf(Scene *scene, ListBase *seqbase, bool for_render)
   }
 }
 
-static void sequencer_all_free_anim_ibufs(ListBase *seqbase, int timeline_frame)
+static void sequencer_all_free_anim_ibufs(Editing *ed,
+                                          ListBase *seqbase,
+                                          int timeline_frame,
+                                          const int frame_range[2])
 {
   for (Sequence *seq = seqbase->first; seq != NULL; seq = seq->next) {
-    if (!SEQ_time_strip_intersects_frame(seq, timeline_frame)) {
+    if (!SEQ_time_strip_intersects_frame(seq, timeline_frame) ||
+        !((frame_range[0] <= timeline_frame) && (frame_range[1] > timeline_frame))) {
       SEQ_relations_sequence_free_anim(seq);
     }
     if (seq->type == SEQ_TYPE_META) {
-      sequencer_all_free_anim_ibufs(&seq->seqbase, timeline_frame);
+      int meta_range[2];
+
+      MetaStack *ms = SEQ_meta_stack_active_get(ed);
+      if (ms != NULL && ms->parseq == seq) {
+        meta_range[0] = -MAXFRAME;
+        meta_range[1] = MAXFRAME;
+      }
+      else {
+        /* Limit frame range to meta strip. */
+        meta_range[0] = max_ii(frame_range[0], seq->startdisp);
+        meta_range[1] = min_ii(frame_range[1], seq->enddisp);
+      }
+
+      sequencer_all_free_anim_ibufs(ed, &seq->seqbase, timeline_frame, meta_range);
     }
   }
 }
@@ -299,7 +317,9 @@ void SEQ_relations_free_all_anim_ibufs(Scene *scene, int timeline_frame)
   if (ed == NULL) {
     return;
   }
-  sequencer_all_free_anim_ibufs(&ed->seqbase, timeline_frame);
+
+  const int frame_range[2] = {-MAXFRAME, MAXFRAME};
+  sequencer_all_free_anim_ibufs(ed, &ed->seqbase, timeline_frame, frame_range);
 }
 
 static Sequence *sequencer_check_scene_recursion(Scene *scene, ListBase *seqbase)



More information about the Bf-blender-cvs mailing list