Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vdevice1394.C

Go to the documentation of this file.
00001 #include "assets.h"
00002 #include "audio1394.h"
00003 #include "audioconfig.h"
00004 #include "audiodevice.h"
00005 #include "device1394input.h"
00006 #include "device1394output.h"
00007 #include "iec61883input.h"
00008 #include "iec61883output.h"
00009 #include "file.inc"
00010 #include "preferences.h"
00011 #include "recordconfig.h"
00012 #include "vdevice1394.h"
00013 #include "vframe.h"
00014 #include "playbackconfig.h"
00015 #include "videodevice.h"
00016 
00017 
00018 #ifdef HAVE_FIREWIRE
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 VDevice1394::VDevice1394(VideoDevice *device)
00028  : VDeviceBase(device)
00029 {
00030         initialize();
00031 }
00032 
00033 VDevice1394::~VDevice1394()
00034 {
00035         close_all();
00036 }
00037 
00038 int VDevice1394::initialize()
00039 {
00040         input_thread = 0;
00041         output_thread = 0;
00042         input_iec = 0;
00043         output_iec = 0;
00044         user_frame = 0;
00045 }
00046 
00047 int VDevice1394::open_input()
00048 {
00049 // Share audio driver.  The audio driver does the capturing in this case
00050 // and fills video frames for us.
00051         int result = 0;
00052         if(device->adevice &&
00053                 (device->adevice->in_config->driver == AUDIO_1394 ||
00054                         device->adevice->in_config->driver == AUDIO_DV1394 ||
00055                         device->adevice->in_config->driver == AUDIO_IEC61883))
00056         {
00057                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_in();
00058                 input_thread = low_level->input_thread;
00059                 input_iec = low_level->input_iec;
00060                 device->sharing = 1;
00061         }
00062         else
00063         if(!input_thread && !input_iec)
00064         {
00065                 if(device->in_config->driver == CAPTURE_FIREWIRE)
00066                 {
00067                         input_thread = new Device1394Input;
00068                         result = input_thread->open(device->in_config->firewire_port, 
00069                                 device->in_config->firewire_channel, 
00070                                 device->in_config->capture_length,
00071                                 2,
00072                                 48000,
00073                                 16,
00074                                 device->in_config->w,
00075                                 device->in_config->h);
00076                         if(result)
00077                         {
00078                                 delete input_thread;
00079                                 input_thread = 0;
00080                         }
00081                 }
00082                 else
00083                 {
00084                         input_iec = new IEC61883Input;
00085                         result = input_iec->open(device->in_config->firewire_port, 
00086                                 device->in_config->firewire_channel, 
00087                                 device->in_config->capture_length,
00088                                 2,
00089                                 48000,
00090                                 16,
00091                                 device->in_config->w,
00092                                 device->in_config->h);
00093                         if(result)
00094                         {
00095                                 delete input_iec;
00096                                 input_iec = 0;
00097                         }
00098                 }
00099         }
00100         return result;
00101 }
00102 
00103 int VDevice1394::open_output()
00104 {
00105 // Share audio driver.  The audio driver takes DV frames from us and
00106 // inserts audio.
00107         if(device->adevice &&
00108                 (device->adevice->out_config->driver == AUDIO_1394 ||
00109                         device->adevice->out_config->driver == AUDIO_DV1394 ||
00110                         device->adevice->out_config->driver == AUDIO_IEC61883))
00111         {
00112                 Audio1394 *low_level = (Audio1394*)device->adevice->get_lowlevel_out();
00113                 output_thread = low_level->output_thread;
00114                 output_iec = low_level->output_iec;
00115                 device->sharing = 1;
00116         }
00117         else
00118         if(!output_thread && !output_iec)
00119         {
00120                 if(device->out_config->driver == PLAYBACK_DV1394)
00121                 {
00122                         output_thread = new Device1394Output(device);
00123                         output_thread->open(device->out_config->dv1394_path,
00124                                 device->out_config->dv1394_port, 
00125                                 device->out_config->dv1394_channel,
00126                                 30,
00127                                 2,
00128                                 16,
00129                                 48000,
00130                                 device->out_config->dv1394_syt);
00131                 }
00132                 else
00133                 if(device->out_config->driver == PLAYBACK_FIREWIRE)
00134                 {
00135                         output_thread = new Device1394Output(device);
00136                         output_thread->open(device->out_config->firewire_path,
00137                                 device->out_config->firewire_port, 
00138                                 device->out_config->firewire_channel,
00139                                 30,
00140                                 2,
00141                                 16,
00142                                 48000,
00143                                 device->out_config->firewire_syt);
00144                 }
00145                 else
00146                 {
00147                         output_iec = new IEC61883Output(device);
00148                         output_iec->open(device->out_config->firewire_port, 
00149                                 device->out_config->firewire_channel,
00150                                 30,
00151                                 2,
00152                                 16,
00153                                 48000,
00154                                 device->out_config->firewire_syt);
00155                 }
00156         }
00157 
00158         return 0;
00159 }
00160 
00161 int VDevice1394::close_all()
00162 {
00163         if(device->sharing)
00164         {
00165                 input_thread = 0;
00166                 output_thread = 0;
00167                 output_iec = 0;
00168                 input_iec = 0;
00169                 device->sharing = 0;
00170         }
00171         else
00172         {
00173                 if(input_thread)
00174                 {
00175                         delete input_thread;
00176                         input_thread = 0;
00177                 }
00178                 if(output_thread)
00179                 {
00180                         delete output_thread;
00181                         output_thread = 0;
00182                 }
00183                 if(input_iec)
00184                 {
00185                         delete input_iec;
00186                         input_iec = 0;
00187                 }
00188                 if(output_iec)
00189                 {
00190                         delete output_iec;
00191                         output_iec = 0;
00192                 }
00193         }
00194         if(user_frame) delete user_frame;
00195         initialize();
00196         return 0;
00197 }
00198 
00199 
00200 int VDevice1394::read_buffer(VFrame *frame)
00201 {
00202         unsigned char *data;
00203         long size = 0;
00204         int result = 0;
00205         if(!input_thread && !input_iec) return 1;
00206 
00207         if(input_thread) input_thread->read_video(frame);
00208         else
00209         if(input_iec) input_iec->read_video(frame);
00210 
00211         return result;
00212 }
00213 
00214 
00215 void VDevice1394::new_output_buffer(VFrame **outputs,
00216         int colormodel)
00217 {
00218         if(user_frame)
00219         {
00220                 if(colormodel != user_frame->get_color_model())
00221                 {
00222                         delete user_frame;
00223                         user_frame = 0;
00224                 }
00225         }
00226 
00227         if(!user_frame)
00228         {
00229                 switch(colormodel)
00230                 {
00231                         case BC_COMPRESSED:
00232                                 user_frame = new VFrame;
00233                                 break;
00234                         default:
00235                                 user_frame = new VFrame(0,
00236                                         device->out_w,
00237                                         device->out_h,
00238                                         colormodel,
00239                                         -1);
00240                                 break;
00241                 }
00242         }
00243         user_frame->set_shm_offset(0);
00244         outputs[0] = user_frame;
00245 }
00246 
00247 int VDevice1394::write_buffer(VFrame **frame, EDL *edl)
00248 {
00249         if(output_thread) output_thread->write_frame(frame[0]);
00250         else
00251         if(output_iec) output_iec->write_frame(frame[0]);
00252         return 0;
00253 }
00254 
00255 
00256 
00257 
00258 int VDevice1394::can_copy_from(Asset *asset, int output_w, int output_h)
00259 {
00260         return 0;
00261 }
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 #endif // HAVE_FIREWIRE

Generated on Sun Jan 8 13:39:01 2006 for Cinelerra-svn by  doxygen 1.4.4