Bug 1852754: part 9) Add tests for dynamically loading <link rel="prefetch"> elements...
[gecko.git] / dom / media / CubebUtils.h
blob03512ec5f543e8105f7f0be6b0c0558727dcee82
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #if !defined(CubebUtils_h_)
8 # define CubebUtils_h_
10 # include "cubeb/cubeb.h"
12 # include "AudioSampleFormat.h"
13 # include "nsString.h"
15 class AudioDeviceInfo;
17 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(cubeb_stream_prefs)
19 namespace mozilla {
21 class CallbackThreadRegistry;
23 namespace CubebUtils {
25 typedef cubeb_devid AudioDeviceID;
27 template <AudioSampleFormat N>
28 struct ToCubebFormat {
29 static const cubeb_sample_format value = CUBEB_SAMPLE_FLOAT32NE;
32 template <>
33 struct ToCubebFormat<AUDIO_FORMAT_S16> {
34 static const cubeb_sample_format value = CUBEB_SAMPLE_S16NE;
37 // Initialize Audio Library. Some Audio backends require initializing the
38 // library before using it.
39 void InitLibrary();
41 // Shutdown Audio Library. Some Audio backends require shutting down the
42 // library after using it.
43 void ShutdownLibrary();
45 bool SandboxEnabled();
47 // Returns the maximum number of channels supported by the audio hardware.
48 uint32_t MaxNumberOfChannels();
50 // Get the sample rate the hardware/mixer runs at. Thread safe.
51 uint32_t PreferredSampleRate(bool aShouldResistFingerprinting);
53 // Initialize a cubeb stream. A pass through wrapper for cubeb_stream_init,
54 // that can simulate streams that are very slow to start, by setting the pref
55 // media.cubeb.slow_stream_init_ms.
56 int CubebStreamInit(cubeb* context, cubeb_stream** stream,
57 char const* stream_name, cubeb_devid input_device,
58 cubeb_stream_params* input_stream_params,
59 cubeb_devid output_device,
60 cubeb_stream_params* output_stream_params,
61 uint32_t latency_frames, cubeb_data_callback data_callback,
62 cubeb_state_callback state_callback, void* user_ptr);
64 enum Side { Input, Output };
66 double GetVolumeScale();
67 bool GetFirstStream();
68 cubeb* GetCubebContext();
69 void ReportCubebStreamInitFailure(bool aIsFirstStream);
70 void ReportCubebBackendUsed();
71 uint32_t GetCubebPlaybackLatencyInMilliseconds();
72 uint32_t GetCubebMTGLatencyInFrames(cubeb_stream_params* params);
73 bool CubebLatencyPrefSet();
74 void GetCurrentBackend(nsAString& aBackend);
75 cubeb_stream_prefs GetDefaultStreamPrefs(cubeb_device_type aType);
76 char* GetForcedOutputDevice();
77 // No-op on all platforms but Android, where it tells the device's AudioManager
78 // to switch to "communication mode", which might change audio routing,
79 // bluetooth communication type, etc.
80 void SetInCommunication(bool aInCommunication);
81 // Returns true if the output streams should be routed like a stream containing
82 // voice data, and not generic audio. This can influence audio processing and
83 // device selection.
84 bool RouteOutputAsVoice();
85 // Returns, in seconds, the roundtrip latency Gecko thinks there is between the
86 // default input and output devices. This is for diagnosing purposes, the
87 // latency figures are best used directly from the cubeb streams themselves, as
88 // the devices being used matter. This is blocking.
89 bool EstimatedRoundTripLatencyDefaultDevices(double* aMean, double* aStdDev);
91 # ifdef MOZ_WIDGET_ANDROID
92 int32_t AndroidGetAudioOutputSampleRate();
93 int32_t AndroidGetAudioOutputFramesPerBuffer();
94 # endif
96 # ifdef ENABLE_SET_CUBEB_BACKEND
97 void ForceSetCubebContext(cubeb* aCubebContext);
98 # endif
99 } // namespace CubebUtils
100 } // namespace mozilla
102 #endif // CubebUtils_h_