From 5d94ce44f19316ce1c30c23635bf9575d80aa4e2 Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Fri, 2 Oct 2009 14:45:05 +1000 Subject: Fixed logic in clock() function of audio class's. - clock() should return valid value except in stop state, return 0. - Added clock() function testing to unit tests. Reviewed-by:Justin McPherson --- src/multimedia/audio/qaudioinput_alsa_p.cpp | 2 +- src/multimedia/audio/qaudioinput_mac_p.cpp | 3 +++ src/multimedia/audio/qaudioinput_win32_p.cpp | 2 +- src/multimedia/audio/qaudiooutput_alsa_p.cpp | 2 +- src/multimedia/audio/qaudiooutput_mac_p.cpp | 3 +++ src/multimedia/audio/qaudiooutput_win32_p.cpp | 2 +- tests/auto/qaudioinput/tst_qaudioinput.cpp | 3 +++ tests/auto/qaudiooutput/tst_qaudiooutput.cpp | 3 +++ 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index 46c4392..5e9aa81 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -598,7 +598,7 @@ qint64 QAudioInputPrivate::clock() const if(!handle) return 0; - if(deviceState != QAudio::ActiveState) + if (deviceState == QAudio::StopState) return 0; snd_pcm_status_t* status; diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp index 07fa3f4..cb05920 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ b/src/multimedia/audio/qaudioinput_mac_p.cpp @@ -819,6 +819,9 @@ qint64 QAudioInputPrivate::totalTime() const qint64 QAudioInputPrivate::clock() const { + if (stateCode == QAudio::StopState) + return 0; + return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); } diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp index d4226f5..b6b1efe 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ b/src/multimedia/audio/qaudioinput_win32_p.cpp @@ -541,7 +541,7 @@ bool QAudioInputPrivate::deviceReady() qint64 QAudioInputPrivate::clock() const { - if(deviceState != QAudio::ActiveState) + if (deviceState == QAudio::StopState) return 0; return timeStampOpened.elapsed(); diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp index 0d37d61..d814d97 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -650,7 +650,7 @@ qint64 QAudioOutputPrivate::clock() const if(!handle) return 0; - if(deviceState != QAudio::ActiveState) + if (deviceState == QAudio::StopState) return 0; snd_pcm_status_t* status; diff --git a/src/multimedia/audio/qaudiooutput_mac_p.cpp b/src/multimedia/audio/qaudiooutput_mac_p.cpp index 4364704..f23db80 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.cpp +++ b/src/multimedia/audio/qaudiooutput_mac_p.cpp @@ -551,6 +551,9 @@ qint64 QAudioOutputPrivate::totalTime() const qint64 QAudioOutputPrivate::clock() const { + if (stateCode == QAudio::StopState) + return 0; + return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); } diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp index bb61f41..ef4bf0e 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp @@ -492,7 +492,7 @@ bool QAudioOutputPrivate::deviceReady() qint64 QAudioOutputPrivate::clock() const { - if(deviceState != QAudio::ActiveState) + if (deviceState == QAudio::StopState) return 0; return timeStampOpened.elapsed(); diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 69b507d..3945364 100644 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -139,12 +139,14 @@ void tst_QAudioInput::pullFile() // Always have default states, before start QVERIFY(audio->state() == QAudio::StopState); QVERIFY(audio->error() == QAudio::NoError); + QVERIFY(audio->clock() == 0); audio->start(&filename); QTest::qWait(20); // Check state and periodSize() are valid non-zero values. QVERIFY(audio->state() == QAudio::ActiveState); QVERIFY(audio->error() == QAudio::NoError); + QVERIFY(audio->clock() > 0); QVERIFY(audio->periodSize() > 0); QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState @@ -157,6 +159,7 @@ void tst_QAudioInput::pullFile() audio->stop(); QTest::qWait(20); QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->clock() == 0); // Can only check to make sure we got at least 1 more signal, but can be more. QVERIFY(stateSignal.count() > 1); diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index f1c75dc..b90873e 100644 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -142,6 +142,7 @@ void tst_QAudioOutput::pullFile() // Always have default states, before start QVERIFY(audio->state() == QAudio::StopState); QVERIFY(audio->error() == QAudio::NoError); + QVERIFY(audio->clock() == 0); audio->start(&file); QTest::qWait(20); // wait 20ms @@ -149,6 +150,7 @@ void tst_QAudioOutput::pullFile() QVERIFY(audio->state() == QAudio::ActiveState); QVERIFY(audio->error() == QAudio::NoError); QVERIFY(audio->periodSize() > 0); + QVERIFY(audio->clock() > 0); QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState // Wait until finished... @@ -160,6 +162,7 @@ void tst_QAudioOutput::pullFile() audio->stop(); QTest::qWait(20); // wait 20ms QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->clock() == 0); // Can only check to make sure we got at least 1 more signal, but can be more. QVERIFY(stateSignal.count() > 1); -- cgit v0.12