5 #include "commonrender.h"
8 #include "edlsession.h"
11 #include "floatautos.h"
13 #include "overlayframe.h"
15 #include "pluginarray.h"
16 #include "preferences.h"
17 #include "renderengine.h"
18 #include "sharedlocation.h"
19 #include "transition.h"
20 #include "transportque.h"
22 #include "vattachmentpoint.h"
30 #include "interlacemodes.h"
31 #include "maskengine.h"
32 #include "automation.h"
34 VModule::VModule(RenderEngine *renderengine,
35 CommonRender *commonrender,
36 PluginArray *plugin_array,
38 : Module(renderengine, commonrender, plugin_array, track)
40 data_type = TRACK_VIDEO;
45 masker = new MaskEngine(renderengine->preferences->processors);
47 masker = new MaskEngine(plugin_array->mwindow->preferences->processors);
53 if(overlay_temp) delete overlay_temp;
54 if(input_temp) delete input_temp;
55 if(transition_temp) delete transition_temp;
60 AttachmentPoint* VModule::new_attachment(Plugin *plugin)
62 return new VAttachmentPoint(renderengine, plugin);
65 int VModule::get_buffer_size()
70 CICache* VModule::get_cache()
73 return renderengine->get_vcache();
78 int VModule::import_frame(VFrame *output,
80 int64_t input_position,
84 int64_t corrected_position;
85 int64_t corrected_position_project;
86 // Translation of edit
97 double edl_rate = get_edl()->session->frame_rate;
98 int64_t input_position_project = (int64_t)(input_position *
102 if(!output) printf("VModule::import_frame 10 output=%p\n", output);
105 corrected_position = input_position;
106 corrected_position_project = input_position_project;
107 if(direction == PLAY_REVERSE)
109 corrected_position--;
110 input_position_project--;
113 // Load frame into output
119 File *source = get_cache()->check_out(current_edit->asset);
121 // get_cache()->dump();
125 int64_t edit_startproject = (int64_t)(current_edit->startproject *
128 int64_t edit_startsource = (int64_t)(current_edit->startsource *
131 uint64_t position = corrected_position -
134 // if we hit the end of stream, freeze at last frame
135 uint64_t max_position = source->get_video_length(frame_rate) - 1;
136 if (position > max_position) position = max_position;
137 source->set_video_position(position,
139 source->set_layer(current_edit->channel);
142 ((VTrack*)track)->calculate_input_transfer(current_edit->asset,
143 input_position_project,
155 // printf("VModule::import_frame 1 [ilace] Project: mode (%d) Asset: autofixoption (%d), mode (%d), method (%d)\n",
156 // get_edl()->session->interlace_mode,
157 // current_edit->asset->interlace_autofixoption,
158 // current_edit->asset->interlace_mode,
159 // current_edit->asset->interlace_fixmethod);
161 // Determine the interlacing method to use.
162 int interlace_fixmethod = ilaceautofixmethod2(get_edl()->session->interlace_mode,
163 current_edit->asset->interlace_autofixoption,
164 current_edit->asset->interlace_mode,
165 current_edit->asset->interlace_fixmethod);
167 // char string[BCTEXTLEN];
168 // ilacefixmethod_to_text(string,interlace_fixmethod);
169 // printf("VModule::import_frame 1 [ilace] Compensating by using: '%s'\n",string);
171 // Compensate for the said interlacing...
172 switch (interlace_fixmethod) {
173 case BC_ILACE_FIXMETHOD_NONE:
176 case BC_ILACE_FIXMETHOD_UPONE:
179 case BC_ILACE_FIXMETHOD_DOWNONE:
183 printf("vmodule::importframe WARNING - unknown fix method for interlacing, no compensation in effect\n");
188 // file -> temp -> output
189 if( !EQUIV(in_x1, 0) ||
191 !EQUIV(in_w1, track->track_w) ||
192 !EQUIV(in_h1, track->track_h) ||
195 !EQUIV(out_w1, track->track_w) ||
196 !EQUIV(out_h1, track->track_h) ||
197 !EQUIV(in_w1, current_edit->asset->width) ||
198 !EQUIV(in_h1, current_edit->asset->height))
200 //printf("VModule::import_frame 1\n");
201 // Get temporary input buffer
206 VRender *vrender = (VRender*)commonrender;
207 input = &vrender->input_temp;
217 ((*input)->get_w() != current_edit->asset->width ||
218 (*input)->get_h() != current_edit->asset->height))
230 (*input) = new VFrame(0,
231 current_edit->asset->width,
232 current_edit->asset->height,
233 get_edl()->session->color_model,
240 // Cache for single frame only
241 // if(renderengine && renderengine->command->single_frame())
242 source->set_cache_frames(1);
244 result = source->read_frame((*input));
246 // if(renderengine && renderengine->command->single_frame())
247 source->set_cache_frames(0);
249 //printf("VModule::import_frame 1 %lld %f\n", input_position, frame_rate);
250 OverlayFrame *overlayer = 0;
254 VRender *vrender = (VRender*)commonrender;
255 overlayer = vrender->overlayer;
261 printf("VModule::import_frame neither plugin_array nor commonrender is defined.\n");
264 overlay_temp = new OverlayFrame(plugin_array->mwindow->preferences->processors);
267 overlayer = overlay_temp;
269 // printf("VModule::import_frame 1 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
280 // for(int j = 0; j < output->get_w() * 3 * 5; j++)
281 // output->get_rows()[0][j] = 255;
283 output->clear_frame();
286 // get_cache()->check_in(current_edit->asset);
289 int mode = TRANSFER_REPLACE;
291 overlayer->overlay(output,
303 get_edl()->session->interpolation_type);
305 //printf("VModule::import_frame 20\n");
310 //printf("VModule::import_frame 30 %p\n", output);
311 // Cache single frames only
312 // if(renderengine && renderengine->command->single_frame())
313 source->set_cache_frames(1);
314 result = source->read_frame(output);
315 // if(renderengine && renderengine->command->single_frame())
316 source->set_cache_frames(0);
317 //printf("VModule::import_frame 40\n");
321 get_cache()->check_in(current_edit->asset);
325 output->clear_frame();
332 output->clear_frame();
340 int VModule::render(VFrame *output,
341 int64_t start_position,
348 double edl_rate = get_edl()->session->frame_rate;
350 if(use_nudge) start_position += (int64_t)(track->nudge *
355 int64_t start_position_project = (int64_t)(start_position *
361 printf(" VModule::render %d %lld %s\n",
363 start_position_project,
366 update_transition(start_position_project,
370 VEdit* current_edit = (VEdit*)track->edits->editof(start_position_project,
374 VEdit* previous_edit = 0;
378 output->clear_frame();
379 // We do not apply mask here, since alpha is 0, and neither substracting nor multypling changes it
380 // Another mask mode - "addition" should be added to be able to create mask from empty frames
381 // in this case we would call masking here too...
388 // Process transition
392 // Get temporary buffer
393 VFrame **transition_input = 0;
396 VRender *vrender = (VRender*)commonrender;
397 transition_input = &vrender->transition_temp;
401 transition_input = &transition_temp;
404 if((*transition_input) &&
405 ((*transition_input)->get_w() != track->track_w ||
406 (*transition_input)->get_h() != track->track_h))
408 delete (*transition_input);
409 (*transition_input) = 0;
412 // Load incoming frame
413 if(!(*transition_input))
415 (*transition_input) = new VFrame(0,
418 get_edl()->session->color_model,
422 result = import_frame((*transition_input),
429 // Load transition buffer
430 previous_edit = (VEdit*)current_edit->previous;
432 result |= import_frame(output,
438 // Execute plugin with transition_input and output here
439 transition_server->process_transition((*transition_input),
441 (direction == PLAY_FORWARD) ?
442 (start_position_project - current_edit->startproject) :
443 (start_position_project - current_edit->startproject - 1),
448 // Load output buffer
450 result = import_frame(output,
458 int64_t mask_position;
460 mask_position = renderengine->vrender->current_position;
462 mask_position = start_position;
463 masker->do_mask(output,
467 (MaskAutos*)track->automation->autos[AUTOMATION_MASK],
469 1); // we are calling before plugins
480 void VModule::create_objects()
482 Module::create_objects();