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 #ifndef _BITSTREAM_D_H_ 20 #define _BITSTREAM_D_H_ 21 22 #include "mp4dec_lib.h" /* video decoder function prototypes */ 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif /* __cplusplus */ 28 29 #define PV_BS_INLINE /* support inline bitstream functions */ 30 31 #define PV_BitstreamFlushBits(A,B) {(A)->bitcnt += (B); (A)->incnt -= (B); (A)->curr_word <<= (B);} 32 33 PV_STATUS BitstreamFillBuffer(BitstreamDecVideo *stream); 34 PV_STATUS BitstreamFillCache(BitstreamDecVideo *stream); 35 void BitstreamReset(BitstreamDecVideo *stream, uint8 *buffer, int32 buffer_size); 36 int BitstreamOpen(BitstreamDecVideo *stream, int layer); 37 void BitstreamClose(BitstreamDecVideo *stream); 38 39 PV_STATUS BitstreamShowBits32(BitstreamDecVideo *stream, int nbits, uint32 *code); 40 uint32 BitstreamReadBits32(BitstreamDecVideo *stream, int nbits); 41 42 uint BitstreamReadBits16(BitstreamDecVideo *stream, int nbits); 43 uint BitstreamRead1Bits(BitstreamDecVideo *stream); 44 #ifndef PV_BS_INLINE 45 PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code); 46 PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code); 47 PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code); 48 uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits); 49 uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream); 50 #else BitstreamShowBits16(BitstreamDecVideo * stream,int nbits,uint * code)51 __inline PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code) 52 { 53 PV_STATUS status = PV_SUCCESS; 54 55 56 if (stream->incnt < nbits) 57 { 58 /* frame-based decoding */ 59 status = BitstreamFillCache(stream); 60 } 61 62 *code = stream->curr_word >> (32 - nbits); 63 return status; 64 } 65 66 67 68 /* =========================================================================*/ BitstreamShow15Bits(BitstreamDecVideo * stream,uint * code)69 __inline PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code) 70 { 71 PV_STATUS status = PV_SUCCESS; 72 73 if (stream->incnt < 15) 74 { 75 /* frame-based decoding */ 76 status = BitstreamFillCache(stream); 77 } 78 *code = stream->curr_word >> 17; 79 return status; 80 } 81 82 BitstreamShow13Bits(BitstreamDecVideo * stream,uint * code)83 __inline PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code) 84 { 85 PV_STATUS status = PV_SUCCESS; 86 87 if (stream->incnt < 13) 88 { 89 /* frame-based decoding */ 90 status = BitstreamFillCache(stream); 91 } 92 *code = stream->curr_word >> 19; 93 return status; 94 } BitstreamReadBits16_INLINE(BitstreamDecVideo * stream,int nbits)95 __inline uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits) 96 { 97 uint code; 98 99 if (stream->incnt < nbits) 100 { 101 /* frame-based decoding */ 102 BitstreamFillCache(stream); 103 } 104 code = stream->curr_word >> (32 - nbits); 105 PV_BitstreamFlushBits(stream, nbits); 106 return code; 107 } 108 109 BitstreamRead1Bits_INLINE(BitstreamDecVideo * stream)110 __inline uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream) 111 { 112 uint code; 113 114 if (stream->incnt < 1) 115 { 116 /* frame-based decoding */ 117 BitstreamFillCache(stream); 118 } 119 code = stream->curr_word >> 31; 120 PV_BitstreamFlushBits(stream, 1); 121 122 return code; 123 } 124 125 #endif 126 127 128 129 130 131 132 133 PV_STATUS PV_BitstreamFlushBitsCheck(BitstreamDecVideo *stream, int nbits); 134 135 uint32 BitstreamReadBits32HC(BitstreamDecVideo *stream); 136 PV_STATUS BitstreamShowBits32HC(BitstreamDecVideo *stream, uint32 *code); 137 138 139 140 PV_STATUS BitstreamCheckEndBuffer(BitstreamDecVideo *stream); 141 142 PV_STATUS PV_BitstreamShowBitsByteAlign(BitstreamDecVideo *stream, int nbits, uint32 *code); 143 #ifdef PV_ANNEX_IJKT_SUPPORT 144 PV_STATUS PV_BitstreamShowBitsByteAlignNoForceStuffing(BitstreamDecVideo *stream, int nbits, uint32 *code); 145 Bool validStuffing_h263(BitstreamDecVideo *stream); 146 PV_STATUS quickSearchH263SliceHeader(BitstreamDecVideo *stream); 147 #endif 148 PV_STATUS PV_BitstreamByteAlign(BitstreamDecVideo *stream); 149 PV_STATUS BitstreamByteAlignNoForceStuffing(BitstreamDecVideo *stream); 150 Bool validStuffing(BitstreamDecVideo *stream); 151 152 PV_STATUS movePointerTo(BitstreamDecVideo *stream, int32 pos); 153 PV_STATUS PVSearchNextM4VFrame(BitstreamDecVideo *stream); 154 PV_STATUS PVSearchNextH263Frame(BitstreamDecVideo *stream); 155 PV_STATUS quickSearchVideoPacketHeader(BitstreamDecVideo *stream, int marker_length); 156 157 158 /* for error concealment & soft-decoding */ 159 void PVLocateM4VFrameBoundary(BitstreamDecVideo *stream); 160 void PVSearchH263FrameBoundary(BitstreamDecVideo *stream); 161 162 PV_STATUS quickSearchMotionMarker(BitstreamDecVideo *stream); 163 PV_STATUS quickSearchDCM(BitstreamDecVideo *stream); 164 PV_STATUS quickSearchGOBHeader(BitstreamDecVideo *stream); 165 void BitstreamShowBuffer(BitstreamDecVideo *stream, int32 startbit, int32 endbit, uint8 *bitBfr); 166 167 /* 10/8/98 New prototyps. */ 168 int32 getPointer(BitstreamDecVideo *stream); 169 170 #ifdef __cplusplus 171 } 172 #endif /* __cplusplus */ 173 174 #endif /* _BITSTREAM_D_H_ */ 175