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"
23 #include "vdevicex11.h"
26 #include "videodevice.h"
32 #include "interlacemodes.h"
33 #include "maskengine.h"
34 #include "automation.h"
36 VModule::VModule(RenderEngine *renderengine,
37 CommonRender *commonrender,
38 PluginArray *plugin_array,
40 : Module(renderengine, commonrender, plugin_array, track)
42 data_type = TRACK_VIDEO;
47 masker = new MaskEngine(renderengine->preferences->processors);
49 masker = new MaskEngine(plugin_array->mwindow->preferences->processors);
55 if(overlay_temp) delete overlay_temp;
56 if(input_temp) delete input_temp;
57 if(transition_temp) delete transition_temp;
62 AttachmentPoint* VModule::new_attachment(Plugin *plugin)
64 return new VAttachmentPoint(renderengine, plugin);
67 int VModule::get_buffer_size()
72 CICache* VModule::get_cache()
75 return renderengine->get_vcache();
80 int VModule::import_frame(VFrame *output,
82 int64_t input_position,
87 int64_t corrected_position;
88 int64_t corrected_position_project;
89 // Translation of edit
99 double edl_rate = get_edl()->session->frame_rate;
100 int64_t input_position_project = (int64_t)(input_position *
104 if(!output) printf("VModule::import_frame 10 output=%p\n", output);
106 corrected_position = input_position;
107 corrected_position_project = input_position_project;
108 if(direction == PLAY_REVERSE)
110 corrected_position--;
111 input_position_project--;
114 VDeviceX11 *x11_device = 0;
117 if(renderengine && renderengine->video)
119 x11_device = (VDeviceX11*)renderengine->video->get_output_base();
120 output->set_opengl_state(VFrame::RAM);
125 // Load frame into output
130 File *source = get_cache()->check_out(current_edit->asset,
132 // get_cache()->dump();
136 int64_t edit_startproject = (int64_t)(current_edit->startproject *
139 int64_t edit_startsource = (int64_t)(current_edit->startsource *
142 uint64_t position = corrected_position -
145 // if we hit the end of stream, freeze at last frame
146 uint64_t max_position = source->get_video_length(frame_rate) - 1;
147 if (position > max_position) position = max_position;
148 source->set_video_position(position,
150 source->set_layer(current_edit->channel);
152 ((VTrack*)track)->calculate_input_transfer(current_edit->asset,
153 input_position_project,
165 // printf("VModule::import_frame 1 [ilace] Project: mode (%d) Asset: autofixoption (%d), mode (%d), method (%d)\n",
166 // get_edl()->session->interlace_mode,
167 // current_edit->asset->interlace_autofixoption,
168 // current_edit->asset->interlace_mode,
169 // current_edit->asset->interlace_fixmethod);
171 // Determine the interlacing method to use.
172 int interlace_fixmethod = ilaceautofixmethod2(get_edl()->session->interlace_mode,
173 current_edit->asset->interlace_autofixoption,
174 current_edit->asset->interlace_mode,
175 current_edit->asset->interlace_fixmethod);
177 // char string[BCTEXTLEN];
178 // ilacefixmethod_to_text(string,interlace_fixmethod);
179 // printf("VModule::import_frame 1 [ilace] Compensating by using: '%s'\n",string);
181 // Compensate for the said interlacing...
182 switch (interlace_fixmethod) {
183 case BC_ILACE_FIXMETHOD_NONE:
186 case BC_ILACE_FIXMETHOD_UPONE:
189 case BC_ILACE_FIXMETHOD_DOWNONE:
193 printf("vmodule::importframe WARNING - unknown fix method for interlacing, no compensation in effect\n");
197 // file -> temp -> output
198 if( !EQUIV(in_x1, 0) ||
200 !EQUIV(in_w1, track->track_w) ||
201 !EQUIV(in_h1, track->track_h) ||
204 !EQUIV(out_w1, track->track_w) ||
205 !EQUIV(out_h1, track->track_h) ||
206 !EQUIV(in_w1, current_edit->asset->width) ||
207 !EQUIV(in_h1, current_edit->asset->height))
213 // Get temporary input buffer
218 VRender *vrender = (VRender*)commonrender;
219 input = &vrender->input_temp;
229 ((*input)->get_w() != current_edit->asset->width ||
230 (*input)->get_h() != current_edit->asset->height))
242 (*input) = new VFrame(0,
243 current_edit->asset->width,
244 current_edit->asset->height,
245 get_edl()->session->color_model,
251 (*input)->copy_stacks(output);
254 // Cache for single frame only
255 // if(renderengine && renderengine->command->single_frame())
256 source->set_cache_frames(1);
257 result = source->read_frame((*input));
258 // if(renderengine && renderengine->command->single_frame())
259 source->set_cache_frames(0);
260 (*input)->set_opengl_state(VFrame::RAM);
262 //printf("VModule::import_frame 1 %lld %f\n", input_position, frame_rate);
264 // Find an overlayer object to perform the camera transformation
265 OverlayFrame *overlayer = 0;
267 // OpenGL playback uses hardware
275 VRender *vrender = (VRender*)commonrender;
276 overlayer = vrender->overlayer;
282 printf("VModule::import_frame neither plugin_array nor commonrender is defined.\n");
285 overlay_temp = new OverlayFrame(plugin_array->mwindow->preferences->processors);
288 overlayer = overlay_temp;
290 // printf("VModule::import_frame 1 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
301 // for(int j = 0; j < output->get_w() * 3 * 5; j++)
302 // output->get_rows()[0][j] = 255;
306 x11_device->do_camera(output,
319 output->clear_frame();
322 // get_cache()->check_in(current_edit->asset);
325 // TRANSFER_REPLACE is the fastest transfer mode but it has the disadvantage
326 // of producing green borders in floating point translation of YUV
327 int mode = TRANSFER_REPLACE;
328 if(get_edl()->session->interpolation_type != NEAREST_NEIGHBOR &&
329 cmodel_is_yuv(output->get_color_model()))
330 mode = TRANSFER_NORMAL;
332 overlayer->overlay(output,
344 get_edl()->session->interpolation_type);
347 output->copy_stacks((*input));
352 // Cache single frames only
353 // if(renderengine && renderengine->command->single_frame())
354 source->set_cache_frames(1);
355 result = source->read_frame(output);
356 // if(renderengine && renderengine->command->single_frame())
357 source->set_cache_frames(0);
358 output->set_opengl_state(VFrame::RAM);
361 get_cache()->check_in(current_edit->asset);
367 x11_device->clear_input(output);
371 output->clear_frame();
381 x11_device->clear_input(output);
385 output->clear_frame();
395 int VModule::render(VFrame *output,
396 int64_t start_position,
404 double edl_rate = get_edl()->session->frame_rate;
406 if(use_nudge) start_position += (int64_t)(track->nudge *
410 int64_t start_position_project = (int64_t)(start_position *
415 update_transition(start_position_project,
418 VEdit* current_edit = (VEdit*)track->edits->editof(start_position_project,
421 VEdit* previous_edit = 0;
424 printf(" VModule::render %d %lld %s transition=%p opengl=%d current_edit=%p output=%p\n",
426 start_position_project,
435 output->clear_frame();
436 // We do not apply mask here, since alpha is 0, and neither substracting nor multypling changes it
437 // Another mask mode - "addition" should be added to be able to create mask from empty frames
438 // in this case we would call masking here too...
445 // Process transition
449 // Get temporary buffer
450 VFrame **transition_input = 0;
453 VRender *vrender = (VRender*)commonrender;
454 transition_input = &vrender->transition_temp;
458 transition_input = &transition_temp;
461 if((*transition_input) &&
462 ((*transition_input)->get_w() != track->track_w ||
463 (*transition_input)->get_h() != track->track_h))
465 delete (*transition_input);
466 (*transition_input) = 0;
469 // Load incoming frame
470 if(!(*transition_input))
472 (*transition_input) = new VFrame(0,
475 get_edl()->session->color_model,
479 result = import_frame((*transition_input),
487 // Load transition buffer
488 previous_edit = (VEdit*)current_edit->previous;
490 result |= import_frame(output,
497 // Execute plugin with transition_input and output here
499 transition_server->set_use_opengl(use_opengl, renderengine->video);
500 transition_server->process_transition((*transition_input),
502 (direction == PLAY_FORWARD) ?
503 (start_position_project - current_edit->startproject) :
504 (start_position_project - current_edit->startproject - 1),
509 // Load output buffer
510 result = import_frame(output,
518 int64_t mask_position;
520 mask_position = renderengine->vrender->current_position;
522 mask_position = start_position;
523 masker->do_mask(output,
527 (MaskAutos*)track->automation->autos[AUTOMATION_MASK],
529 1); // we are calling before plugins
540 void VModule::create_objects()
542 Module::create_objects();