r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vdevice1394.C
blob0461d870ca8169134467b6374a62fb5f11903657
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                         device->out_config->firewire_use_dv1394);
99         }
101         return 0;
104 int VDevice1394::close_all()
106         if(device->sharing)
107         {
108                 input_thread = 0;
109                 output_thread = 0;
110                 device->sharing = 0;
111         }
112         else
113         {
114                 if(input_thread)
115                 {
116                         delete input_thread;
117                         input_thread = 0;
118                 }
119                 if(output_thread)
120                 {
121                         delete output_thread;
122                         output_thread = 0;
123                 }
124         }
125         if(user_frame) delete user_frame;
126         initialize();
127         return 0;
131 int VDevice1394::read_buffer(VFrame *frame)
133         unsigned char *data;
134         long size = 0;
135         int result = 0;
136         if(!input_thread) return 1;
138         input_thread->read_video(frame);
140         return result;
144 void VDevice1394::new_output_buffer(VFrame **outputs,
145         int colormodel)
147         if(user_frame)
148         {
149                 if(colormodel != user_frame->get_color_model())
150                 {
151                         delete user_frame;
152                         user_frame = 0;
153                 }
154         }
156         if(!user_frame)
157         {
158                 switch(colormodel)
159                 {
160                         case BC_COMPRESSED:
161                                 user_frame = new VFrame;
162                                 break;
163                         default:
164                                 user_frame = new VFrame(0,
165                                         device->out_w,
166                                         device->out_h,
167                                         colormodel,
168                                         -1);
169                                 break;
170                 }
171         }
172         user_frame->set_shm_offset(0);
173         outputs[0] = user_frame;
176 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
178         output_thread->write_frame(frame[0]);
179         return 0;
185 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
187         return 0;
200 #endif // HAVE_FIREWIRE