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"
32 VModule::VModule(RenderEngine *renderengine,
33 CommonRender *commonrender,
34 PluginArray *plugin_array,
36 : Module(renderengine, commonrender, plugin_array, track)
38 data_type = TRACK_VIDEO;
46 if(overlay_temp) delete overlay_temp;
47 if(input_temp) delete input_temp;
48 if(transition_temp) delete transition_temp;
52 AttachmentPoint* VModule::new_attachment(Plugin *plugin)
54 return new VAttachmentPoint(renderengine, plugin);
57 int VModule::get_buffer_size()
62 CICache* VModule::get_cache()
65 return renderengine->get_vcache();
70 int VModule::import_frame(VFrame *output,
72 int64_t input_position,
76 int64_t corrected_position;
77 int64_t corrected_position_project;
78 // Translation of edit
89 double edl_rate = get_edl()->session->frame_rate;
90 int64_t input_position_project = (int64_t)(input_position *
94 if(!output) printf("VModule::import_frame 10 output=%p\n", output);
97 corrected_position = input_position;
98 corrected_position_project = input_position_project;
99 if(direction == PLAY_REVERSE)
101 corrected_position--;
102 input_position_project--;
105 // Load frame into output
111 File *source = get_cache()->check_out(current_edit->asset);
113 // get_cache()->dump();
117 int64_t edit_startproject = (int64_t)(current_edit->startproject *
120 int64_t edit_startsource = (int64_t)(current_edit->startsource *
123 uint64_t position = corrected_position -
126 // if we hit the end of stream, freeze at last frame
127 uint64_t max_position = source->get_video_length(frame_rate) - 1;
128 if (position > max_position) position = max_position;
129 source->set_video_position(position,
131 source->set_layer(current_edit->channel);
134 ((VTrack*)track)->calculate_input_transfer(current_edit->asset,
135 input_position_project,
147 // printf("VModule::import_frame 1 [ilace] Project: mode (%d) Asset: autofixoption (%d), mode (%d), method (%d)\n",
148 // get_edl()->session->interlace_mode,
149 // current_edit->asset->interlace_autofixoption,
150 // current_edit->asset->interlace_mode,
151 // current_edit->asset->interlace_fixmethod);
153 // Determine the interlacing method to use.
154 int interlace_fixmethod = ilaceautofixmethod2(get_edl()->session->interlace_mode,
155 current_edit->asset->interlace_autofixoption,
156 current_edit->asset->interlace_mode,
157 current_edit->asset->interlace_fixmethod);
159 // char string[BCTEXTLEN];
160 // ilacefixmethod_to_text(string,interlace_fixmethod);
161 // printf("VModule::import_frame 1 [ilace] Compensating by using: '%s'\n",string);
163 // Compensate for the said interlacing...
164 switch (interlace_fixmethod) {
165 case BC_ILACE_FIXMETHOD_NONE:
168 case BC_ILACE_FIXMETHOD_UPONE:
171 case BC_ILACE_FIXMETHOD_DOWNONE:
175 printf("vmodule::importframe WARNING - unknown fix method for interlacing, no compensation in effect\n");
180 // file -> temp -> output
181 if( !EQUIV(in_x1, 0) ||
183 !EQUIV(in_w1, track->track_w) ||
184 !EQUIV(in_h1, track->track_h) ||
187 !EQUIV(out_w1, track->track_w) ||
188 !EQUIV(out_h1, track->track_h) ||
189 !EQUIV(in_w1, current_edit->asset->width) ||
190 !EQUIV(in_h1, current_edit->asset->height))
192 //printf("VModule::import_frame 1\n");
193 // Get temporary input buffer
198 VRender *vrender = (VRender*)commonrender;
199 input = &vrender->input_temp;
209 ((*input)->get_w() != current_edit->asset->width ||
210 (*input)->get_h() != current_edit->asset->height))
222 (*input) = new VFrame(0,
223 current_edit->asset->width,
224 current_edit->asset->height,
225 get_edl()->session->color_model,
232 // Cache for single frame only
233 if(renderengine && renderengine->command->single_frame())
234 source->set_cache_frames(1);
236 result = source->read_frame((*input));
238 if(renderengine && renderengine->command->single_frame())
239 source->set_cache_frames(0);
241 //printf("VModule::import_frame 1 %lld %f\n", input_position, frame_rate);
242 OverlayFrame *overlayer = 0;
246 VRender *vrender = (VRender*)commonrender;
247 overlayer = vrender->overlayer;
253 printf("VModule::import_frame neither plugin_array nor commonrender is defined.\n");
256 overlay_temp = new OverlayFrame(plugin_array->mwindow->preferences->processors);
259 overlayer = overlay_temp;
261 // printf("VModule::import_frame 1 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
272 // for(int j = 0; j < output->get_w() * 3 * 5; j++)
273 // output->get_rows()[0][j] = 255;
275 output->clear_frame();
278 // get_cache()->check_in(current_edit->asset);
281 int mode = TRANSFER_REPLACE;
283 overlayer->overlay(output,
295 get_edl()->session->interpolation_type);
297 //printf("VModule::import_frame 20\n");
302 //printf("VModule::import_frame 30 %p\n", output);
303 // Cache single frames only
304 if(renderengine && renderengine->command->single_frame())
305 source->set_cache_frames(1);
306 result = source->read_frame(output);
307 if(renderengine && renderengine->command->single_frame())
308 source->set_cache_frames(0);
309 //printf("VModule::import_frame 40\n");
313 get_cache()->check_in(current_edit->asset);
317 output->clear_frame();
324 output->clear_frame();
332 int VModule::render(VFrame *output,
333 int64_t start_position,
340 double edl_rate = get_edl()->session->frame_rate;
343 if(use_nudge) start_position += (int64_t)(track->nudge *
348 int64_t start_position_project = (int64_t)(start_position *
354 printf(" VModule::render %d %lld %s\n",
356 start_position_project,
359 update_transition(start_position_project,
363 VEdit* current_edit = (VEdit*)track->edits->editof(start_position_project,
367 VEdit* previous_edit = 0;
371 output->clear_frame();
378 // Process transition
382 // Get temporary buffer
383 VFrame **transition_input = 0;
386 VRender *vrender = (VRender*)commonrender;
387 transition_input = &vrender->transition_temp;
391 transition_input = &transition_temp;
394 if((*transition_input) &&
395 ((*transition_input)->get_w() != track->track_w ||
396 (*transition_input)->get_h() != track->track_h))
398 delete (*transition_input);
399 (*transition_input) = 0;
402 // Load incoming frame
403 if(!(*transition_input))
405 (*transition_input) = new VFrame(0,
408 get_edl()->session->color_model,
412 result = import_frame((*transition_input),
419 // Load transition buffer
420 previous_edit = (VEdit*)current_edit->previous;
422 result |= import_frame(output,
428 // Execute plugin with transition_input and output here
429 transition_server->process_transition((*transition_input),
431 (direction == PLAY_FORWARD) ?
432 (start_position_project - current_edit->startproject) :
433 (start_position_project - current_edit->startproject - 1),
438 // Load output buffer
440 result = import_frame(output,
457 void VModule::create_objects()
459 Module::create_objects();