[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.38, Sat Feb 15 15:22:18 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;
# 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 396  Line 558 
558                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);                                  DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
559                                  if (BitstreamGetBit(bs))        // vbv_parameters                                  if (BitstreamGetBit(bs))        // vbv_parameters
560                                  {                                  {
561                                            unsigned int bitrate;
562                                            unsigned int buffer_size;
563                                            unsigned int occupancy;
564    
565                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
566                                          BitstreamSkip(bs, 15);  // first_half_bitrate  
567                                            bitrate = BitstreamGetBits(bs,15) << 15;        // first_half_bit_rate
568                                          READ_MARKER();                                          READ_MARKER();
569                                          BitstreamSkip(bs, 15);  // latter_half_bitrate                                          bitrate |= BitstreamGetBits(bs,15);             // latter_half_bit_rate
570                                          READ_MARKER();                                          READ_MARKER();
571                                          BitstreamSkip(bs, 15);  // first_half_vbv_buffer_size  
572                                            buffer_size = BitstreamGetBits(bs, 15) << 3;    // first_half_vbv_buffer_size
573                                          READ_MARKER();                                          READ_MARKER();
574                                          BitstreamSkip(bs, 3);   // latter_half_vbv_buffer_size                                          buffer_size |= BitstreamGetBits(bs, 3);         // latter_half_vbv_buffer_size
575                                          BitstreamSkip(bs, 11);  // first_half_vbv_occupancy  
576                                            occupancy = BitstreamGetBits(bs, 11) << 15;     // first_half_vbv_occupancy
577                                          READ_MARKER();                                          READ_MARKER();
578                                          BitstreamSkip(bs, 15);  // latter_half_vbv_occupancy                                          occupancy |= BitstreamGetBits(bs, 15);  // latter_half_vbv_occupancy
579                                          READ_MARKER();                                          READ_MARKER();
580    
581                                            DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate);
582                                            DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size);
583                                            DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy);
584                                  }                                  }
585                            }else{
586                                    dec->low_delay = dec->low_delay_default;
587                          }                          }
588    
589                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
# Line 576  Line 751 
751                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
752    
753    
754                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable                                  dec->complexity_estimation_disable = BitstreamGetBit(bs);       /* complexity estimation disable */
755                                    if (!dec->complexity_estimation_disable)
756                                  {                                  {
757                                          DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported");                                          read_vol_complexity_estimation_header(bs, dec);
                                         return -1;  
758                                  }                                  }
759    
760                                  BitstreamSkip(bs, 1);   // resync_marker_disable                                  BitstreamSkip(bs, 1);   // resync_marker_disable
# Line 598  Line 773 
773                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type
774                                                  BitstreamSkip(bs, 1);   // newpred_segment_type                                                  BitstreamSkip(bs, 1);   // newpred_segment_type
775                                          }                                          }
776                                          dec->reduced_resolution_enable = BitstreamGetBit(bs);                                          dec->reduced_resolution_enable = BitstreamGetBit(bs);   /* reduced_resolution_vop_enable */
777                                          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;  
                                         }  
778                                  }                                  }
779                                  else                                  else
780                                  {                                  {
# Line 611  Line 782 
782                                          dec->reduced_resolution_enable = 0;                                          dec->reduced_resolution_enable = 0;
783                                  }                                  }
784    
785                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability                                  dec->scalability = BitstreamGetBit(bs); /* scalability */
786                                    if (dec->scalability)
787                                  {                                  {
788                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
789                                            BitstreamSkip(bs, 1);   /* hierarchy_type */
790                                            BitstreamSkip(bs, 4);   /* ref_layer_id */
791                                            BitstreamSkip(bs, 1);   /* ref_layer_sampling_direc */
792                                            BitstreamSkip(bs, 5);   /* hor_sampling_factor_n */
793                                            BitstreamSkip(bs, 5);   /* hor_sampling_factor_m */
794                                            BitstreamSkip(bs, 5);   /* vert_sampling_factor_n */
795                                            BitstreamSkip(bs, 5);   /* vert_sampling_factor_m */
796                                            BitstreamSkip(bs, 1);   /* enhancement_type */
797                                            if(dec->shape == VIDOBJLAY_SHAPE_BINARY /* && hierarchy_type==0 */) {
798                                                    BitstreamSkip(bs, 1);   /* use_ref_shape */
799                                                    BitstreamSkip(bs, 1);   /* use_ref_texture */
800                                                    BitstreamSkip(bs, 5);   /* shape_hor_sampling_factor_n */
801                                                    BitstreamSkip(bs, 5);   /* shape_hor_sampling_factor_m */
802                                                    BitstreamSkip(bs, 5);   /* shape_vert_sampling_factor_n */
803                                                    BitstreamSkip(bs, 5);   /* shape_vert_sampling_factor_m */
804                                            }
805                                          return -1;                                          return -1;
806                                  }                                  }
807                          } else                          // dec->shape == BINARY_ONLY                          } else                          // dec->shape == BINARY_ONLY
808                          {                          {
809                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
810                                          if (BitstreamGetBit(bs))        // scalability                                          dec->scalability = BitstreamGetBit(bs); /* scalability */
811                                            if (dec->scalability)
812                                          {                                          {
813                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
814                                                    BitstreamSkip(bs, 4);   /* ref_layer_id */
815                                                    BitstreamSkip(bs, 5);   /* hor_sampling_factor_n */
816                                                    BitstreamSkip(bs, 5);   /* hor_sampling_factor_m */
817                                                    BitstreamSkip(bs, 5);   /* vert_sampling_factor_n */
818                                                    BitstreamSkip(bs, 5);   /* vert_sampling_factor_m */
819                                                  return -1;                                                  return -1;
820                                          }                                          }
821                                  }                                  }
# Line 644  Line 838 
838                                  READ_MARKER();                                  READ_MARKER();
839                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
840    
841                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);                                  DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds);
842                          }                          }
843                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
844                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
# Line 694  Line 888 
888                                  dec->time_bp = (uint32_t)                                  dec->time_bp = (uint32_t)
889                                          (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;
890                          }                          }
891                            DPRINTF(DPRINTF_HEADER,"time_pp=%i", dec->time_pp);
892                            DPRINTF(DPRINTF_HEADER,"time_bp=%i", dec->time_bp);
893    
894                          READ_MARKER();                          READ_MARKER();
895    
# Line 732  Line 928 
928                                  (coding_type == P_VOP || coding_type == I_VOP)) {                                  (coding_type == P_VOP || coding_type == I_VOP)) {
929    
930                                  *reduced_resolution = BitstreamGetBit(bs);                                  *reduced_resolution = BitstreamGetBit(bs);
931                                    DPRINTF(DPRINTF_HEADER, "reduced_resolution %i", *reduced_resolution);
932                          }                          }
933                          else                          else
934                          {                          {
# Line 767  Line 964 
964                          }                          }
965    
966                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {                          if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
967    
968                                    if (!dec->complexity_estimation_disable)
969                                    {
970                                            read_vop_complexity_estimation_header(bs, dec, coding_type);
971                                    }
972    
973                                  // intra_dc_vlc_threshold                                  // intra_dc_vlc_threshold
974                                  *intra_dc_threshold =                                  *intra_dc_threshold =
975                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
# Line 809  Line 1012 
1012                                          }                                          }
1013                                          READ_MARKER();                                          READ_MARKER();
1014    
1015                                          gmc_mv[i].x = x;                                          gmc_warp->duv[i].x = x;
1016                                          gmc_mv[i].y = y;                                          gmc_warp->duv[i].y = y;
1017    
1018                                          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);
1019                                  }                                  }
# Line 849  Line 1052 
1052    
1053                  } else if (start_code == USERDATA_START_CODE) {                  } else if (start_code == USERDATA_START_CODE) {
1054                          char tmp[256];                          char tmp[256];
1055                      int i;                      int i, version, build;
1056                            char packed;
1057    
1058                          BitstreamSkip(bs, 32);  // user_data_start_code                          BitstreamSkip(bs, 32);  // user_data_start_code
1059    
# Line 866  Line 1070 
1070    
1071                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);                          DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp);
1072    
1073                          if(strncmp(tmp, "DivX501b481p", 12) == 0) {                      /* divx detection */
1074                                  dec->packed_mode = 1;                          i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);
1075                                  DPRINTF(DPRINTF_STARTCODE, "packed_mode = %d\n", dec->packed_mode);                          if (i < 2)
1076                                    i = sscanf(tmp, "DivX%db%d%c", &version, &build, &packed);
1077    
1078                            if (i >= 2)
1079                            {
1080                                    dec->packed_mode = (i == 3 && packed == 'p');
1081                                    DPRINTF(DPRINTF_HEADER, "divx version=%i, build=%i packed=%i",
1082                                                    version, build, dec->packed_mode);
1083                          }                          }
1084    
1085                  } else                                  // start_code == ?                  } else                                  // start_code == ?
1086                  {                  {
1087                          if (BitstreamShowBits(bs, 24) == 0x000001) {                          if (BitstreamShowBits(bs, 24) == 0x000001) {
# Line 915  Line 1126 
1126                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1127                                                  const FRAMEINFO * const frame)                                                  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->m_quarterpel ||  (frame->global_flags & XVID_GMC) ||
1135                     (pParam->global & XVID_GLOBAL_REDUCED))
1136                  vol_ver_id = 2;                  vol_ver_id = 2;
1137    
1138            if ((pParam->global & XVID_GLOBAL_REDUCED))
1139                    profile = 0x93; /* advanced realtime simple profile/level 3 */
1140    
1141            if (pParam->m_quarterpel ||  (frame->global_flags & XVID_GMC))
1142                    profile = 0xf3; /* advanced simple profile/level 2 */
1143    
1144            // visual_object_sequence_start_code
1145    //      BitstreamPad(bs);
1146    /* no padding here, anymore. You have to make sure that you are
1147       byte aligned, and that always 1-8 padding bits have been written */
1148    
1149            BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32);
1150            BitstreamPutBits(bs, profile, 8);
1151    
1152            // visual_object_start_code
1153            BitstreamPad(bs);
1154            BitstreamPutBits(bs, VISOBJ_START_CODE, 32);
1155            BitstreamPutBits(bs, 0, 1);             // is_visual_object_identifier
1156            BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4);             // visual_object_type
1157    
1158          // video object_start_code & vo_id          // video object_start_code & vo_id
1159          BitstreamPad(bs);          BitstreamPad(bs);
1160          BitstreamPutBits(bs, VO_START_CODE, 27);          BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32);
         BitstreamPutBits(bs, 0, 5);  
1161    
1162          // video_object_layer_start_code & vol_id          // video_object_layer_start_code & vol_id
1163          BitstreamPutBits(bs, VOL_START_CODE, 28);          BitstreamPad(bs);
1164          BitstreamPutBits(bs, 0, 4);          BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32);
1165    
1166          BitstreamPutBit(bs, 0);         // random_accessible_vol          BitstreamPutBit(bs, 0);         // random_accessible_vol
1167          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication          BitstreamPutBits(bs, 0, 8);     // video_object_type_indication
# Line 1029  Line 1263 
1263          if (vol_ver_id != 1)          if (vol_ver_id != 1)
1264          {          {
1265                  BitstreamPutBit(bs, 0);         // newpred_enable                  BitstreamPutBit(bs, 0);         // newpred_enable
1266                  BitstreamPutBit(bs, 0);         // reduced_resolution_vop_enabled  
1267                    BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0);
1268                                                                            /* reduced_resolution_vop_enabled */
1269          }          }
1270    
1271          BitstreamPutBit(bs, 0);         // scalability          BitstreamPutBit(bs, 0);         // scalability
1272    
1273            /* fake divx5 id, to ensure compatibility with divx5 decoder */
1274    #define DIVX5_ID "DivX501b481p"
1275            if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) {
1276                    BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1277            }
1278    
1279            /* xvid id */
1280    #define XVID_ID "XviD" XVID_BS_VERSION
1281            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1282  }  }
1283    
1284    
# Line 1041  Line 1286 
1286    write vop header    write vop header
1287  */  */
1288  void  void
1289  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(
1290                                                    Bitstream * const bs,
1291                                                  const MBParam * pParam,                                                  const MBParam * pParam,
1292                                                  const FRAMEINFO * const frame,                                                  const FRAMEINFO * const frame,
1293                                                  int vop_coded)                                                  int vop_coded)
1294  {  {
1295          uint32_t i;          uint32_t i;
1296    
1297          BitstreamPad(bs);  //      BitstreamPad(bs);
1298    /* no padding here, anymore. You have to make sure that you are
1299       byte aligned, and that always 1-8 padding bits have been written */
1300    
1301          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
1302    
1303          BitstreamPutBits(bs, frame->coding_type, 2);          BitstreamPutBits(bs, frame->coding_type, 2);
# Line 1080  Line 1329 
1329          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )          if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) )
1330                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1331    
1332            if ((pParam->global & XVID_GLOBAL_REDUCED))
1333                    BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0);
1334    
1335          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold          BitstreamPutBits(bs, 0, 3);     // intra_dc_vlc_threshold
1336    
1337          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
# Line 1088  Line 1340 
1340          }          }
1341    
1342          if (frame->coding_type == S_VOP) {          if (frame->coding_type == S_VOP) {
1343                  if (1)  {               // no_of_sprite_warping_points>=1                  if (1)  {               // no_of_sprite_warping_points>=1 (we use 2!)
1344                          if (pParam->m_quarterpel)                          int k;
1345                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0]                          for (k=0;k<2;k++)
1346                          else                          {
1347                                  bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0]                                  bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k]
1348                          WRITE_MARKER();                          WRITE_MARKER();
1349    
1350                          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]  
1351                          WRITE_MARKER();                          WRITE_MARKER();
1352    
   
1353                          if (pParam->m_quarterpel)                          if (pParam->m_quarterpel)
1354                          {                          {
1355                                  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);
1356                          }                          }
1357                          else                          else
1358                          {                          {
1359                                  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);
1360                          }                          }
   
1361                  }                  }
 /* 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();  
1362                  }                  }
                 // no support for brightness_change!  
1363          }          }
1364    
1365    
1366            DPRINTF(DPRINTF_HEADER, "quant = %i", frame->quant);
1367    
1368          BitstreamPutBits(bs, frame->quant, 5);  // quantizer          BitstreamPutBits(bs, frame->quant, 5);  // quantizer
1369    
1370          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.38

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