Merge remote-tracking branch 'x264/master'
authorPhillip Blucas <pblucas@gmail.com>
Wed, 7 Mar 2012 03:29:22 +0000 (21:29 -0600)
committerPhillip Blucas <pblucas@gmail.com>
Wed, 7 Mar 2012 03:29:22 +0000 (21:29 -0600)
Conflicts:
common/bitstream.h
common/x86/quant-a.asm
encoder/encoder.c

This also reverts de5a0adca1a7d08b1233b317ec092dbf19263d2f

17 files changed:
1  2 
Makefile
common/common.c
common/common.h
common/frame.c
common/frame.h
common/macroblock.c
common/mc.c
common/mc.h
common/x86/quant-a.asm
configure
encoder/analyse.c
encoder/encoder.c
encoder/me.c
encoder/ratecontrol.c
encoder/slicetype.c
tools/checkasm.c
x264.h

diff --cc Makefile
Simple merge
diff --cc common/common.c
@@@ -490,28 -456,6 +490,28 @@@ int x264_param_apply_profile( x264_para
          x264_log( NULL, X264_LOG_ERROR, "invalid profile: %s\n", profile );
          return -1;
      }
-     
 +
 +    if( param->b_mpeg2 )
 +    {
 +        if( p == MPEG2_PROFILE_SIMPLE )
 +        {
 +            param->i_bframe = 0;
 +            param->i_intra_dc_precision = X264_INTRA_DC_8_BIT;
 +            if( param->b_interlaced )
 +            {
 +                x264_log( NULL, X264_LOG_ERROR, "simple profile doesn't support interlacing\n" );
 +                return -1;
 +            }
 +        }
 +        else if( p == MPEG2_PROFILE_MAIN )
 +            param->i_intra_dc_precision = x264_clip3( param->i_intra_dc_precision,
 +                                                      X264_INTRA_DC_8_BIT, X264_INTRA_DC_10_BIT );
 +        else if( p == MPEG2_PROFILE_HIGH )
 +            param->b_high_profile = 1;
 +
 +        return 0;
 +    }
++
      if( p < PROFILE_HIGH444_PREDICTIVE && ((param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant <= 0) ||
          (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + QP_BD_OFFSET) <= 0)) )
      {
diff --cc common/common.h
Simple merge
diff --cc common/frame.c
Simple merge
diff --cc common/frame.h
Simple merge
Simple merge
diff --cc common/mc.c
@@@ -238,120 -242,9 +242,120 @@@ static pixel *get_ref( pixel *dst,   in
      }
  }
  
 +static void hpel_filter_mpeg2( pixel *dsth, pixel *dstv, pixel *dstc, pixel *src,
 +                               int stride, int width, int height, dctcoef *buf )
 +{
 +    for( int y = 0; y < height; y++ )
 +    {
 +        for( int x = 0; x < width; x++ )
 +            dsth[x] = (src[x] + src[x+1] + 1) >> 1;
 +        for( int x = 0; x < width; x++ )
 +            dstv[x] = (src[x] + src[x+stride] + 1) >> 1;
 +        for( int x = 0; x < width; x++ )
 +            dstc[x] = (src[x] + src[x+1] + src[x+stride] + src[x+stride+1] + 2) >> 2;
 +        dsth += stride;
 +        dstv += stride;
 +        dstc += stride;
 +        src += stride;
 +    }
 +}
 +
 +static void mc_luma_mpeg2( pixel *dst,    int i_dst_stride,
 +                           pixel *src[4], int i_src_stride,
 +                           int mvx, int mvy,
 +                           int i_width, int i_height, const x264_weight_t *weight )
 +{
 +    int idx = ((mvx&2)>>1) + (mvy&2);
 +    int offset = (mvy>>2)*i_src_stride + (mvx>>2);
 +    pixel *src1 = src[idx] + offset;
 +    mc_copy( src1, i_src_stride, dst, i_dst_stride, i_width, i_height );
 +}
 +
 +static void mc_chroma_mpeg2( pixel *dstu, pixel *dstv, int i_dst_stride,
 +                            pixel *src, int i_src_stride,
 +                            int mvx, int mvy, int i_width, int i_height )
 +{
 +    mvx /= 4;
 +    mvy /= 4;
 +    src += (mvy >> 1) * i_src_stride + (mvx >> 1)*2;
 +    pixel *srcp = &src[i_src_stride];
 +
 +    if( !((mvx|mvy)&1) ) //fullpell
 +    {
 +        for( int y = 0; y < i_height; y++ )
 +        {
 +            for( int x = 0; x < i_width; x++ )
 +            {
 +                dstu[x] = src[2*x];
 +                dstv[x] = src[2*x+1];
 +            }
 +            dstu += i_dst_stride;
 +            dstv += i_dst_stride;
 +            src += i_src_stride;
 +        }
 +    }
 +    else if( (mvx&mvy)&1 ) // centre hpel positions
 +    {
 +        for( int y = 0; y < i_height; y++ )
 +        {
 +            for( int x = 0; x < i_width; x++ )
 +            {
 +                dstu[x] = ( src[2*x] + src[2*x+2] + srcp[2*x] + srcp[2*x+2] + 2 ) >> 2;
 +                dstv[x] = ( src[2*x+1] + src[2*x+3] + srcp[2*x+1] + srcp[2*x+3] + 2 ) >> 2;
 +            }
 +            dstu += i_dst_stride;
 +            dstv += i_dst_stride;
 +            src   = srcp;
 +            srcp += i_src_stride;
 +        }
 +    }
 +    else if( mvx&1 ) // horizontal hpel positions
 +    {
 +        for( int y = 0; y < i_height; y++ )
 +        {
 +            for( int x = 0; x < i_width; x++ )
 +            {
 +                dstu[x] = ( src[2*x] + src[2*x+2] + 1 ) >> 1;
 +                dstv[x] = ( src[2*x+1] + src[2*x+3] + 1 ) >> 1;
 +            }
 +            dstu += i_dst_stride;
 +            dstv += i_dst_stride;
 +            src  += i_src_stride;
 +        }
 +    }
 +    else // vertical hpel positions
 +    {
 +        for( int y = 0; y < i_height; y++ )
 +        {
 +            for( int x = 0; x < i_width; x++ )
 +            {
 +                dstu[x] = ( src[2*x] + srcp[2*x] + 1 ) >> 1;
 +                dstv[x] = ( src[2*x+1] + srcp[2*x+1] + 1 ) >> 1;
 +            }
 +            dstu += i_dst_stride;
 +            dstv += i_dst_stride;
 +            src = srcp;
 +            srcp += i_src_stride;
 +        }
 +    }
 +}
 +
 +static pixel *get_ref_mpeg2( pixel *dst,   int *i_dst_stride,
 +                             pixel *src[4], int i_src_stride,
 +                             int mvx, int mvy,
 +                             int i_width, int i_height, const x264_weight_t *weight )
 +{
 +    int idx = ((mvx&2)>>1) + (mvy&2);
 +    int offset = (mvy>>2)*i_src_stride + (mvx>>2);
 +    pixel *src1 = src[idx] + offset;
 +
 +    *i_dst_stride = i_src_stride;
 +    return src1;
 +}
 +
  /* full chroma mc (ie until 1/8 pixel)*/
- static void mc_chroma( pixel *dstu, pixel *dstv, int i_dst_stride,
-                        pixel *src, int i_src_stride,
+ static void mc_chroma( pixel *dstu, pixel *dstv, intptr_t i_dst_stride,
+                        pixel *src, intptr_t i_src_stride,
                         int mvx, int mvy,
                         int i_width, int i_height )
  {
diff --cc common/mc.h
Simple merge
Simple merge
diff --cc configure
index 0f1c651,16970b8..acfe7d9
mode 100644,100755..100644
+++ b/configure
Simple merge
@@@ -333,16 -349,8 +349,16 @@@ static void x264_slice_header_write( bs
      }
  }
  
 +static void x264_slice_header_write_mpeg2( x264_t *h, bs_t *s, int i_mb_y )
 +{
 +    if( h->param.i_height > 2800 )
 +       bs_write( s, 3, 0 ); // FIXME
 +    bs_write( s, 5, h->mb.i_qp ); // quantiser_scale_code
 +    bs_write1( s, 0 ); // extra_bit_slice
 +}
 +
  /* If we are within a reasonable distance of the end of the memory allocated for the bitstream, */
- /* reallocate, adding an arbitrary amount of space (100 kilobytes). */
+ /* reallocate, adding an arbitrary amount of space. */
  static int x264_bitstream_check_buffer( x264_t *h )
  {
      uint8_t *bs_bak = h->out.p_bitstream;
@@@ -633,10 -594,9 +649,9 @@@ static int x264_validate_parameters( x2
          h->param.rc.b_mb_tree = 0;
          h->param.rc.i_bitrate = 0;
      }
-     h->param.rc.i_qp_max = x264_clip3( h->param.rc.i_qp_max, 1, MPEG2 ? QP_MAX_SPEC_MPEG2 : QP_MAX );
-     h->param.rc.i_qp_min = x264_clip3( h->param.rc.i_qp_min, 1, h->param.rc.i_qp_max );
-     h->param.rc.i_qp_step = x264_clip3( h->param.rc.i_qp_step, 0, QP_MAX );
 -    h->param.rc.i_qp_max = x264_clip3( h->param.rc.i_qp_max, 0, QP_MAX );
 -    h->param.rc.i_qp_min = x264_clip3( h->param.rc.i_qp_min, 0, h->param.rc.i_qp_max );
++    h->param.rc.i_qp_max = x264_clip3( h->param.rc.i_qp_max, MPEG2, MPEG2 ? QP_MAX_SPEC_MPEG2 : QP_MAX );
++    h->param.rc.i_qp_min = x264_clip3( h->param.rc.i_qp_min, MPEG2, h->param.rc.i_qp_max );
+     h->param.rc.i_qp_step = x264_clip3( h->param.rc.i_qp_step, 2, QP_MAX );
      h->param.rc.i_bitrate = x264_clip3( h->param.rc.i_bitrate, 0, 2000000 );
      h->param.rc.i_vbv_buffer_size = x264_clip3( h->param.rc.i_vbv_buffer_size, 0, 2000000 );
      h->param.rc.i_vbv_max_bitrate = x264_clip3( h->param.rc.i_vbv_max_bitrate, 0, 2000000 );
      BOOLIFY( b_fake_interlaced );
      BOOLIFY( b_open_gop );
      BOOLIFY( b_bluray_compat );
 +    BOOLIFY( b_nonlinear_quant );
 +    BOOLIFY( b_alt_intra_vlc );
 +    BOOLIFY( b_alternate_scan );
+     BOOLIFY( b_full_recon );
      BOOLIFY( analyse.b_transform_8x8 );
      BOOLIFY( analyse.b_weighted_bipred );
      BOOLIFY( analyse.b_chroma_me );
@@@ -2318,41 -2246,15 +2441,24 @@@ static int x264_slice_write( x264_t *h 
          {
              if( x264_bitstream_check_buffer( h ) )
                  return -1;
-             if( back_up_bitstream )
-             {
-                 mv_bits_bak = h->stat.frame.i_mv_bits;
-                 tex_bits_bak = h->stat.frame.i_tex_bits;
-                 /* We don't need the contexts because flushing the CABAC encoder has no context
-                  * dependency and macroblocks are only re-encoded in the case where a slice is
-                  * ended (and thus the content of all contexts are thrown away). */
-                 if( h->param.b_cabac )
-                 {
-                     memcpy( &cabac_bak, &h->cabac, offsetof(x264_cabac_t, f8_bits_encoded) );
-                     /* x264's CABAC writer modifies the previous byte during carry, so it has to be
-                      * backed up. */
-                     cabac_prevbyte_bak = h->cabac.p[-1];
-                 }
-                 else
-                 {
-                     bs_bak = h->out.bs;
-                     i_skip_bak = i_skip;
-                 }
-             }
+             if( !(i_mb_y & SLICE_MBAFF) && h->param.rc.i_vbv_buffer_size )
+                 x264_bitstream_backup( h, &bs_bak[1], i_skip, 1 );
+             if( !h->mb.b_reencode_mb )
+                 x264_fdec_filter_row( h, i_mb_y, 0 );
          }
  
-         if( i_mb_x == 0 && !h->mb.b_reencode_mb )
-             x264_fdec_filter_row( h, i_mb_y, 1 );
+         if( !(i_mb_y & SLICE_MBAFF) && back_up_bitstream )
+             x264_bitstream_backup( h, &bs_bak[0], i_skip, 0 );
  
 +        if( MPEG2 && ( i_skip || i_mb_x == 0 || !IS_INTRA( h->mb.i_type ) ) )
 +            x264_reset_intra_dc_mpeg2( h );
 +
 +        if( MPEG2 && i_mb_x == 0 )
 +        {
 +            i_skip = 0;
 +            x264_reset_mv_predictor_mpeg2( h );
 +        }
 +
          if( PARAM_INTERLACED )
          {
              if( h->mb.b_adaptive_mbaff )
@@@ -2590,18 -2456,8 +2689,16 @@@ reencode
          if( b_deblock )
              x264_macroblock_deblock_strength( h );
  
-         x264_ratecontrol_mb( h, mb_size );
          if( mb_xy == h->sh.i_last_mb )
 +        {
 +            if( MPEG2 )
 +            {
 +                bs_align_0( &h->out.bs );
 +                if( x264_nal_end( h ) )
 +                    return -1;
 +            }
              break;
 +        }
  
          if( SLICE_MBAFF )
          {
diff --cc encoder/me.c
Simple merge
@@@ -1429,9 -1417,9 +1431,9 @@@ int x264_ratecontrol_mb( x264_t *h, in
      rc->qpa_rc += rc->qpm * h->mb.i_mb_width;
  
      if( !rc->b_vbv )
-         return;
+         return 0;
  
 -    float qscale = qp2qscale( rc->qpm );
 +    float qscale = qp2qscale( h, rc->qpm );
      h->fdec->f_row_qp[y] = rc->qpm;
      h->fdec->f_row_qscale[y] = qscale;
  
Simple merge
Simple merge
diff --cc x264.h
Simple merge