r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vdevice1394.C
blob7dd62955493ec605c7b1fdbc98dcad36a83c59d7
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 "file.inc"
8 #include "preferences.h"
9 #include "recordconfig.h"
10 #include "vdevice1394.h"
11 #include "vframe.h"
12 #include "playbackconfig.h"
13 #include "videodevice.h"
16 #ifdef HAVE_FIREWIRE
25 VDevice1394::VDevice1394(VideoDevice *device)
26  : VDeviceBase(device)
28         initialize();
31 VDevice1394::~VDevice1394()
33         close_all();
36 int VDevice1394::initialize()
38         input_thread = 0;
39         output_thread = 0;
40         user_frame = 0;
43 int VDevice1394::open_input()
45 //printf("VDevice1394::open_input 1\n");
46 // Share audio driver.  The audio driver does the capturing in this case
47 // and fills video frames for us.
48         int result = 0;
49         if(device->adevice &&
50                 (device->adevice->in_config->driver == AUDIO_1394 ||
51                         device->adevice->in_config->driver == AUDIO_DV1394))
52         {
53                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_in();
54                 input_thread = low_level->input_thread;
55                 device->sharing = 1;
56         }
57         else
58         if(!input_thread)
59         {
60                 input_thread = new Device1394Input;
61                 result = input_thread->open(device->in_config->firewire_port, 
62                         device->in_config->firewire_channel, 
63                         device->in_config->capture_length,
64                         2,
65                         48000,
66                         16);
67                 if(result)
68                 {
69                         delete input_thread;
70                         input_thread = 0;
71                 }
72         }
73         return result;
76 int VDevice1394::open_output()
78 // Share audio driver.  The audio driver takes DV frames from us and
79 // inserts audio.
80         if(device->adevice &&
81                 (device->adevice->out_config->driver == AUDIO_1394 ||
82                         device->adevice->out_config->driver == AUDIO_DV1394))
83         {
84                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
85                 output_thread = low_level->output_thread;
86                 device->sharing = 1;
87         }
88         else
89         if(!output_thread)
90         {
91                 output_thread = new Device1394Output(device);
92                 if(device->out_config->driver == PLAYBACK_DV1394)
93                 {
94                         output_thread->open(device->out_config->dv1394_path,
95                                 device->out_config->dv1394_port, 
96                                 device->out_config->dv1394_channel,
97                                 30,
98                                 2,
99                                 16,
100                                 48000,
101                                 device->out_config->dv1394_syt);
102                 }
103                 else
104                 {
105                         output_thread->open(device->out_config->firewire_path,
106                                 device->out_config->firewire_port, 
107                                 device->out_config->firewire_channel,
108                                 30,
109                                 2,
110                                 16,
111                                 48000,
112                                 device->out_config->firewire_syt);
113                 }
114         }
116         return 0;
119 int VDevice1394::close_all()
121         if(device->sharing)
122         {
123                 input_thread = 0;
124                 output_thread = 0;
125                 device->sharing = 0;
126         }
127         else
128         {
129                 if(input_thread)
130                 {
131                         delete input_thread;
132                         input_thread = 0;
133                 }
134                 if(output_thread)
135                 {
136                         delete output_thread;
137                         output_thread = 0;
138                 }
139         }
140         if(user_frame) delete user_frame;
141         initialize();
142         return 0;
146 int VDevice1394::read_buffer(VFrame *frame)
148         unsigned char *data;
149         long size = 0;
150         int result = 0;
151         if(!input_thread) return 1;
153         input_thread->read_video(frame);
155         return result;
159 void VDevice1394::new_output_buffer(VFrame **outputs,
160         int colormodel)
162         if(user_frame)
163         {
164                 if(colormodel != user_frame->get_color_model())
165                 {
166                         delete user_frame;
167                         user_frame = 0;
168                 }
169         }
171         if(!user_frame)
172         {
173                 switch(colormodel)
174                 {
175                         case BC_COMPRESSED:
176                                 user_frame = new VFrame;
177                                 break;
178                         default:
179                                 user_frame = new VFrame(0,
180                                         device->out_w,
181                                         device->out_h,
182                                         colormodel,
183                                         -1);
184                                 break;
185                 }
186         }
187         user_frame->set_shm_offset(0);
188         outputs[0] = user_frame;
191 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
193         output_thread->write_frame(frame[0]);
194         return 0;
200 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
202         return 0;
215 #endif // HAVE_FIREWIRE