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.
5 #ifndef CHROMEOS_AUDIO_AUDIO_DEVICE_H_
6 #define CHROMEOS_AUDIO_AUDIO_DEVICE_H_
12 #include "base/basictypes.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/audio_node.h"
18 // Ordered from the highest priority to the lowest.
19 enum AudioDeviceType
{
25 AUDIO_TYPE_INTERNAL_SPEAKER
,
26 AUDIO_TYPE_INTERNAL_MIC
,
27 AUDIO_TYPE_KEYBOARD_MIC
,
29 AUDIO_TYPE_POST_MIX_LOOPBACK
,
30 AUDIO_TYPE_POST_DSP_LOOPBACK
,
34 struct CHROMEOS_EXPORT AudioDevice
{
36 explicit AudioDevice(const AudioNode
& node
);
37 std::string
ToString() const;
39 // Converts between the string type sent via D-Bus and AudioDeviceType.
40 // Static so they can be used by tests.
41 static std::string
GetTypeString(chromeos::AudioDeviceType type
);
42 static chromeos::AudioDeviceType
GetAudioType(const std::string
& node_type
);
44 // Indicates that an input or output audio device is for simple usage like
45 // playback or recording for user. In contrast, audio device such as
46 // loopback, always on keyword recognition (AOKR), and keyboard mic are
47 // not for simple usage.
48 bool is_for_simple_usage() const {
49 return (type
== AUDIO_TYPE_HEADPHONE
||
50 type
== AUDIO_TYPE_INTERNAL_MIC
||
51 type
== AUDIO_TYPE_MIC
||
52 type
== AUDIO_TYPE_USB
||
53 type
== AUDIO_TYPE_BLUETOOTH
||
54 type
== AUDIO_TYPE_HDMI
||
55 type
== AUDIO_TYPE_INTERNAL_SPEAKER
);
60 std::string display_name
;
61 std::string device_name
;
62 std::string mic_positions
;
69 typedef std::vector
<AudioDevice
> AudioDeviceList
;
70 typedef std::map
<uint64
, AudioDevice
> AudioDeviceMap
;
72 struct AudioDeviceCompare
{
73 // Rules used to discern which device is higher,
75 // [Headphones/USB/Bluetooh > HDMI > Internal Speakers]
76 // [External Mic/USB Mic/Bluetooth > Internal Mic]
77 // 2.) Device Plugged in Time:
79 bool operator()(const chromeos::AudioDevice
& a
,
80 const chromeos::AudioDevice
& b
) const {
81 if (a
.priority
< b
.priority
) {
83 } else if (b
.priority
< a
.priority
) {
85 } else if (a
.plugged_time
< b
.plugged_time
) {
93 } // namespace chromeos
95 #endif // CHROMEOS_AUDIO_AUDIO_DEVICE_H_