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 {MSERR_SEEK_CONTINUOUS_UNSUPPORTED, "seek continonous is unsupported for this source"},
89 {MSERR_SUPER_RESOLUTION_UNSUPPORTED, "super resolution not supported"},
90 {MSERR_SUPER_RESOLUTION_NOT_ENABLED, "super resolution not enabled"},
91 };
92
93 const std::map<MediaServiceErrCode, MediaServiceExtErrCode> MSERRCODE_TO_EXTERRORCODE = {
94 {MSERR_OK, MSERR_EXT_OK},
95 {MSERR_NO_MEMORY, MSERR_EXT_NO_MEMORY},
96 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_IO},
97 {MSERR_INVALID_OPERATION, MSERR_EXT_OPERATE_NOT_PERMIT},
98 {MSERR_INVALID_VAL, MSERR_EXT_INVALID_VAL},
99 {MSERR_UNKNOWN, MSERR_EXT_UNKNOWN},
100 {MSERR_SERVICE_DIED, MSERR_EXT_SERVICE_DIED},
101 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
102 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_UNKNOWN},
103 {MSERR_INVALID_STATE, MSERR_EXT_INVALID_STATE},
104 {MSERR_UNSUPPORT, MSERR_EXT_UNSUPPORT},
105 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_UNSUPPORT},
106 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_UNSUPPORT},
107 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_UNSUPPORT},
108 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_UNSUPPORT},
109 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_UNSUPPORT},
110 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_UNSUPPORT},
111 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_UNSUPPORT},
112 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_UNSUPPORT},
113 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_UNSUPPORT},
114 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_UNSUPPORT},
115 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_UNSUPPORT},
116 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_UNSUPPORT},
117 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_UNSUPPORT},
118 {MSERR_UNSUPPORT_FILE, MSERR_EXT_UNSUPPORT},
119 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_UNSUPPORT},
120 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_UNSUPPORT},
121 {MSERR_AUD_ENC_FAILED, MSERR_EXT_UNKNOWN},
122 {MSERR_VID_ENC_FAILED, MSERR_EXT_UNKNOWN},
123 {MSERR_AUD_DEC_FAILED, MSERR_EXT_UNKNOWN},
124 {MSERR_VID_DEC_FAILED, MSERR_EXT_UNKNOWN},
125 {MSERR_MUXER_FAILED, MSERR_EXT_UNKNOWN},
126 {MSERR_DEMUXER_FAILED, MSERR_EXT_UNKNOWN},
127 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_UNKNOWN},
128 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_UNKNOWN},
129 {MSERR_START_FAILED, MSERR_EXT_UNKNOWN},
130 {MSERR_PAUSE_FAILED, MSERR_EXT_UNKNOWN},
131 {MSERR_STOP_FAILED, MSERR_EXT_UNKNOWN},
132 {MSERR_SEEK_FAILED, MSERR_EXT_UNKNOWN},
133 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_TIMEOUT},
134 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_UNSUPPORT},
135 {MSERR_EXTEND_START, MSERR_EXT_EXTEND_START},
136 {MSERR_IO_CANNOT_FIND_HOST, MSERR_EXT_IO},
137 {MSERR_IO_CONNECTION_TIMEOUT, MSERR_EXT_IO},
138 {MSERR_IO_NETWORK_ABNORMAL, MSERR_EXT_IO},
139 {MSERR_IO_NETWORK_UNAVAILABLE, MSERR_EXT_IO},
140 {MSERR_IO_NO_PERMISSION, MSERR_EXT_IO},
141 {MSERR_IO_NETWORK_ACCESS_DENIED, MSERR_EXT_IO},
142 {MSERR_IO_RESOURE_NOT_FOUND, MSERR_EXT_IO},
143 {MSERR_IO_SSL_CLIENT_CERT_NEEDED, MSERR_EXT_IO},
144 {MSERR_IO_SSL_CONNECT_FAIL, MSERR_EXT_IO},
145 {MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, MSERR_EXT_IO},
146 {MSERR_IO_UNSUPPORTTED_REQUEST, MSERR_EXT_IO},
147 {MSERR_SUPER_RESOLUTION_UNSUPPORTED, MSERR_EXT_UNSUPPORT},
148 {MSERR_SUPER_RESOLUTION_NOT_ENABLED, MSERR_EXT_UNKNOWN},
149 };
150
151 const std::map<MediaServiceExtErrCode, std::string> MSEXTERRCODE_INFOS = {
152 {MSERR_EXT_OK, "success"},
153 {MSERR_EXT_NO_MEMORY, "no memory"},
154 {MSERR_EXT_OPERATE_NOT_PERMIT, "operation not be permitted"},
155 {MSERR_EXT_INVALID_VAL, "invalid argument"},
156 {MSERR_EXT_IO, "IO error"},
157 {MSERR_EXT_TIMEOUT, "network timeout"},
158 {MSERR_EXT_UNKNOWN, "unkown error"},
159 {MSERR_EXT_SERVICE_DIED, "media service died"},
160 {MSERR_EXT_INVALID_STATE, "the state is not support this operation"},
161 {MSERR_EXT_UNSUPPORT, "unsupport interface"},
162 {MSERR_EXT_EXTEND_START, "extend err start"},
163 };
164
165 const std::map<MediaServiceErrCode, MediaServiceExtErrCodeAPI9> MSERRCODE_TO_EXTERRORCODEAPI9 = {
166 {MSERR_OK, MSERR_EXT_API9_OK},
167 {MSERR_NO_MEMORY, MSERR_EXT_API9_NO_MEMORY},
168 {MSERR_INVALID_OPERATION, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
169 {MSERR_INVALID_VAL, MSERR_EXT_API9_INVALID_PARAMETER},
170 {MSERR_MANDATORY_PARAMETER_UNSPECIFIED, MSERR_EXT_API9_INVALID_PARAMETER},
171 {MSERR_INCORRECT_PARAMETER_TYPE, MSERR_EXT_API9_INVALID_PARAMETER},
172 {MSERR_PARAMETER_VERIFICATION_FAILED, MSERR_EXT_API9_INVALID_PARAMETER},
173 {MSERR_SERVICE_DIED, MSERR_EXT_API9_SERVICE_DIED},
174 {MSERR_CREATE_REC_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
175 {MSERR_CREATE_PLAYER_ENGINE_FAILED, MSERR_EXT_API9_NO_MEMORY},
176 {MSERR_INVALID_STATE, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
177 {MSERR_UNSUPPORT, MSERR_EXT_API9_UNSUPPORT_FORMAT},
178 {MSERR_UNSUPPORT_AUD_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
179 {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
180 {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
181 {MSERR_UNSUPPORT_AUD_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
182 {MSERR_UNSUPPORT_AUD_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
183 {MSERR_UNSUPPORT_VID_SRC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
184 {MSERR_UNSUPPORT_VID_ENC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
185 {MSERR_UNSUPPORT_VID_PARAMS, MSERR_EXT_API9_UNSUPPORT_FORMAT},
186 {MSERR_UNSUPPORT_CONTAINER_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
187 {MSERR_UNSUPPORT_PROTOCOL_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
188 {MSERR_UNSUPPORT_VID_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
189 {MSERR_UNSUPPORT_AUD_DEC_TYPE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
190 {MSERR_UNSUPPORT_STREAM, MSERR_EXT_API9_UNSUPPORT_FORMAT},
191 {MSERR_UNSUPPORT_FILE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
192 {MSERR_UNSUPPORT_SOURCE, MSERR_EXT_API9_UNSUPPORT_FORMAT},
193 {MSERR_AUD_RENDER_FAILED, MSERR_EXT_API9_IO},
194 {MSERR_AUD_ENC_FAILED, MSERR_EXT_API9_IO},
195 {MSERR_VID_ENC_FAILED, MSERR_EXT_API9_IO},
196 {MSERR_AUD_DEC_FAILED, MSERR_EXT_API9_IO},
197 {MSERR_VID_DEC_FAILED, MSERR_EXT_API9_IO},
198 {MSERR_MUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
199 {MSERR_DEMUXER_FAILED, MSERR_EXT_API9_UNSUPPORT_FORMAT},
200 {MSERR_OPEN_FILE_FAILED, MSERR_EXT_API9_IO},
201 {MSERR_FILE_ACCESS_FAILED, MSERR_EXT_API9_IO},
202 {MSERR_START_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
203 {MSERR_PAUSE_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
204 {MSERR_STOP_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
205 {MSERR_SEEK_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
206 {MSERR_DRM_VERIFICATION_FAILED, MSERR_EXT_API9_OPERATE_NOT_PERMIT},
207 {MSERR_NETWORK_TIMEOUT, MSERR_EXT_API9_TIMEOUT},
208 {MSERR_NOT_FIND_CONTAINER, MSERR_EXT_API9_UNSUPPORT_FORMAT},
209 {MSERR_UNKNOWN, MSERR_EXT_API9_IO},
210 {MSERR_DATA_SOURCE_IO_ERROR, MSERR_EXT_API9_IO},
211 {MSERR_DATA_SOURCE_ERROR_UNKNOWN, MSERR_EXT_API9_IO},
212 {MSERR_AUD_INTERRUPT, MSERR_EXT_API9_AUDIO_INTERRUPTED},
213 {MSERR_USER_NO_PERMISSION, MSERR_EXT_API9_NO_PERMISSION},
214 {MSERR_UNSUPPORT_WATER_MARK, MSERR_EXT_API9_UNSUPPORT_CAPABILITY},
215 {MSERR_DEMUXER_BUFFER_NO_MEMORY, MSERR_EXT_API9_IO},
216 {MSERR_IO_CANNOT_FIND_HOST, MSERR_EXT_API14_IO_CANNOT_FIND_HOST},
217 {MSERR_IO_CONNECTION_TIMEOUT, MSERR_EXT_API14_IO_CONNECTION_TIMEOUT},
218 {MSERR_IO_NETWORK_ABNORMAL, MSERR_EXT_API14_IO_NETWORK_ABNORMAL},
219 {MSERR_IO_NETWORK_UNAVAILABLE, MSERR_EXT_API14_IO_NETWORK_UNAVAILABLE},
220 {MSERR_IO_NO_PERMISSION, MSERR_EXT_API14_IO_NO_PERMISSION},
221 {MSERR_IO_NETWORK_ACCESS_DENIED, MSERR_EXT_API14_IO_NETWORK_ACCESS_DENIED},
222 {MSERR_IO_RESOURE_NOT_FOUND, MSERR_EXT_API14_IO_RESOURE_NOT_FOUND},
223 {MSERR_IO_SSL_CLIENT_CERT_NEEDED, MSERR_EXT_API14_IO_SSL_CLIENT_CERT_NEEDED},
224 {MSERR_IO_SSL_CONNECT_FAIL, MSERR_EXT_API14_IO_SSL_CONNECT_FAIL},
225 {MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, MSERR_EXT_API14_IO_SSL_SERVER_CERT_UNTRUSTED},
226 {MSERR_IO_UNSUPPORTTED_REQUEST, MSERR_EXT_API14_IO_UNSUPPORTTED_REQUEST},
227 {MSERR_SEEK_CONTINUOUS_UNSUPPORTED, MSERR_EXT_API16_SEEK_CONTINUOUS_UNSUPPORTED},
228 {MSERR_SUPER_RESOLUTION_UNSUPPORTED, MSERR_EXT_API16_SUPER_RESOLUTION_UNSUPPORTED},
229 {MSERR_SUPER_RESOLUTION_NOT_ENABLED, MSERR_EXT_API16_SUPER_RESOLUTION_NOT_ENABLED},
230 };
231
232 const std::map<MediaServiceExtErrCodeAPI9, std::string> MSEXTERRCODE_API9_INFOS = {
233 {MSERR_EXT_API9_OK, "Success: "},
234 {MSERR_EXT_API9_NO_PERMISSION, "No Permission: "},
235 {MSERR_EXT_API9_PERMISSION_DENIED, "Permission Denied"},
236 {MSERR_EXT_API9_INVALID_PARAMETER, "Invalid Parameter: "},
237 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, "Unsupport Capability: "},
238 {MSERR_EXT_API9_NO_MEMORY, "No Memory: "},
239 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, "Operate Not Permit: "},
240 {MSERR_EXT_API9_IO, "IO Error: "},
241 {MSERR_EXT_API9_TIMEOUT, "Network Timeout: "},
242 {MSERR_EXT_API9_SERVICE_DIED, "Service Died: "},
243 {MSERR_EXT_API9_UNSUPPORT_FORMAT, "Unsupported Format: "},
244 {MSERR_EXT_API9_AUDIO_INTERRUPTED, "Audio Interruped: "},
245 {MSERR_EXT_API14_IO_CANNOT_FIND_HOST, "IO Cannot Find Host: "},
246 {MSERR_EXT_API14_IO_CONNECTION_TIMEOUT, "IO Connection Timeout: "},
247 {MSERR_EXT_API14_IO_NETWORK_ABNORMAL, "IO Network Abnormal: "},
248 {MSERR_EXT_API14_IO_NETWORK_UNAVAILABLE, "IO Network Unavailable: "},
249 {MSERR_EXT_API14_IO_NO_PERMISSION, "IO No Permission: "},
250 {MSERR_EXT_API14_IO_NETWORK_ACCESS_DENIED, "IO Request Denied: "},
251 {MSERR_EXT_API14_IO_RESOURE_NOT_FOUND, "IO Resource Not Found: "},
252 {MSERR_EXT_API14_IO_SSL_CLIENT_CERT_NEEDED, "IO SSL Client Cert Needed: "},
253 {MSERR_EXT_API14_IO_SSL_CONNECT_FAIL, "IO SSL Connect Fail: "},
254 {MSERR_EXT_API14_IO_SSL_SERVER_CERT_UNTRUSTED, "IO SSL Server Cert Untrusted: "},
255 {MSERR_EXT_API14_IO_UNSUPPORTTED_REQUEST, "IO Unsupported Request: "},
256 {MSERR_EXT_API16_SEEK_CONTINUOUS_UNSUPPORTED, "Seek continuous unsupported: "},
257 };
258
259 const std::set<MediaServiceErrCode> API14_EXT_IO_ERRORS = {
260 MSERR_IO_CANNOT_FIND_HOST,
261 MSERR_IO_CONNECTION_TIMEOUT,
262 MSERR_IO_NETWORK_ABNORMAL,
263 MSERR_IO_NETWORK_UNAVAILABLE,
264 MSERR_IO_NO_PERMISSION,
265 MSERR_IO_NETWORK_ACCESS_DENIED,
266 MSERR_IO_RESOURE_NOT_FOUND,
267 MSERR_IO_SSL_CLIENT_CERT_NEEDED,
268 MSERR_IO_SSL_CONNECT_FAIL,
269 MSERR_IO_SSL_SERVER_CERT_UNTRUSTED,
270 MSERR_IO_UNSUPPORTTED_REQUEST,
271 };
272
ErrorMessageOk(const std::string & param1,const std::string & param2)273 std::string ErrorMessageOk(const std::string& param1, const std::string& param2)
274 {
275 (void)param1;
276 (void)param2;
277 return "success";
278 }
279
ErrorMessageNoPermission(const std::string & param1,const std::string & param2)280 std::string ErrorMessageNoPermission(const std::string& param1, const std::string& param2)
281 {
282 std::string message = "Try to do " + param1 + " failed. User should request permission " + param2 + " first.";
283 return message;
284 }
285
ErrorMessageInvalidParameter(const std::string & param1,const std::string & param2)286 std::string ErrorMessageInvalidParameter(const std::string& param1, const std::string& param2)
287 {
288 (void)param2;
289 std::string message = "The Parameter " + param1 + " is invalid. Please check the type and range.";
290 return message;
291 }
292
ErrorMessageUnsupportCapability(const std::string & param1,const std::string & param2)293 std::string ErrorMessageUnsupportCapability(const std::string& param1, const std::string& param2)
294 {
295 (void)param2;
296 std::string message = "Function " + param1 + " can not work correctly due to limited device capability.";
297 return message;
298 }
299
ErrorMessageNoMemory(const std::string & param1,const std::string & param2)300 std::string ErrorMessageNoMemory(const std::string& param1, const std::string& param2)
301 {
302 (void)param2;
303 std::string message = "Create " + param1 + " failed due to system memory.";
304 return message;
305 }
306
ErrorMessageOperateNotPermit(const std::string & param1,const std::string & param2)307 std::string ErrorMessageOperateNotPermit(const std::string& param1, const std::string& param2)
308 {
309 (void)param2;
310 std::string message = "The operate " + param1 + " failed due to not permit in current state.";
311 return message;
312 }
313
ErrorMessageIO(const std::string & param1,const std::string & param2)314 std::string ErrorMessageIO(const std::string& param1, const std::string& param2)
315 {
316 (void)param2;
317 std::string message = "IO error happened due to " + param1 + ".";
318 return message;
319 }
320
ErrorMessageTimeout(const std::string & param1,const std::string & param2)321 std::string ErrorMessageTimeout(const std::string& param1, const std::string& param2)
322 {
323 std::string message = "Timeout happend when " + param1 + " due to " + param2 + ".";
324 return message;
325 }
326
ErrorMessageServiceDied(const std::string & param1,const std::string & param2)327 std::string ErrorMessageServiceDied(const std::string& param1, const std::string& param2)
328 {
329 (void)param1;
330 (void)param2;
331 std::string message = "Media Serviced Died.";
332 return message;
333 }
334
ErrorMessageUnsupportFormat(const std::string & param1,const std::string & param2)335 std::string ErrorMessageUnsupportFormat(const std::string& param1, const std::string& param2)
336 {
337 (void)param2;
338 std::string message = "The format " + param1 + " is not support.";
339 return message;
340 }
341
ErrorMessageAudioInterruped(const std::string & param1,const std::string & param2)342 std::string ErrorMessageAudioInterruped(const std::string & param1, const std::string& param2)
343 {
344 (void)param1;
345 (void)param2;
346 std::string message = "Audio Interrupted by other process.";
347 return message;
348 }
349
350 const std::map<MediaServiceExtErrCodeAPI9, ErrorMessageFunc> MSEXTERRAPI9CODE_FUNCS = {
351 {MSERR_EXT_API9_OK, &ErrorMessageOk},
352 {MSERR_EXT_API9_NO_PERMISSION, &ErrorMessageNoPermission},
353 {MSERR_EXT_API9_INVALID_PARAMETER, &ErrorMessageInvalidParameter},
354 {MSERR_EXT_API9_UNSUPPORT_CAPABILITY, &ErrorMessageUnsupportCapability},
355 {MSERR_EXT_API9_NO_MEMORY, &ErrorMessageNoMemory},
356 {MSERR_EXT_API9_OPERATE_NOT_PERMIT, &ErrorMessageOperateNotPermit},
357 {MSERR_EXT_API9_IO, &ErrorMessageIO},
358 {MSERR_EXT_API9_TIMEOUT, &ErrorMessageTimeout},
359 {MSERR_EXT_API9_SERVICE_DIED, &ErrorMessageServiceDied},
360 {MSERR_EXT_API9_UNSUPPORT_FORMAT, &ErrorMessageUnsupportFormat},
361 {MSERR_EXT_API9_AUDIO_INTERRUPTED, &ErrorMessageAudioInterruped},
362 };
363
MSErrorToString(MediaServiceErrCode code)364 std::string MSErrorToString(MediaServiceErrCode code)
365 {
366 if (MSERRCODE_INFOS.count(code) != 0) {
367 return MSERRCODE_INFOS.at(code);
368 }
369
370 if (code > MSERR_EXTEND_START) {
371 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
372 }
373
374 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
375 }
376
MSExtErrorToString(MediaServiceExtErrCode code)377 std::string MSExtErrorToString(MediaServiceExtErrCode code)
378 {
379 if (MSEXTERRCODE_INFOS.count(code) != 0) {
380 return MSEXTERRCODE_INFOS.at(code);
381 }
382
383 if (code > MSERR_EXT_EXTEND_START) {
384 return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
385 }
386
387 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
388 }
389
MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code,const std::string & param1,const std::string & param2)390 std::string MSExtErrorAPI9ToString(MediaServiceExtErrCodeAPI9 code,
391 const std::string& param1, const std::string& param2)
392 {
393 if (MSEXTERRAPI9CODE_FUNCS.count(code) != 0) {
394 return MSEXTERRAPI9CODE_FUNCS.at(code)(param1, param2);
395 }
396
397 return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
398 }
399
MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)400 std::string MSExtAVErrorToString(MediaServiceExtErrCodeAPI9 code)
401 {
402 if (MSEXTERRCODE_API9_INFOS.count(code) != 0) {
403 return MSEXTERRCODE_API9_INFOS.at(code);
404 }
405
406 return "invalid error code:";
407 }
408
MSErrorToExtErrorString(MediaServiceErrCode code)409 std::string MSErrorToExtErrorString(MediaServiceErrCode code)
410 {
411 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
412 MediaServiceExtErrCode extCode = MSERRCODE_TO_EXTERRORCODE.at(code);
413 if (MSEXTERRCODE_INFOS.count(extCode) != 0) {
414 return MSEXTERRCODE_INFOS.at(extCode);
415 }
416 }
417
418 return "unkown error";
419 }
420
MSErrorToExtErrorAPI9String(MediaServiceErrCode code,const std::string & param1,const std::string & param2)421 std::string MSErrorToExtErrorAPI9String(MediaServiceErrCode code, const std::string& param1, const std::string& param2)
422 {
423 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
424 MediaServiceExtErrCodeAPI9 extCode = MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
425 if (MSEXTERRAPI9CODE_FUNCS.count(extCode) != 0) {
426 return MSEXTERRAPI9CODE_FUNCS.at(extCode)(param1, param2);
427 }
428 }
429
430 return "unkown error";
431 }
432
MSErrorToExtError(MediaServiceErrCode code)433 MediaServiceExtErrCode MSErrorToExtError(MediaServiceErrCode code)
434 {
435 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
436 return MSERRCODE_TO_EXTERRORCODE.at(code);
437 }
438
439 return MSERR_EXT_UNKNOWN;
440 }
441
MSErrorToExtErrorAPI9(MediaServiceErrCode code)442 MediaServiceExtErrCodeAPI9 MSErrorToExtErrorAPI9(MediaServiceErrCode code)
443 {
444 if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODEAPI9.count(code) != 0) {
445 return MSERRCODE_TO_EXTERRORCODEAPI9.at(code);
446 }
447 // If error not in map, need add error and should not return default MSERR_EXT_API9_IO.
448 return MSERR_EXT_API9_IO;
449 }
450
IsAPI14IOError(MediaServiceErrCode code)451 bool IsAPI14IOError(MediaServiceErrCode code)
452 {
453 return API14_EXT_IO_ERRORS.find(code) != API14_EXT_IO_ERRORS.end();
454 }
455 } // namespace Media
456 } // namespace OHOS
457