• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <unistd.h>
27 #include <unordered_map>
28 #include <audio_source_type.h>
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 constexpr int32_t MAX_NUM_STREAMS = 3;
33 constexpr int32_t RENDERER_STREAM_USAGE_SHIFT = 16;
34 constexpr int32_t MINIMUM_BUFFER_SIZE_MSEC = 5;
35 constexpr int32_t MAXIMUM_BUFFER_SIZE_MSEC = 20;
36 constexpr int32_t MIN_SERVICE_COUNT = 2;
37 constexpr int32_t ROOT_UID = 0;
38 constexpr int32_t INVALID_UID = -1;
39 constexpr int32_t INTELL_VOICE_SERVICR_UID = 1042;
40 constexpr int32_t NETWORK_ID_SIZE = 80;
41 constexpr int32_t DEFAULT_VOLUME_GROUP_ID = 1;
42 constexpr int32_t DEFAULT_VOLUME_INTERRUPT_ID = 1;
43 constexpr uint32_t STREAM_FLAG_FAST = 1;
44 
45 const std::string MICROPHONE_PERMISSION = "ohos.permission.MICROPHONE";
46 const std::string MANAGE_INTELLIGENT_VOICE_PERMISSION = "ohos.permission.MANAGE_INTELLIGENT_VOICE";
47 const std::string MANAGE_AUDIO_CONFIG = "ohos.permission.MANAGE_AUDIO_CONFIG";
48 const std::string MODIFY_AUDIO_SETTINGS_PERMISSION = "ohos.permission.MODIFY_AUDIO_SETTINGS";
49 const std::string ACCESS_NOTIFICATION_POLICY_PERMISSION = "ohos.permission.ACCESS_NOTIFICATION_POLICY";
50 const std::string USE_BLUETOOTH_PERMISSION = "ohos.permission.USE_BLUETOOTH";
51 const std::string CAPTURER_VOICE_DOWNLINK_PERMISSION = "ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO";
52 const std::string LOCAL_NETWORK_ID = "LocalDevice";
53 const std::string REMOTE_NETWORK_ID = "RemoteDevice";
54 
55 constexpr int32_t WAKEUP_LIMIT = 2;
56 constexpr std::string_view PRIMARY_WAKEUP = "Built_in_wakeup";
57 constexpr std::string_view PRIMARY_WAKEUP_MIRROR = "Built_in_wakeup_mirror";
58 constexpr std::string_view WAKEUP_NAMES[WAKEUP_LIMIT] = {
59     PRIMARY_WAKEUP,
60     PRIMARY_WAKEUP_MIRROR
61 };
62 
63 #ifdef FEATURE_DTMF_TONE
64 // Maximun number of sine waves in a tone segment
65 constexpr uint32_t TONEINFO_MAX_WAVES = 3;
66 
67 // Maximun number of segments in a tone descriptor
68 constexpr uint32_t TONEINFO_MAX_SEGMENTS = 12;
69 constexpr uint32_t TONEINFO_INF = 0xFFFFFFFF;
70 class ToneSegment {
71 public:
72     uint32_t duration;
73     uint16_t waveFreq[TONEINFO_MAX_WAVES+1];
74     uint16_t loopCnt;
75     uint16_t loopIndx;
76 };
77 
78 class ToneInfo {
79 public:
80     ToneSegment segments[TONEINFO_MAX_SEGMENTS+1];
81     uint32_t segmentCnt;
82     uint32_t repeatCnt;
83     uint32_t repeatSegment;
ToneInfo()84     ToneInfo() {}
85 };
86 #endif
87 
88 enum VolumeAdjustType {
89     /**
90      * Adjust volume up
91      */
92     VOLUME_UP = 0,
93     /**
94      * Adjust volume down
95      */
96     VOLUME_DOWN = 1,
97 };
98 
99 enum DeviceFlag {
100     /**
101      * Device flag none.
102      */
103     NONE_DEVICES_FLAG = 0,
104     /**
105      * Indicates all output audio devices.
106      */
107     OUTPUT_DEVICES_FLAG = 1,
108     /**
109      * Indicates all input audio devices.
110      */
111     INPUT_DEVICES_FLAG = 2,
112     /**
113      * Indicates all audio devices.
114      */
115     ALL_DEVICES_FLAG = 3,
116     /**
117      * Indicates all distributed output audio devices.
118      */
119     DISTRIBUTED_OUTPUT_DEVICES_FLAG = 4,
120     /**
121      * Indicates all distributed input audio devices.
122      */
123     DISTRIBUTED_INPUT_DEVICES_FLAG = 8,
124     /**
125      * Indicates all distributed audio devices.
126      */
127     ALL_DISTRIBUTED_DEVICES_FLAG = 12,
128     /**
129      * Indicates all local and distributed audio devices.
130      */
131     ALL_L_D_DEVICES_FLAG = 15,
132     /**
133      * Device flag max count.
134      */
135     DEVICE_FLAG_MAX
136 };
137 
138 enum DeviceRole {
139     /**
140      * Device role none.
141      */
142     DEVICE_ROLE_NONE = -1,
143     /**
144      * Input device role.
145      */
146     INPUT_DEVICE = 1,
147     /**
148      * Output device role.
149      */
150     OUTPUT_DEVICE = 2,
151     /**
152      * Device role max count.
153      */
154     DEVICE_ROLE_MAX
155 };
156 
157 enum DeviceType {
158     /**
159      * Indicates device type none.
160      */
161     DEVICE_TYPE_NONE = -1,
162     /**
163      * Indicates invalid device
164      */
165     DEVICE_TYPE_INVALID = 0,
166     /**
167      * Indicates a built-in earpiece device
168      */
169     DEVICE_TYPE_EARPIECE = 1,
170     /**
171      * Indicates a speaker built in a device.
172      */
173     DEVICE_TYPE_SPEAKER = 2,
174     /**
175      * Indicates a headset, which is the combination of a pair of headphones and a microphone.
176      */
177     DEVICE_TYPE_WIRED_HEADSET = 3,
178     /**
179      * Indicates a pair of wired headphones.
180      */
181     DEVICE_TYPE_WIRED_HEADPHONES = 4,
182     /**
183      * Indicates a Bluetooth device used for telephony.
184      */
185     DEVICE_TYPE_BLUETOOTH_SCO = 7,
186     /**
187      * Indicates a Bluetooth device supporting the Advanced Audio Distribution Profile (A2DP).
188      */
189     DEVICE_TYPE_BLUETOOTH_A2DP = 8,
190     /**
191      * Indicates a microphone built in a device.
192      */
193     DEVICE_TYPE_MIC = 15,
194     /**
195      * Indicates a microphone built in a device.
196      */
197     DEVICE_TYPE_WAKEUP = 16,
198     /**
199      * Indicates a microphone built in a device.
200      */
201     DEVICE_TYPE_USB_HEADSET = 22,
202     /**
203      * Indicates a debug sink device
204      */
205     DEVICE_TYPE_FILE_SINK = 50,
206     /**
207      * Indicates a debug source device
208      */
209     DEVICE_TYPE_FILE_SOURCE = 51,
210     /**
211      * Indicates any headset/headphone for disconnect
212      */
213     DEVICE_TYPE_EXTERN_CABLE = 100,
214     /**
215      * Indicates default device
216      */
217     DEVICE_TYPE_DEFAULT = 1000,
218     /**
219      * Indicates device type max count.
220      */
221     DEVICE_TYPE_MAX
222 };
223 
224 enum ConnectType {
225     /**
226      * Group connect type of local device
227      */
228     CONNECT_TYPE_LOCAL = 0,
229     /**
230      * Group connect type of distributed device
231      */
232     CONNECT_TYPE_DISTRIBUTED
233 };
234 
235 enum ActiveDeviceType {
236     ACTIVE_DEVICE_TYPE_NONE = -1,
237     EARPIECE = 1,
238     SPEAKER = 2,
239     BLUETOOTH_SCO = 7,
240     FILE_SINK_DEVICE = 50,
241     ACTIVE_DEVICE_TYPE_MAX
242 };
243 
244 enum AudioStreamType {
245     /**
246      * Indicates audio streams default.
247      */
248     STREAM_DEFAULT = -1,
249     /**
250      * Indicates audio streams of voices in calls.
251      */
252     STREAM_VOICE_CALL = 0,
253     /**
254      * Indicates audio streams for music.
255      */
256     STREAM_MUSIC = 1,
257     /**
258      * Indicates audio streams for ringtones.
259      */
260     STREAM_RING = 2,
261     /**
262      * Indicates audio streams for media.
263      * Deprecated
264      */
265     STREAM_MEDIA = 3,
266     /**
267      * Indicates audio streams used for voice assistant and text-to-speech (TTS).
268      */
269     STREAM_VOICE_ASSISTANT = 4,
270     /**
271      * Indicates audio streams for system sounds.
272      */
273     STREAM_SYSTEM = 5,
274     /**
275      * Indicates audio streams for alarms.
276      */
277     STREAM_ALARM = 6,
278     /**
279      * Indicates audio streams for notifications.
280      */
281     STREAM_NOTIFICATION = 7,
282     /**
283      * Indicates audio streams for voice calls routed through a connected Bluetooth device.
284      * Deprecated
285      */
286     STREAM_BLUETOOTH_SCO = 8,
287     /**
288      * Indicates audio streams for enforced audible.
289      */
290     STREAM_ENFORCED_AUDIBLE = 9,
291     /**
292      * Indicates audio streams for dual-tone multi-frequency (DTMF) tones.
293      */
294     STREAM_DTMF = 10,
295     /**
296      * Indicates audio streams exclusively transmitted through the speaker (text-to-speech) of a device.
297      * Deprecated
298      */
299     STREAM_TTS =  11,
300     /**
301      * Indicates audio streams used for prompts in terms of accessibility.
302      */
303     STREAM_ACCESSIBILITY = 12,
304     /**
305      * Indicates special scene used for recording.
306      * Deprecated
307      */
308     STREAM_RECORDING = 13,
309     /**
310      * Indicates audio streams for movie.
311      * New
312      */
313     STREAM_MOVIE = 14,
314     /**
315      * Indicates audio streams for game.
316      * New
317      */
318     STREAM_GAME = 15,
319     /**
320      * Indicates audio streams for speech.
321      * New
322      */
323     STREAM_SPEECH = 16,
324     /**
325      * Indicates audio streams for enforced audible.
326      * New
327      */
328     STREAM_SYSTEM_ENFORCED = 17,
329     /**
330      * Indicates audio streams used for ultrasonic ranging.
331      */
332     STREAM_ULTRASONIC = 18,
333     /**
334      * Indicates audio streams for wakeup.
335      */
336     STREAM_WAKEUP = 19,
337     /**
338      * Indicates audio streams for voice message.
339      */
340     STREAM_VOICE_MESSAGE = 20,
341     /**
342      * Indicates audio streams for navigation.
343      */
344     STREAM_NAVIGATION = 21,
345     /**
346      * Indicates the max value of audio stream type (except STREAM_ALL).
347      */
348     STREAM_TYPE_MAX = STREAM_NAVIGATION,
349 
350     /**
351      * Indicates audio streams used for only one volume bar of a device.
352      */
353     STREAM_ALL = 100
354 };
355 
356 typedef AudioStreamType AudioVolumeType;
357 
358 enum FocusType {
359     /**
360      * Recording type.
361      */
362     FOCUS_TYPE_RECORDING = 0,
363 };
364 
365 enum API_VERSION {
366     API_7 = 7,
367     API_8 = 8,
368     API_9 = 9
369 };
370 
371 enum AudioErrors {
372     /**
373      * Common errors.
374      */
375     ERROR_INVALID_PARAM = 6800101,
376     ERROR_NO_MEMORY     = 6800102,
377     ERROR_ILLEGAL_STATE = 6800103,
378     ERROR_UNSUPPORTED   = 6800104,
379     ERROR_TIMEOUT       = 6800105,
380     /**
381      * Audio specific errors.
382      */
383     ERROR_STREAM_LIMIT  = 6800201,
384     /**
385      * Default error.
386      */
387     ERROR_SYSTEM        = 6800301
388 };
389 
390 enum CommunicationDeviceType {
391     /**
392      * Speaker.
393      * @since 7
394      * @syscap SystemCapability.Multimedia.Audio.Communication
395      */
396     COMMUNICATION_SPEAKER = 2
397 };
398 
399 enum InterruptMode {
400     SHARE_MODE = 0,
401     INDEPENDENT_MODE = 1
402 };
403 
404 enum AudioEncodingType {
405     ENCODING_PCM = 0,
406     ENCODING_INVALID = -1
407 };
408 
409 // Ringer Mode
410 enum AudioRingerMode {
411     RINGER_MODE_SILENT = 0,
412     RINGER_MODE_VIBRATE = 1,
413     RINGER_MODE_NORMAL = 2
414 };
415 
416 // format
417 enum AudioSampleFormat {
418     SAMPLE_U8 = 0,
419     SAMPLE_S16LE = 1,
420     SAMPLE_S24LE = 2,
421     SAMPLE_S32LE = 3,
422     SAMPLE_F32LE = 4,
423     INVALID_WIDTH = -1
424 };
425 
426 // channel
427 enum AudioChannel {
428     MONO = 1,
429     STEREO = 2,
430     CHANNEL_3 = 3,
431     CHANNEL_4 = 4,
432     CHANNEL_5 = 5,
433     CHANNEL_6 = 6,
434     CHANNEL_7 = 7,
435     CHANNEL_8 = 8
436 };
437 
438 
439 /**
440  * Enumerates the audio interrupt request type.
441  */
442 enum InterruptRequestType {
443     INTERRUPT_REQUEST_TYPE_DEFAULT = 0,
444 };
445 
446 /**
447  * Enumerates audio interrupt request result type.
448  */
449 enum InterruptRequestResultType {
450     INTERRUPT_REQUEST_GRANT = 0,
451     INTERRUPT_REQUEST_REJECT = 1
452 };
453 
454 // sampling rate
455 enum AudioSamplingRate {
456     SAMPLE_RATE_8000 = 8000,
457     SAMPLE_RATE_11025 = 11025,
458     SAMPLE_RATE_12000 = 12000,
459     SAMPLE_RATE_16000 = 16000,
460     SAMPLE_RATE_22050 = 22050,
461     SAMPLE_RATE_24000 = 24000,
462     SAMPLE_RATE_32000 = 32000,
463     SAMPLE_RATE_44100 = 44100,
464     SAMPLE_RATE_48000 = 48000,
465     SAMPLE_RATE_64000 = 64000,
466     SAMPLE_RATE_96000 = 96000
467 };
468 
469 typedef enum {
470     /** Invalid audio source */
471     AUDIO_SOURCE_INVALID = -1,
472     /** Default audio source */
473     AUDIO_SOURCE_DEFAULT = 0,
474     /** Microphone */
475     AUDIO_MIC = 1,
476     /** Uplink voice */
477     AUDIO_VOICE_UPLINK = 2,
478     /** Downlink voice */
479     AUDIO_VOICE_DOWNLINK = 3,
480     /** Voice call */
481     AUDIO_VOICE_CALL = 4,
482     /** Camcorder */
483     AUDIO_CAMCORDER = 5,
484     /** Voice recognition */
485     AUDIO_VOICE_RECOGNITION = 6,
486     /** Voice communication */
487     AUDIO_VOICE_COMMUNICATION = 7,
488     /** Remote submix */
489     AUDIO_REMOTE_SUBMIX = 8,
490     /** Unprocessed audio */
491     AUDIO_UNPROCESSED = 9,
492     /** Voice performance */
493     AUDIO_VOICE_PERFORMANCE = 10,
494     /** Echo reference */
495     AUDIO_ECHO_REFERENCE = 1997,
496     /** Radio tuner */
497     AUDIO_RADIO_TUNER = 1998,
498     /** Hotword */
499     AUDIO_HOTWORD = 1999,
500     /** Extended remote submix */
501     AUDIO_REMOTE_SUBMIX_EXTEND = 10007,
502 } AudioSourceType;
503 
504 struct AudioStreamParams {
505     uint32_t samplingRate;
506     uint8_t encoding;
507     uint8_t format;
508     uint8_t channels;
509 };
510 
511 /**
512 * Enumerates the audio content type.
513 */
514 enum ContentType {
515     CONTENT_TYPE_UNKNOWN = 0,
516     CONTENT_TYPE_SPEECH = 1,
517     CONTENT_TYPE_MUSIC = 2,
518     CONTENT_TYPE_MOVIE = 3,
519     CONTENT_TYPE_SONIFICATION = 4,
520     CONTENT_TYPE_RINGTONE = 5,
521     // other ContentType
522     CONTENT_TYPE_PROMPT = 6,
523     CONTENT_TYPE_GAME = 7,
524     CONTENT_TYPE_DTMF = 8,
525     CONTENT_TYPE_ULTRASONIC = 9
526 };
527 
528 /**
529 * Enumerates the stream usage.
530 */
531 enum StreamUsage {
532     STREAM_USAGE_UNKNOWN = 0,
533     STREAM_USAGE_MEDIA = 1,
534     STREAM_USAGE_MUSIC = 1,
535     STREAM_USAGE_VOICE_COMMUNICATION = 2,
536     STREAM_USAGE_VOICE_ASSISTANT = 3,
537     STREAM_USAGE_ALARM = 4,
538     STREAM_USAGE_VOICE_MESSAGE = 5,
539     STREAM_USAGE_NOTIFICATION_RINGTONE = 6,
540     STREAM_USAGE_RINGTONE = 6,
541     STREAM_USAGE_NOTIFICATION = 7,
542     STREAM_USAGE_ACCESSIBILITY = 8,
543     STREAM_USAGE_SYSTEM = 9,
544     STREAM_USAGE_MOVIE = 10,
545     STREAM_USAGE_GAME = 11,
546     STREAM_USAGE_AUDIOBOOK = 12,
547     STREAM_USAGE_NAVIGATION = 13,
548     STREAM_USAGE_DTMF = 14,
549     STREAM_USAGE_ENFORCED_TONE = 15,
550     STREAM_USAGE_ULTRASONIC = 16,
551     //other StreamUsage
552     STREAM_USAGE_RANGING,
553     STREAM_USAGE_VOICE_MODEM_COMMUNICATION
554 };
555 
556 
557 /**
558  * Enumerates audio stream privacy type for playback capture.
559  */
560 enum AudioPrivacyType {
561     PRIVACY_TYPE_PUBLIC = 0,
562     PRIVACY_TYPE_PRIVATE = 1
563 };
564 
565 /**
566 * Enumerates the renderer playback speed.
567 */
568 enum AudioRendererRate {
569     RENDER_RATE_NORMAL = 0,
570     RENDER_RATE_DOUBLE = 1,
571     RENDER_RATE_HALF = 2,
572 };
573 
574 enum InterruptType {
575     INTERRUPT_TYPE_BEGIN = 1,
576     INTERRUPT_TYPE_END = 2,
577 };
578 
579 enum InterruptHint {
580     INTERRUPT_HINT_NONE = 0,
581     INTERRUPT_HINT_RESUME,
582     INTERRUPT_HINT_PAUSE,
583     INTERRUPT_HINT_STOP,
584     INTERRUPT_HINT_DUCK,
585     INTERRUPT_HINT_UNDUCK
586 };
587 
588 enum InterruptForceType {
589     /**
590      * Force type, system change audio state.
591      */
592     INTERRUPT_FORCE = 0,
593     /**
594      * Share type, application change audio state.
595      */
596     INTERRUPT_SHARE
597 };
598 
599 enum ActionTarget {
600     CURRENT = 0,
601     INCOMING,
602     BOTH
603 };
604 
605 enum AudioFocuState {
606     ACTIVE = 0,
607     DUCK,
608     PAUSE,
609     STOP
610 };
611 
612 struct InterruptEvent {
613     /**
614      * Interrupt event type, begin or end
615      */
616     InterruptType eventType;
617     /**
618      * Interrupt force type, force or share
619      */
620     InterruptForceType forceType;
621     /**
622      * Interrupt hint type. In force type, the audio state already changed,
623      * but in share mode, only provide a hint for application to decide.
624      */
625     InterruptHint hintType;
626 };
627 
628 // Used internally only by AudioFramework
629 struct InterruptEventInternal {
630     InterruptType eventType;
631     InterruptForceType forceType;
632     InterruptHint hintType;
633     float duckVolume;
634 };
635 
636 struct AudioFocusEntry {
637     InterruptForceType forceType;
638     InterruptHint hintType;
639     ActionTarget actionOn;
640     bool isReject;
641 };
642 
643 struct AudioFocusType {
644     AudioStreamType streamType;
645     SourceType sourceType;
646     bool isPlay;
647     bool operator==(const AudioFocusType &value) const
648     {
649         return streamType == value.streamType && sourceType == value.sourceType && isPlay == value.isPlay;
650     }
651 
652     bool operator<(const AudioFocusType &value) const
653     {
654         return streamType < value.streamType || (streamType == value.streamType && sourceType < value.sourceType);
655     }
656 
657     bool operator>(const AudioFocusType &value) const
658     {
659         return streamType > value.streamType || (streamType == value.streamType && sourceType > value.sourceType);
660     }
661 };
662 
663 struct AudioInterrupt {
664     StreamUsage streamUsage;
665     ContentType contentType;
666     AudioFocusType audioFocusType;
667     uint32_t sessionID;
668     bool pauseWhenDucked;
669     int32_t pid { -1 };
670     InterruptMode mode { SHARE_MODE };
671     bool parallelPlayFlag { false };
672 };
673 
674 struct VolumeEvent {
675     AudioStreamType volumeType;
676     int32_t volume;
677     bool updateUi;
678     int32_t volumeGroupId;
679     std::string networkId;
680 };
681 
682 struct AudioParameters {
683     AudioSampleFormat format;
684     AudioChannel channels;
685     AudioSamplingRate samplingRate;
686     AudioEncodingType encoding;
687     ContentType contentType;
688     StreamUsage usage;
689     DeviceRole deviceRole;
690     DeviceType deviceType;
691 };
692 
693 struct AudioStreamInfo {
694     AudioSamplingRate samplingRate;
695     AudioEncodingType encoding = AudioEncodingType::ENCODING_PCM;
696     AudioSampleFormat format;
697     AudioChannel channels;
698 };
699 
700 struct AudioRendererInfo {
701     ContentType contentType = CONTENT_TYPE_UNKNOWN;
702     StreamUsage streamUsage = STREAM_USAGE_UNKNOWN;
703     int32_t rendererFlags = 0;
704 };
705 
706 struct AudioCapturerInfo {
707     SourceType sourceType = SOURCE_TYPE_INVALID;
708     int32_t capturerFlags = 0;
709 };
710 
711 struct AudioRendererDesc {
712     ContentType contentType = CONTENT_TYPE_UNKNOWN;
713     StreamUsage streamUsage = STREAM_USAGE_UNKNOWN;
714 };
715 
716 struct AudioRendererOptions {
717     AudioStreamInfo streamInfo;
718     AudioRendererInfo rendererInfo;
719     AudioPrivacyType privacyType = PRIVACY_TYPE_PUBLIC;
720 };
721 
722 struct MicStateChangeEvent {
723     bool mute;
724 };
725 
726 enum DeviceChangeType {
727     CONNECT = 0,
728     DISCONNECT = 1,
729 };
730 
731 enum AudioInterruptChangeType {
732     ACTIVATE_AUDIO_INTERRUPT = 0,
733     DEACTIVATE_AUDIO_INTERRUPT = 1,
734 };
735 
736 enum AudioScene {
737     /**
738      * Default audio scene
739      */
740     AUDIO_SCENE_DEFAULT,
741     /**
742      * Ringing audio scene
743      * Only available for system api.
744      */
745     AUDIO_SCENE_RINGING,
746     /**
747      * Phone call audio scene
748      * Only available for system api.
749      */
750     AUDIO_SCENE_PHONE_CALL,
751     /**
752      * Voice chat audio scene
753      */
754     AUDIO_SCENE_PHONE_CHAT,
755 };
756 
757 struct CaptureFilterOptions {
758     std::vector<StreamUsage> usages;
759 };
760 
761 struct AudioPlaybackCaptureConfig {
762     CaptureFilterOptions filterOptions;
763     bool silentCapture {false};
764 };
765 
766 struct AudioCapturerOptions {
767     AudioStreamInfo streamInfo;
768     AudioCapturerInfo capturerInfo;
769     AudioPlaybackCaptureConfig playbackCaptureConfig;
770 };
771 
772 struct AppInfo {
773     int32_t appUid { INVALID_UID };
774     uint32_t appTokenId { 0 };
775     int32_t appPid { 0 };
776     uint64_t appFullTokenId { 0 };
777 };
778 
779 // Supported audio parameters for both renderer and capturer
780 const std::vector<AudioSampleFormat> AUDIO_SUPPORTED_FORMATS {
781     SAMPLE_U8,
782     SAMPLE_S16LE,
783     SAMPLE_S24LE,
784     SAMPLE_S32LE
785 };
786 
787 const std::vector<AudioChannel> RENDERER_SUPPORTED_CHANNELS {
788     MONO,
789     STEREO,
790     CHANNEL_3,
791     CHANNEL_4,
792     CHANNEL_5,
793     CHANNEL_6,
794     CHANNEL_7,
795     CHANNEL_8
796 };
797 
798 const std::vector<AudioChannel> CAPTURER_SUPPORTED_CHANNELS {
799     MONO,
800     STEREO,
801     CHANNEL_3,
802     CHANNEL_4,
803     CHANNEL_5,
804     CHANNEL_6
805 };
806 
807 const std::vector<AudioEncodingType> AUDIO_SUPPORTED_ENCODING_TYPES {
808     ENCODING_PCM
809 };
810 
811 const std::vector<AudioSamplingRate> AUDIO_SUPPORTED_SAMPLING_RATES {
812     SAMPLE_RATE_8000,
813     SAMPLE_RATE_11025,
814     SAMPLE_RATE_12000,
815     SAMPLE_RATE_16000,
816     SAMPLE_RATE_22050,
817     SAMPLE_RATE_24000,
818     SAMPLE_RATE_32000,
819     SAMPLE_RATE_44100,
820     SAMPLE_RATE_48000,
821     SAMPLE_RATE_64000,
822     SAMPLE_RATE_96000
823 };
824 
825 const std::vector<StreamUsage> AUDIO_SUPPORTED_STREAM_USAGES {
826     STREAM_USAGE_UNKNOWN,
827     STREAM_USAGE_MEDIA,
828     STREAM_USAGE_MUSIC,
829     STREAM_USAGE_VOICE_COMMUNICATION,
830     STREAM_USAGE_VOICE_ASSISTANT,
831     STREAM_USAGE_ALARM,
832     STREAM_USAGE_VOICE_MESSAGE,
833     STREAM_USAGE_NOTIFICATION_RINGTONE,
834     STREAM_USAGE_RINGTONE,
835     STREAM_USAGE_NOTIFICATION,
836     STREAM_USAGE_ACCESSIBILITY,
837     STREAM_USAGE_SYSTEM,
838     STREAM_USAGE_MOVIE,
839     STREAM_USAGE_GAME,
840     STREAM_USAGE_AUDIOBOOK,
841     STREAM_USAGE_NAVIGATION,
842     STREAM_USAGE_DTMF,
843     STREAM_USAGE_ENFORCED_TONE,
844     STREAM_USAGE_ULTRASONIC,
845     STREAM_USAGE_RANGING,
846     STREAM_USAGE_VOICE_MODEM_COMMUNICATION
847 };
848 
849 // Supported audio parameters for fast audio stream
850 const std::vector<AudioSamplingRate> AUDIO_FAST_STREAM_SUPPORTED_SAMPLING_RATES {
851     SAMPLE_RATE_48000,
852 };
853 
854 const std::vector<AudioChannel> AUDIO_FAST_STREAM_SUPPORTED_CHANNELS {
855     MONO,
856     STEREO,
857 };
858 
859 const std::vector<AudioSampleFormat> AUDIO_FAST_STREAM_SUPPORTED_FORMATS {
860     SAMPLE_S16LE,
861     SAMPLE_S32LE
862 };
863 struct BufferDesc {
864     uint8_t* buffer;
865     size_t bufLength;
866     size_t dataLength;
867 };
868 
869 struct BufferQueueState {
870     uint32_t numBuffers;
871     uint32_t currentIndex;
872 };
873 
874 enum AudioRenderMode {
875     RENDER_MODE_NORMAL,
876     RENDER_MODE_CALLBACK
877 };
878 
879 enum AudioCaptureMode {
880     CAPTURE_MODE_NORMAL,
881     CAPTURE_MODE_CALLBACK
882 };
883 
884 struct SinkInfo {
885     uint32_t sinkId; // sink id
886     std::string sinkName;
887     std::string adapterName;
888 };
889 
890 struct SinkInput {
891     int32_t streamId;
892     AudioStreamType streamType;
893 
894     // add for routing stream.
895     int32_t uid; // client uid
896     int32_t pid; // client pid
897     uint32_t paStreamId; // streamId
898     uint32_t deviceSinkId; // sink id
899     std::string sinkName; // sink name
900     int32_t statusMark; // mark the router status
901     uint64_t startTime; // when this router is created
902 };
903 
904 struct SourceOutput {
905     int32_t streamId;
906     AudioStreamType streamType;
907 
908     // add for routing stream.
909     int32_t uid; // client uid
910     int32_t pid; // client pid
911     uint32_t paStreamId; // streamId
912     uint32_t deviceSourceId; // sink id
913     int32_t statusMark; // mark the router status
914     uint64_t startTime; // when this router is created
915 };
916 
917 typedef uint32_t AudioIOHandle;
918 
FLOAT_COMPARE_EQ(const float & x,const float & y)919 static inline bool FLOAT_COMPARE_EQ(const float& x, const float& y)
920 {
921     return (std::abs((x) - (y)) <= (std::numeric_limits<float>::epsilon()));
922 }
923 
924 // Below APIs are added to handle compilation error in call manager
925 // Once call manager adapt to new interrupt APIs, this will be removed
926 enum InterruptActionType {
927     TYPE_ACTIVATED = 0,
928     TYPE_INTERRUPT = 1
929 };
930 
931 struct InterruptAction {
932     InterruptActionType actionType;
933     InterruptType interruptType;
934     InterruptHint interruptHint;
935     bool activated;
936 };
937 
938 enum AudioServiceIndex {
939     HDI_SERVICE_INDEX = 0,
940     AUDIO_SERVICE_INDEX
941 };
942 
943 /**
944  * @brief Enumerates the rendering states of the current device.
945  */
946 enum RendererState {
947     /** INVALID state */
948     RENDERER_INVALID = -1,
949     /** Create New Renderer instance */
950     RENDERER_NEW,
951     /** Reneder Prepared state */
952     RENDERER_PREPARED,
953     /** Rendere Running state */
954     RENDERER_RUNNING,
955     /** Renderer Stopped state */
956     RENDERER_STOPPED,
957     /** Renderer Released state */
958     RENDERER_RELEASED,
959     /** Renderer Paused state */
960     RENDERER_PAUSED
961 };
962 
963 /**
964  * @brief Enumerates the capturing states of the current device.
965  */
966 enum CapturerState {
967     /** Capturer INVALID state */
968     CAPTURER_INVALID = -1,
969     /** Create new capturer instance */
970     CAPTURER_NEW,
971     /** Capturer Prepared state */
972     CAPTURER_PREPARED,
973     /** Capturer Running state */
974     CAPTURER_RUNNING,
975     /** Capturer Stopped state */
976     CAPTURER_STOPPED,
977     /** Capturer Released state */
978     CAPTURER_RELEASED,
979     /** Capturer Paused state */
980     CAPTURER_PAUSED
981 };
982 
983 enum State {
984     /** INVALID */
985     INVALID = -1,
986     /** New */
987     NEW,
988     /** Prepared */
989     PREPARED,
990     /** Running */
991     RUNNING,
992     /** Stopped */
993     STOPPED,
994     /** Released */
995     RELEASED,
996     /** Paused */
997     PAUSED,
998     /** Stopping */
999     STOPPING
1000 };
1001 
1002 enum StateChangeCmdType {
1003     CMD_FROM_CLIENT = 0,
1004     CMD_FROM_SYSTEM = 1
1005 };
1006 
1007 enum AudioMode {
1008     AUDIO_MODE_PLAYBACK,
1009     AUDIO_MODE_RECORD
1010 };
1011 
1012 struct AudioProcessConfig {
1013     AppInfo appInfo;
1014 
1015     AudioStreamInfo streamInfo;
1016 
1017     AudioMode audioMode;
1018 
1019     AudioRendererInfo rendererInfo;
1020 
1021     AudioCapturerInfo capturerInfo;
1022 
1023     AudioStreamType streamType;
1024 };
1025 
1026 struct AudioStreamData {
1027     AudioStreamInfo streamInfo;
1028     BufferDesc bufferDesc;
1029     int32_t volumeStart;
1030     int32_t volumeEnd;
1031 };
1032 
1033 struct Volume {
1034     bool isMute = false;
1035     float volumeFloat = 1.0f;
1036     uint32_t volumeInt = 0;
1037 };
1038 
1039 struct DeviceInfo {
1040     DeviceType deviceType;
1041     DeviceRole deviceRole;
1042     int32_t deviceId;
1043     int32_t channelMasks;
1044     std::string deviceName;
1045     std::string macAddress;
1046     AudioStreamInfo audioStreamInfo;
1047     std::string networkId;
1048     std::string displayName;
1049     int32_t interruptGroupId;
1050     int32_t volumeGroupId;
1051     bool isLowLatencyDevice;
1052 };
1053 
1054 enum StreamSetState {
1055     STREAM_PAUSE,
1056     STREAM_RESUME
1057 };
1058 
1059 struct StreamSetStateEventInternal {
1060     StreamSetState streamSetState;
1061     AudioStreamType audioStreamType;
1062 };
1063 
1064 struct AudioRendererChangeInfo {
1065     int32_t createrUID;
1066     int32_t clientUID;
1067     int32_t sessionId;
1068     int32_t tokenId;
1069     AudioRendererInfo rendererInfo;
1070     RendererState rendererState;
1071     DeviceInfo outputDeviceInfo;
1072 };
1073 
1074 struct AudioCapturerChangeInfo {
1075     int32_t createrUID;
1076     int32_t clientUID;
1077     int32_t sessionId;
1078     AudioCapturerInfo capturerInfo;
1079     CapturerState capturerState;
1080     DeviceInfo inputDeviceInfo;
1081 };
1082 
1083 struct AudioStreamChangeInfo {
1084     AudioRendererChangeInfo audioRendererChangeInfo;
1085     AudioCapturerChangeInfo audioCapturerChangeInfo;
1086 };
1087 
1088 enum AudioPin {
1089     AUDIO_PIN_NONE = 0,
1090     AUDIO_PIN_OUT_SPEAKER = 1,
1091     AUDIO_PIN_OUT_HEADSET = 2,
1092     AUDIO_PIN_OUT_LINEOUT = 4,
1093     AUDIO_PIN_OUT_HDMI = 8,
1094     AUDIO_PIN_OUT_USB = 16,
1095     AUDIO_PIN_OUT_USB_EXT = 32,
1096     AUDIO_PIN_OUT_DAUDIO_DEFAULT = 64,
1097     AUDIO_PIN_IN_MIC = 134217729,
1098     AUDIO_PIN_IN_HS_MIC = 134217730,
1099     AUDIO_PIN_IN_LINEIN = 134217732,
1100     AUDIO_PIN_IN_USB_EXT = 134217736,
1101     AUDIO_PIN_IN_DAUDIO_DEFAULT = 134217744,
1102 };
1103 
1104 enum AudioParamKey {
1105     NONE = 0,
1106     VOLUME = 1,
1107     INTERRUPT = 2,
1108     RENDER_STATE = 5,
1109     A2DP_SUSPEND_STATE = 6,  // for bluetooth sink
1110     BT_HEADSET_NREC = 7,
1111     BT_WBS = 8,
1112     PARAM_KEY_LOWPOWER = 1000,
1113 };
1114 
1115 struct DStatusInfo {
1116     char networkId[NETWORK_ID_SIZE];
1117     AudioPin hdiPin = AUDIO_PIN_NONE;
1118     int32_t mappingVolumeId = 0;
1119     int32_t mappingInterruptId = 0;
1120     int32_t deviceId;
1121     int32_t channelMasks;
1122     std::string deviceName = "";
1123     bool isConnected = false;
1124     std::string macAddress;
1125     AudioStreamInfo streamInfo = {};
1126     ConnectType connectType = CONNECT_TYPE_LOCAL;
1127 };
1128 
1129 struct AudioRendererDataInfo {
1130     uint8_t *buffer;
1131     size_t flag;
1132 };
1133 
1134 enum AudioPermissionState {
1135     AUDIO_PERMISSION_START = 0,
1136     AUDIO_PERMISSION_STOP = 1,
1137 };
1138 
1139 class AudioRendererPolicyServiceDiedCallback {
1140 public:
1141     virtual ~AudioRendererPolicyServiceDiedCallback() = default;
1142 
1143     /**
1144      * Called when audio policy service died.
1145      * @since 10
1146      */
1147     virtual void OnAudioPolicyServiceDied() = 0;
1148 };
1149 
1150 enum DeviceVolumeType {
1151     EARPIECE_VOLUME_TYPE = 0,
1152     SPEAKER_VOLUME_TYPE = 1,
1153     HEADSET_VOLUME_TYPE = 2,
1154 };
1155 } // namespace AudioStandard
1156 } // namespace OHOS
1157 #endif // AUDIO_INFO_H
1158