[svn] / trunk / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/bitstream/bitstream.c

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

revision 223, Wed Jun 19 01:01:02 2002 UTC revision 478, Thu Sep 12 19:06:37 2002 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
   *                                                                            *  
   *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *  
   *                                                                            *  
   *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *  
   *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *  
   *  software module in hardware or software products are advised that its     *  
   *  use may infringe existing patents or copyrights, and any such use         *  
   *  would be at such party's own risk.  The original developer of this        *  
   *  software module and his/her company, and subsequent editors and their     *  
   *  companies, will have no liability for use of this software or             *  
   *  modifications or derivatives thereof.                                     *  
   *                                                                            *  
   *  XviD is free software; you can redistribute it and/or modify it           *  
   *  under the terms of the GNU General Public License as published by         *  
   *  the Free Software Foundation; either version 2 of the License, or         *  
   *  (at your option) any later version.                                       *  
   *                                                                            *  
   *  XviD is distributed in the hope that it will be useful, but               *  
   *  WITHOUT ANY WARRANTY; without even the implied warranty of                *  
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *  
   *  GNU General Public License for more details.                              *  
   *                                                                            *  
   *  You should have received a copy of the GNU General Public License         *  
   *  along with this program; if not, write to the Free Software               *  
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  bitstream.c                                                               *  
   *                                                                            *  
   *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  19.06.2002  Fix a little bug in use custom quant matrix                   *  
   *              MinChen <chenm001@163.com>                                    *  
   *  08.05.2002  add low_delay support for B_VOP decode                        *  
   *              MinChen <chenm001@163.com>                                    *  
   *  06.05.2002 low_delay                                                      *  
   *  06.05.2002 fixed fincr/fbase error                                        *  
   *  01.05.2002 added BVOP support to BitstreamWriteVopHeader                  *  
   *  15.04.2002 rewrite log2bin use asm386  By MinChen <chenm001@163.com>      *  
   *  26.03.2002 interlacing support                                            *  
   *  03.03.2002 qmatrix writing                                                *  
   *  03.03.2002 merged BITREADER and BITWRITER                                 *  
   *      30.02.2002     intra_dc_threshold support                             *  
   *      04.12.2001     support for additional headers                         *  
   *      16.12.2001     inital version                                         *  
2    *    *
3    ******************************************************************************/   *  XVID MPEG-4 VIDEO CODEC
4     *  - Bitstream reader/writer functions -
5     *
6     *  Copyright (C) 2001-2002 - Peter Ross <pross@cs.rmit.edu.au>
7     *
8     *  This program is an implementation of a part of one or more MPEG-4
9     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
10     *  to use this software module in hardware or software products are
11     *  advised that its use may infringe existing patents or copyrights, and
12     *  any such use would be at such party's own risk.  The original
13     *  developer of this software module and his/her company, and subsequent
14     *  editors and their companies, will have no liability for use of this
15     *  software or modifications or derivatives thereof.
16     *
17     *  This program is free software ; you can redistribute it and/or modify
18     *  it under the terms of the GNU General Public License as published by
19     *  the Free Software Foundation ; either version 2 of the License, or
20     *  (at your option) any later version.
21     *
22     *  This program is distributed in the hope that it will be useful,
23     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
24     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     *  GNU General Public License for more details.
26     *
27     *  You should have received a copy of the GNU General Public License
28     *  along with this program ; if not, write to the Free Software
29     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
30     *
31     * $Id: bitstream.c,v 1.30 2002-09-12 19:06:37 edgomez Exp $
32     *
33     ****************************************************************************/
34    
35  #include "bitstream.h"  #include "bitstream.h"
36  #include "zigzag.h"  #include "zigzag.h"
37  #include "../quant/quant_matrix.h"  #include "../quant/quant_matrix.h"
38    
39    /*****************************************************************************
40     * Functions
41     ****************************************************************************/
42    
43  static uint32_t __inline  static uint32_t __inline
44  log2bin(uint32_t value)  log2bin(uint32_t value)
# Line 117  Line 93 
93          }          }
94  }  }
95    
96    
97    
98    // for PVOP addbits == fcode - 1
99    // for BVOP addbits == max(fcode,bcode) - 1
100    // returns mbpos
101    int
102    read_video_packet_header(Bitstream *bs, const int addbits, int * quant)
103    {
104            int nbits;
105            int mbnum;
106            int hec;
107    
108            nbits = NUMBITS_VP_RESYNC_MARKER + addbits;
109    
110            BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs));
111            BitstreamSkip(bs, nbits);
112    
113            DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>");
114    
115            // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
116                    // hec
117                    // vop_width
118                    // marker_bit
119                    // vop_height
120                    // marker_bit
121    
122            //}
123    
124            mbnum = BitstreamGetBits(bs, 9);
125            DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum);
126    
127            // if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY)
128            *quant = BitstreamGetBits(bs, 5);
129            DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
130    
131            // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
132            hec = BitstreamGetBit(bs);
133            DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec);
134            // if (hec)
135            //   .. decoder hec-header ...
136    
137            return mbnum;
138    }
139    
140    
141    
142  /*  /*
143  decode headers  decode headers
144  returns coding_type, or -1 if error  returns coding_type, or -1 if error
145  */  */
146    
147    #define VIDOBJ_START_CODE_MASK          0x0000001f
148    #define VIDOBJLAY_START_CODE_MASK       0x0000000f
149    
150  int  int
151  BitstreamReadHeaders(Bitstream * bs,  BitstreamReadHeaders(Bitstream * bs,
152                                           DECODER * dec,                                           DECODER * dec,
# Line 136  Line 161 
161          uint32_t coding_type;          uint32_t coding_type;
162          uint32_t start_code;          uint32_t start_code;
163          uint32_t time_incr = 0;          uint32_t time_incr = 0;
164          int32_t time_increment;          int32_t time_increment = 0;
165    
166          do {          do {
167                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
168                  start_code = BitstreamShowBits(bs, 32);                  start_code = BitstreamShowBits(bs, 32);
169    
170                  if (start_code == VISOBJSEQ_START_CODE) {                  if (start_code == VISOBJSEQ_START_CODE) {
171                          // DEBUG("visual_object_sequence");  
172                            int profile;
173    
174                            DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>");
175    
176                          BitstreamSkip(bs, 32);  // visual_object_sequence_start_code                          BitstreamSkip(bs, 32);  // visual_object_sequence_start_code
177                          BitstreamSkip(bs, 8);   // profile_and_level_indication                          profile = BitstreamGetBits(bs, 8);      // profile_and_level_indication
178    
179                            DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile);
180    
181                  } else if (start_code == VISOBJSEQ_STOP_CODE) {                  } else if (start_code == VISOBJSEQ_STOP_CODE) {
182    
183                          BitstreamSkip(bs, 32);  // visual_object_sequence_stop_code                          BitstreamSkip(bs, 32);  // visual_object_sequence_stop_code
184    
185                            DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>");
186    
187                  } else if (start_code == VISOBJ_START_CODE) {                  } else if (start_code == VISOBJ_START_CODE) {
188                          // DEBUG("visual_object");  
189                            DPRINTF(DPRINTF_STARTCODE, "<visual_object>");
190    
191                          BitstreamSkip(bs, 32);  // visual_object_start_code                          BitstreamSkip(bs, 32);  // visual_object_start_code
192                          if (BitstreamGetBit(bs))        // is_visual_object_identified                          if (BitstreamGetBit(bs))        // is_visual_object_identified
193                          {                          {
194                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id                                  vol_ver_id = BitstreamGetBits(bs, 4);   // visual_object_ver_id
195                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
196                                  BitstreamSkip(bs, 3);   // visual_object_priority                                  BitstreamSkip(bs, 3);   // visual_object_priority
197                          } else {                          } else {
198                                  vol_ver_id = 1;                                  vol_ver_id = 1;
# Line 161  Line 200 
200    
201                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type                          if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)      // visual_object_type
202                          {                          {
203                                  DEBUG("visual_object_type != video");                                  DPRINTF(DPRINTF_ERROR, "visual_object_type != video");
204                                  return -1;                                  return -1;
205                          }                          }
206                          BitstreamSkip(bs, 4);                          BitstreamSkip(bs, 4);
# Line 170  Line 209 
209    
210                          if (BitstreamGetBit(bs))        // video_signal_type                          if (BitstreamGetBit(bs))        // video_signal_type
211                          {                          {
212                                  DEBUG("+ video_signal_type");                                  DPRINTF(DPRINTF_HEADER,"+ video_signal_type");
213                                  BitstreamSkip(bs, 3);   // video_format                                  BitstreamSkip(bs, 3);   // video_format
214                                  BitstreamSkip(bs, 1);   // video_range                                  BitstreamSkip(bs, 1);   // video_range
215                                  if (BitstreamGetBit(bs))        // color_description                                  if (BitstreamGetBit(bs))        // color_description
216                                  {                                  {
217                                          DEBUG("+ color_description");                                          DPRINTF(DPRINTF_HEADER,"+ color_description");
218                                          BitstreamSkip(bs, 8);   // color_primaries                                          BitstreamSkip(bs, 8);   // color_primaries
219                                          BitstreamSkip(bs, 8);   // transfer_characteristics                                          BitstreamSkip(bs, 8);   // transfer_characteristics
220                                          BitstreamSkip(bs, 8);   // matrix_coefficients                                          BitstreamSkip(bs, 8);   // matrix_coefficients
221                                  }                                  }
222                          }                          }
223                  } else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) {                  } else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) {
224    
225                            DPRINTF(DPRINTF_STARTCODE, "<video_object>");
226                            DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK);
227    
228                          BitstreamSkip(bs, 32);  // video_object_start_code                          BitstreamSkip(bs, 32);  // video_object_start_code
229                  } else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) {  
230                          // DEBUG("video_object_layer");                  } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) {
231    
232                            DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>");
233                            DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK);
234    
235                          BitstreamSkip(bs, 32);  // video_object_layer_start_code                          BitstreamSkip(bs, 32);  // video_object_layer_start_code
236    
237                          BitstreamSkip(bs, 1);   // random_accessible_vol                          BitstreamSkip(bs, 1);   // random_accessible_vol
# Line 192  Line 239 
239                          // video_object_type_indication                          // video_object_type_indication
240                          if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0)   // BUGGY DIVX                          if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0)   // BUGGY DIVX
241                          {                          {
242                                  DEBUG1("video_object_type_indication not supported",                                  DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ",
243                                             BitstreamShowBits(bs, 8));                                             BitstreamShowBits(bs, 8));
244                                  return -1;                                  return -1;
245                          }                          }
# Line 201  Line 248 
248    
249                          if (BitstreamGetBit(bs))        // is_object_layer_identifier                          if (BitstreamGetBit(bs))        // is_object_layer_identifier
250                          {                          {
251                                  DEBUG("+ is_object_layer_identifier");                                  DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier");
252                                  vol_ver_id = BitstreamGetBits(bs, 4);   // video_object_layer_verid                                  vol_ver_id = BitstreamGetBits(bs, 4);   // video_object_layer_verid
253                                    DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id);
254                                  BitstreamSkip(bs, 3);   // video_object_layer_priority                                  BitstreamSkip(bs, 3);   // video_object_layer_priority
255                          } else {                          } else {
256                                  vol_ver_id = 1;                                  vol_ver_id = 1;
257                          }                          }
                         //DEBUGI("vol_ver_id", vol_ver_id);  
258    
259                          if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR)     // aspect_ratio_info                          if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR)     // aspect_ratio_info
260                          {                          {
261                                  DEBUG("+ aspect_ratio_info");                                  DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info");
262                                  BitstreamSkip(bs, 8);   // par_width                                  BitstreamSkip(bs, 8);   // par_width
263                                  BitstreamSkip(bs, 8);   // par_height                                  BitstreamSkip(bs, 8);   // par_height
264                          }                          }
265    
266                          if (BitstreamGetBit(bs))        // vol_control_parameters                          if (BitstreamGetBit(bs))        // vol_control_parameters
267                          {                          {
268                                  DEBUG("+ vol_control_parameters");                                  DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters");
269                                  BitstreamSkip(bs, 2);   // chroma_format                                  BitstreamSkip(bs, 2);   // chroma_format
270                                  dec->low_delay = BitstreamGetBit(bs);   // low_delay                                  dec->low_delay = BitstreamGetBit(bs);   // low_delay
271                                    DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay);
272                                  if (BitstreamGetBit(bs))        // vbv_parameters                                  if (BitstreamGetBit(bs))        // vbv_parameters
273                                  {                                  {
274                                          DEBUG("+ vbv_parameters");                                          DPRINTF(DPRINTF_HEADER,"+ vbv_parameters");
275                                          BitstreamSkip(bs, 15);  // first_half_bitrate                                          BitstreamSkip(bs, 15);  // first_half_bitrate
276                                          READ_MARKER();                                          READ_MARKER();
277                                          BitstreamSkip(bs, 15);  // latter_half_bitrate                                          BitstreamSkip(bs, 15);  // latter_half_bitrate
# Line 240  Line 288 
288                          }                          }
289    
290                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape                          dec->shape = BitstreamGetBits(bs, 2);   // video_object_layer_shape
291                          // DEBUG1("shape", dec->shape);                          DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape);
292    
293                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) {
294                                  BitstreamSkip(bs, 4);   // video_object_layer_shape_extension                                  BitstreamSkip(bs, 4);   // video_object_layer_shape_extension
# Line 250  Line 298 
298    
299  // *************************** for decode B-frame time ***********************  // *************************** for decode B-frame time ***********************
300                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution                          time_increment_resolution = BitstreamGetBits(bs, 16);   // vop_time_increment_resolution
301                          time_increment_resolution--;  
302                          //DEBUG1("time_increment_resolution=",time_increment_resolution);                          DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution);
303    
304    //                      time_increment_resolution--;
305    
306                          if (time_increment_resolution > 0) {                          if (time_increment_resolution > 0) {
307                                  dec->time_inc_bits = log2bin(time_increment_resolution);                                  dec->time_inc_bits = log2bin(time_increment_resolution-1);
308                          } else {                          } else {
309                                  // dec->time_inc_bits = 0;                                  // dec->time_inc_bits = 0;
   
310                                  // for "old" xvid compatibility, set time_inc_bits = 1                                  // for "old" xvid compatibility, set time_inc_bits = 1
311                                  dec->time_inc_bits = 1;                                  dec->time_inc_bits = 1;
312                          }                          }
# Line 265  Line 315 
315    
316                          if (BitstreamGetBit(bs))        // fixed_vop_rate                          if (BitstreamGetBit(bs))        // fixed_vop_rate
317                          {                          {
318                                    DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate");
319                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment                                  BitstreamSkip(bs, dec->time_inc_bits);  // fixed_vop_time_increment
320                          }                          }
321    
# Line 275  Line 326 
326    
327                                          READ_MARKER();                                          READ_MARKER();
328                                          width = BitstreamGetBits(bs, 13);       // video_object_layer_width                                          width = BitstreamGetBits(bs, 13);       // video_object_layer_width
                                         //DEBUGI("width", width);  
329                                          READ_MARKER();                                          READ_MARKER();
330                                          height = BitstreamGetBits(bs, 13);      // video_object_layer_height                                          height = BitstreamGetBits(bs, 13);      // video_object_layer_height
                                         //DEBUGI("height", height);  
331                                          READ_MARKER();                                          READ_MARKER();
332    
333                                            DPRINTF(DPRINTF_HEADER, "width %i", width);
334                                            DPRINTF(DPRINTF_HEADER, "height %i", height);
335    
336                                            // for auto set width & height
337                                            if (dec->width == 0)
338                                                    dec->width = width;
339                                            if (dec->height == 0)
340                                                    dec->height = height;
341    
342                                          if (width != dec->width || height != dec->height) {                                          if (width != dec->width || height != dec->height) {
343                                                  DEBUG("FATAL: video dimension discrepancy ***");                                                  DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream");
                                                 DEBUG2("bitstream width/height", width, height);  
                                                 DEBUG2("param width/height", dec->width, dec->height);  
344                                                  return -1;                                                  return -1;
345                                          }                                          }
346    
347                                  }                                  }
348    
349                                  if ((dec->interlacing = BitstreamGetBit(bs))) {                                  dec->interlacing = BitstreamGetBit(bs);
350                                          DEBUG("vol: interlacing");                                  DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing);
                                 }  
351    
352                                  if (!BitstreamGetBit(bs))       // obmc_disable                                  if (!BitstreamGetBit(bs))       // obmc_disable
353                                  {                                  {
354                                          DEBUG("IGNORED/TODO: !obmc_disable");                                          DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported");
355                                          // TODO                                          // TODO
356                                          // fucking divx4.02 has this enabled                                          // fucking divx4.02 has this enabled
357                                  }                                  }
358    
359                                  if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)))    // sprite_enable                                  if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)))    // sprite_enable
360                                  {                                  {
361                                          DEBUG("sprite_enable; not supported");                                          DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported");
362                                          return -1;                                          return -1;
363                                  }                                  }
364    
# Line 314  Line 369 
369    
370                                  if (BitstreamGetBit(bs))        // not_8_bit                                  if (BitstreamGetBit(bs))        // not_8_bit
371                                  {                                  {
372                                          DEBUG("+ not_8_bit [IGNORED/TODO]");                                          DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)");
373                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision                                          dec->quant_bits = BitstreamGetBits(bs, 4);      // quant_precision
374                                          BitstreamSkip(bs, 4);   // bits_per_pixel                                          BitstreamSkip(bs, 4);   // bits_per_pixel
375                                  } else {                                  } else {
# Line 328  Line 383 
383                                  }                                  }
384    
385                                  dec->quant_type = BitstreamGetBit(bs);  // quant_type                                  dec->quant_type = BitstreamGetBit(bs);  // quant_type
386                                  // DEBUG1("**** quant_type", dec->quant_type);                                  DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type);
387    
388                                  if (dec->quant_type) {                                  if (dec->quant_type) {
389                                          if (BitstreamGetBit(bs))        // load_intra_quant_mat                                          if (BitstreamGetBit(bs))        // load_intra_quant_mat
390                                          {                                          {
391                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
392    
393                                                    DPRINTF(DPRINTF_HEADER, "load_intra_quant_mat");
394    
395                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
396                                                  set_intra_matrix(matrix);                                                  set_intra_matrix(matrix);
397                                          } else                                          } else
# Line 344  Line 401 
401                                          {                                          {
402                                                  uint8_t matrix[64];                                                  uint8_t matrix[64];
403    
404                                                    DPRINTF(DPRINTF_HEADER, "load_inter_quant_mat");
405    
406                                                  bs_get_matrix(bs, matrix);                                                  bs_get_matrix(bs, matrix);
407                                                  set_inter_matrix(matrix);                                                  set_inter_matrix(matrix);
408                                          } else                                          } else
409                                                  set_inter_matrix(get_default_inter_matrix());                                                  set_inter_matrix(get_default_inter_matrix());
410    
411                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {                                          if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
412                                                  // TODO                                                  DPRINTF(DPRINTF_ERROR, "greyscale matrix not supported");
                                                 DEBUG("TODO: grayscale matrix stuff");  
413                                                  return -1;                                                  return -1;
414                                          }                                          }
415    
# Line 359  Line 417 
417    
418    
419                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
420                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sampe                                          DEBUG("QUARTERPEL BITSTREAM");
421                                          if (dec->quarterpel) {                                          dec->quarterpel = BitstreamGetBit(bs);  // quarter_sample
                                                 DEBUG("IGNORED/TODO: quarter_sample");  
422                                          }                                          }
423                                  } else {                                  else
424                                          dec->quarterpel = 0;                                          dec->quarterpel = 0;
425                                  }  
426    
427                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable                                  if (!BitstreamGetBit(bs))       // complexity_estimation_disable
428                                  {                                  {
429                                          DEBUG("TODO: complexity_estimation header");                                          DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported");
                                         // TODO  
430                                          return -1;                                          return -1;
431                                  }                                  }
432    
433                                  if (!BitstreamGetBit(bs))       // resync_marker_disable                                  BitstreamSkip(bs, 1);   // resync_marker_disable
                                 {  
                                         DEBUG("IGNORED/TODO: !resync_marker_disable");  
                                         // TODO  
                                 }  
434    
435                                  if (BitstreamGetBit(bs))        // data_partitioned                                  if (BitstreamGetBit(bs))        // data_partitioned
436                                  {                                  {
437                                          DEBUG("+ data_partitioned");                                          DPRINTF(DPRINTF_ERROR, "data_partitioned not supported");
438                                          BitstreamSkip(bs, 1);   // reversible_vlc                                          BitstreamSkip(bs, 1);   // reversible_vlc
439                                  }                                  }
440    
441                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
442                                          if (BitstreamGetBit(bs))        // newpred_enable                                          if (BitstreamGetBit(bs))        // newpred_enable
443                                          {                                          {
444                                                  DEBUG("+ newpred_enable");                                                  DPRINTF(DPRINTF_HEADER, "+ newpred_enable");
445                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type                                                  BitstreamSkip(bs, 2);   // requested_upstream_message_type
446                                                  BitstreamSkip(bs, 1);   // newpred_segment_type                                                  BitstreamSkip(bs, 1);   // newpred_segment_type
447                                          }                                          }
448                                          if (BitstreamGetBit(bs))        // reduced_resolution_vop_enable                                          if (BitstreamGetBit(bs))        // reduced_resolution_vop_enable
449                                          {                                          {
450                                                  DEBUG("TODO: reduced_resolution_vop_enable");                                                  DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported");
                                                 // TODO  
451                                                  return -1;                                                  return -1;
452                                          }                                          }
453                                  }                                  }
454    
455                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability                                  if ((dec->scalability = BitstreamGetBit(bs)))   // scalability
456                                  {                                  {
457                                          // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                         DEBUG("TODO: scalability");  
458                                          return -1;                                          return -1;
459                                  }                                  }
460                          } else                          // dec->shape == BINARY_ONLY                          } else                          // dec->shape == BINARY_ONLY
# Line 412  Line 462 
462                                  if (vol_ver_id != 1) {                                  if (vol_ver_id != 1) {
463                                          if (BitstreamGetBit(bs))        // scalability                                          if (BitstreamGetBit(bs))        // scalability
464                                          {                                          {
465                                                  // TODO                                          DPRINTF(DPRINTF_ERROR, "scalability not supported");
                                                 DEBUG("TODO: scalability");  
466                                                  return -1;                                                  return -1;
467                                          }                                          }
468                                  }                                  }
# Line 422  Line 471 
471                          }                          }
472    
473                  } else if (start_code == GRPOFVOP_START_CODE) {                  } else if (start_code == GRPOFVOP_START_CODE) {
474                          // DEBUG("group_of_vop");  
475                            DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>");
476    
477                          BitstreamSkip(bs, 32);                          BitstreamSkip(bs, 32);
478                          {                          {
479                                  int hours, minutes, seconds;                                  int hours, minutes, seconds;
# Line 431  Line 482 
482                                  minutes = BitstreamGetBits(bs, 6);                                  minutes = BitstreamGetBits(bs, 6);
483                                  READ_MARKER();                                  READ_MARKER();
484                                  seconds = BitstreamGetBits(bs, 6);                                  seconds = BitstreamGetBits(bs, 6);
485                                  // DEBUG3("hms", hours, minutes, seconds);  
486                                    DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours);
487                          }                          }
488                          BitstreamSkip(bs, 1);   // closed_gov                          BitstreamSkip(bs, 1);   // closed_gov
489                          BitstreamSkip(bs, 1);   // broken_link                          BitstreamSkip(bs, 1);   // broken_link
490    
491                  } else if (start_code == VOP_START_CODE) {                  } else if (start_code == VOP_START_CODE) {
492                          // DEBUG("vop_start_code");  
493                            DPRINTF(DPRINTF_STARTCODE, "<vop>");
494    
495                          BitstreamSkip(bs, 32);  // vop_start_code                          BitstreamSkip(bs, 32);  // vop_start_code
496    
497                          coding_type = BitstreamGetBits(bs, 2);  // vop_coding_type                          coding_type = BitstreamGetBits(bs, 2);  // vop_coding_type
498                          //DEBUG1("coding_type", coding_type);                          DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type);
499    
500  // *************************** for decode B-frame time ***********************  // *************************** for decode B-frame time ***********************
501                          while (BitstreamGetBit(bs) != 0)        // time_base                          while (BitstreamGetBit(bs) != 0)        // time_base
# Line 448  Line 503 
503    
504                          READ_MARKER();                          READ_MARKER();
505    
                         //DEBUG1("time_inc_bits", dec->time_inc_bits);  
                         //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));  
506                          if (dec->time_inc_bits) {                          if (dec->time_inc_bits) {
                                 //BitstreamSkip(bs, dec->time_inc_bits);    // vop_time_increment  
507                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment                                  time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));    // vop_time_increment
508                          }                          }
509    
510                            DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr);
511                            DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment);
512    
513                            DPRINTF(DPRINTF_TIMECODE, "%c %i:%i",
514                                    coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B',
515                                    time_incr, time_increment);
516    
517                          if (coding_type != B_VOP) {                          if (coding_type != B_VOP) {
518                                  dec->last_time_base = dec->time_base;                                  dec->last_time_base = dec->time_base;
519                                  dec->time_base += time_incr;                                  dec->time_base += time_incr;
520                                  dec->time =                                  dec->time = time_increment;
521                                          dec->time_base * time_increment_resolution +  
522    /*                                      dec->time_base * time_increment_resolution +
523                                          time_increment;                                          time_increment;
524                                  dec->time_pp = (uint32_t) (dec->time - dec->last_non_b_time);  */                              dec->time_pp = (uint32_t)
525                                            (time_increment_resolution + dec->time - dec->last_non_b_time)%time_increment_resolution;
526                                  dec->last_non_b_time = dec->time;                                  dec->last_non_b_time = dec->time;
527                          } else {                          } else {
528                                  dec->time =                                  dec->time = time_increment;
529    /*
530                                          (dec->last_time_base +                                          (dec->last_time_base +
531                                           time_incr) * time_increment_resolution + time_increment;                                           time_incr) * time_increment_resolution + time_increment;
532                                  dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time);  */
533                                    dec->time_bp = (uint32_t)
534                                            (time_increment_resolution + dec->last_non_b_time - dec->time)%time_increment_resolution;
535                          }                          }
                         //DEBUG1("time_increment=",time_increment);  
536    
537                          READ_MARKER();                          READ_MARKER();
538    
539                          if (!BitstreamGetBit(bs))       // vop_coded                          if (!BitstreamGetBit(bs))       // vop_coded
540                          {                          {
541                                    DPRINTF(DPRINTF_HEADER, "vop_coded==false");
542                                  return N_VOP;                                  return N_VOP;
543                          }                          }
544    
# Line 486  Line 551 
551                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&                          if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
552                                  (coding_type == P_VOP)) {                                  (coding_type == P_VOP)) {
553                                  *rounding = BitstreamGetBit(bs);        // rounding_type                                  *rounding = BitstreamGetBit(bs);        // rounding_type
554                                  //DEBUG1("rounding", *rounding);                                  DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding);
555                          }                          }
556    
557                          /* if (reduced_resolution_enable)                          /* if (reduced_resolution_enable)
# Line 507  Line 572 
572                                  vert_mc_ref = BitstreamGetBits(bs, 13);                                  vert_mc_ref = BitstreamGetBits(bs, 13);
573                                  READ_MARKER();                                  READ_MARKER();
574    
575                                  // DEBUG2("vop_width/height", width, height);                                  DPRINTF(DPRINTF_HEADER, "width %i", width);
576                                  // DEBUG2("ref             ", horiz_mc_ref, vert_mc_ref);                                  DPRINTF(DPRINTF_HEADER, "height %i", height);
577                                    DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref);
578                                    DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref);
579    
580                                  BitstreamSkip(bs, 1);   // change_conv_ratio_disable                                  BitstreamSkip(bs, 1);   // change_conv_ratio_disable
581                                  if (BitstreamGetBit(bs))        // vop_constant_alpha                                  if (BitstreamGetBit(bs))        // vop_constant_alpha
# Line 524  Line 591 
591                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];                                          intra_dc_threshold_table[BitstreamGetBits(bs, 3)];
592    
593                                  if (dec->interlacing) {                                  if (dec->interlacing) {
594                                          if ((dec->top_field_first = BitstreamGetBit(bs))) {                                          dec->top_field_first = BitstreamGetBit(bs);
595                                                  DEBUG("vop: top_field_first");                                          DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first);
596                                          }                                          dec->alternate_vertical_scan = BitstreamGetBit(bs);
597                                          if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) {                                          DPRINTF(DPRINTF_HEADER, "interlace alternate_vertical_scan %i", dec->alternate_vertical_scan);
598                                                  DEBUG("vop: alternate_vertical_scan");  
                                         }  
599                                  }                                  }
600                          }                          }
601    
602                          if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1)       // vop_quant                          if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1)       // vop_quant
603                                  *quant = 1;                                  *quant = 1;
604    
605                          //DEBUG1("quant", *quant);                          DPRINTF(DPRINTF_HEADER, "quant %i", *quant);
606    
607                          if (coding_type != I_VOP) {                          if (coding_type != I_VOP) {
608                                  *fcode_forward = BitstreamGetBits(bs, 3);       // fcode_forward                                  *fcode_forward = BitstreamGetBits(bs, 3);       // fcode_forward
609                                    DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward);
610                          }                          }
611    
612                          if (coding_type == B_VOP) {                          if (coding_type == B_VOP) {
613                                  *fcode_backward = BitstreamGetBits(bs, 3);      // fcode_backward                                  *fcode_backward = BitstreamGetBits(bs, 3);      // fcode_backward
614                                    DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward);
615                          }                          }
616                          if (!dec->scalability) {                          if (!dec->scalability) {
617                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&                                  if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&
# Line 552  Line 620 
620                                  }                                  }
621                          }                          }
622                          return coding_type;                          return coding_type;
623    
624                  } else if (start_code == USERDATA_START_CODE) {                  } else if (start_code == USERDATA_START_CODE) {
625                          // DEBUG("user_data");  
626                            DPRINTF(DPRINTF_STARTCODE, "<user_data>");
627    
628                          BitstreamSkip(bs, 32);  // user_data_start_code                          BitstreamSkip(bs, 32);  // user_data_start_code
629    
630                  } else                                  // start_code == ?                  } else                                  // start_code == ?
631                  {                  {
632                          if (BitstreamShowBits(bs, 24) == 0x000001) {                          if (BitstreamShowBits(bs, 24) == 0x000001) {
633                                  DEBUG1("*** WARNING: unknown start_code",                                  DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32));
                                            BitstreamShowBits(bs, 32));  
634                          }                          }
635                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
636                  }                  }
637          }          }
638          while ((BitstreamPos(bs) >> 3) < bs->length);          while ((BitstreamPos(bs) >> 3) < bs->length);
639    
640          DEBUG("*** WARNING: no vop_start_code found");          //DPRINTF("*** WARNING: no vop_start_code found");
641          return -1;                                      /* ignore it */          return -1;                                      /* ignore it */
642  }  }
643    
# Line 580  Line 651 
651          int i, j;          int i, j;
652          const int last = matrix[scan_tables[0][63]];          const int last = matrix[scan_tables[0][63]];
653    
654          for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--);          for (j = 63; j > 0 && matrix[scan_tables[0][j - 1]] == last; j--);
655    
656          for (i = 0; i <= j; i++) {          for (i = 0; i <= j; i++) {
657                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);                  BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);
# Line 614  Line 685 
685          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)          BitstreamPutBit(bs, 0);         // is_object_layer_identified (0=not given)
686          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)          BitstreamPutBits(bs, 1, 4);     // aspect_ratio_info (1=1:1)
687    
 #ifdef BFRAMES  
         if (pParam->max_bframes > 0) {  
                 dprintf("low_delay=1");  
688                  BitstreamPutBit(bs, 1); // vol_control_parameters                  BitstreamPutBit(bs, 1); // vol_control_parameters
689                  BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"                  BitstreamPutBits(bs, 1, 2);     // chroma_format 1="4:2:0"
690    
691    #ifdef BFRAMES
692            if (pParam->max_bframes > 0) {
693                  BitstreamPutBit(bs, 0); // low_delay                  BitstreamPutBit(bs, 0); // low_delay
                 BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)  
694          } else          } else
695  #endif  #endif
696          {          {
697                  BitstreamPutBits(bs, 0, 1);     // vol_control_parameters (0=not given)                  BitstreamPutBit(bs, 1); // low_delay
698          }          }
699            BitstreamPutBit(bs, 0); // vbv_parameters (0=not given)
700    
701          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)          BitstreamPutBits(bs, 0, 2);     // video_object_layer_shape (0=rectangular)
702    
# Line 640  Line 710 
710  #ifdef BFRAMES  #ifdef BFRAMES
711          BitstreamPutBits(bs, pParam->fbase, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
712  #else  #else
713          BitstreamPutBits(bs, 2, 16);          BitstreamPutBits(bs, pParam->fbase, 16);
714  #endif  #endif
715    
716          WRITE_MARKER();          WRITE_MARKER();
717    
718          // fixed_vop_rate  #ifdef BFRAMES
719          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
720            BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
721          // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution)  #else
722          // BitstreamPutBits(bs, 0, 15);          BitstreamPutBit(bs, 1);         // fixed_vop_rate = 1
723            BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase));    // fixed_vop_time_increment
724    #endif
725    
726          WRITE_MARKER();          WRITE_MARKER();
727          BitstreamPutBits(bs, pParam->width, 13);        // width          BitstreamPutBits(bs, pParam->width, 13);        // width
# Line 696  Line 768 
768  void  void
769  BitstreamWriteVopHeader(Bitstream * const bs,  BitstreamWriteVopHeader(Bitstream * const bs,
770                                                  const MBParam * pParam,                                                  const MBParam * pParam,
771                                                  const FRAMEINFO * frame)                                                  const FRAMEINFO * frame,
772                                                    int vop_coded)
773  {  {
 #ifdef BFRAMES  
774          uint32_t i;          uint32_t i;
775  #endif  
776          BitstreamPad(bs);          BitstreamPad(bs);
777          BitstreamPutBits(bs, VOP_START_CODE, 32);          BitstreamPutBits(bs, VOP_START_CODE, 32);
778    
# Line 713  Line 785 
785          }          }
786          BitstreamPutBit(bs, 0);          BitstreamPutBit(bs, 0);
787  #else  #else
788          BitstreamPutBits(bs, 0, 1);          for (i = 0; i < frame->seconds; i++) {
789                    BitstreamPutBit(bs, 1);
790            }
791            BitstreamPutBit(bs, 0);
792    //      BitstreamPutBits(bs, 0, 1);
793  #endif  #endif
794    
795          WRITE_MARKER();          WRITE_MARKER();
# Line 721  Line 797 
797          // time_increment: value=nth_of_sec, nbits = log2(resolution)          // time_increment: value=nth_of_sec, nbits = log2(resolution)
798  #ifdef BFRAMES  #ifdef BFRAMES
799          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
800          dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks,          /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks,
801                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==                          frame->coding_type == I_VOP ? 'I' : frame->coding_type ==
802                          P_VOP ? 'P' : 'B');                          P_VOP ? 'P' : 'B');*/
803  #else  #else
804          BitstreamPutBits(bs, 1, 1);          BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase));
805    //      BitstreamPutBits(bs, 1, 1);
806  #endif  #endif
807    
808          WRITE_MARKER();          WRITE_MARKER();
809    
810            if (!vop_coded) {
811                    BitstreamPutBits(bs, 0, 1);
812                    return;
813            }
814    
815          BitstreamPutBits(bs, 1, 1);     // vop_coded          BitstreamPutBits(bs, 1, 1);     // vop_coded
816    
817          if (frame->coding_type == P_VOP)          if (frame->coding_type == P_VOP)

Legend:
Removed from v.223  
changed lines
  Added in v.478

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