[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.2.6, Tue Nov 12 15:53:23 2002 UTC revision 1.39.2.4, Wed Mar 26 10:39:53 2003 UTC
# Line 41  Line 41 
41    *                                                                            *    *                                                                            *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44    *  28.10.2002 GMC support - gruel                                                                                        *    *  05.01.2003 GMC support - gruel                                            *
45    *  04.10.2002 qpel support - Isibaar                                                                             *    *  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)               *
# Line 67  Line 67 
67    
68    
69  #include <string.h>  #include <string.h>
70    #include <stdio.h>
71    
72  #include "bitstream.h"  #include "bitstream.h"
73  #include "zigzag.h"  #include "zigzag.h"
74  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
# Line 77  Line 79 
79  log2bin(uint32_t value)  log2bin(uint32_t value)
80  {  {
81  /* Changed by Chenm001 */  /* Changed by Chenm001 */
82  #ifndef WIN32  #if !defined(_MSC_VER)
83          int n = 0;          int n = 0;
84    
85          while (value) {          while (value) {
# Line 171  Line 173 
173    
174          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
175          {          {
176                  *quant = BitstreamGetBits(bs, 5);       /* quant_scale */                  *quant = BitstreamGetBits(bs, dec->quant_bits); /* quant_scale */
177                  DPRINTF(DPRINTF_HEADER, "quant %i", *quant);                  DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
178          }          }
179    
# Line 216  Line 218 
218                                  dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&                                  dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&
219                                  (coding_type == P_VOP || coding_type == I_VOP))                                  (coding_type == P_VOP || coding_type == I_VOP))
220                          {                          {
221                                  BitstreamSkip(bs, 1); /* vop_reduced_resolution */                                  BitstreamSkip(bs, 1); /* XXX: vop_reduced_resolution */
222                          }                          }
223    
224                          if (coding_type != I_VOP && fcode_forward)                          if (coding_type != I_VOP && fcode_forward)
# Line 228  Line 230 
230                          if (coding_type == B_VOP && fcode_backward)                          if (coding_type == B_VOP && fcode_backward)
231                          {                          {
232                                  *fcode_backward = BitstreamGetBits(bs, 3);                                  *fcode_backward = BitstreamGetBits(bs, 3);
233                                  DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward);                                  DPRINTF(DPRINTF_HEADER,"fcode_backward %i", *fcode_backward);
234                          }                          }
235                  }                  }
236    
# Line 254  Line 256 
256    
257    
258    
259    
260    /* vol estimation header */
261    static void
262    read_vol_complexity_estimation_header(Bitstream * bs, DECODER * dec)
263    {
264            ESTIMATION * e = &dec->estimation;
265    
266            e->method = BitstreamGetBits(bs, 2);    /* estimation_method */
267            DPRINTF(DPRINTF_HEADER,"+ complexity_estimation_header; method=%i", e->method);
268    
269            if (e->method == 0 || e->method == 1)
270            {
271                    if (!BitstreamGetBit(bs))               /* shape_complexity_estimation_disable */
272                    {
273                            e->opaque = BitstreamGetBit(bs);                /* opaque */
274                            e->transparent = BitstreamGetBit(bs);           /* transparent */
275                            e->intra_cae = BitstreamGetBit(bs);             /* intra_cae */
276                            e->inter_cae = BitstreamGetBit(bs);             /* inter_cae */
277                            e->no_update = BitstreamGetBit(bs);             /* no_update */
278                            e->upsampling = BitstreamGetBit(bs);            /* upsampling */
279                    }
280    
281                    if (!BitstreamGetBit(bs))       /* texture_complexity_estimation_set_1_disable */
282                    {
283                            e->intra_blocks = BitstreamGetBit(bs);          /* intra_blocks */
284                            e->inter_blocks = BitstreamGetBit(bs);          /* inter_blocks */
285                            e->inter4v_blocks = BitstreamGetBit(bs);                /* inter4v_blocks */
286                            e->not_coded_blocks = BitstreamGetBit(bs);              /* not_coded_blocks */
287                    }
288            }
289    
290            READ_MARKER();
291    
292            if (!BitstreamGetBit(bs))               /* texture_complexity_estimation_set_2_disable */
293            {
294                    e->dct_coefs = BitstreamGetBit(bs);             /* dct_coefs */
295                    e->dct_lines = BitstreamGetBit(bs);             /* dct_lines */
296                    e->vlc_symbols = BitstreamGetBit(bs);           /* vlc_symbols */
297                    e->vlc_bits = BitstreamGetBit(bs);              /* vlc_bits */
298            }
299    
300            if (!BitstreamGetBit(bs))               /* motion_compensation_complexity_disable */
301            {
302                    e->apm = BitstreamGetBit(bs);           /* apm */
303                    e->npm = BitstreamGetBit(bs);           /* npm */
304                    e->interpolate_mc_q = BitstreamGetBit(bs);              /* interpolate_mc_q */
305                    e->forw_back_mc_q = BitstreamGetBit(bs);                /* forw_back_mc_q */
306                    e->halfpel2 = BitstreamGetBit(bs);              /* halfpel2 */
307                    e->halfpel4 = BitstreamGetBit(bs);              /* halfpel4 */
308            }
309    
310            READ_MARKER();
311    
312            if (e->method == 1)
313            {
314                    if (!BitstreamGetBit(bs))       /* version2_complexity_estimation_disable */
315                    {
316                            e->sadct = BitstreamGetBit(bs);         /* sadct */
317                            e->quarterpel = BitstreamGetBit(bs);            /* quarterpel */
318                    }
319            }
320    }
321    
322    
323    /* vop estimation header */
324    static void
325    read_vop_complexity_estimation_header(Bitstream * bs, DECODER * dec, int coding_type)
326    {
327            ESTIMATION * e = &dec->estimation;
328    
329            if (e->method == 0 || e->method == 1)
330            {
331                    if (coding_type == I_VOP) {
332                            if (e->opaque)          BitstreamSkip(bs, 8);   /* dcecs_opaque */
333                            if (e->transparent) BitstreamSkip(bs, 8);       /* */
334                            if (e->intra_cae)       BitstreamSkip(bs, 8);   /* */
335                            if (e->inter_cae)       BitstreamSkip(bs, 8);   /* */
336                            if (e->no_update)       BitstreamSkip(bs, 8);   /* */
337                            if (e->upsampling)      BitstreamSkip(bs, 8);   /* */
338                            if (e->intra_blocks) BitstreamSkip(bs, 8);      /* */
339                            if (e->not_coded_blocks) BitstreamSkip(bs, 8);  /* */
340                            if (e->dct_coefs)       BitstreamSkip(bs, 8);   /* */
341                            if (e->dct_lines)       BitstreamSkip(bs, 8);   /* */
342                            if (e->vlc_symbols) BitstreamSkip(bs, 8);       /* */
343                            if (e->vlc_bits)        BitstreamSkip(bs, 8);   /* */
344                            if (e->sadct)           BitstreamSkip(bs, 8);   /* */
345                    }
346    
347                    if (coding_type == P_VOP) {
348                            if (e->opaque) BitstreamSkip(bs, 8);            /* */
349                            if (e->transparent) BitstreamSkip(bs, 8);       /* */
350                            if (e->intra_cae)       BitstreamSkip(bs, 8);   /* */
351                            if (e->inter_cae)       BitstreamSkip(bs, 8);   /* */
352                            if (e->no_update)       BitstreamSkip(bs, 8);   /* */
353                            if (e->upsampling) BitstreamSkip(bs, 8);        /* */
354                            if (e->intra_blocks) BitstreamSkip(bs, 8);      /* */
355                            if (e->not_coded_blocks)        BitstreamSkip(bs, 8);   /* */
356                            if (e->dct_coefs)       BitstreamSkip(bs, 8);   /* */
357                            if (e->dct_lines)       BitstreamSkip(bs, 8);   /* */
358                            if (e->vlc_symbols) BitstreamSkip(bs, 8);       /* */
359                            if (e->vlc_bits)        BitstreamSkip(bs, 8);   /* */
360                            if (e->inter_blocks) BitstreamSkip(bs, 8);      /* */
361                            if (e->inter4v_blocks) BitstreamSkip(bs, 8);    /* */
362                            if (e->apm)                     BitstreamSkip(bs, 8);   /* */
363                            if (e->npm)                     BitstreamSkip(bs, 8);   /* */
364                            if (e->forw_back_mc_q) BitstreamSkip(bs, 8);    /* */
365                            if (e->halfpel2)        BitstreamSkip(bs, 8);   /* */
366                            if (e->halfpel4)        BitstreamSkip(bs, 8);   /* */
367                            if (e->sadct)           BitstreamSkip(bs, 8);   /* */
368                            if (e->quarterpel)      BitstreamSkip(bs, 8);   /* */
369                    }
370                    if (coding_type == B_VOP) {
371                            if (e->opaque)          BitstreamSkip(bs, 8);   /* */
372                            if (e->transparent)     BitstreamSkip(bs, 8);   /* */
373                            if (e->intra_cae)       BitstreamSkip(bs, 8);   /* */
374                            if (e->inter_cae)       BitstreamSkip(bs, 8);   /* */
375                            if (e->no_update)       BitstreamSkip(bs, 8);   /* */
376                            if (e->upsampling)      BitstreamSkip(bs, 8);   /* */
377                            if (e->intra_blocks) BitstreamSkip(bs, 8);      /* */
378                            if (e->not_coded_blocks) BitstreamSkip(bs, 8);  /* */
379                            if (e->dct_coefs)       BitstreamSkip(bs, 8);   /* */
380                            if (e->dct_lines)       BitstreamSkip(bs, 8);   /* */
381                            if (e->vlc_symbols)     BitstreamSkip(bs, 8);   /* */
382                            if (e->vlc_bits)        BitstreamSkip(bs, 8);   /* */
383                            if (e->inter_blocks) BitstreamSkip(bs, 8);      /* */
384                            if (e->inter4v_blocks) BitstreamSkip(bs, 8);    /* */
385                            if (e->apm)                     BitstreamSkip(bs, 8);   /* */
386                            if (e->npm)                     BitstreamSkip(bs, 8);   /* */
387                            if (e->forw_back_mc_q) BitstreamSkip(bs, 8);    /* */
388                            if (e->halfpel2)        BitstreamSkip(bs, 8);   /* */
389                            if (e->halfpel4)        BitstreamSkip(bs, 8);   /* */
390                            if (e->interpolate_mc_q) BitstreamSkip(bs, 8);  /* */
391                            if (e->sadct)           BitstreamSkip(bs, 8);   /* */
392                            if (e->quarterpel)      BitstreamSkip(bs, 8);   /* */
393                    }
394    
395                    if (coding_type == S_VOP && dec->sprite_enable == SPRITE_STATIC) {
396                            if (e->intra_blocks) BitstreamSkip(bs, 8);      /* */
397                            if (e->not_coded_blocks) BitstreamSkip(bs, 8);  /* */
398                            if (e->dct_coefs)       BitstreamSkip(bs, 8);   /* */
399                            if (e->dct_lines)       BitstreamSkip(bs, 8);   /* */
400                            if (e->vlc_symbols)     BitstreamSkip(bs, 8);   /* */
401                            if (e->vlc_bits)        BitstreamSkip(bs, 8);   /* */
402                            if (e->inter_blocks) BitstreamSkip(bs, 8);      /* */
403                            if (e->inter4v_blocks)  BitstreamSkip(bs, 8);   /* */
404                            if (e->apm)                     BitstreamSkip(bs, 8);   /* */
405                            if (e->npm)                     BitstreamSkip(bs, 8);   /* */
406                            if (e->forw_back_mc_q)  BitstreamSkip(bs, 8);   /* */
407                            if (e->halfpel2)        BitstreamSkip(bs, 8);   /* */
408                            if (e->halfpel4)        BitstreamSkip(bs, 8);   /* */
409                            if (e->interpolate_mc_q) BitstreamSkip(bs, 8);  /* */
410                    }
411            }
412    }
413    
414    
415    
416    
417    
418  /*  /*
419  decode headers  decode headers
420  returns coding_type, or -1 if error  returns coding_type, or -1 if error
# Line 271  Line 432 
432                                           uint32_t * fcode_forward,                                           uint32_t * fcode_forward,
433                                           uint32_t * fcode_backward,                                           uint32_t * fcode_backward,
434                                           uint32_t * intra_dc_threshold,                                           uint32_t * intra_dc_threshold,
435                                           VECTOR * gmc_mv)                                           WARPPOINTS *gmc_warp)
436  {  {
437          uint32_t vol_ver_id;          uint32_t vol_ver_id;
438          uint32_t coding_type;          uint32_t coding_type;
439          uint32_t start_code;          uint32_t start_code;
440          uint32_t time_incr = 0;          uint32_t time_incr = 0;
441          int32_t time_increment;          int32_t time_increment = 0;
442          int resize = 0;          int resize = 0;
443    
444          do {          do {
# Line 303  Line 464 
464                          DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");                          DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");
465    
466                  } else if (start_code == VISOBJ_START_CODE) {                  } else if (start_code == VISOBJ_START_CODE) {
467                            int visobj_ver_id;
468    
469                          DPRINTF(DPRINTF_STARTCODE, "<visual_object>");                          DPRINTF(DPRINTF_STARTCODE, "<visual_object>");
470    
471                          BitstreamSkip(bs, 32);  // visual_object_start_code                          BitstreamSkip(bs, 32);  // visual_object_start_code
472                          if (BitstreamGetBit(bs))        // is_visual_object_identified                          if (BitstreamGetBit(bs))        // is_visual_object_identified
473                          {                          {
474                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id                                  visobj_ver_id = BitstreamGetBits(bs, 4);        // visual_object_ver_id
475                                  DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);                                  DPRINTF(DPRINTF_HEADER,"visobj_ver_id %i", visobj_ver_id);
476                                  BitstreamSkip(bs, 3);   // visual_object_priority                                  BitstreamSkip(bs, 3);   // visual_object_priority
477                          } else {                          } else {
478                                  vol_ver_id = 1;                                  visobj_ver_id = 1;
479                          }                          }
480    
481                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type
# Line 360  Line 522 
522                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN &&                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN &&
523                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ACE &&                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ACE &&
524                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE &&                                  BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE &&
525                    BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ASP &&
526                                  BitstreamShowBits(bs, 8) != 0)  // BUGGY DIVX                                  BitstreamShowBits(bs, 8) != 0)  // BUGGY DIVX
527                          {                          {
528                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",
# Line 396  Line 559 
559                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
560                                  if (BitstreamGetBit(bs))        // vbv_parameters                                  if (BitstreamGetBit(bs))        // vbv_parameters
561                                  {                                  {
562                                            unsigned int bitrate;
563                                            unsigned int buffer_size;
564                                            unsigned int occupancy;
565    
566                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
567                                          BitstreamSkip(bs, 15);  // first_half_bitrate  
568                                            bitrate = BitstreamGetBits(bs,15) << 15;        // first_half_bit_rate
569                                          READ_MARKER();                                          READ_MARKER();
570                                          BitstreamSkip(bs, 15);  // latter_half_bitrate                                          bitrate |= BitstreamGetBits(bs,15);             // latter_half_bit_rate
571                                          READ_MARKER();                                          READ_MARKER();
572                                          BitstreamSkip(bs, 15);  // first_half_vbv_buffer_size  
573                                            buffer_size = BitstreamGetBits(bs, 15) << 3;    // first_half_vbv_buffer_size
574                                          READ_MARKER();                                          READ_MARKER();
575                                          BitstreamSkip(bs, 3);   // latter_half_vbv_buffer_size                                          buffer_size |= BitstreamGetBits(bs, 3);         // latter_half_vbv_buffer_size
576                                          BitstreamSkip(bs, 11);  // first_half_vbv_occupancy  
577                                            occupancy = BitstreamGetBits(bs, 11) << 15;     // first_half_vbv_occupancy
578                                          READ_MARKER();                                          READ_MARKER();
579                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy                                          occupancy |= BitstreamGetBits(bs, 15);  // latter_half_vbv_occupancy
580                                          READ_MARKER();                                          READ_MARKER();
581    
582                                            DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate);
583                                            DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size);
584                                            DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy);
585                                  }                                  }
586                            }else{
587                                    dec->low_delay = dec->low_delay_default;
588                          }                          }
589    
590                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
# Line 465  Line 641 
641                                          {                                          {
642                                                  if (dec->fixed_dimensions)                                                  if (dec->fixed_dimensions)
643                                                  {                                                  {
644                                                          DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");                                                          DPRINTF(DPRINTF_ERROR, "decoder width/height does not match bitstream");
645                                                          return -1;                                                          return -1;
646                                                  }                                                  }
647                                                  resize = 1;                                                  resize = 1;
# Line 576  Line 752 
752                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
753    
754    
755                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable                                  dec->complexity_estimation_disable = BitstreamGetBit(bs);       /* complexity estimation disable */
756                                    if (!dec->complexity_estimation_disable)
757                                  {                                  {
758                                          DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported");                                          read_vol_complexity_estimation_header(bs, dec);
                                         return -1;  
759                                  }                                  }
760    
761                                  BitstreamSkip(bs, 1);   // resync_marker_disable                                  BitstreamSkip(bs, 1);   // resync_marker_disable
# Line 598  Line 774 
774                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type
775                                                  BitstreamSkip(bs, 1);   // newpred_segment_type                                                  BitstreamSkip(bs, 1);   // newpred_segment_type
776                                          }                                          }
777                                          dec->reduced_resolution_enable = BitstreamGetBit(bs);                                          dec->reduced_resolution_enable = BitstreamGetBit(bs);   /* reduced_resolution_vop_enable */
778                                          if (dec->reduced_resolution_enable)     // reduced_resolution_vop_enable                                          DPRINTF(DPRINTF_HEADER, "reduced_resolution_enable %i", dec->reduced_resolution_enable);
                                         {  
                                                 DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");  
                                                 //return -1;  
                                         }  
779                                  }                                  }
780                                  else                                  else
781                                  {                                  {
# Line 611  Line 783 
783                                          dec->reduced_resolution_enable = 0;                                          dec->reduced_resolution_enable = 0;
784                                  }                                  }
785    
786                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability                                  dec->scalability = BitstreamGetBit(bs); /* scalability */
787                                    if (dec->scalability)
788                                  {                                  {
789                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
790                                            BitstreamSkip(bs, 1);   /* hierarchy_type */
791                                            BitstreamSkip(bs, 4);   /* ref_layer_id */
792                                            BitstreamSkip(bs, 1);   /* ref_layer_sampling_direc */
793                                            BitstreamSkip(bs, 5);   /* hor_sampling_factor_n */
794                                            BitstreamSkip(bs, 5);   /* hor_sampling_factor_m */
795                                            BitstreamSkip(bs, 5);   /* vert_sampling_factor_n */
796                                            BitstreamSkip(bs, 5);   /* vert_sampling_factor_m */
797                                            BitstreamSkip(bs, 1);   /* enhancement_type */
798                                            if(dec->shape == VIDOBJLAY_SHAPE_BINARY /* && hierarchy_type==0 */) {
799                                                    BitstreamSkip(bs, 1);   /* use_ref_shape */
800                                                    BitstreamSkip(bs, 1);   /* use_ref_texture */
801                                                    BitstreamSkip(bs, 5);   /* shape_hor_sampling_factor_n */
802                                                    BitstreamSkip(bs, 5);   /* shape_hor_sampling_factor_m */
803                                                    BitstreamSkip(bs, 5);   /* shape_vert_sampling_factor_n */
804                                                    BitstreamSkip(bs, 5);   /* shape_vert_sampling_factor_m */
805                                            }
806                                          return -1;                                          return -1;
807                                  }                                  }
808                          } else                          // dec->shape == BINARY_ONLY                          } else                          // dec->shape == BINARY_ONLY
809                          {                          {
810                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
811                                          if (BitstreamGetBit(bs))        // scalability                                          dec->scalability = BitstreamGetBit(bs); /* scalability */
812                                            if (dec->scalability)
813                                          {                                          {
814                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
815                                                    BitstreamSkip(bs, 4);   /* ref_layer_id */
816                                                    BitstreamSkip(bs, 5);   /* hor_sampling_factor_n */
817                                                    BitstreamSkip(bs, 5);   /* hor_sampling_factor_m */
818                                                    BitstreamSkip(bs, 5);   /* vert_sampling_factor_n */
819                                                    BitstreamSkip(bs, 5);   /* vert_sampling_factor_m */
820                                                  return -1;                                                  return -1;
821                                          }                                          }
822                                  }                                  }
# Line 644  Line 839 
839                                  READ_MARKER();                                  READ_MARKER();
840                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
841    
842                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds);
843                          }                          }
844                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
845                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
# Line 694  Line 889 
889                                  dec->time_bp = (uint32_t)                                  dec->time_bp = (uint32_t)
890                                          (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;                                          (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution;
891                          }                          }
892                            DPRINTF(DPRINTF_HEADER,"time_pp=%i", dec->time_pp);
893                            DPRINTF(DPRINTF_HEADER,"time_bp=%i", dec->time_bp);
894    
895                          READ_MARKER();                          READ_MARKER();
896    
# Line 732  Line 929 
929                                  (coding_type == P_VOP || coding_type == I_VOP)) {                                  (coding_type == P_VOP || coding_type == I_VOP)) {
930    
931                                  *reduced_resolution = BitstreamGetBit(bs);                                  *reduced_resolution = BitstreamGetBit(bs);
932                                    DPRINTF(DPRINTF_HEADER, "reduced_resolution %i", *reduced_resolution);
933                          }                          }
934                          else                          else
935                          {                          {
# Line 767  Line 965 
965                          }                          }
966    
967                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
968    
969                                    if (!dec->complexity_estimation_disable)
970                                    {
971                                            read_vop_complexity_estimation_header(bs, dec, coding_type);
972                                    }
973    
974                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
975                                  *intra_dc_threshold =                                  *intra_dc_threshold =
976                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
# Line 809  Line 1013 
1013                                          }                                          }
1014                                          READ_MARKER();                                          READ_MARKER();
1015    
1016                                          gmc_mv[i].x = x;                                          gmc_warp->duv[i].x = x;
1017                                          gmc_mv[i].y = y;                                          gmc_warp->duv[i].y = y;
1018    
1019                                          DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y);                                          DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y);
1020                                  }                                  }
# Line 849  Line 1053 
1053    
1054                  } else if (start_code == USERDATA_START_CODE) {                  } else if (start_code == USERDATA_START_CODE) {
1055                          char tmp[256];                          char tmp[256];
1056                      int i;                      int i, version, build;
1057                            char packed;
1058    
1059                          BitstreamSkip(bs, 32);  // user_data_start_code                          BitstreamSkip(bs, 32);  // user_data_start_code
1060    
# Line 864  Line 1069 
1069                                  BitstreamSkip(bs, 8);                                  BitstreamSkip(bs, 8);
1070                          }                          }
1071    
1072                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s", tmp);
   
                         if(strncmp(tmp, "DivX501b481p", 12) == 0) {  
                                 dec->packed_mode = 1;  
                                 DPRINTF(DPRINTF_STARTCODE, "packed_mode = %d\n", dec->packed_mode);  
1073    
1074                        /* divx detection */
1075                            i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);
1076                            if (i < 2)
1077                                    i = sscanf(tmp, "DivX%db%d%c", &version, &build, &packed);
1078    
1079                            if (i >= 2)
1080                            {
1081                                    dec->packed_mode = (i == 3 && packed == 'p');
1082                                    DPRINTF(DPRINTF_HEADER, "divx version=%i, build=%i packed=%i",
1083                                                    version, build, dec->packed_mode);
1084                          }                          }
1085    
1086                  } else                                  // start_code == ?                  } else                                  // start_code == ?
1087                  {                  {
1088                          if (BitstreamShowBits(bs, 24) == 0x000001) {                          if (BitstreamShowBits(bs, 24) == 0x000001) {
# Line 912  Line 1124 
1124  */  */
1125  void  void
1126  BitstreamWriteVolHeader(Bitstream * const bs,  BitstreamWriteVolHeader(Bitstream * const bs,
1127                                                  const MBParam * pParam,                                                  const MBParam * pParam)
                                                 const FRAMEINFO * const frame)  
1128  {  {
1129            static const unsigned int vo_id = 0;
1130            static const unsigned int vol_id = 0;
1131          int vol_ver_id=1;          int vol_ver_id=1;
1132            int profile = 0x03;     /* simple profile/level 3 */
1133    
1134          if ( (pParam->m_quarterpel) || (frame->global_flags & XVID_GMC) )          if ( (pParam->vol_flags & XVID_QUARTERPEL) ||
1135             (pParam->vol_flags & XVID_GMC) ||
1136                     (pParam->vol_flags & XVID_REDUCED_ENABLE))
1137                  vol_ver_id = 2;                  vol_ver_id = 2;
1138    
1139            if ((pParam->vol_flags & XVID_REDUCED_ENABLE))
1140                    profile = 0x93; /* advanced realtime simple profile/level 3 */
1141    
1142            if ((pParam->vol_flags & XVID_QUARTERPEL) ||
1143            (pParam->vol_flags & XVID_GMC))
1144                    profile = 0xf3; /* advanced simple profile/level 2 */
1145    
1146            // visual_object_sequence_start_code
1147    //      BitstreamPad(bs);
1148    /* no padding here, anymore. You have to make sure that you are
1149       byte aligned, and that always 1-8 padding bits have been written */
1150    
1151            BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32);
1152            BitstreamPutBits(bs, profile, 8);
1153    
1154            // visual_object_start_code
1155            BitstreamPad(bs);
1156            BitstreamPutBits(bs, VISOBJ_START_CODE, 32);
1157            BitstreamPutBits(bs, 0, 1);             // is_visual_object_identifier
1158            BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4);             // visual_object_type
1159    
1160          // video object_start_code & vo_id          // video object_start_code & vo_id
1161          BitstreamPad(bs);          BitstreamPad(bs);
1162          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32);
         BitstreamPutBits(bs, 0, 5);  
1163    
1164          // video_object_layer_start_code & vol_id          // video_object_layer_start_code & vol_id
1165          BitstreamPutBits(bs, VOL_START_CODE, 28);          BitstreamPad(bs);
1166          BitstreamPutBits(bs, 0, 4);          BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32);
1167    
1168          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
1169          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
# Line 969  Line 1205 
1205    
1206          WRITE_MARKER();          WRITE_MARKER();
1207    
1208        if (pParam->fincr>0) {
1209          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
1210          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment          BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
1211        }else{
1212            BitstreamPutBit(bs, 0);         // fixed_vop_rate = 0
1213        }
1214    
1215          WRITE_MARKER();          WRITE_MARKER();
1216          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 978  Line 1218 
1218          BitstreamPutBits(bs, pParam->height, 13);       // height          BitstreamPutBits(bs, pParam->height, 13);       // height
1219          WRITE_MARKER();          WRITE_MARKER();
1220    
1221          BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING);    // interlace          BitstreamPutBit(bs, pParam->vol_flags & XVID_INTERLACING);      // interlace
1222          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)          BitstreamPutBit(bs, 1);         // obmc_disable (overlapped block motion compensation)
1223    
1224          if (vol_ver_id != 1)          if (vol_ver_id != 1)
1225          {       if (frame->global_flags & XVID_GMC)          {       if ((pParam->vol_flags & XVID_GMC))
1226                  {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'                  {       BitstreamPutBits(bs, 2, 2);             // sprite_enable=='GMC'
1227                          BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points                          BitstreamPutBits(bs, 2, 6);             // no_of_sprite_warping_points
1228                          BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16                          BitstreamPutBits(bs, 3, 2);             // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16
# Line 1000  Line 1240 
1240          BitstreamPutBit(bs, 0);         // not_8_bit          BitstreamPutBit(bs, 0);         // not_8_bit
1241    
1242          // quant_type   0=h.263  1=mpeg4(quantizer tables)          // quant_type   0=h.263  1=mpeg4(quantizer tables)
1243          BitstreamPutBit(bs, pParam->m_quant_type);          BitstreamPutBit(bs, pParam->vol_flags & XVID_MPEGQUANT);
1244    
1245          if (pParam->m_quant_type) {          if ((pParam->vol_flags & XVID_MPEGQUANT)) {
1246                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat                  BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
1247                  if (get_intra_matrix_status()) {                  if (get_intra_matrix_status()) {
1248                          bs_put_matrix(bs, get_intra_matrix());                          bs_put_matrix(bs, get_intra_matrix());
# Line 1016  Line 1256 
1256          }          }
1257    
1258          if (vol_ver_id != 1) {          if (vol_ver_id != 1) {
1259                  if (pParam->m_quarterpel)                  if ((pParam->vol_flags & XVID_QUARTERPEL))
1260                          BitstreamPutBit(bs, 1);         //  quarterpel                          BitstreamPutBit(bs, 1);         //  quarterpel
1261                  else                  else
1262                          BitstreamPutBit(bs, 0);         // no quarterpel                          BitstreamPutBit(bs, 0);         // no quarterpel
# Line 1029  Line 1269 
1269          if (vol_ver_id != 1)          if (vol_ver_id != 1)
1270          {          {
1271                  BitstreamPutBit(bs, 0);         // newpred_enable                  BitstreamPutBit(bs, 0);         // newpred_enable
1272                  BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled  
1273                    BitstreamPutBit(bs, (pParam->vol_flags & XVID_REDUCED_ENABLE)?1:0);
1274                                                                            /* reduced_resolution_vop_enabled */
1275          }          }
1276    
1277          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1278    
1279            /* fake divx5 id, to ensure compatibility with divx5 decoder */
1280    #define DIVX5_ID "DivX000b000p"
1281            if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_PACKED)) {
1282                    BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1283            }
1284    
1285            /* xvid id */
1286    #define XVID_ID "XviD" XVID_BS_VERSION
1287            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1288  }  }
1289    
1290    
# Line 1041  Line 1292 
1292    write vop header    write vop header
1293  */  */
1294  void  void
1295  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(
1296                                                    Bitstream * const bs,
1297                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1298                                                  const FRAMEINFO * const frame,                                                  const FRAMEINFO * const frame,
1299                                                  int vop_coded)                                                  int vop_coded)
1300  {  {
1301          uint32_t i;          uint32_t i;
1302    
1303          BitstreamPad(bs);  //      BitstreamPad(bs);
1304    /* no padding here, anymore. You have to make sure that you are
1305       byte aligned, and that always 1-8 padding bits have been written */
1306    
1307          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1308    
1309          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
# Line 1080  Line 1335 
1335          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
1336                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1337    
1338            if ((frame->vol_flags & XVID_REDUCED_ENABLE))
1339                    BitstreamPutBit(bs, (frame->vop_flags & XVID_REDUCED)?1:0);
1340    
1341          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
1342    
1343          if (frame->global_flags & XVID_INTERLACING) {          if ((frame->vol_flags & XVID_INTERLACING)) {
1344                  BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST));                  BitstreamPutBit(bs, (frame->vop_flags & XVID_TOPFIELDFIRST));
1345                  BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN));                  BitstreamPutBit(bs, (frame->vop_flags & XVID_ALTERNATESCAN));
1346          }          }
1347    
1348          if (frame->coding_type == S_VOP) {          if (frame->coding_type == S_VOP) {
1349                  if (1)  {               // no_of_sprite_warping_points>=1                  if (1)  {               // no_of_sprite_warping_points>=1 (we use 2!)
1350                          if (pParam->m_quarterpel)                          int k;
1351                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]                          for (k=0;k<2;k++)
1352                          else                          {
1353                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k]
1354                          WRITE_MARKER();                          WRITE_MARKER();
1355    
1356                          if (pParam->m_quarterpel)                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k]
                                 bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0]  
                         else  
                                 bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0]  
1357                          WRITE_MARKER();                          WRITE_MARKER();
1358    
1359                            if ((frame->vol_flags & XVID_QUARTERPEL))
                         if (pParam->m_quarterpel)  
1360                          {                          {
1361                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2);                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].y/2);
1362                          }                          }
1363                          else                          else
1364                          {                          {
1365                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y);                                  DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", k, frame->warp.duv[k].x, frame->warp.duv[k].y);
1366                          }                          }
   
1367                  }                  }
 /* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */  
   
                 if (2) {                // no_of_sprite_warping_points>=2 (for DivX5 compat)  
                         bs_put_spritetrajectory(bs, 0 );  
                         WRITE_MARKER();  
                         bs_put_spritetrajectory(bs, 0 );  
                         WRITE_MARKER();  
1368                  }                  }
                 // no support for brightness_change!  
1369          }          }
1370    
1371    
1372            DPRINTF(DPRINTF_HEADER, "quant = %i", frame->quant);
1373    
1374          BitstreamPutBits(bs, frame->quant, 5);  // quantizer          BitstreamPutBits(bs, frame->quant, 5);  // quantizer
1375    
1376          if (frame->coding_type != I_VOP)          if (frame->coding_type != I_VOP)

Legend:
Removed from v.1.28.2.6  
changed lines
  Added in v.1.39.2.4

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