prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / audio1394.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifdef HAVE_FIREWIRE
23
24
25
26
27
28 #include "audio1394.h"
29 #include "playbackconfig.h"
30 #include "device1394input.h"
31 #include "device1394output.h"
32 #include "iec61883input.h"
33 #include "iec61883output.h"
34 #include "preferences.h"
35 #include "recordconfig.h"
36 #include "videoconfig.h"
37 #include "videodevice.h"
38
39 #define SAMPLES_PER_FRAME 2048
40
41 Audio1394::Audio1394(AudioDevice *device)
42  : AudioLowLevel(device)
43 {
44         initialize();
45 }
46
47
48 Audio1394::~Audio1394()
49 {
50         close_all();
51 }
52
53 int Audio1394::initialize()
54 {
55         input_thread = 0;
56         output_thread = 0;
57         input_iec = 0;
58         output_iec = 0;
59         return 0;
60 }
61
62 int Audio1394::open_input()
63 {
64         int result = 0;
65         if(!input_thread && !input_iec)
66         {
67 // Lock the channels for the DV format
68                 device->in_channels = 2;
69                 device->in_bits = 16;
70                 bytes_per_sample = device->in_channels * device->in_bits / 8;
71
72
73                 if(device->idriver == AUDIO_DV1394 ||
74                         device->idriver == AUDIO_1394)
75                 {
76                         input_thread = new Device1394Input;
77                         result = input_thread->open(device->in_config->firewire_port, 
78                                 device->in_config->firewire_channel, 
79                                 30,
80                                 device->in_channels,
81                                 device->in_samplerate,
82                                 device->in_bits,
83                                 device->vconfig->w,
84                                 device->vconfig->h);
85                 }
86                 else
87                 {
88                         input_iec = new IEC61883Input;
89                         result = input_iec->open(device->in_config->firewire_port, 
90                                 device->in_config->firewire_channel, 
91                                 30,
92                                 device->in_channels,
93                                 device->in_samplerate,
94                                 device->in_bits,
95                                 device->vconfig->w,
96                                 device->vconfig->h);
97                 }
98
99
100
101
102                 if(result)
103                 {
104                         delete input_thread;
105                         input_thread = 0;
106                         delete input_iec;
107                         input_iec = 0;
108                 }
109         }
110
111         return result;
112 }
113
114 int Audio1394::open_output()
115 {
116         if(!output_thread && !output_iec)
117         {
118 // Lock the channels for the DV format
119                 device->out_channels = 2;
120                 device->out_bits = 16;
121                 bytes_per_sample = device->out_channels * device->out_bits / 8;
122
123
124                 if(device->odriver == AUDIO_DV1394)
125                 {
126                         output_thread = new Device1394Output(device);
127                         output_thread->open(device->out_config->dv1394_path,
128                                 device->out_config->dv1394_port,
129                                 device->out_config->dv1394_channel,
130                                 30,
131                                 device->out_channels, 
132                                 device->out_bits, 
133                                 device->out_samplerate,
134                                 device->out_config->dv1394_syt);
135                 }
136                 else
137                 if(device->odriver == AUDIO_1394)
138                 {
139                         output_thread = new Device1394Output(device);
140                         output_thread->open(device->out_config->firewire_path,
141                                 device->out_config->firewire_port,
142                                 device->out_config->firewire_channel,
143                                 30,
144                                 device->out_channels, 
145                                 device->out_bits, 
146                                 device->out_samplerate,
147                                 device->out_config->firewire_syt);
148                 }
149                 else
150                 {
151                         output_iec = new IEC61883Output(device);
152                         output_iec->open(device->out_config->firewire_port,
153                                 device->out_config->firewire_channel,
154                                 30,
155                                 device->out_channels, 
156                                 device->out_bits, 
157                                 device->out_samplerate,
158                                 device->out_config->firewire_syt);
159                 }
160         }
161         return 0;
162 }
163
164 int Audio1394::close_all()
165 {
166         if(input_thread)
167         {
168                 delete input_thread;
169         }
170
171         if(output_thread)
172         {
173                 delete output_thread;
174         }
175         delete input_iec;
176         delete output_iec;
177
178         initialize();
179         return 0;
180 }
181
182
183 int Audio1394::read_buffer(char *buffer, int bytes)
184 {
185         if(input_thread)
186         {
187                 input_thread->read_audio(buffer, bytes / bytes_per_sample);
188         }
189         else
190         if(input_iec)
191         {
192                 input_iec->read_audio(buffer, bytes / bytes_per_sample);
193         }
194
195         return 0;
196 }
197
198 int Audio1394::write_buffer(char *buffer, int bytes)
199 {
200         if(output_thread)
201                 output_thread->write_samples(buffer, bytes / bytes_per_sample);
202         else
203         if(output_iec)
204                 output_iec->write_samples(buffer, bytes / bytes_per_sample);
205         return 0;
206 }
207
208 int64_t Audio1394::device_position()
209 {
210         if(output_thread)
211                 return output_thread->get_audio_position();
212         else
213         if(output_iec)
214                 return output_iec->get_audio_position();
215         else
216                 return 0;
217 }
218
219
220 int Audio1394::flush_device()
221 {
222         if(output_thread)
223                 output_thread->flush();
224         else
225         if(output_iec)
226                 output_iec->flush();
227         return 0;
228 }
229
230 int Audio1394::interrupt_playback()
231 {
232         if(output_thread)
233                 output_thread->interrupt();
234         else
235         if(output_iec)
236                 output_iec->interrupt();
237         return 0;
238 }
239
240
241
242 #endif