summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudioinput_win32_p.cpp
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2010-02-23 21:21:30 (GMT)
committerKurt Korbatits <kurt.korbatits@nokia.com>2010-02-23 21:21:30 (GMT)
commit1e546bf392acca81e0117da2d91906143f52d362 (patch)
treed81dc76eac2aa97e475aae8d382e30d5d7ca0d44 /src/multimedia/audio/qaudioinput_win32_p.cpp
parentaa90ed9a169b169fc1ea6bcc9f4588785957b4d8 (diff)
downloadQt-1e546bf392acca81e0117da2d91906143f52d362.zip
Qt-1e546bf392acca81e0117da2d91906143f52d362.tar.gz
Qt-1e546bf392acca81e0117da2d91906143f52d362.tar.bz2
win32 backend for low-level audio doesn't pass new unit tests
New unit tests have identified issues with awin32 backend. These issues need to be resolved before new unit tests are added. * stateChanged() signal should only be emitted on change of state currently signals can be emitted multiple times. * for output data is being lost when input can be read from QIODevice but cannot be written to audio sub system. Task-number:QTBUG-8441 Reviewed-by:Dmytro Poplavskiy
Diffstat (limited to 'src/multimedia/audio/qaudioinput_win32_p.cpp')
-rw-r--r--src/multimedia/audio/qaudioinput_win32_p.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp
index 17e8bfb..ec0359a 100644
--- a/src/multimedia/audio/qaudioinput_win32_p.cpp
+++ b/src/multimedia/audio/qaudioinput_win32_p.cpp
@@ -192,9 +192,11 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device)
//set to pull mode
pullMode = true;
audioSource = device;
+ deviceState = QAudio::ActiveState;
} else {
//set to push mode
pullMode = false;
+ deviceState = QAudio::IdleState;
audioSource = new InputPrivate(this);
audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
}
@@ -306,7 +308,6 @@ bool QAudioInputPrivate::open()
elapsedTimeOffset = 0;
totalTimeValue = 0;
errorState = QAudio::NoError;
- deviceState = QAudio::ActiveState;
return true;
}
@@ -315,9 +316,9 @@ void QAudioInputPrivate::close()
if(deviceState == QAudio::StoppedState)
return;
+ deviceState = QAudio::StoppedState;
waveInReset(hWaveIn);
waveInClose(hWaveIn);
- deviceState = QAudio::StoppedState;
int count = 0;
while(!finished && count < 500) {
@@ -352,7 +353,6 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
char* p = data;
qint64 l = 0;
qint64 written = 0;
-
while(!done) {
// Read in some audio data
if(waveBlocks[header].dwBytesRecorded > 0 && waveBlocks[header].dwFlags & WHDR_DONE) {
@@ -373,11 +373,12 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
errorState = QAudio::IOError;
} else {
- totalTimeValue += waveBlocks[header].dwBytesRecorded
- /((settings.channels()*settings.sampleSize()/8))
- *10000/settings.frequency()*100;
+ totalTimeValue += waveBlocks[header].dwBytesRecorded;
errorState = QAudio::NoError;
- deviceState = QAudio::ActiveState;
+ if (deviceState != QAudio::ActiveState) {
+ deviceState = QAudio::ActiveState;
+ emit stateChanged(deviceState);
+ }
resuming = false;
}
} else {
@@ -387,16 +388,17 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
#ifdef DEBUG_AUDIO
qDebug()<<"IN: "<<waveBlocks[header].dwBytesRecorded<<", OUT: "<<l;
#endif
- totalTimeValue += waveBlocks[header].dwBytesRecorded
- /((settings.channels()*settings.sampleSize()/8))
- *10000/settings.frequency()*100;
+ totalTimeValue += waveBlocks[header].dwBytesRecorded;
errorState = QAudio::NoError;
- deviceState = QAudio::ActiveState;
+ if (deviceState != QAudio::ActiveState) {
+ deviceState = QAudio::ActiveState;
+ emit stateChanged(deviceState);
+ }
resuming = false;
}
} else {
//no data, not ready yet, next time
- return 0;
+ break;
}
waveInUnprepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR));
@@ -505,7 +507,13 @@ int QAudioInputPrivate::notifyInterval() const
qint64 QAudioInputPrivate::processedUSecs() const
{
- return totalTimeValue;
+ if (deviceState == QAudio::StoppedState)
+ return 0;
+ qint64 result = qint64(1000000) * totalTimeValue /
+ (settings.channels()*(settings.sampleSize()/8)) /
+ settings.frequency();
+
+ return result;
}
void QAudioInputPrivate::suspend()
@@ -535,6 +543,9 @@ bool QAudioInputPrivate::deviceReady()
QTime now(QTime::currentTime());
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :deviceReady() INPUT";
#endif
+ if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
+ return true;
+
if(pullMode) {
// reads some audio data and writes it to QIODevice
read(0,0);
@@ -543,8 +554,6 @@ bool QAudioInputPrivate::deviceReady()
InputPrivate* a = qobject_cast<InputPrivate*>(audioSource);
a->trigger();
}
- if(deviceState != QAudio::ActiveState)
- return true;
if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
@@ -577,7 +586,8 @@ InputPrivate::~InputPrivate() {}
qint64 InputPrivate::readData( char* data, qint64 len)
{
// push mode, user read() called
- if(audioDevice->deviceState != QAudio::ActiveState)
+ if(audioDevice->deviceState != QAudio::ActiveState &&
+ audioDevice->deviceState != QAudio::IdleState)
return 0;
// Read in some audio data
return audioDevice->read(data,len);