OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMECAST_PUBLIC_VOLUME_CONTROL_H_ |
| 6 #define CHROMECAST_PUBLIC_VOLUME_CONTROL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "chromecast_export.h" |
| 12 |
| 13 namespace chromecast { |
| 14 namespace media { |
| 15 |
| 16 // Audio content types for volume control. Each content type has a separate |
| 17 // volume and mute state. |
| 18 enum class AudioContentType { |
| 19 kMedia, // Normal audio playback; also used for system sound effects. |
| 20 kAlarm, // Alarm sounds. |
| 21 kCommunication, // Voice communication, eg assistant TTS. |
| 22 }; |
| 23 |
| 24 // Observer for volume/mute state changes. This is useful to detect volume |
| 25 // changes that occur outside of cast_shell. Add/RemoveVolumeObserver() must not |
| 26 // be called synchronously from OnVolumeChange() or OnMuteChange(). |
| 27 class VolumeObserver { |
| 28 public: |
| 29 // Called whenever the volume changes for a given stream |type|. May be called |
| 30 // on an arbitrary thread. |
| 31 virtual void OnVolumeChange(AudioContentType type, float new_volume) = 0; |
| 32 |
| 33 // Called whenever the mute state changes for a given stream |type|. May be |
| 34 // called on an arbitrary thread. |
| 35 virtual void OnMuteChange(AudioContentType type, bool new_muted) = 0; |
| 36 |
| 37 protected: |
| 38 virtual ~VolumeObserver() = default; |
| 39 }; |
| 40 |
| 41 // Volume control is initialized once when cast_shell starts up, and finalized |
| 42 // on shutdown. Revoking resources has no effect on volume control. All volume |
| 43 // control methods are called on the same thread that calls Initialize(). |
| 44 class CHROMECAST_EXPORT VolumeControl { |
| 45 public: |
| 46 // Initializes platform-specific volume control. Only called when volume |
| 47 // control is in an uninitialized state. The implementation of this method |
| 48 // should load previously set volume and mute states from persistent storage, |
| 49 // so that the volume and mute are preserved across reboots. |
| 50 static void Initialize(const std::vector<std::string>& argv) |
| 51 __attribute__((__weak__)); |
| 52 |
| 53 // Tears down platform-specific volume control and returns to the |
| 54 // uninitialized state. |
| 55 static void Finalize() __attribute__((__weak__)); |
| 56 |
| 57 // Adds a volume observer. |
| 58 static void AddVolumeObserver(VolumeObserver* observer) |
| 59 __attribute__((__weak__)); |
| 60 // Removes a volume observer. After this is called, the implementation must |
| 61 // not call any more methods on the observer. |
| 62 static void RemoveVolumeObserver(VolumeObserver* observer) |
| 63 __attribute__((__weak__)); |
| 64 |
| 65 // Gets/sets the output volume for a given audio stream |type|. The volume |
| 66 // |level| is in the range [0.0, 1.0]. |
| 67 static float GetVolume(AudioContentType type) __attribute__((__weak__)); |
| 68 static void SetVolume(AudioContentType type, float level) |
| 69 __attribute__((__weak__)); |
| 70 |
| 71 // Gets/sets the mute state for a given audio stream |type|. |
| 72 static bool IsMuted(AudioContentType type) __attribute__((__weak__)); |
| 73 static void SetMuted(AudioContentType type, bool muted) |
| 74 __attribute__((__weak__)); |
| 75 |
| 76 // Limits the output volume for a given stream |type| to no more than |limit|. |
| 77 // This does not affect the logical volume for the stream type; the volume |
| 78 // returned by GetVolume() should not change, and no OnVolumeChange() event |
| 79 // should be sent to observers. |
| 80 static void SetOutputLimit(AudioContentType type, float limit) |
| 81 __attribute__((__weak__)); |
| 82 |
| 83 // Converts a volume level in the range [0.0, 1.0] to/from a volume in dB. |
| 84 // The volume in dB should be full-scale (so a volume level of 1.0 would be |
| 85 // 0.0 dBFS, and any lower volume level would be negative). |
| 86 // May be called from multiple processes. |
| 87 static float VolumeToDbFS(float volume) __attribute__((__weak__)); |
| 88 static float DbFSToVolume(float dbfs) __attribute__((__weak__)); |
| 89 }; |
| 90 |
| 91 } // namespace media |
| 92 } // namespace chromecast |
| 93 |
| 94 #endif // CHROMECAST_PUBLIC_VOLUME_CONTROL_H_ |
OLD | NEW |