]> granicus.if.org Git - libx264/commitdiff
Disable deblocking filter in frames of sufficiently low QP that it would have no...
authorLoren Merritt <pengvado@videolan.org>
Fri, 25 Feb 2005 03:10:04 +0000 (03:10 +0000)
committerLoren Merritt <pengvado@videolan.org>
Fri, 25 Feb 2005 03:10:04 +0000 (03:10 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@144 df754926-b1dd-0310-bc7b-ec298dee348c

common/common.h
encoder/encoder.c
encoder/ratecontrol.c
encoder/set.c

index 9ce75bb054cb13263ed0b06ec7d96df92a5d9e7a..d76f054ff03d21e5c9a8f93930dfbdcea5d62741 100644 (file)
@@ -292,7 +292,6 @@ struct x264_t
         
         /* Search parameters */
         int     i_subpel_refine;
-
         /* Allowed qpel MV range to stay within the picture + emulated edge pixels */
         int     mv_min[2];
         int     mv_max[2];
@@ -367,6 +366,7 @@ struct x264_t
         /* */
         int     i_last_qp;  /* last qp */
         int     i_last_dqp; /* last delta qp */
+        int     b_variable_qp; /* whether qp is allowed to vary per macroblock */
 
         /* B_direct and weighted prediction */
         int     dist_scale_factor[16][16];
index 1b95de1276e6e7716f816df90769f56789ac90d2..61ff00ff35863b04a64301eae81c725390851042 100644 (file)
@@ -119,10 +119,12 @@ static void x264_frame_dump( x264_t *h, x264_frame_t *fr, char *name )
 
 
 /* Fill "default" values */
-static void x264_slice_header_init( x264_slice_header_t *sh, x264_param_t *param,
+static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
                                     x264_sps_t *sps, x264_pps_t *pps,
-                                    int i_type, int i_idr_pic_id, int i_frame )
+                                    int i_type, int i_idr_pic_id, int i_frame, int i_qp )
 {
+    x264_param_t *param = &h->param;
+
     /* First we fill all field */
     sh->sps = sps;
     sh->pps = pps;
@@ -154,11 +156,14 @@ static void x264_slice_header_init( x264_slice_header_t *sh, x264_param_t *param
 
     sh->i_cabac_init_idc = param->i_cabac_init_idc;
 
-    sh->i_qp_delta = 0;
+    sh->i_qp_delta = i_qp - pps->i_pic_init_qp;
     sh->b_sp_for_swidth = 0;
     sh->i_qs_delta = 0;
 
-    if( param->b_deblocking_filter )
+    /* If effective qp <= 15, deblocking would have no effect anyway */
+    if( param->b_deblocking_filter
+        && ( h->mb.b_variable_qp
+        || 15 < i_qp + X264_MAX(param->i_deblocking_filter_alphac0, param->i_deblocking_filter_beta) ) )
     {
         sh->i_disable_deblocking_filter_idc = 0;
     }
@@ -666,7 +671,7 @@ static inline void x264_reference_update( x264_t *h )
     int i;
 
     /* apply deblocking filter to the current decoded picture */
-    if( h->param.b_deblocking_filter )
+    if( !h->sh.i_disable_deblocking_filter_idc )
     {
         TIMER_START( i_mtime_filter );
         x264_frame_deblocking_filter( h, h->sh.i_type );
@@ -719,14 +724,14 @@ static inline void x264_slice_init( x264_t *h, int i_nal_type, int i_slice_type,
     /* ------------------------ Create slice header  ----------------------- */
     if( i_nal_type == NAL_SLICE_IDR )
     {
-        x264_slice_header_init( &h->sh, &h->param, h->sps, h->pps, i_slice_type, h->i_idr_pic_id, h->i_frame_num - 1 );
+        x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, h->i_idr_pic_id, h->i_frame_num - 1, i_global_qp );
 
         /* increment id */
         h->i_idr_pic_id = ( h->i_idr_pic_id + 1 ) % 65536;
     }
     else
     {
-        x264_slice_header_init( &h->sh, &h->param, h->sps, h->pps, i_slice_type, -1, h->i_frame_num - 1 );
+        x264_slice_header_init( h, &h->sh, h->sps, h->pps, i_slice_type, -1, h->i_frame_num - 1, i_global_qp );
 
         /* always set the real higher num of ref frame used */
         h->sh.b_num_ref_idx_override = 1;
@@ -748,9 +753,6 @@ static inline void x264_slice_init( x264_t *h, int i_nal_type, int i_slice_type,
         /* Nothing to do ? */
     }
 
-    /* global qp */
-    h->sh.i_qp_delta = i_global_qp - h->pps->i_pic_init_qp;
-
     /* get adapative cabac model if needed */
     if( h->param.b_cabac )
     {
@@ -869,7 +871,8 @@ static inline void x264_slice_write( x264_t *h, int i_nal_type, int i_nal_ref_id
 
         h->stat.frame.i_mb_count[h->mb.i_type]++;
 
-        x264_ratecontrol_mb(h, bs_pos(&h->out.bs) - mb_spos);
+        if( h->mb.b_variable_qp )
+            x264_ratecontrol_mb(h, bs_pos(&h->out.bs) - mb_spos);
     }
 
     if( h->param.b_cabac )
index b7edc5905a1cb6cd692e4f22d43da8369c4ac700..fecc994a697cfbcc4f728ca94c6caca5334af042 100644 (file)
@@ -188,6 +188,9 @@ int x264_ratecontrol_new( x264_t *h )
     rc->qp_constant[SLICE_TYPE_I] = x264_clip3( (int)( qscale2qp( qp2qscale( h->param.rc.i_qp_constant ) / fabs( h->param.rc.f_ip_factor )) + 0.5 ), 0, 51 );
     rc->qp_constant[SLICE_TYPE_B] = x264_clip3( (int)( qscale2qp( qp2qscale( h->param.rc.i_qp_constant ) * fabs( h->param.rc.f_pb_factor )) + 0.5 ), 0, 51 );
 
+    /* Currently there is no adaptive quant, and per-MB ratecontrol is used only in CBR. */
+    h->mb.b_variable_qp = h->param.rc.b_cbr && !h->param.rc.b_stat_read;
+
     /* Init 1pass CBR algo */
     if( h->param.rc.b_cbr ){
         rc->buffer_size = h->param.rc.i_rc_buffer_size * 1000;
@@ -521,9 +524,6 @@ void x264_ratecontrol_mb( x264_t *h, int bits )
     int dqp;
     int i;
 
-    if( !h->param.rc.b_cbr || h->param.rc.b_stat_read )
-        return;
-
     x264_cpu_restore( h->param.cpu );
 
     rc->qps += rc->qpm;
@@ -907,7 +907,7 @@ static int init_pass2( x264_t *h )
         }
         /* weighted average of cplx of past frames */
         weight = 1.0;
-        for(j=0; j<cplxblur*2 && j<=i; j++){
+        for(j=0; j<=cplxblur*2 && j<=i; j++){
             ratecontrol_entry_t *rcj = &rcc->entry[i-j];
             weight_sum += weight;
             cplx_sum += weight * qscale2bits(rcj, 1);
index c0bfa08b355fd4cc42cdac02c793b01b71e0dc9f..234cfc1ecf69103ac886519c4f131b3b79eee7f0 100644 (file)
@@ -298,16 +298,6 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
     pps->i_pic_init_qs = 26;
 
     pps->i_chroma_qp_index_offset = 0;
-#if 0
-    if( !param->b_deblocking_filter )
-    {
-        pps->b_deblocking_filter_control = 1;
-    }
-    else
-    {
-        pps->b_deblocking_filter_control = 1;
-    }
-#endif
     pps->b_deblocking_filter_control = 1;
     pps->b_constrained_intra_pred = 0;
     pps->b_redundant_pic_cnt = 0;