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