1 /* 2 * Copyright (C) 2022 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 NATIVE_AVCODEC_VIDEODECODER_H 17 #define NATIVE_AVCODEC_VIDEODECODER_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include "native_averrors.h" 22 #include "native_avformat.h" 23 #include "native_avmemory.h" 24 #include "native_avcodec_base.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /** 31 * @brief Creates a video decoder instance from the mime type, which is recommended in most cases. 32 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 33 * @param mime mime type description string, refer to {@link AVCODEC_MIME_TYPE} 34 * @return Returns a Pointer to an OH_AVCodec instance 35 * @since 9 36 * @version 1.0 37 */ 38 OH_AVCodec *OH_VideoDecoder_CreateByMime(const char *mime); 39 40 /** 41 * @brief Create a video decoder instance through the video decoder name. 42 * The premise of using this interface is to know the exact name of the decoder. 43 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 44 * @param name video codec name 45 * @return Returns a Pointer to an OH_AVCodec instance 46 * @since 9 47 * @version 1.0 48 */ 49 OH_AVCodec *OH_VideoDecoder_CreateByName(const char *name); 50 51 /** 52 * @brief Clear the internal resources of the decoder and destroy the decoder instance 53 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 54 * @param codec Pointer to an OH_AVCodec instance 55 * @return Returns AV_ERR_OK if the execution is successful, 56 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 57 * @since 9 58 * @version 1.0 59 */ 60 OH_AVErrCode OH_VideoDecoder_Destroy(OH_AVCodec *codec); 61 62 /** 63 * @brief Set the asynchronous callback function so that your application can respond to the events 64 * generated by the video decoder. This interface must be called before Prepare is called. 65 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 66 * @param codec Pointer to an OH_AVCodec instance 67 * @param callback A collection of all callback functions, see {@link OH_AVCodecAsyncCallback} 68 * @param userData User specific data 69 * @return Returns AV_ERR_OK if the execution is successful, 70 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 71 * @since 9 72 * @version 1.0 73 */ 74 OH_AVErrCode OH_VideoDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData); 75 76 /** 77 * @brief Specify the output Surface to provide video decoding output, 78 * this interface must be called before Prepare is called 79 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 80 * @param codec Pointer to an OH_AVCodec instance 81 * @param window A pointer to a OHNativeWindow instance, see {@link OHNativeWindow} 82 * @return Returns AV_ERR_OK if the execution is successful, 83 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 84 * @since 9 85 * @version 1.0 86 */ 87 OH_AVErrCode OH_VideoDecoder_SetSurface(OH_AVCodec *codec, OHNativeWindow *window); 88 89 /** 90 * @brief To configure the video decoder, typically, you need to configure the description information of the decoded 91 * video track, which can be extracted from the container. This interface must be called before Prepare is called. 92 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 93 * @param codec Pointer to an OH_AVCodec instance 94 * @param format A pointer to an OH_AVFormat to give the description of the video track to be decoded 95 * @return Returns AV_ERR_OK if the execution is successful, 96 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 97 * @since 9 98 * @version 1.0 99 */ 100 OH_AVErrCode OH_VideoDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format); 101 102 /** 103 * @brief To prepare the internal resources of the decoder, the Configure interface must be called before 104 * calling this interface. 105 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 106 * @param codec Pointer to an OH_AVCodec instance 107 * @return Returns AV_ERR_OK if the execution is successful, 108 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 109 * @since 9 110 * @version 1.0 111 */ 112 OH_AVErrCode OH_VideoDecoder_Prepare(OH_AVCodec *codec); 113 114 /** 115 * @brief Start the decoder, this interface must be called after the Prepare is successful. 116 * After being successfully started, the decoder will start reporting NeedInputData events. 117 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 118 * @param codec Pointer to an OH_AVCodec instance 119 * @return Returns AV_ERR_OK if the execution is successful, 120 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 121 * @since 9 122 * @version 1.0 123 */ 124 OH_AVErrCode OH_VideoDecoder_Start(OH_AVCodec *codec); 125 126 /** 127 * @brief Stop the decoder. After stopping, you can re-enter the Started state through Start, 128 * but it should be noted that if Codec-Specific-Data has been input to the decoder before, it needs to be input again. 129 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 130 * @param codec Pointer to an OH_AVCodec instance 131 * @return Returns AV_ERR_OK if the execution is successful, 132 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 133 * @since 9 134 * @version 1.0 135 */ 136 OH_AVErrCode OH_VideoDecoder_Stop(OH_AVCodec *codec); 137 138 /** 139 * @brief Clear the input and output data buffered in the decoder. After this interface is called, all the Buffer 140 * indexes previously reported through the asynchronous callback will be invalidated, make sure not to access 141 * the Buffers corresponding to these indexes. 142 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 143 * @param codec Pointer to an OH_AVCodec instance 144 * @return Returns AV_ERR_OK if the execution is successful, 145 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 146 * @since 9 147 * @version 1.0 148 */ 149 OH_AVErrCode OH_VideoDecoder_Flush(OH_AVCodec *codec); 150 151 /** 152 * @brief Reset the decoder. To continue decoding, you need to call the Configure interface again 153 * to configure the decoder instance. 154 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 155 * @param codec Pointer to an OH_AVCodec instance 156 * @return Returns AV_ERR_OK if the execution is successful, 157 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 158 * @since 9 159 * @version 1.0 160 */ 161 OH_AVErrCode OH_VideoDecoder_Reset(OH_AVCodec *codec); 162 163 /** 164 * @brief Get the description information of the output data of the decoder, refer to {@link OH_AVFormat} 165 * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs 166 * to be manually released by the caller. 167 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 168 * @param codec Pointer to an OH_AVCodec instance 169 * @return Returns a pointer to an OH_AVFormat instance 170 * @since 9 171 * @version 1.0 172 */ 173 OH_AVFormat *OH_VideoDecoder_GetOutputDescription(OH_AVCodec *codec); 174 175 /** 176 * @brief Set dynamic parameters to the decoder. Note: This interface can only be called after the decoder is started. 177 * At the same time, incorrect parameter settings may cause decoding failure. 178 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 179 * @param codec Pointer to an OH_AVCodec instance 180 * @param format pointer to an OH_AVFormat instance 181 * @return Returns AV_ERR_OK if the execution is successful, 182 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 183 * @since 9 184 * @version 1.0 185 */ 186 OH_AVErrCode OH_VideoDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format); 187 188 /** 189 * @brief Submit the input buffer filled with data to the video decoder. The {@link OH_AVCodecOnNeedInputData} callback 190 * will report the available input buffer and the corresponding index value. Once the buffer with the specified index 191 * is submitted to the video decoder, the buffer cannot be accessed again until the {@link OH_AVCodecOnNeedInputData} 192 * callback is received again reporting that the buffer with the same index is available. In addition, for some 193 * decoders, it is required to input Codec-Specific-Data to the decoder at the beginning to initialize the decoding 194 * process of the decoder, such as PPS/SPS data in H264 format. 195 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 196 * @param codec Pointer to an OH_AVCodec instance 197 * @param index Enter the index value corresponding to the Buffer 198 * @param attr Information describing the data contained in the Buffer 199 * @return Returns AV_ERR_OK if the execution is successful, 200 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 201 * @since 9 202 * @version 1.0 203 */ 204 OH_AVErrCode OH_VideoDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr); 205 206 /** 207 * @brief Return the processed output Buffer to the decoder, and notify the decoder to finish rendering the 208 * decoded data contained in the Buffer on the output Surface. If the output surface is not configured before, 209 * calling this interface only returns the output buffer corresponding to the specified index to the decoder. 210 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 211 * @param codec Pointer to an OH_AVCodec instance 212 * @param index The index value corresponding to the output Buffer 213 * @return Returns AV_ERR_OK if the execution is successful, 214 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 215 * @since 9 216 * @version 1.0 217 */ 218 OH_AVErrCode OH_VideoDecoder_RenderOutputData(OH_AVCodec *codec, uint32_t index); 219 220 /** 221 * @brief Return the processed output Buffer to the decoder. 222 * @syscap SystemCapability.Multimedia.Media.VideoDecoder 223 * @param codec Pointer to an OH_AVCodec instance 224 * @param index The index value corresponding to the output Buffer 225 * @return Returns AV_ERR_OK if the execution is successful, 226 * otherwise returns a specific error code, refer to {@link OH_AVErrCode} 227 * @since 9 228 * @version 1.0 229 */ 230 OH_AVErrCode OH_VideoDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index); 231 232 #ifdef __cplusplus 233 } 234 #endif 235 236 #endif // NATIVE_AVCODEC_VIDEODECODER_H