[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.13, Thu May 9 00:15:51 2002 UTC revision 1.15, Fri Jun 14 12:26:06 2002 UTC
# Line 62  Line 62 
62  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
63    
64    
65  static uint32_t __inline log2bin(uint32_t value)  static uint32_t __inline
66    log2bin(uint32_t value)
67  {  {
68  /* Changed by Chenm001 */  /* Changed by Chenm001 */
69  #ifndef WIN32  #ifndef WIN32
70          int n = 0;          int n = 0;
71          while (value)  
72          {          while (value) {
73                  value >>= 1;                  value >>= 1;
74                  n++;                  n++;
75          }          }
# Line 82  Line 83 
83  }  }
84    
85    
86  static const uint32_t intra_dc_threshold_table[] =  static const uint32_t intra_dc_threshold_table[] = {
 {  
87          32,     /* never use */          32,     /* never use */
88          13,          13,
89          15,          15,
# Line 95  Line 95 
95  };  };
96    
97    
98  void bs_get_matrix(Bitstream * bs, uint8_t * matrix)  void
99    bs_get_matrix(Bitstream * bs,
100                              uint8_t * matrix)
101  {  {
102          int i = 0;          int i = 0;
103      int last, value = 0;      int last, value = 0;
104    
105      do          do {
         {  
106                  last = value;                  last = value;
107          value = BitstreamGetBits(bs, 8);          value = BitstreamGetBits(bs, 8);
108          matrix[ scan_tables[0][i++] ]  = value;          matrix[ scan_tables[0][i++] ]  = value;
109      }      }
110      while (value != 0 && i < 64);      while (value != 0 && i < 64);
111    
112          while (i < 64)          while (i < 64) {
         {  
113                  matrix[ scan_tables[0][i++] ]  = last;                  matrix[ scan_tables[0][i++] ]  = last;
114          }          }
115  }  }
# Line 119  Line 119 
119  returns coding_type, or -1 if error  returns coding_type, or -1 if error
120  */  */
121    
122  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)  int
123    BitstreamReadHeaders(Bitstream * bs,
124                                             DECODER * dec,
125                                             uint32_t * rounding,
126                                             uint32_t * quant,
127                                             uint32_t * fcode_forward,
128                                             uint32_t * fcode_backward,
129                                             uint32_t * intra_dc_threshold)
130  {  {
131          uint32_t vol_ver_id;          uint32_t vol_ver_id;
132          static uint32_t time_increment_resolution;          static uint32_t time_increment_resolution;
# Line 128  Line 135 
135          uint32_t time_incr=0;          uint32_t time_incr=0;
136          int32_t  time_increment;          int32_t  time_increment;
137    
138          do          do {
         {  
139                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
140                  start_code = BitstreamShowBits(bs, 32);                  start_code = BitstreamShowBits(bs, 32);
141    
142                  if (start_code == VISOBJSEQ_START_CODE)                  if (start_code == VISOBJSEQ_START_CODE) {
                 {  
143                          // DEBUG("visual_object_sequence");                          // DEBUG("visual_object_sequence");
144                          BitstreamSkip(bs, 32);                          // visual_object_sequence_start_code                          BitstreamSkip(bs, 32);                          // visual_object_sequence_start_code
145                          BitstreamSkip(bs, 8);                                   // profile_and_level_indication                          BitstreamSkip(bs, 8);                                   // profile_and_level_indication
146                  }                  } else if (start_code == VISOBJSEQ_STOP_CODE) {
                 else if (start_code == VISOBJSEQ_STOP_CODE)  
                 {  
147                          BitstreamSkip(bs, 32);                          // visual_object_sequence_stop_code                          BitstreamSkip(bs, 32);                          // visual_object_sequence_stop_code
148                  }                  } else if (start_code == VISOBJ_START_CODE) {
                 else if (start_code == VISOBJ_START_CODE)  
                 {  
149                          // DEBUG("visual_object");                          // DEBUG("visual_object");
150                          BitstreamSkip(bs,32);                                   // visual_object_start_code                          BitstreamSkip(bs,32);                                   // visual_object_start_code
151                          if (BitstreamGetBit(bs))                                // is_visual_object_identified                          if (BitstreamGetBit(bs))                                // is_visual_object_identified
152                          {                          {
153                                  vol_ver_id = BitstreamGetBits(bs,4);    // visual_object_ver_id                                  vol_ver_id = BitstreamGetBits(bs,4);    // visual_object_ver_id
154                                  BitstreamSkip(bs, 3);                           // visual_object_priority                                  BitstreamSkip(bs, 3);                           // visual_object_priority
155                          }                          } else {
                         else  
                         {  
156                                  vol_ver_id = 1;                                  vol_ver_id = 1;
157                          }                          }
158    
# Line 179  Line 178 
178                                          BitstreamSkip(bs, 8);                   // matrix_coefficients                                          BitstreamSkip(bs, 8);                   // matrix_coefficients
179                                  }                                  }
180                          }                          }
181                  }                  } else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) {
                 else if ((start_code & ~0x1f) == VIDOBJ_START_CODE)  
                 {  
182                          BitstreamSkip(bs, 32);          // video_object_start_code                          BitstreamSkip(bs, 32);          // video_object_start_code
183                  }                  } else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) {
                 else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE)  
                 {  
184                          // DEBUG("video_object_layer");                          // DEBUG("video_object_layer");
185                          BitstreamSkip(bs, 32);                                  // video_object_layer_start_code                          BitstreamSkip(bs, 32);                                  // video_object_layer_start_code
186    
187                          BitstreamSkip(bs, 1);                                   // random_accessible_vol                          BitstreamSkip(bs, 1);                                   // random_accessible_vol
188    
189                          // video_object_type_indication                          // video_object_type_indication
190                          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  
191                          {                          {
192                                  DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8));                                  DEBUG1("video_object_type_indication not supported",
193                                               BitstreamShowBits(bs, 8));
194                                  return -1;                                  return -1;
195                          }                          }
196                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
# Line 208  Line 201 
201                                  DEBUG("+ is_object_layer_identifier");                                  DEBUG("+ is_object_layer_identifier");
202                                  vol_ver_id = BitstreamGetBits(bs,4);            // video_object_layer_verid                                  vol_ver_id = BitstreamGetBits(bs,4);            // video_object_layer_verid
203                                  BitstreamSkip(bs, 3);                                   // video_object_layer_priority                                  BitstreamSkip(bs, 3);                                   // video_object_layer_priority
204                          }                          } else {
                         else  
                         {  
205                                  vol_ver_id = 1;                                  vol_ver_id = 1;
206                          }                          }
207                          //DEBUGI("vol_ver_id", vol_ver_id);                          //DEBUGI("vol_ver_id", vol_ver_id);
# Line 248  Line 239 
239                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
240                          // DEBUG1("shape", dec->shape);                          // DEBUG1("shape", dec->shape);
241    
242                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1)                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {
                         {  
243                                  BitstreamSkip(bs, 4);           // video_object_layer_shape_extension                                  BitstreamSkip(bs, 4);           // video_object_layer_shape_extension
244                          }                          }
245    
# Line 259  Line 249 
249                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution
250                          time_increment_resolution--;                          time_increment_resolution--;
251                          //DEBUG1("time_increment_resolution=",time_increment_resolution);                          //DEBUG1("time_increment_resolution=",time_increment_resolution);
252                          if (time_increment_resolution > 0)                          if (time_increment_resolution > 0) {
                         {  
253                                  dec->time_inc_bits = log2bin(time_increment_resolution);                                  dec->time_inc_bits = log2bin(time_increment_resolution);
254                          }                          } else {
                         else  
                         {  
255                                  // dec->time_inc_bits = 0;                                  // dec->time_inc_bits = 0;
256    
257                                  // for "old" xvid compatibility, set time_inc_bits = 1                                  // for "old" xvid compatibility, set time_inc_bits = 1
# Line 278  Line 265 
265                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment
266                          }                          }
267    
268                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
                         {  
269    
270                                  if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)                                  if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) {
                                 {  
271                                          uint32_t width, height;                                          uint32_t width, height;
272    
273                                          READ_MARKER();                                          READ_MARKER();
# Line 293  Line 278 
278                                          //DEBUGI("height", height);                                          //DEBUGI("height", height);
279                                          READ_MARKER();                                          READ_MARKER();
280    
281                                          if (width != dec->width || height != dec->height)                                          if (width != dec->width || height != dec->height) {
                                         {  
282                                                  DEBUG("FATAL: video dimension discrepancy ***");                                                  DEBUG("FATAL: video dimension discrepancy ***");
283                                                  DEBUG2("bitstream width/height", width, height);                                                  DEBUG2("bitstream width/height", width, height);
284                                                  DEBUG2("param width/height", dec->width, dec->height);                                                  DEBUG2("param width/height", dec->width, dec->height);
# Line 303  Line 287 
287    
288                                  }                                  }
289    
290                                  if ((dec->interlacing = BitstreamGetBit(bs)))                                  if ((dec->interlacing = BitstreamGetBit(bs))) {
                                 {  
291                                          DEBUG("vol: interlacing");                                          DEBUG("vol: interlacing");
292                                  }                                  }
293    
# Line 321  Line 304 
304                                          return -1;                                          return -1;
305                                  }                                  }
306    
307                                  if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)                                  if (vol_ver_id != 1 &&
308                                  {                                          dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
309                                          BitstreamSkip(bs, 1);                                   // sadct_disable                                          BitstreamSkip(bs, 1);                                   // sadct_disable
310                                  }                                  }
311    
# Line 331  Line 314 
314                                          DEBUG("+ not_8_bit [IGNORED/TODO]");                                          DEBUG("+ not_8_bit [IGNORED/TODO]");
315                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision
316                                          BitstreamSkip(bs, 4);                                           // bits_per_pixel                                          BitstreamSkip(bs, 4);                                           // bits_per_pixel
317                                  }                                  } else {
                                 else  
                                 {  
318                                          dec->quant_bits = 5;                                          dec->quant_bits = 5;
319                                  }                                  }
320    
321                                  if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)                                  if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
                                 {  
322                                          BitstreamSkip(bs, 1);                   // no_gray_quant_update                                          BitstreamSkip(bs, 1);                   // no_gray_quant_update
323                                          BitstreamSkip(bs, 1);                   // composition_method                                          BitstreamSkip(bs, 1);                   // composition_method
324                                          BitstreamSkip(bs, 1);                   // linear_composition                                          BitstreamSkip(bs, 1);                   // linear_composition
# Line 347  Line 327 
327                                  dec->quant_type = BitstreamGetBit(bs);          // quant_type                                  dec->quant_type = BitstreamGetBit(bs);          // quant_type
328                                  // DEBUG1("**** quant_type", dec->quant_type);                                  // DEBUG1("**** quant_type", dec->quant_type);
329    
330                                  if (dec->quant_type)                                  if (dec->quant_type) {
                                 {  
331                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat                                          if (BitstreamGetBit(bs))                // load_intra_quant_mat
332                                          {                                          {
333                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
334    
335                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
336                                                  set_intra_matrix(matrix);                                                  set_intra_matrix(matrix);
337                                          }                                          } else
                                         else  
338                                                  set_intra_matrix(get_default_intra_matrix());                                                  set_intra_matrix(get_default_intra_matrix());
339    
340                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat                                          if (BitstreamGetBit(bs))                // load_inter_quant_mat
341                                          {                                          {
342                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
343    
344                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
345                                                  set_inter_matrix(matrix);                                                  set_inter_matrix(matrix);
346                                          }                                          } else
                                         else  
347                                                  set_inter_matrix(get_default_inter_matrix());                                                  set_inter_matrix(get_default_inter_matrix());
348    
349                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
                                         {  
350                                                  // TODO                                                  // TODO
351                                                  DEBUG("TODO: grayscale matrix stuff");                                                  DEBUG("TODO: grayscale matrix stuff");
352                                                  return -1;                                                  return -1;
# Line 377  Line 355 
355                                  }                                  }
356    
357    
358                                  if (vol_ver_id != 1)                                  if (vol_ver_id != 1) {
                                 {  
359                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe
360                                          if (dec->quarterpel)                                          if (dec->quarterpel) {
                                         {  
361                                                  DEBUG("IGNORED/TODO: quarter_sample");                                                  DEBUG("IGNORED/TODO: quarter_sample");
362                                          }                                          }
363                                  }                                  } else {
                                 else  
                                 {  
364                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
365                                  }                                  }
366    
# Line 409  Line 383 
383                                          BitstreamSkip(bs, 1);           // reversible_vlc                                          BitstreamSkip(bs, 1);           // reversible_vlc
384                                  }                                  }
385    
386                                  if (vol_ver_id != 1)                                  if (vol_ver_id != 1) {
                                 {  
387                                          if (BitstreamGetBit(bs))                        // newpred_enable                                          if (BitstreamGetBit(bs))                        // newpred_enable
388                                          {                                          {
389                                                  DEBUG("+ newpred_enable");                                                  DEBUG("+ newpred_enable");
# Line 431  Line 404 
404                                          DEBUG("TODO: scalability");                                          DEBUG("TODO: scalability");
405                                          return -1;                                          return -1;
406                                  }                                  }
407                          }                          } else                          // dec->shape == BINARY_ONLY
                         else    // dec->shape == BINARY_ONLY  
                         {  
                                 if (vol_ver_id != 1)  
408                                  {                                  {
409                                    if (vol_ver_id != 1) {
410                                          if (BitstreamGetBit(bs))        // scalability                                          if (BitstreamGetBit(bs))        // scalability
411                                          {                                          {
412                                                  // TODO                                                  // TODO
# Line 447  Line 418 
418    
419                          }                          }
420    
421                  }                  } else if (start_code == GRPOFVOP_START_CODE) {
                 else if (start_code == GRPOFVOP_START_CODE)  
                 {  
422                          // DEBUG("group_of_vop");                          // DEBUG("group_of_vop");
423                          BitstreamSkip(bs, 32);                          BitstreamSkip(bs, 32);
424                          {                          {
425                                  int hours, minutes, seconds;                                  int hours, minutes, seconds;
426    
427                                  hours = BitstreamGetBits(bs, 5);                                  hours = BitstreamGetBits(bs, 5);
428                                  minutes = BitstreamGetBits(bs, 6);                                  minutes = BitstreamGetBits(bs, 6);
429                                  READ_MARKER();                                  READ_MARKER();
# Line 462  Line 432 
432                          }                          }
433                          BitstreamSkip(bs, 1);                   // closed_gov                          BitstreamSkip(bs, 1);                   // closed_gov
434                          BitstreamSkip(bs, 1);                   // broken_link                          BitstreamSkip(bs, 1);                   // broken_link
435                  }                  } else if (start_code == VOP_START_CODE) {
                 else if (start_code == VOP_START_CODE)  
                 {  
436                          // DEBUG("vop_start_code");                          // DEBUG("vop_start_code");
437                          BitstreamSkip(bs, 32);                                          // vop_start_code                          BitstreamSkip(bs, 32);                                          // vop_start_code
438    
# Line 479  Line 447 
447    
448                          //DEBUG1("time_inc_bits", dec->time_inc_bits);                          //DEBUG1("time_inc_bits", dec->time_inc_bits);
449                          //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));                          //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));
450                          if (dec->time_inc_bits)                          if (dec->time_inc_bits) {
                         {  
451                                  //BitstreamSkip(bs, dec->time_inc_bits);        // vop_time_increment                                  //BitstreamSkip(bs, dec->time_inc_bits);        // vop_time_increment
452                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment
453                          }                          }
454                          if(coding_type != B_VOP){                          if(coding_type != B_VOP){
455                              dec->last_time_base = dec->time_base;                              dec->last_time_base = dec->time_base;
456                                  dec->time_base += time_incr;                                  dec->time_base += time_incr;
457                                  dec->time = dec->time_base*time_increment_resolution + time_increment;                                  dec->time =
458                                            dec->time_base * time_increment_resolution +
459                                            time_increment;
460                                  dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time);                                  dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time);
461                                  dec->last_non_b_time= dec->time;                                  dec->last_non_b_time= dec->time;
462                          }else{                          }else{
463                                  dec->time = (dec->last_time_base + time_incr)*time_increment_resolution + time_increment;                                  dec->time =
464                                            (dec->last_time_base +
465                                             time_incr) * time_increment_resolution + time_increment;
466                                  dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time);                                  dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time);
467                          }                          }
468                          //DEBUG1("time_increment=",time_increment);                          //DEBUG1("time_increment=",time_increment);
# Line 509  Line 480 
480                          */                          */
481    
482                          // fix a little bug by MinChen <chenm002@163.com>                          // fix a little bug by MinChen <chenm002@163.com>
483                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && (coding_type == P_VOP))                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
484                          {                                  (coding_type == P_VOP)) {
485                                  *rounding = BitstreamGetBit(bs);        // rounding_type                                  *rounding = BitstreamGetBit(bs);        // rounding_type
486                                  //DEBUG1("rounding", *rounding);                                  //DEBUG1("rounding", *rounding);
487                          }                          }
# Line 520  Line 491 
491                          }                          }
492                          */                          */
493    
494                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
                         {  
495                                  uint32_t width, height;                                  uint32_t width, height;
496                                  uint32_t horiz_mc_ref, vert_mc_ref;                                  uint32_t horiz_mc_ref, vert_mc_ref;
497    
# Line 545  Line 515 
515                          }                          }
516    
517    
518                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
                         {  
519                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
520                                  *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];                                  *intra_dc_threshold =
521                                            intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
522    
523                                  if (dec->interlacing)                                  if (dec->interlacing) {
524                                  {                                          if ((dec->top_field_first = BitstreamGetBit(bs))) {
                                         if ((dec->top_field_first = BitstreamGetBit(bs)))  
                                         {  
525                                                  DEBUG("vop: top_field_first");                                                  DEBUG("vop: top_field_first");
526                                          }                                          }
527                                          if ((dec->alternate_vertical_scan = BitstreamGetBit(bs)))                                          if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) {
                                         {  
528                                                  DEBUG("vop: alternate_vertical_scan");                                                  DEBUG("vop: alternate_vertical_scan");
529                                          }                                          }
530                                  }                                  }
# Line 568  Line 535 
535    
536                          //DEBUG1("quant", *quant);                          //DEBUG1("quant", *quant);
537    
538                          if (coding_type != I_VOP)                          if (coding_type != I_VOP) {
                         {  
539                                  *fcode_forward = BitstreamGetBits(bs, 3);               // fcode_forward                                  *fcode_forward = BitstreamGetBits(bs, 3);               // fcode_forward
540                          }                          }
541    
542                          if (coding_type == B_VOP)                          if (coding_type == B_VOP) {
                         {  
543                                  *fcode_backward = BitstreamGetBits(bs, 3);              // fcode_backward                                  *fcode_backward = BitstreamGetBits(bs, 3);              // fcode_backward
544                          }                          }
545                          if (!dec->scalability){                          if (!dec->scalability){
546                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && (coding_type != I_VOP)){                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&
547                                            (coding_type != I_VOP)) {
548                                          BitstreamSkip(bs, 1);           // vop_shape_coding_type                                          BitstreamSkip(bs, 1);           // vop_shape_coding_type
549                                  }                                  }
550                          }                          }
551                          return coding_type;                          return coding_type;
552                  }                  } else if (start_code == USERDATA_START_CODE) {
                 else if (start_code == USERDATA_START_CODE)  
                 {  
553                          // DEBUG("user_data");                          // DEBUG("user_data");
554                          BitstreamSkip(bs, 32);          // user_data_start_code                          BitstreamSkip(bs, 32);          // user_data_start_code
555                  }                  } else                                  // start_code == ?
                 else  // start_code == ?  
                 {  
                         if (BitstreamShowBits(bs, 24) == 0x000001)  
556                          {                          {
557                                  DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32));                          if (BitstreamShowBits(bs, 24) == 0x000001) {
558                                    DEBUG1("*** WARNING: unknown start_code",
559                                               BitstreamShowBits(bs, 32));
560                          }                          }
561                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
562                  }                  }
# Line 607  Line 570 
570    
571  /* write custom quant matrix */  /* write custom quant matrix */
572    
573  static void bs_put_matrix(Bitstream * bs, const int16_t *matrix)  static void
574    bs_put_matrix(Bitstream * bs,
575                              const int16_t * matrix)
576  {  {
577          int i, j;          int i, j;
578          const int last = matrix[scan_tables[0][63]];          const int last = matrix[scan_tables[0][63]];
579    
580          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--) ;
581    
582          for (i = 0; i <= j; i++)          for (i = 0; i <= j; i++) {
         {  
583                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);
584          }          }
585    
586          if (j < 63)          if (j < 63) {
         {  
587                  BitstreamPutBits(bs, 0, 8);                  BitstreamPutBits(bs, 0, 8);
588          }          }
589  }  }
# Line 629  Line 592 
592  /*  /*
593          write vol header          write vol header
594  */  */
595  void BitstreamWriteVolHeader(Bitstream * const bs,  void
596                                                  const MBParam * pParam,  const FRAMEINFO * frame)  BitstreamWriteVolHeader(Bitstream * const bs,
597                                                    const MBParam * pParam,
598                                                    const FRAMEINFO * frame)
599  {  {
600          // video object_start_code & vo_id          // video object_start_code & vo_id
601      BitstreamPad(bs);      BitstreamPad(bs);
# Line 647  Line 612 
612          BitstreamPutBits(bs, 1, 4);                     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);                     // aspect_ratio_info (1=1:1)
613    
614  #ifdef BFRAMES  #ifdef BFRAMES
615          if (pParam->max_bframes > 0)          if (pParam->max_bframes > 0) {
         {  
616                  dprintf("low_delay=1");                  dprintf("low_delay=1");
617                  BitstreamPutBit(bs, 1);                         // vol_control_parameters                  BitstreamPutBit(bs, 1);                         // vol_control_parameters
618                  BitstreamPutBits(bs, 1, 2);                     // chroma_format 1="4:2:0"                  BitstreamPutBits(bs, 1, 2);                     // chroma_format 1="4:2:0"
619                  BitstreamPutBit(bs, 0);                         // low_delay                  BitstreamPutBit(bs, 0);                         // low_delay
620                  BitstreamPutBit(bs, 0);                         // vbv_parameters (0=not given)                  BitstreamPutBit(bs, 0);                         // vbv_parameters (0=not given)
621          }          } else
         else  
622  #endif  #endif
623          {          {
624                  BitstreamPutBits(bs, 0, 1);                     // vol_control_parameters (0=not given)                  BitstreamPutBits(bs, 0, 1);                     // vol_control_parameters (0=not given)
# Line 699  Line 662 
662          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
663          BitstreamPutBit(bs, pParam->m_quant_type);          BitstreamPutBit(bs, pParam->m_quant_type);
664    
665          if (pParam->m_quant_type)          if (pParam->m_quant_type) {
         {  
666                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
667                  if (get_intra_matrix_status())                  if (get_intra_matrix_status()) {
                 {  
668                          bs_put_matrix(bs, get_intra_matrix());                          bs_put_matrix(bs, get_intra_matrix());
669                  }                  }
670    
671                  BitstreamPutBit(bs, get_inter_matrix_status());         // load_inter_quant_mat                  BitstreamPutBit(bs, get_inter_matrix_status());         // load_inter_quant_mat
672                  if (get_inter_matrix_status())                  if (get_inter_matrix_status()) {
                 {  
673                          bs_put_matrix(bs, get_inter_matrix());                          bs_put_matrix(bs, get_inter_matrix());
674                  }                  }
675    
# Line 730  Line 690 
690    time_inc = nth of a second since last resync    time_inc = nth of a second since last resync
691    (decoder uses these values to determine precise time since last resync)    (decoder uses these values to determine precise time since last resync)
692  */  */
693  void BitstreamWriteVopHeader(Bitstream * const bs,  void
694    BitstreamWriteVopHeader(Bitstream * const bs,
695                                                  const MBParam * pParam,                                                  const MBParam * pParam,
696                                                  const FRAMEINFO * frame)                                                  const FRAMEINFO * frame)
697  {  {
# Line 744  Line 705 
705    
706          // time_base = 0  write n x PutBit(1), PutBit(0)          // time_base = 0  write n x PutBit(1), PutBit(0)
707  #ifdef BFRAMES  #ifdef BFRAMES
708          for (i = 0; i < frame->seconds; i++)          for (i = 0; i < frame->seconds; i++) {
         {  
709                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
710          }          }
711          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 0);
# Line 758  Line 718 
718          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
719  #ifdef BFRAMES  #ifdef BFRAMES
720          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
721          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,
722                            frame->coding_type == I_VOP ? 'I' : frame->coding_type ==
723                            P_VOP ? 'P' : 'B');
724  #else  #else
725          BitstreamPutBits(bs, 1, 1);          BitstreamPutBits(bs, 1, 1);
726  #endif  #endif
# Line 772  Line 734 
734    
735          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);                             // intra_dc_vlc_threshold
736    
737          if (frame->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
         {  
738                  BitstreamPutBit(bs, 1);         // top field first                  BitstreamPutBit(bs, 1);         // top field first
739                  BitstreamPutBit(bs, 0);         // alternate vertical scan                  BitstreamPutBit(bs, 0);         // alternate vertical scan
740          }          }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.15

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