[svn] / branches / dev-api-3 / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/bitstream/bitstream.c

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

trunk/xvidcore/src/bitstream/bitstream.c revision 233, Sat Jun 22 07:23:10 2002 UTC branches/dev-api-3/xvidcore/src/bitstream/bitstream.c revision 631, Thu Nov 7 10:31:03 2002 UTC
# Line 41  Line 41 
41    *                                                                            *    *                                                                            *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44    *      22.05.2002 bs_put_matrix fix    *  28.10.2002 GMC support - gruel                                                                                        *
45      *  04.10.2002 qpel support - Isibaar                                                                             *
46      *  11.07.2002 add VOP width & height return to dec when dec->width           *
47      *             or dec->height is 0  (for use in examples/ex1.c)               *
48      *             MinChen <chenm001@163.com>                                     *
49      *  22.05.2002 bs_put_matrix fix                                              *
50    *  20.05.2002 added BitstreamWriteUserData                                   *    *  20.05.2002 added BitstreamWriteUserData                                   *
51    *  19.06.2002  Fix a little bug in use custom quant matrix                   *    *  19.06.2002  Fix a little bug in use custom quant matrix                   *
52    *              MinChen <chenm001@163.com>                                    *    *              MinChen <chenm001@163.com>                                    *
# Line 57  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 119  Line 125 
125          }          }
126  }  }
127    
128    
129    
130    // for PVOP addbits == fcode - 1
131    // for BVOP addbits == max(fcode,bcode) - 1
132    // returns mbpos
133    int
134    read_video_packet_header(Bitstream *bs,
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 startcode_bits = NUMBITS_VP_RESYNC_MARKER + addbits;
143            int mbnum_bits = log2bin(dec->mb_width *  dec->mb_height - 1);
144            int mbnum;
145            int hec = 0;
146    
147            BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs));
148            BitstreamSkip(bs, startcode_bits);
149    
150            DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>");
151    
152            if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
153            {
154                    hec = BitstreamGetBit(bs);              /* header_extension_code */
155                    if (hec && !(dec->sprite_enable == SPRITE_STATIC /* && current_coding_type = I_VOP */))
156                    {
157                            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, mbnum_bits);               /* macroblock_number */
169            DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum);
170    
171            if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
172            {
173                    *quant = BitstreamGetBits(bs, 5);       /* quant_scale */
174                    DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
175            }
176    
177            if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)
178                    hec = BitstreamGetBit(bs);              /* header_extension_code */
179    
180    
181            DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec);
182            if (hec)
183            {
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;
252    }
253    
254    
255    
256  /*  /*
257  decode headers  decode headers
258  returns coding_type, or -1 if error  returns coding_type, or -1 if error
259  */  */
260    
261    #define VIDOBJ_START_CODE_MASK          0x0000001f
262    #define VIDOBJLAY_START_CODE_MASK       0x0000000f
263    
264  int  int
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    
287                  if (start_code == VISOBJSEQ_START_CODE) {                  if (start_code == VISOBJSEQ_START_CODE) {
288                          // DPRINTF("visual_object_sequence");  
289                            int profile;
290    
291                            DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>");
292    
293                          BitstreamSkip(bs, 32);  // visual_object_sequence_start_code                          BitstreamSkip(bs, 32);  // visual_object_sequence_start_code
294                          BitstreamSkip(bs, 8);   // profile_and_level_indication                          profile = BitstreamGetBits(bs, 8);      // profile_and_level_indication
295    
296                            DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile);
297    
298                  } else if (start_code == VISOBJSEQ_STOP_CODE) {                  } else if (start_code == VISOBJSEQ_STOP_CODE) {
299    
300                          BitstreamSkip(bs, 32);  // visual_object_sequence_stop_code                          BitstreamSkip(bs, 32);  // visual_object_sequence_stop_code
301    
302                            DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");
303    
304                  } else if (start_code == VISOBJ_START_CODE) {                  } else if (start_code == VISOBJ_START_CODE) {
305                          //DPRINTF("visual_object");  
306                            DPRINTF(DPRINTF_STARTCODE, "<visual_object>");
307    
308                          BitstreamSkip(bs, 32);  // visual_object_start_code                          BitstreamSkip(bs, 32);  // visual_object_start_code
309                          if (BitstreamGetBit(bs))        // is_visual_object_identified                          if (BitstreamGetBit(bs))        // is_visual_object_identified
310                          {                          {
311                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id
312                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
313                                  BitstreamSkip(bs, 3);   // visual_object_priority                                  BitstreamSkip(bs, 3);   // visual_object_priority
314                          } else {                          } else {
315                                  vol_ver_id = 1;                                  vol_ver_id = 1;
# Line 163  Line 317 
317    
318                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type
319                          {                          {
320                                  //DPRINTF("visual_object_type != video");                                  DPRINTF(DPRINTF_ERROR, "visual_object_type != video");
321                                  return -1;                                  return -1;
322                          }                          }
323                          BitstreamSkip(bs, 4);                          BitstreamSkip(bs, 4);
# Line 172  Line 326 
326    
327                          if (BitstreamGetBit(bs))        // video_signal_type                          if (BitstreamGetBit(bs))        // video_signal_type
328                          {                          {
329                                  //DPRINTF("+ video_signal_type");                                  DPRINTF(DPRINTF_HEADER,"+ video_signal_type");
330                                  BitstreamSkip(bs, 3);   // video_format                                  BitstreamSkip(bs, 3);   // video_format
331                                  BitstreamSkip(bs, 1);   // video_range                                  BitstreamSkip(bs, 1);   // video_range
332                                  if (BitstreamGetBit(bs))        // color_description                                  if (BitstreamGetBit(bs))        // color_description
333                                  {                                  {
334                                          //DPRINTF("+ color_description");                                          DPRINTF(DPRINTF_HEADER,"+ color_description");
335                                          BitstreamSkip(bs, 8);   // color_primaries                                          BitstreamSkip(bs, 8);   // color_primaries
336                                          BitstreamSkip(bs, 8);   // transfer_characteristics                                          BitstreamSkip(bs, 8);   // transfer_characteristics
337                                          BitstreamSkip(bs, 8);   // matrix_coefficients                                          BitstreamSkip(bs, 8);   // matrix_coefficients
338                                  }                                  }
339                          }                          }
340                  } else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) {                  } else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) {
341    
342                            DPRINTF(DPRINTF_STARTCODE, "<video_object>");
343                            DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK);
344    
345                          BitstreamSkip(bs, 32);  // video_object_start_code                          BitstreamSkip(bs, 32);  // video_object_start_code
346                  } else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) {  
347                          //DPRINTF("video_object_layer");                  } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) {
348    
349                            DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>");
350                            DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK);
351    
352                          BitstreamSkip(bs, 32);  // video_object_layer_start_code                          BitstreamSkip(bs, 32);  // video_object_layer_start_code
353    
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("video_object_type_indication %i not supported ",                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",
365                                  //  BitstreamShowBits(bs, 8));                                          BitstreamShowBits(bs, 8));
366                                  return -1;                                  return -1;
367                          }                          }
368                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
# Line 203  Line 370 
370    
371                          if (BitstreamGetBit(bs))        // is_object_layer_identifier                          if (BitstreamGetBit(bs))        // is_object_layer_identifier
372                          {                          {
373                                  //DPRINTF("+ is_object_layer_identifier");                                  DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier");
374                                  vol_ver_id = BitstreamGetBits(bs, 4);   // video_object_layer_verid                                  vol_ver_id = BitstreamGetBits(bs, 4);   // video_object_layer_verid
375                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
376                                  BitstreamSkip(bs, 3);   // video_object_layer_priority                                  BitstreamSkip(bs, 3);   // video_object_layer_priority
377                          } else {                          } else {
378                                  vol_ver_id = 1;                                  vol_ver_id = 1;
379                          }                          }
                         //DPRINTF("vol_ver_id %i", vol_ver_id);  
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("+ 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
391                          {                          {
392                                  //DPRINTF("+ vol_control_parameters");                                  DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters");
393                                  BitstreamSkip(bs, 2);   // chroma_format                                  BitstreamSkip(bs, 2);   // chroma_format
394                                  dec->low_delay = BitstreamGetBit(bs);   // low_delay                                  dec->low_delay = BitstreamGetBit(bs);   // low_delay
395                                    DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
396                                  if (BitstreamGetBit(bs))        // vbv_parameters                                  if (BitstreamGetBit(bs))        // vbv_parameters
397                                  {                                  {
398                                          //DPRINTF("+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
399                                          BitstreamSkip(bs, 15);  // first_half_bitrate                                          BitstreamSkip(bs, 15);  // first_half_bitrate
400                                          READ_MARKER();                                          READ_MARKER();
401                                          BitstreamSkip(bs, 15);  // latter_half_bitrate                                          BitstreamSkip(bs, 15);  // latter_half_bitrate
# Line 237  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                          //DPRINTF("shape %i", dec->shape);  
415                            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 251  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                          time_increment_resolution--;                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", dec->time_inc_resolution);
430                          //DPRINTF("time_increment_resolution = %i",time_increment_resolution);  
431                          if (time_increment_resolution > 0) {  //                      dec->time_inc_resolution--;
432                                  dec->time_inc_bits = log2bin(time_increment_resolution);  
433                            if (dec->time_inc_resolution > 0) {
434                                    dec->time_inc_bits = log2bin(dec->time_inc_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
438                                  dec->time_inc_bits = 1;                                  dec->time_inc_bits = 1;
439                          }                          }
# Line 267  Line 442 
442    
443                          if (BitstreamGetBit(bs))        // fixed_vop_rate                          if (BitstreamGetBit(bs))        // fixed_vop_rate
444                          {                          {
445                                    DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate");
446                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment
447                          }                          }
448    
# Line 277  Line 453 
453    
454                                          READ_MARKER();                                          READ_MARKER();
455                                          width = BitstreamGetBits(bs, 13);       // video_object_layer_width                                          width = BitstreamGetBits(bs, 13);       // video_object_layer_width
                                         //DPRINTF("width %i", width);  
456                                          READ_MARKER();                                          READ_MARKER();
457                                          height = BitstreamGetBits(bs, 13);      // video_object_layer_height                                          height = BitstreamGetBits(bs, 13);      // video_object_layer_height
                                         //DPRINTF("height %i", height);  
458                                          READ_MARKER();                                          READ_MARKER();
459    
460                                          if (width != dec->width || height != dec->height) {                                          DPRINTF(DPRINTF_HEADER, "width %i", width);
461                                                  //DPRINTF("FATAL: video dimension discrepancy ***");                                          DPRINTF(DPRINTF_HEADER, "height %i", height);
462                                                  //DPRINTF("bitstream width/height  %i x %i", width, height);  
463                                                  //DPRINTF("param width/height  %i x %i", dec->width, dec->height);                                          if (dec->width != width || dec->height != height)
464                                            {
465                                                    if (dec->fixed_dimensions)
466                                                    {
467                                                            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                                  }                                  }
   
                                 if ((dec->interlacing = BitstreamGetBit(bs))) {  
                                         //DPRINTF("vol: interlacing");  
474                                  }                                  }
475    
476                                    dec->interlacing = BitstreamGetBit(bs);
477                                    DPRINTF(DPRINTF_HEADER, "interlacing %i", dec->interlacing);
478    
479                                  if (!BitstreamGetBit(bs))       // obmc_disable                                  if (!BitstreamGetBit(bs))       // obmc_disable
480                                  {                                  {
481                                          //DPRINTF("IGNORED/TODO: !obmc_disable");                                          DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported");
482                                          // TODO                                          // TODO
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("sprite_enable; 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 316  Line 520 
520    
521                                  if (BitstreamGetBit(bs))        // not_8_bit                                  if (BitstreamGetBit(bs))        // not_8_bit
522                                  {                                  {
523                                          //DPRINTF("+ not_8_bit [IGNORED/TODO]");                                          DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)");
524                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision
525                                          BitstreamSkip(bs, 4);   // bits_per_pixel                                          BitstreamSkip(bs, 4);   // bits_per_pixel
526                                  } else {                                  } else {
# Line 330  Line 534 
534                                  }                                  }
535    
536                                  dec->quant_type = BitstreamGetBit(bs);  // quant_type                                  dec->quant_type = BitstreamGetBit(bs);  // quant_type
537                                  //DPRINTF("**** quant_type %i", dec->quant_type);                                  DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type);
538    
539                                  if (dec->quant_type) {                                  if (dec->quant_type) {
540                                          if (BitstreamGetBit(bs))        // load_intra_quant_mat                                          if (BitstreamGetBit(bs))        // load_intra_quant_mat
541                                          {                                          {
542                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
543    
544                                                    DPRINTF(DPRINTF_HEADER, "load_intra_quant_mat");
545    
546                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
547                                                  set_intra_matrix(matrix);                                                  set_intra_matrix(matrix);
548                                          } else                                          } else
# Line 346  Line 552 
552                                          {                                          {
553                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
554    
555                                                    DPRINTF(DPRINTF_HEADER, "load_inter_quant_mat");
556    
557                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
558                                                  set_inter_matrix(matrix);                                                  set_inter_matrix(matrix);
559                                          } else                                          } else
560                                                  set_inter_matrix(get_default_inter_matrix());                                                  set_inter_matrix(get_default_inter_matrix());
561    
562                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
563                                                  // TODO                                                  DPRINTF(DPRINTF_ERROR, "greyscale matrix not supported");
                                                 //DPRINTF("TODO: grayscale matrix stuff");  
564                                                  return -1;                                                  return -1;
565                                          }                                          }
566    
# Line 361  Line 568 
568    
569    
570                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
571                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sample
572                                          if (dec->quarterpel) {                                          DPRINTF(DPRINTF_HEADER,"quarterpel %i", dec->quarterpel);
                                                 //DPRINTF("IGNORED/TODO: quarter_sample");  
573                                          }                                          }
574                                  } else {                                  else
575                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
576                                  }  
577    
578                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable
579                                  {                                  {
580                                          //DPRINTF("TODO: complexity_estimation header");                                          DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported");
                                         // TODO  
581                                          return -1;                                          return -1;
582                                  }                                  }
583    
584                                  if (!BitstreamGetBit(bs))       // resync_marker_disable                                  BitstreamSkip(bs, 1);   // resync_marker_disable
                                 {  
                                         //DPRINTF("IGNORED/TODO: !resync_marker_disable");  
                                         // TODO  
                                 }  
585    
586                                  if (BitstreamGetBit(bs))        // data_partitioned                                  if (BitstreamGetBit(bs))        // data_partitioned
587                                  {                                  {
588                                          //DPRINTF("+ data_partitioned");                                          DPRINTF(DPRINTF_ERROR, "data_partitioned not supported");
589                                          BitstreamSkip(bs, 1);   // reversible_vlc                                          BitstreamSkip(bs, 1);   // reversible_vlc
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("+ 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("TODO: reduced_resolution_vop_enable");                                                  DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");
604                                                  // TODO                                                  //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
614                                  {                                  {
615                                          // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                         //DPRINTF("TODO: scalability");  
616                                          return -1;                                          return -1;
617                                  }                                  }
618                          } else                          // dec->shape == BINARY_ONLY                          } else                          // dec->shape == BINARY_ONLY
# Line 414  Line 620 
620                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
621                                          if (BitstreamGetBit(bs))        // scalability                                          if (BitstreamGetBit(bs))        // scalability
622                                          {                                          {
623                                                  // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                                 //DPRINTF("TODO: scalability");  
624                                                  return -1;                                                  return -1;
625                                          }                                          }
626                                  }                                  }
# Line 423  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                          //DPRINTF("group_of_vop");  
635                            DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>");
636    
637                          BitstreamSkip(bs, 32);                          BitstreamSkip(bs, 32);
638                          {                          {
639                                  int hours, minutes, seconds;                                  int hours, minutes, seconds;
# Line 433  Line 642 
642                                  minutes = BitstreamGetBits(bs, 6);                                  minutes = BitstreamGetBits(bs, 6);
643                                  READ_MARKER();                                  READ_MARKER();
644                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
645                                  //DPRINTF("%ih %im %is", hours, minutes, seconds);  
646                                    DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);
647                          }                          }
648                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
649                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
650    
651                  } else if (start_code == VOP_START_CODE) {                  } else if (start_code == VOP_START_CODE) {
652                          //DPRINTF("vop_start_code");  
653                            DPRINTF(DPRINTF_STARTCODE, "<vop>");
654    
655                          BitstreamSkip(bs, 32);  // vop_start_code                          BitstreamSkip(bs, 32);  // vop_start_code
656    
657                          coding_type = BitstreamGetBits(bs, 2);  // vop_coding_type                          coding_type = BitstreamGetBits(bs, 2);  // vop_coding_type
658                          //DPRINTF("coding_type %i", coding_type);                          DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type);
659    
660  // *************************** for decode B-frame time ***********************  // *************************** for decode B-frame time ***********************
661                          while (BitstreamGetBit(bs) != 0)        // time_base                          while (BitstreamGetBit(bs) != 0)        // time_base
# Line 450  Line 663 
663    
664                          READ_MARKER();                          READ_MARKER();
665    
                         //DPRINTF("time_inc_bits %i", dec->time_inc_bits);  
                         //DPRINTF("vop_time_incr %i", BitstreamShowBits(bs, dec->time_inc_bits));  
666                          if (dec->time_inc_bits) {                          if (dec->time_inc_bits) {
                                 //BitstreamSkip(bs, dec->time_inc_bits);    // vop_time_increment  
667                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment
668                          }                          }
669    
670                            DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr);
671                            DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment);
672    
673                            DPRINTF(DPRINTF_TIMECODE, "%c %i:%i",
674                                    coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : coding_type == B_VOP ? 'B' : 'S',
675                                    time_incr, time_increment);
676    
677                          if (coding_type != B_VOP) {                          if (coding_type != B_VOP) {
678                                  dec->last_time_base = dec->time_base;                                  dec->last_time_base = dec->time_base;
679                                  dec->time_base += time_incr;                                  dec->time_base += time_incr;
680                                  dec->time =                                  dec->time = time_increment;
681                                          dec->time_base * time_increment_resolution +  
682    /*                                      dec->time_base * dec->time_inc_resolution +
683                                          time_increment;                                          time_increment;
684                                  dec->time_pp = (uint32_t) (dec->time - dec->last_non_b_time);  */                              dec->time_pp = (uint32_t)
685                                            (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 =                                  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                                  dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time);  */
693                                    dec->time_bp = (uint32_t)
694                                            (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;
695                          }                          }
                         //DPRINTF("time_increment %i",time_increment);  
696    
697                          READ_MARKER();                          READ_MARKER();
698    
699                          if (!BitstreamGetBit(bs))       // vop_coded                          if (!BitstreamGetBit(bs))       // vop_coded
700                          {                          {
701                                    DPRINTF(DPRINTF_HEADER, "vop_coded==false");
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("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 509  Line 752 
752                                  vert_mc_ref = BitstreamGetBits(bs, 13);                                  vert_mc_ref = BitstreamGetBits(bs, 13);
753                                  READ_MARKER();                                  READ_MARKER();
754    
755                                  //DPRINTF("vop_width/height %i x %i", width, height);                                          DPRINTF(DPRINTF_HEADER, "width %i", width);
756                                  //DPRINTF("ref              %i x %i", horiz_mc_ref, vert_mc_ref);                                          DPRINTF(DPRINTF_HEADER, "height %i", height);
757                                            DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref);
758                                            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 519  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                                          if ((dec->top_field_first = BitstreamGetBit(bs))) {                                          dec->top_field_first = BitstreamGetBit(bs);
778                                                  //DPRINTF("vop: top_field_first");                                          DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first);
779                                            dec->alternate_vertical_scan = BitstreamGetBit(bs);
780                                            DPRINTF(DPRINTF_HEADER, "interlace alternate_vertical_scan %i", dec->alternate_vertical_scan);
781    
782                                          }                                          }
                                         if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) {  
                                                 //DPRINTF("vop: alternate_vertical_scan");  
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("quant %i", *quant);  
831    
832                          if (coding_type != I_VOP) {                          if (coding_type != I_VOP) {
833                                  *fcode_forward = BitstreamGetBits(bs, 3);       // fcode_forward                                  *fcode_forward = BitstreamGetBits(bs, 3);       // fcode_forward
834                                    DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward);
835                          }                          }
836    
837                          if (coding_type == B_VOP) {                          if (coding_type == B_VOP) {
838                                  *fcode_backward = BitstreamGetBits(bs, 3);      // fcode_backward                                  *fcode_backward = BitstreamGetBits(bs, 3);      // fcode_backward
839                                    DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward);
840                          }                          }
841                          if (!dec->scalability) {                          if (!dec->scalability) {
842                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&
# Line 554  Line 845 
845                                  }                                  }
846                          }                          }
847                          return coding_type;                          return coding_type;
848    
849                  } else if (start_code == USERDATA_START_CODE) {                  } else if (start_code == USERDATA_START_CODE) {
850                          //DPRINTF("user_data");  
851                            DPRINTF(DPRINTF_STARTCODE, "<user_data>");
852    
853                          BitstreamSkip(bs, 32);  // user_data_start_code                          BitstreamSkip(bs, 32);  // user_data_start_code
854    
855                  } else                                  // start_code == ?                  } else                                  // start_code == ?
856                  {                  {
857                          if (BitstreamShowBits(bs, 24) == 0x000001) {                          if (BitstreamShowBits(bs, 24) == 0x000001) {
858                                  //DPRINTF("*** WARNING: unknown start_code %x",                                  DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32));
                                 //         BitstreamShowBits(bs, 32));  
859                          }                          }
860                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
861                  }                  }
# Line 600  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 613  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    
 #ifdef BFRAMES  
         if (pParam->max_bframes > 0) {  
                 //DPRINTF("low_delay=1");  
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    
932            if (pParam->max_bframes > 0) {
933                  BitstreamPutBit(bs, 0); // low_delay                  BitstreamPutBit(bs, 0); // low_delay
                 BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)  
934          } else          } else
 #endif  
935          {          {
936                  BitstreamPutBits(bs, 0, 1);     // vol_control_parameters (0=not given)                  BitstreamPutBit(bs, 1); // low_delay
937          }          }
938            BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)
939    
940          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)
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  
949          BitstreamPutBits(bs, pParam->fbase, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
 #else  
         BitstreamPutBits(bs, 2, 16);  
 #endif  
950    
951          WRITE_MARKER();          WRITE_MARKER();
952    
953          // fixed_vop_rate          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
954          BitstreamPutBit(bs, 0);          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
   
         // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution)  
         // BitstreamPutBits(bs, 0, 15);  
955    
956          WRITE_MARKER();          WRITE_MARKER();
957          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 661  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 680  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  {  {
 #ifdef BFRAMES  
1030          uint32_t i;          uint32_t i;
1031  #endif  
1032          BitstreamPad(bs);          BitstreamPad(bs);
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  
         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, 1, 1);  
 #endif  
1051    
1052          WRITE_MARKER();          WRITE_MARKER();
1053    
# Line 740  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 760  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.233  
changed lines
  Added in v.631

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