summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-11-13 13:20:03 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-13 22:55:06 +0000
commit6b39152c02ca5ad393db6db595317359d84f3761 (patch)
treecd7a10fd674afd75a4ba720312c7c83a8690f609
parent4f8c336f7ca4b47700a0ba3bb021dec899d7937b (diff)
Add environment variable for testing audio sample rate deviations
In some cases, mostly on Linux, audio sink consumes bytes faster than expected, that causes audio stuttering. The variable might help us to test on the user side how the sample rate deviation affects the audio playback. Task-number: QTBUG-116020 Pick-to: 6.5 Change-Id: Ie6a34b7e8f9223f70b4a21ada536375d2bb787be Reviewed-by: Lars Knoll <lars@knoll.priv.no> (cherry picked from commit 2ab05abc865356a2fb1748993eeb9204d346afcc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp
index d43593c35..d3ae750b7 100644
--- a/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp
+++ b/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegaudiorenderer.cpp
@@ -28,6 +28,32 @@ constexpr auto SampleCompenationOffset = AudioSinkBufferTime / 10;
constexpr qreal CompensationAngleFactor = 0.01;
constexpr auto DurationBias = 2ms; // avoids extra timer events
+
+qreal sampleRateFactor() {
+ // Test purposes:
+ //
+ // The env var describes a factor for the sample rate of
+ // audio data that we feed to the audio sink.
+ //
+ // In some cases audio sink might consume data slightly slower or faster than expected;
+ // even though the synchronization in the audio renderer is supposed to handle it,
+ // it makes sense to experiment with QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR != 1.
+ //
+ // Set QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR > 1 (e.g. 1.01 - 1.1) to test high buffer loading
+ // or try compensating too fast data consumption by the audio sink.
+ // Set QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR < 1 to test low buffer loading
+ // or try compensating too slow data consumption by the audio sink.
+
+
+ static const qreal result = []() {
+ const auto sampleRateFactorStr = qEnvironmentVariable("QT_MEDIA_PLAYER_AUDIO_SAMPLE_RATE_FACTOR");
+ bool ok = false;
+ const auto result = sampleRateFactorStr.toDouble(&ok);
+ return ok ? result : 1.;
+ }();
+
+ return result;
+}
} // namespace
AudioRenderer::AudioRenderer(const TimeController &tc, QAudioOutput *output)
@@ -131,14 +157,9 @@ void AudioRenderer::initResempler(const Codec *codec)
#endif
*/
- // Test purposes:
- // Set PlaybackRateDeviation > 1 (e.g. 1.01) to test high buffer loading
- // or PlaybackRateDeviation < 1 to test low buffer loading.
- constexpr qreal PlaybackRateDeviation = 1.;
-
auto resamplerFormat = m_format;
resamplerFormat.setSampleRate(
- qRound(m_format.sampleRate() / playbackRate() * PlaybackRateDeviation));
+ qRound(m_format.sampleRate() / playbackRate() * sampleRateFactor()));
m_resampler = std::make_unique<Resampler>(codec, resamplerFormat);
}