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 
16 /**
17  * @addtogroup MultiMedia_AudioCommon
18  * @{
19  *
20  * @brief Provides data types and audio formats required for recording and playing and recording audio.
21  *
22  *
23  * @since 1.0
24  * @version 1.0
25  */
26 
27 /**
28  * @file audio_errors.h
29  *
30  * @brief Declares the <b>audio_errors</b> class to define errors that may occur during audio operations.
31  *
32  *
33  * @since 1.0
34  * @version 1.0
35  */
36 
37 #ifndef AUDIO_ERRORS_H
38 #define AUDIO_ERRORS_H
39 
40 #include <cstdint>
41 
42 namespace OHOS {
43 namespace AudioStandard {
44 constexpr int MODULE_AUDIO = 1;
45 constexpr int SUBSYS_AUDIO = 30;
46 constexpr uint32_t OPEN_PORT_FAILURE = (uint32_t) -1;
47 
48 using ErrCode = int32_t;
49 constexpr int SUBSYSTEM_BIT_NUM = 21;
50 constexpr int MODULE_BIT_NUM = 16;
51 
52 constexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0)
53 {
54     return (subsystem << SUBSYSTEM_BIT_NUM) | (module << MODULE_BIT_NUM);
55 }
56 
57 constexpr int32_t BASE_AUDIO_ERR_OFFSET = -ErrCodeOffset(SUBSYS_AUDIO, MODULE_AUDIO);
58 
59 /** Success */
60 const int32_t  SUCCESS = 0;
61 
62 /** Fail */
63 const int32_t  ERROR = BASE_AUDIO_ERR_OFFSET;
64 
65 /** Status error */
66 const int32_t  ERR_ILLEGAL_STATE = BASE_AUDIO_ERR_OFFSET - 1;
67 
68 /** Invalid parameter */
69 const int32_t  ERR_INVALID_PARAM = BASE_AUDIO_ERR_OFFSET - 2;
70 
71 /** Early media preparation */
72 const int32_t  ERR_EARLY_PREPARE = BASE_AUDIO_ERR_OFFSET - 3;
73 
74 /** Invalid operation */
75 const int32_t  ERR_INVALID_OPERATION = BASE_AUDIO_ERR_OFFSET - 4;
76 
77 /** error operation failed */
78 const int32_t  ERR_OPERATION_FAILED = BASE_AUDIO_ERR_OFFSET - 5;
79 
80 /** Buffer reading failed */
81 const int32_t  ERR_READ_BUFFER = BASE_AUDIO_ERR_OFFSET - 6;
82 
83 /** Buffer writing failed */
84 const int32_t  ERR_WRITE_BUFFER = BASE_AUDIO_ERR_OFFSET - 7;
85 
86 /**  Device not started */
87 const int32_t  ERR_NOT_STARTED = BASE_AUDIO_ERR_OFFSET - 8;
88 
89 /**  Invalid Device handle */
90 const int32_t  ERR_INVALID_HANDLE = BASE_AUDIO_ERR_OFFSET - 9;
91 
92 /**  unsupported operation */
93 const int32_t  ERR_NOT_SUPPORTED = BASE_AUDIO_ERR_OFFSET - 10;
94 
95 /**  unsupported device */
96 const int32_t  ERR_DEVICE_NOT_SUPPORTED = BASE_AUDIO_ERR_OFFSET - 11;
97 
98 /**  write operation failed */
99 const int32_t  ERR_WRITE_FAILED = BASE_AUDIO_ERR_OFFSET - 12;
100 
101 /**  read operation failed */
102 const int32_t  ERR_READ_FAILED = BASE_AUDIO_ERR_OFFSET - 13;
103 
104 /**  device init failed */
105 const int32_t  ERR_DEVICE_INIT = BASE_AUDIO_ERR_OFFSET - 14;
106 
107 /** Invalid data size that has been read */
108 const int32_t  ERR_INVALID_READ = BASE_AUDIO_ERR_OFFSET - 15;
109 
110 /** Invalid data size that has been written */
111 const int32_t  ERR_INVALID_WRITE = BASE_AUDIO_ERR_OFFSET - 16;
112 
113 /** set invalid index < 0 */
114 const int32_t  ERR_INVALID_INDEX = BASE_AUDIO_ERR_OFFSET - 17;
115 
116 /** focus request denied */
117 const int32_t  ERR_FOCUS_DENIED = BASE_AUDIO_ERR_OFFSET - 18;
118 
119 /** incorrect render/capture mode */
120 const int32_t  ERR_INCORRECT_MODE = BASE_AUDIO_ERR_OFFSET - 19;
121 
122 /** incorrect render/capture mode */
123 const int32_t  ERR_PERMISSION_DENIED = BASE_AUDIO_ERR_OFFSET - 20;
124 
125 /** Memory alloc failed */
126 const int32_t  ERR_MEMORY_ALLOC_FAILED = BASE_AUDIO_ERR_OFFSET - 21;
127 
128 /** microphone is disabled by EDM */
129 const int32_t ERR_MICROPHONE_DISABLED_BY_EDM = BASE_AUDIO_ERR_OFFSET - 22;
130 
131 /** system permission denied */
132 const int32_t ERR_SYSTEM_PERMISSION_DENIED = BASE_AUDIO_ERR_OFFSET - 23;
133 
134 /** callback not registered */
135 const int32_t ERR_CALLBACK_NOT_REGISTERED = BASE_AUDIO_ERR_OFFSET - 24;
136 
137 /** need not switch device */
138 const int32_t ERR_NEED_NOT_SWITCH_DEVICE = BASE_AUDIO_ERR_OFFSET - 25;
139 
140 const int32_t ERR_CONCEDE_INCOMING_STREAM = BASE_AUDIO_ERR_OFFSET - 26;
141 
142 const int32_t ERR_RENDERER_IN_SERVER_UNDERRUN = BASE_AUDIO_ERR_OFFSET - 27;
143 
144 /**exceed max audio stream cnt*/
145 const int32_t ERR_EXCEED_MAX_STREAM_CNT = BASE_AUDIO_ERR_OFFSET - 28;
146 
147 /**exceed max audio stream cnt per uid*/
148 const int32_t ERR_EXCEED_MAX_STREAM_CNT_PER_UID = BASE_AUDIO_ERR_OFFSET - 29;
149 /** Unknown error */
150 const int32_t  ERR_UNKNOWN = BASE_AUDIO_ERR_OFFSET - 200;
151 }  // namespace AudioStandard
152 }  // namespace OHOS
153 #endif  // AUDIO_ERRORS_H
154