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