initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / vdevice1394.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 "assets.h"
23 #include "audio1394.h"
24 #include "audioconfig.h"
25 #include "audiodevice.h"
26 #include "device1394input.h"
27 #include "device1394output.h"
28 #include "iec61883input.h"
29 #include "iec61883output.h"
30 #include "file.inc"
31 #include "preferences.h"
32 #include "recordconfig.h"
33 #include "vdevice1394.h"
34 #include "vframe.h"
35 #include "playbackconfig.h"
36 #include "videodevice.h"
37
38
39 #ifdef HAVE_FIREWIRE
40
41
42
43
44
45
46
47
48 VDevice1394::VDevice1394(VideoDevice *device)
49  : VDeviceBase(device)
50 {
51         initialize();
52 }
53
54 VDevice1394::~VDevice1394()
55 {
56         close_all();
57 }
58
59 int VDevice1394::initialize()
60 {
61         input_thread = 0;
62         output_thread = 0;
63         input_iec = 0;
64         output_iec = 0;
65         user_frame = 0;
66         return 0;
67 }
68
69 int VDevice1394::open_input()
70 {
71 // Share audio driver.  The audio driver does the capturing in this case
72 // and fills video frames for us.
73         int result = 0;
74         if(device->adevice &&
75                 (device->adevice->in_config->driver == AUDIO_1394 ||
76                         device->adevice->in_config->driver == AUDIO_DV1394 ||
77                         device->adevice->in_config->driver == AUDIO_IEC61883))
78         {
79                 Audio1394 *low_level = (Audio1394*)device->adevice->lowlevel_in;
80                 input_thread = low_level->input_thread;
81                 input_iec = low_level->input_iec;
82                 device->sharing = 1;
83         }
84         else
85         if(!input_thread && !input_iec)
86         {
87                 if(device->in_config->driver == CAPTURE_FIREWIRE)
88                 {
89                         input_thread = new Device1394Input;
90                         result = input_thread->open(device->in_config->firewire_port, 
91                                 device->in_config->firewire_channel, 
92                                 device->in_config->capture_length,
93                                 2,
94                                 48000,
95                                 16,
96                                 device->in_config->w,
97                                 device->in_config->h);
98                         if(result)
99                         {
100                                 delete input_thread;
101                                 input_thread = 0;
102                         }
103                 }
104                 else
105                 {
106                         input_iec = new IEC61883Input;
107                         result = input_iec->open(device->in_config->firewire_port, 
108                                 device->in_config->firewire_channel, 
109                                 device->in_config->capture_length,
110                                 2,
111                                 48000,
112                                 16,
113                                 device->in_config->w,
114                                 device->in_config->h);
115                         if(result)
116                         {
117                                 delete input_iec;
118                                 input_iec = 0;
119                         }
120                 }
121         }
122         return result;
123 }
124
125 int VDevice1394::open_output()
126 {
127 // Share audio driver.  The audio driver takes DV frames from us and
128 // inserts audio.
129         if(device->adevice &&
130                 (device->adevice->out_config->driver == AUDIO_1394 ||
131                         device->adevice->out_config->driver == AUDIO_DV1394 ||
132                         device->adevice->out_config->driver == AUDIO_IEC61883))
133         {
134                 Audio1394 *low_level = (Audio1394*)device->adevice->lowlevel_out;
135                 output_thread = low_level->output_thread;
136                 output_iec = low_level->output_iec;
137                 device->sharing = 1;
138         }
139         else
140         if(!output_thread && !output_iec)
141         {
142                 if(device->out_config->driver == PLAYBACK_DV1394)
143                 {
144                         output_thread = new Device1394Output(device);
145                         output_thread->open(device->out_config->dv1394_path,
146                                 device->out_config->dv1394_port, 
147                                 device->out_config->dv1394_channel,
148                                 30,
149                                 2,
150                                 16,
151                                 48000,
152                                 device->out_config->dv1394_syt);
153                 }
154                 else
155                 if(device->out_config->driver == PLAYBACK_FIREWIRE)
156                 {
157                         output_thread = new Device1394Output(device);
158                         output_thread->open(device->out_config->firewire_path,
159                                 device->out_config->firewire_port, 
160                                 device->out_config->firewire_channel,
161                                 30,
162                                 2,
163                                 16,
164                                 48000,
165                                 device->out_config->firewire_syt);
166                 }
167                 else
168                 {
169                         output_iec = new IEC61883Output(device);
170                         output_iec->open(device->out_config->firewire_port, 
171                                 device->out_config->firewire_channel,
172                                 30,
173                                 2,
174                                 16,
175                                 48000,
176                                 device->out_config->firewire_syt);
177                 }
178         }
179
180         return 0;
181 }
182
183 int VDevice1394::close_all()
184 {
185         if(device->sharing)
186         {
187                 input_thread = 0;
188                 output_thread = 0;
189                 output_iec = 0;
190                 input_iec = 0;
191                 device->sharing = 0;
192         }
193         else
194         {
195                 if(input_thread)
196                 {
197                         delete input_thread;
198                         input_thread = 0;
199                 }
200                 if(output_thread)
201                 {
202                         delete output_thread;
203                         output_thread = 0;
204                 }
205                 if(input_iec)
206                 {
207                         delete input_iec;
208                         input_iec = 0;
209                 }
210                 if(output_iec)
211                 {
212                         delete output_iec;
213                         output_iec = 0;
214                 }
215         }
216         if(user_frame) delete user_frame;
217         initialize();
218         return 0;
219 }
220
221
222 int VDevice1394::read_buffer(VFrame *frame)
223 {
224         int result = 0;
225         if(!input_thread && !input_iec) return 1;
226
227         if(input_thread) input_thread->read_video(frame);
228         else
229         if(input_iec) input_iec->read_video(frame);
230
231         return result;
232 }
233
234
235 void VDevice1394::new_output_buffer(VFrame **output,
236         int colormodel)
237 {
238         if(user_frame)
239         {
240                 if(colormodel != user_frame->get_color_model())
241                 {
242                         delete user_frame;
243                         user_frame = 0;
244                 }
245         }
246
247         if(!user_frame)
248         {
249                 switch(colormodel)
250                 {
251                         case BC_COMPRESSED:
252                                 user_frame = new VFrame;
253                                 break;
254                         default:
255                                 user_frame = new VFrame(0,
256                                         -1,
257                                         device->out_w,
258                                         device->out_h,
259                                         colormodel,
260                                         -1);
261                                 break;
262                 }
263         }
264
265 //      user_frame->set_shm_offset(0);
266         *output = user_frame;
267 }
268
269 int VDevice1394::write_buffer(VFrame *frame, EDL *edl)
270 {
271         if(output_thread) output_thread->write_frame(frame);
272         else
273         if(output_iec) output_iec->write_frame(frame);
274         return 0;
275 }
276
277
278
279
280 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
281 {
282         return 0;
283 }
284
285
286
287
288
289
290
291
292
293
294
295 #endif // HAVE_FIREWIRE