[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 1547, Sat Sep 4 14:16:24 2004 UTC revision 1616, Tue May 17 21:03:32 2005 UTC
# Line 20  Line 20 
20   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   * $Id: bitstream.c,v 1.46 2004-09-04 14:16:24 edgomez Exp $   * $Id: bitstream.c,v 1.51 2005-05-17 21:03:32 Skal Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 33  Line 33 
33  #include "mbcoding.h"  #include "mbcoding.h"
34    
35    
36  static uint32_t __inline  static const uint8_t log2_tab_16[256] =  { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
37  log2bin(uint32_t value)  
38    static uint32_t __inline log2bin(uint32_t value)
39  {  {
40          int n = 0;          int n = 0;
41      if (value & 0xffff0000) {
42          while (value) {      value >>= 16;
43                  value >>= 1;      n += 16;
44                  n++;    }
45      if (value & 0xff00) {
46        value >>= 8;
47        n += 8;
48      }
49      if (value & 0xf0) {
50        value >>= 4;
51        n += 4;
52          }          }
53          return n;   return n + log2_tab_16[value];
54  }  }
55    
   
56  static const uint32_t intra_dc_threshold_table[] = {  static const uint32_t intra_dc_threshold_table[] = {
57          32,                                                     /* never use */          32,                                                     /* never use */
58          13,          13,
# Line 381  Line 388 
388  BitstreamReadHeaders(Bitstream * bs,  BitstreamReadHeaders(Bitstream * bs,
389                                           DECODER * dec,                                           DECODER * dec,
390                                           uint32_t * rounding,                                           uint32_t * rounding,
                                          uint32_t * reduced_resolution,  
391                                           uint32_t * quant,                                           uint32_t * quant,
392                                           uint32_t * fcode_forward,                                           uint32_t * fcode_forward,
393                                           uint32_t * fcode_backward,                                           uint32_t * fcode_backward,
# Line 395  Line 401 
401          int32_t time_increment = 0;          int32_t time_increment = 0;
402          int resize = 0;          int resize = 0;
403    
404          do {          while ((BitstreamPos(bs) >> 3) + 4 <= bs->length) {
405    
406                  BitstreamByteAlign(bs);                  BitstreamByteAlign(bs);
407                  start_code = BitstreamShowBits(bs, 32);                  start_code = BitstreamShowBits(bs, 32);
# Line 862  Line 868 
868                                  dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&                                  dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&
869                                  (coding_type == P_VOP || coding_type == I_VOP)) {                                  (coding_type == P_VOP || coding_type == I_VOP)) {
870    
871                                  *reduced_resolution = BitstreamGetBit(bs);                                  if (BitstreamGetBit(bs));
872                                  DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution %i\n", *reduced_resolution);                                          DPRINTF(XVID_DEBUG_ERROR, "RRV not supported (anymore)\n");
                         }  
                         else  
                         {  
                                 *reduced_resolution = 0;  
873                          }                          }
874    
875                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {                          if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
# Line 1038  Line 1040 
1040                          BitstreamSkip(bs, 8);                          BitstreamSkip(bs, 8);
1041                  }                  }
1042          }          }
         while ((BitstreamPos(bs) >> 3) < bs->length);  
1043    
1044  #if 0  #if 0
1045          DPRINTF("*** WARNING: no vop_start_code found");          DPRINTF("*** WARNING: no vop_start_code found");
# Line 1091  Line 1092 
1092          vol_type_ind = VIDOBJLAY_TYPE_ART_SIMPLE;          vol_type_ind = VIDOBJLAY_TYPE_ART_SIMPLE;
1093      }      }
1094    
1095          if ((pParam->vol_flags & XVID_VOL_QUARTERPEL) ||      if ((pParam->vol_flags & (XVID_VOL_MPEGQUANT|XVID_VOL_QUARTERPEL|XVID_VOL_GMC|XVID_VOL_INTERLACING)) ||
1096          (pParam->vol_flags & XVID_VOL_GMC)) {           pParam->max_bframes>0) {
1097          vol_type_ind = VIDOBJLAY_TYPE_ASP;          vol_type_ind = VIDOBJLAY_TYPE_ASP;
1098      }      }
1099    
# Line 1257  Line 1258 
1258    
1259          BitstreamPadAlways(bs); /* next_start_code(); */          BitstreamPadAlways(bs); /* next_start_code(); */
1260    
1261          /* fake divx5 id, to ensure compatibility with divx5 decoder */          /* divx5 userdata string */
1262  #define DIVX5_ID "DivX999b000p"  #define DIVX5_ID "DivX503b1393"
1263          if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED)) {    if ((pParam->global_flags & XVID_GLOBAL_DIVX5_USERDATA)) {
1264                  BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));                  BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID));
1265            if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED))
1266          BitstreamPutBits(bs, 'p', 8);
1267          }          }
1268    
1269          /* xvid id */          /* xvid id */
# Line 1343  Line 1346 
1346                  BitstreamPutBits(bs, frame->rounding_type, 1);                  BitstreamPutBits(bs, frame->rounding_type, 1);
1347    
1348          if ((frame->vol_flags & XVID_VOL_REDUCED_ENABLE))          if ((frame->vol_flags & XVID_VOL_REDUCED_ENABLE))
1349                  BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_REDUCED)?1:0);                  BitstreamPutBit(bs, 0);
1350    
1351          BitstreamPutBits(bs, 0, 3);     /* intra_dc_vlc_threshold */          BitstreamPutBits(bs, 0, 3);     /* intra_dc_vlc_threshold */
1352    
# Line 1405  Line 1408 
1408          }          }
1409    
1410  }  }
1411    
1412    /*
1413     * Group of VOP
1414     */
1415    void
1416    BitstreamWriteGroupOfVopHeader(Bitstream * const bs,
1417                                   const MBParam * pParam,
1418                                   uint32_t is_closed_gov)
1419    {
1420      int64_t time = (pParam->m_stamp + (pParam->fbase/2)) / pParam->fbase;
1421      int hours, minutes, seconds;
1422    
1423      /* compute time_code */
1424      seconds = time % 60; time /= 60;
1425      minutes = time % 60; time /= 60;
1426      hours = time % 24; /* don't overflow */
1427    
1428      BitstreamPutBits(bs, GRPOFVOP_START_CODE, 32);
1429      BitstreamPutBits(bs, hours, 5);
1430      BitstreamPutBits(bs, minutes, 6);
1431      BitstreamPutBit(bs, 1);
1432      BitstreamPutBits(bs, seconds, 6);
1433      BitstreamPutBits(bs, is_closed_gov, 1);
1434      BitstreamPutBits(bs, 0, 1); /* broken_link */
1435    }
1436    
1437    /*
1438     * End of Sequence
1439     */
1440    void
1441    BitstreamWriteEndOfSequence(Bitstream * const bs)
1442    {
1443        BitstreamPadAlways(bs);
1444        BitstreamPutBits(bs, VISOBJSEQ_STOP_CODE, 32);
1445    }
1446    
1447    /*
1448     * Video Packet (resync marker)
1449     */
1450    
1451    void write_video_packet_header(Bitstream * const bs,
1452                                   const MBParam * pParam,
1453                                   const FRAMEINFO * const frame,
1454                                   int mbnum)
1455    {
1456        const int mbnum_bits = log2bin(pParam->mb_width *  pParam->mb_height - 1);
1457        uint32_t nbitsresyncmarker;
1458        int addbits=0;
1459        if (frame->coding_type != I_VOP)
1460            addbits = frame->fcode -1;
1461        if (frame->coding_type == B_VOP)
1462            addbits = MAX(frame->fcode, frame->bcode)-1;
1463        BitstreamPadAlways(bs);
1464        nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits;
1465        BitstreamPutBits(bs, RESYNC_MARKER, nbitsresyncmarker);
1466        BitstreamPutBits(bs, mbnum, mbnum_bits);
1467        BitstreamPutBits(bs, frame->quant, 5);
1468        BitstreamPutBit(bs, 0); /* hec */
1469    }

Legend:
Removed from v.1547  
changed lines
  Added in v.1616

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