LCOV - code coverage report
Current view: top level - dom/media - MediaPrefs.h (source / functions) Hit Total Coverage
Test: output.info Lines: 64 64 100.0 %
Date: 2017-07-14 16:53:18 Functions: 218 263 82.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef MEDIA_PREFS_H
       7             : #define MEDIA_PREFS_H
       8             : 
       9             : #ifdef MOZ_WIDGET_ANDROID
      10             : #include "GeneratedJNIWrappers.h"
      11             : #endif
      12             : 
      13             : #include "mozilla/Atomics.h"
      14             : 
      15             : // First time MediaPrefs::GetSingleton() needs to be called on the main thread,
      16             : // before any of the methods accessing the values are used, but after
      17             : // the Preferences system has been initialized.
      18             : 
      19             : // The static methods to access the preference value are safe to call
      20             : // from any thread after that first call.
      21             : 
      22             : // To register a preference, you need to add a line in this file using
      23             : // the DECL_MEDIA_PREF macro.
      24             : //
      25             : // For example this line in the .h:
      26             : //   DECL_MEDIA_PREF("media.resampling.enabled",AudioSinkResampling,bool,false);
      27             : // means that you can call
      28             : //   const bool& var = MediaPrefs::AudioSinkResampling();
      29             : // from any thread, you will get the most up to date preference value of
      30             : // "media.resampling.enabled".  If the value is not set, the default would be
      31             : // false.
      32             : 
      33             : #define DECL_MEDIA_PREF(Pref, Name, Type, Default)                            \
      34             : public:                                                                       \
      35             : static const Type& Name() { MOZ_ASSERT(SingletonExists()); return GetSingleton().mPref##Name.mValue; } \
      36             : private:                                                                      \
      37             : static const char* Get##Name##PrefName() { return Pref; }                     \
      38             : static StripAtomic<Type> Get##Name##PrefDefault() { return Default; }         \
      39             : PrefTemplate<Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name
      40             : 
      41             : // Custom Definitions.
      42             : #define GMP_DEFAULT_ASYNC_SHUTDOWN_TIMEOUT 3000
      43             : #define SUSPEND_BACKGROUND_VIDEO_DELAY_MS 10000
      44             : #define TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE "media.webspeech.test.fake_recognition_service"
      45             : 
      46             : namespace mozilla {
      47             : 
      48             : template<class T> class StaticAutoPtr;
      49             : 
      50             : class MediaPrefs final
      51             : {
      52             :   typedef Atomic<uint32_t, Relaxed> AtomicUint32;
      53             : 
      54             :   template <typename T>
      55             :   struct StripAtomicImpl {
      56             :     typedef T Type;
      57             :   };
      58             : 
      59             :   template <typename T, MemoryOrdering Order>
      60             :   struct StripAtomicImpl<Atomic<T, Order>> {
      61             :     typedef T Type;
      62             :   };
      63             : 
      64             :   template <typename T>
      65             :   using StripAtomic = typename StripAtomicImpl<T>::Type;
      66             : 
      67             : private:
      68             :   // Since we cannot use const char*, use a function that returns it.
      69             :   template <class T, StripAtomic<T> Default(), const char* Pref()>
      70             :   class PrefTemplate
      71             :   {
      72             :   public:
      73         162 :     PrefTemplate()
      74         162 :     : mValue(Default())
      75             :     {
      76         162 :       Register(Pref());
      77         162 :     }
      78             :     T mValue;
      79             :   private:
      80         162 :     void Register(const char* aPreference)
      81             :     {
      82         162 :       AssertMainThread();
      83         162 :       PrefAddVarCache(&mValue, aPreference, mValue);
      84         162 :     }
      85             :   };
      86             : 
      87             :   // This is where DECL_MEDIA_PREF for each of the preferences should go.
      88             : 
      89             :   // Cache sizes.
      90           6 :   DECL_MEDIA_PREF("media.cache_size",                         MediaCacheSizeKb, uint32_t, 512000);
      91           6 :   DECL_MEDIA_PREF("media.memory_cache_max_size",              MediaMemoryCacheMaxSize, uint32_t, 8192);
      92           6 :   DECL_MEDIA_PREF("media.memory_caches_combined_limit_kb",    MediaMemoryCachesCombinedLimitKb, uint32_t, 524288);
      93           6 :   DECL_MEDIA_PREF("media.memory_caches_combined_limit_pc_sysmem",
      94             :                                                               MediaMemoryCachesCombinedLimitPcSysmem, uint32_t, 5);
      95           6 :   DECL_MEDIA_PREF("media.cache.resource-index",               MediaResourceIndexCache, uint32_t, 8192);
      96             : 
      97             :   // AudioSink
      98           6 :   DECL_MEDIA_PREF("accessibility.monoaudio.enable",           MonoAudio, bool, false);
      99           6 :   DECL_MEDIA_PREF("media.resampling.enabled",                 AudioSinkResampling, bool, false);
     100           6 :   DECL_MEDIA_PREF("media.resampling.rate",                    AudioSinkResampleRate, uint32_t, 48000);
     101             : #if defined(XP_WIN) || defined(XP_DARWIN) || defined(MOZ_PULSEAUDIO)
     102             :   // libcubeb backend implement .get_preferred_channel_layout
     103           6 :   DECL_MEDIA_PREF("media.forcestereo.enabled",                AudioSinkForceStereo, bool, false);
     104             : #else
     105             :   DECL_MEDIA_PREF("media.forcestereo.enabled",                AudioSinkForceStereo, bool, true);
     106             : #endif
     107             :   // VideoSink
     108           6 :   DECL_MEDIA_PREF("media.ruin-av-sync.enabled",               RuinAvSync, bool, false);
     109             : 
     110             :   // Encrypted Media Extensions
     111           6 :   DECL_MEDIA_PREF("media.clearkey.persistent-license.enabled", ClearKeyPersistentLicenseEnabled, bool, false);
     112             : 
     113             :   // PlatformDecoderModule
     114           6 :   DECL_MEDIA_PREF("media.apple.forcevda",                     AppleForceVDA, bool, false);
     115           6 :   DECL_MEDIA_PREF("media.gmp.insecure.allow",                 GMPAllowInsecure, bool, false);
     116           6 :   DECL_MEDIA_PREF("media.eme.enabled",                        EMEEnabled, bool, false);
     117           6 :   DECL_MEDIA_PREF("media.use-blank-decoder",                  PDMUseBlankDecoder, bool, false);
     118           6 :   DECL_MEDIA_PREF("media.gpu-process-decoder",                PDMUseGPUDecoder, bool, false);
     119             : #ifdef MOZ_GONK_MEDIACODEC
     120             :   DECL_MEDIA_PREF("media.gonk.enabled",                       PDMGonkDecoderEnabled, bool, true);
     121             : #endif
     122             : #ifdef MOZ_WIDGET_ANDROID
     123             :   DECL_MEDIA_PREF("media.android-media-codec.enabled",        PDMAndroidMediaCodecEnabled, bool, false);
     124             :   DECL_MEDIA_PREF("media.android-media-codec.preferred",      PDMAndroidMediaCodecPreferred, bool, false);
     125             :   DECL_MEDIA_PREF("media.navigator.hardware.vp8_encode.acceleration_remote_enabled", RemoteMediaCodecVP8EncoderEnabled, bool, false);
     126             : #endif
     127             : #ifdef MOZ_FFMPEG
     128           6 :   DECL_MEDIA_PREF("media.ffmpeg.enabled",                     PDMFFmpegEnabled, bool, true);
     129           6 :   DECL_MEDIA_PREF("media.libavcodec.allow-obsolete",          LibavcodecAllowObsolete, bool, false);
     130             : #endif
     131             : #if defined(MOZ_FFMPEG) || defined(MOZ_FFVPX)
     132           6 :   DECL_MEDIA_PREF("media.ffmpeg.low-latency.enabled",         PDMFFmpegLowLatencyEnabled, bool, false);
     133             : #endif
     134             : #ifdef MOZ_FFVPX
     135           6 :   DECL_MEDIA_PREF("media.ffvpx.enabled",                      PDMFFVPXEnabled, bool, true);
     136             : #endif
     137             : #ifdef XP_WIN
     138             :   DECL_MEDIA_PREF("media.wmf.enabled",                        PDMWMFEnabled, bool, true);
     139             :   DECL_MEDIA_PREF("media.wmf.skip-blacklist",                 PDMWMFSkipBlacklist, bool, false);
     140             :   DECL_MEDIA_PREF("media.decoder-doctor.wmf-disabled-is-failure", DecoderDoctorWMFDisabledIsFailure, bool, false);
     141             :   DECL_MEDIA_PREF("media.wmf.vp9.enabled",                    PDMWMFVP9DecoderEnabled, bool, true);
     142             :   DECL_MEDIA_PREF("media.wmf.decoder.thread-count",           PDMWMFThreadCount, int32_t, -1);
     143             :   DECL_MEDIA_PREF("media.wmf.allow-unsupported-resolutions",  PDMWMFAllowUnsupportedResolutions, bool, false);
     144             : #endif
     145           6 :   DECL_MEDIA_PREF("media.decoder.fuzzing.enabled",            PDMFuzzingEnabled, bool, false);
     146           6 :   DECL_MEDIA_PREF("media.decoder.fuzzing.video-output-minimum-interval-ms", PDMFuzzingInterval, uint32_t, 0);
     147           6 :   DECL_MEDIA_PREF("media.decoder.fuzzing.dont-delay-inputexhausted", PDMFuzzingDelayInputExhausted, bool, true);
     148           6 :   DECL_MEDIA_PREF("media.decoder.recycle.enabled",            MediaDecoderCheckRecycling, bool, false);
     149           6 :   DECL_MEDIA_PREF("media.decoder.skip-to-next-key-frame.enabled", MFRSkipToNextKeyFrameEnabled, bool, true);
     150           6 :   DECL_MEDIA_PREF("media.gmp.decoder.enabled",                PDMGMPEnabled, bool, true);
     151           6 :   DECL_MEDIA_PREF("media.gmp.decoder.aac",                    GMPAACPreferred, uint32_t, 0);
     152           6 :   DECL_MEDIA_PREF("media.gmp.decoder.h264",                   GMPH264Preferred, uint32_t, 0);
     153           6 :   DECL_MEDIA_PREF("media.eme.audio.blank",                    EMEBlankAudio, bool, false);
     154           6 :   DECL_MEDIA_PREF("media.eme.video.blank",                    EMEBlankVideo, bool, false);
     155           8 :   DECL_MEDIA_PREF("media.eme.chromium-api.enabled",           EMEChromiumAPIEnabled, bool, false);
     156           6 :   DECL_MEDIA_PREF("media.eme.chromium-api.video-shmems",
     157             :                   EMEChromiumAPIVideoShmemCount,
     158             :                   uint32_t,
     159             :                   3);
     160             : 
     161             :   // MediaDecoderStateMachine
     162           6 :   DECL_MEDIA_PREF("media.suspend-bkgnd-video.enabled",        MDSMSuspendBackgroundVideoEnabled, bool, false);
     163           6 :   DECL_MEDIA_PREF("media.suspend-bkgnd-video.delay-ms",       MDSMSuspendBackgroundVideoDelay, AtomicUint32, SUSPEND_BACKGROUND_VIDEO_DELAY_MS);
     164           6 :   DECL_MEDIA_PREF("media.dormant-on-pause-timeout-ms",        DormantOnPauseTimeout, int32_t, 5000);
     165             : 
     166             :   // WebSpeech
     167           6 :   DECL_MEDIA_PREF("media.webspeech.synth.force_global_queue", WebSpeechForceGlobal, bool, false);
     168           6 :   DECL_MEDIA_PREF("media.webspeech.test.enable",              WebSpeechTestEnabled, bool, false);
     169           6 :   DECL_MEDIA_PREF("media.webspeech.test.fake_fsm_events",     WebSpeechFakeFSMEvents, bool, false);
     170           6 :   DECL_MEDIA_PREF(TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE,   WebSpeechFakeRecognitionService, bool, false);
     171           6 :   DECL_MEDIA_PREF("media.webspeech.recognition.enable",       WebSpeechRecognitionEnabled, bool, false);
     172           6 :   DECL_MEDIA_PREF("media.webspeech.recognition.force_enable", WebSpeechRecognitionForceEnabled, bool, false);
     173             : 
     174           6 :   DECL_MEDIA_PREF("media.num-decode-threads",                 MediaThreadPoolDefaultCount, uint32_t, 4);
     175           6 :   DECL_MEDIA_PREF("media.decoder.limit",                      MediaDecoderLimit, int32_t, MediaDecoderLimitDefault());
     176             : 
     177             : #if defined(RELEASE_OR_BETA)
     178             :   DECL_MEDIA_PREF("media.audio-max-decode-error",             MaxAudioDecodeError, uint32_t, 3);
     179             :   DECL_MEDIA_PREF("media.video-max-decode-error",             MaxVideoDecodeError, uint32_t, 2);
     180             : #else
     181             :   // Take zero tolerance of decoding error in debug for any decoder regression.
     182           6 :   DECL_MEDIA_PREF("media.audio-max-decode-error",             MaxAudioDecodeError, uint32_t, 0);
     183           6 :   DECL_MEDIA_PREF("media.video-max-decode-error",             MaxVideoDecodeError, uint32_t, 0);
     184             : #endif
     185             : 
     186             :   // Ogg
     187           6 :   DECL_MEDIA_PREF("media.ogg.enabled",                        OggEnabled, bool, true);
     188             :   // Flac
     189           6 :   DECL_MEDIA_PREF("media.ogg.flac.enabled",                   FlacInOgg, bool, false);
     190           6 :   DECL_MEDIA_PREF("media.flac.enabled",                       FlacEnabled, bool, true);
     191             : 
     192             :   // Hls
     193           6 :   DECL_MEDIA_PREF("media.hls.enabled",                        HLSEnabled, bool, false);
     194             : 
     195             :   // Both rust/stagefright will be enabled when this is true regardless of 'media.rust.mp4parser'.
     196           6 :   DECL_MEDIA_PREF("media.rust.test_mode",                     RustTestMode, bool, false);
     197             : 
     198             :   // True, it enables rust parser and fallback to stagefright if rust parser fails.
     199             :   // False, it uses stagefright only.
     200           6 :   DECL_MEDIA_PREF("media.rust.mp4parser",                     EnableRustMP4Parser, bool, true);
     201             : 
     202           6 :   DECL_MEDIA_PREF("media.mp4.enabled",                        MP4Enabled, bool, false);
     203             : 
     204             :   // Error/warning handling, Decoder Doctor
     205           6 :   DECL_MEDIA_PREF("media.playback.warnings-as-errors",        MediaWarningsAsErrors, bool, false);
     206           6 :   DECL_MEDIA_PREF("media.playback.warnings-as-errors.stagefright-vs-rust",
     207             :                                                               MediaWarningsAsErrorsStageFrightVsRust, bool, false);
     208             : 
     209             : public:
     210             :   // Manage the singleton:
     211             :   static MediaPrefs& GetSingleton();
     212             :   static bool SingletonExists();
     213             : 
     214             : private:
     215             :   template<class T> friend class StaticAutoPtr;
     216             :   static StaticAutoPtr<MediaPrefs> sInstance;
     217             : 
     218             :   // Default value functions
     219           3 :   static int32_t MediaDecoderLimitDefault()
     220             :   {
     221             : #ifdef MOZ_WIDGET_ANDROID
     222             :     if (jni::GetAPIVersion() < 18) {
     223             :       // Older Android versions have broken support for multiple simultaneous
     224             :       // decoders, see bug 1278574.
     225             :       return 1;
     226             :     }
     227             : #endif
     228             :     // Otherwise, set no decoder limit.
     229           3 :     return -1;
     230             :   }
     231             : 
     232             :   // Creating these to avoid having to include Preferences.h in the .h
     233             :   static void PrefAddVarCache(bool*, const char*, bool);
     234             :   static void PrefAddVarCache(int32_t*, const char*, int32_t);
     235             :   static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
     236             :   static void PrefAddVarCache(float*, const char*, float);
     237             :   static void PrefAddVarCache(AtomicUint32*, const char*, uint32_t);
     238             : 
     239             :   static void AssertMainThread();
     240             : 
     241             :   MediaPrefs();
     242             :   MediaPrefs(const MediaPrefs&) = delete;
     243             :   MediaPrefs& operator=(const MediaPrefs&) = delete;
     244             : };
     245             : 
     246             : #undef DECL_MEDIA_PREF /* Don't need it outside of this file */
     247             : 
     248             : } // namespace mozilla
     249             : 
     250             : #endif /* MEDIA_PREFS_H */

Generated by: LCOV version 1.13