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

audio1394.C

Go to the documentation of this file.
00001 #ifdef HAVE_FIREWIRE
00002 
00003 
00004 
00005 
00006 
00007 #include "audio1394.h"
00008 #include "playbackconfig.h"
00009 #include "device1394input.h"
00010 #include "device1394output.h"
00011 #include "iec61883input.h"
00012 #include "iec61883output.h"
00013 #include "preferences.h"
00014 #include "recordconfig.h"
00015 #include "videoconfig.h"
00016 #include "videodevice.h"
00017 
00018 #define SAMPLES_PER_FRAME 2048
00019 
00020 Audio1394::Audio1394(AudioDevice *device)
00021  : AudioLowLevel(device)
00022 {
00023         initialize();
00024 }
00025 
00026 
00027 Audio1394::~Audio1394()
00028 {
00029         close_all();
00030 }
00031 
00032 int Audio1394::initialize()
00033 {
00034         input_thread = 0;
00035         output_thread = 0;
00036         input_iec = 0;
00037         output_iec = 0;
00038 }
00039 
00040 int Audio1394::open_input()
00041 {
00042         int result = 0;
00043         if(!input_thread && !input_iec)
00044         {
00045 // Lock the channels for the DV format
00046                 device->in_channels = 2;
00047                 device->in_bits = 16;
00048                 bytes_per_sample = device->in_channels * device->in_bits / 8;
00049 
00050 
00051                 if(device->driver == AUDIO_DV1394 ||
00052                         device->driver == AUDIO_1394)
00053                 {
00054                         input_thread = new Device1394Input;
00055                         result = input_thread->open(device->in_config->firewire_port, 
00056                                 device->in_config->firewire_channel, 
00057                                 30,
00058                                 device->in_channels,
00059                                 device->in_samplerate,
00060                                 device->in_bits,
00061                                 device->vconfig->w,
00062                                 device->vconfig->h);
00063                 }
00064                 else
00065                 {
00066                         input_iec = new IEC61883Input;
00067                         result = input_iec->open(device->in_config->firewire_port, 
00068                                 device->in_config->firewire_channel, 
00069                                 30,
00070                                 device->in_channels,
00071                                 device->in_samplerate,
00072                                 device->in_bits,
00073                                 device->vconfig->w,
00074                                 device->vconfig->h);
00075                 }
00076 
00077 
00078 
00079 
00080                 if(result)
00081                 {
00082                         delete input_thread;
00083                         input_thread = 0;
00084                         delete input_iec;
00085                         input_iec = 0;
00086                 }
00087         }
00088 
00089         return result;
00090 }
00091 
00092 int Audio1394::open_output()
00093 {
00094         if(!output_thread && !output_iec)
00095         {
00096 // Lock the channels for the DV format
00097                 device->out_channels = 2;
00098                 device->out_bits = 16;
00099                 bytes_per_sample = device->out_channels * device->out_bits / 8;
00100 
00101 
00102                 if(device->driver == AUDIO_DV1394)
00103                 {
00104                         output_thread = new Device1394Output(device);
00105                         output_thread->open(device->out_config->dv1394_path,
00106                                 device->out_config->dv1394_port,
00107                                 device->out_config->dv1394_channel,
00108                                 30,
00109                                 device->out_channels, 
00110                                 device->out_bits, 
00111                                 device->out_samplerate,
00112                                 device->out_config->dv1394_syt);
00113                 }
00114                 else
00115                 if(device->driver == AUDIO_1394)
00116                 {
00117                         output_thread = new Device1394Output(device);
00118                         output_thread->open(device->out_config->firewire_path,
00119                                 device->out_config->firewire_port,
00120                                 device->out_config->firewire_channel,
00121                                 30,
00122                                 device->out_channels, 
00123                                 device->out_bits, 
00124                                 device->out_samplerate,
00125                                 device->out_config->firewire_syt);
00126                 }
00127                 else
00128                 {
00129                         output_iec = new IEC61883Output(device);
00130                         output_iec->open(device->out_config->firewire_port,
00131                                 device->out_config->firewire_channel,
00132                                 30,
00133                                 device->out_channels, 
00134                                 device->out_bits, 
00135                                 device->out_samplerate,
00136                                 device->out_config->firewire_syt);
00137                 }
00138         }
00139 }
00140 
00141 int Audio1394::close_all()
00142 {
00143         if(input_thread)
00144         {
00145                 delete input_thread;
00146         }
00147 
00148         if(output_thread)
00149         {
00150                 delete output_thread;
00151         }
00152         delete input_iec;
00153         delete output_iec;
00154 
00155         initialize();
00156         return 0;
00157 }
00158 
00159 
00160 int Audio1394::read_buffer(char *buffer, int bytes)
00161 {
00162         if(input_thread)
00163         {
00164                 input_thread->read_audio(buffer, bytes / bytes_per_sample);
00165         }
00166         else
00167         if(input_iec)
00168         {
00169                 input_iec->read_audio(buffer, bytes / bytes_per_sample);
00170         }
00171 
00172         return 0;
00173 }
00174 
00175 int Audio1394::write_buffer(char *buffer, int bytes)
00176 {
00177         if(output_thread)
00178                 output_thread->write_samples(buffer, bytes / bytes_per_sample);
00179         else
00180         if(output_iec)
00181                 output_iec->write_samples(buffer, bytes / bytes_per_sample);
00182         return 0;
00183 }
00184 
00185 int64_t Audio1394::device_position()
00186 {
00187         if(output_thread)
00188                 return output_thread->get_audio_position();
00189         else
00190         if(output_iec)
00191                 return output_iec->get_audio_position();
00192         else
00193                 return 0;
00194 }
00195 
00196 
00197 int Audio1394::flush_device()
00198 {
00199         if(output_thread)
00200                 output_thread->flush();
00201         else
00202         if(output_iec)
00203                 output_iec->flush();
00204         return 0;
00205 }
00206 
00207 int Audio1394::interrupt_playback()
00208 {
00209         if(output_thread)
00210                 output_thread->interrupt();
00211         else
00212         if(output_iec)
00213                 output_iec->interrupt();
00214         return 0;
00215 }
00216 
00217 
00218 
00219 #endif

Generated on Sun Jan 8 13:38:50 2006 for Cinelerra-svn by  doxygen 1.4.4