summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudioinput_win32_p.cpp
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2010-04-26 22:56:25 (GMT)
committerKurt Korbatits <kurt.korbatits@nokia.com>2010-04-26 22:56:25 (GMT)
commite340e68d7ee2c0e7cbf2e1bd2f79b15418141016 (patch)
treee84e854441d9c75b7e19826ad51b1d1ee4950704 /src/multimedia/audio/qaudioinput_win32_p.cpp
parent4fedbbded38d7a978c16b41d66439e00e586dfb1 (diff)
downloadQt-e340e68d7ee2c0e7cbf2e1bd2f79b15418141016.zip
Qt-e340e68d7ee2c0e7cbf2e1bd2f79b15418141016.tar.gz
Qt-e340e68d7ee2c0e7cbf2e1bd2f79b15418141016.tar.bz2
win32 backend for low-level audio fixes
- fix deadlock with QAudioInput (win32) backend - changed win32 backend to use QMutex lock - setNotifyInterval(0) to disable notify() signal Reviewed-by:Derick Hawcroft
Diffstat (limited to 'src/multimedia/audio/qaudioinput_win32_p.cpp')
-rw-r--r--src/multimedia/audio/qaudioinput_win32_p.cpp68
1 files changed, 29 insertions, 39 deletions
diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp
index 5152d9a..8240047 100644
--- a/src/multimedia/audio/qaudioinput_win32_p.cpp
+++ b/src/multimedia/audio/qaudioinput_win32_p.cpp
@@ -57,8 +57,6 @@ QT_BEGIN_NAMESPACE
//#define DEBUG_AUDIO 1
-static const int minimumIntervalTime = 50;
-
QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
settings(audioFormat)
{
@@ -74,16 +72,11 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor
pullMode = true;
resuming = false;
finished = false;
-
- connect(this,SIGNAL(processMore()),SLOT(deviceReady()));
-
- InitializeCriticalSection(&waveInCriticalSection);
}
QAudioInputPrivate::~QAudioInputPrivate()
{
stop();
- DeleteCriticalSection(&waveInCriticalSection);
}
void CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
@@ -98,20 +91,18 @@ void CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
if(!qAudio)
return;
+ QMutexLocker(&qAudio->mutex);
+
switch(uMsg) {
case WIM_OPEN:
break;
case WIM_DATA:
- EnterCriticalSection(&qAudio->waveInCriticalSection);
if(qAudio->waveFreeBlockCount > 0)
qAudio->waveFreeBlockCount--;
qAudio->feedback();
- LeaveCriticalSection(&qAudio->waveInCriticalSection);
break;
case WIM_CLOSE:
- EnterCriticalSection(&qAudio->waveInCriticalSection);
qAudio->finished = true;
- LeaveCriticalSection(&qAudio->waveInCriticalSection);
break;
default:
return;
@@ -156,8 +147,7 @@ void QAudioInputPrivate::freeBlocks(WAVEHDR* blockArray)
int count = buffer_size/period_size;
for(int i = 0; i < count; i++) {
- if (blocks->dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
+ waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
blocks+=sizeof(WAVEHDR);
}
HeapFree(GetProcessHeap(), 0, blockArray);
@@ -279,9 +269,9 @@ bool QAudioInputPrivate::open()
return false;
}
- EnterCriticalSection(&waveInCriticalSection);
+ mutex.lock();
waveFreeBlockCount = buffer_size/period_size;
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
waveCurrentBlock = 0;
@@ -325,13 +315,11 @@ void QAudioInputPrivate::close()
Sleep(10);
}
- EnterCriticalSection(&waveInCriticalSection);
- for(int i=0; i<waveFreeBlockCount; i++) {
- if(waveBlocks[i].dwFlags & WHDR_PREPARED)
- waveInUnprepareHeader(hWaveIn,&waveBlocks[i],sizeof(WAVEHDR));
- }
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.lock();
+ for(int i=0; i<waveFreeBlockCount; i++)
+ waveInUnprepareHeader(hWaveIn,&waveBlocks[i],sizeof(WAVEHDR));
freeBlocks(waveBlocks);
+ mutex.unlock();
}
int QAudioInputPrivate::bytesReady() const
@@ -402,9 +390,10 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
waveInUnprepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
- EnterCriticalSection(&waveInCriticalSection);
+ mutex.lock();
waveFreeBlockCount++;
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
+
waveBlocks[header].dwBytesRecorded=0;
waveBlocks[header].dwFlags = 0L;
result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
@@ -412,18 +401,22 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
qWarning("QAudioInput: failed to prepare block %d,err=%d",header,result);
errorState = QAudio::IOError;
- EnterCriticalSection(&waveInCriticalSection);
+
+ mutex.lock();
waveFreeBlockCount--;
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
+
return 0;
}
result = waveInAddBuffer(hWaveIn, &waveBlocks[header], sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR) {
qWarning("QAudioInput: failed to setup block %d,err=%d",header,result);
errorState = QAudio::IOError;
- EnterCriticalSection(&waveInCriticalSection);
+
+ mutex.lock();
waveFreeBlockCount--;
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
+
return 0;
}
header++;
@@ -431,7 +424,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
header = 0;
p+=l;
- EnterCriticalSection(&waveInCriticalSection);
+ mutex.lock();
if(!pullMode) {
if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size)
done = true;
@@ -439,7 +432,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
if(waveFreeBlockCount == buffer_size/period_size)
done = true;
}
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
written+=l;
}
@@ -463,9 +456,10 @@ void QAudioInputPrivate::resume()
return;
}
}
- EnterCriticalSection(&waveInCriticalSection);
+
+ mutex.lock();
waveFreeBlockCount = buffer_size/period_size;
- LeaveCriticalSection(&waveInCriticalSection);
+ mutex.unlock();
waveCurrentBlock = 0;
header = 0;
@@ -493,10 +487,7 @@ int QAudioInputPrivate::periodSize() const
void QAudioInputPrivate::setNotifyInterval(int ms)
{
- if(ms >= minimumIntervalTime)
- intervalTime = ms;
- else
- intervalTime = minimumIntervalTime;
+ intervalTime = qMax(0, ms);
}
int QAudioInputPrivate::notifyInterval() const
@@ -530,14 +521,13 @@ void QAudioInputPrivate::feedback()
QTime now(QTime::currentTime());
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT "<<this;
#endif
- bytesAvailable = bytesReady();
-
if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState))
- emit processMore();
+ QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection);
}
bool QAudioInputPrivate::deviceReady()
{
+ bytesAvailable = bytesReady();
#ifdef DEBUG_AUDIO
QTime now(QTime::currentTime());
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :deviceReady() INPUT";
@@ -554,7 +544,7 @@ bool QAudioInputPrivate::deviceReady()
a->trigger();
}
- if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
+ if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
timeStamp.restart();