1 /*! 2 * \copy 3 * Copyright (c) 2008-2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * 32 * decoder_core.h 33 * 34 * Abstract 35 * Encapsulative core interfaces 36 * 37 * History 38 * 07/10/2008 Created 39 * 40 *****************************************************************************/ 41 #ifndef WELS_DECODER_CORE_H__ 42 #define WELS_DECODER_CORE_H__ 43 44 #include "typedefs.h" 45 #include "wels_common_basis.h" 46 #include "decoder_context.h" 47 48 #include "codec_def.h" 49 50 namespace WelsDec { 51 /* 52 * InitBsBuffer 53 * Memory allocation for Bitstream Buffer 54 * return: 55 * 0 - success; otherwise returned error_no defined in error_no.h. 56 */ 57 int32_t InitBsBuffer (PWelsDecoderContext pCtx); 58 59 /* 60 * ExpandBsBuffer 61 * Expand current BS buffer and copy its content 62 * new buffer size will consider input size as a reference 63 * return: 64 * 0 - success; otherwise returned error_no defined in error_no.h. 65 */ 66 int32_t ExpandBsBuffer (PWelsDecoderContext pCtx, const int32_t kiSrcLen); 67 68 /* 69 * ExpandBsLenBuffer 70 * Expand current BS length buffer to double size or maximum, due to max slice number exceeding 71 * Parameter: 72 * kiCurrLen: current value of total nal number (including non-VCL nal) 73 * return: 74 * 0 - success; otherwise returned error_no defined in error_no.h. 75 */ 76 int32_t ExpandBsLenBuffer (PWelsDecoderContext pCtx, const int32_t kiCurrLen); 77 78 /* 79 * CheckBsBuffer 80 * Check if current buffer size is enough 81 */ 82 int32_t CheckBsBuffer (PWelsDecoderContext pCtx, const int32_t kiSrcLen); 83 84 /* 85 * WelsInitStaticMemory 86 * Memory request for introduced data at decoder start 87 * Especially for: 88 * rbsp_au_buffer, cur_dq_layer_ptr and ref_dq_layer_ptr in MB info cache. 89 * return: 90 * 0 - success; otherwise returned error_no defined in error_no.h. 91 */ 92 int32_t WelsInitStaticMemory (PWelsDecoderContext pCtx); 93 94 /* 95 * WelsFreeStaticMemory 96 * Free memory introduced in WelsInitStaticMemory at destruction of decoder. 97 * 98 */ 99 void WelsFreeStaticMemory (PWelsDecoderContext pCtx); 100 101 /*! 102 * \brief request memory when maximal picture width and height are available 103 */ 104 int32_t InitialDqLayersContext (PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight); 105 106 /*! 107 * \brief free dq layer context memory related 108 */ 109 void UninitialDqLayersContext (PWelsDecoderContext pCtx); 110 111 /* 112 * DecodeNalHeaderExt 113 * Trigger condition: NAL_UNIT_TYPE = NAL_UNIT_PREFIX or NAL_UNIT_CODED_SLICE_EXT 114 * Parameter: 115 * pNal: target NALUnit ptr 116 * pSrc: NAL Unit bitstream 117 */ 118 void DecodeNalHeaderExt (PNalUnit pNal, uint8_t* pSrc); 119 120 /* 121 * ParseSliceHeaderSyntaxs 122 * Parse slice header of bitstream 123 */ 124 int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, const bool kbExtensionFlag); 125 /* 126 * Copy relative syntax elements of NALUnitHeaderExt, sRefPicBaseMarking and bStoreRefBasePicFlag in prefix nal unit. 127 * pSrc: mark as decoded prefix NAL 128 * pDst: succeeded VCL NAL based AVC (I/P Slice) 129 */ 130 bool PrefetchNalHeaderExtSyntax (PWelsDecoderContext pCtx, PNalUnit const kpDst, PNalUnit const kpSrc); 131 132 /* 133 * WelsDecodeInitAccessUnitStart 134 * check and (re)allocate picture buffers on new sequence begin 135 * bit_len: size in bit length of data 136 * buf_len: size in byte length of data 137 * coded_au: mark an Access Unit decoding finished 138 * return: 139 * 0 - success; otherwise returned error_no defined in error_no.h 140 */ 141 int32_t WelsDecodeInitAccessUnitStart (PWelsDecoderContext pCtx, SBufferInfo* pDstInfo); 142 /* 143 * AllocPicBuffOnNewSeqBegin 144 * check and (re)allocate picture buffers on new sequence begin 145 * return: 146 * 0 - success; otherwise returned error_no defined in error_no.h 147 */ 148 int32_t AllocPicBuffOnNewSeqBegin (PWelsDecoderContext pCtx); 149 150 /* 151 * InitConstructAccessUnit 152 * Init before constructing an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to 153 * joint a collective access unit. 154 * parameter\ 155 * SBufferInfo: Buffer info 156 * return: 157 * 0 - success; otherwise returned error_no defined in error_no.h 158 */ 159 int32_t InitConstructAccessUnit (PWelsDecoderContext pCtx, SBufferInfo* pDstInfo); 160 161 /* 162 * ConstructAccessUnit 163 * construct an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to 164 * joint a collective access unit. 165 * parameter\ 166 * buf: bitstream data buffer 167 * bit_len: size in bit length of data 168 * buf_len: size in byte length of data 169 * coded_au: mark an Access Unit decoding finished 170 * return: 171 * 0 - success; otherwise returned error_no defined in error_no.h 172 */ 173 int32_t ConstructAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo); 174 175 176 /* 177 * DecodeCurrentAccessUnit 178 * Decode current access unit when current AU is completed. 179 */ 180 int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo); 181 182 /* 183 * Check if frame is completed and EC is required 184 */ 185 bool CheckAndFinishLastPic (PWelsDecoderContext pCtx, uint8_t** pDst, SBufferInfo* pDstInfo); 186 /* 187 * Prepare current dq layer context initialization. 188 */ 189 void WelsDqLayerDecodeStart (PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pSps, PPps pPps); 190 191 192 int32_t WelsDecodeAccessUnitStart (PWelsDecoderContext pCtx); 193 void WelsDecodeAccessUnitEnd (PWelsDecoderContext pCtx); 194 void DecodeFinishUpdate (PWelsDecoderContext pCtx); 195 196 void ForceResetCurrentAccessUnit (PAccessUnit pAu); 197 void ForceClearCurrentNal (PAccessUnit pAu); 198 199 bool CheckRefPicturesComplete (PWelsDecoderContext pCtx); // Check whether all ref pictures are complete 200 201 void ForceResetParaSetStatusAndAUList (PWelsDecoderContext pCtx); 202 } // namespace WelsDec 203 204 #endif//WELS_DECODER_CORE_H__ 205 206 207