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 };
77
78 const std::map<MediaServiceErrCode, MediaServiceExtErrCode> MSERRCODE_TO_EXTERRORCODE = {
79 {MSERR_OK, MSERR_EXT_OK},
80 {MSERR_NO_MEMORY, MSERR_EXT_NO_MEMORY},
81 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_IO},
82 {MSERR_INVALID_OPERATION, MSERR_EXT_OPERATE_NOT_PERMIT},
83 {MSERR_INVALID_VAL, MSERR_EXT_INVALID_VAL},
84 {MSERR_UNKNOWN, MSERR_EXT_UNKNOWN},
85 {MSERR_SERVICE_DIED, MSERR_EXT_SERVICE_DIED},
86 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
87 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
88 {MSERR_INVALID_STATE, MSERR_EXT_INVALID_STATE},
89 {MSERR_UNSUPPORT, MSERR_EXT_UNSUPPORT},
90 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_UNSUPPORT},
91 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_UNSUPPORT},
92 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_UNSUPPORT},
93 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_UNSUPPORT},
94 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_UNSUPPORT},
95 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_UNSUPPORT},
96 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_UNSUPPORT},
97 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_UNSUPPORT},
98 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_UNSUPPORT},
99 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_UNSUPPORT},
100 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_UNSUPPORT},
101 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_UNSUPPORT},
102 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_UNSUPPORT},
103 {MSERR_UNSUPPORT_FILE, MSERR_EXT_UNSUPPORT},
104 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_UNSUPPORT},
105 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_UNSUPPORT},
106 {MSERR_AUD_ENC_FAILED, MSERR_EXT_UNKNOWN},
107 {MSERR_VID_ENC_FAILED, MSERR_EXT_UNKNOWN},
108 {MSERR_AUD_DEC_FAILED, MSERR_EXT_UNKNOWN},
109 {MSERR_VID_DEC_FAILED, MSERR_EXT_UNKNOWN},
110 {MSERR_MUXER_FAILED, MSERR_EXT_UNKNOWN},
111 {MSERR_DEMUXER_FAILED, MSERR_EXT_UNKNOWN},
112 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_UNKNOWN},
113 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_UNKNOWN},
114 {MSERR_START_FAILED, MSERR_EXT_UNKNOWN},
115 {MSERR_PAUSE_FAILED, MSERR_EXT_UNKNOWN},
116 {MSERR_STOP_FAILED, MSERR_EXT_UNKNOWN},
117 {MSERR_SEEK_FAILED, MSERR_EXT_UNKNOWN},
118 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_TIMEOUT},
119 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_UNSUPPORT},
120 {MSERR_EXTEND_START, MSERR_EXT_EXTEND_START},
121 };
122
123 const std::map<MediaServiceExtErrCode, std::string> MSEXTERRCODE_INFOS = {
124 {MSERR_EXT_OK, "success"},
125 {MSERR_EXT_NO_MEMORY, "no memory"},
126 {MSERR_EXT_OPERATE_NOT_PERMIT, "operation not be permitted"},
127 {MSERR_EXT_INVALID_VAL, "invalid argument"},
128 {MSERR_EXT_IO, "IO error"},
129 {MSERR_EXT_TIMEOUT, "network timeout"},
130 {MSERR_EXT_UNKNOWN, "unkown error"},
131 {MSERR_EXT_SERVICE_DIED, "media service died"},
132 {MSERR_EXT_INVALID_STATE, "the state is not support this operation"},
133 {MSERR_EXT_UNSUPPORT, "unsupport interface"},
134 {MSERR_EXT_EXTEND_START, "extend err start"},
135 };
136
137 const std::map<MediaServiceErrCode, MediaServiceExtErrCodeAPI9> MSERRCODE_TO_EXTERRORCODEAPI9 = {
138 {MSERR_OK, MSERR_EXT_API9_OK},
139 {MSERR_NO_MEMORY, MSERR_EXT_API9_NO_MEMORY},
140 {MSERR_INVALID_OPERATION, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
141 {MSERR_INVALID_VAL, MSERR_EXT_API9_INVALID_PARAMETER},
142 {MSERR_MANDATORY_PARAMETER_UNSPECIFIED, MSERR_EXT_API9_INVALID_PARAMETER},
143 {MSERR_INCORRECT_PARAMETER_TYPE, MSERR_EXT_API9_INVALID_PARAMETER},
144 {MSERR_PARAMETER_VERIFICATION_FAILED, MSERR_EXT_API9_INVALID_PARAMETER},
145 {MSERR_SERVICE_DIED, MSERR_EXT_API9_SERVICE_DIED},
146 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
147 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
148 {MSERR_INVALID_STATE, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
149 {MSERR_UNSUPPORT, MSERR_EXT_API9_UNSUPPORT_FORMAT},
150 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
151 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
152 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
153 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
154 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
155 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
156 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
157 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
158 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
159 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
160 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
161 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
162 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
163 {MSERR_UNSUPPORT_FILE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
164 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
165 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_API9_IO},
166 {MSERR_AUD_ENC_FAILED, MSERR_EXT_API9_IO},
167 {MSERR_VID_ENC_FAILED, MSERR_EXT_API9_IO},
168 {MSERR_AUD_DEC_FAILED, MSERR_EXT_API9_IO},
169 {MSERR_VID_DEC_FAILED, MSERR_EXT_API9_IO},
170 {MSERR_MUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
171 {MSERR_DEMUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
172 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_API9_IO},
173 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_API9_IO},
174 {MSERR_START_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
175 {MSERR_PAUSE_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
176 {MSERR_STOP_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
177 {MSERR_SEEK_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
178 {MSERR_DRM_VERIFICATION_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
179 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_API9_TIMEOUT},
180 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_API9_UNSUPPORT_FORMAT},
181 {MSERR_UNKNOWN, MSERR_EXT_API9_IO},
182 {MSERR_DATA_SOURCE_IO_ERROR, MSERR_EXT_API9_IO},
183 {MSERR_DATA_SOURCE_ERROR_UNKNOWN, MSERR_EXT_API9_IO},
184 {MSERR_AUD_INTERRUPT, MSERR_EXT_API9_AUDIO_INTERRUPTED},
185 {MSERR_USER_NO_PERMISSION, MSERR_EXT_API9_NO_PERMISSION},
186 {MSERR_UNSUPPORT_WATER_MARK, MSERR_EXT_API9_UNSUPPORT_CAPABILITY},
187 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_API9_IO}
188 };
189
190 const std::map<MediaServiceExtErrCodeAPI9, std::string> MSEXTERRCODE_API9_INFOS = {
191 {MSERR_EXT_API9_OK, "Success: "},
192 {MSERR_EXT_API9_NO_PERMISSION, "No Permission: "},
193 {MSERR_EXT_API9_PERMISSION_DENIED, "Permission Denied"},
194 {MSERR_EXT_API9_INVALID_PARAMETER, "Invalid Parameter: "},
195 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, "Unsupport Capability: "},
196 {MSERR_EXT_API9_NO_MEMORY, "No Memory: "},
197 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, "Operate Not Permit: "},
198 {MSERR_EXT_API9_IO, "IO Error: "},
199 {MSERR_EXT_API9_TIMEOUT, "Network Timeout: "},
200 {MSERR_EXT_API9_SERVICE_DIED, "Service Died: "},
201 {MSERR_EXT_API9_UNSUPPORT_FORMAT, "Unsupport Format: "},
202 {MSERR_EXT_API9_AUDIO_INTERRUPTED, "Audio Interruped: "},
203 };
204
ErrorMessageOk(const std::string & param1,const std::string & param2)205 std::string ErrorMessageOk(const std::string& param1, const std::string& param2)
206 {
207 (void)param1;
208 (void)param2;
209 return "success";
210 }
211
ErrorMessageNoPermission(const std::string & param1,const std::string & param2)212 std::string ErrorMessageNoPermission(const std::string& param1, const std::string& param2)
213 {
214 std::string message = "Try to do " + param1 + " failed. User should request permission " + param2 +" first.";
215 return message;
216 }
217
ErrorMessageInvalidParameter(const std::string & param1,const std::string & param2)218 std::string ErrorMessageInvalidParameter(const std::string& param1, const std::string& param2)
219 {
220 (void)param2;
221 std::string message = "The Parameter " + param1 + " is invalid. Please check the type and range.";
222 return message;
223 }
224
ErrorMessageUnsupportCapability(const std::string & param1,const std::string & param2)225 std::string ErrorMessageUnsupportCapability(const std::string& param1, const std::string& param2)
226 {
227 (void)param2;
228 std::string message = "Function " + param1 + " can not work correctly due to limited device capability.";
229 return message;
230 }
231
ErrorMessageNoMemory(const std::string & param1,const std::string & param2)232 std::string ErrorMessageNoMemory(const std::string& param1, const std::string& param2)
233 {
234 (void)param2;
235 std::string message = "Create " + param1 + " failed due to system memory.";
236 return message;
237 }
238
ErrorMessageOperateNotPermit(const std::string & param1,const std::string & param2)239 std::string ErrorMessageOperateNotPermit(const std::string& param1, const std::string& param2)
240 {
241 (void)param2;
242 std::string message = "The operate " + param1 + " failed due to not permit in current state.";
243 return message;
244 }
245
ErrorMessageIO(const std::string & param1,const std::string & param2)246 std::string ErrorMessageIO(const std::string& param1, const std::string& param2)
247 {
248 (void)param2;
249 std::string message = "IO error happened due to " + param1 + ".";
250 return message;
251 }
252
ErrorMessageTimeout(const std::string & param1,const std::string & param2)253 std::string ErrorMessageTimeout(const std::string& param1, const std::string& param2)
254 {
255 std::string message = "Timeout happend when " + param1 + " due to " + param2 + ".";
256 return message;
257 }
258
ErrorMessageServiceDied(const std::string & param1,const std::string & param2)259 std::string ErrorMessageServiceDied(const std::string& param1, const std::string& param2)
260 {
261 (void)param1;
262 (void)param2;
263 std::string message = "Media Serviced Died.";
264 return message;
265 }
266
ErrorMessageUnsupportFormat(const std::string & param1,const std::string & param2)267 std::string ErrorMessageUnsupportFormat(const std::string& param1, const std::string& param2)
268 {
269 (void)param2;
270 std::string message = "The format " + param1 + " is not support.";
271 return message;
272 }
273
ErrorMessageAudioInterruped(const std::string & param1,const std::string & param2)274 std::string ErrorMessageAudioInterruped(const std::string & param1, const std::string& param2)
275 {
276 (void)param1;
277 (void)param2;
278 std::string message = "Audio Interrupted by other process.";
279 return message;
280 }
281
282 const std::map<MediaServiceExtErrCodeAPI9, ErrorMessageFunc> MSEXTERRAPI9CODE_FUNCS = {
283 {MSERR_EXT_API9_OK, &ErrorMessageOk},
284 {MSERR_EXT_API9_NO_PERMISSION, &ErrorMessageNoPermission},
285 {MSERR_EXT_API9_INVALID_PARAMETER, &ErrorMessageInvalidParameter},
286 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, &ErrorMessageUnsupportCapability},
287 {MSERR_EXT_API9_NO_MEMORY, &ErrorMessageNoMemory},
288 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, &ErrorMessageOperateNotPermit},
289 {MSERR_EXT_API9_IO, &ErrorMessageIO},
290 {MSERR_EXT_API9_TIMEOUT, &ErrorMessageTimeout},
291 {MSERR_EXT_API9_SERVICE_DIED, &ErrorMessageServiceDied},
292 {MSERR_EXT_API9_UNSUPPORT_FORMAT, &ErrorMessageUnsupportFormat},
293 {MSERR_EXT_API9_AUDIO_INTERRUPTED, &ErrorMessageAudioInterruped},
294 };
295
MSErrorToString(MediaServiceErrCode code)296 std::string MSErrorToString(MediaServiceErrCode code)
297 {
298 if (MSERRCODE_INFOS.count(code) != 0) {
299 return MSERRCODE_INFOS.at(code);
300 }
301
302 if (code > MSERR_EXTEND_START) {
303 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
304 }
305
306 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
307 }
308
MSExtErrorToString(MediaServiceExtErrCode code)309 std::string MSExtErrorToString(MediaServiceExtErrCode code)
310 {
311 if (MSEXTERRCODE_INFOS.count(code) != 0) {
312 return MSEXTERRCODE_INFOS.at(code);
313 }
314
315 if (code > MSERR_EXT_EXTEND_START) {
316 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
317 }
318
319 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
320 }
321
MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code,const std::string & param1,const std::string & param2)322 std::string MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code,
323 const std::string& param1, const std::string& param2)
324 {
325 if (MSEXTERRAPI9CODE_FUNCS.count(code) != 0) {
326 return MSEXTERRAPI9CODE_FUNCS.at(code)(param1, param2);
327 }
328
329 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
330 }
331
MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)332 std::string MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)
333 {
334 if (MSEXTERRCODE_API9_INFOS.count(code) != 0) {
335 return MSEXTERRCODE_API9_INFOS.at(code);
336 }
337
338 return "invalid error code:";
339 }
340
MSErrorToExtErrorString(MediaServiceErrCode code)341 std::string MSErrorToExtErrorString(MediaServiceErrCode code)
342 {
343 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
344 MediaServiceExtErrCode extCode = MSERRCODE_TO_EXTERRORCODE.at(code);
345 if (MSEXTERRCODE_INFOS.count(extCode) != 0) {
346 return MSEXTERRCODE_INFOS.at(extCode);
347 }
348 }
349
350 return "unkown error";
351 }
352
MSErrorToExtErrorAPI9String(MediaServiceErrCode code,const std::string & param1,const std::string & param2)353 std::string MSErrorToExtErrorAPI9String(MediaServiceErrCode code, const std::string& param1, const std::string& param2)
354 {
355 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
356 MediaServiceExtErrCodeAPI9 extCode = MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
357 if (MSEXTERRAPI9CODE_FUNCS.count(extCode) != 0) {
358 return MSEXTERRAPI9CODE_FUNCS.at(extCode)(param1, param2);
359 }
360 }
361
362 return "unkown error";
363 }
364
MSErrorToExtError(MediaServiceErrCode code)365 MediaServiceExtErrCode MSErrorToExtError(MediaServiceErrCode code)
366 {
367 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
368 return MSERRCODE_TO_EXTERRORCODE.at(code);
369 }
370
371 return MSERR_EXT_UNKNOWN;
372 }
373
MSErrorToExtErrorAPI9(MediaServiceErrCode code)374 MediaServiceExtErrCodeAPI9 MSErrorToExtErrorAPI9(MediaServiceErrCode code)
375 {
376 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
377 return MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
378 }
379 // If error not in map, need add error and should not return default MSERR_EXT_API9_IO.
380 return MSERR_EXT_API9_IO;
381 }
382 } // namespace Media
383 } // namespace OHOS
384