r793: Small API addon, so plugins can 'see' camera and projector automation
[cinelerra_cv/mob.git] / cinelerra / vdevice1394.C
blob59d1f53ff8e4510579e4217167265db94ddf34b9
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_port, 
68                                 device->in_config->firewire_channel, 
69                                 device->in_config->capture_length,
70                                 2,
71                                 48000,
72                                 16,
73                                 device->in_config->w,
74                                 device->in_config->h);
75                         if(result)
76                         {
77                                 delete input_thread;
78                                 input_thread = 0;
79                         }
80                 }
81                 else
82                 {
83                         input_iec = new IEC61883Input;
84                         result = input_iec->open(device->in_config->firewire_port, 
85                                 device->in_config->firewire_channel, 
86                                 device->in_config->capture_length,
87                                 2,
88                                 48000,
89                                 16,
90                                 device->in_config->w,
91                                 device->in_config->h);
92                         if(result)
93                         {
94                                 delete input_iec;
95                                 input_iec = 0;
96                         }
97                 }
98         }
99         return result;
102 int VDevice1394::open_output()
104 // Share audio driver.  The audio driver takes DV frames from us and
105 // inserts audio.
106         if(device->adevice &&
107                 (device->adevice->out_config->driver == AUDIO_1394 ||
108                         device->adevice->out_config->driver == AUDIO_DV1394 ||
109                         device->adevice->out_config->driver == AUDIO_IEC61883))
110         {
111                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
112                 output_thread = low_level->output_thread;
113                 output_iec = low_level->output_iec;
114                 device->sharing = 1;
115         }
116         else
117         if(!output_thread && !output_iec)
118         {
119                 if(device->out_config->driver == PLAYBACK_DV1394)
120                 {
121                         output_thread = new Device1394Output(device);
122                         output_thread->open(device->out_config->dv1394_path,
123                                 device->out_config->dv1394_port, 
124                                 device->out_config->dv1394_channel,
125                                 30,
126                                 2,
127                                 16,
128                                 48000,
129                                 device->out_config->dv1394_syt);
130                 }
131                 else
132                 if(device->out_config->driver == PLAYBACK_FIREWIRE)
133                 {
134                         output_thread = new Device1394Output(device);
135                         output_thread->open(device->out_config->firewire_path,
136                                 device->out_config->firewire_port, 
137                                 device->out_config->firewire_channel,
138                                 30,
139                                 2,
140                                 16,
141                                 48000,
142                                 device->out_config->firewire_syt);
143                 }
144                 else
145                 {
146                         output_iec = new IEC61883Output(device);
147                         output_iec->open(device->out_config->firewire_port, 
148                                 device->out_config->firewire_channel,
149                                 30,
150                                 2,
151                                 16,
152                                 48000,
153                                 device->out_config->firewire_syt);
154                 }
155         }
157         return 0;
160 int VDevice1394::close_all()
162         if(device->sharing)
163         {
164                 input_thread = 0;
165                 output_thread = 0;
166                 output_iec = 0;
167                 input_iec = 0;
168                 device->sharing = 0;
169         }
170         else
171         {
172                 if(input_thread)
173                 {
174                         delete input_thread;
175                         input_thread = 0;
176                 }
177                 if(output_thread)
178                 {
179                         delete output_thread;
180                         output_thread = 0;
181                 }
182                 if(input_iec)
183                 {
184                         delete input_iec;
185                         input_iec = 0;
186                 }
187                 if(output_iec)
188                 {
189                         delete output_iec;
190                         output_iec = 0;
191                 }
192         }
193         if(user_frame) delete user_frame;
194         initialize();
195         return 0;
199 int VDevice1394::read_buffer(VFrame *frame)
201         unsigned char *data;
202         long size = 0;
203         int result = 0;
204         if(!input_thread && !input_iec) return 1;
206         if(input_thread) input_thread->read_video(frame);
207         else
208         if(input_iec) input_iec->read_video(frame);
210         return result;
214 void VDevice1394::new_output_buffer(VFrame **outputs,
215         int colormodel)
217         if(user_frame)
218         {
219                 if(colormodel != user_frame->get_color_model())
220                 {
221                         delete user_frame;
222                         user_frame = 0;
223                 }
224         }
226         if(!user_frame)
227         {
228                 switch(colormodel)
229                 {
230                         case BC_COMPRESSED:
231                                 user_frame = new VFrame;
232                                 break;
233                         default:
234                                 user_frame = new VFrame(0,
235                                         device->out_w,
236                                         device->out_h,
237                                         colormodel,
238                                         -1);
239                                 break;
240                 }
241         }
242         user_frame->set_shm_offset(0);
243         outputs[0] = user_frame;
246 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
248         if(output_thread) output_thread->write_frame(frame[0]);
249         else
250         if(output_iec) output_iec->write_frame(frame[0]);
251         return 0;
257 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
259         return 0;