Blender  V2.93
sequencer_proxy.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 #include "BLI_blenlib.h"
27 #include "BLI_ghash.h"
28 
29 #include "DNA_scene_types.h"
30 
31 #include "BKE_context.h"
32 #include "BKE_global.h"
33 #include "BKE_main.h"
34 #include "BKE_report.h"
35 
36 #include "SEQ_iterator.h"
37 #include "SEQ_proxy.h"
38 #include "SEQ_relations.h"
39 #include "SEQ_sequencer.h"
40 
41 #include "WM_api.h"
42 #include "WM_types.h"
43 
44 #include "RNA_define.h"
45 
46 /* For menu, popup, icons, etc. */
47 #include "ED_screen.h"
48 
49 /* Own include. */
50 #include "sequencer_intern.h"
51 
52 /* -------------------------------------------------------------------- */
56 static void seq_proxy_build_job(const bContext *C, ReportList *reports)
57 {
59  Editing *ed = SEQ_editing_get(scene, false);
61 
62  if (ed == NULL) {
63  return;
64  }
65 
66  wmJob *wm_job = ED_seq_proxy_wm_job_get(C);
67  ProxyJob *pj = ED_seq_proxy_job_get(C, wm_job);
68 
70  bool selected = false; /* Check for no selected strips */
71 
73  if (!ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_IMAGE) || (seq->flag & SELECT) == 0) {
74  continue;
75  }
76 
77  selected = true;
78  if (!(seq->flag & SEQ_USE_PROXY)) {
79  BKE_reportf(reports, RPT_WARNING, "Proxy is not enabled for %s, skipping", seq->name);
80  continue;
81  }
82  if (seq->strip->proxy->build_size_flags == 0) {
83  BKE_reportf(reports, RPT_WARNING, "Resolution is not selected for %s, skipping", seq->name);
84  continue;
85  }
86 
87  bool success = SEQ_proxy_rebuild_context(
88  pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue);
89 
90  if (!success && (seq->strip->proxy->build_flags & SEQ_PROXY_SKIP_EXISTING) != 0) {
91  BKE_reportf(reports, RPT_WARNING, "Overwrite is not checked for %s, skipping", seq->name);
92  }
93  }
94 
95  BLI_gset_free(file_list, MEM_freeN);
96 
97  if (!selected) {
98  BKE_reportf(reports, RPT_WARNING, "Select movie or image strips");
99  return;
100  }
101 
102  if (selected && !WM_jobs_is_running(wm_job)) {
103  G.is_break = false;
104  WM_jobs_start(CTX_wm_manager(C), wm_job);
105  }
106 
108 }
109 
111  wmOperator *op,
112  const wmEvent *UNUSED(event))
113 {
115 
116  return OPERATOR_FINISHED;
117 }
118 
120 {
121  Main *bmain = CTX_data_main(C);
124  Editing *ed = SEQ_editing_get(scene, false);
125  GSet *file_list;
126 
127  if (ed == NULL) {
128  return OPERATOR_CANCELLED;
129  }
130 
131  file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
132 
134  if ((seq->flag & SELECT)) {
135  ListBase queue = {NULL, NULL};
136  LinkData *link;
137  short stop = 0, do_update;
138  float progress;
139 
140  SEQ_proxy_rebuild_context(bmain, depsgraph, scene, seq, file_list, &queue);
141 
142  for (link = queue.first; link; link = link->next) {
143  struct SeqIndexBuildContext *context = link->data;
144  SEQ_proxy_rebuild(context, &stop, &do_update, &progress);
146  }
147  SEQ_relations_free_imbuf(scene, &ed->seqbase, false);
148  }
149  }
150 
151  BLI_gset_free(file_list, MEM_freeN);
152 
153  return OPERATOR_FINISHED;
154 }
155 
157 {
158  /* Identifiers. */
159  ot->name = "Rebuild Proxy and Timecode Indices";
160  ot->idname = "SEQUENCER_OT_rebuild_proxy";
161  ot->description = "Rebuild all selected proxies and timecode indices using the job system";
162 
163  /* Api callbacks. */
166 
167  /* Flags. */
169 }
170 
173 /* -------------------------------------------------------------------- */
178  wmOperator *op,
179  const wmEvent *UNUSED(event))
180 {
181  return WM_operator_props_dialog_popup(C, op, 200);
182 }
183 
185 {
187  Editing *ed = SEQ_editing_get(scene, false);
188  bool proxy_25 = RNA_boolean_get(op->ptr, "proxy_25");
189  bool proxy_50 = RNA_boolean_get(op->ptr, "proxy_50");
190  bool proxy_75 = RNA_boolean_get(op->ptr, "proxy_75");
191  bool proxy_100 = RNA_boolean_get(op->ptr, "proxy_100");
192  bool overwrite = RNA_boolean_get(op->ptr, "overwrite");
193  bool turnon = true;
194 
195  if (ed == NULL || !(proxy_25 || proxy_50 || proxy_75 || proxy_100)) {
196  turnon = false;
197  }
198 
200  if ((seq->flag & SELECT)) {
202  SEQ_proxy_set(seq, turnon);
203  if (seq->strip->proxy == NULL) {
204  continue;
205  }
206 
207  if (proxy_25) {
209  }
210  else {
212  }
213 
214  if (proxy_50) {
216  }
217  else {
219  }
220 
221  if (proxy_75) {
223  }
224  else {
226  }
227 
228  if (proxy_100) {
230  }
231  else {
233  }
234 
235  if (!overwrite) {
237  }
238  else {
240  }
241  }
242  }
243  }
244 
246 
247  return OPERATOR_FINISHED;
248 }
249 
251 {
252  /* Identifiers. */
253  ot->name = "Set Selected Strip Proxies";
254  ot->idname = "SEQUENCER_OT_enable_proxies";
255  ot->description = "Enable selected proxies on all selected Movie and Image strips";
256 
257  /* Api callbacks. */
260 
261  /* Flags. */
263 
264  RNA_def_boolean(ot->srna, "proxy_25", false, "25%", "");
265  RNA_def_boolean(ot->srna, "proxy_50", false, "50%", "");
266  RNA_def_boolean(ot->srna, "proxy_75", false, "75%", "");
267  RNA_def_boolean(ot->srna, "proxy_100", false, "100%", "");
268  RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite", "");
269 }
270 
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
struct GSet GSet
Definition: BLI_ghash.h:189
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:1125
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1253
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define SEQ_PROXY_IMAGE_SIZE_75
@ SEQ_USE_PROXY
#define SEQ_PROXY_IMAGE_SIZE_100
@ SEQ_PROXY_SKIP_EXISTING
#define SEQ_PROXY_IMAGE_SIZE_50
@ SEQ_TYPE_IMAGE
@ SEQ_TYPE_MOVIE
#define SEQ_PROXY_IMAGE_SIZE_25
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_area_tag_redraw(ScrArea *area)
Definition: area.c:745
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define ND_SEQUENCER
Definition: WM_types.h:337
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_SCENE
Definition: WM_types.h:279
#define SELECT
Scene scene
const Depsgraph * depsgraph
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static void area(int d1, int d2, int e1, int e2, float weights[2])
ThreadQueue * queue
all scheduled work for the cpu
void SEQ_proxy_set(struct Sequence *seq, bool value)
Definition: proxy.c:584
void SEQ_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_update, float *progress)
Definition: proxy.c:490
void SEQ_proxy_rebuild_finish(SeqIndexBuildContext *context, bool stop)
Definition: proxy.c:563
bool SEQ_proxy_rebuild_context(Main *bmain, Depsgraph *depsgraph, Scene *scene, Sequence *seq, struct GSet *file_list, ListBase *queue)
Definition: proxy.c:410
ProxyJob * ED_seq_proxy_job_get(const bContext *C, wmJob *wm_job)
Definition: proxy_job.c:94
struct wmJob * ED_seq_proxy_wm_job_get(const bContext *C)
Definition: proxy_job.c:111
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
struct SELECTID_Context context
Definition: select_engine.c:47
ListBase * SEQ_active_seqbase_get(const Editing *ed)
Definition: sequencer.c:350
Editing * SEQ_editing_get(Scene *scene, bool alloc)
Definition: sequencer.c:232
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:42
struct LinkData * next
Definition: DNA_listBase.h:41
Definition: BKE_main.h:116
Scene * scene
Definition: clip_ops.c:1182
struct ListBase queue
Definition: SEQ_proxy.h:60
struct Main * main
Definition: clip_ops.c:1183
struct Depsgraph * depsgraph
Definition: SEQ_proxy.h:58
Sequence * seq
Definition: proxy.c:81
short build_size_flags
StripProxy * proxy
Definition: wm_jobs.c:73
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct PointerRNA * ptr
#define G(x, y, z)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition: wm_jobs.c:450
bool WM_jobs_is_running(wmJob *wm_job)
Definition: wm_jobs.c:325
int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width)