initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / vpluginarray.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "cache.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "file.h"
26 #include "mwindow.h"
27 #include "pluginserver.h"
28 #include "preferences.h"
29 #include "recordablevtracks.h"
30 #include "mainsession.h"
31 #include "vframe.h"
32 #include "vmodule.h"
33 #include "vpluginarray.h"
34 #include "vtrack.h"
35
36
37 #define RING_BUFFERS 2
38
39
40
41 VPluginArray::VPluginArray()
42  : PluginArray(TRACK_VIDEO)
43 {
44         realtime_buffers = 0;
45 }
46
47 VPluginArray::~VPluginArray()
48 {
49         file->stop_video_thread();
50         for(int i = 0; i < total_tracks(); i++)
51         {
52                 delete modules[i];
53         }
54         delete tracks;
55 }
56
57 void VPluginArray::get_recordable_tracks()
58 {
59         tracks = new RecordableVTracks(edl->tracks);
60 }
61
62 int64_t VPluginArray::get_bufsize()
63 {
64         return 1;
65 }
66
67 void VPluginArray::create_buffers()
68 {
69         file->start_video_thread(buffer_size,
70                 edl->session->color_model,
71                 RING_BUFFERS,
72                 0);
73 //      if(!plugin_server->realtime) realtime_buffers = file->get_video_buffer();
74 }
75
76 void VPluginArray::get_buffers()
77 {
78         if(!realtime_buffers) realtime_buffers = file->get_video_buffer();
79 }
80
81 void VPluginArray::create_modules()
82 {
83         modules = new Module*[total_tracks()];
84         for(int i = 0; i < total_tracks(); i++)
85         {
86                 modules[i] = new VModule(0, 0, this, tracks->values[i]);
87                 modules[i]->cache = cache;
88                 modules[i]->edl = edl;
89                 modules[i]->create_objects();
90                 modules[i]->render_init();
91         }
92 }
93
94
95 void VPluginArray::process_realtime(int module, 
96         int64_t input_position, 
97         int64_t len)
98 {
99         values[module]->process_buffer(realtime_buffers[module], 
100                         input_position, 
101                         edl->session->frame_rate,
102                         0,
103                         PLAY_FORWARD);
104 }
105
106 int VPluginArray::process_loop(int module, int64_t &write_length)
107 {
108         if(!realtime_buffers) realtime_buffers = file->get_video_buffer();
109
110 // Convert from array of frames to array of tracks
111         VFrame **temp_buffer;
112         temp_buffer = new VFrame*[total_tracks()];
113         for(int i = 0; i < total_tracks(); i++)
114         {
115                 temp_buffer[i] = realtime_buffers[i][0];
116         }
117
118         int result = values[module]->process_loop(realtime_buffers[module], write_length);
119         delete [] temp_buffer;
120         return result;
121 }
122
123 int VPluginArray::write_buffers(int64_t len)
124 {
125         int result = file->write_video_buffer(len);
126         realtime_buffers = 0;
127
128 //      if(!plugin_server->realtime && !done && !result) realtime_buffers = file->get_video_buffer();
129         return result;
130 }
131
132
133 int VPluginArray::total_tracks()
134 {
135         return tracks->total;
136 }
137
138 Track* VPluginArray::track_number(int number)
139 {
140         return (Track*)tracks->values[number];
141 }
142
143