r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vdevice1394.C
blob577f6a409b269afd99dcb61f939546237c4c4b54
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                         device->in_config->w,
68                         device->in_config->h);
69                 if(result)
70                 {
71                         delete input_thread;
72                         input_thread = 0;
73                 }
74         }
75         return result;
78 int VDevice1394::open_output()
80 // Share audio driver.  The audio driver takes DV frames from us and
81 // inserts audio.
82         if(device->adevice &&
83                 (device->adevice->out_config->driver == AUDIO_1394 ||
84                         device->adevice->out_config->driver == AUDIO_DV1394))
85         {
86                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
87                 output_thread = low_level->output_thread;
88                 device->sharing = 1;
89         }
90         else
91         if(!output_thread)
92         {
93                 output_thread = new Device1394Output(device);
94                 if(device->out_config->driver == PLAYBACK_DV1394)
95                 {
96                         output_thread->open(device->out_config->dv1394_path,
97                                 device->out_config->dv1394_port, 
98                                 device->out_config->dv1394_channel,
99                                 30,
100                                 2,
101                                 16,
102                                 48000,
103                                 device->out_config->dv1394_syt);
104                 }
105                 else
106                 {
107                         output_thread->open(device->out_config->firewire_path,
108                                 device->out_config->firewire_port, 
109                                 device->out_config->firewire_channel,
110                                 30,
111                                 2,
112                                 16,
113                                 48000,
114                                 device->out_config->firewire_syt);
115                 }
116         }
118         return 0;
121 int VDevice1394::close_all()
123         if(device->sharing)
124         {
125                 input_thread = 0;
126                 output_thread = 0;
127                 device->sharing = 0;
128         }
129         else
130         {
131                 if(input_thread)
132                 {
133                         delete input_thread;
134                         input_thread = 0;
135                 }
136                 if(output_thread)
137                 {
138                         delete output_thread;
139                         output_thread = 0;
140                 }
141         }
142         if(user_frame) delete user_frame;
143         initialize();
144         return 0;
148 int VDevice1394::read_buffer(VFrame *frame)
150         unsigned char *data;
151         long size = 0;
152         int result = 0;
153         if(!input_thread) return 1;
155         input_thread->read_video(frame);
157         return result;
161 void VDevice1394::new_output_buffer(VFrame **outputs,
162         int colormodel)
164         if(user_frame)
165         {
166                 if(colormodel != user_frame->get_color_model())
167                 {
168                         delete user_frame;
169                         user_frame = 0;
170                 }
171         }
173         if(!user_frame)
174         {
175                 switch(colormodel)
176                 {
177                         case BC_COMPRESSED:
178                                 user_frame = new VFrame;
179                                 break;
180                         default:
181                                 user_frame = new VFrame(0,
182                                         device->out_w,
183                                         device->out_h,
184                                         colormodel,
185                                         -1);
186                                 break;
187                 }
188         }
189         user_frame->set_shm_offset(0);
190         outputs[0] = user_frame;
193 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
195         output_thread->write_frame(frame[0]);
196         return 0;
202 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
204         return 0;
217 #endif // HAVE_FIREWIRE