r121: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vdevice1394.C
blobb343b7b0aea4c475baa9c489bd1640f0940395d9
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         {
52                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_in();
53                 input_thread = low_level->input_thread;
54                 device->sharing = 1;
55         }
56         else
57         if(!input_thread)
58         {
59                 input_thread = new Device1394Input;
60                 result = input_thread->open(device->in_config->firewire_port, 
61                         device->in_config->firewire_channel, 
62                         device->in_config->capture_length,
63                         2,
64                         48000,
65                         16);
66                 if(result)
67                 {
68                         delete input_thread;
69                         input_thread = 0;
70                 }
71         }
72         return result;
75 int VDevice1394::open_output()
77 // Share audio driver.  The audio driver takes DV frames from us and
78 // inserts audio.
79         if(device->adevice &&
80                 device->adevice->out_config->driver == AUDIO_1394)
81         {
82                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
83                 output_thread = low_level->output_thread;
84                 device->sharing = 1;
85         }
86         else
87         if(!output_thread)
88         {
89                 output_thread = new Device1394Output;
90                 output_thread->open(device->out_config->firewire_path,
91                         device->out_config->firewire_port, 
92                         device->out_config->firewire_channel,
93                         30,
94                         2,
95                         16,
96                         48000,
97                         device->out_config->firewire_syt);
98         }
100         return 0;
103 int VDevice1394::close_all()
105         if(device->sharing)
106         {
107                 input_thread = 0;
108                 output_thread = 0;
109                 device->sharing = 0;
110         }
111         else
112         {
113                 if(input_thread)
114                 {
115                         delete input_thread;
116                         input_thread = 0;
117                 }
118                 if(output_thread)
119                 {
120                         delete output_thread;
121                         output_thread = 0;
122                 }
123         }
124         if(user_frame) delete user_frame;
125         initialize();
126         return 0;
130 int VDevice1394::read_buffer(VFrame *frame)
132         unsigned char *data;
133         long size = 0;
134         int result = 0;
135         if(!input_thread) return 1;
137         input_thread->read_video(frame);
139         return result;
143 void VDevice1394::new_output_buffer(VFrame **outputs,
144         int colormodel)
146         if(user_frame)
147         {
148                 if(colormodel != user_frame->get_color_model())
149                 {
150                         delete user_frame;
151                         user_frame = 0;
152                 }
153         }
155         if(!user_frame)
156         {
157                 switch(colormodel)
158                 {
159                         case BC_COMPRESSED:
160                                 user_frame = new VFrame;
161                                 break;
162                         default:
163                                 user_frame = new VFrame(0,
164                                         device->out_w,
165                                         device->out_h,
166                                         colormodel,
167                                         -1);
168                                 break;
169                 }
170         }
171         user_frame->set_shm_offset(0);
172         outputs[0] = user_frame;
175 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
177         output_thread->write_frame(frame[0]);
178         return 0;
184 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
186         return 0;
199 #endif // HAVE_FIREWIRE