File: audio_device.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (155 lines) | stat: -rw-r--r-- 5,737 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_AUDIO_AUDIO_DEVICE_H_
#define CHROMEOS_ASH_COMPONENTS_AUDIO_AUDIO_DEVICE_H_

#include <stdint.h>

#include <map>
#include <string>
#include <vector>

#include "base/component_export.h"
#include "chromeos/ash/components/dbus/audio/audio_node.h"

namespace ash {

// This enum is used in histograms, do not remove/renumber entries. If you're
// adding to this enum, update the corresponding enum listing in
// tools/metrics/histograms/enums.xml.
//
// Originally ordered from the highest priority to the lowest.
enum class AudioDeviceType {
  kHeadphone,
  kMic,
  kUsb,
  kBluetooth,
  kBluetoothNbMic,
  kHdmi,
  kInternalSpeaker,
  kInternalMic,
  kFrontMic,
  kRearMic,
  kKeyboardMic,
  kHotword,
  kLineout,
  kPostMixLoopback,
  kPostDspLoopback,
  kAlsaLoopback,
  kOther,
  kMaxValue = kOther,
};

// Default value of user priority preference.
const int kUserPriorityNone = 0;
// Min value of user priority preference.
const int kUserPriorityMin = 1;

struct COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_AUDIO) AudioDevice {
  AudioDevice();
  explicit AudioDevice(const AudioNode& node);
  AudioDevice(const AudioDevice& other);
  AudioDevice& operator=(const AudioDevice& other);
  std::string ToString() const;

  // Converts between the string type sent via D-Bus and AudioDeviceType.
  // Static so they can be used by tests.
  static std::string GetTypeString(AudioDeviceType type);
  static AudioDeviceType GetAudioType(const std::string& node_type);

  // Indicates that an input or output audio device is for simple usage like
  // playback or recording for user. In contrast, audio device such as
  // loopback, always on keyword recognition (HOTWORD), and keyboard mic are
  // not for simple usage.
  // One special case is ALSA loopback device, which will only exist under
  // testing, and we want it visible to users for e2e tests.
  bool is_for_simple_usage() const {
    return (type == AudioDeviceType::kHeadphone ||
            type == AudioDeviceType::kInternalMic ||
            type == AudioDeviceType::kFrontMic ||
            type == AudioDeviceType::kRearMic ||
            type == AudioDeviceType::kMic || type == AudioDeviceType::kUsb ||
            type == AudioDeviceType::kBluetooth ||
            type == AudioDeviceType::kBluetoothNbMic ||
            type == AudioDeviceType::kHdmi ||
            type == AudioDeviceType::kInternalSpeaker ||
            type == AudioDeviceType::kLineout ||
            type == AudioDeviceType::kAlsaLoopback);
  }

  // Indicates if a device has privilege. System will automatically
  // activate those devices when they are connected, disregarding previously
  // saved user preferences. In other words, having privilege overrides the
  // priority stored in user preferences.
  bool has_privilege() const {
    return type == AudioDeviceType::kHeadphone ||
           type == AudioDeviceType::kMic ||
           type == AudioDeviceType::kBluetooth ||
           type == AudioDeviceType::kBluetoothNbMic;
  }

  bool IsExternalDevice() const;

  bool IsInternalMic() const;

  bool IsInternalSpeaker() const;

  bool is_input = false;

  // Id of this audio device. The legacy |id| is assigned to be unique everytime
  // when each device got plugged, so that the same physical device will have
  // a different id after unplug then re-plug.
  // The |stable_device_id| is designed to be persistent across system reboot
  // and plug/unplug for the same physical device. It is guaranteed that
  // different type of hardware has different |stable_device_id|, but not
  // guaranteed to be different between the same kind of audio device, e.g
  // USB headset. |id| and |stable_device_id| can be used together to achieve
  // various goals.
  // Note that because algorithm used to determine |stable_device_id| changed in
  // system code, |stable_device_id_version| and |deprecated_stable_device_id|
  // have been introduced - to ensure backward compatibility until persisted
  // references to stable device ID have been updated where needed.
  // |stable_device_id_version| is the version of stable device ID set in
  // |stable_device_id|. If version is set to 2, |deprecated_stable_device_id|
  // will contain deprecated, v1 stable device id version.
  uint64_t id = 0;
  int stable_device_id_version = 0;
  uint64_t stable_device_id = 0;
  uint64_t deprecated_stable_device_id = 0;
  std::string display_name;
  std::string device_name;
  AudioDeviceType type = AudioDeviceType::kOther;
  uint8_t priority = 0;
  bool active = false;
  uint64_t plugged_time = 0;
  uint32_t max_supported_channels = 0;
  uint32_t audio_effect = 0;
  int32_t number_of_volume_steps = 0;
  // The larger value means the higher priority.
  uint32_t user_priority = kUserPriorityNone;
};

typedef std::vector<AudioDevice> AudioDeviceList;
typedef std::map<uint64_t, AudioDevice> AudioDeviceMap;

// Compare device user priority first. If tie, compare them with the
// LessBuiltInPriority().
bool LessUserPriority(const AudioDevice& a, const AudioDevice& b);

// Rules used to discern which device is higher:
// 1.) Device Type:
//       [Headphones/USB/Bluetooth > HDMI > Internal Speakers]
//       [External Mic/USB Mic/Bluetooth > Internal Mic]
// 2.) Device Plugged in Time:
//       [Later > Earlier]
bool LessBuiltInPriority(const AudioDevice& a, const AudioDevice& b);

struct COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_AUDIO) AudioDeviceCompare {
  bool operator()(const AudioDevice& a, const AudioDevice& b) const;
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_AUDIO_AUDIO_DEVICE_H_