~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/h263/h263-decoder.h

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  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/h263-decoder.h,v 1.5 2004/05/27 00:15:36 larry Exp $
 34  */
 35 
 36 #include <sys/types.h>
 37 
 38 /*
 39  * Mode A packets do not contain a GOB number in the RTP header.  For mode A
 40  * packets, we pass these values as the GOB number to indicate whether the
 41  * previous packet was received.
 42 */
 43 #define SEQUENTIAL_PACKET    -1
 44 #define NONSEQUENTIAL_PACKET -2
 45 
 46 /*
 47  * These are the maximum possible numbers of GOBs and macroblocks in the
 48  * standard H.263 picture formats.
 49 */
 50 #define MAX_NUM_GOBS       24
 51 #define MAX_NUM_MBS_IN_ROW 88
 52 
 53 /*
 54  * These are the numbers of GOBs and macroblocks to allocate for efficient data
 55  * structures.  The number of macroblocks in a row is padded to allow for
 56  * macroblocks outside the picture (at the left and right sides).  The other
 57  * numbers are rounded up to the nearest power of 2.
 58 */
 59 #define NUM_GOBS_ALLOC       32
 60 #define NUM_MBS_IN_ROW_ALLOC (MAX_NUM_MBS_IN_ROW + 2)
 61 #define NUM_MBS_ALLOC        512
 62 
 63 struct huffcode;
 64 
 65 class H263BitstreamDecoder {
 66   public:
 67         H263BitstreamDecoder();
 68         virtual ~H263BitstreamDecoder();
 69         u_char* frame() const { return (back_); }
 70 
 71         // ndblk() returns the number of blocks decoded. The H263 codec counts 
 72         //      macroblocks, though. Therefore we have to multiply times the number 
 73         //      of blocks per macroblock (6, i.e. 4Y, 1U, and 1V)
 74         inline int ndblk() const { return (6*ndmblk_); }
 75         inline void resetndblk() { ndmblk_ = 0; }
 76 
 77         inline int width() const { return (width_); }
 78         inline int height() const { return (height_); }
 79         inline int ngob() const { return (ngob_); }
 80         inline int qtidx() const { return (qtidx_); }
 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 
 97         inline void marks(u_char* p) { marks_ = p; }
 98         inline void mark(int v) { mark_ = v; }
 99         void reset_stats();
100         void dump_stats();
101 
102         /*
103          * Decoding statistics
104          */
105         u_int fn_;                      /* frame # */
106         u_int ifn_;                     /* i-frame # */
107         u_int pfn_;                     /* p-frame # */
108         u_int sump_;            /* used to compute avg #p frames between i frames */
109         u_int niblks_;          /* number of i-blocks */
110         u_int nmv_;                     /* number of motion vectors */
111         u_int n00mv_;           /* number of (0,0) motion vectors */
112         u_int nfullpelmv_;      /* number of full-pel motion vectors */
113         u_int nhalfpelmv_;      /* number of half-pel motion vectors */
114         u_int nhpmvB_;          /*   case B half-pel MV's */
115         u_int nhpmvC_;          /*   case C half-pel MV's */
116         u_int nhpmvD_;          /*   case D half-pel MV's */
117         u_int npkts_;           /* number of pkts decoded */
118   protected:
119         void dump(int indent, const char *format, ...) const;
120         void init();
121         virtual void allocate();
122         void inithuff();
123         void initquant();
124         virtual void err(const char* msg ...) const;
125         int quantize(int v, int q);
126         void filter(u_char* in, u_char* out, u_int stride);
127         void mvblk(u_char* in, u_char* out, u_int stride);
128         void mvblka(u_char*, u_char*, u_int stride);
129 
130     int parse_sc(int &gob);
131     int parse_picture_hdr();
132     int parse_gob_hdr(int &gfid);
133     int parse_mb_hdr(u_int &cbp);
134     int decode_mb();
135 #ifdef INT_64
136     int parse_block(bool tc, short *blk, INT_64 *mask);
137 #else
138     int parse_block(bool tc, short *blk, u_int *mask);
139 #endif
140     void decode_block(bool tc, u_int x, u_int y, u_int stride,
141                       u_char *front, u_char *back, int sf);
142 
143         void mbcopy(u_int x, u_int y);
144         void swap();
145 
146     bool picture_started_;
147 
148         /*
149          * Decoded frame buffer - contains two complete images
150          */
151         u_int size_;    /* size of buffer */
152         u_char* fs_;    /* pointer to buffer with two images */
153         u_char* front_; /* pointer to current image being decoded */
154         u_char* back_;  /* pointer to last image decoded */
155 
156         struct hufftab {
157                 int maxlen;
158                 const short* prefix;
159         };
160         hufftab h263_ht_mtype_i_;
161         hufftab h263_ht_mtype_p_;
162         hufftab h263_ht_cbpy_i_;
163         hufftab h263_ht_cbpy_p_;
164         hufftab h263_ht_mba_;
165         hufftab h263_ht_mvd_;
166         hufftab h263_ht_tcoeff_;
167 
168         /*
169          * Input bitstream buffer.  Uses 32-bit word to hold initial segment 
170          * of the bitstream.
171          */
172         u_int bb_;                      /* 32-bit bit buffer */
173         int nbb_;                       /* number bits in bit buffer */
174         const u_short* bs_;     /* input bit stream (less bits in bb_) */
175         const u_short* es_;     /* pointer to end if input stream */
176         const u_short* ps_;     /* packet start (for error reporting) */
177         int pebit_;                     /* packet end bit (for error reporting) */
178 
179 #define MBST_FRESH      0
180 #define MBST_OLD        1
181 #define MBST_NEW        2
182         u_char* mbst_;
183         short* qt_;             /* pointer to dequant table */
184         u_short* coord_;
185 
186         /* Values for source format */
187 #define FMT_FORBIDDEN 0
188 #define FMT_SUBQCIF   1
189 #define FMT_QCIF      2
190 #define FMT_CIF       3
191 #define FMT_4CIF      4
192 #define FMT_16CIF     5
193 #define FMT_RESERVED  6
194 #define FMT_EXTENDED  7
195         u_int fmt_;             /* source format */
196 
197         /* Values for picture type */
198 #define PCT_INTRA 0
199 #define PCT_INTER 1
200         u_int pct_;             /* picture coding type */
201         u_int opptype_; /* Optional PLUSPTYPE flags */
202         u_int mpptype_; /* Mandatory PLUSPTYPE flags */
203         u_int rpr_;             /* optional Reference Picture Resampling (Annex P) */
204         u_int rru_;             /* optional Reduced Resolution Update (Annex Q) */
205         u_int rtype_;   /* Optional rounding type for half-pel MV's */
206 
207         /* Values for Picture Aspect Ratio */
208 #define PAR_FORBIDDEN  0;
209 #define PAR_SQUARE_1_1 1;
210 #define PAR_CIF_4_3    2;
211 #define PAR_525_4_3    3;
212 #define PAR_CIF_16_9   4;
213 #define PAR_525_16_9   5;
214 #define PAR_EXTENDED  15;
215         u_int par_;             /* pixel aspect ratio for custom picture formats */
216         u_int pwi_;             /* pixel width indication for custom picture formats */
217         u_int phi_;             /* pixel height indication for custom picture formats */
218         u_int epar_width_;      /* extended PAR width */
219         u_int epar_height_;     /* extended PAR height */
220 
221         int frame_id_;          /* frame id */
222 
223         u_int width_;           /* width of Y component */
224         u_int height_;          /* height of Y component */
225         u_int last_width_;
226         u_int last_height_;
227 
228         u_int ngob_;            /* number of gobs */
229         u_int maxgob_;          /* max gob seen this frame */
230         u_int nrowingob_;       /* number of rows in a gob */
231         u_int nmbinrow_;        /* number of macroblocks in a row */
232         u_int nmbingob_;        /* number of macroblocks in a gob */
233         u_int nmb_;                     /* total number of macroblocks in picture */
234 
235         /* 
236          * Number of decoded macroblocks. As H.263 is always 4:2:0, one
237          * macroblock is composed of 6 8x8-pixels blocks: 4 Y, 1 U, and 1 V 
238          */
239         int ndmblk_;
240 
241         int qtidx_;                     /* quantizer index */
242         u_int mt_;                      /* macroblock type (flags in h263-huff.h) */
243         u_int gob_;                     /* current gob index */
244         u_int mba_;                     /* macroblock address */
245         u_int blk_;                     /* block number */
246         u_int dumplevel_;       /* dynamic debugging info flag */
247 
248         /* bounding box */
249         u_int minx_;
250         u_int miny_;
251         u_int maxx_;
252         u_int maxy_;
253         u_int bbx_;
254         u_int bby_;
255         u_int bbw_;
256         u_int bbh_;
257 
258         /*
259          * Table to indicate which blocks have changed.
260          */
261         u_char* marks_;
262         int mark_;
263 
264         /* error counters */
265         int bad_psc_;
266         int bad_bits_;
267         int bad_GOBno_;
268         int bad_fmt_;           /* # times RTP fmt != H.263 fmt */
269 
270         u_char mb_state_[NUM_GOBS_ALLOC * NUM_MBS_ALLOC];
271 
272         /* inverse quantization via table lookup */
273         short quant_[32 * 256];
274 
275         /* motion vector candidate predictors */
276         short mvcp_[2][NUM_MBS_IN_ROW_ALLOC];
277         char *above_row_;
278         char *current_row_;
279 };
280 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.