Blender  V3.3
sequencer_proxy.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "BLI_blenlib.h"
11 #include "BLI_ghash.h"
12 
13 #include "DNA_scene_types.h"
14 
15 #include "BKE_context.h"
16 #include "BKE_global.h"
17 #include "BKE_main.h"
18 #include "BKE_report.h"
19 
20 #include "SEQ_iterator.h"
21 #include "SEQ_proxy.h"
22 #include "SEQ_relations.h"
23 #include "SEQ_sequencer.h"
24 
25 #include "WM_api.h"
26 #include "WM_types.h"
27 
28 #include "RNA_define.h"
29 
30 /* For menu, popup, icons, etc. */
31 #include "ED_screen.h"
32 
33 /* Own include. */
34 #include "sequencer_intern.h"
35 
36 /* -------------------------------------------------------------------- */
40 static void seq_proxy_build_job(const bContext *C, ReportList *reports)
41 {
45 
46  if (ed == NULL) {
47  return;
48  }
49 
50  wmJob *wm_job = ED_seq_proxy_wm_job_get(C);
51  ProxyJob *pj = ED_seq_proxy_job_get(C, wm_job);
52 
54  bool selected = false; /* Check for no selected strips */
55 
57  if (!ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_IMAGE) || (seq->flag & SELECT) == 0) {
58  continue;
59  }
60 
61  selected = true;
62  if (!(seq->flag & SEQ_USE_PROXY)) {
63  BKE_reportf(reports, RPT_WARNING, "Proxy is not enabled for %s, skipping", seq->name);
64  continue;
65  }
66  if (seq->strip->proxy->build_size_flags == 0) {
67  BKE_reportf(reports, RPT_WARNING, "Resolution is not selected for %s, skipping", seq->name);
68  continue;
69  }
70 
71  bool success = SEQ_proxy_rebuild_context(
72  pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue, false);
73 
74  if (!success && (seq->strip->proxy->build_flags & SEQ_PROXY_SKIP_EXISTING) != 0) {
75  BKE_reportf(reports, RPT_WARNING, "Overwrite is not checked for %s, skipping", seq->name);
76  }
77  }
78 
79  BLI_gset_free(file_list, MEM_freeN);
80 
81  if (!selected) {
82  BKE_reportf(reports, RPT_WARNING, "Select movie or image strips");
83  return;
84  }
85 
86  if (!WM_jobs_is_running(wm_job)) {
87  G.is_break = false;
88  WM_jobs_start(CTX_wm_manager(C), wm_job);
89  }
90 
92 }
93 
95  wmOperator *op,
96  const wmEvent *UNUSED(event))
97 {
99 
100  return OPERATOR_FINISHED;
101 }
102 
104 {
105  Main *bmain = CTX_data_main(C);
109  GSet *file_list;
110 
111  if (ed == NULL) {
112  return OPERATOR_CANCELLED;
113  }
114 
115  file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
116 
118  if (seq->flag & SELECT) {
119  ListBase queue = {NULL, NULL};
120  LinkData *link;
121  short stop = 0, do_update;
122  float progress;
123 
124  SEQ_proxy_rebuild_context(bmain, depsgraph, scene, seq, file_list, &queue, false);
125 
126  for (link = queue.first; link; link = link->next) {
127  struct SeqIndexBuildContext *context = link->data;
128  SEQ_proxy_rebuild(context, &stop, &do_update, &progress);
130  }
131  SEQ_relations_free_imbuf(scene, &ed->seqbase, false);
132  }
133  }
134 
135  BLI_gset_free(file_list, MEM_freeN);
136 
137  return OPERATOR_FINISHED;
138 }
139 
141 {
142  /* Identifiers. */
143  ot->name = "Rebuild Proxy and Timecode Indices";
144  ot->idname = "SEQUENCER_OT_rebuild_proxy";
145  ot->description = "Rebuild all selected proxies and timecode indices using the job system";
146 
147  /* Api callbacks. */
150 
151  /* Flags. */
153 }
154 
157 /* -------------------------------------------------------------------- */
162  wmOperator *op,
163  const wmEvent *UNUSED(event))
164 {
165  return WM_operator_props_dialog_popup(C, op, 200);
166 }
167 
169 {
172  bool proxy_25 = RNA_boolean_get(op->ptr, "proxy_25");
173  bool proxy_50 = RNA_boolean_get(op->ptr, "proxy_50");
174  bool proxy_75 = RNA_boolean_get(op->ptr, "proxy_75");
175  bool proxy_100 = RNA_boolean_get(op->ptr, "proxy_100");
176  bool overwrite = RNA_boolean_get(op->ptr, "overwrite");
177  bool turnon = true;
178 
179  if (ed == NULL || !(proxy_25 || proxy_50 || proxy_75 || proxy_100)) {
180  turnon = false;
181  }
182 
184  if (seq->flag & SELECT) {
186  SEQ_proxy_set(seq, turnon);
187  if (seq->strip->proxy == NULL) {
188  continue;
189  }
190 
191  if (proxy_25) {
193  }
194  else {
196  }
197 
198  if (proxy_50) {
200  }
201  else {
203  }
204 
205  if (proxy_75) {
207  }
208  else {
210  }
211 
212  if (proxy_100) {
214  }
215  else {
217  }
218 
219  if (!overwrite) {
221  }
222  else {
224  }
225  }
226  }
227  }
228 
230 
231  return OPERATOR_FINISHED;
232 }
233 
235 {
236  /* Identifiers. */
237  ot->name = "Set Selected Strip Proxies";
238  ot->idname = "SEQUENCER_OT_enable_proxies";
239  ot->description = "Enable selected proxies on all selected Movie and Image strips";
240 
241  /* Api callbacks. */
244 
245  /* Flags. */
247 
248  RNA_def_boolean(ot->srna, "proxy_25", false, "25%", "");
249  RNA_def_boolean(ot->srna, "proxy_50", false, "50%", "");
250  RNA_def_boolean(ot->srna, "proxy_75", false, "75%", "");
251  RNA_def_boolean(ot->srna, "proxy_100", false, "100%", "");
252  RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite", "");
253 }
254 
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
struct GSet GSet
Definition: BLI_ghash.h:340
bool BLI_ghashutil_strcmp(const void *a, const void *b)
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
GSet * BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:947
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1037
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
@ SEQ_TYPE_IMAGE
@ SEQ_TYPE_MOVIE
#define SEQ_PROXY_IMAGE_SIZE_75
#define SEQ_PROXY_IMAGE_SIZE_100
#define SEQ_PROXY_IMAGE_SIZE_50
@ SEQ_USE_PROXY
@ SEQ_PROXY_SKIP_EXISTING
#define SEQ_PROXY_IMAGE_SIZE_25
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:729
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
#define ND_SEQUENCER
Definition: WM_types.h:385
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_SCENE
Definition: WM_types.h:328
#define SELECT
Scene scene
const Depsgraph * depsgraph
SyclQueue * queue
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
#define G(x, y, z)
static void area(int d1, int d2, int e1, int e2, float weights[2])
void SEQ_proxy_set(struct Sequence *seq, bool value)
Definition: proxy.c:571
void SEQ_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_update, float *progress)
Definition: proxy.c:484
void SEQ_proxy_rebuild_finish(SeqIndexBuildContext *context, bool stop)
Definition: proxy.c:554
bool SEQ_proxy_rebuild_context(Main *bmain, Depsgraph *depsgraph, Scene *scene, Sequence *seq, struct GSet *file_list, ListBase *queue, bool build_only_on_bad_performance)
Definition: proxy.c:401
ProxyJob * ED_seq_proxy_job_get(const bContext *C, wmJob *wm_job)
Definition: proxy_job.c:77
struct wmJob * ED_seq_proxy_wm_job_get(const bContext *C)
Definition: proxy_job.c:94
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:388
Editing * SEQ_editing_get(const Scene *scene)
Definition: sequencer.c:241
void SEQUENCER_OT_enable_proxies(wmOperatorType *ot)
void SEQUENCER_OT_rebuild_proxy(wmOperatorType *ot)
static int sequencer_enable_proxies_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int sequencer_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
static int sequencer_rebuild_proxy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int sequencer_enable_proxies_exec(bContext *C, wmOperator *op)
static void seq_proxy_build_job(const bContext *C, ReportList *reports)
void SEQ_relations_free_imbuf(Scene *scene, ListBase *seqbase, bool for_render)
ListBase seqbase
void * data
Definition: DNA_listBase.h:26
struct LinkData * next
Definition: DNA_listBase.h:25
Definition: BKE_main.h:121
Scene * scene
Definition: clip_ops.c:1171
struct ListBase queue
Definition: SEQ_proxy.h:45
struct Main * main
Definition: clip_ops.c:1172
struct Depsgraph * depsgraph
Definition: SEQ_proxy.h:43
Sequence * seq
Definition: proxy.c:67
short build_size_flags
StripProxy * proxy
Definition: wm_jobs.c:57
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
bool WM_jobs_is_running(const wmJob *wm_job)
Definition: wm_jobs.c:304
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition: wm_jobs.c:437
int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width)