1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /** 19 This file contains application function interfaces to the AVC decoder library 20 and necessary type defitionitions and enumerations. 21 @publishedAll 22 */ 23 24 #ifndef _AVCDEC_API_H_ 25 #define _AVCDEC_API_H_ 26 27 #include "avcapi_common.h" 28 29 /** 30 This enumeration is used for the status returned from the library interface. 31 */ 32 typedef enum 33 { 34 /** 35 The followings are fail with details. Their values are negative. 36 */ 37 AVCDEC_NO_DATA = -4, 38 AVCDEC_PACKET_LOSS = -3, 39 /** 40 Fail information 41 */ 42 AVCDEC_NO_BUFFER = -2, /* no output picture buffer available */ 43 AVCDEC_MEMORY_FAIL = -1, /* memory allocation failed */ 44 AVCDEC_FAIL = 0, 45 /** 46 Generic success value 47 */ 48 AVCDEC_SUCCESS = 1, 49 AVCDEC_PICTURE_OUTPUT_READY = 2, 50 AVCDEC_PICTURE_READY = 3, 51 52 /** 53 The followings are success with warnings. Their values are positive integers. 54 */ 55 AVCDEC_NO_NEXT_SC = 4, 56 AVCDEC_REDUNDANT_FRAME = 5, 57 AVCDEC_CONCEALED_FRAME = 6 /* detect and conceal the error */ 58 } AVCDec_Status; 59 60 61 /** 62 This structure contains sequence parameters information. 63 */ 64 typedef struct tagAVCDecSPSInfo 65 { 66 int FrameWidth; 67 int FrameHeight; 68 uint frame_only_flag; 69 int frame_crop_left; 70 int frame_crop_right; 71 int frame_crop_top; 72 int frame_crop_bottom; 73 74 } AVCDecSPSInfo; 75 76 77 #ifdef __cplusplus 78 extern "C" 79 { 80 #endif 81 /** THE FOLLOWINGS ARE APIS */ 82 /** 83 This function parses one NAL unit from byte stream format input according to Annex B. 84 \param "bitstream" "Pointer to the bitstream buffer." 85 \param "nal_unit" "Point to pointer and the location of the start of the first NAL unit 86 found in bitstream." 87 \param "size" "As input, the pointer to the size of bitstream in bytes. As output, 88 the value is changed to be the size of the found NAL unit." 89 \return "AVCDEC_SUCCESS if success, AVCDEC_FAIL if no first start code is found, AVCDEC_NO_NEX_SC if 90 the first start code is found, but the second start code is missing (potential partial NAL)." 91 */ 92 OSCL_IMPORT_REF AVCDec_Status PVAVCAnnexBGetNALUnit(uint8 *bitstream, uint8 **nal_unit, int *size); 93 94 /** 95 This function sniffs the nal_unit_type such that users can call corresponding APIs. 96 \param "bitstream" "Pointer to the beginning of a NAL unit (start with forbidden_zero_bit, etc.)." 97 \param "size" "size of the bitstream (NumBytesInNALunit + 1)." 98 \param "nal_unit_type" "Pointer to the return value of nal unit type." 99 \return "AVCDEC_SUCCESS if success, AVCDEC_FAIL otherwise." 100 */ 101 OSCL_IMPORT_REF AVCDec_Status PVAVCDecGetNALType(uint8 *bitstream, int size, int *nal_type, int *nal_ref_idc); 102 103 /** 104 This function decodes the sequence parameters set, initializes related parameters and 105 allocates memory (reference frames list), must also be compliant with Annex A. 106 It is equivalent to decode VOL header of MPEG4. 107 \param "avcHandle" "Handle to the AVC decoder library object." 108 \param "nal_unit" "Pointer to the buffer containing single NAL unit. 109 The content will change due to EBSP-to-RBSP conversion." 110 \param "nal_size" "size of the bitstream NumBytesInNALunit." 111 \return "AVCDEC_SUCCESS if success, 112 AVCDEC_FAIL if profile and level is not supported, 113 AVCDEC_MEMORY_FAIL if memory allocations return null." 114 */ 115 OSCL_IMPORT_REF AVCDec_Status PVAVCDecSeqParamSet(AVCHandle *avcHandle, uint8 *nal_unit, int nal_size); 116 117 /** 118 This function returns sequence parameters such as dimension and field flag of the most recently 119 decoded SPS. More can be added later or grouped together into a structure. This API can be called 120 after PVAVCInitSequence. If no sequence parameter has been decoded yet, it will return AVCDEC_FAIL. 121 122 \param "avcHandle" "Handle to the AVC decoder library object." 123 \param "seqInfo" "Pointer to the AVCDecSeqParamInfo structure." 124 \return "AVCDEC_SUCCESS if success and AVCDEC_FAIL if fail." 125 \note "This API can be combined with PVAVCInitSequence if wanted to be consistent with m4vdec lib." 126 */ 127 OSCL_IMPORT_REF AVCDec_Status PVAVCDecGetSeqInfo(AVCHandle *avcHandle, AVCDecSPSInfo *seqInfo); 128 129 /** 130 This function decodes the picture parameters set and initializes related parameters. Note thate 131 the PPS may not be present for every picture. 132 \param "avcHandle" "Handle to the AVC decoder library object." 133 \param "nal_unit" "Pointer to the buffer containing single NAL unit. 134 The content will change due to EBSP-to-RBSP conversion." 135 \param "nal_size" "size of the bitstream NumBytesInNALunit." 136 \return "AVCDEC_SUCCESS if success, AVCDEC_FAIL if profile and level is not supported." 137 */ 138 OSCL_IMPORT_REF AVCDec_Status PVAVCDecPicParamSet(AVCHandle *avcHandle, uint8 *nal_unit, int nal_size); 139 140 /** 141 This function decodes one NAL unit of bitstream. The type of nal unit is one of the 142 followings, 1, 5. (for now, no data partitioning, type 2,3,4). 143 \param "avcHandle" "Handle to the AVC decoder library object." 144 \param "nal_unit" "Pointer to the buffer containing a single or partial NAL unit. 145 The content will change due to EBSP-to-RBSP conversion." 146 \param "buf_size" "Size of the buffer (less than or equal nal_size)." 147 \param "nal_size" "size of the current NAL unit NumBytesInNALunit." 148 \return "AVCDEC_PICTURE_READY for success and an output is ready, 149 AVCDEC_SUCCESS for success but no output is ready, 150 AVCDEC_PACKET_LOSS is GetData returns AVCDEC_PACKET_LOSS, 151 AVCDEC_FAIL if syntax error is detected, 152 AVCDEC_MEMORY_FAIL if memory is corrupted. 153 AVCDEC_NO_PICTURE if no frame memory to write to (users need to get output and/or return picture). 154 AVCDEC_REDUNDANT_PICTURE if error has been detected in the primary picture and redundant picture is available, 155 AVCDEC_CONCEALED_PICTURE if error has been detected and decoder has concealed it." 156 */ 157 OSCL_IMPORT_REF AVCDec_Status PVAVCDecSEI(AVCHandle *avcHandle, uint8 *nal_unit, int nal_size); 158 159 OSCL_IMPORT_REF AVCDec_Status PVAVCDecodeSlice(AVCHandle *avcHandle, uint8 *buffer, int buf_size); 160 161 /** 162 Check the availability of the decoded picture in decoding order (frame_num). 163 The AVCFrameIO also provide displaying order information such that the application 164 can re-order the frame for display. A picture can be retrieved only once. 165 \param "avcHandle" "Handle to the AVC decoder library object." 166 \param "output" "Pointer to the AVCOutput structure. Note that decoder library will 167 not re-used the pixel memory in this structure until it has been returned 168 thru PVAVCReleaseOutput API." 169 \return "AVCDEC_SUCCESS for success, AVCDEC_FAIL if no picture is available to be displayed, 170 AVCDEC_PICTURE_READY if there is another picture to be displayed." 171 */ 172 OSCL_IMPORT_REF AVCDec_Status PVAVCDecGetOutput(AVCHandle *avcHandle, int *indx, int *release_flag, AVCFrameIO *output); 173 174 /** 175 This function resets the decoder and expects to see the next IDR slice. 176 \param "avcHandle" "Handle to the AVC decoder library object." 177 */ 178 OSCL_IMPORT_REF void PVAVCDecReset(AVCHandle *avcHandle); 179 180 /** 181 This function performs clean up operation including memory deallocation. 182 \param "avcHandle" "Handle to the AVC decoder library object." 183 */ 184 OSCL_IMPORT_REF void PVAVCCleanUpDecoder(AVCHandle *avcHandle); 185 //AVCDec_Status EBSPtoRBSP(uint8 *nal_unit,int *size); 186 187 188 189 /** CALLBACK FUNCTION TO BE IMPLEMENTED BY APPLICATION */ 190 /** In AVCHandle structure, userData is a pointer to an object with the following 191 member functions. 192 */ 193 AVCDec_Status CBAVCDec_GetData(uint32 *userData, unsigned char **buffer, unsigned int *size); 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif /* _AVCDEC_API_H_ */ 200 201