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

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

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

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

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.28.2.4

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