• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const std::map<MediaServiceErrCode, std::string> MSERRCODE_INFOS = {
23     {MSERR_OK, "success"},
24     {MSERR_NO_MEMORY, "no memory"},
25     {MSERR_INVALID_OPERATION, "opertation not be permitted"},
26     {MSERR_INVALID_VAL, "invalid argument"},
27     {MSERR_UNKNOWN, "unkown error"},
28     {MSERR_SERVICE_DIED, "media service died"},
29     {MSERR_CREATE_REC_ENGINE_FAILED, "create recorder engine failed"},
30     {MSERR_CREATE_PLAYER_ENGINE_FAILED, "create player engine failed"},
31     {MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "create avmetadatahelper engine failed"},
32     {MSERR_INVALID_STATE, "the state is not support this operation"},
33     {MSERR_UNSUPPORT, "unsupport interface"},
34     {MSERR_UNSUPPORT_AUD_SRC_TYPE, "unsupport audio source type"},
35     {MSERR_UNSUPPORT_AUD_SAMPLE_RATE, "unsupport audio sample rate"},
36     {MSERR_UNSUPPORT_AUD_CHANNEL_NUM, "unsupport audio channel"},
37     {MSERR_UNSUPPORT_AUD_ENC_TYPE, "unsupport audio encoder type"},
38     {MSERR_UNSUPPORT_AUD_PARAMS, "unsupport audio params(other params)"},
39     {MSERR_UNSUPPORT_VID_SRC_TYPE, "unsupport video source type"},
40     {MSERR_UNSUPPORT_VID_ENC_TYPE, "unsupport video encoder type"},
41     {MSERR_UNSUPPORT_VID_PARAMS, "unsupport video params(other params)"},
42     {MSERR_UNSUPPORT_CONTAINER_TYPE, "unsupport container format type"},
43     {MSERR_UNSUPPORT_PROTOCOL_TYPE, "unsupport protocol type"},
44     {MSERR_UNSUPPORT_VID_DEC_TYPE, "unsupport video decoder type"},
45     {MSERR_UNSUPPORT_AUD_DEC_TYPE, "unsupport audio decoder type"},
46     {MSERR_AUD_ENC_FAILED, "audio encode failed"},
47     {MSERR_VID_ENC_FAILED, "video encode failed"},
48     {MSERR_AUD_DEC_FAILED, "audio decode failed"},
49     {MSERR_VID_DEC_FAILED, "video decode failed"},
50     {MSERR_MUXER_FAILED, "stream muxer failed"},
51     {MSERR_DEMUXER_FAILED, "stream demuxer or parser failed"},
52     {MSERR_OPEN_FILE_FAILED, "open file failed"},
53     {MSERR_FILE_ACCESS_FAILED, "read or write file failed"},
54     {MSERR_START_FAILED, "audio or video start failed"},
55     {MSERR_PAUSE_FAILED, "audio or video pause failed"},
56     {MSERR_STOP_FAILED, "audio or video stop failed"},
57     {MSERR_SEEK_FAILED, "audio or video seek failed"},
58     {MSERR_NETWORK_TIMEOUT, "network timeout"},
59     {MSERR_NOT_FIND_CONTAINER, "not find a demuxer"},
60     {MSERR_EXTEND_START, "extend start error code"},
61 };
62 
63 const std::map<MediaServiceErrCode, MediaServiceExtErrCode> MSERRCODE_TO_EXTERRORCODE = {
64     {MSERR_OK,                                  MSERR_EXT_OK},
65     {MSERR_NO_MEMORY,                           MSERR_EXT_NO_MEMORY},
66     {MSERR_INVALID_OPERATION,                   MSERR_EXT_OPERATE_NOT_PERMIT},
67     {MSERR_INVALID_VAL,                         MSERR_EXT_INVALID_VAL},
68     {MSERR_UNKNOWN,                             MSERR_EXT_UNKNOWN},
69     {MSERR_SERVICE_DIED,                        MSERR_EXT_SERVICE_DIED},
70     {MSERR_CREATE_REC_ENGINE_FAILED,            MSERR_EXT_UNKNOWN},
71     {MSERR_CREATE_PLAYER_ENGINE_FAILED,         MSERR_EXT_UNKNOWN},
72     {MSERR_INVALID_STATE,                       MSERR_EXT_INVALID_STATE},
73     {MSERR_UNSUPPORT,                           MSERR_EXT_UNSUPPORT},
74     {MSERR_UNSUPPORT_AUD_SRC_TYPE,              MSERR_EXT_UNSUPPORT},
75     {MSERR_UNSUPPORT_AUD_SAMPLE_RATE,           MSERR_EXT_UNSUPPORT},
76     {MSERR_UNSUPPORT_AUD_CHANNEL_NUM,           MSERR_EXT_UNSUPPORT},
77     {MSERR_UNSUPPORT_AUD_ENC_TYPE,              MSERR_EXT_UNSUPPORT},
78     {MSERR_UNSUPPORT_AUD_PARAMS,                MSERR_EXT_UNSUPPORT},
79     {MSERR_UNSUPPORT_VID_SRC_TYPE,              MSERR_EXT_UNSUPPORT},
80     {MSERR_UNSUPPORT_VID_ENC_TYPE,              MSERR_EXT_UNSUPPORT},
81     {MSERR_UNSUPPORT_VID_PARAMS,                MSERR_EXT_UNSUPPORT},
82     {MSERR_UNSUPPORT_CONTAINER_TYPE,            MSERR_EXT_UNSUPPORT},
83     {MSERR_UNSUPPORT_PROTOCOL_TYPE,             MSERR_EXT_UNSUPPORT},
84     {MSERR_UNSUPPORT_VID_DEC_TYPE,              MSERR_EXT_UNSUPPORT},
85     {MSERR_UNSUPPORT_AUD_DEC_TYPE,              MSERR_EXT_UNSUPPORT},
86     {MSERR_AUD_ENC_FAILED,                      MSERR_EXT_UNKNOWN},
87     {MSERR_VID_ENC_FAILED,                      MSERR_EXT_UNKNOWN},
88     {MSERR_AUD_DEC_FAILED,                      MSERR_EXT_UNKNOWN},
89     {MSERR_VID_DEC_FAILED,                      MSERR_EXT_UNKNOWN},
90     {MSERR_MUXER_FAILED,                        MSERR_EXT_UNKNOWN},
91     {MSERR_DEMUXER_FAILED,                      MSERR_EXT_UNKNOWN},
92     {MSERR_OPEN_FILE_FAILED,                    MSERR_EXT_UNKNOWN},
93     {MSERR_FILE_ACCESS_FAILED,                  MSERR_EXT_UNKNOWN},
94     {MSERR_START_FAILED,                        MSERR_EXT_UNKNOWN},
95     {MSERR_PAUSE_FAILED,                        MSERR_EXT_UNKNOWN},
96     {MSERR_STOP_FAILED,                         MSERR_EXT_UNKNOWN},
97     {MSERR_SEEK_FAILED,                         MSERR_EXT_UNKNOWN},
98     {MSERR_NETWORK_TIMEOUT,                     MSERR_EXT_TIMEOUT},
99     {MSERR_NOT_FIND_CONTAINER,                  MSERR_EXT_UNSUPPORT},
100     {MSERR_EXTEND_START,                        MSERR_EXT_EXTEND_START},
101 };
102 
103 const std::map<MediaServiceExtErrCode, std::string> MSEXTERRCODE_INFOS = {
104     {MSERR_EXT_OK, "success"},
105     {MSERR_EXT_NO_MEMORY, "no memory"},
106     {MSERR_EXT_OPERATE_NOT_PERMIT, "opertation not be permitted"},
107     {MSERR_EXT_INVALID_VAL, "invalid argument"},
108     {MSERR_EXT_IO, "IO error"},
109     {MSERR_EXT_TIMEOUT, "network timeout"},
110     {MSERR_EXT_UNKNOWN, "unkown error"},
111     {MSERR_EXT_SERVICE_DIED, "media service died"},
112     {MSERR_EXT_INVALID_STATE, "the state is not support this operation"},
113     {MSERR_EXT_UNSUPPORT, "unsupport interface"},
114     {MSERR_EXT_EXTEND_START, "extend err start"},
115 };
116 
MSErrorToString(MediaServiceErrCode code)117 std::string MSErrorToString(MediaServiceErrCode code)
118 {
119     if (MSERRCODE_INFOS.count(code) != 0) {
120         return MSERRCODE_INFOS.at(code);
121     }
122 
123     if (code > MSERR_EXTEND_START) {
124         return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
125     }
126 
127     return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
128 }
129 
MSExtErrorToString(MediaServiceExtErrCode code)130 std::string MSExtErrorToString(MediaServiceExtErrCode code)
131 {
132     if (MSEXTERRCODE_INFOS.count(code) != 0) {
133         return MSEXTERRCODE_INFOS.at(code);
134     }
135 
136     if (code > MSERR_EXT_EXTEND_START) {
137         return "extend error:" + std::to_string(static_cast<int32_t>(code - MSERR_EXTEND_START));
138     }
139 
140     return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
141 }
142 
MSErrorToExtErrorString(MediaServiceErrCode code)143 std::string MSErrorToExtErrorString(MediaServiceErrCode code)
144 {
145     if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
146         MediaServiceExtErrCode extCode = MSERRCODE_TO_EXTERRORCODE.at(code);
147         if (MSEXTERRCODE_INFOS.count(extCode) != 0) {
148             return MSEXTERRCODE_INFOS.at(extCode);
149         }
150     }
151 
152     return "unkown error";
153 }
154 
MSErrorToExtError(MediaServiceErrCode code)155 MediaServiceExtErrCode MSErrorToExtError(MediaServiceErrCode code)
156 {
157     if (MSERRCODE_INFOS.count(code) != 0 && MSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
158         return MSERRCODE_TO_EXTERRORCODE.at(code);
159     }
160 
161     return MSERR_EXT_UNKNOWN;
162 }
163 } // namespace Media
164 } // namespace OHOS
165