xref: /aosp_15_r20/frameworks/native/include/audiomanager/AudioManager.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_AUDIOMANAGER_H
18 #define ANDROID_AUDIOMANAGER_H
19 
20 namespace android {
21 
22 // must be kept in sync with definitions in AudioPlaybackConfiguration.java
23 #define PLAYER_PIID_INVALID -1
24 
25 // TODO (b/309532236) remove manual IAudioManager impl in favor of AIDL.
26 typedef enum {
27     PLAYER_TYPE_SLES_AUDIOPLAYER_BUFFERQUEUE = 11,
28     PLAYER_TYPE_SLES_AUDIOPLAYER_URI_FD = 12,
29     PLAYER_TYPE_AAUDIO = 13,
30     PLAYER_TYPE_HW_SOURCE = 14,
31     PLAYER_TYPE_EXTERNAL_PROXY = 15,
32 } player_type_t;
33 
34 typedef enum {
35     PLAYER_STATE_UNKNOWN  = -1,
36     PLAYER_STATE_RELEASED = 0,
37     PLAYER_STATE_IDLE     = 1,
38     PLAYER_STATE_STARTED  = 2,
39     PLAYER_STATE_PAUSED   = 3,
40     PLAYER_STATE_STOPPED  = 4,
41     PLAYER_UPDATE_DEVICE_ID = 5,
42     PLAYER_UPDATE_PORT_ID = 6,
43     PLAYER_UPDATE_MUTED = 7,
44     PLAYER_UPDATE_FORMAT = 8,
45 } player_state_t;
46 
47 static constexpr char
48     kExtraPlayerEventSpatializedKey[] = "android.media.extra.PLAYER_EVENT_SPATIALIZED";
49 static constexpr char
50     kExtraPlayerEventSampleRateKey[] = "android.media.extra.PLAYER_EVENT_SAMPLE_RATE";
51 static constexpr char
52     kExtraPlayerEventChannelMaskKey[] = "android.media.extra.PLAYER_EVENT_CHANNEL_MASK";
53 
54 static constexpr char
55     kExtraPlayerEventMuteKey[] = "android.media.extra.PLAYER_EVENT_MUTE";
56 enum {
57     PLAYER_MUTE_MASTER = (1 << 0),
58     PLAYER_MUTE_STREAM_VOLUME = (1 << 1),
59     PLAYER_MUTE_STREAM_MUTED = (1 << 2),
60     PLAYER_MUTE_PLAYBACK_RESTRICTED = (1 << 3),
61     PLAYER_MUTE_CLIENT_VOLUME = (1 << 4),
62     PLAYER_MUTE_VOLUME_SHAPER = (1 << 5),
63     PLAYER_MUTE_PORT_VOLUME = (1 << 6),
64     PLAYER_MUTE_OP_AUDIO_CONTROL = (1 << 7),
65 };
66 
67 struct mute_state_t {
68     /** Flag used when the master volume is causing the mute state. */
69     bool muteFromMasterMute = false;
70     /** Flag used when the stream volume is causing the mute state. */
71     bool muteFromStreamVolume = false;
72     /** Flag used when the stream muted is causing the mute state. */
73     bool muteFromStreamMuted = false;
74     /** Flag used when playback is restricted by AppOps manager with OP_PLAY_AUDIO. */
75     bool muteFromPlaybackRestricted = false;
76     /** Flag used when audio track was muted by client volume. */
77     bool muteFromClientVolume = false;
78     /** Flag used when volume is muted by volume shaper. */
79     bool muteFromVolumeShaper = false;
80     /** Flag used when volume is muted by port volume. */
81     bool muteFromPortVolume = false;
82     /** Flag used when volume is muted by audio control op. */
83     bool muteFromOpAudioControl = false;
84 
85     explicit operator int() const
86     {
87         int result = muteFromMasterMute * PLAYER_MUTE_MASTER;
88         result |= muteFromStreamVolume * PLAYER_MUTE_STREAM_VOLUME;
89         result |= muteFromStreamMuted * PLAYER_MUTE_STREAM_MUTED;
90         result |= muteFromPlaybackRestricted * PLAYER_MUTE_PLAYBACK_RESTRICTED;
91         result |= muteFromClientVolume * PLAYER_MUTE_CLIENT_VOLUME;
92         result |= muteFromVolumeShaper * PLAYER_MUTE_VOLUME_SHAPER;
93         result |= muteFromPortVolume * PLAYER_MUTE_PORT_VOLUME;
94         result |= muteFromOpAudioControl * PLAYER_MUTE_OP_AUDIO_CONTROL;
95         return result;
96     }
97 
98     bool operator==(const mute_state_t& other) const
99     {
100         return static_cast<int>(*this) == static_cast<int>(other);
101     }
102 };
103 
104 // must be kept in sync with definitions in AudioManager.java
105 #define RECORD_RIID_INVALID -1
106 
107 typedef enum {
108     RECORDER_STATE_UNKNOWN  = -1,
109     RECORDER_STATE_STARTED  = 0,
110     RECORDER_STATE_STOPPED  = 1,
111 } recorder_state_t;
112 
113 }; // namespace android
114 
115 #endif // ANDROID_AUDIOMANAGER_H
116