summaryrefslogtreecommitdiffstats
path: root/dom/media/MediaPrefs.h
blob: 7f8191cc1015c3057a8add715780c0b219d490bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef MEDIA_PREFS_H
#define MEDIA_PREFS_H

#ifdef MOZ_WIDGET_ANDROID
#include "GeneratedJNIWrappers.h"
#endif

#include "mozilla/Atomics.h"

// First time MediaPrefs::GetSingleton() needs to be called on the main thread,
// before any of the methods accessing the values are used, but after
// the Preferences system has been initialized.

// The static methods to access the preference value are safe to call
// from any thread after that first call.

// To register a preference, you need to add a line in this file using
// the DECL_MEDIA_PREF macro.
//
// For example this line in the .h:
//   DECL_MEDIA_PREF("media.resampling.enabled",AudioSinkResampling,bool,false);
// means that you can call
//   const bool& var = MediaPrefs::AudioSinkResampling();
// from any thread, you will get the most up to date preference value of
// "media.resampling.enabled".  If the value is not set, the default would be
// false.

#define DECL_MEDIA_PREF(Pref, Name, Type, Default)                      \
 public:                                                                \
  static const Type& Name() {                                           \
    MOZ_ASSERT(SingletonExists());                                      \
    return GetSingleton().mPref##Name.mValue;                           \
  }                                                                     \
                                                                        \
 private:                                                               \
  static const char* Get##Name##PrefName() { return Pref; }             \
  static StripAtomic<Type> Get##Name##PrefDefault() { return Default; } \
  PrefTemplate<Type, Get##Name##PrefDefault, Get##Name##PrefName> mPref##Name

// Custom Definitions.
#define GMP_DEFAULT_ASYNC_SHUTDOWN_TIMEOUT 3000
#define SUSPEND_BACKGROUND_VIDEO_DELAY_MS 10000
#define TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE \
  "media.webspeech.test.fake_recognition_service"

namespace mozilla {

template <class T>
class StaticAutoPtr;

class MediaPrefs final {
  typedef Atomic<bool, Relaxed> AtomicBool;
  typedef Atomic<int32_t, Relaxed> AtomicInt32;
  typedef Atomic<uint32_t, Relaxed> AtomicUint32;

  template <typename T>
  struct StripAtomicImpl {
    typedef T Type;
  };

  template <typename T, MemoryOrdering Order>
  struct StripAtomicImpl<Atomic<T, Order>> {
    typedef T Type;
  };

  template <typename T>
  using StripAtomic = typename StripAtomicImpl<T>::Type;

 private:
  // Since we cannot use const char*, use a function that returns it.
  template <class T, StripAtomic<T> Default(), const char* Pref()>
  class PrefTemplate {
   public:
    PrefTemplate() : mValue(Default()) { Register(Pref()); }
    T mValue;

   private:
    void Register(const char* aPreference) {
      AssertMainThread();
      PrefAddVarCache(&mValue, aPreference, mValue);
    }
  };

  // This is where DECL_MEDIA_PREF for each of the preferences should go.

  // Cache sizes.
  DECL_MEDIA_PREF("media.cache_size", MediaCacheSizeKb, uint32_t, 512000);
  DECL_MEDIA_PREF("media.memory_cache_max_size", MediaMemoryCacheMaxSize,
                  uint32_t, 8192);
  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_resume_threshold", MediaCacheResumeThreshold,
                  int32_t, 10);
  DECL_MEDIA_PREF("media.cache_readahead_limit", MediaCacheReadaheadLimit,
                  int32_t, 30);

  // AudioSink
  DECL_MEDIA_PREF("accessibility.monoaudio.enable", MonoAudio, bool, false);
  DECL_MEDIA_PREF("media.resampling.enabled", AudioSinkResampling, bool, false);
#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);
#else
  DECL_MEDIA_PREF("media.forcestereo.enabled", AudioSinkForceStereo, bool,
                  true);
#endif
  // VideoSink
  DECL_MEDIA_PREF("media.ruin-av-sync.enabled", RuinAvSync, bool, false);

  // Encrypted Media Extensions
  DECL_MEDIA_PREF("media.clearkey.persistent-license.enabled",
                  ClearKeyPersistentLicenseEnabled, bool, false);

  // PlatformDecoderModule
  DECL_MEDIA_PREF("media.gmp.insecure.allow", GMPAllowInsecure, bool, false);
  DECL_MEDIA_PREF("media.eme.enabled", EMEEnabled, bool, false);
  DECL_MEDIA_PREF("media.use-blank-decoder", PDMUseBlankDecoder, bool, false);
  DECL_MEDIA_PREF("media.gpu-process-decoder", PDMUseGPUDecoder, bool, false);
#ifdef MOZ_WIDGET_ANDROID
  DECL_MEDIA_PREF("media.android-media-codec.enabled",
                  PDMAndroidMediaCodecEnabled, bool, false);
  DECL_MEDIA_PREF("media.android-media-codec.preferred",
                  PDMAndroidMediaCodecPreferred, bool, false);
  DECL_MEDIA_PREF(
      "media.navigator.hardware.vp8_encode.acceleration_remote_enabled",
      RemoteMediaCodecVP8EncoderEnabled, bool, false);
#endif
  // WebRTC
  DECL_MEDIA_PREF("media.navigator.mediadatadecoder_enabled",
                  MediaDataDecoderEnabled, bool, false);
#ifdef MOZ_FFMPEG
  DECL_MEDIA_PREF("media.ffmpeg.enabled", PDMFFmpegEnabled, bool, true);
  DECL_MEDIA_PREF("media.libavcodec.allow-obsolete", LibavcodecAllowObsolete,
                  bool, false);
#endif
#if defined(MOZ_FFMPEG) || defined(MOZ_FFVPX)
  DECL_MEDIA_PREF("media.ffmpeg.low-latency.enabled",
                  PDMFFmpegLowLatencyEnabled, bool, false);
#endif
#ifdef MOZ_FFVPX
  DECL_MEDIA_PREF("media.ffvpx.enabled", PDMFFVPXEnabled, bool, true);
#endif
#ifdef XP_WIN
  DECL_MEDIA_PREF("media.wmf.enabled", PDMWMFEnabled, bool, true);
  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);
#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);
  DECL_MEDIA_PREF("media.gmp.decoder.enabled", PDMGMPEnabled, bool, true);
  DECL_MEDIA_PREF("media.eme.audio.blank", EMEBlankAudio, bool, false);
  DECL_MEDIA_PREF("media.eme.video.blank", EMEBlankVideo, bool, false);
  DECL_MEDIA_PREF("media.eme.chromium-api.video-shmems",
                  EMEChromiumAPIVideoShmemCount, uint32_t, 3);

  // MediaDecoderStateMachine
  DECL_MEDIA_PREF("media.suspend-bkgnd-video.enabled",
                  MDSMSuspendBackgroundVideoEnabled, bool, false);
  DECL_MEDIA_PREF("media.suspend-bkgnd-video.delay-ms",
                  MDSMSuspendBackgroundVideoDelay, AtomicUint32,
                  SUSPEND_BACKGROUND_VIDEO_DELAY_MS);
  DECL_MEDIA_PREF("media.dormant-on-pause-timeout-ms", DormantOnPauseTimeout,
                  int32_t, 5000);

  // WebSpeech
  DECL_MEDIA_PREF("media.webspeech.synth.force_global_queue",
                  WebSpeechForceGlobal, bool, false);
  DECL_MEDIA_PREF("media.webspeech.test.enable", WebSpeechTestEnabled, bool,
                  false);
  DECL_MEDIA_PREF("media.webspeech.test.fake_fsm_events",
                  WebSpeechFakeFSMEvents, bool, false);
  DECL_MEDIA_PREF(TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE,
                  WebSpeechFakeRecognitionService, bool, false);
  DECL_MEDIA_PREF("media.webspeech.recognition.enable",
                  WebSpeechRecognitionEnabled, bool, false);
  DECL_MEDIA_PREF("media.webspeech.recognition.force_enable",
                  WebSpeechRecognitionForceEnabled, bool, false);

#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);
#else
  // Take zero tolerance of decoding error in debug for any decoder regression.
  DECL_MEDIA_PREF("media.audio-max-decode-error", MaxAudioDecodeError, uint32_t,
                  0);
  DECL_MEDIA_PREF("media.video-max-decode-error", MaxVideoDecodeError, uint32_t,
                  0);
#endif

  // Ogg
  DECL_MEDIA_PREF("media.ogg.enabled", OggEnabled, bool, true);
  // Flac
  DECL_MEDIA_PREF("media.ogg.flac.enabled", FlacInOgg, bool, false);
  DECL_MEDIA_PREF("media.flac.enabled", FlacEnabled, bool, true);

  // Hls
  DECL_MEDIA_PREF("media.hls.enabled", HLSEnabled, bool, false);

  // Both rust/stagefright will be enabled when this is true regardless of
  // 'media.rust.mp4parser'.
  DECL_MEDIA_PREF("media.rust.test_mode", RustTestMode, bool, false);

  // True, it enables rust parser and fallback to stagefright if rust parser
  // fails. False, it uses stagefright only.
  DECL_MEDIA_PREF("media.rust.mp4parser", EnableRustMP4Parser, bool, true);

  DECL_MEDIA_PREF("media.mp4.enabled", MP4Enabled, bool, false);

  // Error/warning handling, Decoder Doctor
  DECL_MEDIA_PREF("media.playback.warnings-as-errors", MediaWarningsAsErrors,
                  bool, false);
  DECL_MEDIA_PREF("media.playback.warnings-as-errors.stagefright-vs-rust",
                  MediaWarningsAsErrorsStageFrightVsRust, bool, false);

  // resume background video decoding when the cursor is hovering over the tab.
  DECL_MEDIA_PREF("media.resume-bkgnd-video-on-tabhover",
                  ResumeVideoDecodingOnTabHover, bool, false);

  // Enable sandboxing support for cubeb
  DECL_MEDIA_PREF("media.cubeb.sandbox", CubebSandbox, bool, false);
  DECL_MEDIA_PREF("media.videocontrols.lock-video-orientation",
                  VideoOrientationLockEnabled, bool, false);

  // Media Seamless Looping
  DECL_MEDIA_PREF("media.seamless-looping", SeamlessLooping, bool, true);

 public:
  // Manage the singleton:
  static MediaPrefs& GetSingleton();
  static bool SingletonExists();

 private:
  template <class T>
  friend class StaticAutoPtr;
  static StaticAutoPtr<MediaPrefs> sInstance;

  // 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);
  static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
  static void PrefAddVarCache(float*, const char*, float);
  static void PrefAddVarCache(AtomicBool*, const char*, bool);
  static void PrefAddVarCache(AtomicInt32*, const char*, int32_t);
  static void PrefAddVarCache(AtomicUint32*, const char*, uint32_t);

  static void AssertMainThread();

  MediaPrefs();
  MediaPrefs(const MediaPrefs&) = delete;
  MediaPrefs& operator=(const MediaPrefs&) = delete;
};

#undef DECL_MEDIA_PREF /* Don't need it outside of this file */

}  // namespace mozilla

#endif /* MEDIA_PREFS_H */