2 #include "automation.h"
8 #include "edlsession.h"
9 #include "fadeengine.h"
10 #include "floatauto.h"
11 #include "floatautos.h"
14 #include "maskengine.h"
17 #include "overlayframe.h"
18 #include "playabletracks.h"
20 #include "preferences.h"
21 #include "renderengine.h"
22 #include "transition.h"
23 #include "transportque.h"
24 #include "vattachmentpoint.h"
25 #include "vdevicex11.h"
27 #include "videodevice.h"
28 #include "virtualvconsole.h"
29 #include "virtualvnode.h"
37 VirtualVNode::VirtualVNode(RenderEngine *renderengine,
38 VirtualConsole *vconsole,
42 VirtualNode *parent_node)
43 : VirtualNode(renderengine,
50 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
51 fader = new FadeEngine(renderengine->preferences->processors);
54 VirtualVNode::~VirtualVNode()
59 VirtualNode* VirtualVNode::create_module(Plugin *real_plugin,
63 return new VirtualVNode(renderengine,
72 VirtualNode* VirtualVNode::create_plugin(Plugin *real_plugin)
74 return new VirtualVNode(renderengine,
82 int VirtualVNode::read_data(VFrame *output_temp,
83 int64_t start_position,
87 VirtualNode *previous_plugin = 0;
91 printf("VirtualVNode::read_data output_temp=%p\n", output_temp);
93 if(vconsole->debug_tree)
94 printf(" VirtualVNode::read_data position=%lld rate=%f title=%s opengl=%d\n",
100 // This is a plugin on parent module with a preceeding effect.
101 // Get data from preceeding effect on parent module.
102 if(parent_node && (previous_plugin = parent_node->get_previous_plugin(this)))
104 result = ((VirtualVNode*)previous_plugin)->render(output_temp,
110 // The current node is the first plugin on parent module.
111 // The parent module has an edit to read from or the current node
112 // has no source to read from.
113 // Read data from parent module
116 result = ((VirtualVNode*)parent_node)->read_data(output_temp,
123 // This is the first node in the tree
124 result = ((VModule*)real_module)->render(output_temp,
126 renderengine->command->get_direction(),
129 vconsole->debug_tree,
137 int VirtualVNode::render(VFrame *output_temp,
138 int64_t start_position,
142 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
145 render_as_module(vrender->video_out,
154 render_as_plugin(output_temp,
162 void VirtualVNode::render_as_plugin(VFrame *output_temp,
163 int64_t start_position,
169 !real_plugin->on) return;
172 if(vconsole->debug_tree)
173 printf(" VirtualVNode::render_as_plugin title=%s use_opengl=%d\n",
177 ((VAttachmentPoint*)attachment)->render(
179 plugin_buffer_number,
182 vconsole->debug_tree,
187 int VirtualVNode::render_as_module(VFrame *video_out,
189 int64_t start_position,
194 int direction = renderengine->command->get_direction();
195 double edl_rate = renderengine->edl->session->frame_rate;
196 // Get position relative to project, compensated for direction
197 int64_t start_position_project = (int64_t)(start_position *
200 if(direction == PLAY_REVERSE) start_position_project--;
202 if(vconsole->debug_tree)
203 printf(" VirtualVNode::render_as_module title=%s use_opengl=%d video_out=%p output_temp=%p\n",
209 output_temp->push_next_effect("VirtualVNode::render_as_module");
211 // Process last subnode. This propogates up the chain of subnodes and finishes
215 VirtualVNode *node = (VirtualVNode*)subnodes.values[subnodes.total - 1];
216 node->render(output_temp,
222 // Read data from previous entity
224 read_data(output_temp,
230 output_temp->pop_next_effect();
232 render_fade(output_temp,
235 track->automation->autos[AUTOMATION_FADE],
238 // Apply mask to output
239 ((VModule *)real_module)->masker->do_mask(output_temp,
243 (MaskAutos*)track->automation->autos[AUTOMATION_MASK],
245 0); // we are not before plugins
248 // overlay on the final output
251 int mute_fragment = 1;
252 int64_t mute_position = 0;
256 get_mute_fragment(start_position,
259 (Autos*)((VTrack*)track)->automation->autos[AUTOMATION_MUTE],
266 render_projector(output_temp,
272 output_temp->push_prev_effect("VirtualVNode::render_as_module");
273 //printf("VirtualVNode::render_as_module\n");
274 //output_temp->dump_stacks();
277 if(renderengine->show_tc)
278 renderengine->vrender->insert_timecode(edit,
285 int VirtualVNode::render_fade(VFrame *output,
286 // start of input fragment in project if forward / end of input fragment if reverse
287 // relative to requested frame rate
288 int64_t start_position,
293 double slope, intercept;
294 int64_t slope_len = 1;
295 FloatAuto *previous = 0;
297 double edl_rate = renderengine->edl->session->frame_rate;
298 int64_t start_position_project = (int64_t)(start_position *
302 if(vconsole->debug_tree)
303 printf(" VirtualVNode::render_fade title=%s\n", track->title);
305 intercept = ((FloatAutos*)autos)->get_value(start_position_project,
311 // CLAMP(intercept, 0, 100);
314 // Can't use overlay here because overlayer blends the frame with itself.
315 // The fade engine can compensate for lack of alpha channels by multiplying the
316 // color components by alpha.
317 if(!EQUIV(intercept / 100, 1))
319 if(((VirtualVConsole*)vconsole)->use_opengl)
320 ((VDeviceX11*)((VirtualVConsole*)vconsole)->get_vdriver())->do_fade(
324 fader->do_fade(output, output, intercept / 100);
330 // Start of input fragment in project if forward. End of input fragment if reverse.
331 int VirtualVNode::render_projector(VFrame *input,
333 int64_t start_position,
336 float in_x1, in_y1, in_x2, in_y2;
337 float out_x1, out_y1, out_x2, out_y2;
338 double edl_rate = renderengine->edl->session->frame_rate;
339 int64_t start_position_project = (int64_t)(start_position *
342 VRender *vrender = ((VirtualVConsole*)vconsole)->vrender;
343 if(vconsole->debug_tree)
344 printf(" VirtualVNode::render_projector input=%p output=%p title=%s\n",
345 input, output, track->title);
349 ((VTrack*)track)->calculate_output_transfer(start_position_project,
350 renderengine->command->get_direction(),
365 //for(int j = 0; j < input->get_w() * 3 * 5; j++)
366 // input->get_rows()[0][j] = 255;
368 if(out_x2 > out_x1 &&
373 int direction = renderengine->command->get_direction();
374 IntAuto *mode_keyframe = 0;
376 (IntAuto*)track->automation->autos[AUTOMATION_MODE]->get_prev_auto(
377 start_position_project,
379 (Auto* &)mode_keyframe);
381 int mode = mode_keyframe->value;
383 // Fade is performed in render_fade so as to allow this module
384 // to be chained in another module, thus only 4 component colormodels
385 // can do dissolves, although a blend equation is still required for 3 component
386 // colormodels since fractional translation requires blending.
388 // If this is the first playable video track and the mode_keyframe is "normal"
389 // the mode may be overridden with "replace". Replace is faster.
390 if(mode == TRANSFER_NORMAL &&
391 vconsole->current_exit_node == vconsole->total_exit_nodes - 1)
392 mode = TRANSFER_REPLACE;
394 if(((VirtualVConsole*)vconsole)->use_opengl)
396 ((VDeviceX11*)((VirtualVConsole*)vconsole)->get_vdriver())->overlay(
413 vrender->overlayer->overlay(output,
425 renderengine->edl->session->interpolation_type);