2 #include "automation.h"
7 #include "edlsession.h"
8 #include "fadeengine.h"
10 #include "floatautos.h"
13 #include "maskengine.h"
16 #include "overlayframe.h"
17 #include "playabletracks.h"
19 #include "preferences.h"
20 #include "renderengine.h"
21 #include "transition.h"
22 #include "transportque.h"
23 #include "vattachmentpoint.h"
24 #include "vdevicex11.h"
26 #include "videodevice.h"
27 #include "virtualvconsole.h"
28 #include "virtualvnode.h"
36 VirtualVNode::VirtualVNode(RenderEngine *renderengine,
37 VirtualConsole *vconsole,
41 VirtualNode *parent_node)
42 : VirtualNode(renderengine,
49 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
50 fader = new FadeEngine(renderengine->preferences->processors);
53 VirtualVNode::~VirtualVNode()
58 VirtualNode* VirtualVNode::create_module(Plugin *real_plugin,
62 return new VirtualVNode(renderengine,
71 VirtualNode* VirtualVNode::create_plugin(Plugin *real_plugin)
73 return new VirtualVNode(renderengine,
81 int VirtualVNode::read_data(VFrame *output_temp,
82 int64_t start_position,
86 VirtualNode *previous_plugin = 0;
90 printf("VirtualVNode::read_data output_temp=%p\n", output_temp);
92 if(vconsole->debug_tree)
93 printf(" VirtualVNode::read_data position=%lld rate=%f title=%s opengl=%d\n",
99 // If there is a parent module but the parent module has no data source,
100 // use our own data source.
101 // Current edit in parent track
102 VEdit *parent_edit = 0;
103 if(parent_node && parent_node->track && renderengine)
105 double edl_rate = renderengine->edl->session->frame_rate;
106 int64_t start_position_project = (int64_t)(start_position *
110 parent_edit = (VEdit*)parent_node->track->edits->editof(start_position_project,
111 renderengine->command->get_direction(),
116 // This is a plugin on parent module with a preceeding effect.
117 // Get data from preceeding effect on parent module.
118 if(parent_node && (previous_plugin = parent_node->get_previous_plugin(this)))
120 result = ((VirtualVNode*)previous_plugin)->render(output_temp,
126 // The current node is the first plugin on parent module.
127 // The parent module has an edit to read from or the current node
128 // has no source to read from.
129 // Read data from parent module
130 if(parent_node && (parent_edit || !real_module))
132 result = ((VirtualVNode*)parent_node)->read_data(output_temp,
140 // This is the first node in the tree
141 result = ((VModule*)real_module)->render(output_temp,
143 renderengine->command->get_direction(),
146 vconsole->debug_tree,
154 int VirtualVNode::render(VFrame *output_temp,
155 int64_t start_position,
159 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
162 render_as_module(vrender->video_out,
171 render_as_plugin(output_temp,
179 void VirtualVNode::render_as_plugin(VFrame *output_temp,
180 int64_t start_position,
186 !real_plugin->on) return;
189 if(vconsole->debug_tree)
190 printf(" VirtualVNode::render_as_plugin title=%s use_opengl=%d\n",
194 ((VAttachmentPoint*)attachment)->render(
196 plugin_buffer_number,
199 vconsole->debug_tree,
204 int VirtualVNode::render_as_module(VFrame *video_out,
206 int64_t start_position,
211 int direction = renderengine->command->get_direction();
212 double edl_rate = renderengine->edl->session->frame_rate;
213 // Get position relative to project, compensated for direction
214 int64_t start_position_project = (int64_t)(start_position *
217 if(direction == PLAY_REVERSE) start_position_project--;
219 if(vconsole->debug_tree)
220 printf(" VirtualVNode::render_as_module title=%s use_opengl=%d video_out=%p output_temp=%p\n",
226 output_temp->push_next_effect("VirtualVNode::render_as_module");
228 // Process last subnode. This propogates up the chain of subnodes and finishes
232 VirtualVNode *node = (VirtualVNode*)subnodes.values[subnodes.total - 1];
233 node->render(output_temp,
239 // Read data from previous entity
241 read_data(output_temp,
247 output_temp->pop_next_effect();
249 render_fade(output_temp,
252 track->automation->autos[AUTOMATION_FADE],
255 // Apply mask to output
256 ((VModule *)real_module)->masker->do_mask(output_temp,
260 (MaskAutos*)track->automation->autos[AUTOMATION_MASK],
262 0); // we are not before plugins
265 // overlay on the final output
268 int mute_fragment = 1;
269 int64_t mute_position = 0;
273 get_mute_fragment(start_position,
276 (Autos*)((VTrack*)track)->automation->autos[AUTOMATION_MUTE],
283 render_projector(output_temp,
289 output_temp->push_prev_effect("VirtualVNode::render_as_module");
290 //printf("VirtualVNode::render_as_module\n");
291 //output_temp->dump_stacks();
294 if(renderengine->show_tc)
295 renderengine->vrender->insert_timecode(edit,
302 int VirtualVNode::render_fade(VFrame *output,
303 // start of input fragment in project if forward / end of input fragment if reverse
304 // relative to requested frame rate
305 int64_t start_position,
310 double slope, intercept;
311 int64_t slope_len = 1;
312 FloatAuto *previous = 0;
314 double edl_rate = renderengine->edl->session->frame_rate;
315 int64_t start_position_project = (int64_t)(start_position *
319 if(vconsole->debug_tree)
320 printf(" VirtualVNode::render_fade title=%s\n", track->title);
322 intercept = ((FloatAutos*)autos)->get_value(start_position_project,
328 CLAMP(intercept, 0, 100);
331 // Can't use overlay here because overlayer blends the frame with itself.
332 // The fade engine can compensate for lack of alpha channels by multiplying the
333 // color components by alpha.
334 if(!EQUIV(intercept / 100, 1))
336 if(((VirtualVConsole*)vconsole)->use_opengl)
337 ((VDeviceX11*)((VirtualVConsole*)vconsole)->get_vdriver())->do_fade(
341 fader->do_fade(output, output, intercept / 100);
347 // Start of input fragment in project if forward. End of input fragment if reverse.
348 int VirtualVNode::render_projector(VFrame *input,
350 int64_t start_position,
353 float in_x1, in_y1, in_x2, in_y2;
354 float out_x1, out_y1, out_x2, out_y2;
355 double edl_rate = renderengine->edl->session->frame_rate;
356 int64_t start_position_project = (int64_t)(start_position *
359 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
360 if(vconsole->debug_tree)
361 printf(" VirtualVNode::render_projector input=%p output=%p title=%s\n",
362 input, output, track->title);
366 ((VTrack*)track)->calculate_output_transfer(start_position_project,
367 renderengine->command->get_direction(),
382 //for(int j = 0; j < input->get_w() * 3 * 5; j++)
383 // input->get_rows()[0][j] = 255;
385 if(out_x2 > out_x1 &&
390 int direction = renderengine->command->get_direction();
391 IntAuto *mode_keyframe = 0;
393 (IntAuto*)track->automation->autos[AUTOMATION_MODE]->get_prev_auto(
394 start_position_project,
396 (Auto* &)mode_keyframe);
398 int mode = mode_keyframe->value;
400 // Fade is performed in render_fade so as to allow this module
401 // to be chained in another module, thus only 4 component colormodels
402 // can do dissolves, although a blend equation is still required for 3 component
403 // colormodels since fractional translation requires blending.
405 // If this is the first playable video track and the mode_keyframe is "normal"
406 // the mode may be overridden with "replace". Replace is faster.
407 if(mode == TRANSFER_NORMAL &&
408 vconsole->current_exit_node == vconsole->total_exit_nodes - 1)
409 mode = TRANSFER_REPLACE;
411 if(((VirtualVConsole*)vconsole)->use_opengl)
413 ((VDeviceX11*)((VirtualVConsole*)vconsole)->get_vdriver())->overlay(
430 vrender->overlayer->overlay(output,
442 renderengine->edl->session->interpolation_type);