1 /*
2 * Copyright (C) 2021 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 #include "media_errors.h"
17 #include <map>
18 #include <string>
19
20 namespace OHOS {
21 namespace Media {
22 using ErrorMessageFunc = std::function<std::string(const std::string& param1, const std::string& param2)>;
23 const std::map<MediaServiceErrCode, std::string> MSERRCODE_INFOS = {
24 {MSERR_OK, "success"},
25 {MSERR_NO_MEMORY, "no memory"},
26 {MSERR_INVALID_OPERATION, "operation not be permitted"},
27 {MSERR_INVALID_VAL, "invalid argument"},
28 {MSERR_UNKNOWN, "unkown error"},
29 {MSERR_MANDATORY_PARAMETER_UNSPECIFIED, "mandatory parameters are left unspecified"},
30 {MSERR_INCORRECT_PARAMETER_TYPE, "Incorrect parameter types"},
31 {MSERR_PARAMETER_VERIFICATION_FAILED, "Parameter verification failed"},
32 {MSERR_SERVICE_DIED, "media service died"},
33 {MSERR_CREATE_REC_ENGINE_FAILED, "create recorder engine failed"},
34 {MSERR_CREATE_PLAYER_ENGINE_FAILED, "create player engine failed"},
35 {MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "create avmetadatahelper engine failed"},
36 {MSERR_INVALID_STATE, "the state is not support this operation"},
37 {MSERR_UNSUPPORT, "unsupport interface"},
38 {MSERR_UNSUPPORT_AUD_SRC_TYPE, "unsupport audio source type"},
39 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, "unsupport audio sample rate"},
40 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, "unsupport audio channel"},
41 {MSERR_UNSUPPORT_AUD_ENC_TYPE, "unsupport audio encoder type"},
42 {MSERR_UNSUPPORT_AUD_PARAMS, "unsupport audio params(other params)"},
43 {MSERR_UNSUPPORT_VID_SRC_TYPE, "unsupport video source type"},
44 {MSERR_UNSUPPORT_VID_ENC_TYPE, "unsupport video encoder type"},
45 {MSERR_UNSUPPORT_VID_PARAMS, "unsupport video params(other params)"},
46 {MSERR_UNSUPPORT_CONTAINER_TYPE, "unsupport container format type"},
47 {MSERR_UNSUPPORT_PROTOCOL_TYPE, "unsupport protocol type"},
48 {MSERR_UNSUPPORT_VID_DEC_TYPE, "unsupport video decoder type"},
49 {MSERR_UNSUPPORT_AUD_DEC_TYPE, "unsupport audio decoder type"},
50 {MSERR_UNSUPPORT_STREAM, "internal data stream error"},
51 {MSERR_UNSUPPORT_FILE, "this appears to be a text file"},
52 {MSERR_UNSUPPORT_SOURCE, "unsupport source type"},
53 {MSERR_AUD_ENC_FAILED, "audio encode failed"},
54 {MSERR_AUD_RENDER_FAILED, "audio render failed"},
55 {MSERR_VID_ENC_FAILED, "video encode failed"},
56 {MSERR_AUD_DEC_FAILED, "audio decode failed"},
57 {MSERR_VID_DEC_FAILED, "video decode failed"},
58 {MSERR_MUXER_FAILED, "stream avmuxer failed"},
59 {MSERR_DEMUXER_FAILED, "stream demuxer or parser failed"},
60 {MSERR_OPEN_FILE_FAILED, "open file failed"},
61 {MSERR_FILE_ACCESS_FAILED, "read or write file failed"},
62 {MSERR_START_FAILED, "audio or video start failed"},
63 {MSERR_PAUSE_FAILED, "audio or video pause failed"},
64 {MSERR_STOP_FAILED, "audio or video stop failed"},
65 {MSERR_SEEK_FAILED, "audio or video seek failed"},
66 {MSERR_NETWORK_TIMEOUT, "network timeout"},
67 {MSERR_NOT_FIND_CONTAINER, "not find a demuxer"},
68 {MSERR_EXTEND_START, "extend start error code"},
69 {MSERR_AUD_INTERRUPT, "audio interrupted"},
70 {MSERR_USER_NO_PERMISSION, "user no permission"},
71 {MSERR_DATA_SOURCE_ERROR_UNKNOWN, "media data source error unknow"},
72 {MSERR_DATA_SOURCE_IO_ERROR, "media data source IO failed"},
73 {MSERR_DRM_VERIFICATION_FAILED, "DRM verification failed"},
74 {MSERR_UNSUPPORT_WATER_MARK, "unsupported water mark"},
75 {MSERR_DEMUXER_BUFFER_NO_MEMORY, "demuxer cache data reached its limit"},
76 {MSERR_IO_CANNOT_FIND_HOST, "IO can not find host"},
77 {MSERR_IO_CONNECTION_TIMEOUT, "IO connection timeout"},
78 {MSERR_IO_NETWORK_ABNORMAL, "IO network abnormal"},
79 {MSERR_IO_NETWORK_UNAVAILABLE, "IO network unavailable"},
80 {MSERR_IO_NO_PERMISSION, "IO no permission"},
81 {MSERR_IO_NETWORK_ACCESS_DENIED, "IO request denied"},
82 {MSERR_IO_RESOURE_NOT_FOUND, "IO resource not found"},
83 {MSERR_IO_SSL_CLIENT_CERT_NEEDED, "IO SSL client cert needed"},
84 {MSERR_IO_SSL_CONNECT_FAIL, "IO SSL connect fail"},
85 {MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, "IO SSL server cert untrusted"},
86 {MSERR_IO_UNSUPPORTTED_REQUEST, "IO unsupported request"},
87 {MSERR_IO_DATA_ABNORMAL, "IO data abnormal"},
88 {MSERR_IO_FILE_ACCESS_DENIED, "IO file access denied"},
89 {MSERR_IO_FILE_BAD_HANDLE, "IO file bad handle"},
90 {MSERR_IO_FILE_NOT_FOUND, "IO file not found"},
91 {MSERR_IO_FILE_PERMISSION_DENIED, "IO file permission denied"},
92 {MSERR_IO_AUDIO_DEC_FAILED, "IO decode failed"},
93 {MSERR_IO_AUDIO_DEC_INIT_FAILED, "audio decode init failed"},
94 {MSERR_IO_AUDIO_DEC_UNAVAILABLE, "audio decode unavailable"},
95 {MSERR_IO_AUDIO_DEVICE_ERROR, "audio device error"},
96 {MSERR_IO_AUDIO_DEVICE_INVALID_STATE, "audio device invalid state"},
97 {MSERR_IO_AUDIO_DEVICE_TIMEOUT, "audio device timeout"},
98 {MSERR_IO_AUDIO_DEVICE_UNAVAILABLE, "audio device unavailable"},
99 {MSERR_IO_AUDIO_ENC_FAILED, "audio encode failed"},
100 {MSERR_IO_AUDIO_ENC_INIT_FAILED, "audio encode init failed"},
101 {MSERR_IO_AUDIO_ENC_UNAVAILABLE, "audio encode unavailable"},
102 {MSERR_IO_VIDEO_DEC_FAILED, "video decode failed"},
103 {MSERR_IO_VIDEO_DEC_INIT_FAILED, "video decode init failed"},
104 {MSERR_IO_VIDEO_DEC_UNAVAILABLE, "video decode unavailable"},
105 {MSERR_IO_VIDEO_DEVICE_ERROR, "video device error"},
106 {MSERR_IO_VIDEO_ENC_FAILED, "video encode failed"},
107 {MSERR_IO_VIDEO_ENC_INIT_FAILED, "video encode init failed"},
108 {MSERR_IO_VIDEO_ENC_UNAVAILABLE, "video encode unavailable"},
109 };
110
111 const std::map<MediaServiceErrCode, MediaServiceExtErrCode> MSERRCODE_TO_EXTERRORCODE = {
112 {MSERR_OK, MSERR_EXT_OK},
113 {MSERR_NO_MEMORY, MSERR_EXT_NO_MEMORY},
114 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_IO},
115 {MSERR_INVALID_OPERATION, MSERR_EXT_OPERATE_NOT_PERMIT},
116 {MSERR_INVALID_VAL, MSERR_EXT_INVALID_VAL},
117 {MSERR_UNKNOWN, MSERR_EXT_UNKNOWN},
118 {MSERR_SERVICE_DIED, MSERR_EXT_SERVICE_DIED},
119 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
120 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
121 {MSERR_INVALID_STATE, MSERR_EXT_INVALID_STATE},
122 {MSERR_UNSUPPORT, MSERR_EXT_UNSUPPORT},
123 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_UNSUPPORT},
124 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_UNSUPPORT},
125 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_UNSUPPORT},
126 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_UNSUPPORT},
127 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_UNSUPPORT},
128 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_UNSUPPORT},
129 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_UNSUPPORT},
130 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_UNSUPPORT},
131 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_UNSUPPORT},
132 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_UNSUPPORT},
133 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_UNSUPPORT},
134 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_UNSUPPORT},
135 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_UNSUPPORT},
136 {MSERR_UNSUPPORT_FILE, MSERR_EXT_UNSUPPORT},
137 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_UNSUPPORT},
138 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_UNSUPPORT},
139 {MSERR_AUD_ENC_FAILED, MSERR_EXT_UNKNOWN},
140 {MSERR_VID_ENC_FAILED, MSERR_EXT_UNKNOWN},
141 {MSERR_AUD_DEC_FAILED, MSERR_EXT_UNKNOWN},
142 {MSERR_VID_DEC_FAILED, MSERR_EXT_UNKNOWN},
143 {MSERR_MUXER_FAILED, MSERR_EXT_UNKNOWN},
144 {MSERR_DEMUXER_FAILED, MSERR_EXT_UNKNOWN},
145 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_UNKNOWN},
146 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_UNKNOWN},
147 {MSERR_START_FAILED, MSERR_EXT_UNKNOWN},
148 {MSERR_PAUSE_FAILED, MSERR_EXT_UNKNOWN},
149 {MSERR_STOP_FAILED, MSERR_EXT_UNKNOWN},
150 {MSERR_SEEK_FAILED, MSERR_EXT_UNKNOWN},
151 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_TIMEOUT},
152 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_UNSUPPORT},
153 {MSERR_EXTEND_START, MSERR_EXT_EXTEND_START},
154 {MSERR_IO_CANNOT_FIND_HOST, MSERR_EXT_IO},
155 {MSERR_IO_CONNECTION_TIMEOUT, MSERR_EXT_IO},
156 {MSERR_IO_NETWORK_ABNORMAL, MSERR_EXT_IO},
157 {MSERR_IO_NETWORK_UNAVAILABLE, MSERR_EXT_IO},
158 {MSERR_IO_NO_PERMISSION, MSERR_EXT_IO},
159 {MSERR_IO_NETWORK_ACCESS_DENIED, MSERR_EXT_IO},
160 {MSERR_IO_RESOURE_NOT_FOUND, MSERR_EXT_IO},
161 {MSERR_IO_SSL_CLIENT_CERT_NEEDED, MSERR_EXT_IO},
162 {MSERR_IO_SSL_CONNECT_FAIL, MSERR_EXT_IO},
163 {MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, MSERR_EXT_IO},
164 {MSERR_IO_UNSUPPORTTED_REQUEST, MSERR_EXT_IO},
165 {MSERR_IO_DATA_ABNORMAL, MSERR_EXT_IO},
166 {MSERR_IO_FILE_ACCESS_DENIED, MSERR_EXT_IO},
167 {MSERR_IO_FILE_BAD_HANDLE, MSERR_EXT_IO},
168 {MSERR_IO_FILE_NOT_FOUND, MSERR_EXT_IO},
169 {MSERR_IO_FILE_PERMISSION_DENIED, MSERR_EXT_IO},
170 {MSERR_IO_AUDIO_DEC_FAILED, MSERR_EXT_IO},
171 {MSERR_IO_AUDIO_DEC_INIT_FAILED, MSERR_EXT_IO},
172 {MSERR_IO_AUDIO_DEC_UNAVAILABLE, MSERR_EXT_IO},
173 {MSERR_IO_AUDIO_DEVICE_ERROR, MSERR_EXT_IO},
174 {MSERR_IO_AUDIO_DEVICE_INVALID_STATE, MSERR_EXT_IO},
175 {MSERR_IO_AUDIO_DEVICE_TIMEOUT, MSERR_EXT_IO},
176 {MSERR_IO_AUDIO_DEVICE_UNAVAILABLE, MSERR_EXT_IO},
177 {MSERR_IO_AUDIO_ENC_FAILED, MSERR_EXT_IO},
178 {MSERR_IO_AUDIO_ENC_INIT_FAILED, MSERR_EXT_IO},
179 {MSERR_IO_AUDIO_ENC_UNAVAILABLE, MSERR_EXT_IO},
180 {MSERR_IO_VIDEO_DEC_FAILED, MSERR_EXT_IO},
181 {MSERR_IO_VIDEO_DEC_INIT_FAILED, MSERR_EXT_IO},
182 {MSERR_IO_VIDEO_DEC_UNAVAILABLE, MSERR_EXT_IO},
183 {MSERR_IO_VIDEO_DEVICE_ERROR, MSERR_EXT_IO},
184 {MSERR_IO_VIDEO_ENC_FAILED, MSERR_EXT_IO},
185 {MSERR_IO_VIDEO_ENC_INIT_FAILED, MSERR_EXT_IO},
186 {MSERR_IO_VIDEO_ENC_UNAVAILABLE, MSERR_EXT_IO},
187 };
188
189 const std::map<MediaServiceExtErrCode, std::string> MSEXTERRCODE_INFOS = {
190 {MSERR_EXT_OK, "success"},
191 {MSERR_EXT_NO_MEMORY, "no memory"},
192 {MSERR_EXT_OPERATE_NOT_PERMIT, "operation not be permitted"},
193 {MSERR_EXT_INVALID_VAL, "invalid argument"},
194 {MSERR_EXT_IO, "IO error"},
195 {MSERR_EXT_TIMEOUT, "network timeout"},
196 {MSERR_EXT_UNKNOWN, "unkown error"},
197 {MSERR_EXT_SERVICE_DIED, "media service died"},
198 {MSERR_EXT_INVALID_STATE, "the state is not support this operation"},
199 {MSERR_EXT_UNSUPPORT, "unsupport interface"},
200 {MSERR_EXT_EXTEND_START, "extend err start"},
201 };
202
203 const std::map<MediaServiceErrCode, MediaServiceExtErrCodeAPI9> MSERRCODE_TO_EXTERRORCODEAPI9 = {
204 {MSERR_OK, MSERR_EXT_API9_OK},
205 {MSERR_NO_MEMORY, MSERR_EXT_API9_NO_MEMORY},
206 {MSERR_INVALID_OPERATION, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
207 {MSERR_INVALID_VAL, MSERR_EXT_API9_INVALID_PARAMETER},
208 {MSERR_MANDATORY_PARAMETER_UNSPECIFIED, MSERR_EXT_API9_INVALID_PARAMETER},
209 {MSERR_INCORRECT_PARAMETER_TYPE, MSERR_EXT_API9_INVALID_PARAMETER},
210 {MSERR_PARAMETER_VERIFICATION_FAILED, MSERR_EXT_API9_INVALID_PARAMETER},
211 {MSERR_SERVICE_DIED, MSERR_EXT_API9_SERVICE_DIED},
212 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
213 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
214 {MSERR_INVALID_STATE, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
215 {MSERR_UNSUPPORT, MSERR_EXT_API9_UNSUPPORT_FORMAT},
216 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
217 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
218 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
219 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
220 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
221 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
222 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
223 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
224 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
225 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
226 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
227 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
228 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
229 {MSERR_UNSUPPORT_FILE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
230 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
231 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_API9_IO},
232 {MSERR_AUD_ENC_FAILED, MSERR_EXT_API9_IO},
233 {MSERR_VID_ENC_FAILED, MSERR_EXT_API9_IO},
234 {MSERR_AUD_DEC_FAILED, MSERR_EXT_API9_IO},
235 {MSERR_VID_DEC_FAILED, MSERR_EXT_API9_IO},
236 {MSERR_MUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
237 {MSERR_DEMUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
238 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_API9_IO},
239 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_API9_IO},
240 {MSERR_START_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
241 {MSERR_PAUSE_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
242 {MSERR_STOP_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
243 {MSERR_SEEK_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
244 {MSERR_DRM_VERIFICATION_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
245 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_API9_TIMEOUT},
246 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_API9_UNSUPPORT_FORMAT},
247 {MSERR_UNKNOWN, MSERR_EXT_API9_IO},
248 {MSERR_DATA_SOURCE_IO_ERROR, MSERR_EXT_API9_IO},
249 {MSERR_DATA_SOURCE_ERROR_UNKNOWN, MSERR_EXT_API9_IO},
250 {MSERR_AUD_INTERRUPT, MSERR_EXT_API9_AUDIO_INTERRUPTED},
251 {MSERR_USER_NO_PERMISSION, MSERR_EXT_API9_NO_PERMISSION},
252 {MSERR_UNSUPPORT_WATER_MARK, MSERR_EXT_API9_UNSUPPORT_CAPABILITY},
253 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_API9_IO},
254 {MSERR_IO_CANNOT_FIND_HOST, MSERR_EXT_API14_IO_CANNOT_FIND_HOST},
255 {MSERR_IO_CONNECTION_TIMEOUT, MSERR_EXT_API14_IO_CONNECTION_TIMEOUT},
256 {MSERR_IO_NETWORK_ABNORMAL, MSERR_EXT_API14_IO_NETWORK_ABNORMAL},
257 {MSERR_IO_NETWORK_UNAVAILABLE, MSERR_EXT_API14_IO_NETWORK_UNAVAILABLE},
258 {MSERR_IO_NO_PERMISSION, MSERR_EXT_API14_IO_NO_PERMISSION},
259 {MSERR_IO_NETWORK_ACCESS_DENIED, MSERR_EXT_API14_IO_NETWORK_ACCESS_DENIED},
260 {MSERR_IO_RESOURE_NOT_FOUND, MSERR_EXT_API14_IO_RESOURE_NOT_FOUND},
261 {MSERR_IO_SSL_CLIENT_CERT_NEEDED, MSERR_EXT_API14_IO_SSL_CLIENT_CERT_NEEDED},
262 {MSERR_IO_SSL_CONNECT_FAIL, MSERR_EXT_API14_IO_SSL_CONNECT_FAIL},
263 {MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, MSERR_EXT_API14_IO_SSL_SERVER_CERT_UNTRUSTED},
264 {MSERR_IO_UNSUPPORTTED_REQUEST, MSERR_EXT_API14_IO_UNSUPPORTTED_REQUEST},
265 };
266
267 const std::map<MediaServiceExtErrCodeAPI9, std::string> MSEXTERRCODE_API9_INFOS = {
268 {MSERR_EXT_API9_OK, "Success: "},
269 {MSERR_EXT_API9_NO_PERMISSION, "No Permission: "},
270 {MSERR_EXT_API9_PERMISSION_DENIED, "Permission Denied"},
271 {MSERR_EXT_API9_INVALID_PARAMETER, "Invalid Parameter: "},
272 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, "Unsupport Capability: "},
273 {MSERR_EXT_API9_NO_MEMORY, "No Memory: "},
274 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, "Operate Not Permit: "},
275 {MSERR_EXT_API9_IO, "IO Error: "},
276 {MSERR_EXT_API9_TIMEOUT, "Network Timeout: "},
277 {MSERR_EXT_API9_SERVICE_DIED, "Service Died: "},
278 {MSERR_EXT_API9_UNSUPPORT_FORMAT, "Unsupported Format: "},
279 {MSERR_EXT_API9_AUDIO_INTERRUPTED, "Audio Interruped: "},
280 {MSERR_EXT_API14_IO_CANNOT_FIND_HOST, "IO Cannot Find Host: "},
281 {MSERR_EXT_API14_IO_CONNECTION_TIMEOUT, "IO Connection Timeout: "},
282 {MSERR_EXT_API14_IO_NETWORK_ABNORMAL, "IO Network Abnormal: "},
283 {MSERR_EXT_API14_IO_NETWORK_UNAVAILABLE, "IO Network Unavailable: "},
284 {MSERR_EXT_API14_IO_NO_PERMISSION, "IO No Permission: "},
285 {MSERR_EXT_API14_IO_NETWORK_ACCESS_DENIED, "IO Request Denied: "},
286 {MSERR_EXT_API14_IO_RESOURE_NOT_FOUND, "IO Resource Not Found: "},
287 {MSERR_EXT_API14_IO_SSL_CLIENT_CERT_NEEDED, "IO SSL Client Cert Needed: "},
288 {MSERR_EXT_API14_IO_SSL_CONNECT_FAIL, "IO SSL Connect Fail: "},
289 {MSERR_EXT_API14_IO_SSL_SERVER_CERT_UNTRUSTED, "IO SSL Server Cert Untrusted: "},
290 {MSERR_EXT_API14_IO_UNSUPPORTTED_REQUEST, "IO Unsupported Request: "},
291 {MSERR_EXT_API14_IO_DATA_ABNORMAL, "IO data abnormal: "},
292 {MSERR_EXT_API14_IO_FILE_ACCESS_DENIED, "IO file access denied: "},
293 {MSERR_EXT_API14_IO_FILE_BAD_HANDLE, "IO file bad handle: "},
294 {MSERR_EXT_API14_IO_FILE_NOT_FOUND, "IO file not found: "},
295 {MSERR_EXT_API14_IO_FILE_PERMISSION_DENIED, "IO file permission denied: "},
296 {MSERR_EXT_API14_IO_AUDIO_DEC_FAILED, "IO decode failed: "},
297 {MSERR_EXT_API14_IO_AUDIO_DEC_INIT_FAILED, "audio decode init failed: "},
298 {MSERR_EXT_API14_IO_AUDIO_DEC_UNAVAILABLE, "audio decode unavailable: "},
299 {MSERR_EXT_API14_IO_AUDIO_DEVICE_ERROR, "audio device error: "},
300 {MSERR_EXT_API14_IO_AUDIO_DEVICE_INVALID_STATE, "audio device invalid state: "},
301 {MSERR_EXT_API14_IO_AUDIO_DEVICE_TIMEOUT, "audio device timeout: "},
302 {MSERR_EXT_API14_IO_AUDIO_DEVICE_UNAVAILABLE, "audio device unavailable: "},
303 {MSERR_EXT_API14_IO_AUDIO_ENC_FAILED, "audio encode failed: "},
304 {MSERR_EXT_API14_IO_AUDIO_ENC_INIT_FAILED, "audio encode init failed: "},
305 {MSERR_EXT_API14_IO_AUDIO_ENC_UNAVAILABLE, "audio encode unavailable: "},
306 {MSERR_EXT_API14_IO_VIDEO_DEC_FAILED, "video decode failed: "},
307 {MSERR_EXT_API14_IO_VIDEO_DEC_INIT_FAILED, "video decode init failed: "},
308 {MSERR_EXT_API14_IO_VIDEO_DEC_UNAVAILABLE, "video decode unavailable: "},
309 {MSERR_EXT_API14_IO_VIDEO_DEVICE_ERROR, "video device error: "},
310 {MSERR_EXT_API14_IO_VIDEO_ENC_FAILED, "video encode failed: "},
311 {MSERR_EXT_API14_IO_VIDEO_ENC_INIT_FAILED, "video encode init failed: "},
312 {MSERR_EXT_API14_IO_VIDEO_ENC_UNAVAILABLE, "video encode unavailable: "},
313 };
314
ErrorMessageOk(const std::string& param1, const std::string& param2)315 std::string ErrorMessageOk(const std::string& param1, const std::string& param2)
316 {
317 (void)param1;
318 (void)param2;
319 return "success";
320 }
321
ErrorMessageNoPermission(const std::string& param1, const std::string& param2)322 std::string ErrorMessageNoPermission(const std::string& param1, const std::string& param2)
323 {
324 std::string message = "Try to do " + param1 + " failed. User should request permission " + param2 +" first.";
325 return message;
326 }
327
ErrorMessageInvalidParameter(const std::string& param1, const std::string& param2)328 std::string ErrorMessageInvalidParameter(const std::string& param1, const std::string& param2)
329 {
330 (void)param2;
331 std::string message = "The Parameter " + param1 + " is invalid. Please check the type and range.";
332 return message;
333 }
334
ErrorMessageUnsupportCapability(const std::string& param1, const std::string& param2)335 std::string ErrorMessageUnsupportCapability(const std::string& param1, const std::string& param2)
336 {
337 (void)param2;
338 std::string message = "Function " + param1 + " can not work correctly due to limited device capability.";
339 return message;
340 }
341
ErrorMessageNoMemory(const std::string& param1, const std::string& param2)342 std::string ErrorMessageNoMemory(const std::string& param1, const std::string& param2)
343 {
344 (void)param2;
345 std::string message = "Create " + param1 + " failed due to system memory.";
346 return message;
347 }
348
ErrorMessageOperateNotPermit(const std::string& param1, const std::string& param2)349 std::string ErrorMessageOperateNotPermit(const std::string& param1, const std::string& param2)
350 {
351 (void)param2;
352 std::string message = "The operate " + param1 + " failed due to not permit in current state.";
353 return message;
354 }
355
ErrorMessageIO(const std::string& param1, const std::string& param2)356 std::string ErrorMessageIO(const std::string& param1, const std::string& param2)
357 {
358 (void)param2;
359 std::string message = "IO error happened due to " + param1 + ".";
360 return message;
361 }
362
ErrorMessageTimeout(const std::string& param1, const std::string& param2)363 std::string ErrorMessageTimeout(const std::string& param1, const std::string& param2)
364 {
365 std::string message = "Timeout happend when " + param1 + " due to " + param2 + ".";
366 return message;
367 }
368
ErrorMessageServiceDied(const std::string& param1, const std::string& param2)369 std::string ErrorMessageServiceDied(const std::string& param1, const std::string& param2)
370 {
371 (void)param1;
372 (void)param2;
373 std::string message = "Media Serviced Died.";
374 return message;
375 }
376
ErrorMessageUnsupportFormat(const std::string& param1, const std::string& param2)377 std::string ErrorMessageUnsupportFormat(const std::string& param1, const std::string& param2)
378 {
379 (void)param2;
380 std::string message = "The format " + param1 + " is not support.";
381 return message;
382 }
383
ErrorMessageAudioInterruped(const std::string & param1, const std::string& param2)384 std::string ErrorMessageAudioInterruped(const std::string & param1, const std::string& param2)
385 {
386 (void)param1;
387 (void)param2;
388 std::string message = "Audio Interrupted by other process.";
389 return message;
390 }
391
392 const std::map<MediaServiceExtErrCodeAPI9, ErrorMessageFunc> MSEXTERRAPI9CODE_FUNCS = {
393 {MSERR_EXT_API9_OK, &ErrorMessageOk},
394 {MSERR_EXT_API9_NO_PERMISSION, &ErrorMessageNoPermission},
395 {MSERR_EXT_API9_INVALID_PARAMETER, &ErrorMessageInvalidParameter},
396 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, &ErrorMessageUnsupportCapability},
397 {MSERR_EXT_API9_NO_MEMORY, &ErrorMessageNoMemory},
398 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, &ErrorMessageOperateNotPermit},
399 {MSERR_EXT_API9_IO, &ErrorMessageIO},
400 {MSERR_EXT_API9_TIMEOUT, &ErrorMessageTimeout},
401 {MSERR_EXT_API9_SERVICE_DIED, &ErrorMessageServiceDied},
402 {MSERR_EXT_API9_UNSUPPORT_FORMAT, &ErrorMessageUnsupportFormat},
403 {MSERR_EXT_API9_AUDIO_INTERRUPTED, &ErrorMessageAudioInterruped},
404 };
405
MSErrorToString(MediaServiceErrCode code)406 std::string MSErrorToString(MediaServiceErrCode code)
407 {
408 if (MSERRCODE_INFOS.count(code) != 0) {
409 return MSERRCODE_INFOS.at(code);
410 }
411
412 if (code > MSERR_EXTEND_START) {
413 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
414 }
415
416 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
417 }
418
MSExtErrorToString(MediaServiceExtErrCode code)419 std::string MSExtErrorToString(MediaServiceExtErrCode code)
420 {
421 if (MSEXTERRCODE_INFOS.count(code) != 0) {
422 return MSEXTERRCODE_INFOS.at(code);
423 }
424
425 if (code > MSERR_EXT_EXTEND_START) {
426 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
427 }
428
429 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
430 }
431
MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code, const std::string& param1, const std::string& param2)432 std::string MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code,
433 const std::string& param1, const std::string& param2)
434 {
435 if (MSEXTERRAPI9CODE_FUNCS.count(code) != 0) {
436 return MSEXTERRAPI9CODE_FUNCS.at(code)(param1, param2);
437 }
438
439 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
440 }
441
MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)442 std::string MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)
443 {
444 if (MSEXTERRCODE_API9_INFOS.count(code) != 0) {
445 return MSEXTERRCODE_API9_INFOS.at(code);
446 }
447
448 return "invalid error code:";
449 }
450
MSErrorToExtErrorString(MediaServiceErrCode code)451 std::string MSErrorToExtErrorString(MediaServiceErrCode code)
452 {
453 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
454 MediaServiceExtErrCode extCode = MSERRCODE_TO_EXTERRORCODE.at(code);
455 if (MSEXTERRCODE_INFOS.count(extCode) != 0) {
456 return MSEXTERRCODE_INFOS.at(extCode);
457 }
458 }
459
460 return "unkown error";
461 }
462
MSErrorToExtErrorAPI9String(MediaServiceErrCode code, const std::string& param1, const std::string& param2)463 std::string MSErrorToExtErrorAPI9String(MediaServiceErrCode code, const std::string& param1, const std::string& param2)
464 {
465 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
466 MediaServiceExtErrCodeAPI9 extCode = MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
467 if (MSEXTERRAPI9CODE_FUNCS.count(extCode) != 0) {
468 return MSEXTERRAPI9CODE_FUNCS.at(extCode)(param1, param2);
469 }
470 }
471
472 return "unkown error";
473 }
474
MSErrorToExtError(MediaServiceErrCode code)475 MediaServiceExtErrCode MSErrorToExtError(MediaServiceErrCode code)
476 {
477 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
478 return MSERRCODE_TO_EXTERRORCODE.at(code);
479 }
480
481 return MSERR_EXT_UNKNOWN;
482 }
483
MSErrorToExtErrorAPI9(MediaServiceErrCode code)484 MediaServiceExtErrCodeAPI9 MSErrorToExtErrorAPI9(MediaServiceErrCode code)
485 {
486 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
487 return MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
488 }
489 // If error not in map, need add error and should not return default MSERR_EXT_API9_IO.
490 return MSERR_EXT_API9_IO;
491 }
492 } // namespace Media
493 } // namespace OHOS
494