r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / cinelerra / vattachmentpoint.C
blobb97fef4cdb400fc34b677a2524ecb49a9b1fbdf6
1 #include "bcsignals.h"
2 #include "clip.h"
3 #include "datatype.h"
4 #include "edl.h"
5 #include "edlsession.h"
6 #include "plugin.h"
7 #include "pluginserver.h"
8 #include "renderengine.h"
9 #include "transportque.h"
10 #include "vattachmentpoint.h"
11 #include "vdevicex11.h"
12 #include "videodevice.h"
13 #include "vframe.h"
15 VAttachmentPoint::VAttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
16 : AttachmentPoint(renderengine, plugin, TRACK_VIDEO)
18         buffer_vector = 0;
21 VAttachmentPoint::~VAttachmentPoint()
23         delete_buffer_vector();
26 void VAttachmentPoint::delete_buffer_vector()
28         if(!this) printf("VAttachmentPoint::delete_buffer_vector NULL\n");
29         if(buffer_vector)
30         {
31                 for(int i = 0; i < virtual_plugins.total; i++)
32                         delete buffer_vector[i];
33                 delete [] buffer_vector;
34         }
35         buffer_vector = 0;
38 void VAttachmentPoint::new_buffer_vector(int width, int height, int colormodel)
40         if(!this) printf("VAttachmentPoint::new_buffer_vector NULL\n");
41         if(buffer_vector &&
42                 (width != buffer_vector[0]->get_w() ||
43                 height != buffer_vector[0]->get_h() ||
44                 colormodel != buffer_vector[0]->get_color_model()))
45         {
46                 delete_buffer_vector();
47         }
49         if(!buffer_vector)
50         {
51                 buffer_vector = new VFrame*[virtual_plugins.total];
52                 for(int i = 0; i < virtual_plugins.total; i++)
53                 {
54                         buffer_vector[i] = new VFrame(0,
55                                 width,
56                                 height,
57                                 colormodel,
58                                 -1);
59                 }
60         }
63 int VAttachmentPoint::get_buffer_size()
65         return 1;
68 void VAttachmentPoint::render(VFrame *output, 
69         int buffer_number,
70         int64_t start_position,
71         double frame_rate,
72         int debug_render,
73         int use_opengl)
75         if(!this) printf("VAttachmentPoint::render NULL\n");
76         if(!plugin_server || !plugin->on) return;
78         if(debug_render)
79                 printf("    VAttachmentPoint::render \"%s\" multi=%d opengl=%d\n", 
80                         plugin_server->title,
81                         plugin_server->multichannel,
82                         use_opengl);
84         if(plugin_server->multichannel)
85         {
86 // Test against previous parameters for reuse of previous data
87                 if(is_processed &&
88                         this->start_position == start_position &&
89                         EQUIV(this->frame_rate, frame_rate))
90                 {
91 // Need to copy PBuffer if OpenGL, regardless of use_opengl
92                         if(buffer_vector[buffer_number]->get_opengl_state() == VFrame::RAM)
93                         {
94                                 output->copy_from(buffer_vector[buffer_number]);
95                                 output->set_opengl_state(VFrame::RAM);
96                         }
97                         else
98                         if(renderengine && renderengine->video)
99                         {
100 // Need to copy PBuffer to texture
101 // printf("VAttachmentPoint::render temp=%p output=%p\n", 
102 // buffer_vector[buffer_number],
103 // output);
104                                 VDeviceX11 *x11_device = (VDeviceX11*)renderengine->video->get_output_base();
105                                 x11_device->copy_frame(output, buffer_vector[buffer_number]);
106                         }
107                         return;
108                 }
110                 is_processed = 1;
111                 this->start_position = start_position;
112                 this->frame_rate = frame_rate;
114 // Allocate buffer vector for subsequent render calls
115                 new_buffer_vector(output->get_w(), 
116                         output->get_h(), 
117                         output->get_color_model());
119 // Create temporary vector with output argument substituted in
120                 VFrame **output_temp = new VFrame*[virtual_plugins.total];
121                 for(int i = 0; i < virtual_plugins.total; i++)
122                 {
123                         if(i == buffer_number)
124                                 output_temp[i] = output;
125                         else
126                                 output_temp[i] = buffer_vector[i];
127                 }
129 // Process plugin
130 //printf("VAttachmentPoint::render 1 %d\n", buffer_number);
131                 if(renderengine)
132                         plugin_servers.values[0]->set_use_opengl(use_opengl,
133                                 renderengine->video);
134                 plugin_servers.values[0]->process_buffer(output_temp,
135                         start_position,
136                         frame_rate,
137                         (int64_t)Units::round(plugin->length * 
138                                 frame_rate / 
139                                 renderengine->edl->session->frame_rate),
140                         renderengine->command->get_direction());
141 //printf("VAttachmentPoint::render 2\n");
143                 delete [] output_temp;
144 //printf("VAttachmentPoint::render 3\n");
145         }
146         else
147 // process single track
148         {
149                 VFrame *output_temp[1];
150                 output_temp[0] = output;
151                 if(renderengine)
152                         plugin_servers.values[buffer_number]->set_use_opengl(use_opengl,
153                                 renderengine->video);
154                 plugin_servers.values[buffer_number]->process_buffer(output_temp,
155                         start_position,
156                         frame_rate,
157                         (int64_t)Units::round(plugin->length * 
158                                 frame_rate / 
159                                 renderengine->edl->session->frame_rate),
160                         renderengine->command->get_direction());
161         }