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

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: Move audio_manager to be a regular member of CrasAudioManager. Fix InitializeForTesting Created 5 years, 6 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
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 "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 class AudioManager;
26 }
27
24 namespace chromeos { 28 namespace chromeos {
25 29
26 class AudioDevicesPrefHandler; 30 class AudioDevicesPrefHandler;
27 31
28 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, 32 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
29 public AudioPrefObserver, 33 public AudioPrefObserver,
30 public SessionManagerClient::Observer { 34 public SessionManagerClient::Observer {
31 public: 35 public:
32 typedef std::priority_queue<AudioDevice, 36 typedef std::priority_queue<AudioDevice,
33 std::vector<AudioDevice>, 37 std::vector<AudioDevice>,
(...skipping 22 matching lines...) Expand all
56 60
57 // Called when active audio input node changed. 61 // Called when active audio input node changed.
58 virtual void OnActiveInputNodeChanged(); 62 virtual void OnActiveInputNodeChanged();
59 63
60 protected: 64 protected:
61 AudioObserver(); 65 AudioObserver();
62 virtual ~AudioObserver(); 66 virtual ~AudioObserver();
63 DISALLOW_COPY_AND_ASSIGN(AudioObserver); 67 DISALLOW_COPY_AND_ASSIGN(AudioObserver);
64 }; 68 };
65 69
70 // The wrapper for audio manager methods to be called from this class.
71 // The detail of AudioManager is hidden from CrasAudioHandler.
72 class AudioManagerWrapper {
73 public:
74 virtual ~AudioManagerWrapper();
75 virtual void SetHasInputDevices(bool has_input_devices) = 0;
76
77 protected:
78 AudioManagerWrapper();
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapper);
82 };
83
66 // Sets the global instance. Must be called before any calls to Get(). 84 // Sets the global instance. Must be called before any calls to Get().
85 // Optionally pass audio_manager to use implementation other than
86 // AudioManagerWrapperImpl.
67 static void Initialize( 87 static void Initialize(
68 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 88 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
89 scoped_ptr<AudioManagerWrapper> audio_manager = NULL);
Daniel Erat 2015/06/24 13:37:45 default arguments aren't allowed in cases like thi
cychiang 2015/06/25 05:45:24 Done. Change production code at chrome/browser/chr
69 90
70 // Sets the global instance for testing. 91 // Sets the global instance for testing.
71 static void InitializeForTesting(); 92 static void InitializeForTesting();
72 93
73 // Destroys the global instance. 94 // Destroys the global instance.
74 static void Shutdown(); 95 static void Shutdown();
75 96
76 // Returns true if the global instance is initialized. 97 // Returns true if the global instance is initialized.
77 static bool IsInitialized(); 98 static bool IsInitialized();
78 99
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Swaps the left and right channel of the internal speaker. 203 // Swaps the left and right channel of the internal speaker.
183 // Swap the left and right channel if |swap| is true; otherwise, swap the left 204 // Swap the left and right channel if |swap| is true; otherwise, swap the left
184 // and right channel back to the normal mode. 205 // and right channel back to the normal mode.
185 // If the feature is not supported on the device, nothing happens. 206 // If the feature is not supported on the device, nothing happens.
186 virtual void SwapInternalSpeakerLeftRightChannel(bool swap); 207 virtual void SwapInternalSpeakerLeftRightChannel(bool swap);
187 208
188 // Enables error logging. 209 // Enables error logging.
189 virtual void LogErrors(); 210 virtual void LogErrors();
190 211
191 protected: 212 protected:
192 explicit CrasAudioHandler( 213 explicit CrasAudioHandler(
Daniel Erat 2015/06/24 13:37:45 nit: you don't need 'explicit' here now that this
cychiang 2015/06/25 05:45:24 Done.
193 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 214 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
215 scoped_ptr<AudioManagerWrapper> audio_manager);
194 ~CrasAudioHandler() override; 216 ~CrasAudioHandler() override;
195 217
196 private: 218 private:
197 friend class CrasAudioHandlerTest; 219 friend class CrasAudioHandlerTest;
198 220
221 class AudioManagerWrapperImpl : public AudioManagerWrapper {
222 public:
223 AudioManagerWrapperImpl();
224 ~AudioManagerWrapperImpl() override;
225 void SetHasInputDevices(bool has_input_devices) override;
226
227 private:
228 DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperImpl);
229 };
230
199 // CrasAudioClient::Observer overrides. 231 // CrasAudioClient::Observer overrides.
200 void AudioClientRestarted() override; 232 void AudioClientRestarted() override;
201 void NodesChanged() override; 233 void NodesChanged() override;
202 void ActiveOutputNodeChanged(uint64_t node_id) override; 234 void ActiveOutputNodeChanged(uint64_t node_id) override;
203 void ActiveInputNodeChanged(uint64_t node_id) override; 235 void ActiveInputNodeChanged(uint64_t node_id) override;
204 236
205 // AudioPrefObserver overrides. 237 // AudioPrefObserver overrides.
206 void OnAudioPolicyPrefChanged() override; 238 void OnAudioPolicyPrefChanged() override;
207 239
208 // SessionManagerClient::Observer overrides. 240 // SessionManagerClient::Observer overrides.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 bool is_input, 306 bool is_input,
275 AudioNodeList* new_discovered); 307 AudioNodeList* new_discovered);
276 308
277 // Handles dbus callback for GetNodes. 309 // Handles dbus callback for GetNodes.
278 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); 310 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success);
279 311
280 // Handles the dbus error callback. 312 // Handles the dbus error callback.
281 void HandleGetNodesError(const std::string& error_name, 313 void HandleGetNodesError(const std::string& error_name,
282 const std::string& error_msg); 314 const std::string& error_msg);
283 315
316 // Sets HasInputDevice in AudioManager based on the updated device list.
317 void UpdateAudioManagerHasInputDevices();
318
319 // Sets HasInputDevice in AudioManager to true or false.
320 void SetAudioManagerHasInputDevices(bool has_input_devices);
321
284 // Adds an active node. 322 // Adds an active node.
285 // If there is no active node, |node_id| will be switched to become the 323 // 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 324 // primary active node. Otherwise, it will be added as an additional active
287 // node. 325 // node.
288 void AddActiveNode(uint64_t node_id, bool notify); 326 void AddActiveNode(uint64_t node_id, bool notify);
289 327
290 // Adds |node_id| into additional active nodes. 328 // Adds |node_id| into additional active nodes.
291 void AddAdditionalActiveNode(uint64_t node_id, bool notify); 329 void AddAdditionalActiveNode(uint64_t node_id, bool notify);
292 330
293 // Removes |node_id| from additional active nodes. 331 // Removes |node_id| from additional active nodes.
294 void RemoveActiveNodeInternal(uint64_t node_id, bool notify); 332 void RemoveActiveNodeInternal(uint64_t node_id, bool notify);
295 333
296 enum DeviceStatus { 334 enum DeviceStatus {
297 OLD_DEVICE, 335 OLD_DEVICE,
298 NEW_DEVICE, 336 NEW_DEVICE,
299 CHANGED_DEVICE, 337 CHANGED_DEVICE,
300 }; 338 };
301 339
302 // Checks if |device| is a newly discovered, changed, or existing device for 340 // Checks if |device| is a newly discovered, changed, or existing device for
303 // the nodes sent from NodesChanged signal. 341 // the nodes sent from NodesChanged signal.
304 DeviceStatus CheckDeviceStatus(const AudioDevice& device); 342 DeviceStatus CheckDeviceStatus(const AudioDevice& device);
305 343
306 void NotifyActiveNodeChanged(bool is_input); 344 void NotifyActiveNodeChanged(bool is_input);
307 345
308 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; 346 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
309 base::ObserverList<AudioObserver> observers_; 347 base::ObserverList<AudioObserver> observers_;
310 348
349 // audio_manager_ will point to an AudioManagerWrapperImpl object or
Daniel Erat 2015/06/24 13:37:45 nit: "will hold" would probably be more accurate t
cychiang 2015/06/25 05:45:24 Done.
350 // a mocked AudioManagerWrapper object for testing.
351 scoped_ptr<CrasAudioHandler::AudioManagerWrapper> audio_manager_;
352
311 // Audio data and state. 353 // Audio data and state.
312 AudioDeviceMap audio_devices_; 354 AudioDeviceMap audio_devices_;
313 355
314 AudioDevicePriorityQueue input_devices_pq_; 356 AudioDevicePriorityQueue input_devices_pq_;
315 AudioDevicePriorityQueue output_devices_pq_; 357 AudioDevicePriorityQueue output_devices_pq_;
316 358
317 bool output_mute_on_; 359 bool output_mute_on_;
318 bool input_mute_on_; 360 bool input_mute_on_;
319 int output_volume_; 361 int output_volume_;
320 int input_gain_; 362 int input_gain_;
321 uint64_t active_output_node_id_; 363 uint64_t active_output_node_id_;
322 uint64_t active_input_node_id_; 364 uint64_t active_input_node_id_;
323 bool has_alternative_input_; 365 bool has_alternative_input_;
324 bool has_alternative_output_; 366 bool has_alternative_output_;
325 367
326 bool output_mute_locked_; 368 bool output_mute_locked_;
327 369
328 // Failures are not logged at startup, since CRAS may not be running yet. 370 // Failures are not logged at startup, since CRAS may not be running yet.
329 bool log_errors_; 371 bool log_errors_;
330 372
331 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; 373 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
332 374
333 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); 375 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
334 }; 376 };
335 377
336 } // namespace chromeos 378 } // namespace chromeos
337 379
338 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ 380 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698