• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef AUDIO_INFO_H
16 #define AUDIO_INFO_H
17 
18 #ifdef __MUSL__
19 #include <stdint.h>
20 #endif // __MUSL__
21 
22 #include <cmath>
23 #include <limits>
24 #include <string>
25 #include <vector>
26 #include <array>
27 #include <unistd.h>
28 #include <unordered_map>
29 #include <parcel.h>
30 #include <audio_source_type.h>
31 #include <audio_device_info.h>
32 #include <audio_interrupt_info.h>
33 #include <audio_session_info.h>
34 #include <audio_stream_info.h>
35 #include <audio_asr.h>
36 
37 namespace OHOS {
38 namespace AudioStandard {
39 namespace {
40 constexpr int32_t INVALID_PID = -1;
41 constexpr int32_t CLEAR_PID = 0;
42 constexpr int32_t SYSTEM_PID = 1;
43 constexpr int32_t CLEAR_UID = 0;
44 constexpr int32_t SYSTEM_UID = 1;
45 constexpr int32_t INVALID_UID = -1;
46 constexpr int32_t INVALID_ZONEID = -1;
47 constexpr int32_t NETWORK_ID_SIZE = 80;
48 constexpr int32_t DEFAULT_VOLUME_GROUP_ID = 1;
49 constexpr int32_t AUDIO_FLAG_INVALID = -1;
50 constexpr int32_t AUDIO_FLAG_NORMAL = 0;
51 constexpr int32_t AUDIO_FLAG_MMAP = 1;
52 constexpr int32_t AUDIO_FLAG_VOIP_FAST = 2;
53 constexpr int32_t AUDIO_FLAG_DIRECT = 3;
54 constexpr int32_t AUDIO_FLAG_VOIP_DIRECT = 4;
55 constexpr int32_t AUDIO_FLAG_PCM_OFFLOAD = 5;
56 constexpr int32_t AUDIO_FLAG_FORCED_NORMAL = 10;
57 constexpr int32_t AUDIO_FLAG_VKB_NORMAL = 1024;
58 constexpr int32_t AUDIO_FLAG_VKB_FAST = 1025;
59 constexpr int32_t AUDIO_USAGE_NORMAL = 0;
60 constexpr int32_t AUDIO_USAGE_VOIP = 1;
61 constexpr uint32_t STREAM_FLAG_FAST = 1;
62 constexpr float MAX_STREAM_SPEED_LEVEL = 4.0f;
63 constexpr float MIN_STREAM_SPEED_LEVEL = 0.125f;
64 constexpr float NORMAL_STREAM_SPEED_LEVEL = 1.0f;
65 constexpr int32_t EMPTY_UID = 0;
66 constexpr int32_t AUDIO_NORMAL_MANAGER_TYPE = 0;
67 constexpr int32_t AUDIO_DIRECT_MANAGER_TYPE = 2;
68 
69 constexpr uint32_t MIN_STREAMID = 100000;
70 constexpr uint32_t MAX_STREAMID = UINT32_MAX - MIN_STREAMID;
71 
72 constexpr uint64_t AUDIO_US_PER_MS = 1000;
73 constexpr uint64_t AUDIO_NS_PER_US = 1000;
74 constexpr uint64_t AUDIO_US_PER_S = 1000000;
75 constexpr uint64_t AUDIO_MS_PER_S = 1000;
76 
77 constexpr uint64_t MAX_CBBUF_IN_USEC = 100000;
78 constexpr uint64_t MIN_CBBUF_IN_USEC = 20000;
79 
80 const float MIN_FLOAT_VOLUME = 0.0f;
81 const float MAX_FLOAT_VOLUME = 1.0f;
82 
83 const char* MICROPHONE_PERMISSION = "ohos.permission.MICROPHONE";
84 const char* MODIFY_AUDIO_SETTINGS_PERMISSION = "ohos.permission.MODIFY_AUDIO_SETTINGS";
85 const char* ACCESS_NOTIFICATION_POLICY_PERMISSION = "ohos.permission.ACCESS_NOTIFICATION_POLICY";
86 const char* CAPTURER_VOICE_DOWNLINK_PERMISSION = "ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO";
87 const char* RECORD_VOICE_CALL_PERMISSION = "ohos.permission.RECORD_VOICE_CALL";
88 
89 const char* PRIMARY_WAKEUP = "Built_in_wakeup";
90 const char* INNER_CAPTURER_SINK = "InnerCapturerSink_";
91 const char* REMOTE_CAST_INNER_CAPTURER_SINK_NAME = "RemoteCastInnerCapturer";
92 const char* DUP_STREAM = "DupStream";
93 }
94 
95 //#ifdef FEATURE_DTMF_TONE  cant contain this macro due to idl dependency
96 // Maximun number of sine waves in a tone segment
97 constexpr uint32_t TONEINFO_MAX_WAVES = 3;
98 //Maximun number of SupportedTones
99 constexpr uint32_t MAX_SUPPORTED_TONEINFO_SIZE = 65535;
100 // Maximun number of segments in a tone descriptor
101 constexpr uint32_t TONEINFO_MAX_SEGMENTS = 12;
102 constexpr uint32_t TONEINFO_INF = 0xFFFFFFFF;
103 
104 class ToneSegment : public Parcelable {
105 public:
106     uint32_t duration;
107     uint16_t waveFreq[TONEINFO_MAX_WAVES+1];
108     uint16_t loopCnt;
109     uint16_t loopIndx;
110 
111     ToneSegment() = default;
Marshalling(Parcel & parcel)112     bool Marshalling(Parcel &parcel) const override
113     {
114         parcel.WriteUint32(duration);
115         parcel.WriteUint16(loopCnt);
116         parcel.WriteUint16(loopIndx);
117         for (uint32_t i = 0; i < TONEINFO_MAX_WAVES + 1; i++) {
118             parcel.WriteUint16(waveFreq[i]);
119         }
120         return true;
121     }
122 
UnmarshallingSelf(Parcel & parcel)123     void UnmarshallingSelf(Parcel &parcel)
124     {
125         duration = parcel.ReadUint32();
126         loopCnt = parcel.ReadUint16();
127         loopIndx = parcel.ReadUint16();
128         for (uint32_t i = 0; i < TONEINFO_MAX_WAVES + 1; i++) {
129             waveFreq[i] = parcel.ReadUint16();
130         }
131     }
132 
Unmarshalling(Parcel & parcel)133     static ToneSegment *Unmarshalling(Parcel &parcel)
134     {
135         auto info = new(std::nothrow) ToneSegment();
136         if (info == nullptr) {
137             return nullptr;
138         }
139 
140         info->UnmarshallingSelf(parcel);
141         return info;
142     }
143 };
144 
145 class ToneInfo : public Parcelable {
146 public:
147     ToneSegment segments[TONEINFO_MAX_SEGMENTS+1];
148     uint32_t segmentCnt;
149     uint32_t repeatCnt;
150     uint32_t repeatSegment;
151     ToneInfo() = default;
Marshalling(Parcel & parcel)152     bool Marshalling(Parcel &parcel) const override
153     {
154         parcel.WriteUint32(segmentCnt);
155         parcel.WriteUint32(repeatCnt);
156         parcel.WriteUint32(repeatSegment);
157         if (!(segmentCnt >= 0 && segmentCnt <= TONEINFO_MAX_SEGMENTS + 1)) {
158             return false;
159         }
160         for (uint32_t i = 0; i < segmentCnt; i++) {
161             segments[i].Marshalling(parcel);
162         }
163         return true;
164     }
Unmarshalling(Parcel & parcel)165     static ToneInfo *Unmarshalling(Parcel &parcel)
166     {
167         auto info = new(std::nothrow) ToneInfo();
168         if (info == nullptr) {
169             return nullptr;
170         }
171         info->segmentCnt = parcel.ReadUint32();
172         info->repeatCnt = parcel.ReadUint32();
173         info->repeatSegment = parcel.ReadUint32();
174         if (!(info->segmentCnt >= 0 && info->segmentCnt <= TONEINFO_MAX_SEGMENTS + 1)) {
175             delete info;
176             return nullptr;
177         }
178         for (uint32_t i = 0; i < info->segmentCnt; i++) {
179             info->segments[i].UnmarshallingSelf(parcel);
180         }
181         return info;
182     }
183 };
184 //#endif
185 
186 enum VolumeAdjustType {
187     /**
188      * Adjust volume up
189      */
190     VOLUME_UP = 0,
191     /**
192      * Adjust volume down
193      */
194     VOLUME_DOWN = 1,
195 };
196 
197 enum ChannelBlendMode {
198     /**
199      * No channel process.
200      */
201     MODE_DEFAULT = 0,
202     /**
203      * Blend left and right channel.
204      */
205     MODE_BLEND_LR = 1,
206     /**
207      * Replicate left to right channel.
208      */
209     MODE_ALL_LEFT = 2,
210     /**
211      * Replicate right to left channel.
212      */
213     MODE_ALL_RIGHT = 3,
214 };
215 
216 enum ConnectType {
217     /**
218      * Group connect type of local device
219      */
220     CONNECT_TYPE_LOCAL = 0,
221     /**
222      * Group connect type of distributed device
223      */
224     CONNECT_TYPE_DISTRIBUTED
225 };
226 
227 typedef AudioStreamType AudioVolumeType;
228 
229 enum VolumeFlag {
230     /**
231      * Show system volume bar
232      */
233     FLAG_SHOW_SYSTEM_UI = 1,
234 };
235 
236 enum AudioOffloadType {
237     /**
238      * Indicates audio offload state default.
239      */
240     OFFLOAD_DEFAULT = -1,
241     /**
242      * Indicates audio offload state : screen is active & app is foreground.
243      */
244     OFFLOAD_ACTIVE_FOREGROUND = 0,
245     /**
246      * Indicates audio offload state : screen is active & app is background.
247      */
248     OFFLOAD_ACTIVE_BACKGROUND = 1,
249     /**
250      * Indicates audio offload state : screen is inactive & app is background.
251      */
252     OFFLOAD_INACTIVE_BACKGROUND = 3,
253 };
254 
255 enum FocusType {
256     /**
257      * Recording type.
258      */
259     FOCUS_TYPE_RECORDING = 0,
260 };
261 
262 enum AudioErrors {
263     /**
264      * Common errors.
265      */
266     ERROR_INVALID_PARAM = 6800101,
267     ERROR_NO_MEMORY     = 6800102,
268     ERROR_ILLEGAL_STATE = 6800103,
269     ERROR_UNSUPPORTED   = 6800104,
270     ERROR_TIMEOUT       = 6800105,
271     ERROR_UNSUPPORTED_FORMAT = 6800106,
272     /**
273      * Audio specific errors.
274      */
275     ERROR_STREAM_LIMIT  = 6800201,
276     /**
277      * Default error.
278      */
279     ERROR_SYSTEM        = 6800301
280 };
281 
282 // Ringer Mode
283 enum AudioRingerMode {
284     RINGER_MODE_SILENT = 0,
285     RINGER_MODE_VIBRATE = 1,
286     RINGER_MODE_NORMAL = 2
287 };
288 
289 /**
290  * Enumerates audio stream privacy type for playback capture.
291  */
292 enum AudioPrivacyType {
293     PRIVACY_TYPE_PUBLIC = 0,
294     PRIVACY_TYPE_PRIVATE = 1
295 };
296 
297 /**
298 * Enumerates the renderer playback speed.
299 */
300 enum AudioRendererRate {
301     RENDER_RATE_NORMAL = 0,
302     RENDER_RATE_DOUBLE = 1,
303     RENDER_RATE_HALF = 2,
304 };
305 
306 /**
307 * media safe volume status
308 */
309 enum SafeStatus : int32_t {
310     SAFE_UNKNOWN = -1,
311     SAFE_INACTIVE = 0,
312     SAFE_ACTIVE = 1,
313 };
314 
315 enum CallbackChange : int32_t {
316     CALLBACK_UNKNOWN = 0,
317     CALLBACK_FOCUS_INFO_CHANGE,
318     CALLBACK_RENDERER_STATE_CHANGE,
319     CALLBACK_CAPTURER_STATE_CHANGE,
320     CALLBACK_MICMUTE_STATE_CHANGE,
321     CALLBACK_AUDIO_SESSION,
322     CALLBACK_PREFERRED_OUTPUT_DEVICE_CHANGE,
323     CALLBACK_PREFERRED_INPUT_DEVICE_CHANGE,
324     CALLBACK_SET_VOLUME_KEY_EVENT,
325     CALLBACK_SET_DEVICE_CHANGE,
326     CALLBACK_SET_RINGER_MODE,
327     CALLBACK_APP_VOLUME_CHANGE,
328     CALLBACK_SELF_APP_VOLUME_CHANGE,
329     CALLBACK_ACTIVE_VOLUME_TYPE_CHANGE,
330     CALLBACK_SET_MIC_STATE_CHANGE,
331     CALLBACK_SPATIALIZATION_ENABLED_CHANGE,
332     CALLBACK_HEAD_TRACKING_ENABLED_CHANGE,
333     CALLBACK_SET_MICROPHONE_BLOCKED,
334     CALLBACK_DEVICE_CHANGE_WITH_INFO,
335     CALLBACK_HEAD_TRACKING_DATA_REQUESTED_CHANGE,
336     CALLBACK_NN_STATE_CHANGE,
337     CALLBACK_SET_AUDIO_SCENE_CHANGE,
338     CALLBACK_SPATIALIZATION_ENABLED_CHANGE_FOR_CURRENT_DEVICE,
339     CALLBACK_DISTRIBUTED_OUTPUT_CHANGE,
340     CALLBACK_FORMAT_UNSUPPORTED_ERROR,
341     CALLBACK_STREAM_VOLUME_CHANGE,
342     CALLBACK_SYSTEM_VOLUME_CHANGE,
343     CALLBACK_AUDIO_SESSION_STATE,
344     CALLBACK_AUDIO_SESSION_DEVICE,
345     CALLBACK_SET_VOLUME_DEGREE_CHANGE,
346     CALLBACK_MAX,
347 };
348 
349 enum AdjustStreamVolume {
350     STREAM_VOLUME_INFO = 0,
351     LOW_POWER_VOLUME_INFO,
352     DUCK_VOLUME_INFO,
353 };
354 
355 struct AdjustStreamVolumeInfo {
356     float volume;
357     uint32_t sessionId;
358     std::string invocationTime;
359 };
360 
361 struct StreamVolumeParams {
362     uint32_t sessionId;
363     int32_t streamType;
364     int32_t streamUsage;
365     int32_t uid;
366     int32_t pid;
367     bool isSystemApp;
368     int32_t mode;
369     bool isVKB;
370 };
371 
372 constexpr CallbackChange CALLBACK_ENUMS[] = {
373     CALLBACK_UNKNOWN,
374     CALLBACK_FOCUS_INFO_CHANGE,
375     CALLBACK_RENDERER_STATE_CHANGE,
376     CALLBACK_CAPTURER_STATE_CHANGE,
377     CALLBACK_MICMUTE_STATE_CHANGE,
378     CALLBACK_AUDIO_SESSION,
379     CALLBACK_PREFERRED_OUTPUT_DEVICE_CHANGE,
380     CALLBACK_PREFERRED_INPUT_DEVICE_CHANGE,
381     CALLBACK_SET_VOLUME_KEY_EVENT,
382     CALLBACK_SET_DEVICE_CHANGE,
383     CALLBACK_SET_VOLUME_KEY_EVENT,
384     CALLBACK_ACTIVE_VOLUME_TYPE_CHANGE,
385     CALLBACK_SET_DEVICE_CHANGE,
386     CALLBACK_SET_RINGER_MODE,
387     CALLBACK_SET_MIC_STATE_CHANGE,
388     CALLBACK_SPATIALIZATION_ENABLED_CHANGE,
389     CALLBACK_HEAD_TRACKING_ENABLED_CHANGE,
390     CALLBACK_SET_MICROPHONE_BLOCKED,
391     CALLBACK_DEVICE_CHANGE_WITH_INFO,
392     CALLBACK_HEAD_TRACKING_DATA_REQUESTED_CHANGE,
393     CALLBACK_NN_STATE_CHANGE,
394     CALLBACK_SET_AUDIO_SCENE_CHANGE,
395     CALLBACK_SPATIALIZATION_ENABLED_CHANGE_FOR_CURRENT_DEVICE,
396     CALLBACK_DISTRIBUTED_OUTPUT_CHANGE,
397     CALLBACK_FORMAT_UNSUPPORTED_ERROR,
398     CALLBACK_STREAM_VOLUME_CHANGE,
399     CALLBACK_SYSTEM_VOLUME_CHANGE,
400     CALLBACK_AUDIO_SESSION_STATE,
401     CALLBACK_AUDIO_SESSION_DEVICE,
402     CALLBACK_SET_VOLUME_DEGREE_CHANGE,
403 };
404 
405 static_assert((sizeof(CALLBACK_ENUMS) / sizeof(CallbackChange)) == static_cast<size_t>(CALLBACK_MAX),
406     "check CALLBACK_ENUMS");
407 
408 struct VolumeEvent : public Parcelable {
409     AudioVolumeType volumeType;
410     int32_t volume;
411     int32_t volumeDegree;
412     bool updateUi;
413     int32_t volumeGroupId = 0;
414     std::string networkId = LOCAL_NETWORK_ID;
415     AudioVolumeMode volumeMode = AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL;
416     bool notifyRssWhenAccountsChange = false;
417 
VolumeEventVolumeEvent418     VolumeEvent(AudioVolumeType volType, int32_t volLevel, bool isUiUpdated) : volumeType(volType),
419         volume(volLevel), updateUi(isUiUpdated) {}
420     VolumeEvent() = default;
421 
MarshallingVolumeEvent422     bool Marshalling(Parcel &parcel) const override
423     {
424         return parcel.WriteInt32(static_cast<int32_t>(volumeType))
425             && parcel.WriteInt32(volume)
426             && parcel.WriteInt32(volumeDegree)
427             && parcel.WriteBool(updateUi)
428             && parcel.WriteInt32(volumeGroupId)
429             && parcel.WriteString(networkId)
430             && parcel.WriteInt32(static_cast<int32_t>(volumeMode))
431             && parcel.WriteBool(notifyRssWhenAccountsChange);
432     }
UnmarshallingSelfVolumeEvent433     void UnmarshallingSelf(Parcel &parcel)
434     {
435         volumeType = static_cast<AudioVolumeType>(parcel.ReadInt32());
436         volume = parcel.ReadInt32();
437         volumeDegree = parcel.ReadInt32();
438         updateUi = parcel.ReadBool();
439         volumeGroupId = parcel.ReadInt32();
440         networkId = parcel.ReadString();
441         volumeMode = static_cast<AudioVolumeMode>(parcel.ReadInt32());
442         notifyRssWhenAccountsChange = parcel.ReadBool();
443     }
444 
UnmarshallingVolumeEvent445     static VolumeEvent *Unmarshalling(Parcel &parcel)
446     {
447         auto event = new(std::nothrow) VolumeEvent();
448         if (event == nullptr) {
449             return nullptr;
450         }
451         event->UnmarshallingSelf(parcel);
452         return event;
453     }
454 };
455 
456 struct StreamVolumeEvent : public Parcelable {
457     StreamUsage streamUsage = STREAM_USAGE_INVALID;
458     int32_t volume = -1;
459     bool updateUi = false;
460     int32_t volumeGroupId = -1;
461     std::string networkId = "";
462     AudioVolumeMode volumeMode = AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL;
MarshallingStreamVolumeEvent463     bool Marshalling(Parcel &parcel) const override
464     {
465         return parcel.WriteInt32(static_cast<int32_t>(streamUsage))
466             && parcel.WriteInt32(volume)
467             && parcel.WriteBool(updateUi)
468             && parcel.WriteInt32(volumeGroupId)
469             && parcel.WriteString(networkId)
470             && parcel.WriteInt32(static_cast<int32_t>(volumeMode));
471     }
UnmarshallingSelfStreamVolumeEvent472     void UnmarshallingSelf(Parcel &parcel)
473     {
474         streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
475         volume = parcel.ReadInt32();
476         updateUi = parcel.ReadInt32();
477         volumeGroupId = parcel.ReadInt32();
478         networkId = parcel.ReadString();
479         volumeMode = static_cast<AudioVolumeMode>(parcel.ReadInt32());
480     }
481 
UnmarshallingStreamVolumeEvent482     static StreamVolumeEvent *Unmarshalling(Parcel &parcel)
483     {
484         auto event = new(std::nothrow) StreamVolumeEvent();
485         if (event == nullptr) {
486             return nullptr;
487         }
488 
489         event->UnmarshallingSelf(parcel);
490         return event;
491     }
492 };
493 
494 struct AudioParameters {
495     AudioSampleFormat format;
496     AudioChannel channels;
497     AudioSamplingRate samplingRate;
498     AudioEncodingType encoding;
499     ContentType contentType;
500     StreamUsage usage;
501     DeviceRole deviceRole;
502     DeviceType deviceType;
503     AudioVolumeMode mode;
504 };
505 
506 struct A2dpDeviceConfigInfo {
507     DeviceStreamInfo streamInfo;
508     bool absVolumeSupport = false;
509     int32_t volumeLevel = -1;
510     bool mute = false;
511 };
512 
513 enum PlayerType : int32_t {
514     PLAYER_TYPE_DEFAULT = 0,
515 
516     // AudioFramework internal type.
517     PLAYER_TYPE_OH_AUDIO_RENDERER = 100,
518     PLAYER_TYPE_ARKTS_AUDIO_RENDERER = 101,
519     PLAYER_TYPE_CJ_AUDIO_RENDERER = 102,
520     PLAYER_TYPE_OPENSL_ES = 103,
521 
522     // Indicates a type from the system internals, but not from the AudioFramework.
523     PLAYER_TYPE_SOUND_POOL = 1000,
524     PLAYER_TYPE_AV_PLAYER = 1001,
525     PLAYER_TYPE_SYSTEM_WEBVIEW = 1002,
526     PLAYER_TYPE_TONE_PLAYER = 1003,
527 };
528 
529 enum RecorderType : int32_t {
530     RECORDER_TYPE_DEFAULT = 0,
531 
532     // AudioFramework internal type.
533     RECORDER_TYPE_ARKTS_AUDIO_RECORDER = 100,
534     RECORDER_TYPE_OPENSL_ES = 101,
535 
536     // Indicates a type from the system internals, but not from the AudioFramework.
537     RECORDER_TYPE_AV_RECORDER = 1000,
538 };
539 
540 enum AudioLoopbackMode {
541     /** The hardware mode of audio loopback.*/
542     LOOPBACK_HARDWARE = 0,
543 };
544 
545 enum AudioLoopbackStatus {
546     /** Audio loopback unavailable by the output or input device. For example, the device change.*/
547     LOOPBACK_UNAVAILABLE_DEVICE = -2,
548     /** Audio loopback unavailable by the audio scene. For example, the audio interrupt.*/
549     LOOPBACK_UNAVAILABLE_SCENE = -1,
550     /** Audio loopback available and idle.*/
551     LOOPBACK_AVAILABLE_IDLE = 0,
552     /** Audio loopback available and running.*/
553     LOOPBACK_AVAILABLE_RUNNING = 1,
554 };
555 
556 enum AudioLoopbackState {
557     LOOPBACK_STATE_IDLE,
558     LOOPBACK_STATE_PREPARED,
559     LOOPBACK_STATE_RUNNING,
560     LOOPBACK_STATE_DESTROYING,
561     LOOPBACK_STATE_DESTROYED,
562 };
563 
564 enum AudioLoopbackReverbPreset {
565     /**
566      * A preset that keep the original reverberation without any enhancement.
567      */
568     REVERB_PRESET_ORIGINAL = 1,
569     /**
570      * A preset representing a reverberation effect with karaoke-like acoustic characteristics.
571      */
572     REVERB_PRESET_KTV = 2,
573     /**
574      * A preset representing a reverberation effect with theater-like acoustic characteristics.
575      */
576     REVERB_PRESET_THEATRE = 3,
577     /**
578      * A preset representing a reverberation effect with concert-like acoustic characteristics.
579      */
580     REVERB_PRESET_CONCERT = 4,
581 };
582 
583 enum AudioLoopbackEqualizerPreset {
584     /**
585      * A preset that keep the original frequency response without any enhancement.
586      */
587     EQUALIZER_PRESET_FLAT = 1,
588     /**
589      * A preset representing a equalizer that can enhance the fullness of the vocie
590      */
591     EQUALIZER_PRESET_FULL = 2,
592     /**
593      * A preset representing a equalizer that can enhance the brightness of the vocie
594      */
595     EQUALIZER_PRESET_BRIGHT = 3,
596 };
597 
598 struct AudioRendererInfo : public Parcelable {
599     ContentType contentType = CONTENT_TYPE_UNKNOWN;
600     StreamUsage streamUsage = STREAM_USAGE_UNKNOWN;
601     int32_t rendererFlags = AUDIO_FLAG_NORMAL;
602     AudioVolumeMode volumeMode = AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL;
603     std::string sceneType = "";
604     bool spatializationEnabled = false;
605     bool headTrackingEnabled = false;
606     int32_t originalFlag = AUDIO_FLAG_NORMAL;
607     AudioPipeType pipeType = PIPE_TYPE_UNKNOWN;
608     AudioSamplingRate samplingRate = SAMPLE_RATE_8000;
609     uint8_t encodingType = 0;
610     uint64_t channelLayout = 0ULL;
611     AudioSampleFormat format = SAMPLE_S16LE;
612     bool isOffloadAllowed = true;
613     bool isSatellite = false;
614     PlayerType playerType = PLAYER_TYPE_DEFAULT;
615     // Expected length of audio stream to be played.
616     // Currently only used for making decisions on fade-in and fade-out strategies.
617     // 0 is the default value, it is considered that no
618     uint64_t expectedPlaybackDurationBytes = 0;
619     int32_t effectMode = 1;
620     bool isLoopback = false;
621     AudioLoopbackMode loopbackMode = LOOPBACK_HARDWARE;
622     bool isVirtualKeyboard = false;
623     // store the finally select routeflag after concurrency
624     uint32_t audioFlag = 0x0;
625 
AudioRendererInfoAudioRendererInfo626     AudioRendererInfo() {}
AudioRendererInfoAudioRendererInfo627     AudioRendererInfo(ContentType contentTypeIn, StreamUsage streamUsageIn, int32_t rendererFlagsIn)
628         : contentType(contentTypeIn), streamUsage(streamUsageIn), rendererFlags(rendererFlagsIn) {}
AudioRendererInfoAudioRendererInfo629     AudioRendererInfo(ContentType contentTypeIn, StreamUsage streamUsageIn,
630         int32_t rendererFlagsIn, AudioVolumeMode volumeModeIn)
631         : contentType(contentTypeIn), streamUsage(streamUsageIn),
632         rendererFlags(rendererFlagsIn), volumeMode(volumeModeIn) {}
633 
MarshallingAudioRendererInfo634     bool Marshalling(Parcel &parcel) const override
635     {
636         return parcel.WriteInt32(static_cast<int32_t>(contentType))
637             && parcel.WriteInt32(static_cast<int32_t>(streamUsage))
638             && parcel.WriteInt32(rendererFlags)
639             && parcel.WriteInt32(originalFlag)
640             && parcel.WriteString(sceneType)
641             && parcel.WriteBool(spatializationEnabled)
642             && parcel.WriteBool(headTrackingEnabled)
643             && parcel.WriteInt32(static_cast<int32_t>(pipeType))
644             && parcel.WriteInt32(static_cast<int32_t>(samplingRate))
645             && parcel.WriteUint8(encodingType)
646             && parcel.WriteUint64(channelLayout)
647             && parcel.WriteInt32(format)
648             && parcel.WriteBool(isOffloadAllowed)
649             && parcel.WriteInt32(playerType)
650             && parcel.WriteUint64(expectedPlaybackDurationBytes)
651             && parcel.WriteInt32(effectMode)
652             && parcel.WriteInt32(static_cast<int32_t>(volumeMode))
653             && parcel.WriteBool(isLoopback)
654             && parcel.WriteInt32(static_cast<int32_t>(loopbackMode))
655             && parcel.WriteBool(isVirtualKeyboard)
656             && parcel.WriteUint32(audioFlag);
657     }
UnmarshallingSelfAudioRendererInfo658     void UnmarshallingSelf(Parcel &parcel)
659     {
660         contentType = static_cast<ContentType>(parcel.ReadInt32());
661         streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
662         rendererFlags = parcel.ReadInt32();
663         originalFlag = parcel.ReadInt32();
664         sceneType = parcel.ReadString();
665         spatializationEnabled = parcel.ReadBool();
666         headTrackingEnabled = parcel.ReadBool();
667         pipeType = static_cast<AudioPipeType>(parcel.ReadInt32());
668         samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32());
669         encodingType = parcel.ReadUint8();
670         channelLayout = parcel.ReadUint64();
671         format = static_cast<AudioSampleFormat>(parcel.ReadInt32());
672         isOffloadAllowed = parcel.ReadBool();
673         playerType = static_cast<PlayerType>(parcel.ReadInt32());
674         expectedPlaybackDurationBytes = parcel.ReadUint64();
675         effectMode = parcel.ReadInt32();
676         volumeMode = static_cast<AudioVolumeMode>(parcel.ReadInt32());
677         isLoopback = parcel.ReadBool();
678         loopbackMode = static_cast<AudioLoopbackMode>(parcel.ReadInt32());
679         isVirtualKeyboard = parcel.ReadBool();
680         audioFlag = parcel.ReadUint32();
681     }
682 
UnmarshallingAudioRendererInfo683     static AudioRendererInfo *Unmarshalling(Parcel &parcel)
684     {
685         auto info = new(std::nothrow) AudioRendererInfo();
686         if (info == nullptr) {
687             return nullptr;
688         }
689         info->UnmarshallingSelf(parcel);
690         return info;
691     }
692 };
693 
694 class AudioCapturerInfo : public Parcelable {
695 public:
696     SourceType sourceType = SOURCE_TYPE_INVALID;
697     int32_t capturerFlags = 0;
698     int32_t originalFlag = AUDIO_FLAG_NORMAL;
699     AudioPipeType pipeType = PIPE_TYPE_UNKNOWN;
700     AudioSamplingRate samplingRate = SAMPLE_RATE_8000;
701     uint8_t encodingType = 0;
702     uint64_t channelLayout = 0ULL;
703     std::string sceneType = "";
704     RecorderType recorderType = RECORDER_TYPE_DEFAULT;
705     bool isLoopback = false;
706     AudioLoopbackMode loopbackMode = LOOPBACK_HARDWARE;
707 
AudioCapturerInfo(SourceType sourceType_,int32_t capturerFlags_)708     AudioCapturerInfo(SourceType sourceType_, int32_t capturerFlags_) : sourceType(sourceType_),
709         capturerFlags(capturerFlags_) {}
AudioCapturerInfo(const AudioCapturerInfo & audioCapturerInfo)710     AudioCapturerInfo(const AudioCapturerInfo &audioCapturerInfo)
711     {
712         *this = audioCapturerInfo;
713     }
714     AudioCapturerInfo() = default;
715     ~AudioCapturerInfo()= default;
Marshalling(Parcel & parcel)716     bool Marshalling(Parcel &parcel) const override
717     {
718         return parcel.WriteInt32(static_cast<int32_t>(sourceType)) &&
719             parcel.WriteInt32(capturerFlags) &&
720             parcel.WriteInt32(originalFlag) &&
721             parcel.WriteInt32(static_cast<int32_t>(pipeType)) &&
722             parcel.WriteInt32(static_cast<int32_t>(samplingRate)) &&
723             parcel.WriteUint8(encodingType) &&
724             parcel.WriteUint64(channelLayout) &&
725             parcel.WriteString(sceneType) &&
726             parcel.WriteInt32(static_cast<int32_t>(recorderType)) &&
727             parcel.WriteBool(isLoopback) &&
728             parcel.WriteInt32(static_cast<int32_t>(loopbackMode));
729     }
730 
UnmarshallingSelf(Parcel & parcel)731     void UnmarshallingSelf(Parcel &parcel)
732     {
733         sourceType = static_cast<SourceType>(parcel.ReadInt32());
734         capturerFlags = parcel.ReadInt32();
735         originalFlag = parcel.ReadInt32();
736         pipeType = static_cast<AudioPipeType>(parcel.ReadInt32());
737         samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32());
738         encodingType = parcel.ReadUint8();
739         channelLayout = parcel.ReadUint64();
740         sceneType = parcel.ReadString();
741         recorderType = static_cast<RecorderType>(parcel.ReadInt32());
742         isLoopback = parcel.ReadBool();
743         loopbackMode = static_cast<AudioLoopbackMode>(parcel.ReadInt32());
744     }
745 
Unmarshalling(Parcel & parcel)746     static AudioCapturerInfo *Unmarshalling(Parcel &parcel)
747     {
748         auto audioCapturerInfo = new(std::nothrow) AudioCapturerInfo();
749         if (audioCapturerInfo == nullptr) {
750             return nullptr;
751         }
752         audioCapturerInfo->UnmarshallingSelf(parcel);
753         return audioCapturerInfo;
754     }
755 };
756 
757 struct AudioRendererDesc {
758     ContentType contentType = CONTENT_TYPE_UNKNOWN;
759     StreamUsage streamUsage = STREAM_USAGE_UNKNOWN;
760 };
761 
762 struct AudioRendererOptions {
763     AudioStreamInfo streamInfo;
764     AudioRendererInfo rendererInfo;
765     AudioPrivacyType privacyType = PRIVACY_TYPE_PUBLIC;
766     AudioSessionStrategy strategy = { AudioConcurrencyMode::INVALID };
767 };
768 
769 struct MicStateChangeEvent : public Parcelable {
770     bool mute;
771 
MarshallingMicStateChangeEvent772     bool Marshalling(Parcel &parcel) const override
773     {
774         return parcel.WriteBool(mute);
775     }
776 
UnmarshallingMicStateChangeEvent777     static MicStateChangeEvent *Unmarshalling(Parcel &parcel)
778     {
779         auto event = new(std::nothrow) MicStateChangeEvent();
780         if (event == nullptr) {
781             return nullptr;
782         }
783         event->mute = parcel.ReadBool();
784         return event;
785     }
786 };
787 
788 enum AudioScene : int32_t {
789     /**
790      * Invalid
791      */
792     AUDIO_SCENE_INVALID = -1,
793     /**
794      * Default audio scene
795      */
796     AUDIO_SCENE_DEFAULT,
797     /**
798      * Ringing audio scene
799      * Only available for system api.
800      */
801     AUDIO_SCENE_RINGING,
802     /**
803      * Phone call audio scene
804      * Only available for system api.
805      */
806     AUDIO_SCENE_PHONE_CALL,
807     /**
808      * Voice chat audio scene
809      */
810     AUDIO_SCENE_PHONE_CHAT,
811     /**
812      * AvSession set call start flag
813      */
814     AUDIO_SCENE_CALL_START,
815     /**
816      * AvSession set call end flag
817      */
818     AUDIO_SCENE_CALL_END,
819     /**
820      * Voice ringing audio scene
821      * Only available for system api.
822      */
823     AUDIO_SCENE_VOICE_RINGING,
824     /**
825      * Max
826      */
827     AUDIO_SCENE_MAX,
828 };
829 
830 enum AudioDeviceUsage : uint32_t {
831     /**
832      * Media output devices.
833      * @syscap SystemCapability.Multimedia.Audio.Device
834      * @systemapi
835      * @since 11
836      */
837     MEDIA_OUTPUT_DEVICES = 1,
838     /**
839      * Media input devices.
840      * @syscap SystemCapability.Multimedia.Audio.Device
841      * @systemapi
842      * @since 11
843      */
844     MEDIA_INPUT_DEVICES = 2,
845     /**
846      * All media devices.
847      * @syscap SystemCapability.Multimedia.Audio.Device
848      * @systemapi
849      * @since 11
850      */
851     ALL_MEDIA_DEVICES = 3,
852     /**
853      * Call output devices.
854      * @syscap SystemCapability.Multimedia.Audio.Device
855      * @systemapi
856      * @since 11
857      */
858     CALL_OUTPUT_DEVICES = 4,
859     /**
860      * Call input devices.
861      * @syscap SystemCapability.Multimedia.Audio.Device
862      * @systemapi
863      * @since 11
864      */
865     CALL_INPUT_DEVICES = 8,
866     /**
867      * All call devices.
868      * @syscap SystemCapability.Multimedia.Audio.Device
869      * @systemapi
870      * @since 11
871      */
872     ALL_CALL_DEVICES = 12,
873     /**
874      * All devices.
875      * @syscap SystemCapability.Multimedia.Audio.Device
876      * @systemapi
877      * @since 11
878      */
879     D_ALL_DEVICES = 15,
880 };
881 
882 enum FilterMode : uint32_t {
883     INCLUDE = 0,
884     EXCLUDE,
885     MAX_FILTER_MODE
886 };
887 
888 // 1.If the size of usages or pids is 0, FilterMode will not work.
889 // 2.Filters will only works with FileterMode INCLUDE or EXCLUDE while the vector size is not zero.
890 // 3.If usages and pids are both not empty, the result is the intersection of the two Filter.
891 // 4.If usages.size() == 0, defalut usages will be filtered with FilterMode::INCLUDE.
892 // 5.Default usages are MEDIA MUSIC MOVIE GAME and BOOK.
893 struct CaptureFilterOptions {
894     std::vector<StreamUsage> usages;
895     FilterMode usageFilterMode {FilterMode::INCLUDE};
896     std::vector<int32_t> pids;
897     FilterMode pidFilterMode {FilterMode::INCLUDE};
898 
899     CaptureFilterOptions() = default;
CaptureFilterOptionsCaptureFilterOptions900     CaptureFilterOptions(const std::vector<StreamUsage> &usage, FilterMode uFilterMode,
901         const std::vector<int32_t> &pid, FilterMode pFilterMode)
902     {
903         this->usages = usage;
904         this->usageFilterMode = uFilterMode;
905         this->pids = pid;
906         this->pidFilterMode = pFilterMode;
907     }
908 
909     bool operator ==(CaptureFilterOptions& filter)
910     {
911         std::sort(filter.usages.begin(), filter.usages.end());
912         std::sort(filter.pids.begin(), filter.pids.end());
913         std::sort(usages.begin(), usages.end());
914         std::sort(pids.begin(), pids.end());
915         return (filter.usages == usages && filter.usageFilterMode == usageFilterMode
916             && filter.pids == pids && filter.pidFilterMode == pidFilterMode);
917     }
918 };
919 
920 inline constexpr uint32_t MAX_VALID_USAGE_SIZE = 30; // 128 for pids
921 inline constexpr uint32_t MAX_VALID_PIDS_SIZE = 128; // 128 for pids
922 
923 struct AudioPlaybackCaptureConfig : public Parcelable {
924     CaptureFilterOptions filterOptions;
925     bool silentCapture {false}; // To be deprecated since 12
926 
927     AudioPlaybackCaptureConfig() = default;
AudioPlaybackCaptureConfigAudioPlaybackCaptureConfig928     AudioPlaybackCaptureConfig(const CaptureFilterOptions &filter, const bool silent)
929         : filterOptions(filter), silentCapture(silent)
930     {
931     }
932 
933     bool operator ==(AudioPlaybackCaptureConfig& filter)
934     {
935         return (filter.filterOptions == filterOptions && filter.silentCapture == silentCapture);
936     }
937 
MarshallingAudioPlaybackCaptureConfig938     bool Marshalling(Parcel &parcel) const override
939     {
940         // filterOptions.usages
941         size_t usageSize = filterOptions.usages.size();
942         if (usageSize >= MAX_VALID_USAGE_SIZE) return false;
943         parcel.WriteUint32(usageSize);
944         for (size_t i = 0; i < usageSize; i++) {
945             parcel.WriteInt32(static_cast<int32_t>(filterOptions.usages[i]));
946         }
947 
948         // filterOptions.usageFilterMode
949         parcel.WriteUint32(filterOptions.usageFilterMode);
950 
951         // filterOptions.pids
952         size_t pidSize = filterOptions.pids.size();
953         if (pidSize >= MAX_VALID_PIDS_SIZE) return false;
954         parcel.WriteUint32(pidSize);
955         for (size_t i = 0; i < pidSize; i++) {
956             parcel.WriteUint32(filterOptions.pids[i]);
957         }
958 
959         // filterOptions.pidFilterMode
960         parcel.WriteUint32(filterOptions.pidFilterMode);
961 
962         // silentCapture
963         parcel.WriteBool(silentCapture);
964         return true;
965     }
966 
UnmarshallingAudioPlaybackCaptureConfig967     static AudioPlaybackCaptureConfig *Unmarshalling(Parcel &parcel)
968     {
969         auto config = new(std::nothrow) AudioPlaybackCaptureConfig();
970         if (config == nullptr) return nullptr;
971         // filterOptions.usages
972         uint32_t usageSize = parcel.ReadUint32();
973         if (usageSize > MAX_VALID_USAGE_SIZE) {
974             delete config;
975             return nullptr;
976         }
977         std::vector<StreamUsage> usages = {};
978         for (uint32_t i = 0; i < usageSize; i++) {
979             int32_t tmpUsage = parcel.ReadInt32();
980             if (std::find(AUDIO_SUPPORTED_STREAM_USAGES.begin(), AUDIO_SUPPORTED_STREAM_USAGES.end(), tmpUsage) ==
981                 AUDIO_SUPPORTED_STREAM_USAGES.end()) {
982                 delete config;
983                 return nullptr;
984             }
985             usages.push_back(static_cast<StreamUsage>(tmpUsage));
986         }
987         config->filterOptions.usages = usages;
988 
989         // filterOptions.usageFilterMode
990         uint32_t tempMode = parcel.ReadUint32();
991         if (tempMode >= FilterMode::MAX_FILTER_MODE) {
992             delete config;
993             return nullptr;
994         }
995         config->filterOptions.usageFilterMode = static_cast<FilterMode>(tempMode);
996 
997         // filterOptions.pids
998         uint32_t pidSize = parcel.ReadUint32();
999         if (pidSize > MAX_VALID_PIDS_SIZE) {
1000             delete config;
1001             return nullptr;
1002         }
1003         std::vector<int32_t> pids = {};
1004         for (uint32_t i = 0; i < pidSize; i++) {
1005             int32_t tmpPid = parcel.ReadInt32();
1006             if (tmpPid <= 0) {
1007                 delete config;
1008                 return nullptr;
1009             }
1010             pids.push_back(tmpPid);
1011         }
1012         config->filterOptions.pids = pids;
1013 
1014         // filterOptions.pidFilterMode
1015         tempMode = parcel.ReadUint32();
1016         if (tempMode >= FilterMode::MAX_FILTER_MODE) {
1017             delete config;
1018             return nullptr;
1019         }
1020         config->filterOptions.pidFilterMode = static_cast<FilterMode>(tempMode);
1021 
1022         // silentCapture
1023         config->silentCapture = parcel.ReadBool();
1024 
1025         return config;
1026     }
1027 };
1028 
1029 struct AudioCapturerOptions {
1030     AudioStreamInfo streamInfo;
1031     AudioCapturerInfo capturerInfo;
1032     AudioPlaybackCaptureConfig playbackCaptureConfig;
1033     AudioSessionStrategy strategy = { AudioConcurrencyMode::INVALID };
1034 };
1035 
1036 struct AppInfo {
1037     int32_t appUid { INVALID_UID };
1038     uint32_t appTokenId { 0 };
1039     int32_t appPid { 0 };
1040     uint64_t appFullTokenId { 0 };
1041 };
1042 
1043 struct BufferQueueState {
1044     uint32_t numBuffers;
1045     uint32_t currentIndex;
1046 };
1047 
1048 enum AudioRenderMode {
1049     RENDER_MODE_NORMAL,
1050     RENDER_MODE_CALLBACK
1051 };
1052 
1053 enum AudioCaptureMode {
1054     CAPTURE_MODE_NORMAL,
1055     CAPTURE_MODE_CALLBACK
1056 };
1057 
1058 struct SinkInfo {
1059     uint32_t sinkId; // sink id
1060     std::string sinkName;
1061     std::string adapterName;
1062 };
1063 
1064 struct SinkInput : public Parcelable {
1065     int32_t streamId;
1066     AudioStreamType streamType;
1067 
1068     // add for routing stream.
1069     int32_t uid; // client uid
1070     int32_t pid; // client pid
1071     uint32_t paStreamId; // streamId
1072     uint32_t deviceSinkId; // sink id
1073     std::string sinkName; // sink name
1074     int32_t statusMark; // mark the router status
1075     uint64_t startTime; // when this router is created
MarshallingSinkInput1076     bool Marshalling(Parcel &parcel) const override
1077     {
1078         return parcel.WriteInt32(streamId) &&
1079                parcel.WriteInt32(static_cast<int32_t>(streamType)) &&
1080                parcel.WriteInt32(uid) &&
1081                parcel.WriteInt32(pid) &&
1082                parcel.WriteUint32(paStreamId);
1083     }
1084 
UnmarshallingSinkInput1085     static SinkInput *Unmarshalling(Parcel &parcel)
1086     {
1087         auto sinkInput = new(std::nothrow) SinkInput();
1088         if (sinkInput == nullptr) {
1089             return nullptr;
1090         }
1091 
1092         sinkInput->streamId = parcel.ReadInt32();
1093         sinkInput->streamType = static_cast<AudioStreamType>(parcel.ReadInt32());
1094         sinkInput->uid = parcel.ReadInt32();
1095         sinkInput->pid = parcel.ReadInt32();
1096         sinkInput->paStreamId = parcel.ReadUint32();
1097         return sinkInput;
1098     }
1099 };
1100 
1101 struct SourceOutput {
1102     int32_t streamId;
1103     AudioStreamType streamType;
1104 
1105     // add for routing stream.
1106     int32_t uid; // client uid
1107     int32_t pid; // client pid
1108     uint32_t paStreamId; // streamId
1109     uint32_t deviceSourceId; // sink id
1110     int32_t statusMark; // mark the router status
1111     uint64_t startTime; // when this router is created
1112 };
1113 
1114 typedef uint32_t AudioIOHandle;
1115 
FLOAT_COMPARE_EQ(const float & x,const float & y)1116 static inline bool FLOAT_COMPARE_EQ(const float& x, const float& y)
1117 {
1118     return (std::abs((x) - (y)) <= (std::numeric_limits<float>::epsilon()));
1119 }
1120 
1121 enum AudioServiceIndex {
1122     HDI_SERVICE_INDEX = 0,
1123     AUDIO_SERVICE_INDEX
1124 };
1125 
1126 /**
1127  * @brief Enumerates the rendering states of the current device.
1128  */
1129 enum RendererState {
1130     /** INVALID state */
1131     RENDERER_INVALID = -1,
1132     /** Create New Renderer instance */
1133     RENDERER_NEW,
1134     /** Reneder Prepared state */
1135     RENDERER_PREPARED,
1136     /** Rendere Running state */
1137     RENDERER_RUNNING,
1138     /** Renderer Stopped state */
1139     RENDERER_STOPPED,
1140     /** Renderer Released state */
1141     RENDERER_RELEASED,
1142     /** Renderer Paused state */
1143     RENDERER_PAUSED
1144 };
1145 
1146 /**
1147  * @brief Enumerates the capturing states of the current device.
1148  */
1149 enum CapturerState {
1150     /** Capturer INVALID state */
1151     CAPTURER_INVALID = -1,
1152     /** Create new capturer instance */
1153     CAPTURER_NEW,
1154     /** Capturer Prepared state */
1155     CAPTURER_PREPARED,
1156     /** Capturer Running state */
1157     CAPTURER_RUNNING,
1158     /** Capturer Stopped state */
1159     CAPTURER_STOPPED,
1160     /** Capturer Released state */
1161     CAPTURER_RELEASED,
1162     /** Capturer Paused state */
1163     CAPTURER_PAUSED
1164 };
1165 
1166 enum State {
1167     /** INVALID */
1168     INVALID = -1,
1169     /** New */
1170     NEW,
1171     /** Prepared */
1172     PREPARED,
1173     /** Running */
1174     RUNNING,
1175     /** Stopped */
1176     STOPPED,
1177     /** Released */
1178     RELEASED,
1179     /** Paused */
1180     PAUSED,
1181     /** Stopping */
1182     STOPPING
1183 };
1184 
1185 /**
1186  * @brief Defines the fast status.
1187  */
1188 enum FastStatus {
1189     /** Invalid status */
1190     FASTSTATUS_INVALID = -1,
1191     /** Normal status */
1192     FASTSTATUS_NORMAL,
1193     /** Fast status */
1194     FASTSTATUS_FAST
1195 };
1196 
1197 struct StreamSwitchingInfo {
1198     bool isSwitching_ = false;
1199     State state_ = INVALID;
1200 };
1201 
1202 struct AudioRegisterTrackerInfo {
1203     uint32_t sessionId;
1204     int32_t clientPid;
1205     State state;
1206     AudioRendererInfo rendererInfo;
1207     AudioCapturerInfo capturerInfo;
1208     int32_t channelCount;
1209     uint32_t appTokenId;
1210 };
1211 
1212 enum StateChangeCmdType {
1213     CMD_FROM_CLIENT = 0,
1214     CMD_FROM_SYSTEM = 1
1215 };
1216 
1217 enum AudioMode {
1218     AUDIO_MODE_PLAYBACK,
1219     AUDIO_MODE_RECORD
1220 };
1221 
1222 enum StopAudioType {
1223     STOP_ALL,
1224     STOP_RENDER,
1225     STOP_RECORD
1226 };
1227 
1228 enum RecordErrorCode {
1229     RECORD_ERROR_GET_FOCUS_FAIL = 0,
1230     RECORD_ERROR_NO_FOCUS_CFG = 1,
1231 };
1232 
1233 // LEGACY_INNER_CAP: Called from hap build with api < 12, work normally.
1234 // LEGACY_MUTE_CAP: Called from hap build with api >= 12, will cap mute data.
1235 // MODERN_INNER_CAP: Called from SA with inner-cap right, work with filter.
1236 enum InnerCapMode : uint32_t {
1237     LEGACY_INNER_CAP = 0,
1238     LEGACY_MUTE_CAP,
1239     MODERN_INNER_CAP,
1240     INVALID_CAP_MODE
1241 };
1242 
1243 struct AudioProcessConfig : public Parcelable {
1244     int32_t callerUid = INVALID_UID;
1245 
1246     AppInfo appInfo;
1247 
1248     AudioStreamInfo streamInfo;
1249 
1250     AudioMode audioMode = AUDIO_MODE_PLAYBACK;
1251 
1252     AudioRendererInfo rendererInfo;
1253 
1254     AudioCapturerInfo capturerInfo;
1255 
1256     AudioStreamType streamType = STREAM_DEFAULT;
1257 
1258     DeviceType deviceType = DEVICE_TYPE_INVALID;
1259 
1260     bool isInnerCapturer = false;
1261 
1262     bool isWakeupCapturer = false;
1263 
1264     uint32_t originalSessionId = 0;
1265 
1266     AudioPrivacyType privacyType = PRIVACY_TYPE_PUBLIC;
1267 
1268     InnerCapMode innerCapMode {InnerCapMode::INVALID_CAP_MODE};
1269 
1270     int32_t innerCapId = 0;
1271 
AudioProcessConfigAudioProcessConfig1272     AudioProcessConfig() {}
MarshallingAudioProcessConfig1273     bool Marshalling(Parcel &parcel) const override
1274     {
1275         // AppInfo
1276         parcel.WriteInt32(appInfo.appUid);
1277         parcel.WriteUint32(appInfo.appTokenId);
1278         parcel.WriteInt32(appInfo.appPid);
1279         parcel.WriteUint64(appInfo.appFullTokenId);
1280 
1281         // AudioStreamInfo
1282         parcel.WriteInt32(streamInfo.samplingRate);
1283         parcel.WriteInt32(streamInfo.encoding);
1284         parcel.WriteInt32(streamInfo.format);
1285         parcel.WriteInt32(streamInfo.channels);
1286         parcel.WriteUint64(streamInfo.channelLayout);
1287 
1288         // AudioMode
1289         parcel.WriteInt32(audioMode);
1290 
1291         // AudioRendererInfo
1292         parcel.WriteInt32(rendererInfo.contentType);
1293         parcel.WriteInt32(rendererInfo.streamUsage);
1294         parcel.WriteInt32(rendererInfo.rendererFlags);
1295         parcel.WriteInt32(rendererInfo.volumeMode);
1296         parcel.WriteInt32(rendererInfo.originalFlag);
1297         parcel.WriteString(rendererInfo.sceneType);
1298         parcel.WriteBool(rendererInfo.spatializationEnabled);
1299         parcel.WriteBool(rendererInfo.headTrackingEnabled);
1300         parcel.WriteBool(rendererInfo.isSatellite);
1301         parcel.WriteInt32(rendererInfo.pipeType);
1302         parcel.WriteInt32(rendererInfo.playerType);
1303         parcel.WriteUint64(rendererInfo.expectedPlaybackDurationBytes);
1304         parcel.WriteInt32(rendererInfo.effectMode);
1305         parcel.WriteBool(rendererInfo.isLoopback);
1306         parcel.WriteInt32(static_cast<int32_t>(rendererInfo.loopbackMode));
1307         parcel.WriteBool(rendererInfo.isVirtualKeyboard);
1308 
1309         //AudioPrivacyType
1310         parcel.WriteInt32(privacyType);
1311 
1312         // AudioCapturerInfo
1313         parcel.WriteInt32(capturerInfo.sourceType);
1314         parcel.WriteInt32(capturerInfo.capturerFlags);
1315         parcel.WriteInt32(capturerInfo.originalFlag);
1316         parcel.WriteInt32(capturerInfo.pipeType);
1317         parcel.WriteInt32(capturerInfo.recorderType);
1318         parcel.WriteBool(capturerInfo.isLoopback);
1319         parcel.WriteInt32(static_cast<int32_t>(capturerInfo.loopbackMode));
1320 
1321         // streamType
1322         parcel.WriteInt32(streamType);
1323 
1324         // deviceType
1325         parcel.WriteInt32(deviceType);
1326 
1327         // Recorder only
1328         parcel.WriteBool(isInnerCapturer);
1329         parcel.WriteBool(isWakeupCapturer);
1330 
1331         // Original session id for re-create stream
1332         parcel.WriteUint32(originalSessionId);
1333         parcel.WriteInt32(innerCapId);
1334 
1335         return true;
1336     }
1337 
UnmarshallingAudioProcessConfig1338     static AudioProcessConfig *Unmarshalling(Parcel &parcel)
1339     {
1340         auto config = new(std::nothrow) AudioProcessConfig();
1341         if (config == nullptr) {
1342             return nullptr;
1343         }
1344         // AppInfo
1345         config->appInfo.appUid = parcel.ReadInt32();
1346         config->appInfo.appTokenId = parcel.ReadUint32();
1347         config->appInfo.appPid = parcel.ReadInt32();
1348         config->appInfo.appFullTokenId = parcel.ReadUint64();
1349 
1350         // AudioStreamInfo
1351         config->streamInfo.samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32());
1352         config->streamInfo.encoding = static_cast<AudioEncodingType>(parcel.ReadInt32());
1353         config->streamInfo.format = static_cast<AudioSampleFormat>(parcel.ReadInt32());
1354         config->streamInfo.channels = static_cast<AudioChannel>(parcel.ReadInt32());
1355         config->streamInfo.channelLayout = static_cast<AudioChannelLayout>(parcel.ReadUint64());
1356 
1357         // AudioMode
1358         config->audioMode = static_cast<AudioMode>(parcel.ReadInt32());
1359 
1360         // AudioRendererInfo
1361         config->rendererInfo.contentType = static_cast<ContentType>(parcel.ReadInt32());
1362         config->rendererInfo.streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
1363         config->rendererInfo.rendererFlags = parcel.ReadInt32();
1364         config->rendererInfo.volumeMode = static_cast<AudioVolumeMode>(parcel.ReadInt32());
1365         config->rendererInfo.originalFlag = parcel.ReadInt32();
1366         config->rendererInfo.sceneType = parcel.ReadString();
1367         config->rendererInfo.spatializationEnabled = parcel.ReadBool();
1368         config->rendererInfo.headTrackingEnabled = parcel.ReadBool();
1369         config->rendererInfo.isSatellite = parcel.ReadBool();
1370         config->rendererInfo.pipeType = static_cast<AudioPipeType>(parcel.ReadInt32());
1371         config->rendererInfo.playerType = static_cast<PlayerType>(parcel.ReadInt32());
1372         config->rendererInfo.expectedPlaybackDurationBytes = parcel.ReadUint64();
1373         config->rendererInfo.effectMode = parcel.ReadInt32();
1374         config->rendererInfo.isLoopback = parcel.ReadBool();
1375         config->rendererInfo.loopbackMode = static_cast<AudioLoopbackMode>(parcel.ReadInt32());
1376         config->rendererInfo.isVirtualKeyboard = parcel.ReadBool();
1377 
1378         //AudioPrivacyType
1379         config->privacyType = static_cast<AudioPrivacyType>(parcel.ReadInt32());
1380 
1381         // AudioCapturerInfo
1382         config->capturerInfo.sourceType = static_cast<SourceType>(parcel.ReadInt32());
1383         config->capturerInfo.capturerFlags = parcel.ReadInt32();
1384         config->capturerInfo.originalFlag = parcel.ReadInt32();
1385         config->capturerInfo.pipeType = static_cast<AudioPipeType>(parcel.ReadInt32());
1386         config->capturerInfo.recorderType = static_cast<RecorderType>(parcel.ReadInt32());
1387         config->capturerInfo.isLoopback = parcel.ReadBool();
1388         config->capturerInfo.loopbackMode = static_cast<AudioLoopbackMode>(parcel.ReadInt32());
1389 
1390         // streamType
1391         config->streamType = static_cast<AudioStreamType>(parcel.ReadInt32());
1392 
1393         // deviceType
1394         config->deviceType = static_cast<DeviceType>(parcel.ReadInt32());
1395 
1396         // Recorder only
1397         config->isInnerCapturer = parcel.ReadBool();
1398         config->isWakeupCapturer = parcel.ReadBool();
1399 
1400         // Original session id for re-create stream
1401         config->originalSessionId = parcel.ReadUint32();
1402         config->innerCapId = parcel.ReadInt32();
1403 
1404         return config;
1405     }
1406 };
1407 
1408 struct Volume {
1409     bool isMute = false;
1410     float volumeFloat = 1.0f;
1411     uint32_t volumeInt = 0;
1412     uint32_t volumeDegree = 0;
1413 };
1414 
1415 enum AppIsBackState {
1416     STATE_UNKNOWN = -1,
1417     STATE_FOREGROUND,
1418     STATE_BACKGROUND,
1419     STATE_END,
1420 };
1421 
1422 enum StreamSetState {
1423     STREAM_PAUSE,
1424     STREAM_RESUME,
1425     STREAM_MUTE,
1426     STREAM_UNMUTE
1427 };
1428 
1429 enum SwitchState {
1430     SWITCH_STATE_WAITING,
1431     SWITCH_STATE_TIMEOUT,
1432     SWITCH_STATE_CREATED,
1433     SWITCH_STATE_STARTED,
1434     SWITCH_STATE_FINISHED
1435 };
1436 
1437 struct SwitchStreamInfo {
1438     uint32_t sessionId = 0;
1439     int32_t callerUid = INVALID_UID;
1440     int32_t appUid = INVALID_UID;
1441     int32_t appPid = 0;
1442     uint32_t appTokenId = 0;
1443     CapturerState nextState = CAPTURER_INVALID;
1444     bool operator==(const SwitchStreamInfo& info) const
1445     {
1446         return sessionId == info.sessionId && callerUid == info.callerUid &&
1447             appUid == info.appUid && appPid == info.appPid && appTokenId == info.appTokenId;
1448     }
1449     bool operator!=(const SwitchStreamInfo& info) const
1450     {
1451         return !(*this == info);
1452     }
1453 
1454     bool operator<(const SwitchStreamInfo& info) const
1455     {
1456         if (sessionId != info.sessionId) {
1457             return sessionId < info.sessionId;
1458         }
1459         if (callerUid != info.callerUid) {
1460             return callerUid < info.callerUid;
1461         }
1462         if (appUid != info.appUid) {
1463             return appUid < info.appUid;
1464         }
1465         if (appPid != info.appPid) {
1466             return appPid < info.appPid;
1467         }
1468         return appTokenId < info.appTokenId;
1469     }
1470 
1471     bool operator<=(const SwitchStreamInfo& info) const
1472     {
1473         return *this < info || *this == info;
1474     }
1475     bool operator>(const SwitchStreamInfo& info) const
1476     {
1477         return !(*this <= info);
1478     }
1479     bool operator>=(const SwitchStreamInfo& info) const
1480     {
1481         return !(*this < info);
1482     }
1483 };
1484 
1485 struct StreamSetStateEventInternal : public Parcelable {
1486     StreamSetState streamSetState;
1487     StreamUsage streamUsage;
1488 
MarshallingStreamSetStateEventInternal1489     bool Marshalling(Parcel &parcel) const override
1490     {
1491         return parcel.WriteInt32(static_cast<int32_t>(streamSetState)) &&
1492             parcel.WriteInt32(static_cast<int32_t>(streamUsage));
1493     }
UnmarshallingStreamSetStateEventInternal1494     static StreamSetStateEventInternal *Unmarshalling(Parcel &parcel)
1495     {
1496         auto event = new(std::nothrow) StreamSetStateEventInternal();
1497         if (event == nullptr) {
1498             return nullptr;
1499         }
1500         event->streamSetState = static_cast<StreamSetState>(parcel.ReadInt32());
1501         event->streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
1502         return event;
1503     }
1504 };
1505 
1506 enum AudioPin {
1507     AUDIO_PIN_NONE = 0, // Invalid pin
1508     AUDIO_PIN_OUT_SPEAKER = 1 << 0, // Speaker output pin
1509     AUDIO_PIN_OUT_HEADSET = 1 << 1, // Wired headset pin for output
1510     AUDIO_PIN_OUT_LINEOUT = 1 << 2, // Line-out pin
1511     AUDIO_PIN_OUT_HDMI = 1 << 3, // HDMI output pin
1512     AUDIO_PIN_OUT_USB = 1 << 4, // USB output pin
1513     AUDIO_PIN_OUT_USB_EXT = 1 << 5, // Extended USB output pin
1514     AUDIO_PIN_OUT_EARPIECE = 1 << 5 | 1 << 4, // Earpiece output pin
1515     AUDIO_PIN_OUT_BLUETOOTH_SCO = 1 << 6, // Bluetooth SCO output pin
1516     AUDIO_PIN_OUT_DAUDIO_DEFAULT = 1 << 7, // Daudio default output pin
1517     AUDIO_PIN_OUT_HEADPHONE = 1 << 8, // Wired headphone output pin
1518     AUDIO_PIN_OUT_USB_HEADSET = 1 << 9,  // Arm usb output pin
1519     AUDIO_PIN_OUT_BLUETOOTH_A2DP = 1 << 10,  // Bluetooth A2dp output pin
1520     AUDIO_PIN_OUT_DP = 1 << 11,
1521     AUDIO_PIN_OUT_NEARLINK = 1 << 12, // Nearlink output pin
1522     AUDIO_PIN_OUT_HEARING_AID = 1 << 13, // HearingAid output pin
1523     AUDIO_PIN_IN_MIC = 1 << 27 | 1 << 0, // Microphone input pin
1524     AUDIO_PIN_IN_HS_MIC = 1 << 27 | 1 << 1, // Wired headset microphone pin for input
1525     AUDIO_PIN_IN_LINEIN = 1 << 27 | 1 << 2, // Line-in pin
1526     AUDIO_PIN_IN_USB_EXT = 1 << 27 | 1 << 3, // Extended USB input pin
1527     AUDIO_PIN_IN_BLUETOOTH_SCO_HEADSET = 1 << 27 | 1 << 4, // Bluetooth SCO headset input pin
1528     AUDIO_PIN_IN_DAUDIO_DEFAULT = 1 << 27 | 1 << 5, // Daudio default input pin
1529     AUDIO_PIN_IN_USB_HEADSET = 1 << 27 | 1 << 6,  // Arm usb input pin
1530     AUDIO_PIN_IN_PENCIL = 1 << 27 | 1 << 7,  // Pencil input pin
1531     AUDIO_PIN_IN_UWB = 1 << 27 | 1 << 8,  // Remote control input pin
1532     AUDIO_PIN_IN_NEARLINK = 1 << 27 | 1 << 9,  // Nearlink input pin
1533 };
1534 
1535 enum AudioParamKey {
1536     NONE = 0,
1537     VOLUME = 1,
1538     INTERRUPT = 2,
1539     PARAM_KEY_STATE = 5,
1540     A2DP_SUSPEND_STATE = 6,  // for bluetooth sink
1541     BT_HEADSET_NREC = 7,
1542     BT_WBS = 8,
1543     A2DP_OFFLOAD_STATE = 9, // for a2dp offload
1544     GET_DP_DEVICE_INFO = 10, // for dp sink
1545     GET_PENCIL_INFO = 11, // for pencil source
1546     GET_UWB_INFO = 12, // for remote control source
1547     USB_DEVICE = 101, // Check USB device type ARM or HIFI
1548     PERF_INFO = 201,
1549     MMI = 301,
1550     PARAM_KEY_LOWPOWER = 1000,
1551 };
1552 
1553 struct DStatusInfo {
1554     char networkId[NETWORK_ID_SIZE];
1555     AudioPin hdiPin = AUDIO_PIN_NONE;
1556     int32_t mappingVolumeId = 0;
1557     int32_t mappingInterruptId = 0;
1558     int32_t deviceId;
1559     int32_t channelMasks;
1560     std::string deviceName = "";
1561     bool isConnected = false;
1562     std::string macAddress;
1563     std::list<DeviceStreamInfo> streamInfo = {};
1564     ConnectType connectType = CONNECT_TYPE_LOCAL;
1565 };
1566 
1567 struct AudioRendererDataInfo {
1568     uint8_t *buffer;
1569     size_t flag;
1570 };
1571 
1572 enum AudioPermissionState {
1573     AUDIO_PERMISSION_START = 0,
1574     AUDIO_PERMISSION_STOP = 1,
1575 };
1576 
1577 class AudioRendererPolicyServiceDiedCallback {
1578 public:
1579     virtual ~AudioRendererPolicyServiceDiedCallback() = default;
1580 
1581     /**
1582      * Called when audio policy service died.
1583      * @since 10
1584      */
1585     virtual void OnAudioPolicyServiceDied() = 0;
1586 };
1587 
1588 class AudioCapturerPolicyServiceDiedCallback {
1589 public:
1590     virtual ~AudioCapturerPolicyServiceDiedCallback() = default;
1591 
1592     /**
1593      * Called when audio policy service died.
1594      * @since 10
1595      */
1596     virtual void OnAudioPolicyServiceDied() = 0;
1597 };
1598 
1599 class AudioStreamPolicyServiceDiedCallback {
1600 public:
1601     virtual ~AudioStreamPolicyServiceDiedCallback() = default;
1602 
1603     /**
1604      * Called when audio policy service died.
1605      * @since 11
1606      */
1607     virtual void OnAudioPolicyServiceDied() = 0;
1608 };
1609 
1610 class AudioSessionManagerPolicyServiceDiedCallback {
1611 public:
1612     virtual ~AudioSessionManagerPolicyServiceDiedCallback() = default;
1613 
1614     /**
1615      * Called when audio policy service died.
1616      * @since 20
1617      */
1618     virtual void OnAudioPolicyServiceDied() = 0;
1619 };
1620 
1621 /**
1622  * Describes three-dimensional value.
1623  * @since 11
1624  */
1625 struct Vector3D {
1626     /**
1627      * X-axis value.
1628      * @since 11
1629      */
1630     float x;
1631     /**
1632      * Y-axis value.
1633      * @since 11
1634      */
1635     float y;
1636     /**
1637      * Z-axis value.
1638      * @since 11
1639      */
1640     float z;
1641 };
1642 
1643 struct SessionInfo {
1644     SourceType sourceType;
1645     uint32_t rate;
1646     uint32_t channels;
1647 };
1648 
1649 enum CastType {
1650     CAST_TYPE_NULL = 0,
1651     CAST_TYPE_ALL,
1652     CAST_TYPE_PROJECTION,
1653     CAST_TYPE_COOPERATION,
1654 };
1655 
1656 class AudioPnpDeviceChangeCallback {
1657 public:
1658     virtual ~AudioPnpDeviceChangeCallback() = default;
1659     virtual void OnPnpDeviceStatusChanged(const std::string &info) = 0;
1660     virtual void OnMicrophoneBlocked(const std::string &info) = 0;
1661 };
1662 
1663 struct SourceInfo {
1664     SourceType sourceType_;
1665     uint32_t rate_;
1666     uint32_t channels_;
1667 };
1668 
1669 /**
1670  * @brief Device group used by set/get volume.
1671  */
1672 enum DeviceGroup {
1673     /** Invalid device group */
1674     DEVICE_GROUP_INVALID = -1,
1675     /** Built in device */
1676     DEVICE_GROUP_BUILT_IN,
1677     /** Wired device */
1678     DEVICE_GROUP_WIRED,
1679     /** Wireless device */
1680     DEVICE_GROUP_WIRELESS,
1681     /** Remote cast device */
1682     DEVICE_GROUP_REMOTE_CAST,
1683     /* earpiece device*/
1684     DEVICE_GROUP_EARPIECE,
1685     /** Dp device */
1686     DEVICE_GROUP_DP,
1687 };
1688 
1689 static const std::map<DeviceType, DeviceGroup> DEVICE_GROUP_FOR_VOLUME = {
1690     {DEVICE_TYPE_EARPIECE, DEVICE_GROUP_EARPIECE}, {DEVICE_TYPE_SPEAKER, DEVICE_GROUP_BUILT_IN},
1691     {DEVICE_TYPE_WIRED_HEADSET, DEVICE_GROUP_WIRED}, {DEVICE_TYPE_USB_HEADSET, DEVICE_GROUP_WIRED},
1692     {DEVICE_TYPE_USB_ARM_HEADSET, DEVICE_GROUP_WIRED}, {DEVICE_TYPE_BLUETOOTH_A2DP, DEVICE_GROUP_WIRELESS},
1693     {DEVICE_TYPE_BLUETOOTH_SCO, DEVICE_GROUP_WIRELESS}, {DEVICE_TYPE_REMOTE_CAST, DEVICE_GROUP_REMOTE_CAST},
1694     {DEVICE_TYPE_ACCESSORY, DEVICE_GROUP_WIRELESS}, {DEVICE_TYPE_NEARLINK, DEVICE_GROUP_WIRELESS},
1695     {DEVICE_TYPE_DP, DEVICE_GROUP_DP}, {DEVICE_TYPE_HDMI, DEVICE_GROUP_DP},
1696     {DEVICE_TYPE_WIRED_HEADPHONES, DEVICE_GROUP_WIRED},
1697 };
1698 
GetVolumeGroupForDevice(DeviceType deviceType)1699 static inline DeviceGroup GetVolumeGroupForDevice(DeviceType deviceType)
1700 {
1701     auto it = DEVICE_GROUP_FOR_VOLUME.find(deviceType);
1702     return it == DEVICE_GROUP_FOR_VOLUME.end() ? DEVICE_GROUP_INVALID : it->second;
1703 }
1704 
1705 enum RouterType {
1706     /**
1707      * None router.
1708      * @since 12
1709      */
1710     ROUTER_TYPE_NONE = 0,
1711     /**
1712      * Default router.
1713      * @since 12
1714      */
1715     ROUTER_TYPE_DEFAULT,
1716     /**
1717      * Stream filter router.
1718      * @since 12
1719      */
1720     ROUTER_TYPE_STREAM_FILTER,
1721     /**
1722      * Package filter router.
1723      * @since 12
1724      */
1725     ROUTER_TYPE_PACKAGE_FILTER,
1726     /**
1727      * Cockpit phone router.
1728      * @since 12
1729      */
1730     ROUTER_TYPE_COCKPIT_PHONE,
1731     /**
1732      * Privacy priority router.
1733      * @since 12
1734      */
1735     ROUTER_TYPE_PRIVACY_PRIORITY,
1736     /**
1737      * Public priority router.
1738      * @since 12
1739      */
1740     ROUTER_TYPE_PUBLIC_PRIORITY,
1741     /**
1742      * Pair device router.
1743      * @since 12
1744      */
1745     ROUTER_TYPE_PAIR_DEVICE,
1746     /**
1747      * User select router.
1748      * @since 12
1749      */
1750     ROUTER_TYPE_USER_SELECT,
1751 
1752     /**
1753      * App select router.
1754      * @since 12
1755      */
1756     ROUTER_TYPE_APP_SELECT,
1757 };
1758 
1759 enum RenderMode {
1760     /**
1761      * Primary render mode.
1762      * @since 12
1763      */
1764     PRIMARY,
1765     /**
1766      * VOIP render mode.
1767      * @since 12
1768      */
1769     VOIP,
1770     /**
1771      * Offload render mode.
1772      * @since 12
1773      */
1774     OFFLOAD,
1775     /**
1776      * Low latency render mode.
1777      * @since 12
1778      */
1779     LOW_LATENCY,
1780 };
1781 
1782 enum WriteDataCallbackType {
1783     /**
1784      * Use OH_AudioRenderer_Callbacks.OH_AudioRenderer_OnWriteData
1785      */
1786     WRITE_DATA_CALLBACK_WITHOUT_RESULT = 0,
1787     /**
1788      * Use OH_AudioRenderer_OnWriteDataCallback
1789      */
1790     WRITE_DATA_CALLBACK_WITH_RESULT = 1,
1791     /**
1792      * Use OH_AudioRenderer_OnWriteDataCallbackAdvanced
1793     */
1794     WRITE_DATA_CALLBACK_ADVANCED = 2,
1795 };
1796 
1797 enum ReadDataCallbackType {
1798     /**
1799      * Use OH_AudioCapturer_Callbacks.OH_AudioCapturer_OnReadData
1800      */
1801     READ_DATA_CALLBACK_WITHOUT_RESULT = 0,
1802     /**
1803      * Use OH_AudioCapturer_OnReadDataCallback
1804      */
1805     READ_DATA_CALLBACK_WITH_RESULT = 1
1806 };
1807 
1808 enum StreamEventCallbackType {
1809     /**
1810      * Use OH_AudioCapturer_Callbacks.OH_AudioCapturer_OnStreamEvent
1811      */
1812     STREAM_EVENT_CALLBACK_COMBINED = 0,
1813     /**
1814      * Use OH_AudioCapturer_OnStreamEventCallback
1815      */
1816     STREAM_EVENT_CALLBACK_SEPERATED = 1
1817 };
1818 
1819 enum ErrorCallbackType {
1820     /**
1821      * Use OH_AudioRenderer_Callbacks.OH_AudioRenderer_OnError
1822      */
1823     ERROR_CALLBACK_COMBINED = 0,
1824     /**
1825      * Use OH_AudioRenderer_OnErrorCallback
1826      */
1827     ERROR_CALLBACK_SEPERATED = 1
1828 };
1829 
1830 enum PolicyType {
1831     EDM_POLICY_TYPE = 0,
1832     PRIVACY_POLCIY_TYPE = 1,
1833     TEMPORARY_POLCIY_TYPE = 2,
1834 };
1835 
1836 enum SuscribeResultCode {
1837     SUCCESS_SUBSCRIBE = 0,
1838     /**
1839      * Volume button input error
1840      */
1841     ERR_SUBSCRIBE_INVALID_PARAM,
1842      /**
1843      * The keyOption creation failed
1844      */
1845     ERR_SUBSCRIBE_KEY_OPTION_NULL,
1846      /**
1847      * The im pointer creation failed
1848      */
1849     ERR_SUBSCRIBE_MMI_NULL,
1850     /**
1851      * Volume key multimode subscription results
1852      */
1853     ERR_MODE_SUBSCRIBE,
1854 };
1855 
1856 enum AudioProcessStage {
1857     AUDIO_PROC_STAGE_STOP,
1858     AUDIO_PROC_STAGE_STOP_BY_RELEASE,
1859 };
1860 
1861 enum RendererStage {
1862     RENDERER_STAGE_UNKNOWN = 0,
1863     RENDERER_STAGE_START_OK = 0x10,
1864     RENDERER_STAGE_START_FAIL = 0x11,
1865     RENDERER_STAGE_PAUSE_OK = 0x20,
1866     RENDERER_STAGE_STOP_OK = 0x30,
1867     RENDERER_STAGE_STOP_BY_RELEASE = 0x31,
1868     RENDERER_STAGE_STANDBY_BEGIN = 0x40,
1869     RENDERER_STAGE_STANDBY_END = 0x41,
1870     RENDERER_STAGE_SET_VOLUME_ZERO = 0x50,
1871     RENDERER_STAGE_SET_VOLUME_NONZERO = 0x51,
1872 };
1873 
1874 enum CapturerStage {
1875     CAPTURER_STAGE_START_OK = 0x10,
1876     CAPTURER_STAGE_START_FAIL = 0x11,
1877     CAPTURER_STAGE_PAUSE_OK = 0x20,
1878     CAPTURER_STAGE_STOP_OK = 0x30,
1879     CAPTURER_STAGE_STOP_BY_RELEASE = 0x31,
1880 };
1881 
1882 
1883 enum RestoreStatus : int32_t {
1884     NO_NEED_FOR_RESTORE = 0,
1885     NEED_RESTORE,
1886     RESTORING,
1887     RESTORE_ERROR,
1888     NEED_RESTORE_TO_NORMAL,
1889 };
1890 
1891 enum RestoreReason : int32_t {
1892     DEFAULT_REASON = 0,
1893     DEVICE_CHANGED,
1894     STREAM_CONCEDED,
1895     STREAM_SPLIT,
1896     SERVER_DIED,
1897 };
1898 
1899 enum CheckPosTimeRes : int32_t {
1900     CHECK_SUCCESS = 0,
1901     CHECK_FAILED,
1902     NEED_MODIFY,
1903 };
1904 
1905 struct RestoreInfo {
1906     RestoreReason restoreReason = DEFAULT_REASON;
1907     int32_t deviceChangeReason = 0;
1908     int32_t targetStreamFlag = AUDIO_FLAG_NORMAL;
1909     uint32_t routeFlag = 0;
1910 };
1911 
1912 struct RestoreInfoIpc : public Parcelable {
1913     RestoreInfo restoreInfo;
1914 
MarshallingRestoreInfoIpc1915     bool Marshalling(Parcel &parcel) const override
1916     {
1917         return parcel.WriteInt32(restoreInfo.restoreReason) &&
1918             parcel.WriteInt32(restoreInfo.deviceChangeReason) &&
1919             parcel.WriteInt32(restoreInfo.targetStreamFlag) &&
1920             parcel.WriteUint32(restoreInfo.routeFlag);
1921     }
1922 
UnmarshallingRestoreInfoIpc1923     static RestoreInfoIpc *Unmarshalling(Parcel &parcel)
1924     {
1925         auto info = new(std::nothrow) RestoreInfoIpc();
1926         if (info == nullptr) {
1927             return nullptr;
1928         }
1929 
1930         info->restoreInfo.restoreReason = static_cast<RestoreReason>(parcel.ReadInt32());
1931         info->restoreInfo.deviceChangeReason = parcel.ReadInt32();
1932         info->restoreInfo.targetStreamFlag = parcel.ReadInt32();
1933         info->restoreInfo.routeFlag = parcel.ReadUint32();
1934         return info;
1935     }
1936 };
1937 
1938 /**
1939  * Enumerates the method sources that trigger priority boosting.
1940  * Used to distinguish between different triggering entry points.
1941  */
1942 enum BoostTriggerMethod : uint32_t {
1943     METHOD_START = 0,
1944     METHOD_WRITE_OR_READ,
1945     METHOD_MAX
1946 };
1947 } // namespace AudioStandard
1948 } // namespace OHOS
1949 #endif // AUDIO_INFO_H
1950