From b15805ab71ae31c9981f9f3506d1bc93165e5520 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Nov 2017 17:16:06 +1100 Subject: [PATCH] Bug 1414759 - Replace some unnecessary media prefs with code constants. r=cpearce Specifically: - media.decoder.limit - media.num-decode-threads - media.resampling.rate - media.wmf.decoder.thread-count - media.cache.resource-index --HG-- extra : rebase_source : a46aa7078b98b4731ec96b66398c51aa6cb42d27 --- dom/ipc/ContentPrefs.cpp | 4 --- dom/media/MediaFormatReader.cpp | 16 ++++++++- dom/media/MediaPrefs.h | 20 ----------- dom/media/MediaResource.cpp | 35 ++++---------------- dom/media/MediaResource.h | 3 -- dom/media/VideoUtils.cpp | 4 ++- dom/media/mediasink/AudioSink.cpp | 2 +- dom/media/platforms/wmf/WMFDecoderModule.cpp | 12 ++----- modules/libpref/init/all.js | 5 --- 9 files changed, 29 insertions(+), 72 deletions(-) diff --git a/dom/ipc/ContentPrefs.cpp b/dom/ipc/ContentPrefs.cpp index 65c7183d9fa4..dc445b681da0 100644 --- a/dom/ipc/ContentPrefs.cpp +++ b/dom/ipc/ContentPrefs.cpp @@ -136,7 +136,6 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "media.cubeb_latency_msg_frames", "media.cubeb_latency_playback_ms", "media.decoder-doctor.wmf-disabled-is-failure", - "media.decoder.limit", "media.decoder.recycle.enabled", "media.dormant-on-pause-timeout-ms", "media.eme.audio.blank", @@ -151,11 +150,9 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "media.gmp.insecure.allow", "media.gpu-process-decoder", "media.libavcodec.allow-obsolete", - "media.num-decode-threads", "media.ogg.enabled", "media.ogg.flac.enabled", "media.resampling.enabled", - "media.resampling.rate", "media.ruin-av-sync.enabled", "media.rust.test_mode", "media.suspend-bkgnd-video.delay-ms", @@ -170,7 +167,6 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = { "media.webspeech.test.fake_fsm_events", "media.webspeech.test.fake_recognition_service", "media.wmf.allow-unsupported-resolutions", - "media.wmf.decoder.thread-count", "media.wmf.enabled", "media.wmf.skip-blacklist", "media.wmf.vp9.enabled", diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 10bee6876221..49e8ae9637cf 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -197,9 +197,23 @@ private: GlobalAllocPolicy& mPolicy; // reference to a singleton object. }; +static int32_t +MediaDecoderLimitDefault() +{ +#ifdef MOZ_WIDGET_ANDROID + if (jni::GetAPIVersion() < 18) { + // Older Android versions have broken support for multiple simultaneous + // decoders, see bug 1278574. + return 1; + } +#endif + // Otherwise, set no decoder limit. + return -1; +} + GlobalAllocPolicy::GlobalAllocPolicy() : mMonitor("DecoderAllocPolicy::mMonitor") - , mDecoderLimit(MediaPrefs::MediaDecoderLimit()) + , mDecoderLimit(MediaDecoderLimitDefault()) { SystemGroup::Dispatch( TaskCategory::Other, diff --git a/dom/media/MediaPrefs.h b/dom/media/MediaPrefs.h index 66f3cdfaaf10..c49a336cd676 100644 --- a/dom/media/MediaPrefs.h +++ b/dom/media/MediaPrefs.h @@ -92,7 +92,6 @@ private: DECL_MEDIA_PREF("media.memory_caches_combined_limit_kb", MediaMemoryCachesCombinedLimitKb, uint32_t, 524288); DECL_MEDIA_PREF("media.memory_caches_combined_limit_pc_sysmem", MediaMemoryCachesCombinedLimitPcSysmem, uint32_t, 5); - DECL_MEDIA_PREF("media.cache.resource-index", MediaResourceIndexCache, uint32_t, 8192); DECL_MEDIA_PREF("media.cache_resume_threshold", MediaCacheResumeThreshold, int32_t, 10); DECL_MEDIA_PREF("media.cache_readahead_limit", MediaCacheReadaheadLimit, int32_t, 30); @@ -100,7 +99,6 @@ private: // AudioSink DECL_MEDIA_PREF("accessibility.monoaudio.enable", MonoAudio, bool, false); DECL_MEDIA_PREF("media.resampling.enabled", AudioSinkResampling, bool, false); - DECL_MEDIA_PREF("media.resampling.rate", AudioSinkResampleRate, uint32_t, 48000); #if defined(XP_WIN) || defined(XP_DARWIN) || defined(MOZ_PULSEAUDIO) // libcubeb backend implement .get_preferred_channel_layout DECL_MEDIA_PREF("media.forcestereo.enabled", AudioSinkForceStereo, bool, false); @@ -140,7 +138,6 @@ private: DECL_MEDIA_PREF("media.wmf.skip-blacklist", PDMWMFSkipBlacklist, bool, false); DECL_MEDIA_PREF("media.decoder-doctor.wmf-disabled-is-failure", DecoderDoctorWMFDisabledIsFailure, bool, false); DECL_MEDIA_PREF("media.wmf.vp9.enabled", PDMWMFVP9DecoderEnabled, bool, true); - DECL_MEDIA_PREF("media.wmf.decoder.thread-count", PDMWMFThreadCount, int32_t, -1); #endif DECL_MEDIA_PREF("media.decoder.recycle.enabled", MediaDecoderCheckRecycling, bool, false); DECL_MEDIA_PREF("media.decoder.skip-to-next-key-frame.enabled", MFRSkipToNextKeyFrameEnabled, bool, true); @@ -165,9 +162,6 @@ private: DECL_MEDIA_PREF("media.webspeech.recognition.enable", WebSpeechRecognitionEnabled, bool, false); DECL_MEDIA_PREF("media.webspeech.recognition.force_enable", WebSpeechRecognitionForceEnabled, bool, false); - DECL_MEDIA_PREF("media.num-decode-threads", MediaThreadPoolDefaultCount, uint32_t, 4); - DECL_MEDIA_PREF("media.decoder.limit", MediaDecoderLimit, int32_t, MediaDecoderLimitDefault()); - #if defined(RELEASE_OR_BETA) DECL_MEDIA_PREF("media.audio-max-decode-error", MaxAudioDecodeError, uint32_t, 3); DECL_MEDIA_PREF("media.video-max-decode-error", MaxVideoDecodeError, uint32_t, 2); @@ -216,20 +210,6 @@ private: template friend class StaticAutoPtr; static StaticAutoPtr sInstance; - // Default value functions - static int32_t MediaDecoderLimitDefault() - { -#ifdef MOZ_WIDGET_ANDROID - if (jni::GetAPIVersion() < 18) { - // Older Android versions have broken support for multiple simultaneous - // decoders, see bug 1278574. - return 1; - } -#endif - // Otherwise, set no decoder limit. - return -1; - } - // Creating these to avoid having to include Preferences.h in the .h static void PrefAddVarCache(bool*, const char*, bool); static void PrefAddVarCache(int32_t*, const char*, int32_t); diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index 83f2b263e79c..3c37aeb986ca 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -5,9 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MediaResource.h" -#include "mozilla/DebugOnly.h" #include "MediaPrefs.h" +#include "mozilla/DebugOnly.h" #include "mozilla/Logging.h" +#include "mozilla/MathAlgorithms.h" #include "mozilla/SystemGroup.h" #include "mozilla/ErrorNames.h" @@ -42,11 +43,15 @@ MediaResource::Destroy() NS_IMPL_ADDREF(MediaResource) NS_IMPL_RELEASE_WITH_DESTROY(MediaResource, Destroy()) +static const uint32_t kMediaResourceIndexCacheSize = 8192; +static_assert(IsPowerOfTwo(kMediaResourceIndexCacheSize), + "kMediaResourceIndexCacheSize cache size must be a power of 2"); + MediaResourceIndex::MediaResourceIndex(MediaResource* aResource) : mResource(aResource) , mOffset(0) , mCacheBlockSize(aResource->ShouldCacheReads() - ? SelectCacheSize(MediaPrefs::MediaResourceIndexCache()) + ? kMediaResourceIndexCacheSize : 0) , mCachedOffset(0) , mCachedBytes(0) @@ -513,32 +518,6 @@ MediaResourceIndex::GetLength() const return mResource->GetLength(); } -// Select the next power of 2 (in range 32B-128KB, or 0 -> no cache) -/* static */ -uint32_t -MediaResourceIndex::SelectCacheSize(uint32_t aHint) -{ - if (aHint == 0) { - return 0; - } - if (aHint <= 32) { - return 32; - } - if (aHint > 64 * 1024) { - return 128 * 1024; - } - // 32-bit next power of 2, from: - // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 - aHint--; - aHint |= aHint >> 1; - aHint |= aHint >> 2; - aHint |= aHint >> 4; - aHint |= aHint >> 8; - aHint |= aHint >> 16; - aHint++; - return aHint; -} - uint32_t MediaResourceIndex::IndexInCache(int64_t aOffsetInFile) const { diff --git a/dom/media/MediaResource.h b/dom/media/MediaResource.h index 50c7a7f7c8d7..7365d1df6bd0 100644 --- a/dom/media/MediaResource.h +++ b/dom/media/MediaResource.h @@ -265,9 +265,6 @@ private: uint32_t aCount, uint32_t* aBytes); - // Select the next power of 2 (in range 32B-128KB, or 0 -> no cache) - static uint32_t SelectCacheSize(uint32_t aHint); - // Maps a file offset to a mCachedBlock index. uint32_t IndexInCache(int64_t aOffsetInFile) const; diff --git a/dom/media/VideoUtils.cpp b/dom/media/VideoUtils.cpp index 03c7911ca6ce..58491e321c96 100644 --- a/dom/media/VideoUtils.cpp +++ b/dom/media/VideoUtils.cpp @@ -209,8 +209,10 @@ already_AddRefed GetMediaThreadPool(MediaThreadType aType) name = "MediaPlayback"; break; } + + static const uint32_t kMediaThreadPoolDefaultCount = 4; return SharedThreadPool:: - Get(nsDependentCString(name), MediaPrefs::MediaThreadPoolDefaultCount()); + Get(nsDependentCString(name), kMediaThreadPoolDefaultCount); } bool diff --git a/dom/media/mediasink/AudioSink.cpp b/dom/media/mediasink/AudioSink.cpp index 345f1a95c0b8..ec438d28524a 100644 --- a/dom/media/mediasink/AudioSink.cpp +++ b/dom/media/mediasink/AudioSink.cpp @@ -51,7 +51,7 @@ AudioSink::AudioSink(AbstractThread* aThread, bool resampling = MediaPrefs::AudioSinkResampling(); if (resampling) { - mOutputRate = MediaPrefs::AudioSinkResampleRate(); + mOutputRate = 48000; } else if (mInfo.mRate == 44100 || mInfo.mRate == 48000) { // The original rate is of good quality and we want to minimize unecessary // resampling. The common scenario being that the sampling rate is one or diff --git a/dom/media/platforms/wmf/WMFDecoderModule.cpp b/dom/media/platforms/wmf/WMFDecoderModule.cpp index cdd64eaf61e7..87fa42c503e8 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.cpp +++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp @@ -74,15 +74,9 @@ WMFDecoderModule::GetNumDecoderThreads() int32_t numCores = PR_GetNumberOfProcessors(); // If we have more than 4 cores, let the decoder decide how many threads. - // On an 8 core machine, WMF chooses 4 decoder threads - const int WMF_DECODER_DEFAULT = -1; - int32_t prefThreadCount = WMF_DECODER_DEFAULT; - if (XRE_GetProcessType() != GeckoProcessType_GPU) { - prefThreadCount = MediaPrefs::PDMWMFThreadCount(); - } - if (prefThreadCount != WMF_DECODER_DEFAULT) { - return std::max(prefThreadCount, 1); - } else if (numCores > 4) { + // On an 8 core machine, WMF chooses 4 decoder threads. + static const int WMF_DECODER_DEFAULT = -1; + if (numCores > 4) { return WMF_DECODER_DEFAULT; } return std::max(numCores - 1, 1); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 85829c74f4a0..0eb5a95e8262 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -333,10 +333,6 @@ pref("media.memory_cache_max_size", 8192); pref("media.memory_caches_combined_limit_kb", 524288); pref("media.memory_caches_combined_limit_pc_sysmem", 5); -// Cache size hint (in bytes) for each MediaResourceIndex. -// 0 -> no cache. Will use next power of 2, clamped to 32B-128KB. -pref("media.cache.resource-index", 8192); - // We'll throttle the download if the download rate is throttle-factor times // the estimated playback rate, AND we satisfy the cache readahead_limit // above. The estimated playback rate is time_duration/length_in_bytes. @@ -368,7 +364,6 @@ pref("media.mp4.enabled", true); pref("media.use-blank-decoder", false); #ifdef MOZ_WMF pref("media.wmf.enabled", true); -pref("media.wmf.decoder.thread-count", -1); pref("media.wmf.dxva.enabled", true); pref("media.wmf.dxva.d3d11.enabled", true); pref("media.wmf.dxva.max-videos", 8);