r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vmodule.C
blob6164d903719aedd702254e2ce10cc2d434c97840
1 #include "asset.h"
2 #include "cache.h"
3 #include "clip.h"
4 #include "commonrender.h"
5 #include "edits.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "file.h"
9 #include "filexml.h"
10 #include "floatautos.h"
11 #include "overlayframe.h"
12 #include "patch.h"
13 #include "preferences.h"
14 #include "renderengine.h"
15 #include "sharedlocation.h"
16 #include "transition.h"
17 #include "transportque.h"
18 #include "units.h"
19 #include "vattachmentpoint.h"
20 #include "vedit.h"
21 #include "vframe.h"
22 #include "vmodule.h"
23 #include "vplugin.h"
24 #include "vtrack.h"
25 #include <string.h>
27 VModule::VModule(RenderEngine *renderengine, 
28         CommonRender *commonrender, 
29         PluginArray *plugin_array,
30         Track *track)
31  : Module(renderengine, commonrender, plugin_array, track)
33         data_type = TRACK_VIDEO;
34         input_temp = transition_temp = 0;
35         overlayer = 0;
38 VModule::~VModule()
40         if(input_temp) 
41         {
42                 delete input_temp;
43         }
44         if(transition_temp) 
45         {
46                 delete transition_temp;
47         }
48         if(overlayer) delete overlayer;
52 AttachmentPoint* VModule::new_attachment(Plugin *plugin)
54         return new VAttachmentPoint(renderengine, plugin);
57 int VModule::get_buffer_size()
59         return 1;
62 CICache* VModule::get_cache()
64         if(renderengine) 
65                 return renderengine->get_vcache();
66         else
67                 return cache;
70 int VModule::import_frame(VFrame *output,
71         VEdit *current_edit,
72         int64_t input_position,
73         int direction)
75         int64_t corrected_position;
77 // Translation of edit
78         float in_x1;
79         float in_y1;
80         float in_w1;
81         float in_h1;
82         float out_x1;
83         float out_y1;
84         float out_w1;
85         float out_h1;
86         int result = 0;
88         corrected_position = input_position;
89         if(direction == PLAY_REVERSE) corrected_position--;
91 // Load frame into output
92         if(current_edit &&
93                 current_edit->asset)
94         {
95                 File *source = get_cache()->check_out(current_edit->asset);
97                 if(source)
98                 {
99                         source->set_video_position(corrected_position - 
100                                 current_edit->startproject + 
101                                 current_edit->startsource,
102                                 get_edl()->session->frame_rate);
103                         source->set_layer(current_edit->channel);
105                         ((VTrack*)track)->calculate_input_transfer(current_edit->asset, 
106                                 input_position, 
107                                 direction, 
108                                 in_x1, 
109                                 in_y1, 
110                                 in_w1, 
111                                 in_h1,
112                                 out_x1, 
113                                 out_y1, 
114                                 out_w1, 
115                                 out_h1);
119 // file -> temp -> output
120                         if( !EQUIV(in_x1, 0) || 
121                                 !EQUIV(in_y1, 0) || 
122                                 !EQUIV(in_w1, track->track_w) || 
123                                 !EQUIV(in_h1, track->track_h) || 
124                                 !EQUIV(out_x1, 0) ||
125                                 !EQUIV(out_y1, 0) ||
126                                 !EQUIV(out_w1, track->track_w) ||
127                                 !EQUIV(out_h1, track->track_h) ||
128                                 !EQUIV(in_w1, current_edit->asset->width) ||
129                                 !EQUIV(in_h1, current_edit->asset->height))
130                         {
131 // Fix buffers
132                                 if(input_temp && 
133                                         (input_temp->get_w() != current_edit->asset->width ||
134                                         input_temp->get_h() != current_edit->asset->height))
135                                 {
136                                         delete input_temp;
137                                         input_temp = 0;
138                                 }
144                                 if(!input_temp)
145                                 {
146 //printf("VModule::import_frame 4\n");
147                                         input_temp = new VFrame(0,
148                                                 current_edit->asset->width,
149                                                 current_edit->asset->height,
150                                                 get_edl()->session->color_model,
151                                                 -1);
152                                 }
153 //printf("VModule::import_frame 5\n");
155 // file -> temp
156                                 result = source->read_frame(input_temp);
157                                 if(!overlayer)
158                                 {
159                                         overlayer = new OverlayFrame(renderengine->preferences->processors);
160                                 }
161 // printf("VModule::import_frame 1 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n", 
162 //      in_x1, 
163 //      in_y1, 
164 //      in_w1, 
165 //      in_h1, 
166 //      out_x1, 
167 //      out_y1, 
168 //      out_w1, 
169 //      out_h1);
171 // temp -> output
172 // for(int j = 0; j < output->get_w() * 3 * 5; j++)
173 //      output->get_rows()[0][j] = 255;
175                                 output->clear_frame();
178 // get_cache()->check_in(current_edit->asset);
179 // return;
181 // TRANSFER_REPLACE is the fastest transfer mode but it has the disadvantage
182 // of producing green borders in floating point translation of YUV
183                                 int mode = TRANSFER_REPLACE;
184                                 if(get_edl()->session->interpolation_type != NEAREST_NEIGHBOR &&
185                                         cmodel_is_yuv(output->get_color_model()))
186                                         mode = TRANSFER_NORMAL;
188                                 overlayer->overlay(output,
189                                         input_temp, 
190                                         in_x1,
191                                         in_y1,
192                                         in_x1 + in_w1,
193                                         in_y1 + in_h1,
194                                         out_x1,
195                                         out_y1,
196                                         out_x1 + out_w1,
197                                         out_y1 + out_h1,
198                                         1,
199                                         mode,
200                                         get_edl()->session->interpolation_type);
201                         }
202                         else
203 // file -> output
204                         {
206 //printf("VModule::import_frame 6\n");
207                                 result = source->read_frame(output);
208                         }
209 //printf("VModule::import_frame 6\n");
211                         get_cache()->check_in(current_edit->asset);
212                 }
213                 else
214                 {
215                         output->clear_frame();
216                         result = 1;
217                 }
218         }
219         else
220 // Silence
221         {
222                 output->clear_frame();
223         }
224 //printf("VModule::import_frame 7\n");
226         return result;
231 int VModule::render(VFrame *output,
232         int64_t input_position,
233         int direction,
234         int use_nudge)
236         int result = 0;
237         if(use_nudge) input_position += track->nudge;
239         update_transition(input_position, direction);
241         VEdit* current_edit = (VEdit*)track->edits->editof(input_position, 
242                 direction,
243                 0);
244         VEdit* previous_edit = 0;
246         if(!current_edit) 
247         {
248                 output->clear_frame();
249                 return 0;
250         }
253 // Process transition
254         if(transition)
255         {
256 // Load incoming frame
257                 if(!transition_temp)
258                 {
259                         transition_temp = new VFrame(0,
260                                 track->track_w,
261                                 track->track_h,
262                                 get_edl()->session->color_model,
263                                 -1);
264                 }
266                 result = import_frame(transition_temp, 
267                         current_edit, 
268                         input_position,
269                         direction);
272 // Load transition buffer
273                 previous_edit = (VEdit*)current_edit->previous;
275                 result |= import_frame(output, 
276                         previous_edit, 
277                         input_position,
278                         direction);
280 // Execute plugin with transition_temp and output here
281                 int64_t corrected_position = input_position;
282                 if(direction == PLAY_REVERSE)
283                         corrected_position--;
285                 transition_server->process_realtime(&transition_temp, 
286                         &output,
287                         (direction == PLAY_FORWARD) ? 
288                                 (input_position - current_edit->startproject) :
289                                 (input_position - current_edit->startproject - 1),
290                         transition->length);
291         }
292         else
293         {
294 // Load output buffer
295                 result = import_frame(output, 
296                         current_edit, 
297                         input_position,
298                         direction);
299         }
302         return result;
310 void VModule::create_objects()
312         Module::create_objects();