audio_device.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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_AUDIO_DEVICE_H_
6#define CHROMEOS_AUDIO_AUDIO_DEVICE_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include "base/basictypes.h"
13#include "chromeos/chromeos_export.h"
14#include "chromeos/dbus/audio_node.h"
15
16namespace chromeos {
17
18// Ordered from the highest priority to the lowest.
19enum AudioDeviceType {
20  AUDIO_TYPE_HEADPHONE,
21  AUDIO_TYPE_MIC,
22  AUDIO_TYPE_USB,
23  AUDIO_TYPE_BLUETOOTH,
24  AUDIO_TYPE_HDMI,
25  AUDIO_TYPE_INTERNAL_SPEAKER,
26  AUDIO_TYPE_INTERNAL_MIC,
27  AUDIO_TYPE_OTHER,
28};
29
30struct CHROMEOS_EXPORT AudioDevice {
31  bool is_input;
32  uint64 id;
33  std::string display_name;
34  AudioDeviceType type;
35  uint8 priority;
36  bool active;
37  uint64 plugged_time;
38
39  AudioDevice();
40  explicit AudioDevice(const AudioNode& node);
41  std::string ToString() const;
42};
43
44typedef std::vector<AudioDevice> AudioDeviceList;
45typedef std::map<uint64, AudioDevice> AudioDeviceMap;
46
47struct AudioDeviceCompare {
48  // Rules used to discern which device is higher,
49  // 1.) Device Type:
50  //       [Headphones/USB/Bluetooh > HDMI > Internal Speakers]
51  //       [External Mic/USB Mic/Bluetooth > Internal Mic]
52  // 2.) Device Plugged in Time:
53  //       [Later > Earlier]
54  bool operator()(const chromeos::AudioDevice& a,
55                  const chromeos::AudioDevice& b) const {
56    if (a.priority < b.priority) {
57      return true;
58    } else if (b.priority < a.priority) {
59      return false;
60    } else if (a.plugged_time < b.plugged_time) {
61      return true;
62    } else {
63      return false;
64    }
65  }
66};
67
68}  // namespace chromeos
69
70#endif  // CHROMEOS_AUDIO_AUDIO_DEVICE_H_
71