diff options
Diffstat (limited to 'src/multimedia/platform/pulseaudio')
-rw-r--r-- | src/multimedia/platform/pulseaudio/qpulseaudiosink.cpp | 36 | ||||
-rw-r--r-- | src/multimedia/platform/pulseaudio/qpulseaudiosource.cpp | 22 |
2 files changed, 35 insertions, 23 deletions
diff --git a/src/multimedia/platform/pulseaudio/qpulseaudiosink.cpp b/src/multimedia/platform/pulseaudio/qpulseaudiosink.cpp index 0521a5670..ae011ef0e 100644 --- a/src/multimedia/platform/pulseaudio/qpulseaudiosink.cpp +++ b/src/multimedia/platform/pulseaudio/qpulseaudiosink.cpp @@ -512,26 +512,29 @@ qint64 QPulseAudioSink::write(const char *data, qint64 len) pulseEngine->lock(); - len = qMin(len, static_cast<qint64>(pa_stream_writable_size(m_stream))); + size_t nbytes = len; + void *dest = nullptr; + + if (pa_stream_begin_write(m_stream, &dest, &nbytes) < 0) { + qWarning("QAudioSink(pulseaudio): pa_stream_begin_write, error = %s", + pa_strerror(pa_context_errno(pulseEngine->context()))); + setError(QAudio::IOError); + return 0; + } + + len = qMin(len, qint64(nbytes)); if (m_volume < 1.0f) { // Don't use PulseAudio volume, as it might affect all other streams of the same category // or even affect the system volume if flat volumes are enabled - void *dest = nullptr; - size_t nbytes = len; - if (pa_stream_begin_write(m_stream, &dest, &nbytes) < 0) { - qWarning("QAudioSink(pulseaudio): pa_stream_begin_write, error = %s", - pa_strerror(pa_context_errno(pulseEngine->context()))); - setError(QAudio::IOError); - return 0; - } - - len = int(nbytes); QAudioHelperInternal::qMultiplySamples(m_volume, m_format, data, dest, len); - data = reinterpret_cast<char *>(dest); + } else { + memcpy(dest, data, len); } - if (pa_stream_write(m_stream, data, len, nullptr, 0, PA_SEEK_RELATIVE) < 0) { + data = reinterpret_cast<char *>(dest); + + if ((pa_stream_write(m_stream, data, len, nullptr, 0, PA_SEEK_RELATIVE)) < 0) { qWarning("QAudioSink(pulseaudio): pa_stream_write, error = %s", pa_strerror(pa_context_errno(pulseEngine->context()))); setError(QAudio::IOError); @@ -672,18 +675,15 @@ qint64 PulseOutputPrivate::readData(char *data, qint64 len) qint64 PulseOutputPrivate::writeData(const char *data, qint64 len) { - int retry = 0; qint64 written = 0; if ((m_audioDevice->m_deviceState == QAudio::ActiveState || m_audioDevice->m_deviceState == QAudio::IdleState)) { - while(written < len) { + while (written < len) { int chunk = m_audioDevice->write(data+written, (len-written)); if (chunk <= 0) - retry++; - written+=chunk; - if (retry > 10) return written; + written += chunk; } } diff --git a/src/multimedia/platform/pulseaudio/qpulseaudiosource.cpp b/src/multimedia/platform/pulseaudio/qpulseaudiosource.cpp index d20929078..19e82c092 100644 --- a/src/multimedia/platform/pulseaudio/qpulseaudiosource.cpp +++ b/src/multimedia/platform/pulseaudio/qpulseaudiosource.cpp @@ -327,6 +327,12 @@ bool QPulseAudioSource::open() return false; } +// auto *ss = pa_stream_get_sample_spec(m_stream); +// qDebug() << "connected stream:"; +// qDebug() << " channels" << ss->channels << spec.channels; +// qDebug() << " format" << ss->format << spec.format; +// qDebug() << " rate" << ss->rate << spec.rate; + while (pa_stream_get_state(m_stream) != PA_STREAM_READY) pa_threaded_mainloop_wait(pulseEngine->mainloop()); @@ -400,16 +406,20 @@ qsizetype QPulseAudioSource::bytesReady() const qint64 QPulseAudioSource::read(char *data, qint64 len) { + Q_ASSERT(data != nullptr || len == 0); + m_bytesAvailable = checkBytesReady(); setError(QAudio::NoError); - setState(QAudio::ActiveState); + if (state() == QAudio::IdleState) + setState(QAudio::ActiveState); int readBytes = 0; if (!m_pullMode && !m_tempBuffer.isEmpty()) { readBytes = qMin(static_cast<int>(len), m_tempBuffer.size()); - memcpy(data, m_tempBuffer.constData(), readBytes); + if (readBytes) + memcpy(data, m_tempBuffer.constData(), readBytes); m_totalTimeValue += readBytes; if (readBytes < m_tempBuffer.size()) { @@ -495,9 +505,10 @@ qint64 QPulseAudioSource::read(char *data, qint64 len) void QPulseAudioSource::applyVolume(const void *src, void *dest, int len) { + Q_ASSERT((src && dest) || len == 0); if (m_volume < 1.f) QAudioHelperInternal::qMultiplySamples(m_volume, m_format, src, dest, len); - else + else if (len) memcpy(dest, src, len); } @@ -549,8 +560,9 @@ qint64 QPulseAudioSource::processedUSecs() const { pa_usec_t usecs = 0; int result = pa_stream_get_time(m_stream, &usecs); - if (result != 0) - qWarning() << "no timing info from pulse"; + Q_UNUSED(result); +// if (result != 0) +// qWarning() << "no timing info from pulse"; return usecs; } |