diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2012-04-13 13:51:09 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-16 10:56:34 +0200 |
commit | 5f7b64346db43a6aa3ea2bbc15c63d4864f4d005 (patch) | |
tree | 845838026bba3e5236999abcab7f0bd9b39d6ec3 /src/plugins/pulseaudio | |
parent | 8441d2e32e3bae40640a1584d1d1d1e82980d718 (diff) |
Expose the audio category information for streams.
QAudioOutput and QSoundEffect now have a category property so that
system volume mixing or processing can be applied.
Initially just pulseaudio supports this but Windows Vista etc should also
work.
Change-Id: I6855b08367e5a055ac7dfcffd644c98bfd7c5a4e
Reviewed-by: Ling Hu <ling.hu@nokia.com>
Diffstat (limited to 'src/plugins/pulseaudio')
-rw-r--r-- | src/plugins/pulseaudio/qaudiooutput_pulse.cpp | 31 | ||||
-rw-r--r-- | src/plugins/pulseaudio/qaudiooutput_pulse.h | 4 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp index 779d54a81..5d226ea63 100644 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp +++ b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp @@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE const int PeriodTimeMs = 20; +const int LowLatencyBufferSizeMs = 40; static void outputStreamWriteCallback(pa_stream *stream, size_t length, void *userdata) { @@ -267,7 +268,23 @@ bool QPulseAudioOutput::open() QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); pa_threaded_mainloop_lock(pulseEngine->mainloop()); - m_stream = pa_stream_new(pulseEngine->context(), m_streamName.constData(), &spec, 0); + + pa_proplist *propList = pa_proplist_new(); + if (m_category.isNull()) { + // Meant to be one of the strings "video", "music", "game", "event", "phone", "animation", "production", "a11y", "test" + // We choose music unless the buffer size is small, where we choose game.. + qint64 bytesPerSecond = m_format.sampleRate() * m_format.channels() * m_format.sampleSize() / 8; + if (m_bufferSize > 0 && bytesPerSecond > 0 && (m_bufferSize * 1000LL / bytesPerSecond < LowLatencyBufferSizeMs)) { + pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, "game"); + } else { + pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, "music"); + } + } else { + pa_proplist_sets(propList, PA_PROP_MEDIA_ROLE, m_category.toLatin1().constData()); + } + + m_stream = pa_stream_new_with_proplist(pulseEngine->context(), m_streamName.constData(), &spec, 0, propList); + pa_proplist_free(propList); pa_stream_set_state_callback(m_stream, outputStreamStateCallback, this); pa_stream_set_write_callback(m_stream, outputStreamWriteCallback, this); @@ -619,6 +636,18 @@ qreal QPulseAudioOutput::volume() const return m_volume; } +void QPulseAudioOutput::setCategory(const QString &category) +{ + if (m_category != category) { + m_category = category; + } +} + +QString QPulseAudioOutput::category() const +{ + return m_category; +} + QT_END_NAMESPACE #include "moc_qaudiooutput_pulse.cpp" diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.h b/src/plugins/pulseaudio/qaudiooutput_pulse.h index 6d9cf339b..6364922ef 100644 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.h +++ b/src/plugins/pulseaudio/qaudiooutput_pulse.h @@ -98,6 +98,9 @@ public: void setVolume(qreal volume); qreal volume() const; + void setCategory(const QString &category); + QString category() const; + public: void streamUnderflowCallback(); @@ -130,6 +133,7 @@ private: QTime m_timeStamp; qint64 m_elapsedTimeOffset; bool m_resuming; + QString m_category; qreal m_volume; pa_cvolume m_chVolume; |