diff options
author | Liang Qi <liang.qi@qt.io> | 2016-09-19 14:29:40 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-09-19 14:29:47 +0200 |
commit | 01c9322bfe918b886468eb520d77b21b6d8c0c11 (patch) | |
tree | 23362a67d26b7b295a04e8cbacd64ee20393f990 /src/plugins/wasapi/qwasapiaudiooutput.cpp | |
parent | 0f47f44d2fc7b3fac7fdd8ee6eeafd767c43ec2e (diff) | |
parent | 256ee311b936d69561e97f7f8ee832cff93cb509 (diff) |
Merge remote-tracking branch 'origin/5.7' into 5.8
Change-Id: I022c07dab3ded6072f7c103e299822caaf40cf34
Diffstat (limited to 'src/plugins/wasapi/qwasapiaudiooutput.cpp')
-rw-r--r-- | src/plugins/wasapi/qwasapiaudiooutput.cpp | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/src/plugins/wasapi/qwasapiaudiooutput.cpp b/src/plugins/wasapi/qwasapiaudiooutput.cpp index 53f4f2710..1b0f64451 100644 --- a/src/plugins/wasapi/qwasapiaudiooutput.cpp +++ b/src/plugins/wasapi/qwasapiaudiooutput.cpp @@ -206,13 +206,9 @@ qreal QWasapiAudioOutput::volume() const void QWasapiAudioOutput::process() { qCDebug(lcMmAudioOutput) << __FUNCTION__; - const quint32 channelCount = m_currentFormat.channelCount(); - const quint32 sampleBytes = m_currentFormat.sampleSize() / 8; - BYTE* buffer; - HRESULT hr; DWORD waitRet; - bool processing = true; + m_processing = true; do { waitRet = WaitForSingleObjectEx(m_event, 2000, FALSE); if (waitRet != WAIT_OBJECT_0) { @@ -224,51 +220,59 @@ void QWasapiAudioOutput::process() if (m_currentState != QAudio::ActiveState && m_currentState != QAudio::IdleState) break; + QMetaObject::invokeMethod(this, "processBuffer", Qt::QueuedConnection); + } while (m_processing); +} - quint32 paddingFrames; - hr = m_interface->m_client->GetCurrentPadding(&paddingFrames); +void QWasapiAudioOutput::processBuffer() +{ + QMutexLocker locker(&m_mutex); - quint32 availableFrames = m_bufferFrames - paddingFrames; - hr = m_renderer->GetBuffer(availableFrames, &buffer); - if (hr != S_OK) { - m_currentError = QAudio::UnderrunError; - QMetaObject::invokeMethod(this, "errorChanged", Qt::QueuedConnection, - Q_ARG(QAudio::Error, QAudio::UnderrunError)); - // Also Error Buffers need to be released - hr = m_renderer->ReleaseBuffer(availableFrames, 0); - ResetEvent(m_event); - continue; // We will continue trying - } + const quint32 channelCount = m_currentFormat.channelCount(); + const quint32 sampleBytes = m_currentFormat.sampleSize() / 8; + BYTE* buffer; + HRESULT hr; - const quint32 readBytes = availableFrames * channelCount * sampleBytes; - qint64 read = m_eventDevice->read((char*)buffer, readBytes); - if (read < static_cast<qint64>(readBytes)) { - // Fill the rest of the buffer with zero to avoid audio glitches - if (m_currentError != QAudio::UnderrunError) { - m_currentError = QAudio::UnderrunError; - QMetaObject::invokeMethod(this, "errorChanged", Qt::QueuedConnection, - Q_ARG(QAudio::Error, QAudio::UnderrunError)); - } - if (m_currentState != QAudio::IdleState) { - m_currentState = QAudio::IdleState; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, - Q_ARG(QAudio::State, QAudio::IdleState)); - } - } + quint32 paddingFrames; + hr = m_interface->m_client->GetCurrentPadding(&paddingFrames); + const quint32 availableFrames = m_bufferFrames - paddingFrames; + hr = m_renderer->GetBuffer(availableFrames, &buffer); + if (hr != S_OK) { + m_currentError = QAudio::UnderrunError; + emit errorChanged(m_currentError); + // Also Error Buffers need to be released hr = m_renderer->ReleaseBuffer(availableFrames, 0); - if (hr != S_OK) - qFatal("Could not release buffer"); ResetEvent(m_event); + return; + } - if (m_interval && m_openTime.elapsed() - m_openTimeOffset > m_interval) { - QMetaObject::invokeMethod(this, "notify", Qt::QueuedConnection); - m_openTimeOffset = m_openTime.elapsed(); + const quint32 readBytes = availableFrames * channelCount * sampleBytes; + const qint64 read = m_eventDevice->read((char*)buffer, readBytes); + if (read < static_cast<qint64>(readBytes)) { + // Fill the rest of the buffer with zero to avoid audio glitches + if (m_currentError != QAudio::UnderrunError) { + m_currentError = QAudio::UnderrunError; + emit errorChanged(m_currentError); } + if (m_currentState != QAudio::IdleState) { + m_currentState = QAudio::IdleState; + emit stateChanged(m_currentState); + } + } + + hr = m_renderer->ReleaseBuffer(availableFrames, 0); + if (hr != S_OK) + qFatal("Could not release buffer"); + ResetEvent(m_event); + + if (m_interval && m_openTime.elapsed() - m_openTimeOffset > m_interval) { + emit notify(); + m_openTimeOffset = m_openTime.elapsed(); + } - m_bytesProcessed += read; - processing = m_currentState == QAudio::ActiveState || m_currentState == QAudio::IdleState; - } while (processing); + m_bytesProcessed += read; + m_processing = m_currentState == QAudio::ActiveState || m_currentState == QAudio::IdleState; } bool QWasapiAudioOutput::initStart(bool pull) |