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 enum class AudioContentType { | |
25 kMedia, | |
alokp
2017/02/24 17:34:26
Add comments about what they mean.
Should we rena
kmackay
2017/02/24 19:01:06
Done.
| |
26 kAlarm, | |
27 kTts, | |
28 }; | |
29 | |
30 // Observer for volume/mute state changes. This is useful to detect volume | |
31 // changes that occur outside of cast_shell. Add/RemoveVolumeObserver() must not | |
32 // be called synchronously from OnVolumeChange() or OnMuteChange(). | |
33 class VolumeObserver { | |
34 public: | |
35 // Called whenever the volume changes for a given stream |type|. May be called | |
36 // on an arbitrary thread. | |
37 virtual void OnVolumeChange(AudioContentType type, float new_volume) = 0; | |
38 | |
39 // Called whenever the mute state changes for a given stream |type|. May be | |
40 // called on an arbitrary thread. | |
41 virtual void OnMuteChange(AudioContentType type, bool new_muted) = 0; | |
42 | |
43 protected: | |
44 virtual ~VolumeObserver() = default; | |
45 }; | |
46 | |
24 // Provides access to platform-specific media systems and hardware resources. | 47 // Provides access to platform-specific media systems and hardware resources. |
25 // In cast_shell, all usage is from the browser process. An implementation is | 48 // 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 | 49 // assumed to be in an uninitialized state initially. When uninitialized, no |
27 // API calls will be made except for Initialize, which brings the implementation | 50 // 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 | 51 // into an initialized state. A call to Finalize returns the implementation to |
29 // its uninitialized state. The implementation must support multiple | 52 // its uninitialized state. The implementation must support multiple |
30 // transitions between these states, to support resource grant/revoke events and | 53 // 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 | 54 // also to allow multiple unit tests to bring up the media systems in isolation |
32 // from other tests. | 55 // from other tests. |
56 // | |
57 // Volume control must run separately since it needs to be functional even when | |
alokp
2017/02/24 17:34:26
It seems clunky to have a separate Initialize/Fina
kmackay
2017/02/24 19:01:06
I added more detail to the comment.
| |
58 // resources are revoked. Initialize() and Finalize() have no impact on the | |
59 // volume control API; instead, InitializeVolume() is called to initialize the | |
60 // volume control (before any volume control API methods are called), and | |
61 // FinalizeVolume() is called to clean up the volume control. All volume control | |
62 // methods are called on the same thread that calls InitializeVolume(). | |
33 class CHROMECAST_EXPORT CastMediaShlib { | 63 class CHROMECAST_EXPORT CastMediaShlib { |
34 public: | 64 public: |
35 // Observer for audio loopback data. | 65 // Observer for audio loopback data. |
36 class LoopbackAudioObserver { | 66 class LoopbackAudioObserver { |
37 public: | 67 public: |
38 // Called whenever audio data is about to be output. The |timestamp| is the | 68 // Called whenever audio data is about to be output. The |timestamp| is the |
39 // estimated time in microseconds (relative to CLOCK_MONOTONIC_RAW) that | 69 // estimated time in microseconds (relative to CLOCK_MONOTONIC_RAW) that |
40 // the audio will actually be output. |length| is the length of the audio | 70 // 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 | 71 // |data| in bytes. The format of the data is given by |sample_format| and |
42 // |num_channels|. | 72 // |num_channels|. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // being added again first. | 142 // being added again first. |
113 // Once the observer is fully removed (ie. once it is certain that | 143 // Once the observer is fully removed (ie. once it is certain that |
114 // OnLoopbackAudio() will not be called again for the observer), the | 144 // OnLoopbackAudio() will not be called again for the observer), the |
115 // observer's OnRemoved() method must be called. The OnRemoved() method must | 145 // observer's OnRemoved() method must be called. The OnRemoved() method must |
116 // be called once for each time that RemoveLoopbackAudioObserver() is called | 146 // be called once for each time that RemoveLoopbackAudioObserver() is called |
117 // for a given observer, even if the observer was not added. The | 147 // for a given observer, even if the observer was not added. The |
118 // implementation may call OnRemoved() from any thread. | 148 // implementation may call OnRemoved() from any thread. |
119 // This function is optional to implement. | 149 // This function is optional to implement. |
120 static void RemoveLoopbackAudioObserver(LoopbackAudioObserver* observer) | 150 static void RemoveLoopbackAudioObserver(LoopbackAudioObserver* observer) |
121 __attribute__((__weak__)); | 151 __attribute__((__weak__)); |
152 | |
153 // Initializes platform-specific volume control. Only called when volume | |
154 // control is in an uninitialized state. | |
155 static void InitializeVolume(const std::vector<std::string>& argv) | |
156 __attribute__((__weak__)); | |
157 | |
158 // Tears down platform-specific volume control and returns to the | |
159 // uninitialized state. | |
160 static void FinalizeVolume() __attribute__((__weak__)); | |
161 | |
162 // Adds a volume observer. | |
163 static void AddVolumeObserver(VolumeObserver* observer) | |
164 __attribute__((__weak__)); | |
165 // Removes a volume observer. After this is called, the implementation must | |
166 // not call any more methods on the observer. | |
167 static void RemoveVolumeObserver(VolumeObserver* observer) | |
168 __attribute__((__weak__)); | |
169 | |
170 // Gets/sets the output volume for a given audio stream |type|. The volume | |
171 // |level| is in the range [0.0, 1.0]. | |
172 static float GetVolume(AudioContentType type) __attribute__((__weak__)); | |
173 static void SetVolume(AudioContentType type, float level) | |
174 __attribute__((__weak__)); | |
175 | |
176 // Gets/sets the mute state for a given audio stream |type|. | |
177 static bool IsMuted(AudioContentType type) __attribute__((__weak__)); | |
178 static void SetMuted(AudioContentType type, bool muted) | |
179 __attribute__((__weak__)); | |
180 | |
181 // Limits the output volume for a given stream |type| to no more than |limit|. | |
182 // This does not affect the logical volume for the stream type; the volume | |
183 // returned by GetVolume() should not change, and no OnVolumeChange() event | |
184 // should be sent to observers. | |
185 static void SetOutputLimit(AudioContentType type, float limit) | |
186 __attribute__((__weak__)); | |
187 | |
188 // Converts a volume level in the range [0.0, 1.0] to/from a volume in dB. | |
189 // The volume in dB should be decibels SPL at 1m from the device; if that | |
190 // is not known, then the volume in dB should be full-scale (so a volume level | |
191 // of 1.0 would be 0.0 dBFS, and any lower volume level would be negative). | |
192 // May be called from multiple processes. | |
193 static float VolumeToDb(float volume) __attribute__((__weak__)); | |
194 static float DbToVolume(float db) __attribute__((__weak__)); | |
122 }; | 195 }; |
123 | 196 |
124 } // namespace media | 197 } // namespace media |
125 } // namespace chromecast | 198 } // namespace chromecast |
126 | 199 |
127 #endif // CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ | 200 #endif // CHROMECAST_PUBLIC_CAST_MEDIA_SHLIB_H_ |
OLD | NEW |