r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / vdevice1394.C
blobf4a4a5bb4bf03491de8f09599a2a76029e425315
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"
18 #ifdef HAVE_FIREWIRE
27 VDevice1394::VDevice1394(VideoDevice *device)
28  : VDeviceBase(device)
30         initialize();
33 VDevice1394::~VDevice1394()
35         close_all();
38 int VDevice1394::initialize()
40         input_thread = 0;
41         output_thread = 0;
42         input_iec = 0;
43         output_iec = 0;
44         user_frame = 0;
47 int VDevice1394::open_input()
49 // Share audio driver.  The audio driver does the capturing in this case
50 // and fills video frames for us.
51         int result = 0;
52         if(device->adevice &&
53                 (device->adevice->in_config->driver == AUDIO_1394 ||
54                         device->adevice->in_config->driver == AUDIO_DV1394 ||
55                         device->adevice->in_config->driver == AUDIO_IEC61883))
56         {
57                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_in();
58                 input_thread = low_level->input_thread;
59                 input_iec = low_level->input_iec;
60                 device->sharing = 1;
61         }
62         else
63         if(!input_thread && !input_iec)
64         {
65                 if(device->in_config->driver == CAPTURE_FIREWIRE)
66                 {
67                         input_thread = new Device1394Input;
68                         result = input_thread->open(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 **outputs,
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         outputs[0] = user_frame;
247 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
249         if(output_thread) output_thread->write_frame(frame[0]);
250         else
251         if(output_iec) output_iec->write_frame(frame[0]);
252         return 0;
258 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
260         return 0;
273 #endif // HAVE_FIREWIRE