4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcsignals.h"
26 #include "edlsession.h"
28 #include "pluginserver.h"
29 #include "renderengine.h"
30 #include "transportque.h"
31 #include "vattachmentpoint.h"
32 #include "vdevicex11.h"
33 #include "videodevice.h"
36 VAttachmentPoint::VAttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
37 : AttachmentPoint(renderengine, plugin, TRACK_VIDEO)
42 VAttachmentPoint::~VAttachmentPoint()
44 delete_buffer_vector();
47 void VAttachmentPoint::delete_buffer_vector()
49 if(!this) printf("VAttachmentPoint::delete_buffer_vector NULL\n");
52 for(int i = 0; i < virtual_plugins.total; i++)
53 delete buffer_vector[i];
54 delete [] buffer_vector;
59 void VAttachmentPoint::new_buffer_vector(int width, int height, int colormodel)
61 if(!this) printf("VAttachmentPoint::new_buffer_vector NULL\n");
63 (width != buffer_vector[0]->get_w() ||
64 height != buffer_vector[0]->get_h() ||
65 colormodel != buffer_vector[0]->get_color_model()))
67 delete_buffer_vector();
72 buffer_vector = new VFrame*[virtual_plugins.total];
73 for(int i = 0; i < virtual_plugins.total; i++)
75 buffer_vector[i] = new VFrame(0,
85 int VAttachmentPoint::get_buffer_size()
90 void VAttachmentPoint::render(VFrame *output,
92 int64_t start_position,
97 if(!this) printf("VAttachmentPoint::render NULL\n");
98 if(!plugin_server || !plugin->on) return;
101 printf(" VAttachmentPoint::render \"%s\" multi=%d opengl=%d\n",
102 plugin_server->title,
103 plugin_server->multichannel,
106 if(plugin_server->multichannel)
108 // Test against previous parameters for reuse of previous data
110 this->start_position == start_position &&
111 EQUIV(this->frame_rate, frame_rate))
113 // Need to copy PBuffer if OpenGL, regardless of use_opengl
114 if(buffer_vector[buffer_number]->get_opengl_state() == VFrame::RAM)
116 output->copy_from(buffer_vector[buffer_number]);
117 output->set_opengl_state(VFrame::RAM);
120 if(renderengine && renderengine->video)
122 // Need to copy PBuffer to texture
123 // printf("VAttachmentPoint::render temp=%p output=%p\n",
124 // buffer_vector[buffer_number],
126 VDeviceX11 *x11_device = (VDeviceX11*)renderengine->video->get_output_base();
127 x11_device->copy_frame(output, buffer_vector[buffer_number]);
133 this->start_position = start_position;
134 this->frame_rate = frame_rate;
136 // Allocate buffer vector for subsequent render calls
137 new_buffer_vector(output->get_w(),
139 output->get_color_model());
141 // Create temporary vector with output argument substituted in
142 VFrame **output_temp = new VFrame*[virtual_plugins.total];
143 for(int i = 0; i < virtual_plugins.total; i++)
145 if(i == buffer_number)
146 output_temp[i] = output;
148 output_temp[i] = buffer_vector[i];
152 //printf("VAttachmentPoint::render 1 %d\n", buffer_number);
154 plugin_servers.values[0]->set_use_opengl(use_opengl,
155 renderengine->video);
156 plugin_servers.values[0]->process_buffer(output_temp,
159 (int64_t)Units::round(plugin->length *
161 renderengine->get_edl()->session->frame_rate),
162 renderengine->command->get_direction());
163 //printf("VAttachmentPoint::render 2\n");
165 delete [] output_temp;
166 //printf("VAttachmentPoint::render 3\n");
169 // process single track
171 VFrame *output_temp[1];
172 output_temp[0] = output;
174 plugin_servers.values[buffer_number]->set_use_opengl(use_opengl,
175 renderengine->video);
176 plugin_servers.values[buffer_number]->process_buffer(output_temp,
179 (int64_t)Units::round(plugin->length *
181 renderengine->get_edl()->session->frame_rate),
182 renderengine->command->get_direction());