author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Fri, 16 Apr 2010 11:39:52 +0300 | |
branch | RCL_3 |
changeset 8 | 740e5562c97f |
parent 7 | 3f74d0d4af4c |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtMultimedia module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
// |
|
43 |
// W A R N I N G |
|
44 |
// ------------- |
|
45 |
// |
|
46 |
// This file is not part of the Qt API. It exists for the convenience |
|
47 |
// of other Qt classes. This header file may change from version to |
|
48 |
// version without notice, or even be removed. |
|
49 |
// |
|
50 |
// We mean it. |
|
51 |
// |
|
52 |
||
53 |
#include <QtCore/qcoreapplication.h> |
|
54 |
#include "qaudioinput_alsa_p.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
#include "qaudiodeviceinfo_alsa_p.h" |
0 | 56 |
|
57 |
QT_BEGIN_NAMESPACE |
|
58 |
||
59 |
//#define DEBUG_AUDIO 1 |
|
60 |
||
61 |
static const int minimumIntervalTime = 50; |
|
62 |
||
63 |
QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): |
|
64 |
settings(audioFormat) |
|
65 |
{ |
|
66 |
bytesAvailable = 0; |
|
67 |
handle = 0; |
|
68 |
ahandler = 0; |
|
69 |
access = SND_PCM_ACCESS_RW_INTERLEAVED; |
|
70 |
pcmformat = SND_PCM_FORMAT_S16; |
|
71 |
buffer_size = 0; |
|
72 |
period_size = 0; |
|
73 |
buffer_time = 100000; |
|
74 |
period_time = 20000; |
|
75 |
totalTimeValue = 0; |
|
76 |
intervalTime = 1000; |
|
77 |
audioBuffer = 0; |
|
78 |
errorState = QAudio::NoError; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
deviceState = QAudio::StoppedState; |
0 | 80 |
audioSource = 0; |
81 |
pullMode = true; |
|
82 |
resuming = false; |
|
83 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
m_device = device; |
0 | 85 |
|
86 |
timer = new QTimer(this); |
|
87 |
connect(timer,SIGNAL(timeout()),SLOT(userFeed())); |
|
88 |
} |
|
89 |
||
90 |
QAudioInputPrivate::~QAudioInputPrivate() |
|
91 |
{ |
|
92 |
close(); |
|
93 |
disconnect(timer, SIGNAL(timeout())); |
|
94 |
QCoreApplication::processEvents(); |
|
95 |
delete timer; |
|
96 |
} |
|
97 |
||
98 |
QAudio::Error QAudioInputPrivate::error() const |
|
99 |
{ |
|
100 |
return errorState; |
|
101 |
} |
|
102 |
||
103 |
QAudio::State QAudioInputPrivate::state() const |
|
104 |
{ |
|
105 |
return deviceState; |
|
106 |
} |
|
107 |
||
108 |
||
109 |
QAudioFormat QAudioInputPrivate::format() const |
|
110 |
{ |
|
111 |
return settings; |
|
112 |
} |
|
113 |
||
114 |
int QAudioInputPrivate::xrun_recovery(int err) |
|
115 |
{ |
|
116 |
int count = 0; |
|
117 |
bool reset = false; |
|
118 |
||
119 |
if(err == -EPIPE) { |
|
120 |
errorState = QAudio::UnderrunError; |
|
121 |
err = snd_pcm_prepare(handle); |
|
122 |
if(err < 0) |
|
123 |
reset = true; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
124 |
else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
125 |
bytesAvailable = bytesReady(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
126 |
if (bytesAvailable <= 0) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
127 |
reset = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
128 |
} |
0 | 129 |
|
130 |
} else if((err == -ESTRPIPE)||(err == -EIO)) { |
|
131 |
errorState = QAudio::IOError; |
|
132 |
while((err = snd_pcm_resume(handle)) == -EAGAIN){ |
|
133 |
usleep(100); |
|
134 |
count++; |
|
135 |
if(count > 5) { |
|
136 |
reset = true; |
|
137 |
break; |
|
138 |
} |
|
139 |
} |
|
140 |
if(err < 0) { |
|
141 |
err = snd_pcm_prepare(handle); |
|
142 |
if(err < 0) |
|
143 |
reset = true; |
|
144 |
} |
|
145 |
} |
|
146 |
if(reset) { |
|
147 |
close(); |
|
148 |
open(); |
|
149 |
snd_pcm_prepare(handle); |
|
150 |
return 0; |
|
151 |
} |
|
152 |
return err; |
|
153 |
} |
|
154 |
||
155 |
int QAudioInputPrivate::setFormat() |
|
156 |
{ |
|
157 |
snd_pcm_format_t format = SND_PCM_FORMAT_S16; |
|
158 |
||
159 |
if(settings.sampleSize() == 8) { |
|
160 |
format = SND_PCM_FORMAT_U8; |
|
161 |
} else if(settings.sampleSize() == 16) { |
|
162 |
if(settings.sampleType() == QAudioFormat::SignedInt) { |
|
163 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
164 |
format = SND_PCM_FORMAT_S16_LE; |
|
165 |
else |
|
166 |
format = SND_PCM_FORMAT_S16_BE; |
|
167 |
} else if(settings.sampleType() == QAudioFormat::UnSignedInt) { |
|
168 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
169 |
format = SND_PCM_FORMAT_U16_LE; |
|
170 |
else |
|
171 |
format = SND_PCM_FORMAT_U16_BE; |
|
172 |
} |
|
173 |
} else if(settings.sampleSize() == 24) { |
|
174 |
if(settings.sampleType() == QAudioFormat::SignedInt) { |
|
175 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
176 |
format = SND_PCM_FORMAT_S24_LE; |
|
177 |
else |
|
178 |
format = SND_PCM_FORMAT_S24_BE; |
|
179 |
} else if(settings.sampleType() == QAudioFormat::UnSignedInt) { |
|
180 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
181 |
format = SND_PCM_FORMAT_U24_LE; |
|
182 |
else |
|
183 |
format = SND_PCM_FORMAT_U24_BE; |
|
184 |
} |
|
185 |
} else if(settings.sampleSize() == 32) { |
|
186 |
if(settings.sampleType() == QAudioFormat::SignedInt) { |
|
187 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
188 |
format = SND_PCM_FORMAT_S32_LE; |
|
189 |
else |
|
190 |
format = SND_PCM_FORMAT_S32_BE; |
|
191 |
} else if(settings.sampleType() == QAudioFormat::UnSignedInt) { |
|
192 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
193 |
format = SND_PCM_FORMAT_U32_LE; |
|
194 |
else |
|
195 |
format = SND_PCM_FORMAT_U32_BE; |
|
196 |
} else if(settings.sampleType() == QAudioFormat::Float) { |
|
197 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
198 |
format = SND_PCM_FORMAT_FLOAT_LE; |
|
199 |
else |
|
200 |
format = SND_PCM_FORMAT_FLOAT_BE; |
|
201 |
} |
|
202 |
} else if(settings.sampleSize() == 64) { |
|
203 |
if(settings.byteOrder() == QAudioFormat::LittleEndian) |
|
204 |
format = SND_PCM_FORMAT_FLOAT64_LE; |
|
205 |
else |
|
206 |
format = SND_PCM_FORMAT_FLOAT64_BE; |
|
207 |
} |
|
208 |
||
209 |
return snd_pcm_hw_params_set_format( handle, hwparams, format); |
|
210 |
} |
|
211 |
||
212 |
QIODevice* QAudioInputPrivate::start(QIODevice* device) |
|
213 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
if(deviceState != QAudio::StoppedState) |
0 | 215 |
close(); |
216 |
||
217 |
if(!pullMode && audioSource) { |
|
218 |
delete audioSource; |
|
219 |
} |
|
220 |
||
221 |
if(device) { |
|
222 |
//set to pull mode |
|
223 |
pullMode = true; |
|
224 |
audioSource = device; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
225 |
deviceState = QAudio::ActiveState; |
0 | 226 |
} else { |
227 |
//set to push mode |
|
228 |
pullMode = false; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
229 |
deviceState = QAudio::IdleState; |
0 | 230 |
audioSource = new InputPrivate(this); |
231 |
audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); |
|
232 |
} |
|
233 |
||
234 |
if( !open() ) |
|
235 |
return 0; |
|
236 |
||
237 |
emit stateChanged(deviceState); |
|
238 |
||
239 |
return audioSource; |
|
240 |
} |
|
241 |
||
242 |
void QAudioInputPrivate::stop() |
|
243 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
if(deviceState == QAudio::StoppedState) |
0 | 245 |
return; |
246 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
deviceState = QAudio::StoppedState; |
0 | 248 |
|
249 |
close(); |
|
250 |
emit stateChanged(deviceState); |
|
251 |
} |
|
252 |
||
253 |
bool QAudioInputPrivate::open() |
|
254 |
{ |
|
255 |
#ifdef DEBUG_AUDIO |
|
256 |
QTime now(QTime::currentTime()); |
|
257 |
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()"; |
|
258 |
#endif |
|
259 |
clockStamp.restart(); |
|
260 |
timeStamp.restart(); |
|
261 |
elapsedTimeOffset = 0; |
|
262 |
||
263 |
int dir; |
|
264 |
int err=-1; |
|
265 |
int count=0; |
|
266 |
unsigned int freakuency=settings.frequency(); |
|
267 |
||
268 |
QString dev = QString(QLatin1String(m_device.constData())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
if(dev.compare(QLatin1String("default")) == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
dev = QLatin1String(devices.first()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
dev = QLatin1String("hw:0,0"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
dev = QLatin1String(m_device); |
0 | 279 |
#else |
280 |
int idx = 0; |
|
281 |
char *name; |
|
282 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
|
0 | 285 |
while(snd_card_get_name(idx,&name) == 0) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) |
0 | 287 |
break; |
288 |
idx++; |
|
289 |
} |
|
290 |
dev = QString(QLatin1String("hw:%1,0")).arg(idx); |
|
291 |
#endif |
|
292 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
|
0 | 294 |
// Step 1: try and open the device |
295 |
while((count < 5) && (err < 0)) { |
|
296 |
err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); |
|
297 |
if(err < 0) |
|
298 |
count++; |
|
299 |
} |
|
300 |
if (( err < 0)||(handle == 0)) { |
|
301 |
errorState = QAudio::OpenError; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
deviceState = QAudio::StoppedState; |
0 | 303 |
emit stateChanged(deviceState); |
304 |
return false; |
|
305 |
} |
|
306 |
snd_pcm_nonblock( handle, 0 ); |
|
307 |
||
308 |
// Step 2: Set the desired HW parameters. |
|
309 |
snd_pcm_hw_params_alloca( &hwparams ); |
|
310 |
||
311 |
bool fatal = false; |
|
312 |
QString errMessage; |
|
313 |
unsigned int chunks = 8; |
|
314 |
||
315 |
err = snd_pcm_hw_params_any( handle, hwparams ); |
|
316 |
if ( err < 0 ) { |
|
317 |
fatal = true; |
|
318 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err); |
|
319 |
} |
|
320 |
if ( !fatal ) { |
|
321 |
err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); |
|
322 |
if ( err < 0 ) { |
|
323 |
fatal = true; |
|
324 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); |
|
325 |
} |
|
326 |
} |
|
327 |
if ( !fatal ) { |
|
328 |
err = snd_pcm_hw_params_set_access( handle, hwparams, access ); |
|
329 |
if ( err < 0 ) { |
|
330 |
fatal = true; |
|
331 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err); |
|
332 |
} |
|
333 |
} |
|
334 |
if ( !fatal ) { |
|
335 |
err = setFormat(); |
|
336 |
if ( err < 0 ) { |
|
337 |
fatal = true; |
|
338 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err); |
|
339 |
} |
|
340 |
} |
|
341 |
if ( !fatal ) { |
|
342 |
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); |
|
343 |
if ( err < 0 ) { |
|
344 |
fatal = true; |
|
345 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err); |
|
346 |
} |
|
347 |
} |
|
348 |
if ( !fatal ) { |
|
349 |
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); |
|
350 |
if ( err < 0 ) { |
|
351 |
fatal = true; |
|
352 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); |
|
353 |
} |
|
354 |
} |
|
355 |
if ( !fatal ) { |
|
356 |
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir); |
|
357 |
if ( err < 0 ) { |
|
358 |
fatal = true; |
|
359 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err); |
|
360 |
} |
|
361 |
} |
|
362 |
if ( !fatal ) { |
|
363 |
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir); |
|
364 |
if ( err < 0 ) { |
|
365 |
fatal = true; |
|
366 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err); |
|
367 |
} |
|
368 |
} |
|
369 |
if ( !fatal ) { |
|
370 |
err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir); |
|
371 |
if ( err < 0 ) { |
|
372 |
fatal = true; |
|
373 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err); |
|
374 |
} |
|
375 |
} |
|
376 |
if ( !fatal ) { |
|
377 |
err = snd_pcm_hw_params(handle, hwparams); |
|
378 |
if ( err < 0 ) { |
|
379 |
fatal = true; |
|
380 |
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err); |
|
381 |
} |
|
382 |
} |
|
383 |
if( err < 0) { |
|
384 |
qWarning()<<errMessage; |
|
385 |
errorState = QAudio::OpenError; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
deviceState = QAudio::StoppedState; |
0 | 387 |
emit stateChanged(deviceState); |
388 |
return false; |
|
389 |
} |
|
390 |
snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames); |
|
391 |
buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames); |
|
392 |
snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir); |
|
393 |
period_size = snd_pcm_frames_to_bytes(handle,period_frames); |
|
394 |
snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir); |
|
395 |
snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir); |
|
396 |
||
397 |
// Step 3: Set the desired SW parameters. |
|
398 |
snd_pcm_sw_params_t *swparams; |
|
399 |
snd_pcm_sw_params_alloca(&swparams); |
|
400 |
snd_pcm_sw_params_current(handle, swparams); |
|
401 |
snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames); |
|
402 |
snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames); |
|
403 |
snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames); |
|
404 |
snd_pcm_sw_params(handle, swparams); |
|
405 |
||
406 |
// Step 4: Prepare audio |
|
407 |
if(audioBuffer == 0) |
|
408 |
audioBuffer = new char[buffer_size]; |
|
409 |
snd_pcm_prepare( handle ); |
|
410 |
snd_pcm_start(handle); |
|
411 |
||
412 |
// Step 5: Setup timer |
|
413 |
bytesAvailable = bytesReady(); |
|
414 |
||
415 |
if(pullMode) |
|
416 |
connect(audioSource,SIGNAL(readyRead()),this,SLOT(userFeed())); |
|
417 |
||
418 |
// Step 6: Start audio processing |
|
419 |
chunks = buffer_size/period_size; |
|
420 |
timer->start(period_time*chunks/2000); |
|
421 |
||
422 |
errorState = QAudio::NoError; |
|
423 |
||
424 |
totalTimeValue = 0; |
|
425 |
||
426 |
return true; |
|
427 |
} |
|
428 |
||
429 |
void QAudioInputPrivate::close() |
|
430 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
deviceState = QAudio::StoppedState; |
0 | 432 |
timer->stop(); |
433 |
||
434 |
if ( handle ) { |
|
435 |
snd_pcm_drop( handle ); |
|
436 |
snd_pcm_close( handle ); |
|
437 |
handle = 0; |
|
438 |
delete [] audioBuffer; |
|
439 |
audioBuffer=0; |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
int QAudioInputPrivate::bytesReady() const |
|
444 |
{ |
|
445 |
if(resuming) |
|
446 |
return period_size; |
|
447 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
448 |
if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) |
0 | 449 |
return 0; |
450 |
int frames = snd_pcm_avail_update(handle); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
451 |
if (frames < 0) return frames; |
0 | 452 |
if((int)frames > (int)buffer_frames) |
453 |
frames = buffer_frames; |
|
454 |
||
455 |
return snd_pcm_frames_to_bytes(handle, frames); |
|
456 |
} |
|
457 |
||
458 |
qint64 QAudioInputPrivate::read(char* data, qint64 len) |
|
459 |
{ |
|
460 |
Q_UNUSED(len) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
461 |
|
0 | 462 |
// Read in some audio data and write it to QIODevice, pull mode |
463 |
if ( !handle ) |
|
464 |
return 0; |
|
465 |
||
466 |
bytesAvailable = bytesReady(); |
|
467 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
468 |
if (bytesAvailable < 0) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
469 |
// bytesAvailable as negative is error code, try to recover from it. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
470 |
xrun_recovery(bytesAvailable); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
471 |
bytesAvailable = bytesReady(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
472 |
if (bytesAvailable < 0) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
473 |
// recovery failed must stop and set error. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
474 |
close(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
475 |
errorState = QAudio::IOError; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
476 |
deviceState = QAudio::StoppedState; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
477 |
emit stateChanged(deviceState); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
478 |
return 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
479 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
480 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
481 |
|
0 | 482 |
int count=0, err = 0; |
483 |
while(count < 5) { |
|
484 |
int chunks = bytesAvailable/period_size; |
|
485 |
int frames = chunks*period_frames; |
|
486 |
if(frames > (int)buffer_frames) |
|
487 |
frames = buffer_frames; |
|
488 |
int readFrames = snd_pcm_readi(handle, audioBuffer, frames); |
|
489 |
if (readFrames >= 0) { |
|
490 |
err = snd_pcm_frames_to_bytes(handle, readFrames); |
|
491 |
#ifdef DEBUG_AUDIO |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
492 |
qDebug()<<QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(err).arg(readFrames).toLatin1().constData(); |
0 | 493 |
#endif |
494 |
break; |
|
495 |
} else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) { |
|
496 |
errorState = QAudio::IOError; |
|
497 |
err = 0; |
|
498 |
break; |
|
499 |
} else { |
|
500 |
if(readFrames == -EPIPE) { |
|
501 |
errorState = QAudio::UnderrunError; |
|
502 |
err = snd_pcm_prepare(handle); |
|
503 |
} else if(readFrames == -ESTRPIPE) { |
|
504 |
err = snd_pcm_prepare(handle); |
|
505 |
} |
|
506 |
if(err != 0) break; |
|
507 |
} |
|
508 |
count++; |
|
509 |
} |
|
510 |
if(err > 0) { |
|
511 |
// got some send it onward |
|
512 |
#ifdef DEBUG_AUDIO |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
513 |
qDebug()<<"frames to write to QIODevice = "<< |
0 | 514 |
snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<<err<<") bytes"; |
515 |
#endif |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
516 |
if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) |
0 | 517 |
return 0; |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
518 |
if (pullMode) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
519 |
qint64 l = audioSource->write(audioBuffer,err); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
520 |
if(l < 0) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
521 |
close(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
522 |
errorState = QAudio::IOError; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
523 |
deviceState = QAudio::StoppedState; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
524 |
emit stateChanged(deviceState); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
525 |
} else if(l == 0) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
526 |
if (deviceState != QAudio::IdleState) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
527 |
errorState = QAudio::NoError; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
528 |
deviceState = QAudio::IdleState; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
529 |
emit stateChanged(deviceState); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
530 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
531 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
532 |
totalTimeValue += err; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
533 |
resuming = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
534 |
if (deviceState != QAudio::ActiveState) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
535 |
errorState = QAudio::NoError; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
536 |
deviceState = QAudio::ActiveState; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
537 |
emit stateChanged(deviceState); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
538 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
539 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
540 |
return l; |
0 | 541 |
|
542 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
543 |
memcpy(data,audioBuffer,err); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
544 |
totalTimeValue += err; |
0 | 545 |
resuming = false; |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
546 |
if (deviceState != QAudio::ActiveState) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
547 |
errorState = QAudio::NoError; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
548 |
deviceState = QAudio::ActiveState; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
549 |
emit stateChanged(deviceState); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
550 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
551 |
return err; |
0 | 552 |
} |
553 |
} |
|
554 |
return 0; |
|
555 |
} |
|
556 |
||
557 |
void QAudioInputPrivate::resume() |
|
558 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
if(deviceState == QAudio::SuspendedState) { |
0 | 560 |
int err = 0; |
561 |
||
562 |
if(handle) { |
|
563 |
err = snd_pcm_prepare( handle ); |
|
564 |
if(err < 0) |
|
565 |
xrun_recovery(err); |
|
566 |
||
567 |
err = snd_pcm_start(handle); |
|
568 |
if(err < 0) |
|
569 |
xrun_recovery(err); |
|
570 |
||
571 |
bytesAvailable = buffer_size; |
|
572 |
} |
|
573 |
resuming = true; |
|
574 |
deviceState = QAudio::ActiveState; |
|
575 |
int chunks = buffer_size/period_size; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
576 |
timer->start(period_time*chunks/2000); |
0 | 577 |
emit stateChanged(deviceState); |
578 |
} |
|
579 |
} |
|
580 |
||
581 |
void QAudioInputPrivate::setBufferSize(int value) |
|
582 |
{ |
|
583 |
buffer_size = value; |
|
584 |
} |
|
585 |
||
586 |
int QAudioInputPrivate::bufferSize() const |
|
587 |
{ |
|
588 |
return buffer_size; |
|
589 |
} |
|
590 |
||
591 |
int QAudioInputPrivate::periodSize() const |
|
592 |
{ |
|
593 |
return period_size; |
|
594 |
} |
|
595 |
||
596 |
void QAudioInputPrivate::setNotifyInterval(int ms) |
|
597 |
{ |
|
598 |
if(ms >= minimumIntervalTime) |
|
599 |
intervalTime = ms; |
|
600 |
else |
|
601 |
intervalTime = minimumIntervalTime; |
|
602 |
} |
|
603 |
||
604 |
int QAudioInputPrivate::notifyInterval() const |
|
605 |
{ |
|
606 |
return intervalTime; |
|
607 |
} |
|
608 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
qint64 QAudioInputPrivate::processedUSecs() const |
0 | 610 |
{ |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
611 |
qint64 result = qint64(1000000) * totalTimeValue / |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
612 |
(settings.channels()*(settings.sampleSize()/8)) / |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
613 |
settings.frequency(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
614 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
615 |
return result; |
0 | 616 |
} |
617 |
||
618 |
void QAudioInputPrivate::suspend() |
|
619 |
{ |
|
620 |
if(deviceState == QAudio::ActiveState||resuming) { |
|
621 |
timer->stop(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
deviceState = QAudio::SuspendedState; |
0 | 623 |
emit stateChanged(deviceState); |
624 |
} |
|
625 |
} |
|
626 |
||
627 |
void QAudioInputPrivate::userFeed() |
|
628 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) |
0 | 630 |
return; |
631 |
#ifdef DEBUG_AUDIO |
|
632 |
QTime now(QTime::currentTime()); |
|
633 |
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() IN"; |
|
634 |
#endif |
|
635 |
deviceReady(); |
|
636 |
} |
|
637 |
||
638 |
bool QAudioInputPrivate::deviceReady() |
|
639 |
{ |
|
640 |
if(pullMode) { |
|
641 |
// reads some audio data and writes it to QIODevice |
|
642 |
read(0,0); |
|
643 |
} else { |
|
644 |
// emits readyRead() so user will call read() on QIODevice to get some audio data |
|
645 |
InputPrivate* a = qobject_cast<InputPrivate*>(audioSource); |
|
646 |
a->trigger(); |
|
647 |
} |
|
648 |
bytesAvailable = bytesReady(); |
|
649 |
||
650 |
if(deviceState != QAudio::ActiveState) |
|
651 |
return true; |
|
652 |
||
653 |
if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { |
|
654 |
emit notify(); |
|
655 |
elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; |
|
656 |
timeStamp.restart(); |
|
657 |
} |
|
658 |
return true; |
|
659 |
} |
|
660 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
qint64 QAudioInputPrivate::elapsedUSecs() const |
0 | 662 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
if (deviceState == QAudio::StoppedState) |
0 | 664 |
return 0; |
665 |
||
666 |
return clockStamp.elapsed()*1000; |
|
667 |
} |
|
668 |
||
669 |
void QAudioInputPrivate::reset() |
|
670 |
{ |
|
671 |
if(handle) |
|
672 |
snd_pcm_reset(handle); |
|
673 |
} |
|
674 |
||
675 |
void QAudioInputPrivate::drain() |
|
676 |
{ |
|
677 |
if(handle) |
|
678 |
snd_pcm_drain(handle); |
|
679 |
} |
|
680 |
||
681 |
InputPrivate::InputPrivate(QAudioInputPrivate* audio) |
|
682 |
{ |
|
683 |
audioDevice = qobject_cast<QAudioInputPrivate*>(audio); |
|
684 |
} |
|
685 |
||
686 |
InputPrivate::~InputPrivate() |
|
687 |
{ |
|
688 |
} |
|
689 |
||
690 |
qint64 InputPrivate::readData( char* data, qint64 len) |
|
691 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
692 |
return audioDevice->read(data,len); |
0 | 693 |
} |
694 |
||
695 |
qint64 InputPrivate::writeData(const char* data, qint64 len) |
|
696 |
{ |
|
697 |
Q_UNUSED(data) |
|
698 |
Q_UNUSED(len) |
|
699 |
return 0; |
|
700 |
} |
|
701 |
||
702 |
void InputPrivate::trigger() |
|
703 |
{ |
|
704 |
emit readyRead(); |
|
705 |
} |
|
706 |
||
707 |
QT_END_NAMESPACE |