[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.28, Tue Sep 3 17:25:45 2002 UTC revision 1.28.2.5, Thu Nov 7 10:28:15 2002 UTC
# Line 41  Line 41 
41    *                                                                            *    *                                                                            *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  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           *    *  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)               *    *             or dec->height is 0  (for use in examples/ex1.c)               *
48    *             MinChen <chenm001@163.com>                                     *    *             MinChen <chenm001@163.com>                                     *
# Line 60  Line 62 
62    *      30.02.2002     intra_dc_threshold support                             *    *      30.02.2002     intra_dc_threshold support                             *
63    *      04.12.2001     support for additional headers                         *    *      04.12.2001     support for additional headers                         *
64    *      16.12.2001     inital version                                         *    *      16.12.2001     inital version                                         *
65    *    *                                                                                                                                                        *
66    ******************************************************************************/    ******************************************************************************/
67    
68    
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 uint32_t __inline  static uint32_t __inline
# Line 128  Line 131 
131  // for BVOP addbits == max(fcode,bcode) - 1  // for BVOP addbits == max(fcode,bcode) - 1
132  // returns mbpos  // returns mbpos
133  int  int
134  read_video_packet_header(Bitstream *bs, const int addbits, int * quant)  read_video_packet_header(Bitstream *bs,
135                                                    DECODER * dec,
136                                                    const int addbits,
137                                                    int * quant,
138                                                    int * fcode_forward,
139                                                    int  * fcode_backward,
140                                                    int * intra_dc_threshold)
141  {  {
142          int nbits;          int startcode_bits = NUMBITS_VP_RESYNC_MARKER + addbits;
143            int mbnum_bits = log2bin(dec->mb_width *  dec->mb_height - 1);
144          int mbnum;          int mbnum;
145          int hec;          int hec = 0;
   
         nbits = NUMBITS_VP_RESYNC_MARKER + addbits;  
146    
147          BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs));          BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs));
148          BitstreamSkip(bs, nbits);          BitstreamSkip(bs, startcode_bits);
149    
150          DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>");          DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>");
151    
152          // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
153                  // hec          {
154                  // vop_width                  hec = BitstreamGetBit(bs);              /* header_extension_code */
155                  // marker_bit                  if (hec && !(dec->sprite_enable == SPRITE_STATIC /* && current_coding_type = I_VOP */))
156                  // vop_height                  {
157                  // marker_bit                          BitstreamSkip(bs, 13);                  /* vop_width */
158                            READ_MARKER();
159          //}                          BitstreamSkip(bs, 13);                  /* vop_height */
160                            READ_MARKER();
161                            BitstreamSkip(bs, 13);                  /* vop_horizontal_mc_spatial_ref */
162                            READ_MARKER();
163                            BitstreamSkip(bs, 13);                  /* vop_vertical_mc_spatial_ref */
164                            READ_MARKER();
165                    }
166            }
167    
168          mbnum = BitstreamGetBits(bs, 9);          mbnum = BitstreamGetBits(bs, mbnum_bits);               /* macroblock_number */
169          DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum);          DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum);
170    
171          // if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY)          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
172          *quant = BitstreamGetBits(bs, 5);          {
173                    *quant = BitstreamGetBits(bs, 5);       /* quant_scale */
174          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
175            }
176    
177            if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)
178                    hec = BitstreamGetBit(bs);              /* header_extension_code */
179    
180    
         // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)  
         hec = BitstreamGetBit(bs);  
181          DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec);          DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec);
182          // if (hec)          if (hec)
183          //   .. decoder hec-header ...          {
184                    int time_base;
185                    int time_increment;
186                    int coding_type;
187    
188                    for (time_base=0; BitstreamGetBit(bs)!=0; time_base++);         /* modulo_time_base */
189                    READ_MARKER();
190                    if (dec->time_inc_bits)
191                            time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    /* vop_time_increment */
192                    READ_MARKER();
193                    DPRINTF(DPRINTF_HEADER,"time %i:%i", time_base, time_increment);
194    
195                    coding_type = BitstreamGetBits(bs, 2);
196                    DPRINTF(DPRINTF_HEADER,"coding_type %i", coding_type);
197    
198                    if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
199                    {
200                            BitstreamSkip(bs, 1);   /* change_conv_ratio_disable */
201                            if (coding_type != I_VOP)
202                                    BitstreamSkip(bs, 1);   /* vop_shape_coding_type */
203                    }
204    
205                    if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
206                    {
207                            *intra_dc_threshold = intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
208    
209                            if (dec->sprite_enable == SPRITE_GMC && coding_type == S_VOP &&
210                                    dec->sprite_warping_points > 0)
211                            {
212                                    // TODO: sprite trajectory
213                            }
214                            if (dec->reduced_resolution_enable &&
215                                    dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&
216                                    (coding_type == P_VOP || coding_type == I_VOP))
217                            {
218                                    BitstreamSkip(bs, 1); /* vop_reduced_resolution */
219                            }
220    
221                            if (coding_type != I_VOP && fcode_forward)
222                            {
223                                    *fcode_forward = BitstreamGetBits(bs, 3);
224                                    DPRINTF(DPRINTF_HEADER,"fcode_forward %i", *fcode_forward);
225                            }
226    
227                            if (coding_type == B_VOP && fcode_backward)
228                            {
229                                    *fcode_backward = BitstreamGetBits(bs, 3);
230                                    DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward);
231                            }
232                    }
233    
234            }
235    
236            if (dec->newpred_enable)
237            {
238                    int vop_id;
239                    int vop_id_for_prediction;
240    
241                    vop_id = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));
242                    DPRINTF(DPRINTF_HEADER, "vop_id %i", vop_id);
243                    if (BitstreamGetBit(bs))        /* vop_id_for_prediction_indication */
244                    {
245                            vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));
246                            DPRINTF(DPRINTF_HEADER, "vop_id_for_prediction %i", vop_id_for_prediction);
247                    }
248                    READ_MARKER();
249            }
250    
251          return mbnum;          return mbnum;
252  }  }
# Line 180  Line 265 
265  BitstreamReadHeaders(Bitstream * bs,  BitstreamReadHeaders(Bitstream * bs,
266                                           DECODER * dec,                                           DECODER * dec,
267                                           uint32_t * rounding,                                           uint32_t * rounding,
268                                             uint32_t * reduced_resolution,
269                                           uint32_t * quant,                                           uint32_t * quant,
270                                           uint32_t * fcode_forward,                                           uint32_t * fcode_forward,
271                                           uint32_t * fcode_backward,                                           uint32_t * fcode_backward,
272                                           uint32_t * intra_dc_threshold)                                           uint32_t * intra_dc_threshold,
273                                             VECTOR * gmc_mv)
274  {  {
275          uint32_t vol_ver_id;          uint32_t vol_ver_id;
         static uint32_t time_increment_resolution;  
276          uint32_t coding_type;          uint32_t coding_type;
277          uint32_t start_code;          uint32_t start_code;
278          uint32_t time_incr = 0;          uint32_t time_incr = 0;
279          int32_t time_increment;          int32_t time_increment;
280            int resize = 0;
281    
282          do {          do {
283    
284                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
285                  start_code = BitstreamShowBits(bs, 32);                  start_code = BitstreamShowBits(bs, 32);
286    
# Line 266  Line 354 
354                          BitstreamSkip(bs, 1);   // random_accessible_vol                          BitstreamSkip(bs, 1);   // random_accessible_vol
355    
356                          // video_object_type_indication                          // video_object_type_indication
357                          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                          if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE &&
358                                    BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE &&
359                                    BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN &&
360                                    BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ACE &&
361                                    BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE &&
362                                    BitstreamShowBits(bs, 8) != 0)  // BUGGY DIVX
363                          {                          {
364                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",
365                                          BitstreamShowBits(bs, 8));                                          BitstreamShowBits(bs, 8));
# Line 285  Line 378 
378                                  vol_ver_id = 1;                                  vol_ver_id = 1;
379                          }                          }
380    
381                          if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR)     // aspect_ratio_info                          dec->aspect_ratio = BitstreamGetBits(bs, 4);
382    
383                            if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR)   // aspect_ratio_info
384                          {                          {
385                                  DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info");                                  DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info");
386                                  BitstreamSkip(bs, 8);   // par_width                                  dec->par_width = BitstreamGetBits(bs, 8);       // par_width
387                                  BitstreamSkip(bs, 8);   // par_height                                  dec->par_height = BitstreamGetBits(bs, 8);      // par_height
388                          }                          }
389    
390                          if (BitstreamGetBit(bs))        // vol_control_parameters                          if (BitstreamGetBit(bs))        // vol_control_parameters
# Line 312  Line 407 
407                                          READ_MARKER();                                          READ_MARKER();
408                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy
409                                          READ_MARKER();                                          READ_MARKER();
   
410                                  }                                  }
411                          }                          }
412    
413                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
414    
415                          DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape);                          DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape);
416                            if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
417                            {
418                                    DPRINTF(DPRINTF_ERROR,"non-rectangular shapes are not supported");
419                            }
420    
421                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {
422                                  BitstreamSkip(bs, 4);   // video_object_layer_shape_extension                                  BitstreamSkip(bs, 4);   // video_object_layer_shape_extension
# Line 326  Line 425 
425                          READ_MARKER();                          READ_MARKER();
426    
427  // *************************** for decode B-frame time ***********************  // *************************** for decode B-frame time ***********************
428                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution                          dec->time_inc_resolution = BitstreamGetBits(bs, 16);    // vop_time_increment_resolution
429                            DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", dec->time_inc_resolution);
430    
431                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution);  //                      dec->time_inc_resolution--;
432    
433  //                      time_increment_resolution--;                          if (dec->time_inc_resolution > 0) {
434                                    dec->time_inc_bits = log2bin(dec->time_inc_resolution-1);
                         if (time_increment_resolution > 0) {  
                                 dec->time_inc_bits = log2bin(time_increment_resolution-1);  
435                          } else {                          } else {
436                                  // dec->time_inc_bits = 0;                                  // dec->time_inc_bits = 0;
437                                  // for "old" xvid compatibility, set time_inc_bits = 1                                  // for "old" xvid compatibility, set time_inc_bits = 1
# Line 362  Line 460 
460                                          DPRINTF(DPRINTF_HEADER, "width %i", width);                                          DPRINTF(DPRINTF_HEADER, "width %i", width);
461                                          DPRINTF(DPRINTF_HEADER, "height %i", height);                                          DPRINTF(DPRINTF_HEADER, "height %i", height);
462    
463                                          // for auto set width & height                                          if (dec->width != width || dec->height != height)
464                                          if (dec->width == 0)                                          {
465                                                  dec->width = width;                                                  if (dec->fixed_dimensions)
466                                          if (dec->height == 0)                                                  {
                                                 dec->height = height;  
   
                                         if (width != dec->width || height != dec->height) {  
467                                                  DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");                                                  DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");
468                                                  return -1;                                                  return -1;
469                                          }                                          }
470                                                    resize = 1;
471                                                    dec->width = width;
472                                                    dec->height = height;
473                                            }
474                                  }                                  }
475    
476                                  dec->interlacing = BitstreamGetBit(bs);                                  dec->interlacing = BitstreamGetBit(bs);
477                                  DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing);                                  DPRINTF(DPRINTF_HEADER, "interlacing %i", dec->interlacing);
478    
479                                  if (!BitstreamGetBit(bs))       // obmc_disable                                  if (!BitstreamGetBit(bs))       // obmc_disable
480                                  {                                  {
# Line 385  Line 483 
483                                          // fucking divx4.02 has this enabled                                          // fucking divx4.02 has this enabled
484                                  }                                  }
485    
486                                  if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)))    // sprite_enable                                  dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2));   // sprite_enable
487    
488                                    if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC)
489                                  {                                  {
490                                          DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported");                                          int low_latency_sprite_enable;
491                                          return -1;  
492                                            if (dec->sprite_enable != SPRITE_GMC)
493                                            {
494                                                    int sprite_width;
495                                                    int sprite_height;
496                                                    int sprite_left_coord;
497                                                    int sprite_top_coord;
498                                                    sprite_width = BitstreamGetBits(bs, 13);                // sprite_width
499                                                    READ_MARKER();
500                                                    sprite_height = BitstreamGetBits(bs, 13);       // sprite_height
501                                                    READ_MARKER();
502                                                    sprite_left_coord = BitstreamGetBits(bs, 13);   // sprite_left_coordinate
503                                                    READ_MARKER();
504                                                    sprite_top_coord = BitstreamGetBits(bs, 13);    // sprite_top_coordinate
505                                                    READ_MARKER();
506                                            }
507                                            dec->sprite_warping_points = BitstreamGetBits(bs, 6);           // no_of_sprite_warping_points
508                                            dec->sprite_warping_accuracy = BitstreamGetBits(bs, 2);         // sprite_warping_accuracy
509                                            dec->sprite_brightness_change = BitstreamGetBits(bs, 1);                // brightness_change
510                                            if (dec->sprite_enable != SPRITE_GMC)
511                                            {
512                                                    low_latency_sprite_enable = BitstreamGetBits(bs, 1);            // low_latency_sprite_enable
513                                            }
514                                  }                                  }
515    
516                                  if (vol_ver_id != 1 &&                                  if (vol_ver_id != 1 &&
# Line 446  Line 568 
568    
569    
570                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
                                         DEBUG("QUARTERPEL BITSTREAM");  
571                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sample                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sample
572                                            DPRINTF(DPRINTF_HEADER,"quarterpel %i", dec->quarterpel);
573                                  }                                  }
574                                  else                                  else
575                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
# Line 468  Line 590 
590                                  }                                  }
591    
592                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
593                                          if (BitstreamGetBit(bs))        // newpred_enable                                          dec->newpred_enable = BitstreamGetBit(bs);
594                                            if (dec->newpred_enable)        // newpred_enable
595                                          {                                          {
596                                                  DPRINTF(DPRINTF_HEADER, "+ newpred_enable");                                                  DPRINTF(DPRINTF_HEADER, "+ newpred_enable");
597                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type
598                                                  BitstreamSkip(bs, 1);   // newpred_segment_type                                                  BitstreamSkip(bs, 1);   // newpred_segment_type
599                                          }                                          }
600                                          if (BitstreamGetBit(bs))        // reduced_resolution_vop_enable                                          dec->reduced_resolution_enable = BitstreamGetBit(bs);
601                                            if (dec->reduced_resolution_enable)     // reduced_resolution_vop_enable
602                                          {                                          {
603                                                  DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");                                                  DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");
604                                                  return -1;                                                  //return -1;
605                                            }
606                                          }                                          }
607                                    else
608                                    {
609                                            dec->newpred_enable = 0;
610                                            dec->reduced_resolution_enable = 0;
611                                  }                                  }
612    
613                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability
# Line 499  Line 628 
628    
629                          }                          }
630    
631                            return (resize ? -3 : -2 );     /* VOL */
632    
633                  } else if (start_code == GRPOFVOP_START_CODE) {                  } else if (start_code == GRPOFVOP_START_CODE) {
634    
635                          DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>");                          DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>");
# Line 540  Line 671 
671                          DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment);                          DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment);
672    
673                          DPRINTF(DPRINTF_TIMECODE, "%c %i:%i",                          DPRINTF(DPRINTF_TIMECODE, "%c %i:%i",
674                                  coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B',                                  coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : coding_type == B_VOP ? 'B' : 'S',
675                                  time_incr, time_increment);                                  time_incr, time_increment);
676    
677                          if (coding_type != B_VOP) {                          if (coding_type != B_VOP) {
# Line 548  Line 679 
679                                  dec->time_base += time_incr;                                  dec->time_base += time_incr;
680                                  dec->time = time_increment;                                  dec->time = time_increment;
681    
682  /*                                      dec->time_base * time_increment_resolution +  /*                                      dec->time_base * dec->time_inc_resolution +
683                                          time_increment;                                          time_increment;
684  */                              dec->time_pp = (uint32_t)  */                              dec->time_pp = (uint32_t)
685                                          (time_increment_resolution + dec->time - dec->last_non_b_time)%time_increment_resolution;                                          (dec->time_inc_resolution + dec->time - dec->last_non_b_time)%dec->time_inc_resolution;
686                                  dec->last_non_b_time = dec->time;                                  dec->last_non_b_time = dec->time;
687                          } else {                          } else {
688                                  dec->time = time_increment;                                  dec->time = time_increment;
689  /*  /*
690                                          (dec->last_time_base +                                          (dec->last_time_base +
691                                           time_incr) * time_increment_resolution + time_increment;                                           time_incr) * dec->time_inc_resolution + time_increment;
692  */  */
693                                  dec->time_bp = (uint32_t)                                  dec->time_bp = (uint32_t)
694                                          (time_increment_resolution + dec->last_non_b_time - dec->time)%time_increment_resolution;                                          (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;
695                          }                          }
696    
697                          READ_MARKER();                          READ_MARKER();
# Line 571  Line 702 
702                                  return N_VOP;                                  return N_VOP;
703                          }                          }
704    
705                          /* if (newpred_enable)                          if (dec->newpred_enable)
706                             {                             {
707                                    int vop_id;
708                                    int vop_id_for_prediction;
709    
710                                    vop_id = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));
711                                    DPRINTF(DPRINTF_HEADER, "vop_id %i", vop_id);
712                                    if (BitstreamGetBit(bs))        /* vop_id_for_prediction_indication */
713                                    {
714                                            vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));
715                                            DPRINTF(DPRINTF_HEADER, "vop_id_for_prediction %i", vop_id_for_prediction);
716                             }                             }
717                           */                                  READ_MARKER();
718                            }
719    
720    
721    
722                          // fix a little bug by MinChen <chenm002@163.com>                          // fix a little bug by MinChen <chenm002@163.com>
723                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
724                                  (coding_type == P_VOP)) {                                  ( (coding_type == P_VOP) || (coding_type == S_VOP && dec->sprite_enable == SPRITE_GMC) ) ) {
725                                  *rounding = BitstreamGetBit(bs);        // rounding_type                                  *rounding = BitstreamGetBit(bs);        // rounding_type
726                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);
727                          }                          }
728    
729                          /* if (reduced_resolution_enable)                          if (dec->reduced_resolution_enable &&
730                                    dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&
731                                    (coding_type == P_VOP || coding_type == I_VOP)) {
732    
733                                    *reduced_resolution = BitstreamGetBit(bs);
734                            }
735                            else
736                             {                             {
737                                    *reduced_resolution = 0;
738                             }                             }
                          */  
739    
740                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
741                                    if(!(dec->sprite_enable == SPRITE_STATIC && coding_type == I_VOP)) {
742    
743                                  uint32_t width, height;                                  uint32_t width, height;
744                                  uint32_t horiz_mc_ref, vert_mc_ref;                                  uint32_t horiz_mc_ref, vert_mc_ref;
745    
# Line 605  Line 756 
756                                  DPRINTF(DPRINTF_HEADER, "height %i", height);                                  DPRINTF(DPRINTF_HEADER, "height %i", height);
757                                  DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref);                                  DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref);
758                                  DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref);                                  DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref);
759                                    }
760    
761                                  BitstreamSkip(bs, 1);   // change_conv_ratio_disable                                  BitstreamSkip(bs, 1);   // change_conv_ratio_disable
762                                  if (BitstreamGetBit(bs))        // vop_constant_alpha                                  if (BitstreamGetBit(bs))        // vop_constant_alpha
# Line 613  Line 765 
765                                  }                                  }
766                          }                          }
767    
   
768                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
769                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
770                                  *intra_dc_threshold =                                  *intra_dc_threshold =
771                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
772    
773                                    dec->top_field_first = 0;
774                                    dec->alternate_vertical_scan = 0;
775    
776                                  if (dec->interlacing) {                                  if (dec->interlacing) {
777                                          dec->top_field_first = BitstreamGetBit(bs);                                          dec->top_field_first = BitstreamGetBit(bs);
778                                          DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first);                                          DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first);
# Line 628  Line 782 
782                                  }                                  }
783                          }                          }
784    
785                            if ((dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable== SPRITE_GMC) && coding_type == S_VOP) {
786    
787                                    int i;
788    
789                                    for (i = 0 ; i < dec->sprite_warping_points; i++)
790                                    {
791                                            int length;
792                                            int x = 0, y = 0;
793    
794                                            /* sprite code borowed from ffmpeg; thx Michael Niedermayer <michaelni@gmx.at> */
795                                            length = bs_get_spritetrajectory(bs);
796                                            if(length){
797                                                    x= BitstreamGetBits(bs, length);
798                                                    if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/
799                                                            x = - (x ^ ((1 << length) - 1));
800                                            }
801                                            READ_MARKER();
802    
803                                            length = bs_get_spritetrajectory(bs);
804                                            if(length){
805                                                    y = BitstreamGetBits(bs, length);
806                                                    if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/
807                                                            y = - (y ^ ((1 << length) - 1));
808                                            }
809                                            READ_MARKER();
810    
811                                            gmc_mv[i].x = x;
812                                            gmc_mv[i].y = y;
813    
814                                            DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y);
815                                    }
816    
817                                    if (dec->sprite_brightness_change)
818                                    {
819                                            // XXX: brightness_change_factor()
820                                    }
821                                    if (dec->sprite_enable == SPRITE_STATIC)
822                                    {
823                                            // XXX: todo
824                                    }
825    
826                            }
827    
828                          if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1)       // vop_quant                          if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1)       // vop_quant
829                                  *quant = 1;                                  *quant = 1;
   
830                          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);                          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
831    
832                          if (coding_type != I_VOP) {                          if (coding_type != I_VOP) {
# Line 698  Line 894 
894  void  void
895  BitstreamWriteVolHeader(Bitstream * const bs,  BitstreamWriteVolHeader(Bitstream * const bs,
896                                                  const MBParam * pParam,                                                  const MBParam * pParam,
897                                                  const FRAMEINFO * frame)                                                  const FRAMEINFO * const frame)
898  {  {
899            int vol_ver_id=1;
900    
901            if ( (pParam->m_quarterpel) || (frame->global_flags & XVID_GMC) )
902                    vol_ver_id = 2;
903    
904          // video object_start_code & vo_id          // video object_start_code & vo_id
905          BitstreamPad(bs);          BitstreamPad(bs);
906          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VO_START_CODE, 27);
# Line 711  Line 912 
912    
913          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
914          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
915    
916            if (vol_ver_id == 1)
917            {
918          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)
919            }
920            else
921            {
922                    BitstreamPutBit(bs, 1);         // is_object_layer_identified
923                    BitstreamPutBits(bs, vol_ver_id, 4);    // vol_ver_id == 2
924                    BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ??
925            }
926    
927          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)
928    
929          BitstreamPutBit(bs, 1); // vol_control_parameters          BitstreamPutBit(bs, 1); // vol_control_parameters
930          BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"          BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"
931    
 #ifdef BFRAMES  
932          if (pParam->max_bframes > 0) {          if (pParam->max_bframes > 0) {
933                  BitstreamPutBit(bs, 0); // low_delay                  BitstreamPutBit(bs, 0); // low_delay
934          } else          } else
 #endif  
935          {          {
936                  BitstreamPutBit(bs, 1); // low_delay                  BitstreamPutBit(bs, 1); // low_delay
937          }          }
# Line 731  Line 941 
941    
942          WRITE_MARKER();          WRITE_MARKER();
943    
944          /* time_increment_resolution; ignored by current decore versions          /* time_inc_resolution; ignored by current decore versions
945             eg. 2fps     res=2       inc=1             eg. 2fps     res=2       inc=1
946             25fps        res=25      inc=1             25fps        res=25      inc=1
947             29.97fps res=30000   inc=1001             29.97fps res=30000   inc=1001
948           */           */
 #ifdef BFRAMES  
         BitstreamPutBits(bs, pParam->fbase, 16);  
 #else  
949          BitstreamPutBits(bs, pParam->fbase, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
 #endif  
950    
951          WRITE_MARKER();          WRITE_MARKER();
952    
 #ifdef BFRAMES  
953          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
954          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
 #else  
         BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1  
         BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment  
 #endif  
955    
956          WRITE_MARKER();          WRITE_MARKER();
957          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 760  Line 961 
961    
962          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace
963          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
964          BitstreamPutBit(bs, 0);         // sprite_enable  
965          BitstreamPutBit(bs, 0);         // not_in_bit          if (vol_ver_id != 1)
966            {       if (frame->global_flags & XVID_GMC)
967                    {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'
968                            BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points
969                            BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16
970                            BitstreamPutBit(bs, 0);                 // sprite_brightness_change (not supported)
971    
972    /* currently we use no_of_sprite_warping_points==2, sprite_warping_accuracy==3
973       for DivX5 compatability */
974    
975                    } else
976                            BitstreamPutBits(bs, 0, 2);             // sprite_enable==off
977            }
978            else
979                    BitstreamPutBit(bs, 0);         // sprite_enable==off
980    
981            BitstreamPutBit(bs, 0);         // not_8_bit
982    
983          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
984          BitstreamPutBit(bs, pParam->m_quant_type);          BitstreamPutBit(bs, pParam->m_quant_type);
# Line 779  Line 996 
996    
997          }          }
998    
999            if (vol_ver_id != 1) {
1000                    if (pParam->m_quarterpel)
1001                            BitstreamPutBit(bs, 1);         //  quarterpel
1002                    else
1003                            BitstreamPutBit(bs, 0);         // no quarterpel
1004            }
1005    
1006          BitstreamPutBit(bs, 1);         // complexity_estimation_disable          BitstreamPutBit(bs, 1);         // complexity_estimation_disable
1007          BitstreamPutBit(bs, 1);         // resync_marker_disable          BitstreamPutBit(bs, 1);         // resync_marker_disable
1008          BitstreamPutBit(bs, 0);         // data_partitioned          BitstreamPutBit(bs, 0);         // data_partitioned
1009    
1010            if (vol_ver_id != 1)
1011            {
1012                    BitstreamPutBit(bs, 0);         // newpred_enable
1013                    BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled
1014            }
1015    
1016          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1017    
1018  }  }
1019    
1020    
1021  /*  /*
1022    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)  
1023  */  */
1024  void  void
1025  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(Bitstream * const bs,
1026                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1027                                                  const FRAMEINFO * frame,                                                  const FRAMEINFO * const frame,
1028                                                  int vop_coded)                                                  int vop_coded)
1029  {  {
1030          uint32_t i;          uint32_t i;
# Line 806  Line 1033 
1033          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1034    
1035          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
1036            DPRINTF(DPRINTF_HEADER, "coding_type = %i", frame->coding_type);
1037    
         // time_base = 0  write n x PutBit(1), PutBit(0)  
 #ifdef BFRAMES  
1038          for (i = 0; i < frame->seconds; i++) {          for (i = 0; i < frame->seconds; i++) {
1039                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
1040          }          }
1041          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 0);
 #else  
         for (i = 0; i < frame->seconds; i++) {  
                 BitstreamPutBit(bs, 1);  
         }  
         BitstreamPutBit(bs, 0);  
 //      BitstreamPutBits(bs, 0, 1);  
 #endif  
1042    
1043          WRITE_MARKER();          WRITE_MARKER();
1044    
1045          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
1046  #ifdef BFRAMES  
1047          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
1048          /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,          /*DPRINTF("[%i:%i] %c", frame->seconds, frame->ticks,
1049                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==
1050                          P_VOP ? 'P' : 'B');*/                          P_VOP ? 'P' : 'B');*/
 #else  
         BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));  
 //      BitstreamPutBits(bs, 1, 1);  
 #endif  
1051    
1052          WRITE_MARKER();          WRITE_MARKER();
1053    
# Line 843  Line 1058 
1058    
1059          BitstreamPutBits(bs, 1, 1);     // vop_coded          BitstreamPutBits(bs, 1, 1);     // vop_coded
1060    
1061          if (frame->coding_type == P_VOP)          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
1062                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1063    
1064          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
1065    
1066          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
1067                  BitstreamPutBit(bs, 1); // top field first                  BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST));
1068                  BitstreamPutBit(bs, 0); // alternate vertical scan                  BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN));
1069            }
1070    
1071            if (frame->coding_type == S_VOP) {
1072                    if (1)  {               // no_of_sprite_warping_points>=1
1073                            if (pParam->m_quarterpel)
1074                                    bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]
1075                            else
1076                                    bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]
1077                            WRITE_MARKER();
1078    
1079                            if (pParam->m_quarterpel)
1080                                    bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0]
1081                            else
1082                                    bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0]
1083                            WRITE_MARKER();
1084    
1085    
1086                            if (pParam->m_quarterpel)
1087                            {
1088                                    DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2);
1089                            }
1090                            else
1091                            {
1092                                    DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y);
1093                            }
1094    
1095                    }
1096    /* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */
1097    
1098                    if (2) {                // no_of_sprite_warping_points>=2 (for DivX5 compat)
1099                            bs_put_spritetrajectory(bs, 0 );
1100                            WRITE_MARKER();
1101                            bs_put_spritetrajectory(bs, 0 );
1102                            WRITE_MARKER();
1103                    }
1104                    // no support for brightness_change!
1105          }          }
1106    
1107          BitstreamPutBits(bs, frame->quant, 5);  // quantizer          BitstreamPutBits(bs, frame->quant, 5);  // quantizer
# Line 863  Line 1114 
1114    
1115  }  }
1116    
   
1117  void  void
1118  BitstreamWriteUserData(Bitstream * const bs,  BitstreamWriteUserData(Bitstream * const bs,
1119                                                  uint8_t * data,                                                  uint8_t * data,

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.28.2.5

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