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