commit b78711ea3ac690960fd2ce98bbf4080e5daf5774
parent f90004e7e99429afdf64efe559e506547771cce7
Author: Gregory Pappas <gp3033@protonmail.com>
Date: Tue, 18 Nov 2025 22:32:52 +0000
Bug 2000838 - Move video queue prefs to static prefs r=media-playback-reviewers,geckoview-reviewers,aosmond,ohall
Instead of caching them manually
Differential Revision: https://phabricator.services.mozilla.com/D273013
Diffstat:
4 files changed, 37 insertions(+), 46 deletions(-)
diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp
@@ -28,7 +28,6 @@
#include "mediasink/DecodedStream.h"
#include "mediasink/VideoSink.h"
#include "mozilla/Logging.h"
-#include "mozilla/Preferences.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/ProfilerMarkerTypes.h"
#include "mozilla/ProfilerMarkers.h"
@@ -134,29 +133,6 @@ static constexpr auto EXHAUSTED_DATA_MARGIN =
TimeUnit::FromMicroseconds(100000);
static const uint32_t MIN_VIDEO_QUEUE_SIZE = 3;
-static const uint32_t MAX_VIDEO_QUEUE_SIZE = 10;
-static const uint32_t HW_VIDEO_QUEUE_SIZE = 3;
-static const uint32_t VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE = 9999;
-
-static uint32_t sVideoQueueDefaultSize = MAX_VIDEO_QUEUE_SIZE;
-static uint32_t sVideoQueueHWAccelSize = HW_VIDEO_QUEUE_SIZE;
-static uint32_t sVideoQueueSendToCompositorSize =
- VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE;
-
-static void InitVideoQueuePrefs() {
- MOZ_ASSERT(NS_IsMainThread());
- static bool sPrefInit = false;
- if (!sPrefInit) {
- sPrefInit = true;
- sVideoQueueDefaultSize = Preferences::GetUint(
- "media.video-queue.default-size", MAX_VIDEO_QUEUE_SIZE);
- sVideoQueueHWAccelSize = Preferences::GetUint(
- "media.video-queue.hw-accel-size", HW_VIDEO_QUEUE_SIZE);
- sVideoQueueSendToCompositorSize =
- Preferences::GetUint("media.video-queue.send-to-compositor-size",
- VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE);
- }
-}
template <typename Type, typename Function>
static void DiscardFramesFromTail(MediaQueue<Type>& aQueue,
@@ -3443,8 +3419,6 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
MOZ_COUNT_CTOR(MediaDecoderStateMachine);
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
- InitVideoQueuePrefs();
-
DDLINKCHILD("reader", aReader);
}
@@ -3521,9 +3495,9 @@ MediaSink* MediaDecoderStateMachine::CreateAudioSink() {
already_AddRefed<MediaSink> MediaDecoderStateMachine::CreateMediaSink() {
MOZ_ASSERT(OnTaskQueue());
RefPtr<MediaSink> audioSink = CreateAudioSink();
- RefPtr<MediaSink> mediaSink =
- new VideoSink(mTaskQueue, audioSink, mVideoQueue, mVideoFrameContainer,
- *mFrameStats, sVideoQueueSendToCompositorSize);
+ RefPtr<MediaSink> mediaSink = new VideoSink(
+ mTaskQueue, audioSink, mVideoQueue, mVideoFrameContainer, *mFrameStats,
+ StaticPrefs::media_video_queue_send_to_compositor_size());
if (mSecondaryVideoContainer.Ref()) {
mediaSink->SetSecondaryVideoContainer(mSecondaryVideoContainer.Ref());
}
@@ -4659,16 +4633,16 @@ uint32_t MediaDecoderStateMachine::GetAmpleVideoFrames() const {
if (mReader->VideoIsHardwareAccelerated()) {
// HW decoding should be fast so queue size can be as small as possible
// to lower frame latency.
- uint32_t hw =
- std::max<uint32_t>(sVideoQueueHWAccelSize, MIN_VIDEO_QUEUE_SIZE);
+ uint32_t hw = std::max<uint32_t>(
+ StaticPrefs::media_video_queue_hw_accel_size(), MIN_VIDEO_QUEUE_SIZE);
mReader->GetMinVideoQueueSize().apply(
[&hw](const uint32_t& x) { hw = std::max(hw, x); });
return hw;
} else {
// SW decoding is slower and queuing more frames in advance reduces the
// chances of dropping late frames.
- uint32_t sw =
- std::max<uint32_t>(sVideoQueueDefaultSize, MIN_VIDEO_QUEUE_SIZE);
+ uint32_t sw = std::max<uint32_t>(
+ StaticPrefs::media_video_queue_default_size(), MIN_VIDEO_QUEUE_SIZE);
mReader->GetMaxVideoQueueSize().apply(
[&sw](const uint32_t& x) { sw = std::min(sw, x); });
return sw;
diff --git a/mobile/android/app/geckoview-prefs.js b/mobile/android/app/geckoview-prefs.js
@@ -323,11 +323,6 @@ pref("media.navigator.permission.device", true);
// this is to preserve battery and data (bug 1540573)
pref("media.throttle-cellular-regardless-of-download-rate", true);
-// The maximum number of queued frames to send to the compositor.
-// On Android, it needs to be throttled because SurfaceTexture contains only one
-// (the most recent) image data. (bug 1299068)
-pref("media.video-queue.send-to-compositor-size", 1);
-
// Increase necko buffer sizes for Android (bug 560591)
pref("network.buffer.cache.size", 16384);
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
@@ -12272,6 +12272,36 @@
value: true
mirror: always
+# The target number of decoded video frames to maintain in
+# MediaDecoderStateMachine's mVideoQueue for hardware video decoding. Hardware
+# decoding is fast, so a small queue size is used to lower frame latency.
+- name: media.video-queue.hw-accel-size
+ type: RelaxedAtomicInt32
+ value: 3
+ mirror: always
+
+# The target number of decoded video frames to maintain in
+# MediaDecoderStateMachine's mVideoQueue for software video decoding. Software
+# decoding is slower, so a larger queue is used to lower chances of
+# dropping late frames.
+- name: media.video-queue.default-size
+ type: RelaxedAtomicInt32
+ value: 10
+ mirror: always
+
+# The maximum number of queued frames to send to the compositor.
+- name: media.video-queue.send-to-compositor-size
+ type: RelaxedAtomicInt32
+#ifdef ANDROID
+# On Android, it needs to be throttled because SurfaceTexture contains only one
+# (the most recent) image data. See bug 1299068.
+ value: 1
+#else
+# Send all of them.
+ value: 9999
+#endif
+ mirror: always
+
# Opus
- name: media.opus.enabled
type: RelaxedAtomicBool
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
@@ -356,14 +356,6 @@ pref("media.recorder.audio_node.enabled", false);
// to keep up under load. Useful for tests but beware of memory consumption!
pref("media.recorder.video.frame_drops", true);
-// The default number of decoded video frames that are enqueued in
-// MediaDecoderReader's mVideoQueue.
-pref("media.video-queue.default-size", 10);
-
-// The maximum number of queued frames to send to the compositor.
-// By default, send all of them.
-pref("media.video-queue.send-to-compositor-size", 9999);
-
pref("media.cubeb.output_voice_routing", true);
// Force cubeb to use the mock context, which exposes only fake devices.