[Bf-blender-cvs] [1d999554dc7] temp-vse-proxies: VSE: Automatic proxy building

Richard Antalik noreply at git.blender.org
Tue Feb 23 15:07:25 CET 2021


Commit: 1d999554dc7e478094796dd7a9f9a369413cc96d
Author: Richard Antalik
Date:   Tue Feb 23 14:54:47 2021 +0100
Branches: temp-vse-proxies
https://developer.blender.org/rB1d999554dc7e478094796dd7a9f9a369413cc96d

VSE: Automatic proxy building

Add `Proxy Setup` enum to user preferences with 3 choices: Manual, For Added strips and Automatic.
With `For Added strips` Only build proxies when adding movie strips.
With `Automatic` setting, proxies are built when preview size changes as well.

TODO:
- Decide what to do when workspace has multiple previews with different preview sizes. See `seq_get_preview_size()`
 - Solution may be to change current design to allow only one size or just build multiple sizes.

Additional possible improvements:
 - Cancel running job if preview size is changed while building proxies
 - Use proxy of different size while building proxies for new size. it would be best to do after some refactoring, so in separate patch.
ref T85469

Maniphest Tasks: T85469

Differential Revision: https://developer.blender.org/D10363

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

M	release/datafiles/userdef/userdef_default.c
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/editors/space_sequencer/sequencer_proxy.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/sequencer/CMakeLists.txt
M	source/blender/sequencer/SEQ_proxy.h
M	source/blender/sequencer/intern/proxy.c
A	source/blender/sequencer/intern/proxy_job.c

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

diff --git a/release/datafiles/userdef/userdef_default.c b/release/datafiles/userdef/userdef_default.c
index 6383d7dfcca..6220edce28f 100644
--- a/release/datafiles/userdef/userdef_default.c
+++ b/release/datafiles/userdef/userdef_default.c
@@ -226,6 +226,7 @@ const UserDef U_default = {
     .sequencer_disk_cache_compression = 0,
     .sequencer_disk_cache_size_limit = 100,
     .sequencer_disk_cache_flag = 0,
+    .sequencer_proxy_setup = USER_SEQ_PROXY_SETUP_AUTOMATIC,
 
     .collection_instance_empty_size = 1.0f,
 
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index a0b5355e64d..78b89c0c2dc 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -655,6 +655,10 @@ class USERPREF_PT_system_video_sequencer(SystemPanel, CenterAlignMixIn, Panel):
         col.prop(system, "sequencer_disk_cache_size_limit", text="Cache Limit")
         col.prop(system, "sequencer_disk_cache_compression", text="Compression")
 
+        layout.separator()
+
+        layout.prop(system, "sequencer_proxy_setup")
+
 
 # -----------------------------------------------------------------------------
 # Viewport Panels
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 3d39181cd32..0716226893b 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -857,6 +857,8 @@ void blo_do_versions_userdef(UserDef *userdef)
     if (userdef->gizmo_size_navigate_v3d == 0) {
       userdef->gizmo_size_navigate_v3d = 80;
     }
+
+    userdef->sequencer_proxy_setup = USER_SEQ_PROXY_SETUP_AUTOMATIC;
   }
 
   LISTBASE_FOREACH (bTheme *, btheme, &userdef->themes) {
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index e605cf4a889..84b77b851fa 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -29,6 +29,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_ghash.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
@@ -36,14 +37,18 @@
 
 #include "DNA_mask_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
 
 #include "BKE_context.h"
+#include "BKE_global.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
 #include "BKE_mask.h"
 #include "BKE_movieclip.h"
 #include "BKE_report.h"
 
+#include "IMB_imbuf.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -52,6 +57,7 @@
 
 #include "SEQ_add.h"
 #include "SEQ_effects.h"
+#include "SEQ_proxy.h"
 #include "SEQ_relations.h"
 #include "SEQ_render.h"
 #include "SEQ_select.h"
@@ -577,6 +583,57 @@ void SEQUENCER_OT_mask_strip_add(struct wmOperatorType *ot)
   ot->prop = prop;
 }
 
+/* Strips are added in context of timeline which has different preview size than actual preview. We
+ * must search for preview area. In most cases there will be only one preview area, but there can
+ * be more with different preview sizes. */
+static IMB_Proxy_Size seq_get_proxy_size_flags(bContext *C)
+{
+  bScreen *screen = CTX_wm_screen(C);
+  IMB_Proxy_Size proxy_sizes = 0;
+  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+    LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+      switch (sl->spacetype) {
+        case SPACE_SEQ: {
+          SpaceSeq *sseq = (SpaceSeq *)sl;
+          if (!ELEM(sseq->view, SEQ_VIEW_PREVIEW, SEQ_VIEW_SEQUENCE_PREVIEW)) {
+            continue;
+          }
+          proxy_sizes |= SEQ_rendersize_to_proxysize(sseq->render_size);
+        }
+      }
+    }
+  }
+  return proxy_sizes;
+}
+
+static void seq_build_proxy(bContext *C, Sequence *seq)
+{
+  if (!ELEM(U.sequencer_proxy_setup,
+            USER_SEQ_PROXY_SETUP_ONLY_STRIP_ADD,
+            USER_SEQ_PROXY_SETUP_AUTOMATIC)) {
+    return;
+  }
+
+  /* Enable and set proxy size. */
+  SEQ_proxy_set(seq, true);
+  seq->strip->proxy->build_size_flags = seq_get_proxy_size_flags(C);
+  seq->strip->proxy->build_flags |= SEQ_PROXY_SKIP_EXISTING;
+
+  /* Build proxy. */
+  GSet *file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
+  wmJob *wm_job = ED_seq_proxy_wm_job_get(C);
+  ProxyJob *pj = ED_seq_proxy_job_get(C, wm_job);
+  SEQ_proxy_rebuild_context(pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue);
+  BLI_gset_free(file_list, MEM_freeN);
+
+  if (!WM_jobs_is_running(wm_job)) {
+    G.is_break = false;
+    WM_jobs_start(CTX_wm_manager(C), wm_job);
+  }
+
+  ED_area_tag_redraw(CTX_wm_area(C));
+}
+
 static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoadFn seq_load_fn)
 {
   Scene *scene = CTX_data_scene(C);
@@ -612,6 +669,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad
           sequencer_add_apply_overlap(C, op, seq_load.seq_sound);
         }
         sequencer_add_apply_overlap(C, op, seq);
+        seq_build_proxy(C, seq);
       }
     }
     RNA_END;
@@ -625,6 +683,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad
         sequencer_add_apply_overlap(C, op, seq_load.seq_sound);
       }
       sequencer_add_apply_overlap(C, op, seq);
+      seq_build_proxy(C, seq);
     }
   }
 
diff --git a/source/blender/editors/space_sequencer/sequencer_proxy.c b/source/blender/editors/space_sequencer/sequencer_proxy.c
index 24fa4ad7a17..e44afde371a 100644
--- a/source/blender/editors/space_sequencer/sequencer_proxy.c
+++ b/source/blender/editors/space_sequencer/sequencer_proxy.c
@@ -49,98 +49,25 @@
 /* Own include. */
 #include "sequencer_intern.h"
 
-/*--------------------------------------------------------------------*/
-/** \name Proxy Job Manager
+/* -------------------------------------------------------------------- */
+/** \name Rebuild Proxy and Timecode Indices Operator
  * \{ */
 
-typedef struct ProxyBuildJob {
-  struct Main *main;
-  struct Depsgraph *depsgraph;
-  Scene *scene;
-  ListBase queue;
-  int stop;
-} ProxyJob;
-
-static void proxy_freejob(void *pjv)
-{
-  ProxyJob *pj = pjv;
-
-  BLI_freelistN(&pj->queue);
-
-  MEM_freeN(pj);
-}
-
-/* Only this runs inside thread. */
-static void proxy_startjob(void *pjv, short *stop, short *do_update, float *progress)
-{
-  ProxyJob *pj = pjv;
-  LinkData *link;
-
-  for (link = pj->queue.first; link; link = link->next) {
-    struct SeqIndexBuildContext *context = link->data;
-
-    SEQ_proxy_rebuild(context, stop, do_update, progress);
-
-    if (*stop) {
-      pj->stop = 1;
-      fprintf(stderr, "Canceling proxy rebuild on users request...\n");
-      break;
-    }
-  }
-}
-
-static void proxy_endjob(void *pjv)
-{
-  ProxyJob *pj = pjv;
-  Editing *ed = SEQ_editing_get(pj->scene, false);
-  LinkData *link;
-
-  for (link = pj->queue.first; link; link = link->next) {
-    SEQ_proxy_rebuild_finish(link->data, pj->stop);
-  }
-
-  SEQ_relations_free_imbuf(pj->scene, &ed->seqbase, false);
-
-  WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, pj->scene);
-}
-
 static void seq_proxy_build_job(const bContext *C, ReportList *reports)
 {
-  wmJob *wm_job;
-  ProxyJob *pj;
-  struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   Scene *scene = CTX_data_scene(C);
   Editing *ed = SEQ_editing_get(scene, false);
   ScrArea *area = CTX_wm_area(C);
   Sequence *seq;
-  GSet *file_list;
 
   if (ed == NULL) {
     return;
   }
 
-  wm_job = WM_jobs_get(CTX_wm_manager(C),
-                       CTX_wm_window(C),
-                       scene,
-                       "Building Proxies",
-                       WM_JOB_PROGRESS,
-                       WM_JOB_TYPE_SEQ_BUILD_PROXY);
-
-  pj = WM_jobs_customdata_get(wm_job);
-
-  if (!pj) {
-    pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
-
-    pj->depsgraph = depsgraph;
-    pj->scene = scene;
-    pj->main = CTX_data_main(C);
+  wmJob *wm_job = ED_seq_proxy_wm_job_get(C);
+  ProxyJob *pj = ED_seq_proxy_job_get(C, wm_job);
 
-    WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
-    WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_SEQUENCER, NC_SCENE | ND_SEQUENCER);
-    WM_jobs_callbacks(wm_job, proxy_startjob, NULL, NULL, proxy_endjob);
-  }
-
-  file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
+  GSet *file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
   bool selected = false; /* Check for no selected strips */
 
   SEQ_CURRENT_BEGIN (ed, seq) {
@@ -182,12 +109,6 @@ static void seq_proxy_build_job(const bContext *C, ReportList *reports)
   ED_area_tag_redraw(area);
 }
 
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Rebuild Proxy and Timecode Indices Operator
- * \{ */
-
 static int sequencer_rebuild_proxy_invoke(bContext *C,
                                           wmOperator *op,
                                           const wmEvent *UNUSED(event))
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index d304641e112..cce2ad02ee0 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -919,7 +919,7 @@ typedef struct UserDef {
   int sequencer_disk_cache_compression; /* eUserpref_DiskCacheCompression */
   int sequencer_disk_cache_size_limit;
   short sequencer_disk_cache_flag;
-  char _pad5[2];
+  short sequencer_proxy_setup; /* eUserpref_SeqProxySetup */
 
   float collection_instance_empty_size;
   char _pad10[3];
@@ -1384,6 +1384,12 @@ typedef enum eUserpref_DiskCacheCompression {
   USER_SEQ_DISK_CACHE_COMPRESSION_HIGH = 2,
 } eUserpref_DiskCacheCompression;
 
+typedef enum eUserpref_SeqProxySetup {
+  USER_SEQ_PROXY_SETUP_MANUAL = 0,
+  USER_SEQ_PROXY_SETUP_ONLY_STRIP_ADD = 1,
+  USER_SEQ_PROXY_SETUP_AUTOMATIC = 2,
+} eUserpref_SeqProxySetup;
+
 /* Locale Ids. Auto will try to get local from OS. Our default is English though. */
 /** #UserDef.language */
 enum {
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 3703c7eef86..9bb78d0edd1 10064

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list