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
3 // found in the LICENSE file.
4 
5 #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <queue>
12 #include <string>
13 #include <vector>
14 
15 #include "base/component_export.h"
16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h"
20 #include "base/optional.h"
21 #include "base/timer/timer.h"
22 #include "chromeos/audio/audio_device.h"
23 #include "chromeos/audio/audio_devices_pref_handler.h"
24 #include "chromeos/audio/audio_pref_observer.h"
25 #include "chromeos/dbus/audio/audio_node.h"
26 #include "chromeos/dbus/audio/cras_audio_client.h"
27 #include "chromeos/dbus/audio/volume_state.h"
28 #include "media/base/video_facing.h"
29 #include "mojo/public/cpp/bindings/pending_remote.h"
30 #include "mojo/public/cpp/bindings/remote.h"
31 #include "services/media_session/public/mojom/media_controller.mojom.h"
32 #include "services/media_session/public/mojom/media_session.mojom.h"
33 
34 namespace base {
35 class SingleThreadTaskRunner;
36 }
37 
38 namespace chromeos {
39 
40 class AudioDevicesPrefHandler;
41 
42 // Callback to handle response of methods without result.
43 // |result| is true if the method call is successfully completed, otherwise
44 // false.
45 using VoidCrasAudioHandlerCallback = base::OnceCallback<void(bool result)>;
46 
47 // This class is not thread safe. The public functions should be called on
48 // browser main thread.
COMPONENT_EXPORT(CHROMEOS_AUDIO)49 class COMPONENT_EXPORT(CHROMEOS_AUDIO) CrasAudioHandler
50     : public CrasAudioClient::Observer,
51       public AudioPrefObserver,
52       public media::VideoCaptureObserver,
53       public media_session::mojom::MediaControllerObserver {
54  public:
55   typedef std::
56       priority_queue<AudioDevice, std::vector<AudioDevice>, AudioDeviceCompare>
57           AudioDevicePriorityQueue;
58   typedef std::vector<uint64_t> NodeIdList;
59   static constexpr int32_t kSystemAecGroupIdNotAvailable = -1;
60 
61   class AudioObserver {
62    public:
63     // Called when an active output volume changed.
64     virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume);
65 
66     // Called when output mute state changed.
67     virtual void OnOutputMuteChanged(bool mute_on);
68 
69     // Called when active input node's gain changed.
70     virtual void OnInputNodeGainChanged(uint64_t node_id, int gain);
71 
72     // Called when input mute state changed.
73     virtual void OnInputMuteChanged(bool mute_on);
74 
75     // Called when audio nodes changed.
76     virtual void OnAudioNodesChanged();
77 
78     // Called when active audio node changed.
79     virtual void OnActiveOutputNodeChanged();
80 
81     // Called when active audio input node changed.
82     virtual void OnActiveInputNodeChanged();
83 
84     // Called when output channel remixing changed.
85     virtual void OnOutputChannelRemixingChanged(bool mono_on);
86 
87     // Called when hotword is detected.
88     virtual void OnHotwordTriggered(uint64_t tv_sec, uint64_t tv_nsec);
89 
90     // Called when the battery level change is reported over the Hands-Free
91     // Profile for a Bluetooth headset.
92     // The address is a Bluetooth address as 6 bytes written in hexadecimal and
93     // separated by colons. Example: 00:11:22:33:44:FF
94     // The level ranges from 0 to 100. Erroneous value reported by the headset
95     // will be ignored and won't trigger this callback.
96     virtual void OnBluetoothBatteryChanged(const std::string& address,
97                                            uint32_t level);
98 
99     // Called when an initial output stream is opened.
100     virtual void OnOutputStarted();
101 
102     // Called when the last output stream is closed.
103     virtual void OnOutputStopped();
104 
105    protected:
106     AudioObserver();
107     virtual ~AudioObserver();
108     DISALLOW_COPY_AND_ASSIGN(AudioObserver);
109   };
110 
111   enum DeviceActivateType {
112     ACTIVATE_BY_PRIORITY = 0,
113     ACTIVATE_BY_USER,
114     ACTIVATE_BY_RESTORE_PREVIOUS_STATE,
115     ACTIVATE_BY_CAMERA
116   };
117 
118   // Sets the global instance. Must be called before any calls to Get().
119   static void Initialize(
120       mojo::PendingRemote<media_session::mojom::MediaControllerManager>
121           media_controller_manager,
122       scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler);
123 
124   // Sets the global instance for testing.
125   static void InitializeForTesting();
126 
127   // Destroys the global instance.
128   static void Shutdown();
129 
130   // Gets the global instance. Initialize must be called first.
131   static CrasAudioHandler* Get();
132 
133   // Overrides media::VideoCaptureObserver.
134   void OnVideoCaptureStarted(media::VideoFacingMode facing) override;
135   void OnVideoCaptureStopped(media::VideoFacingMode facing) override;
136 
137   // Overrides media_session::mojom::MediaControllerObserver.
138   void MediaSessionInfoChanged(
139       media_session::mojom::MediaSessionInfoPtr session_info) override;
140   void MediaSessionMetadataChanged(
141       const base::Optional<media_session::MediaMetadata>& metadata) override;
142   void MediaSessionActionsChanged(
143       const std::vector<media_session::mojom::MediaSessionAction>& actions)
144       override {}
145   void MediaSessionChanged(
146       const base::Optional<base::UnguessableToken>& request_id) override {}
147   void MediaSessionPositionChanged(
148       const base::Optional<media_session::MediaPosition>& position) override;
149 
150   // Adds an audio observer.
151   void AddAudioObserver(AudioObserver* observer);
152 
153   // Removes an audio observer.
154   void RemoveAudioObserver(AudioObserver* observer);
155 
156   // Returns true if keyboard mic exists.
157   bool HasKeyboardMic();
158 
159   // Returns true if hotword input device exists.
160   bool HasHotwordDevice();
161 
162   // Returns true if audio output is muted for the system.
163   bool IsOutputMuted();
164 
165   // Returns true if audio output is muted for a device.
166   bool IsOutputMutedForDevice(uint64_t device_id);
167 
168   // Returns true if audio input is muted.
169   bool IsInputMuted();
170 
171   // Returns true if audio input is muted for a device.
172   bool IsInputMutedForDevice(uint64_t device_id);
173 
174   // Returns true if the output volume is below the default mute volume level.
175   bool IsOutputVolumeBelowDefaultMuteLevel();
176 
177   // Returns volume level in 0-100% range at which the volume should be muted.
178   int GetOutputDefaultVolumeMuteThreshold();
179 
180   // Gets volume level in 0-100% range (0 being pure silence) for the current
181   // active node.
182   int GetOutputVolumePercent();
183 
184   // Gets volume level in 0-100% range (0 being pure silence) for a device.
185   int GetOutputVolumePercentForDevice(uint64_t device_id);
186 
187   // Gets gain level in 0-100% range (0 being pure silence) for the current
188   // active node.
189   int GetInputGainPercent();
190 
191   // Gets volume level in 0-100% range (0 being pure silence) for a device.
192   int GetInputGainPercentForDevice(uint64_t device_id);
193 
194   // Returns node_id of the primary active output node.
195   uint64_t GetPrimaryActiveOutputNode() const;
196 
197   // Returns the node_id of the primary active input node.
198   uint64_t GetPrimaryActiveInputNode() const;
199 
200   // Gets the audio devices back in |device_list|.
201   void GetAudioDevices(AudioDeviceList* device_list) const;
202 
203   bool GetPrimaryActiveOutputDevice(AudioDevice* device) const;
204 
205   // Returns the device matched with |type|. Assuming there is only one device
206   // matched the |type|, if there is more than one matched devices, it will
207   // return the first one found.
208   const AudioDevice* GetDeviceByType(AudioDeviceType type);
209 
210   // Gets the default output buffer size in frames.
211   void GetDefaultOutputBufferSize(int32_t* buffer_size) const;
212 
213   // Whether there is alternative input/output audio device.
214   bool has_alternative_input() const;
215   bool has_alternative_output() const;
216 
217   // Sets all active output devices' volume levels to |volume_percent|, whose
218   // range is from 0-100%.
219   void SetOutputVolumePercent(int volume_percent);
220 
221   // Sets all active input devices' gain level to |gain_percent|, whose range is
222   // from 0-100%.
223   void SetInputGainPercent(int gain_percent);
224 
225   // Adjusts all active output devices' volume up (positive percentage) or down
226   // (negative percentage).
227   void AdjustOutputVolumeByPercent(int adjust_by_percent);
228 
229   // Adjusts all active output devices' volume to a minimum audible level if it
230   // is too low.
231   void AdjustOutputVolumeToAudibleLevel();
232 
233   // Mutes or unmutes audio output device.
234   void SetOutputMute(bool mute_on);
235 
236   // Mutes or unmutes audio input device.
237   void SetInputMute(bool mute_on);
238 
239   // Switches active audio device to |device|. |activate_by| indicates why
240   // the device is switched to active: by user's manual choice, by priority,
241   // or by restoring to its previous active state.
242   void SwitchToDevice(const AudioDevice& device,
243                       bool notify,
244                       DeviceActivateType activate_by);
245 
246   // Sets volume/gain level for a device.
247   void SetVolumeGainPercentForDevice(uint64_t device_id, int value);
248 
249   // Sets the mute for device.
250   void SetMuteForDevice(uint64_t device_id, bool mute_on);
251 
252   // Activates or deactivates keyboard mic if there's one.
253   void SetKeyboardMicActive(bool active);
254 
255   // Changes the active nodes to the nodes specified by |new_active_ids|.
256   // The caller can pass in the "complete" active node list of either input
257   // nodes, or output nodes, or both. If only input nodes are passed in,
258   // it will only change the input nodes' active status, output nodes will NOT
259   // be changed; similarly for the case if only output nodes are passed.
260   // If the nodes specified in |new_active_ids| are already active, they will
261   // remain active. Otherwise, the old active nodes will be de-activated before
262   // we activate the new nodes with the same type(input/output).
263   // DEPRECATED in favor of |SetActiveInputNodes| and |SetActiveOutputNodes|.
264   void ChangeActiveNodes(const NodeIdList& new_active_ids);
265 
266   // Sets the set of active input nodes. Empty |node_ids| will deactivate all
267   // input devices.
268   // |node_ids| is expected to contain only existing input node IDs - the
269   // method will fail if this is not the case.
270   // Returns whether the acive nodes were successfully set.
271   bool SetActiveInputNodes(const NodeIdList& node_ids);
272 
273   // Sets the set of active output nodes. Empty |node_ids| will deactivate all
274   // output devices.
275   // |node_ids| is expected to contain only existing output node IDs - the
276   // method will fail if this is not the case.
277   // Returns whether the acive nodes were successfully set.
278   bool SetActiveOutputNodes(const NodeIdList& node_ids);
279 
280   // Sets |hotword_model| to the given |node_id|.
281   // |hotword_model| is expected to be in format <language>_<region> with lower
282   // cases. E.g., "en_us".
283   // The callback will receive a boolean which indicates if the hotword model is
284   // successfully set.
285   void SetHotwordModel(uint64_t node_id,
286                        const std::string& hotword_model,
287                        VoidCrasAudioHandlerCallback callback);
288 
289   // Swaps the left and right channel of the internal speaker.
290   // Swap the left and right channel if |swap| is true; otherwise, swap the left
291   // and right channel back to the normal mode.
292   // If the feature is not supported on the device, nothing happens.
293   void SwapInternalSpeakerLeftRightChannel(bool swap);
294 
295   // Accessibility mono audio setting: sets the output mono or not.
296   void SetOutputMonoEnabled(bool enabled);
297 
298   // If necessary, sets the starting point for re-discovering the active HDMI
299   // output device caused by device entering/exiting docking mode, HDMI display
300   // changing resolution, or chromeos device suspend/resume. If
301   // |force_rediscovering| is true, it will force to set the starting point for
302   // re-discovering the active HDMI output device again if it has been in the
303   // middle of rediscovering the HDMI active output device.
304   void SetActiveHDMIOutoutRediscoveringIfNecessary(bool force_rediscovering);
305 
306   const AudioDevice* GetDeviceFromId(uint64_t device_id) const;
307 
308   // Returns true the device has dual internal microphones(front and rear).
309   bool HasDualInternalMic() const;
310 
311   // Returns true if |device| is front or rear microphone.
312   bool IsFrontOrRearMic(const AudioDevice& device) const;
313 
314   // Switches to either front or rear microphone depending on the
315   // the use case. It should be called from a user initiated action.
316   void SwitchToFrontOrRearMic();
317 
318   // Returns if system AEC is supported in CRAS.
319   bool system_aec_supported() const;
320 
321   // Returns the system AEC group ID. If no group ID is specified, -1 is
322   // returned.
323   int32_t system_aec_group_id() const;
324 
325   // Asks  CRAS to resend BluetoothBatteryChanged signal, used in cases when
326   // Chrome cleans up the stored battery information but still has the device
327   // connected afterward. For example: User logout.
328   void ResendBluetoothBattery();
329 
330  protected:
331   CrasAudioHandler(
332       mojo::PendingRemote<media_session::mojom::MediaControllerManager>
333           media_controller_manager,
334       scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler);
335   ~CrasAudioHandler() override;
336 
337  private:
338   friend class CrasAudioHandlerTest;
339 
340   // CrasAudioClient::Observer overrides.
341   void AudioClientRestarted() override;
342   void NodesChanged() override;
343   void ActiveOutputNodeChanged(uint64_t node_id) override;
344   void ActiveInputNodeChanged(uint64_t node_id) override;
345   void OutputNodeVolumeChanged(uint64_t node_id, int volume) override;
346   void HotwordTriggered(uint64_t tv_sec, uint64_t tv_nsec) override;
347   void BluetoothBatteryChanged(const std::string& address,
348                                uint32_t level) override;
349   void NumberOfActiveStreamsChanged() override;
350 
351   // AudioPrefObserver overrides.
352   void OnAudioPolicyPrefChanged() override;
353 
354   // Sets the |active_device| to be active.
355   // If |notify|, notifies Active*NodeChange.
356   // Saves device active states in prefs. |activate_by| indicates how
357   // the device was activated.
358   void SetActiveDevice(const AudioDevice& active_device,
359                        bool notify,
360                        DeviceActivateType activate_by);
361 
362   // Shared implementation for |SetActiveInputNodes| and |SetActiveOutputNodes|.
363   bool SetActiveNodes(const NodeIdList& node_ids, bool is_input);
364 
365   // Sets list of active input or output nodes to |devices|.
366   // If |is_input| is set, active input nodes will be set, otherwise active
367   // output nodes will be set.
368   // For each device in |devices| it is expected device.is_input == is_input.
369   void SetActiveDevices(const AudioDeviceList& devices, bool is_input);
370 
371   // Saves |device|'s state in pref. If |active| is true, |activate_by|
372   // indicates how |device| is activated.
373   void SaveDeviceState(const AudioDevice& device,
374                        bool active,
375                        DeviceActivateType activate_by);
376 
377   // Sets up the audio device state based on audio policy and audio settings
378   // saved in prefs.
379   void SetupAudioInputState();
380   void SetupAudioOutputState();
381 
382   // Sets up the additional active audio node's state.
383   void SetupAdditionalActiveAudioNodeState(uint64_t node_id);
384 
385   AudioDevice ConvertAudioNodeWithModifiedPriority(const AudioNode& node);
386 
387   const AudioDevice* GetDeviceFromStableDeviceId(
388       uint64_t stable_device_id) const;
389   const AudioDevice* GetKeyboardMic() const;
390 
391   const AudioDevice* GetHotwordDevice() const;
392 
393   // Initializes audio state, which should only be called when CrasAudioHandler
394   // is created or cras audio client is restarted.
395   void InitializeAudioState();
396 
397   void InitializeAudioAfterCrasServiceAvailable(bool service_is_available);
398 
399   // Applies the audio muting policies whenever the user logs in or policy
400   // change notification is received.
401   void ApplyAudioPolicy();
402 
403   // Sets output volume of |node_id| to |volume|.
404   void SetOutputNodeVolume(uint64_t node_id, int volume);
405 
406   void SetOutputNodeVolumePercent(uint64_t node_id, int volume_percent);
407 
408   // Sets output mute state to |mute_on| internally, returns true if output mute
409   // is set.
410   bool SetOutputMuteInternal(bool mute_on);
411 
412   // Sets input gain of |node_id| to |gain|.
413   void SetInputNodeGain(uint64_t node_id, int gain);
414 
415   void SetInputNodeGainPercent(uint64_t node_id, int gain_percent);
416 
417   // Sets input mute state to |mute_on| internally.
418   void SetInputMuteInternal(bool mute_on);
419 
420   // Calls CRAS over D-Bus to get nodes data.
421   void GetNodes();
422 
423   // Calls CRAS over D-Bus to get the number of active output streams.
424   void GetNumberOfOutputStreams();
425 
426   // Updates the current audio nodes list and switches the active device
427   // if needed.
428   void UpdateDevicesAndSwitchActive(const AudioNodeList& nodes);
429 
430   // Returns true if the current active device is changed to
431   // |new_active_device|.
432   bool ChangeActiveDevice(const AudioDevice& new_active_device);
433 
434   // Returns true if there are any device changes for input or output
435   // specified by |is_input|, by comparing |audio_devices_| with |new_nodes|.
436   // Passes the new nodes discovered in *|new_discovered|.
437   // *|device_removed| indicates if any devices have been removed.
438   // *|active_device_removed| indicates if the current active device has been
439   // removed.
440   bool HasDeviceChange(const AudioNodeList& new_nodes,
441                        bool is_input,
442                        AudioDevicePriorityQueue* new_discovered,
443                        bool* device_removed,
444                        bool* active_device_removed);
445 
446   // Handles dbus callback for GetNodes.
447   void HandleGetNodes(base::Optional<chromeos::AudioNodeList> node_list);
448 
449   void HandleGetNumActiveOutputStreams(
450       base::Optional<int> num_active_output_streams);
451 
452   void HandleGetDeprioritizeBtWbsMic(
453       base::Optional<bool> deprioritize_bt_wbs_mic);
454 
455   // Adds an active node.
456   // If there is no active node, |node_id| will be switched to become the
457   // primary active node. Otherwise, it will be added as an additional active
458   // node.
459   void AddActiveNode(uint64_t node_id, bool notify);
460 
461   // Adds |node_id| into additional active nodes.
462   void AddAdditionalActiveNode(uint64_t node_id, bool notify);
463 
464   // Removes |node_id| from additional active nodes.
465   void RemoveActiveNodeInternal(uint64_t node_id, bool notify);
466 
467   void UpdateAudioAfterHDMIRediscoverGracePeriod();
468 
469   bool IsHDMIPrimaryOutputDevice() const;
470 
471   void StartHDMIRediscoverGracePeriod();
472 
473   bool hdmi_rediscovering() const { return hdmi_rediscovering_; }
474 
475   void SetHDMIRediscoverGracePeriodForTesting(int duration_in_ms);
476 
477   enum DeviceStatus {
478     OLD_DEVICE,
479     NEW_DEVICE,
480     CHANGED_DEVICE,
481   };
482 
483   // Checks if |device| is a newly discovered, changed, or existing device for
484   // the nodes sent from NodesChanged signal.
485   DeviceStatus CheckDeviceStatus(const AudioDevice& device);
486 
487   void NotifyActiveNodeChanged(bool is_input);
488 
489   // Returns true if it retrieves an active audio device from user preference
490   // among the current |audio_devices_|.
491   bool GetActiveDeviceFromUserPref(bool is_input, AudioDevice* device);
492 
493   // Pauses all active streams.
494   void PauseAllStreams();
495 
496   // Handles either input or output device changes, specified by |is_input|.
497   void HandleAudioDeviceChange(bool is_input,
498                                const AudioDevicePriorityQueue& devices_pq,
499                                const AudioDevicePriorityQueue& hotplug_nodes,
500                                bool has_device_change,
501                                bool has_device_removed,
502                                bool active_device_removed);
503 
504   // Handles non-hotplug nodes change cases.
505   void HandleNonHotplugNodesChange(
506       bool is_input,
507       const AudioDevicePriorityQueue& hotplug_nodes,
508       bool has_device_change,
509       bool has_device_removed,
510       bool active_device_removed);
511 
512   // Handles the regular user hotplug case.
513   void HandleHotPlugDevice(
514       const AudioDevice& hotplug_device,
515       const AudioDevicePriorityQueue& device_priority_queue);
516 
517   void SwitchToTopPriorityDevice(bool is_input);
518 
519   // Switch to previous active device if it is found, otherwise, switch
520   // to the top priority device.
521   void SwitchToPreviousActiveDeviceIfAvailable(bool is_input);
522 
523   // Activates the internal mic attached with the camera specified by
524   // |camera_facing|.
525   void ActivateMicForCamera(media::VideoFacingMode camera_facing);
526 
527   // Activates the front or rear mic that is consistent with the active camera.
528   // Note: This should only be called for the dural camera/mic use case.
529   void ActivateInternalMicForActiveCamera();
530 
531   // Returns the microphone for the camera with |camera_facing|.
532   const AudioDevice* GetMicForCamera(media::VideoFacingMode camera_facing);
533 
534   bool IsCameraOn() const;
535 
536   // Returns true if there are any external devices.
537   bool HasExternalDevice(bool is_input) const;
538 
539   // Calling dbus to get default output buffer size.
540   void GetDefaultOutputBufferSizeInternal();
541 
542   // Handle dbus callback for GetDefaultOutputBufferSize.
543   void HandleGetDefaultOutputBufferSize(base::Optional<int> buffer_size);
544 
545   // Calling dbus to get system AEC supported flag.
546   void GetSystemAecSupported();
547 
548   // Calling dbus to get system AEC supported flag on main thread.
549   void GetSystemAecSupportedOnMainThread();
550 
551   // Handle dbus callback for GetSystemAecSupported.
552   void HandleGetSystemAecSupported(base::Optional<bool> system_aec_supported);
553 
554   // Calling dbus to get the system AEC group id if available.
555   void GetSystemAecGroupId();
556 
557   // Calling dbus to get any available system AEC group id on main thread.
558   void GetSystemAecGroupIdOnMainThread();
559 
560   // Handle dbus callback for GetSystemAecGroupId.
561   void HandleGetSystemAecGroupId(base::Optional<int32_t> system_aec_group_id);
562 
563   void OnVideoCaptureStartedOnMainThread(media::VideoFacingMode facing);
564   void OnVideoCaptureStoppedOnMainThread(media::VideoFacingMode facing);
565 
566   void BindMediaControllerObserver();
567 
568   // Handle null Metadata from MediaSession.
569   void HandleMediaSessionMetadataReset();
570 
571   mojo::Remote<media_session::mojom::MediaControllerManager>
572       media_controller_manager_;
573 
574   mojo::Remote<media_session::mojom::MediaController>
575       media_session_controller_remote_;
576 
577   mojo::Receiver<media_session::mojom::MediaControllerObserver>
578       media_controller_observer_receiver_{this};
579 
580   scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
581   base::ObserverList<AudioObserver>::Unchecked observers_;
582 
583   // Audio data and state.
584   AudioDeviceMap audio_devices_;
585 
586   AudioDevicePriorityQueue input_devices_pq_;
587   AudioDevicePriorityQueue output_devices_pq_;
588 
589   bool output_mute_on_ = false;
590   bool input_mute_on_ = false;
591   int output_volume_ = 0;
592   int input_gain_ = 0;
593   uint64_t active_output_node_id_ = 0;
594   uint64_t active_input_node_id_ = 0;
595   bool has_alternative_input_ = false;
596   bool has_alternative_output_ = false;
597 
598   bool output_mute_locked_ = false;
599 
600   // Audio output channel counts.
601   int32_t output_channels_ = 2;
602   bool output_mono_enabled_ = false;
603 
604   // Timer for HDMI re-discovering grace period.
605   base::OneShotTimer hdmi_rediscover_timer_;
606   int hdmi_rediscover_grace_period_duration_in_ms_ = 2000;
607   bool hdmi_rediscovering_ = false;
608 
609   bool cras_service_available_ = false;
610 
611   bool initializing_audio_state_ = false;
612   int init_volume_;
613   uint64_t init_node_id_;
614   int init_volume_count_ = 0;
615 
616   bool front_camera_on_ = false;
617   bool rear_camera_on_ = false;
618 
619   // Default output buffer size in frames.
620   int32_t default_output_buffer_size_ = 512;
621 
622   bool system_aec_supported_ = false;
623   int32_t system_aec_group_id_ = kSystemAecGroupIdNotAvailable;
624 
625   int num_active_output_streams_ = 0;
626 
627   bool fetch_media_session_duration_ = false;
628 
629   // On a few platforms that Bluetooth WBS is still working to be
630   // stabilized, CRAS may report to deprioritze the BT WBS mic's node
631   // priority.
632   bool deprioritize_bt_wbs_mic_ = false;
633 
634   // Task runner of browser main thread. All member variables should be accessed
635   // on this thread.
636   scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
637 
638   base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_{this};
639 
640   DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
641 };
642 
643 }  // namespace chromeos
644 
645 #endif  // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
646