1 /*
2  * Copyright (C) 2023 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 #ifndef MEDIA_AVCODEC_ERRORS_H
17 #define MEDIA_AVCODEC_ERRORS_H
18 
19 #include <map>
20 #include <string>
21 #include "native_averrors.h"
22 #include "errors.h"
23 #include "common/status.h"
24 
25 namespace OHOS {
26 namespace MediaAVCodec {
27 using AVCSErrCode = ErrCode;
28 
29 // bit 28~21 is subsys, bit 20~16 is Module. bit 15~0 is code
30 // confirm module offset
31 constexpr AVCSErrCode AVCS_MODULE = 10;
32 constexpr AVCSErrCode AVCS_ERR_OFFSET = ErrCodeOffset(SUBSYS_MULTIMEDIA, AVCS_MODULE);
33 typedef enum AVCodecServiceErrCode : ErrCode {
34     AVCS_ERR_OK = ERR_OK,
35     AVCS_ERR_NO_MEMORY = AVCS_ERR_OFFSET + ENOMEM,         // no memory
36     AVCS_ERR_INVALID_OPERATION = AVCS_ERR_OFFSET + ENOSYS, // opertation not be permitted
37     AVCS_ERR_INVALID_VAL = AVCS_ERR_OFFSET + EINVAL,       // invalid argument
38     AVCS_ERR_UNKNOWN = AVCS_ERR_OFFSET + 0x200,            // unkown error.
39     AVCS_ERR_SERVICE_DIED,                                 // avcodec service died
40     AVCS_ERR_INVALID_STATE,                                // the state is not support this operation.
41     AVCS_ERR_UNSUPPORT,                                    // unsupport interface.
42     AVCS_ERR_UNSUPPORT_AUD_SRC_TYPE,                       // unsupport audio source type.
43     AVCS_ERR_UNSUPPORT_AUD_SAMPLE_RATE,                    // unsupport audio sample rate.
44     AVCS_ERR_UNSUPPORT_AUD_CHANNEL_NUM,                    // unsupport audio channel.
45     AVCS_ERR_UNSUPPORT_AUD_ENC_TYPE,                       // unsupport audio encoder type.
46     AVCS_ERR_UNSUPPORT_AUD_PARAMS,                         // unsupport audio params(other params).
47     AVCS_ERR_UNSUPPORT_VID_SRC_TYPE,                       // unsupport video source type.
48     AVCS_ERR_UNSUPPORT_VID_ENC_TYPE,                       // unsupport video encoder type.
49     AVCS_ERR_UNSUPPORT_VID_PARAMS,                         // unsupport video params(other params).
50     AVCS_ERR_UNSUPPORT_FILE_TYPE,                          // unsupport file format type.
51     AVCS_ERR_UNSUPPORT_PROTOCOL_TYPE,                      // unsupport protocol type.
52     AVCS_ERR_UNSUPPORT_VID_DEC_TYPE,                       // unsupport video decoder type.
53     AVCS_ERR_UNSUPPORT_AUD_DEC_TYPE,                       // unsupport audio decoder type.
54     AVCS_ERR_UNSUPPORT_STREAM,                             // internal data stream error.
55     AVCS_ERR_UNSUPPORT_SOURCE,                             // unsupport source type.
56     AVCS_ERR_AUD_RENDER_FAILED,                            // audio render failed.
57     AVCS_ERR_AUD_ENC_FAILED,                               // audio encode failed.
58     AVCS_ERR_VID_ENC_FAILED,                               // video encode failed.
59     AVCS_ERR_AUD_DEC_FAILED,                               // audio decode failed.
60     AVCS_ERR_VID_DEC_FAILED,                               // video decode failed.
61     AVCS_ERR_MUXER_FAILED,                                 // stream avmuxer failed.
62     AVCS_ERR_DEMUXER_FAILED,                               // stream demuxer or parser failed.
63     AVCS_ERR_OPEN_FILE_FAILED,                             // open file failed.
64     AVCS_ERR_FILE_ACCESS_FAILED,                           // read or write file failed.
65     AVCS_ERR_START_FAILED,                                 // audio/video start failed.
66     AVCS_ERR_PAUSE_FAILED,                                 // audio/video pause failed.
67     AVCS_ERR_STOP_FAILED,                                  // audio/video stop failed.
68     AVCS_ERR_SEEK_FAILED,                                  // audio/video seek failed.
69     AVCS_ERR_NETWORK_TIMEOUT,                              // network timeout.
70     AVCS_ERR_NOT_FIND_FILE,                                // not find a file.
71     AVCS_ERR_DATA_SOURCE_IO_ERROR,                         // avcodec data source IO failed.
72     AVCS_ERR_DATA_SOURCE_OBTAIN_MEM_ERROR,                 // avcodec data source get mem failed.
73     AVCS_ERR_DATA_SOURCE_ERROR_UNKNOWN,                    // avcodec data source error unknow.
74     AVCS_ERR_CODEC_PARAM_INCORRECT,                        // video codec param check failed.
75 
76     AVCS_ERR_IPC_UNKNOWN,                                  // avcodec ipc unknown err.
77     AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED,            // avcodec ipc err, get sub system ability failed.
78     AVCS_ERR_IPC_SET_DEATH_LISTENER_FAILED,                // avcodec ipc err, set death listener failed.
79     AVCS_ERR_CREATE_CODECLIST_STUB_FAILED,                 // create codeclist sub service failed.
80     AVCS_ERR_CREATE_AVCODEC_STUB_FAILED,                   // create avcodec sub service failed.
81 
82     AVCS_ERR_NOT_ENOUGH_DATA,                              // avcodec output buffer not full of a pack
83     AVCS_ERR_END_OF_STREAM,                                // the end of stream
84     AVCS_ERR_CONFIGURE_MISMATCH_CHANNEL_COUNT,             // not configure channel count attribute
85     AVCS_ERR_MISMATCH_SAMPLE_RATE,                         // not configure channel sample rate
86     AVCS_ERR_MISMATCH_BIT_RATE,                            // not configure channel bit rate
87     AVCS_ERR_CONFIGURE_ERROR,                              // flac encoder configure compression level out of limit
88     AVCS_ERR_INVALID_DATA,                                 // Invalid data found when processing input
89     AVCS_ERR_DECRYPT_FAILED,                               // drm decrypt failed
90     AVCS_ERR_TRY_AGAIN,                                    // try again later
91     AVCS_ERR_INPUT_DATA_ERROR,                             // there is somthing wrong for input data
92     AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION,       // video unsupport color space conversion
93 
94     AVCS_ERR_EXTEND_START = AVCS_ERR_OFFSET + 0xF000,      // extend err start.
95 } AVCodecServiceErrCode;
96 
97 __attribute__((visibility("default"))) std::string AVCSErrorToString(AVCodecServiceErrCode code);
98 __attribute__((visibility("default"))) std::string OHAVErrCodeToString(OH_AVErrCode code);
99 __attribute__((visibility("default"))) std::string AVCSErrorToOHAVErrCodeString(AVCodecServiceErrCode code);
100 __attribute__((visibility("default"))) OH_AVErrCode AVCSErrorToOHAVErrCode(AVCodecServiceErrCode code);
101 __attribute__((visibility("default"))) AVCodecServiceErrCode StatusToAVCodecServiceErrCode(Media::Status code);
102 __attribute__((visibility("default"))) AVCodecServiceErrCode VPEErrorToAVCSError(int32_t code);
103 } // namespace MediaAVCodec
104 } // namespace OHOS
105 #endif // MEDIA_AVCODEC_ERRORS_H
106