[svn] / trunk / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/bitstream/bitstream.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 124, Tue Apr 16 00:17:35 2002 UTC revision 252, Sun Jun 30 10:46:29 2002 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                                                                                                        *    *                                                                                                                                                        *
44      *      22.05.2002 bs_put_matrix fix
45      *  20.05.2002 added BitstreamWriteUserData                                   *
46      *  19.06.2002  Fix a little bug in use custom quant matrix                   *
47      *              MinChen <chenm001@163.com>                                    *
48      *  08.05.2002  add low_delay support for B_VOP decode                        *
49      *              MinChen <chenm001@163.com>                                    *
50      *  06.05.2002 low_delay                                                      *
51      *  06.05.2002 fixed fincr/fbase error                                        *
52      *  01.05.2002 added BVOP support to BitstreamWriteVopHeader                  *
53    *  15.04.2002 rewrite log2bin use asm386  By MinChen <chenm001@163.com>      *    *  15.04.2002 rewrite log2bin use asm386  By MinChen <chenm001@163.com>      *
54    *  26.03.2002 interlacing support                                                                                        *    *  26.03.2002 interlacing support                                                                                        *
55    *  03.03.2002 qmatrix writing                                                                                            *    *  03.03.2002 qmatrix writing                                                                                            *
# Line 48  Line 57 
57    *      30.02.2002     intra_dc_threshold support                                                                         *    *      30.02.2002     intra_dc_threshold support                                                                         *
58    *      04.12.2001     support for additional headers                                                             *    *      04.12.2001     support for additional headers                                                             *
59    *      16.12.2001     inital version                                                     *    *      16.12.2001     inital version                                                     *
60    *                                                                                                                                                        *    *
61    ******************************************************************************/    ******************************************************************************/
62    
63    
# Line 57  Line 66 
66  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
67    
68    
69  static int __inline log2bin(int value)  static uint32_t __inline
70    log2bin(uint32_t value)
71  {  {
72  /* Changed by Chenm001 */  /* Changed by Chenm001 */
73  #ifndef WIN32  #ifndef WIN32
74          int n = 0;          int n = 0;
75          while (value)  
76          {          while (value) {
77                  value >>= 1;                  value >>= 1;
78                  n++;                  n++;
79          }          }
# Line 77  Line 87 
87  }  }
88    
89    
90  static const uint32_t intra_dc_threshold_table[] =  static const uint32_t intra_dc_threshold_table[] = {
 {  
91          32,     /* never use */          32,     /* never use */
92          13,          13,
93          15,          15,
# Line 90  Line 99 
99  };  };
100    
101    
102  void bs_get_matrix(Bitstream * bs, uint8_t * matrix)  void
103    bs_get_matrix(Bitstream * bs,
104                              uint8_t * matrix)
105  {  {
106          int i = 0;          int i = 0;
107      int last, value = 0;      int last, value = 0;
108    
109      do          do {
         {  
110                  last = value;                  last = value;
111          value = BitstreamGetBits(bs, 8);          value = BitstreamGetBits(bs, 8);
112          matrix[ scan_tables[0][i++] ]  = value;          matrix[ scan_tables[0][i++] ]  = value;
113      }      }
114      while (value != 0 && i < 64);      while (value != 0 && i < 64);
115            i--;    // fix little bug at coeff not full
116    
117          while (i < 64)          while (i < 64) {
         {  
118                  matrix[ scan_tables[0][i++] ]  = last;                  matrix[ scan_tables[0][i++] ]  = last;
119          }          }
120  }  }
121    
122    
123    
124    // for PVOP addbits == fcode - 1
125    // for BVOP addbits == max(fcode,bcode) - 1
126    // returns mbpos
127    int
128    read_video_packet_header(Bitstream *bs, const int addbits, int * quant)
129    {
130            int nbits;
131            int mbnum;
132            int hec;
133    
134            nbits = NUMBITS_VP_RESYNC_MARKER + addbits;
135    
136            BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs));
137            BitstreamSkip(bs, nbits);
138    
139            DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>");
140    
141            // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
142                    // hec
143                    // vop_width
144                    // marker_bit
145                    // vop_height
146                    // marker_bit
147    
148            //}
149    
150            mbnum = BitstreamGetBits(bs, 9);
151            DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum);
152    
153            // if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY)
154            *quant = BitstreamGetBits(bs, 5);
155            DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
156    
157            // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
158            hec = BitstreamGetBit(bs);
159            DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec);
160            // if (hec)
161            //   .. decoder hec-header ...
162    
163            return mbnum;
164    }
165    
166    
167    
168  /*  /*
169  decode headers  decode headers
170  returns coding_type, or -1 if error  returns coding_type, or -1 if error
171  */  */
172    
173  int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode, uint32_t * intra_dc_threshold)  #define VIDOBJ_START_CODE_MASK          0x0000001f
174    #define VIDOBJLAY_START_CODE_MASK       0x0000000f
175    
176    int
177    BitstreamReadHeaders(Bitstream * bs,
178                                             DECODER * dec,
179                                             uint32_t * rounding,
180                                             uint32_t * quant,
181                                             uint32_t * fcode_forward,
182                                             uint32_t * fcode_backward,
183                                             uint32_t * intra_dc_threshold)
184  {  {
185          uint32_t vol_ver_id;          uint32_t vol_ver_id;
186          uint32_t time_inc_resolution;          static uint32_t time_increment_resolution;
187          uint32_t coding_type;          uint32_t coding_type;
188          uint32_t start_code;          uint32_t start_code;
189            uint32_t time_incr = 0;
190            int32_t time_increment;
191    
192          do          do {
         {  
193                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
194                  start_code = BitstreamShowBits(bs, 32);                  start_code = BitstreamShowBits(bs, 32);
195    
196                  if (start_code == VISOBJSEQ_START_CODE)                  if (start_code == VISOBJSEQ_START_CODE) {
197                  {  
198                          // DEBUG("visual_object_sequence");                          int profile;
199    
200                            DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>");
201    
202                          BitstreamSkip(bs, 32);                          // visual_object_sequence_start_code                          BitstreamSkip(bs, 32);                          // visual_object_sequence_start_code
203                          BitstreamSkip(bs, 8);                                   // profile_and_level_indication                          profile = BitstreamGetBits(bs, 8);      // profile_and_level_indication
204                  }  
205                  else if (start_code == VISOBJSEQ_STOP_CODE)                          DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile);
206                  {  
207                    } else if (start_code == VISOBJSEQ_STOP_CODE) {
208    
209                          BitstreamSkip(bs, 32);                          // visual_object_sequence_stop_code                          BitstreamSkip(bs, 32);                          // visual_object_sequence_stop_code
210                  }  
211                  else if (start_code == VISOBJ_START_CODE)                          DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");
212                  {  
213                          // DEBUG("visual_object");                  } else if (start_code == VISOBJ_START_CODE) {
214    
215                            DPRINTF(DPRINTF_STARTCODE, "<visual_object>");
216    
217                          BitstreamSkip(bs,32);                                   // visual_object_start_code                          BitstreamSkip(bs,32);                                   // visual_object_start_code
218                          if (BitstreamGetBit(bs))                                // is_visual_object_identified                          if (BitstreamGetBit(bs))                                // is_visual_object_identified
219                          {                          {
220                                  vol_ver_id = BitstreamGetBits(bs,4);    // visual_object_ver_id                                  vol_ver_id = BitstreamGetBits(bs,4);    // visual_object_ver_id
221                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
222                                  BitstreamSkip(bs, 3);                           // visual_object_priority                                  BitstreamSkip(bs, 3);                           // visual_object_priority
223                          }                          } else {
                         else  
                         {  
224                                  vol_ver_id = 1;                                  vol_ver_id = 1;
225                          }                          }
226    
227                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type
228                          {                          {
229                                  DEBUG("visual_object_type != video");                                  DPRINTF(DPRINTF_ERROR, "visual_object_type != video");
230                                  return -1;                                  return -1;
231                          }                          }
232                          BitstreamSkip(bs, 4);                          BitstreamSkip(bs, 4);
# Line 161  Line 235 
235    
236                          if (BitstreamGetBit(bs))                                // video_signal_type                          if (BitstreamGetBit(bs))                                // video_signal_type
237                          {                          {
238                                  DEBUG("+ video_signal_type");                                  DPRINTF(DPRINTF_HEADER,"+ video_signal_type");
239                                  BitstreamSkip(bs, 3);                           // video_format                                  BitstreamSkip(bs, 3);                           // video_format
240                                  BitstreamSkip(bs, 1);                           // video_range                                  BitstreamSkip(bs, 1);                           // video_range
241                                  if (BitstreamGetBit(bs))                        // color_description                                  if (BitstreamGetBit(bs))                        // color_description
242                                  {                                  {
243                                          DEBUG("+ color_description");                                          DPRINTF(DPRINTF_HEADER,"+ color_description");
244                                          BitstreamSkip(bs, 8);                   // color_primaries                                          BitstreamSkip(bs, 8);                   // color_primaries
245                                          BitstreamSkip(bs, 8);                   // transfer_characteristics                                          BitstreamSkip(bs, 8);                   // transfer_characteristics
246                                          BitstreamSkip(bs, 8);                   // matrix_coefficients                                          BitstreamSkip(bs, 8);                   // matrix_coefficients
247                                  }                                  }
248                          }                          }
249                  }                  } else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) {
250                  else if ((start_code & ~0x1f) == VIDOBJ_START_CODE)  
251                  {                          DPRINTF(DPRINTF_STARTCODE, "<video_object>");
252                            DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK);
253    
254                          BitstreamSkip(bs, 32);          // video_object_start_code                          BitstreamSkip(bs, 32);          // video_object_start_code
255                  }  
256                  else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE)                  } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) {
257                  {  
258                          // DEBUG("video_object_layer");                          DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>");
259                            DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK);
260    
261                          BitstreamSkip(bs, 32);                                  // video_object_layer_start_code                          BitstreamSkip(bs, 32);                                  // video_object_layer_start_code
262    
263                          BitstreamSkip(bs, 1);                                                                   // random_accessible_vol                          BitstreamSkip(bs, 1);                                                                   // random_accessible_vol
264    
265                          // video_object_type_indication                          // video_object_type_indication
266                          if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE &&                          if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0)   // BUGGY DIVX
                                 BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE &&  
                                 BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN &&  
                                 BitstreamShowBits(bs, 8) != 0)          // BUGGY DIVX  
267                          {                          {
268                                  DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8));                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",
269                                            BitstreamShowBits(bs, 8));
270                                  return -1;                                  return -1;
271                          }                          }
272                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
# Line 198  Line 274 
274    
275                          if (BitstreamGetBit(bs))                                        // is_object_layer_identifier                          if (BitstreamGetBit(bs))                                        // is_object_layer_identifier
276                          {                          {
277                                  DEBUG("+ is_object_layer_identifier");                                  DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier");
278                                  vol_ver_id = BitstreamGetBits(bs,4);            // video_object_layer_verid                                  vol_ver_id = BitstreamGetBits(bs,4);            // video_object_layer_verid
279                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
280                                  BitstreamSkip(bs, 3);                                   // video_object_layer_priority                                  BitstreamSkip(bs, 3);                                   // video_object_layer_priority
281                          }                          } else {
                         else  
                         {  
282                                  vol_ver_id = 1;                                  vol_ver_id = 1;
283                          }                          }
                         //DEBUGI("vol_ver_id", vol_ver_id);  
284    
285                          if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR)     // aspect_ratio_info                          if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR)     // aspect_ratio_info
286                          {                          {
287                                  DEBUG("+ aspect_ratio_info");                                  DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info");
288                                  BitstreamSkip(bs, 8);                                           // par_width                                  BitstreamSkip(bs, 8);                                           // par_width
289                                  BitstreamSkip(bs, 8);                                           // par_height                                  BitstreamSkip(bs, 8);                                           // par_height
290                          }                          }
291    
292                          if (BitstreamGetBit(bs))                // vol_control_parameters                          if (BitstreamGetBit(bs))                // vol_control_parameters
293                          {                          {
294                                  DEBUG("+ vol_control_parameters");                                  DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters");
295                                  BitstreamSkip(bs, 2);                                           // chroma_format                                  BitstreamSkip(bs, 2);                                           // chroma_format
296                                  BitstreamSkip(bs, 1);                                           // low_delay                                  dec->low_delay = BitstreamGetBit(bs);   // low_delay
297                                    DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
298                                  if (BitstreamGetBit(bs))                                        // vbv_parameters                                  if (BitstreamGetBit(bs))                                        // vbv_parameters
299                                  {                                  {
300                                          DEBUG("+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
301                                          BitstreamSkip(bs, 15);                          // first_half_bitrate                                          BitstreamSkip(bs, 15);                          // first_half_bitrate
302                                          READ_MARKER();                                          READ_MARKER();
303                                          BitstreamSkip(bs, 15);                          // latter_half_bitrate                                          BitstreamSkip(bs, 15);                          // latter_half_bitrate
# Line 239  Line 314 
314                          }                          }
315    
316                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
317                          // DEBUG1("shape", dec->shape);                          DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape);
318    
319                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1)                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {
                         {  
320                                  BitstreamSkip(bs, 4);           // video_object_layer_shape_extension                                  BitstreamSkip(bs, 4);           // video_object_layer_shape_extension
321                          }                          }
322    
323                          READ_MARKER();                          READ_MARKER();
324    
325                          time_inc_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution  // *************************** for decode B-frame time ***********************
326                          time_inc_resolution--;                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution
327                          if (time_inc_resolution > 0)  
328                          {                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution);
329                                  dec->time_inc_bits = log2bin(time_inc_resolution);  
330                          }                          time_increment_resolution--;
                         else  
                         {  
                                 // dec->time_inc_bits = 0;  
331    
332                            if (time_increment_resolution > 0) {
333                                    dec->time_inc_bits = log2bin(time_increment_resolution);
334                            } else {
335                                    // dec->time_inc_bits = 0;
336                                  // for "old" xvid compatibility, set time_inc_bits = 1                                  // for "old" xvid compatibility, set time_inc_bits = 1
337                                  dec->time_inc_bits = 1;                                  dec->time_inc_bits = 1;
338                          }                          }
# Line 266  Line 341 
341    
342                          if (BitstreamGetBit(bs))                                                // fixed_vop_rate                          if (BitstreamGetBit(bs))                                                // fixed_vop_rate
343                          {                          {
344                                    DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate");
345                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment
346                          }                          }
347    
348                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
                         {  
349    
350                                  if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)                                  if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) {
                                 {  
351                                          uint32_t width, height;                                          uint32_t width, height;
352    
353                                          READ_MARKER();                                          READ_MARKER();
354                                          width = BitstreamGetBits(bs, 13);                       // video_object_layer_width                                          width = BitstreamGetBits(bs, 13);                       // video_object_layer_width
                                         //DEBUGI("width", width);  
355                                          READ_MARKER();                                          READ_MARKER();
356                                          height = BitstreamGetBits(bs, 13);              // video_object_layer_height                                          height = BitstreamGetBits(bs, 13);              // video_object_layer_height
                                         //DEBUGI("height", height);  
357                                          READ_MARKER();                                          READ_MARKER();
358    
359                                          if (width != dec->width || height != dec->height)                                          DPRINTF(DPRINTF_HEADER, "width %i", width);
360                                          {                                          DPRINTF(DPRINTF_HEADER, "height %i", height);
361                                                  DEBUG("FATAL: video dimension discrepancy ***");  
362                                                  DEBUG2("bitstream width/height", width, height);                                          if (width != dec->width || height != dec->height) {
363                                                  DEBUG2("param width/height", dec->width, dec->height);                                                  DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");
364                                                  return -1;                                                  return -1;
365                                          }                                          }
366    
367                                  }                                  }
368    
369                                  if ((dec->interlacing = BitstreamGetBit(bs)))                                  dec->interlacing = BitstreamGetBit(bs);
370                                  {                                  DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing);
                                         DEBUG("vol: interlacing");  
                                 }  
371    
372                                  if (!BitstreamGetBit(bs))                               // obmc_disable                                  if (!BitstreamGetBit(bs))                               // obmc_disable
373                                  {                                  {
374                                          DEBUG("IGNORED/TODO: !obmc_disable");                                          DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported");
375                                          // TODO                                          // TODO
376                                          // fucking divx4.02 has this enabled                                          // fucking divx4.02 has this enabled
377                                  }                                  }
378    
379                                  if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)))  // sprite_enable                                  if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)))  // sprite_enable
380                                  {                                  {
381                                          DEBUG("sprite_enable; not supported");                                          DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported");
382                                          return -1;                                          return -1;
383                                  }                                  }
384    
385                                  if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)                                  if (vol_ver_id != 1 &&
386                                  {                                          dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
387                                          BitstreamSkip(bs, 1);                                   // sadct_disable                                          BitstreamSkip(bs, 1);                                   // sadct_disable
388                                  }                                  }
389    
390                                  if (BitstreamGetBit(bs))                                                // not_8_bit                                  if (BitstreamGetBit(bs))                                                // not_8_bit
391                                  {                                  {
392                                          DEBUG("+ not_8_bit [IGNORED/TODO]");                                          DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)");
393                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision
394                                          BitstreamSkip(bs, 4);                                           // bits_per_pixel                                          BitstreamSkip(bs, 4);                                           // bits_per_pixel
395                                  }                                  } else {
                                 else  
                                 {  
396                                          dec->quant_bits = 5;                                          dec->quant_bits = 5;
397                                  }                                  }
398    
399                                  if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)                                  if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
                                 {  
400                                          BitstreamSkip(bs, 1);                   // no_gray_quant_update                                          BitstreamSkip(bs, 1);                   // no_gray_quant_update
401                                          BitstreamSkip(bs, 1);                   // composition_method                                          BitstreamSkip(bs, 1);                   // composition_method
402                                          BitstreamSkip(bs, 1);                   // linear_composition                                          BitstreamSkip(bs, 1);                   // linear_composition
403                                  }                                  }
404    
405                                  dec->quant_type = BitstreamGetBit(bs);          // quant_type                                  dec->quant_type = BitstreamGetBit(bs);          // quant_type
406                                  // DEBUG1("**** quant_type", dec->quant_type);                                  DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type);
407    
408                                  if (dec->quant_type)                                  if (dec->quant_type) {
                                 {  
409                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat
410                                          {                                          {
411                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
412    
413                                                    DPRINTF(DPRINTF_HEADER, "load_intra_quant_mat");
414    
415                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
416                                                  set_intra_matrix(matrix);                                                  set_intra_matrix(matrix);
417                                          }                                          } else
                                         else  
418                                                  set_intra_matrix(get_default_intra_matrix());                                                  set_intra_matrix(get_default_intra_matrix());
419    
420                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat
421                                          {                                          {
422                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
423    
424                                                    DPRINTF(DPRINTF_HEADER, "load_inter_quant_mat");
425    
426                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
427                                                  set_inter_matrix(matrix);                                                  set_inter_matrix(matrix);
428                                          }                                          } else
                                         else  
429                                                  set_inter_matrix(get_default_inter_matrix());                                                  set_inter_matrix(get_default_inter_matrix());
430    
431                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
432                                          {                                                  DPRINTF(DPRINTF_ERROR, "greyscale matrix not supported");
                                                 // TODO  
                                                 DEBUG("TODO: grayscale matrix stuff");  
433                                                  return -1;                                                  return -1;
434                                          }                                          }
435    
436                                  }                                  }
437    
438    
439                                  if (vol_ver_id != 1)                                  if (vol_ver_id != 1) {
                                 {  
440                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe
441                                          if (dec->quarterpel)                                          if (dec->quarterpel) {
442                                          {                                                  DPRINTF(DPRINTF_ERROR, "quarter_sample not supported");
                                                 DEBUG("IGNORED/TODO: quarter_sample");  
                                         }  
443                                  }                                  }
444                                  else                                  } else {
                                 {  
445                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
446                                  }                                  }
447    
448                                  if (!BitstreamGetBit(bs))                       // complexity_estimation_disable                                  if (!BitstreamGetBit(bs))                       // complexity_estimation_disable
449                                  {                                  {
450                                          DEBUG("TODO: complexity_estimation header");                                          DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported");
                                         // TODO  
451                                          return -1;                                          return -1;
452                                  }                                  }
453    
454                                  if (!BitstreamGetBit(bs))                       // resync_marker_disable                                  BitstreamSkip(bs, 1);   // resync_marker_disable
                                 {  
                                         DEBUG("IGNORED/TODO: !resync_marker_disable");  
                                         // TODO  
                                 }  
455    
456                                  if (BitstreamGetBit(bs))                // data_partitioned                                  if (BitstreamGetBit(bs))                // data_partitioned
457                                  {                                  {
458                                          DEBUG("+ data_partitioned");                                          DPRINTF(DPRINTF_ERROR, "data_partitioned not supported");
459                                          BitstreamSkip(bs, 1);           // reversible_vlc                                          BitstreamSkip(bs, 1);           // reversible_vlc
460                                  }                                  }
461    
462                                  if (vol_ver_id != 1)                                  if (vol_ver_id != 1) {
                                 {  
463                                          if (BitstreamGetBit(bs))                        // newpred_enable                                          if (BitstreamGetBit(bs))                        // newpred_enable
464                                          {                                          {
465                                                  DEBUG("+ newpred_enable");                                                  DPRINTF(DPRINTF_HEADER, "+ newpred_enable");
466                                                  BitstreamSkip(bs, 2);                   // requested_upstream_message_type                                                  BitstreamSkip(bs, 2);                   // requested_upstream_message_type
467                                                  BitstreamSkip(bs, 1);                   // newpred_segment_type                                                  BitstreamSkip(bs, 1);                   // newpred_segment_type
468                                          }                                          }
469                                          if (BitstreamGetBit(bs))                        // reduced_resolution_vop_enable                                          if (BitstreamGetBit(bs))                        // reduced_resolution_vop_enable
470                                          {                                          {
471                                                  DEBUG("TODO: reduced_resolution_vop_enable");                                                  DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");
                                                 // TODO  
472                                                  return -1;                                                  return -1;
473                                          }                                          }
474                                  }                                  }
475    
476                                  if (BitstreamGetBit(bs))        // scalability                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability
477                                  {                                  {
478                                          // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                         DEBUG("TODO: scalability");  
479                                          return -1;                                          return -1;
480                                  }                                  }
481                          }                          } else                          // dec->shape == BINARY_ONLY
                         else    // dec->shape == BINARY_ONLY  
                         {  
                                 if (vol_ver_id != 1)  
482                                  {                                  {
483                                    if (vol_ver_id != 1) {
484                                          if (BitstreamGetBit(bs))        // scalability                                          if (BitstreamGetBit(bs))        // scalability
485                                          {                                          {
486                                                  // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                                 DEBUG("TODO: scalability");  
487                                                  return -1;                                                  return -1;
488                                          }                                          }
489                                  }                                  }
# Line 438  Line 491 
491    
492                          }                          }
493    
494                  }                  } else if (start_code == GRPOFVOP_START_CODE) {
495                  else if (start_code == GRPOFVOP_START_CODE)  
496                  {                          DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>");
497                          // DEBUG("group_of_vop");  
498                          BitstreamSkip(bs, 32);                          BitstreamSkip(bs, 32);
499                          {                          {
500                                  int hours, minutes, seconds;                                  int hours, minutes, seconds;
501    
502                                  hours = BitstreamGetBits(bs, 5);                                  hours = BitstreamGetBits(bs, 5);
503                                  minutes = BitstreamGetBits(bs, 6);                                  minutes = BitstreamGetBits(bs, 6);
504                                  READ_MARKER();                                  READ_MARKER();
505                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
506                                  // DEBUG3("hms", hours, minutes, seconds);  
507                                    DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);
508                          }                          }
509                          BitstreamSkip(bs, 1);                   // closed_gov                          BitstreamSkip(bs, 1);                   // closed_gov
510                          BitstreamSkip(bs, 1);                   // broken_link                          BitstreamSkip(bs, 1);                   // broken_link
511                  }  
512                  else if (start_code == VOP_START_CODE)                  } else if (start_code == VOP_START_CODE) {
513                  {  
514                          // DEBUG("vop_start_code");                          DPRINTF(DPRINTF_STARTCODE, "<vop>");
515    
516                          BitstreamSkip(bs, 32);                                          // vop_start_code                          BitstreamSkip(bs, 32);                                          // vop_start_code
517    
518                          coding_type = BitstreamGetBits(bs, 2);          // vop_coding_type                          coding_type = BitstreamGetBits(bs, 2);          // vop_coding_type
519                          //DEBUG1("coding_type", coding_type);                          DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type);
520    
521                          while (BitstreamGetBit(bs) != 0) ;                      // time_base  // *************************** for decode B-frame time ***********************
522                            while (BitstreamGetBit(bs) != 0)        // time_base
523                                    time_incr++;
524    
525                          READ_MARKER();                          READ_MARKER();
526    
527                          //DEBUG1("time_inc_bits", dec->time_inc_bits);                          if (dec->time_inc_bits) {
528                          //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment
529                          if (dec->time_inc_bits)                          }
530                          {  
531                                  BitstreamSkip(bs, dec->time_inc_bits);  // vop_time_increment                          DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr);
532                            DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment);
533    
534                            DPRINTF(DPRINTF_TIMECODE, "%c %i:%i",
535                                    coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B',
536                                    time_incr, time_increment);
537    
538                            if (coding_type != B_VOP) {
539                                    dec->last_time_base = dec->time_base;
540                                    dec->time_base += time_incr;
541                                    dec->time =
542                                            dec->time_base * time_increment_resolution +
543                                            time_increment;
544                                    dec->time_pp = (uint32_t) (dec->time - dec->last_non_b_time);
545                                    dec->last_non_b_time = dec->time;
546                            } else {
547                                    dec->time =
548                                            (dec->last_time_base +
549                                             time_incr) * time_increment_resolution + time_increment;
550                                    dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time);
551                          }                          }
552    
553                          READ_MARKER();                          READ_MARKER();
554    
555                          if (!BitstreamGetBit(bs))                                       // vop_coded                          if (!BitstreamGetBit(bs))                                       // vop_coded
556                          {                          {
557                                    DPRINTF(DPRINTF_HEADER, "vop_coded==false");
558                                  return N_VOP;                                  return N_VOP;
559                          }                          }
560    
# Line 485  Line 563 
563                          }                          }
564                          */                          */
565    
566                          if (coding_type != I_VOP)                          // fix a little bug by MinChen <chenm002@163.com>
567                          {                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
568                                    (coding_type == P_VOP)) {
569                                  *rounding = BitstreamGetBit(bs);        // rounding_type                                  *rounding = BitstreamGetBit(bs);        // rounding_type
570                                  //DEBUG1("rounding", *rounding);                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);
571                          }                          }
572    
573                          /* if (reduced_resolution_enable)                          /* if (reduced_resolution_enable)
# Line 496  Line 575 
575                          }                          }
576                          */                          */
577    
578                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
                         {  
579                                  uint32_t width, height;                                  uint32_t width, height;
580                                  uint32_t horiz_mc_ref, vert_mc_ref;                                  uint32_t horiz_mc_ref, vert_mc_ref;
581    
# Line 510  Line 588 
588                                  vert_mc_ref = BitstreamGetBits(bs, 13);                                  vert_mc_ref = BitstreamGetBits(bs, 13);
589                                  READ_MARKER();                                  READ_MARKER();
590    
591                                  // DEBUG2("vop_width/height", width, height);                                  DPRINTF(DPRINTF_HEADER, "width %i", width);
592                                  // DEBUG2("ref             ", horiz_mc_ref, vert_mc_ref);                                  DPRINTF(DPRINTF_HEADER, "height %i", height);
593                                    DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref);
594                                    DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref);
595    
596                                  BitstreamSkip(bs, 1);                           // change_conv_ratio_disable                                  BitstreamSkip(bs, 1);                           // change_conv_ratio_disable
597                                  if (BitstreamGetBit(bs))                        // vop_constant_alpha                                  if (BitstreamGetBit(bs))                        // vop_constant_alpha
# Line 521  Line 601 
601                          }                          }
602    
603    
604                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
                         {  
605                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
606                                  *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];                                  *intra_dc_threshold =
607                                            intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
608    
609                                    if (dec->interlacing) {
610                                            dec->top_field_first = BitstreamGetBit(bs);
611                                            DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first);
612                                            dec->alternate_vertical_scan = BitstreamGetBit(bs);
613                                            DPRINTF(DPRINTF_HEADER, "interlace alternate_vertical_scan %i", dec->alternate_vertical_scan);
614    
                                 if (dec->interlacing)  
                                 {  
                                         if ((dec->top_field_first = BitstreamGetBit(bs)))  
                                         {  
                                                 DEBUG("vop: top_field_first");  
                                         }  
                                         if ((dec->alternate_vertical_scan = BitstreamGetBit(bs)))  
                                         {  
                                                 DEBUG("vop: alternate_vertical_scan");  
                                         }  
615                                  }                                  }
616                          }                          }
617    
618                          *quant = BitstreamGetBits(bs, dec->quant_bits);         // vop_quant                          if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1)       // vop_quant
619                          //DEBUG1("quant", *quant);                                  *quant = 1;
620    
621                          if (coding_type != I_VOP)                          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
622                          {  
623                                  *fcode = BitstreamGetBits(bs, 3);                       // fcode_forward                          if (coding_type != I_VOP) {
624                                    *fcode_forward = BitstreamGetBits(bs, 3);       // fcode_forward
625                                    DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward);
626                          }                          }
627    
628                          if (coding_type == B_VOP)                          if (coding_type == B_VOP) {
629                          {                                  *fcode_backward = BitstreamGetBits(bs, 3);      // fcode_backward
630                                  // *fcode_backward = BitstreamGetBits(bs, 3);           // fcode_backward                                  DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward);
631                          }                          }
632                          return coding_type;                          if (!dec->scalability) {
633                                    if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&
634                                            (coding_type != I_VOP)) {
635                                            BitstreamSkip(bs, 1);   // vop_shape_coding_type
636                  }                  }
                 else if (start_code == USERDATA_START_CODE)  
                 {  
                         // DEBUG("user_data");  
                         BitstreamSkip(bs, 32);          // user_data_start_code  
637                  }                  }
638                  else  // start_code == ?                          return coding_type;
639                  {  
640                          if (BitstreamShowBits(bs, 24) == 0x000001)                  } else if (start_code == USERDATA_START_CODE) {
641    
642                            DPRINTF(DPRINTF_STARTCODE, "<user_data>");
643    
644                            BitstreamSkip(bs, 32);  // user_data_start_code
645    
646                    } else                                  // start_code == ?
647                          {                          {
648                                  DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32));                          if (BitstreamShowBits(bs, 24) == 0x000001) {
649                                    DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32));
650                          }                          }
651                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
652                  }                  }
653          }          }
654          while ((BitstreamPos(bs) >> 3) < bs->length);          while ((BitstreamPos(bs) >> 3) < bs->length);
655    
656          DEBUG("*** WARNING: no vop_start_code found");          //DPRINTF("*** WARNING: no vop_start_code found");
657          return -1; /* ignore it */          return -1; /* ignore it */
658  }  }
659    
660    
661  /* write custom quant matrix */  /* write custom quant matrix */
662    
663  static void bs_put_matrix(Bitstream * bs, const int16_t *matrix)  static void
664    bs_put_matrix(Bitstream * bs,
665                              const int16_t * matrix)
666  {  {
667          int i, j;          int i, j;
668          const int last = matrix[scan_tables[0][63]];          const int last = matrix[scan_tables[0][63]];
669    
670          for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ;          for (j = 63; j > 0 && matrix[scan_tables[0][j - 1]] == last; j--);
671    
672          for (i = 0; i <= j; i++)          for (i = 0; i <= j; i++) {
         {  
673                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);
674          }          }
675    
676          if (j < 63)          if (j < 63) {
         {  
677                  BitstreamPutBits(bs, 0, 8);                  BitstreamPutBits(bs, 0, 8);
678          }          }
679  }  }
# Line 598  Line 682 
682  /*  /*
683          write vol header          write vol header
684  */  */
685  void BitstreamWriteVolHeader(Bitstream * const bs,  void
686                                                  const MBParam * pParam)  BitstreamWriteVolHeader(Bitstream * const bs,
687                                                    const MBParam * pParam,
688                                                    const FRAMEINFO * frame)
689  {  {
690          // video object_start_code & vo_id          // video object_start_code & vo_id
691      BitstreamPad(bs);      BitstreamPad(bs);
# Line 614  Line 700 
700          BitstreamPutBits(bs, 0, 8);                     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);                     // video_object_type_indication
701          BitstreamPutBit(bs, 0);                         // is_object_layer_identified (0=not given)          BitstreamPutBit(bs, 0);                         // is_object_layer_identified (0=not given)
702          BitstreamPutBits(bs, 1, 4);                     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);                     // aspect_ratio_info (1=1:1)
703          BitstreamPutBit(bs, 0);                         // vol_control_parameters (0=not given)  
704    #ifdef BFRAMES
705            if (pParam->max_bframes > 0) {
706                    //DPRINTF("low_delay=1");
707                    BitstreamPutBit(bs, 1); // vol_control_parameters
708                    BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"
709                    BitstreamPutBit(bs, 0); // low_delay
710                    BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)
711            } else
712    #endif
713            {
714                    BitstreamPutBits(bs, 0, 1);     // vol_control_parameters (0=not given)
715            }
716    
717    
718          BitstreamPutBits(bs, 0, 2);                     // video_object_layer_shape (0=rectangular)          BitstreamPutBits(bs, 0, 2);                     // video_object_layer_shape (0=rectangular)
719    
720          WRITE_MARKER();          WRITE_MARKER();
# Line 624  Line 724 
724                          25fps           res=25          inc=1                          25fps           res=25          inc=1
725                          29.97fps        res=30000       inc=1001                          29.97fps        res=30000       inc=1001
726          */          */
727    #ifdef BFRAMES
728            BitstreamPutBits(bs, pParam->fbase, 16);
729    #else
730          BitstreamPutBits(bs, 2, 16);          BitstreamPutBits(bs, 2, 16);
731    #endif
732    
733          WRITE_MARKER();          WRITE_MARKER();
734    
735          // fixed_vop_rate  #ifdef BFRAMES
736          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
737            BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
738          // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution)  #else
739          // BitstreamPutBits(bs, 0, 15);          BitstreamPutBit(bs, 0);         // fixed_vop_rate = 0
740    #endif
741    
742          WRITE_MARKER();          WRITE_MARKER();
743          BitstreamPutBits(bs, pParam->width, 13);                // width          BitstreamPutBits(bs, pParam->width, 13);                // width
# Line 640  Line 745 
745          BitstreamPutBits(bs, pParam->height, 13);               // height          BitstreamPutBits(bs, pParam->height, 13);               // height
746          WRITE_MARKER();          WRITE_MARKER();
747    
748          BitstreamPutBit(bs, pParam->global_flags & XVID_INTERLACING);           // interlace          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace
749          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
750          BitstreamPutBit(bs, 0);         // sprite_enable          BitstreamPutBit(bs, 0);         // sprite_enable
751          BitstreamPutBit(bs, 0);         // not_in_bit          BitstreamPutBit(bs, 0);         // not_in_bit
752    
753          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
754          BitstreamPutBit(bs, pParam->quant_type);          BitstreamPutBit(bs, pParam->m_quant_type);
755    
756          if (pParam->quant_type)          if (pParam->m_quant_type) {
         {  
757                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
758                  if (get_intra_matrix_status())                  if (get_intra_matrix_status()) {
                 {  
759                          bs_put_matrix(bs, get_intra_matrix());                          bs_put_matrix(bs, get_intra_matrix());
760                  }                  }
761    
762                  BitstreamPutBit(bs, get_inter_matrix_status());         // load_inter_quant_mat                  BitstreamPutBit(bs, get_inter_matrix_status());         // load_inter_quant_mat
763                  if (get_inter_matrix_status())                  if (get_inter_matrix_status()) {
                 {  
764                          bs_put_matrix(bs, get_inter_matrix());                          bs_put_matrix(bs, get_inter_matrix());
765                  }                  }
766    
# Line 679  Line 781 
781    time_inc = nth of a second since last resync    time_inc = nth of a second since last resync
782    (decoder uses these values to determine precise time since last resync)    (decoder uses these values to determine precise time since last resync)
783  */  */
784  void BitstreamWriteVopHeader(Bitstream * const bs,  void
785                                                  const MBParam * pParam)  BitstreamWriteVopHeader(Bitstream * const bs,
786                                                    const MBParam * pParam,
787                                                    const FRAMEINFO * frame,
788                                                    int vop_coded)
789  {  {
790    #ifdef BFRAMES
791            uint32_t i;
792    #endif
793      BitstreamPad(bs);      BitstreamPad(bs);
794      BitstreamPutBits(bs, VOP_START_CODE, 32);      BitstreamPutBits(bs, VOP_START_CODE, 32);
795    
796      BitstreamPutBits(bs, pParam->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
797    
798          // time_base = 0  write n x PutBit(1), PutBit(0)          // time_base = 0  write n x PutBit(1), PutBit(0)
799    #ifdef BFRAMES
800            for (i = 0; i < frame->seconds; i++) {
801                    BitstreamPutBit(bs, 1);
802            }
803            BitstreamPutBit(bs, 0);
804    #else
805          BitstreamPutBits(bs, 0, 1);          BitstreamPutBits(bs, 0, 1);
806    #endif
807    
808          WRITE_MARKER();          WRITE_MARKER();
809    
810          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
811    #ifdef BFRAMES
812            BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
813            /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,
814                            frame->coding_type == I_VOP ? 'I' : frame->coding_type ==
815                            P_VOP ? 'P' : 'B');*/
816    #else
817          BitstreamPutBits(bs, 1, 1);          BitstreamPutBits(bs, 1, 1);
818    #endif
819    
820          WRITE_MARKER();          WRITE_MARKER();
821    
822            if (!vop_coded) {
823                    BitstreamPutBits(bs, 0, 1);
824                    return;
825            }
826    
827          BitstreamPutBits(bs, 1, 1);                             // vop_coded          BitstreamPutBits(bs, 1, 1);                             // vop_coded
828    
829          if (pParam->coding_type != I_VOP)          if (frame->coding_type == P_VOP)
830                  BitstreamPutBits(bs, pParam->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
831    
832          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold
833    
834          if (pParam->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
         {  
835                  BitstreamPutBit(bs, 1);         // top field first                  BitstreamPutBit(bs, 1);         // top field first
836                  BitstreamPutBit(bs, 0);         // alternate vertical scan                  BitstreamPutBit(bs, 0);         // alternate vertical scan
837          }          }
838    
839          BitstreamPutBits(bs, pParam->quant, 5);                 // quantizer          BitstreamPutBits(bs, frame->quant, 5);  // quantizer
840    
841            if (frame->coding_type != I_VOP)
842                    BitstreamPutBits(bs, frame->fcode, 3);  // forward_fixed_code
843    
844            if (frame->coding_type == B_VOP)
845                    BitstreamPutBits(bs, frame->bcode, 3);  // backward_fixed_code
846    
847    }
848    
849    
850    void
851    BitstreamWriteUserData(Bitstream * const bs,
852                                                    uint8_t * data,
853                                                    const int length)
854    {
855            int i;
856    
857            BitstreamPad(bs);
858            BitstreamPutBits(bs, USERDATA_START_CODE, 32);
859    
860            for (i = 0; i < length; i++) {
861                    BitstreamPutBits(bs, data[i], 8);
862            }
863    
         if (pParam->coding_type != I_VOP)  
                 BitstreamPutBits(bs, pParam->fixed_code, 3);            // fixed_code = [1,4]  
864  }  }

Legend:
Removed from v.124  
changed lines
  Added in v.252

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4