r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / audio1394.C
blobc8c0751e4d379b09464fce44680baa4dceab7576
1 #ifdef HAVE_FIREWIRE
7 #include "audio1394.h"
8 #include "playbackconfig.h"
9 #include "device1394input.h"
10 #include "device1394output.h"
11 #include "preferences.h"
12 #include "recordconfig.h"
13 #include "videoconfig.h"
14 #include "videodevice.h"
16 #define SAMPLES_PER_FRAME 2048
18 Audio1394::Audio1394(AudioDevice *device)
19  : AudioLowLevel(device)
21         initialize();
25 Audio1394::~Audio1394()
27         close_all();
30 int Audio1394::initialize()
32         input_thread = 0;
33         output_thread = 0;
36 int Audio1394::open_input()
38         int result = 0;
39         if(!input_thread)
40         {
41 // Lock the channels for the DV format
42                 device->in_channels = 2;
43                 device->in_bits = 16;
44                 bytes_per_sample = device->in_channels * device->in_bits / 8;
47                 input_thread = new Device1394Input;
48                 result = input_thread->open(device->in_config->firewire_port, 
49                         device->in_config->firewire_channel, 
50                         30,
51                         device->in_channels,
52                         device->in_samplerate,
53                         device->in_bits);
54                 if(result)
55                 {
56                         delete input_thread;
57                         input_thread = 0;
58                 }
59         }
61         return result;
64 int Audio1394::open_output()
66         if(!output_thread)
67         {
68 // Lock the channels for the DV format
69                 device->out_channels = 2;
70                 device->out_bits = 16;
71                 bytes_per_sample = device->out_channels * device->out_bits / 8;
73                 output_thread = new Device1394Output(device);
75                 if(device->driver == AUDIO_DV1394)
76                 {
77                         output_thread->open(device->out_config->dv1394_path,
78                                 device->out_config->dv1394_port,
79                                 device->out_config->dv1394_channel,
80                                 30,
81                                 device->out_channels, 
82                                 device->out_bits, 
83                                 device->out_samplerate,
84                                 device->out_config->dv1394_syt);
85                 }
86                 else
87                 {
88                         output_thread->open(device->out_config->firewire_path,
89                                 device->out_config->firewire_port,
90                                 device->out_config->firewire_channel,
91                                 30,
92                                 device->out_channels, 
93                                 device->out_bits, 
94                                 device->out_samplerate,
95                                 device->out_config->firewire_syt);
96                 }
97         }
100 int Audio1394::close_all()
102         if(input_thread)
103         {
104                 delete input_thread;
105         }
107         if(output_thread)
108         {
109                 delete output_thread;
110         }
112         initialize();
113         return 0;
117 int Audio1394::read_buffer(char *buffer, int bytes)
119         if(input_thread)
120         {
121                 input_thread->read_audio(buffer, bytes / bytes_per_sample);
122         }
124         return 0;
127 int Audio1394::write_buffer(char *buffer, int bytes)
129         if(output_thread)
130                 output_thread->write_samples(buffer, bytes / bytes_per_sample);
131         return 0;
134 int64_t Audio1394::device_position()
136         if(output_thread)
137                 return output_thread->get_audio_position();
138         else
139                 return 0;
143 int Audio1394::flush_device()
145         if(output_thread)
146                 output_thread->flush();
147         return 0;
150 int Audio1394::interrupt_playback()
152         if(output_thread)
153                 output_thread->interrupt();
154         return 0;
159 #endif