Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chromeos/audio/cras_audio_handler.h

Issue 1186293003: Implement HasInputDevices in CrasAudioManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add SetHasInputDevice in FakeAudioManager Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/audio/audio_device.h ('k') | chromeos/audio/cras_audio_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "chromeos/audio/audio_device.h" 15 #include "chromeos/audio/audio_device.h"
16 #include "chromeos/audio/audio_pref_observer.h" 16 #include "chromeos/audio/audio_pref_observer.h"
17 #include "chromeos/dbus/audio_node.h" 17 #include "chromeos/dbus/audio_node.h"
18 #include "chromeos/dbus/cras_audio_client.h" 18 #include "chromeos/dbus/cras_audio_client.h"
19 #include "chromeos/dbus/session_manager_client.h" 19 #include "chromeos/dbus/session_manager_client.h"
20 #include "chromeos/dbus/volume_state.h" 20 #include "chromeos/dbus/volume_state.h"
21 21
22 class PrefRegistrySimple; 22 class PrefRegistrySimple;
23 class PrefService; 23 class PrefService;
24 24
25 namespace media {
26 class AudioManager;
stevenjb 2015/07/01 21:11:53 Is this needed? I don't see any references to it b
27 }
28
25 namespace chromeos { 29 namespace chromeos {
26 30
27 class AudioDevicesPrefHandler; 31 class AudioDevicesPrefHandler;
28 32
29 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, 33 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
30 public AudioPrefObserver, 34 public AudioPrefObserver,
31 public SessionManagerClient::Observer { 35 public SessionManagerClient::Observer {
32 public: 36 public:
33 typedef std::priority_queue<AudioDevice, 37 typedef std::priority_queue<AudioDevice,
34 std::vector<AudioDevice>, 38 std::vector<AudioDevice>,
(...skipping 22 matching lines...) Expand all
57 61
58 // Called when active audio input node changed. 62 // Called when active audio input node changed.
59 virtual void OnActiveInputNodeChanged(); 63 virtual void OnActiveInputNodeChanged();
60 64
61 protected: 65 protected:
62 AudioObserver(); 66 AudioObserver();
63 virtual ~AudioObserver(); 67 virtual ~AudioObserver();
64 DISALLOW_COPY_AND_ASSIGN(AudioObserver); 68 DISALLOW_COPY_AND_ASSIGN(AudioObserver);
65 }; 69 };
66 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 // The implementation of AudioManagerWrapper for production code.
86 class AudioManagerWrapperImpl : public AudioManagerWrapper {
87 public:
88 AudioManagerWrapperImpl();
89 ~AudioManagerWrapperImpl() override;
90 void SetHasInputDevices(bool has_input_devices) override;
91
92 private:
93 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperImpl);
94 };
95
67 // Sets the global instance. Must be called before any calls to Get(). 96 // Sets the global instance. Must be called before any calls to Get().
97 // An implemantation of AudioManagerWrapper is passed to constructor
98 // of CrasAudioHandler. It should be AudioManagerWrapperImpl
99 // for production code.
68 static void Initialize( 100 static void Initialize(
69 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 101 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
102 scoped_ptr<AudioManagerWrapper> audio_manager);
70 103
71 // Sets the global instance for testing. 104 // Sets the global instance for testing.
72 static void InitializeForTesting(); 105 static void InitializeForTesting();
73 106
74 // Destroys the global instance. 107 // Destroys the global instance.
75 static void Shutdown(); 108 static void Shutdown();
76 109
77 // Returns true if the global instance is initialized. 110 // Returns true if the global instance is initialized.
78 static bool IsInitialized(); 111 static bool IsInitialized();
79 112
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // If necessary, sets the starting point for re-discovering the active HDMI 225 // If necessary, sets the starting point for re-discovering the active HDMI
193 // output device caused by device entering/exiting docking mode, HDMI display 226 // output device caused by device entering/exiting docking mode, HDMI display
194 // changing resolution, or chromeos device suspend/resume. If 227 // changing resolution, or chromeos device suspend/resume. If
195 // |force_rediscovering| is true, it will force to set the starting point for 228 // |force_rediscovering| is true, it will force to set the starting point for
196 // re-discovering the active HDMI output device again if it has been in the 229 // re-discovering the active HDMI output device again if it has been in the
197 // middle of rediscovering the HDMI active output device. 230 // middle of rediscovering the HDMI active output device.
198 virtual void SetActiveHDMIOutoutRediscoveringIfNecessary( 231 virtual void SetActiveHDMIOutoutRediscoveringIfNecessary(
199 bool force_rediscovering); 232 bool force_rediscovering);
200 233
201 protected: 234 protected:
202 explicit CrasAudioHandler( 235 CrasAudioHandler(scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
203 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 236 scoped_ptr<AudioManagerWrapper> audio_manager);
204 ~CrasAudioHandler() override; 237 ~CrasAudioHandler() override;
205 238
206 private: 239 private:
207 friend class CrasAudioHandlerTest; 240 friend class CrasAudioHandlerTest;
208 241
242 // The implementation of AudioManagerWrapper for testing.
243 // This implementation is used in unittest which needs CrasAudioHandler
244 // while there is no AudioManagerCras, e.g.: running unittests related
245 // to Cras on Linux.
246 class AudioManagerWrapperForTesting : public AudioManagerWrapper {
247 public:
248 AudioManagerWrapperForTesting();
249 ~AudioManagerWrapperForTesting() override;
250 void SetHasInputDevices(bool has_input_devices) override;
251
252 private:
253 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperForTesting);
254 };
255
209 // CrasAudioClient::Observer overrides. 256 // CrasAudioClient::Observer overrides.
210 void AudioClientRestarted() override; 257 void AudioClientRestarted() override;
211 void NodesChanged() override; 258 void NodesChanged() override;
212 void ActiveOutputNodeChanged(uint64_t node_id) override; 259 void ActiveOutputNodeChanged(uint64_t node_id) override;
213 void ActiveInputNodeChanged(uint64_t node_id) override; 260 void ActiveInputNodeChanged(uint64_t node_id) override;
214 261
215 // AudioPrefObserver overrides. 262 // AudioPrefObserver overrides.
216 void OnAudioPolicyPrefChanged() override; 263 void OnAudioPolicyPrefChanged() override;
217 264
218 // SessionManagerClient::Observer overrides. 265 // SessionManagerClient::Observer overrides.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 bool is_input, 331 bool is_input,
285 AudioNodeList* new_discovered); 332 AudioNodeList* new_discovered);
286 333
287 // Handles dbus callback for GetNodes. 334 // Handles dbus callback for GetNodes.
288 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); 335 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success);
289 336
290 // Handles the dbus error callback. 337 // Handles the dbus error callback.
291 void HandleGetNodesError(const std::string& error_name, 338 void HandleGetNodesError(const std::string& error_name,
292 const std::string& error_msg); 339 const std::string& error_msg);
293 340
341 // Sets HasInputDevice in AudioManager based on the updated device list.
342 void UpdateAudioManagerHasInputDevices();
343
344 // Sets HasInputDevice in AudioManager to true or false.
345 void SetAudioManagerHasInputDevices(bool has_input_devices);
346
294 // Adds an active node. 347 // Adds an active node.
295 // If there is no active node, |node_id| will be switched to become the 348 // If there is no active node, |node_id| will be switched to become the
296 // primary active node. Otherwise, it will be added as an additional active 349 // primary active node. Otherwise, it will be added as an additional active
297 // node. 350 // node.
298 void AddActiveNode(uint64_t node_id, bool notify); 351 void AddActiveNode(uint64_t node_id, bool notify);
299 352
300 // Adds |node_id| into additional active nodes. 353 // Adds |node_id| into additional active nodes.
301 void AddAdditionalActiveNode(uint64_t node_id, bool notify); 354 void AddAdditionalActiveNode(uint64_t node_id, bool notify);
302 355
303 // Removes |node_id| from additional active nodes. 356 // Removes |node_id| from additional active nodes.
(...skipping 17 matching lines...) Expand all
321 374
322 // Checks if |device| is a newly discovered, changed, or existing device for 375 // Checks if |device| is a newly discovered, changed, or existing device for
323 // the nodes sent from NodesChanged signal. 376 // the nodes sent from NodesChanged signal.
324 DeviceStatus CheckDeviceStatus(const AudioDevice& device); 377 DeviceStatus CheckDeviceStatus(const AudioDevice& device);
325 378
326 void NotifyActiveNodeChanged(bool is_input); 379 void NotifyActiveNodeChanged(bool is_input);
327 380
328 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; 381 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
329 base::ObserverList<AudioObserver> observers_; 382 base::ObserverList<AudioObserver> observers_;
330 383
384 // audio_manager_ will hold an AudioManagerWrapperImpl object or
385 // a mocked AudioManagerWrapper object for testing.
386 scoped_ptr<CrasAudioHandler::AudioManagerWrapper> audio_manager_;
387
331 // Audio data and state. 388 // Audio data and state.
332 AudioDeviceMap audio_devices_; 389 AudioDeviceMap audio_devices_;
333 390
334 AudioDevicePriorityQueue input_devices_pq_; 391 AudioDevicePriorityQueue input_devices_pq_;
335 AudioDevicePriorityQueue output_devices_pq_; 392 AudioDevicePriorityQueue output_devices_pq_;
336 393
337 bool output_mute_on_; 394 bool output_mute_on_;
338 bool input_mute_on_; 395 bool input_mute_on_;
339 int output_volume_; 396 int output_volume_;
340 int input_gain_; 397 int input_gain_;
(...skipping 13 matching lines...) Expand all
354 bool hdmi_rediscovering_; 411 bool hdmi_rediscovering_;
355 412
356 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; 413 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
357 414
358 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); 415 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
359 }; 416 };
360 417
361 } // namespace chromeos 418 } // namespace chromeos
362 419
363 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ 420 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
OLDNEW
« no previous file with comments | « chromeos/audio/audio_device.h ('k') | chromeos/audio/cras_audio_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698