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 CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 5 #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "chromeos/audio/audio_device.h" | 14 #include "chromeos/audio/audio_device.h" |
15 #include "chromeos/audio/audio_pref_observer.h" | 15 #include "chromeos/audio/audio_pref_observer.h" |
16 #include "chromeos/dbus/audio_node.h" | 16 #include "chromeos/dbus/audio_node.h" |
17 #include "chromeos/dbus/cras_audio_client.h" | 17 #include "chromeos/dbus/cras_audio_client.h" |
18 #include "chromeos/dbus/session_manager_client.h" | 18 #include "chromeos/dbus/session_manager_client.h" |
19 #include "chromeos/dbus/volume_state.h" | 19 #include "chromeos/dbus/volume_state.h" |
20 | 20 |
21 class PrefRegistrySimple; | 21 class PrefRegistrySimple; |
22 class PrefService; | 22 class PrefService; |
23 | 23 |
24 namespace media { | |
25 | |
Daniel Erat
2015/06/23 14:15:49
nit: delete extra blank line here
cychiang
2015/06/24 08:11:29
Done.
| |
26 class AudioManager; | |
27 } | |
28 | |
24 namespace chromeos { | 29 namespace chromeos { |
25 | 30 |
26 class AudioDevicesPrefHandler; | 31 class AudioDevicesPrefHandler; |
27 | 32 |
28 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, | 33 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
29 public AudioPrefObserver, | 34 public AudioPrefObserver, |
30 public SessionManagerClient::Observer { | 35 public SessionManagerClient::Observer { |
31 public: | 36 public: |
32 typedef std::priority_queue<AudioDevice, | 37 typedef std::priority_queue<AudioDevice, |
33 std::vector<AudioDevice>, | 38 std::vector<AudioDevice>, |
(...skipping 22 matching lines...) Expand all Loading... | |
56 | 61 |
57 // Called when active audio input node changed. | 62 // Called when active audio input node changed. |
58 virtual void OnActiveInputNodeChanged(); | 63 virtual void OnActiveInputNodeChanged(); |
59 | 64 |
60 protected: | 65 protected: |
61 AudioObserver(); | 66 AudioObserver(); |
62 virtual ~AudioObserver(); | 67 virtual ~AudioObserver(); |
63 DISALLOW_COPY_AND_ASSIGN(AudioObserver); | 68 DISALLOW_COPY_AND_ASSIGN(AudioObserver); |
64 }; | 69 }; |
65 | 70 |
71 // The wrapper for audio manager methods to be called from this class. | |
72 // The detail of AudioManager is hidden from CrasAudioHandler. | |
73 class AudioManagerWrapper { | |
74 public: | |
75 virtual ~AudioManagerWrapper(); | |
76 virtual void SetHasInputDevices(bool has_input_devices) = 0; | |
77 | |
78 protected: | |
79 AudioManagerWrapper(); | |
80 | |
81 private: | |
82 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapper); | |
83 }; | |
84 | |
85 // Set audio manager wrapper for test. Must be called before Initialize | |
86 // for testing. CrasAudioHandler will delete this pointer at Shutdown. | |
87 static void SetUpAudioManagerWrapperForTesting( | |
88 CrasAudioHandler::AudioManagerWrapper* test_wrapper); | |
Daniel Erat
2015/06/23 14:15:49
pass scoped_ptr<CrasAudioHandler::AudioManagerWrap
| |
89 | |
66 // Sets the global instance. Must be called before any calls to Get(). | 90 // Sets the global instance. Must be called before any calls to Get(). |
67 static void Initialize( | 91 static void Initialize( |
68 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); | 92 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); |
69 | 93 |
70 // Sets the global instance for testing. | 94 // Sets the global instance for testing. |
71 static void InitializeForTesting(); | 95 static void InitializeForTesting(); |
72 | 96 |
73 // Destroys the global instance. | 97 // Destroys the global instance. |
74 static void Shutdown(); | 98 static void Shutdown(); |
75 | 99 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 virtual void LogErrors(); | 213 virtual void LogErrors(); |
190 | 214 |
191 protected: | 215 protected: |
192 explicit CrasAudioHandler( | 216 explicit CrasAudioHandler( |
193 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); | 217 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); |
194 ~CrasAudioHandler() override; | 218 ~CrasAudioHandler() override; |
195 | 219 |
196 private: | 220 private: |
197 friend class CrasAudioHandlerTest; | 221 friend class CrasAudioHandlerTest; |
198 | 222 |
223 class AudioManagerWrapperImpl : public AudioManagerWrapper { | |
224 public: | |
225 AudioManagerWrapperImpl(); | |
226 ~AudioManagerWrapperImpl() override; | |
227 void SetHasInputDevices(bool has_input_devices) override; | |
228 | |
229 private: | |
230 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperImpl); | |
231 }; | |
232 | |
199 // CrasAudioClient::Observer overrides. | 233 // CrasAudioClient::Observer overrides. |
200 void AudioClientRestarted() override; | 234 void AudioClientRestarted() override; |
201 void NodesChanged() override; | 235 void NodesChanged() override; |
202 void ActiveOutputNodeChanged(uint64_t node_id) override; | 236 void ActiveOutputNodeChanged(uint64_t node_id) override; |
203 void ActiveInputNodeChanged(uint64_t node_id) override; | 237 void ActiveInputNodeChanged(uint64_t node_id) override; |
204 | 238 |
205 // AudioPrefObserver overrides. | 239 // AudioPrefObserver overrides. |
206 void OnAudioPolicyPrefChanged() override; | 240 void OnAudioPolicyPrefChanged() override; |
207 | 241 |
208 // SessionManagerClient::Observer overrides. | 242 // SessionManagerClient::Observer overrides. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 bool is_input, | 308 bool is_input, |
275 AudioNodeList* new_discovered); | 309 AudioNodeList* new_discovered); |
276 | 310 |
277 // Handles dbus callback for GetNodes. | 311 // Handles dbus callback for GetNodes. |
278 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); | 312 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); |
279 | 313 |
280 // Handles the dbus error callback. | 314 // Handles the dbus error callback. |
281 void HandleGetNodesError(const std::string& error_name, | 315 void HandleGetNodesError(const std::string& error_name, |
282 const std::string& error_msg); | 316 const std::string& error_msg); |
283 | 317 |
318 // Sets HasInputDevice in AudioManager based on the updated device list. | |
319 void UpdateAudioManagerHasInputDevices(); | |
320 | |
321 // Sets HasInputDevice in AudioManager to true or false. | |
322 void SetAudioManagerHasInputDevices(bool has_input_devices); | |
323 | |
284 // Adds an active node. | 324 // Adds an active node. |
285 // If there is no active node, |node_id| will be switched to become the | 325 // If there is no active node, |node_id| will be switched to become the |
286 // primary active node. Otherwise, it will be added as an additional active | 326 // primary active node. Otherwise, it will be added as an additional active |
287 // node. | 327 // node. |
288 void AddActiveNode(uint64_t node_id, bool notify); | 328 void AddActiveNode(uint64_t node_id, bool notify); |
289 | 329 |
290 // Adds |node_id| into additional active nodes. | 330 // Adds |node_id| into additional active nodes. |
291 void AddAdditionalActiveNode(uint64_t node_id, bool notify); | 331 void AddAdditionalActiveNode(uint64_t node_id, bool notify); |
292 | 332 |
293 // Removes |node_id| from additional active nodes. | 333 // Removes |node_id| from additional active nodes. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 bool log_errors_; | 369 bool log_errors_; |
330 | 370 |
331 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; | 371 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; |
332 | 372 |
333 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); | 373 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); |
334 }; | 374 }; |
335 | 375 |
336 } // namespace chromeos | 376 } // namespace chromeos |
337 | 377 |
338 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 378 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
OLD | NEW |