| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ |
| 6 #define EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ | 6 #define EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/linked_ptr.h" | |
| 14 #include "extensions/common/api/audio.h" | 13 #include "extensions/common/api/audio.h" |
| 15 | 14 |
| 16 namespace extensions { | 15 namespace extensions { |
| 17 | 16 |
| 18 using OutputInfo = std::vector<linked_ptr<api::audio::OutputDeviceInfo>>; | 17 using OutputInfo = std::vector<api::audio::OutputDeviceInfo>; |
| 19 using InputInfo = std::vector<linked_ptr<api::audio::InputDeviceInfo>>; | 18 using InputInfo = std::vector<api::audio::InputDeviceInfo>; |
| 20 using DeviceIdList = std::vector<std::string>; | 19 using DeviceIdList = std::vector<std::string>; |
| 21 using DeviceInfoList = std::vector<linked_ptr<api::audio::AudioDeviceInfo>>; | 20 using DeviceInfoList = std::vector<api::audio::AudioDeviceInfo>; |
| 22 | 21 |
| 23 class AudioService { | 22 class AudioService { |
| 24 public: | 23 public: |
| 25 class Observer { | 24 class Observer { |
| 26 public: | 25 public: |
| 27 // Called when anything changes to the audio device configuration. | 26 // Called when anything changes to the audio device configuration. |
| 28 virtual void OnDeviceChanged() = 0; | 27 virtual void OnDeviceChanged() = 0; |
| 29 | 28 |
| 30 // Called when the sound level of an active audio device changes. | 29 // Called when the sound level of an active audio device changes. |
| 31 virtual void OnLevelChanged(const std::string& id, int level) = 0; | 30 virtual void OnLevelChanged(const std::string& id, int level) = 0; |
| 32 | 31 |
| 33 // Called when the mute state of audio input/output changes. | 32 // Called when the mute state of audio input/output changes. |
| 34 virtual void OnMuteChanged(bool is_input, bool is_muted) = 0; | 33 virtual void OnMuteChanged(bool is_input, bool is_muted) = 0; |
| 35 | 34 |
| 36 // Called when the audio devices change, either new devices being added, or | 35 // Called when the audio devices change, either new devices being added, or |
| 37 // existing devices being removed. | 36 // existing devices being removed. |
| 38 virtual void OnDevicesChanged(const DeviceInfoList&) = 0; | 37 virtual void OnDevicesChanged(const DeviceInfoList&) = 0; |
| 39 | 38 |
| 40 protected: | 39 protected: |
| 41 virtual ~Observer() {} | 40 virtual ~Observer() {} |
| 42 }; | 41 }; |
| 43 | 42 |
| 44 // Callback type for completing to get audio device information. | |
| 45 typedef base::Callback<void(const OutputInfo&, const InputInfo&, bool)> | |
| 46 GetInfoCallback; | |
| 47 | |
| 48 // Creates a platform-specific AudioService instance. | 43 // Creates a platform-specific AudioService instance. |
| 49 static AudioService* CreateInstance(); | 44 static AudioService* CreateInstance(); |
| 50 | 45 |
| 51 virtual ~AudioService() {} | 46 virtual ~AudioService() {} |
| 52 | 47 |
| 53 // Called by listeners to this service to add/remove themselves as observers. | 48 // Called by listeners to this service to add/remove themselves as observers. |
| 54 virtual void AddObserver(Observer* observer) = 0; | 49 virtual void AddObserver(Observer* observer) = 0; |
| 55 virtual void RemoveObserver(Observer* observer) = 0; | 50 virtual void RemoveObserver(Observer* observer) = 0; |
| 56 | 51 |
| 57 // Start to query audio device information. Should be called on UI thread. | 52 // Start to query audio device information. Should be called on UI thread. |
| 58 // The |callback| will be invoked once the query is completed. | 53 // Populates |output_info_out| and |input_info_out| with the results. |
| 59 virtual void StartGetInfo(const GetInfoCallback& callback) = 0; | 54 // Returns true on success. |
| 55 virtual bool GetInfo(OutputInfo* output_info_out, |
| 56 InputInfo* input_info_out) = 0; |
| 60 | 57 |
| 61 // Sets the active devices to the devices specified by |device_list|. | 58 // Sets the active devices to the devices specified by |device_list|. |
| 62 // It can pass in the "complete" active device list of either input | 59 // It can pass in the "complete" active device list of either input |
| 63 // devices, or output devices, or both. If only input devices are passed in, | 60 // devices, or output devices, or both. If only input devices are passed in, |
| 64 // it will only change the input devices' active status, output devices will | 61 // it will only change the input devices' active status, output devices will |
| 65 // NOT be changed; similarly for the case if only output devices are passed. | 62 // NOT be changed; similarly for the case if only output devices are passed. |
| 66 // If the devices specified in |new_active_ids| are already active, they will | 63 // If the devices specified in |new_active_ids| are already active, they will |
| 67 // remain active. Otherwise, the old active devices will be de-activated | 64 // remain active. Otherwise, the old active devices will be de-activated |
| 68 // before we activate the new devices with the same type(input/output). | 65 // before we activate the new devices with the same type(input/output). |
| 69 virtual void SetActiveDevices(const DeviceIdList& device_list) = 0; | 66 virtual void SetActiveDevices(const DeviceIdList& device_list) = 0; |
| 70 | 67 |
| 71 // Set the muted and volume/gain properties of a device. | 68 // Set the muted and volume/gain properties of a device. |
| 72 virtual bool SetDeviceProperties(const std::string& device_id, | 69 virtual bool SetDeviceProperties(const std::string& device_id, |
| 73 bool muted, | 70 bool muted, |
| 74 int volume, | 71 int volume, |
| 75 int gain) = 0; | 72 int gain) = 0; |
| 76 | 73 |
| 77 protected: | 74 protected: |
| 78 AudioService() {} | 75 AudioService() {} |
| 79 | 76 |
| 80 private: | 77 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(AudioService); | 78 DISALLOW_COPY_AND_ASSIGN(AudioService); |
| 82 }; | 79 }; |
| 83 | 80 |
| 84 } // namespace extensions | 81 } // namespace extensions |
| 85 | 82 |
| 86 #endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ | 83 #endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_ |
| OLD | NEW |