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