r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / vdevice1394.C
blob19b45836c2ed7c962995068a9f127755131d4cb7
1 #include "assets.h"
2 #include "audio1394.h"
3 #include "audioconfig.h"
4 #include "audiodevice.h"
5 #include "device1394input.h"
6 #include "device1394output.h"
7 #include "iec61883input.h"
8 #include "iec61883output.h"
9 #include "file.inc"
10 #include "preferences.h"
11 #include "recordconfig.h"
12 #include "vdevice1394.h"
13 #include "vframe.h"
14 #include "playbackconfig.h"
15 #include "videodevice.h"
26 VDevice1394::VDevice1394(VideoDevice *device)
27  : VDeviceBase(device)
29         initialize();
32 VDevice1394::~VDevice1394()
34         close_all();
37 int VDevice1394::initialize()
39         input_thread = 0;
40         output_thread = 0;
41         input_iec = 0;
42         output_iec = 0;
43         user_frame = 0;
46 int VDevice1394::open_input()
48 // Share audio driver.  The audio driver does the capturing in this case
49 // and fills video frames for us.
50         int result = 0;
51         if(device->adevice &&
52                 (device->adevice->in_config->driver == AUDIO_1394 ||
53                         device->adevice->in_config->driver == AUDIO_DV1394 ||
54                         device->adevice->in_config->driver == AUDIO_IEC61883))
55         {
56                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_in();
57                 input_thread = low_level->input_thread;
58                 input_iec = low_level->input_iec;
59                 device->sharing = 1;
60         }
61         else
62         if(!input_thread && !input_iec)
63         {
64                 if(device->in_config->driver == CAPTURE_FIREWIRE)
65                 {
66                         input_thread = new Device1394Input;
67                         result = input_thread->open(device->in_config->firewire_path,
68                                 device->in_config->firewire_port, 
69                                 device->in_config->firewire_channel, 
70                                 device->in_config->capture_length,
71                                 2,
72                                 48000,
73                                 16,
74                                 device->in_config->w,
75                                 device->in_config->h);
76                         if(result)
77                         {
78                                 delete input_thread;
79                                 input_thread = 0;
80                         }
81                 }
82                 else
83                 {
84                         input_iec = new IEC61883Input;
85                         result = input_iec->open(device->in_config->firewire_port, 
86                                 device->in_config->firewire_channel, 
87                                 device->in_config->capture_length,
88                                 2,
89                                 48000,
90                                 16,
91                                 device->in_config->w,
92                                 device->in_config->h);
93                         if(result)
94                         {
95                                 delete input_iec;
96                                 input_iec = 0;
97                         }
98                 }
99         }
100         return result;
103 int VDevice1394::open_output()
105 // Share audio driver.  The audio driver takes DV frames from us and
106 // inserts audio.
107         if(device->adevice &&
108                 (device->adevice->out_config->driver == AUDIO_1394 ||
109                         device->adevice->out_config->driver == AUDIO_DV1394 ||
110                         device->adevice->out_config->driver == AUDIO_IEC61883))
111         {
112                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
113                 output_thread = low_level->output_thread;
114                 output_iec = low_level->output_iec;
115                 device->sharing = 1;
116         }
117         else
118         if(!output_thread && !output_iec)
119         {
120                 if(device->out_config->driver == PLAYBACK_DV1394)
121                 {
122                         output_thread = new Device1394Output(device);
123                         output_thread->open(device->out_config->dv1394_path,
124                                 device->out_config->dv1394_port, 
125                                 device->out_config->dv1394_channel,
126                                 30,
127                                 2,
128                                 16,
129                                 48000,
130                                 device->out_config->dv1394_syt);
131                 }
132                 else
133                 if(device->out_config->driver == PLAYBACK_FIREWIRE)
134                 {
135                         output_thread = new Device1394Output(device);
136                         output_thread->open(device->out_config->firewire_path,
137                                 device->out_config->firewire_port, 
138                                 device->out_config->firewire_channel,
139                                 30,
140                                 2,
141                                 16,
142                                 48000,
143                                 device->out_config->firewire_syt);
144                 }
145                 else
146                 {
147                         output_iec = new IEC61883Output(device);
148                         output_iec->open(device->out_config->firewire_port, 
149                                 device->out_config->firewire_channel,
150                                 30,
151                                 2,
152                                 16,
153                                 48000,
154                                 device->out_config->firewire_syt);
155                 }
156         }
158         return 0;
161 int VDevice1394::close_all()
163         if(device->sharing)
164         {
165                 input_thread = 0;
166                 output_thread = 0;
167                 output_iec = 0;
168                 input_iec = 0;
169                 device->sharing = 0;
170         }
171         else
172         {
173                 if(input_thread)
174                 {
175                         delete input_thread;
176                         input_thread = 0;
177                 }
178                 if(output_thread)
179                 {
180                         delete output_thread;
181                         output_thread = 0;
182                 }
183                 if(input_iec)
184                 {
185                         delete input_iec;
186                         input_iec = 0;
187                 }
188                 if(output_iec)
189                 {
190                         delete output_iec;
191                         output_iec = 0;
192                 }
193         }
194         if(user_frame) delete user_frame;
195         initialize();
196         return 0;
200 int VDevice1394::read_buffer(VFrame *frame)
202         unsigned char *data;
203         long size = 0;
204         int result = 0;
205         if(!input_thread && !input_iec) return 1;
207         if(input_thread) input_thread->read_video(frame);
208         else
209         if(input_iec) input_iec->read_video(frame);
211         return result;
215 void VDevice1394::new_output_buffer(VFrame **output,
216         int colormodel)
218         if(user_frame)
219         {
220                 if(colormodel != user_frame->get_color_model())
221                 {
222                         delete user_frame;
223                         user_frame = 0;
224                 }
225         }
227         if(!user_frame)
228         {
229                 switch(colormodel)
230                 {
231                         case BC_COMPRESSED:
232                                 user_frame = new VFrame;
233                                 break;
234                         default:
235                                 user_frame = new VFrame(0,
236                                         device->out_w,
237                                         device->out_h,
238                                         colormodel,
239                                         -1);
240                                 break;
241                 }
242         }
243         user_frame->set_shm_offset(0);
244         *output = user_frame;
247 int VDevice1394::write_buffer(VFrame *frame, EDL *edl)
249         if(output_thread) output_thread->write_frame(frame);
250         else
251         if(output_iec) output_iec->write_frame(frame);
252         return 0;
258 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
260         return 0;