OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ | 5 #ifndef CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ |
6 #define CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ | 6 #define CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "chromecast_export.h" | 13 #include "chromecast_export.h" |
14 | 14 |
15 namespace chromecast { | 15 namespace chromecast { |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 enum SampleFormat : int; | 18 enum SampleFormat : int; |
19 | 19 |
20 class MediaPipelineBackend; | 20 class MediaPipelineBackend; |
21 struct MediaPipelineDeviceParams; | 21 struct MediaPipelineDeviceParams; |
22 class VideoPlane; | 22 class VideoPlane; |
23 | 23 |
24 // Audio content types for volume control. Each content type has a separate | |
25 // volume and mute state. | |
26 enum class AudioContentType { | |
27 kMedia, // Normal audio playback; also used for system sound effects. | |
28 kAlarm, // Alarm sounds. | |
29 kCommunication, // Voice communication, eg assistant TTS. | |
30 }; | |
31 | |
32 // Observer for volume/mute state changes. This is useful to detect volume | |
33 // changes that occur outside of cast_shell. Add/RemoveVolumeObserver() must not | |
34 // be called synchronously from OnVolumeChange() or OnMuteChange(). | |
35 class VolumeObserver { | |
36 public: | |
37 // Called whenever the volume changes for a given stream |type|. May be called | |
38 // on an arbitrary thread. | |
39 virtual void OnVolumeChange(AudioContentType type, float new_volume) = 0; | |
40 | |
41 // Called whenever the mute state changes for a given stream |type|. May be | |
42 // called on an arbitrary thread. | |
43 virtual void OnMuteChange(AudioContentType type, bool new_muted) = 0; | |
44 | |
45 protected: | |
46 virtual ~VolumeObserver() = default; | |
47 }; | |
48 | |
24 // Provides access to platform-specific media systems and hardware resources. | 49 // Provides access to platform-specific media systems and hardware resources. |
25 // In cast_shell, all usage is from the browser process. An implementation is | 50 // In cast_shell, all usage is from the browser process. An implementation is |
26 // assumed to be in an uninitialized state initially. When uninitialized, no | 51 // assumed to be in an uninitialized state initially. When uninitialized, no |
27 // API calls will be made except for Initialize, which brings the implementation | 52 // API calls will be made except for Initialize, which brings the implementation |
28 // into an initialized state. A call to Finalize returns the implementation to | 53 // into an initialized state. A call to Finalize returns the implementation to |
29 // its uninitialized state. The implementation must support multiple | 54 // its uninitialized state. The implementation must support multiple |
30 // transitions between these states, to support resource grant/revoke events and | 55 // transitions between these states, to support resource grant/revoke events and |
31 // also to allow multiple unit tests to bring up the media systems in isolation | 56 // also to allow multiple unit tests to bring up the media systems in isolation |
32 // from other tests. | 57 // from other tests. |
58 // | |
59 // Volume control must run separately since it needs to be functional even when | |
60 // resources are revoked; since Finalize() is called when resources are revoked, | |
61 // and we need volume control to keep working, we need separate initialization. | |
62 // Therefore, Initialize() and Finalize() have no impact on the volume control | |
63 // API; instead, InitializeVolume() is called to initialize the volume control | |
64 // (before any volume control API methods are called), and FinalizeVolume() is | |
65 // called to clean up the volume control. All volume control methods are called | |
66 // on the same thread that calls InitializeVolume(). | |
halliwell
2017/02/24 21:37:21
This is kind of clumsy. Would it be clearer just
kmackay
2017/02/24 23:53:29
Maybe? But the new class would probably ideally li
halliwell
2017/02/25 00:43:46
Yep, agreed, keeping in same shared lib makes sens
kmackay
2017/02/25 02:01:08
Sure, sounds fine to me
kmackay
2017/02/25 05:57:02
I wouldn't implement it like VideoPlane though; I
kmackay
2017/02/26 21:16:42
Done.
| |
33 class CHROMECAST_EXPORT CastMediaShlib { | 67 class CHROMECAST_EXPORT CastMediaShlib { |
34 public: | 68 public: |
35 // Observer for audio loopback data. | 69 // Observer for audio loopback data. |
36 class LoopbackAudioObserver { | 70 class LoopbackAudioObserver { |
37 public: | 71 public: |
38 // Called whenever audio data is about to be output. The |timestamp| is the | 72 // Called whenever audio data is about to be output. The |timestamp| is the |
39 // estimated time in microseconds (relative to CLOCK_MONOTONIC_RAW) that | 73 // estimated time in microseconds (relative to CLOCK_MONOTONIC_RAW) that |
40 // the audio will actually be output. |length| is the length of the audio | 74 // the audio will actually be output. |length| is the length of the audio |
41 // |data| in bytes. The format of the data is given by |sample_format| and | 75 // |data| in bytes. The format of the data is given by |sample_format| and |
42 // |num_channels|. | 76 // |num_channels|. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // being added again first. | 146 // being added again first. |
113 // Once the observer is fully removed (ie. once it is certain that | 147 // Once the observer is fully removed (ie. once it is certain that |
114 // OnLoopbackAudio() will not be called again for the observer), the | 148 // OnLoopbackAudio() will not be called again for the observer), the |
115 // observer's OnRemoved() method must be called. The OnRemoved() method must | 149 // observer's OnRemoved() method must be called. The OnRemoved() method must |
116 // be called once for each time that RemoveLoopbackAudioObserver() is called | 150 // be called once for each time that RemoveLoopbackAudioObserver() is called |
117 // for a given observer, even if the observer was not added. The | 151 // for a given observer, even if the observer was not added. The |
118 // implementation may call OnRemoved() from any thread. | 152 // implementation may call OnRemoved() from any thread. |
119 // This function is optional to implement. | 153 // This function is optional to implement. |
120 static void RemoveLoopbackAudioObserver(LoopbackAudioObserver* observer) | 154 static void RemoveLoopbackAudioObserver(LoopbackAudioObserver* observer) |
121 __attribute__((__weak__)); | 155 __attribute__((__weak__)); |
156 | |
157 // Initializes platform-specific volume control. Only called when volume | |
158 // control is in an uninitialized state. | |
159 static void InitializeVolume(const std::vector<std::string>& argv) | |
160 __attribute__((__weak__)); | |
161 | |
162 // Tears down platform-specific volume control and returns to the | |
163 // uninitialized state. | |
164 static void FinalizeVolume() __attribute__((__weak__)); | |
165 | |
166 // Adds a volume observer. | |
167 static void AddVolumeObserver(VolumeObserver* observer) | |
168 __attribute__((__weak__)); | |
169 // Removes a volume observer. After this is called, the implementation must | |
170 // not call any more methods on the observer. | |
171 static void RemoveVolumeObserver(VolumeObserver* observer) | |
172 __attribute__((__weak__)); | |
173 | |
174 // Gets/sets the output volume for a given audio stream |type|. The volume | |
175 // |level| is in the range [0.0, 1.0]. | |
176 static float GetVolume(AudioContentType type) __attribute__((__weak__)); | |
177 static void SetVolume(AudioContentType type, float level) | |
178 __attribute__((__weak__)); | |
179 | |
180 // Gets/sets the mute state for a given audio stream |type|. | |
181 static bool IsMuted(AudioContentType type) __attribute__((__weak__)); | |
182 static void SetMuted(AudioContentType type, bool muted) | |
183 __attribute__((__weak__)); | |
184 | |
185 // Limits the output volume for a given stream |type| to no more than |limit|. | |
186 // This does not affect the logical volume for the stream type; the volume | |
187 // returned by GetVolume() should not change, and no OnVolumeChange() event | |
188 // should be sent to observers. | |
189 static void SetOutputLimit(AudioContentType type, float limit) | |
190 __attribute__((__weak__)); | |
191 | |
192 // Converts a volume level in the range [0.0, 1.0] to/from a volume in dB. | |
193 // The volume in dB should be decibels SPL at 1m from the device; if that | |
194 // is not known, then the volume in dB should be full-scale (so a volume level | |
195 // of 1.0 would be 0.0 dBFS, and any lower volume level would be negative). | |
196 // May be called from multiple processes. | |
197 static float VolumeToDb(float volume) __attribute__((__weak__)); | |
198 static float DbToVolume(float db) __attribute__((__weak__)); | |
122 }; | 199 }; |
123 | 200 |
124 } // namespace media | 201 } // namespace media |
125 } // namespace chromecast | 202 } // namespace chromecast |
126 | 203 |
127 #endif // CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ | 204 #endif // CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ |
OLD | NEW |