1 /*
2 * h263-decoder.h --
3 *
4 * H.263 bitstream decoder header file.
5 *
6 * Copyright (c) 2002-2002 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * A. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * B. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * C. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * @(#) $Header: /usr/mash/src/repository/mash/mash-1/codec/h263-new/h263-decoder.h,v 1.2 2003/06/14 19:12:19 larry Exp $
34 */
35
36 #include <sys/types.h>
37
38 /* included from h263.h */
39 /*
40 * Mode A packets do not contain a GOB number in the RTP header. For mode A
41 * packets, we pass these values as the GOB number to indicate whether the
42 * previous packet was received.
43 */
44 #define SEQUENTIAL_PACKET -1
45 #define NONSEQUENTIAL_PACKET -2
46
47 /*
48 * These are the maximum possible numbers of GOBs and macroblocks in the
49 * standard H.263 picture formats.
50 */
51 #define MAX_NUM_GOBS 24
52 #define MAX_NUM_MBS_IN_ROW 88
53
54 /*
55 * These are the numbers of GOBs and macroblocks to allocate for efficient data
56 * structures. The number of macroblocks in a row is padded to allow for
57 * macroblocks outside the picture (at the left and right sides). The other
58 * numbers are rounded up to the nearest power of 2.
59 */
60 #define NUM_GOBS_ALLOC 32
61 #define NUM_MBS_IN_ROW_ALLOC (MAX_NUM_MBS_IN_ROW + 2)
62 #define NUM_MBS_ALLOC 512
63
64 struct huffcode;
65
66 class H263BitstreamDecoder {
67 public:
68 H263BitstreamDecoder();
69 virtual ~H263BitstreamDecoder();
70 u_char* frame() const { return (back_); }
71
72 // ndblk() returns the number of blocks decoded. The H263 codec counts
73 // macroblocks, though. Therefore we have to multiply times the number
74 // of blocks per macroblock (6, i.e. 4Y, 1U, and 1V)
75 inline int ndblk() const { return (6*ndmblk_); }
76 inline void resetndblk() { ndmblk_ = 0; }
77
78 inline int width() const { return (width_); }
79 inline int height() const { return (height_); }
80 inline int ngob() const { return (ngob_); }
81 void H263BitstreamDecoder::print_mb(int gob, int mba, u_char *p);
82
83 virtual int decode(const u_char* bp, int cc,
84 int sbit, int ebit, int mba, int gob, int quant,
85 int mvdh1, int mvdv1, int mvdh2, int mvdv2,
86 int fflag, int pflag);
87 virtual void sync();
88 inline void bb(int& x, int& y, int& w, int& h) {
89 x = bbx_; y = bby_; w = bbw_; h = bbh_;
90 };
91 inline u_int bad_psc() const { return (bad_psc_); }
92 inline u_int bad_bits() const { return (bad_bits_); }
93 inline u_int bad_GOBno() const { return (bad_GOBno_); }
94 inline u_int bad_fmt() const { return (bad_fmt_); }
95 inline int seenMaxGob() const { return (maxgob_ >= ngob_ - 1); }
96 inline u_int gobquant() const { return (gobquant_); }
97
98 inline void marks(u_char* p) { marks_ = p; }
99 inline void mark(int v) { mark_ = v; }
100 protected:
101 void dump(int indent, const char *format, ...) const;
102 void init();
103 virtual void allocate();
104 void inithuff();
105 void initquant();
106 virtual void err(const char* msg ...) const;
107 int quantize(int v, int q);
108 void filter(u_char* in, u_char* out, u_int stride);
109 void mvblk(u_char* in, u_char* out, u_int stride);
110 void mvblka(u_char*, u_char*, u_int stride);
111
112 int parse_sc(int &gob);
113 int parse_picture_hdr();
114 int parse_gob_hdr(int &gfid);
115 int parse_mb_hdr(u_int &cbp);
116 int decode_mb();
117 #ifdef INT_64
118 int parse_block(bool tc, short *blk, INT_64 *mask);
119 #else
120 int parse_block(bool tc, short *blk, u_int *mask);
121 #endif
122 void decode_block(bool tc, u_int x, u_int y, u_int stride,
123 u_char *front, u_char *back, int sf);
124
125 void mbcopy(u_int x, u_int y);
126 void swap();
127
128 bool picture_started_;
129
130 u_int size_;
131 u_char* fs_;
132 u_char* front_;
133 u_char* back_;
134
135 struct hufftab {
136 int maxlen;
137 const short* prefix;
138 };
139 hufftab h263_ht_mtype_i_;
140 hufftab h263_ht_mtype_p_;
141 hufftab h263_ht_cbpy_i_;
142 hufftab h263_ht_cbpy_p_;
143 hufftab h263_ht_mba_;
144 hufftab h263_ht_mvd_;
145 hufftab h263_ht_tcoeff_;
146
147 u_int bb_; /* 32-bit bit buffer */
148 int nbb_; /* number bits in bit buffer */
149 const u_short* bs_; /* input bit stream (less bits in bb_) */
150 const u_short* es_; /* pointer to end if input stream */
151 const u_short* ps_; /* packet start (for error reporting) */
152 int pebit_; /* packet end bit (for error reporting) */
153
154 #define MBST_FRESH 0
155 #define MBST_OLD 1
156 #define MBST_NEW 2
157 u_char* mbst_;
158 short* qt_;
159 u_short* coord_;
160
161 #define FMT_FORBIDDEN 0
162 #define FMT_SUBQCIF 1
163 #define FMT_QCIF 2
164 #define FMT_CIF 3
165 #define FMT_4CIF 4
166 #define FMT_16CIF 5
167 #define FMT_RESERVED 6
168 #define FMT_EXTENDED 7
169 u_int fmt_; /* source format */
170 #define PCT_INTRA 0
171 #define PCT_INTER 1
172 u_int pct_; /* picture coding type */
173 u_int opptype_; /* Optional PLUSPTYPE flags */
174 u_int mpptype_; /* Mandatory PLUSPTYPE flags */
175
176 #define PAR_FORBIDDEN 0;
177 #define PAR_SQUARE_1_1 1;
178 #define PAR_CIF_4_3 2;
179 #define PAR_525_4_3 3;
180 #define PAR_CIF_16_9 4;
181 #define PAR_525_16_9 5;
182 #define PAR_EXTENDED 15;
183 u_int par_; /* pixel aspect ratio for custom picture formats */
184 u_int pwi_; /* pixel width indication for custom picture formats */
185 u_int phi_; /* pixel height indication for custom picture formats */
186 u_int epar_width_; /* extended PAR width */
187 u_int epar_height_; /* extended PAR height */
188
189 int frame_id_; /* frame id */
190
191 u_int width_; /* width of Y component */
192 u_int height_; /* height of Y component */
193 u_int last_width_;
194 u_int last_height_;
195
196 u_int ngob_; /* number of gobs */
197 u_int maxgob_; /* max gob seen this frame */
198 u_int nrowingob_; /* number of rows in a gob */
199 u_int nmbinrow_; /* number of macroblocks in a row */
200 u_int nmbingob_; /* number of macroblocks in a row */
201 u_int nmb_; /* total number of macroblocks in picture */
202 int ndmblk_; /* number of decoded macroblocks. As H.263
203 is always 4:2:0, one macroblock is composed
204 of 6 8x8-pixels blocks, 4 Y, 1 U, and 1 V */
205 u_int gobquant_; /* last gob quantizer (for info funtion) */
206
207 u_int mt_; /* macroblock type (flags in h263-huff.h) */
208 u_int gob_; /* current gob index */
209 u_int mba_; /* macroblock address */
210 u_int blk_; /* block number */
211 u_int dumplevel_; /* dynamic debugging info flag */
212 int ifn_; /* i-frame # (debugging) */
213 u_int pfn_; /* p-frame # (debugging) */
214
215 /* bounding box */
216 u_int minx_;
217 u_int miny_;
218 u_int maxx_;
219 u_int maxy_;
220 u_int bbx_;
221 u_int bby_;
222 u_int bbw_;
223 u_int bbh_;
224
225 /*
226 * Table to indicate which blocks have changed.
227 */
228 u_char* marks_;
229 int mark_;
230
231 /* error counters */
232 int bad_psc_;
233 int bad_bits_;
234 int bad_GOBno_;
235 int bad_fmt_; /* # times RTP fmt != H.263 fmt */
236
237 u_char mb_state_[NUM_GOBS_ALLOC * NUM_MBS_ALLOC];
238
239 /* inverse quantization via table lookup */
240 short quant_[32 * 256];
241
242 /* motion vector candidate predictors */
243 short mvcp_[2][NUM_MBS_IN_ROW_ALLOC];
244 char *above_row_;
245 char *current_row_;
246 };
247
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.