shithub: libvpx

Download patch

ref: d90b1ee16cb13f3b868efc5b084b33a65000689e
parent: 063d68b7eae642996c7fe7af38709c2f1029f091
parent: 3cc5b92c6516aac4c3f9bf27974bd8543b286251
author: Paul Wilkins <paulwilkins@google.com>
date: Mon Feb 27 12:58:12 EST 2012

Merge "Further code simplification and clean up." into experimental

--- a/vp8/common/onyx.h
+++ b/vp8/common/onyx.h
@@ -53,7 +53,6 @@
 
     typedef enum
     {
-        MODE_REALTIME       = 0x0,
         MODE_GOODQUALITY    = 0x1,
         MODE_BESTQUALITY    = 0x2,
         MODE_FIRSTPASS      = 0x3,
@@ -175,10 +174,6 @@
         // these parameters aren't to be used in final build don't use!!!
         int play_alternate;
         int alt_freq;
-        int alt_q;
-        int key_q;
-        int gold_q;
-
 
         int multi_threaded;   // how many threads to run the encoder on
         int token_partitions; // how many token partitions to create for multi core decoding
--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -349,34 +349,9 @@
     // Max allocation for a single frame based on the max section guidelines passed in and how many bits are left
     int max_bits;
 
-    // For CBR we need to also consider buffer fullness.
-    // If we are running below the optimal level then we need to gradually tighten up on max_bits.
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double buffer_fullness_ratio = (double)cpi->buffer_level / DOUBLE_DIVIDE_CHECK((double)cpi->oxcf.optimal_buffer_level);
+    // For VBR base this on the bits and frames left plus the two_pass_vbrmax_section rate passed in by the user
+    max_bits = (int)(((double)cpi->twopass.bits_left / (cpi->twopass.total_stats->count - (double)cpi->common.current_video_frame)) * ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0));
 
-        // For CBR base this on the target average bits per frame plus the maximum sedction rate passed in by the user
-        max_bits = (int)(cpi->av_per_frame_bandwidth * ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0));
-
-        // If our buffer is below the optimum level
-        if (buffer_fullness_ratio < 1.0)
-        {
-            // The lower of max_bits / 4 or cpi->av_per_frame_bandwidth / 4.
-            int min_max_bits = ((cpi->av_per_frame_bandwidth >> 2) < (max_bits >> 2)) ? cpi->av_per_frame_bandwidth >> 2 : max_bits >> 2;
-
-            max_bits = (int)(max_bits * buffer_fullness_ratio);
-
-            if (max_bits < min_max_bits)
-                max_bits = min_max_bits;       // Lowest value we will set ... which should allow the buffer to refil.
-        }
-    }
-    // VBR
-    else
-    {
-        // For VBR base this on the bits and frames left plus the two_pass_vbrmax_section rate passed in by the user
-        max_bits = (int)(((double)cpi->twopass.bits_left / (cpi->twopass.total_stats->count - (double)cpi->common.current_video_frame)) * ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0));
-    }
-
     // Trap case where we are out of bits
     if (max_bits < 0)
         max_bits = 0;
@@ -1828,35 +1803,6 @@
     cpi->twopass.gf_decay_rate =
         (i > 0) ? (int)(100.0 * (1.0 - decay_accumulator)) / i : 0;
 
-    // When using CBR apply additional buffer related upper limits
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double max_boost;
-
-        // For cbr apply buffer related limits
-        if (cpi->drop_frames_allowed)
-        {
-            int df_buffer_level = cpi->oxcf.drop_frames_water_mark *
-                                  (cpi->oxcf.optimal_buffer_level / 100);
-
-            if (cpi->buffer_level > df_buffer_level)
-                max_boost = ((double)((cpi->buffer_level - df_buffer_level) * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-            else
-                max_boost = 0.0;
-        }
-        else if (cpi->buffer_level > 0)
-        {
-            max_boost = ((double)(cpi->buffer_level * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-        }
-        else
-        {
-            max_boost = 0.0;
-        }
-
-        if (boost_score > max_boost)
-            boost_score = max_boost;
-    }
-
     // Dont allow conventional gf too near the next kf
     if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL)
     {
@@ -2175,13 +2121,6 @@
             }
         }
 
-        // Apply an additional limit for CBR
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            if (cpi->twopass.gf_bits > (cpi->buffer_level >> 1))
-                cpi->twopass.gf_bits = cpi->buffer_level >> 1;
-        }
-
         // Dont allow a negative value for gf_bits
         if (gf_bits < 0)
             gf_bits = 0;
@@ -2839,51 +2778,6 @@
         max_grp_bits = (int64_t)max_bits * (int64_t)cpi->twopass.frames_to_key;
         if (cpi->twopass.kf_group_bits > max_grp_bits)
             cpi->twopass.kf_group_bits = max_grp_bits;
-
-        // Additional special case for CBR if buffer is getting full.
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            int opt_buffer_lvl = cpi->oxcf.optimal_buffer_level;
-            int buffer_lvl = cpi->buffer_level;
-
-            // If the buffer is near or above the optimal and this kf group is
-            // not being allocated much then increase the allocation a bit.
-            if (buffer_lvl >= opt_buffer_lvl)
-            {
-                int high_water_mark = (opt_buffer_lvl +
-                                       cpi->oxcf.maximum_buffer_size) >> 1;
-
-                int64_t av_group_bits;
-
-                // Av bits per frame * number of frames
-                av_group_bits = (int64_t)cpi->av_per_frame_bandwidth *
-                                (int64_t)cpi->twopass.frames_to_key;
-
-                // We are at or above the maximum.
-                if (cpi->buffer_level >= high_water_mark)
-                {
-                    int64_t min_group_bits;
-
-                    min_group_bits = av_group_bits +
-                                     (int64_t)(buffer_lvl -
-                                                 high_water_mark);
-
-                    if (cpi->twopass.kf_group_bits < min_group_bits)
-                        cpi->twopass.kf_group_bits = min_group_bits;
-                }
-                // We are above optimal but below the maximum
-                else if (cpi->twopass.kf_group_bits < av_group_bits)
-                {
-                    int64_t bits_below_av = av_group_bits -
-                                              cpi->twopass.kf_group_bits;
-
-                    cpi->twopass.kf_group_bits +=
-                       (int64_t)((double)bits_below_av *
-                                   (double)(buffer_lvl - opt_buffer_lvl) /
-                                   (double)(high_water_mark - opt_buffer_lvl));
-                }
-            }
-        }
     }
     else
         cpi->twopass.kf_group_bits = 0;
@@ -2963,33 +2857,6 @@
         //    cpi->twopass.section_max_qfactor = 1.0;
     }
 
-    // When using CBR apply additional buffer fullness related upper limits
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        double max_boost;
-
-        if (cpi->drop_frames_allowed)
-        {
-            int df_buffer_level = cpi->oxcf.drop_frames_water_mark * (cpi->oxcf.optimal_buffer_level / 100);
-
-            if (cpi->buffer_level > df_buffer_level)
-                max_boost = ((double)((cpi->buffer_level - df_buffer_level) * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-            else
-                max_boost = 0.0;
-        }
-        else if (cpi->buffer_level > 0)
-        {
-            max_boost = ((double)(cpi->buffer_level * 2 / 3) * 16.0) / DOUBLE_DIVIDE_CHECK((double)cpi->av_per_frame_bandwidth);
-        }
-        else
-        {
-            max_boost = 0.0;
-        }
-
-        if (boost_score > max_boost)
-            boost_score = max_boost;
-    }
-
     // Reset the first pass file position
     reset_fpf_position(cpi, start_position);
 
@@ -3065,13 +2932,6 @@
         // Calculate the number of bits to be spent on the key frame
         cpi->twopass.kf_bits  = (int)((double)kf_boost * ((double)cpi->twopass.kf_group_bits / (double)allocation_chunks));
 
-        // Apply an additional limit for CBR
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            if (cpi->twopass.kf_bits > ((3 * cpi->buffer_level) >> 2))
-                cpi->twopass.kf_bits = (3 * cpi->buffer_level) >> 2;
-        }
-
         // If the key frame is actually easier than the average for the
         // kf group (which does sometimes happen... eg a blank intro frame)
         // Then use an alternate calculation based on the kf error score
@@ -3154,15 +3014,10 @@
         //if ( av_bits_per_frame < 0.0 )
         //  av_bits_per_frame = 0.0
 
-        // CBR... Use the clip average as the target for deciding resample
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            bits_per_frame = av_bits_per_frame;
-        }
-
         // In VBR we want to avoid downsampling in easy section unless we are under extreme pressure
         // So use the larger of target bitrate for this sectoion or average bitrate for sequence
-        else
+        //else
+        // TBD deprecatae spatial resampling for experminetal
         {
             bits_per_frame = cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key;     // This accounts for how hard the section is...
 
@@ -3197,20 +3052,7 @@
             fclose(f);
         }
 
-        // The trigger for spatial resampling depends on the various parameters such as whether we are streaming (CBR) or VBR.
-        if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-        {
-            // Trigger resample if we are projected to fall below down sample level or
-            // resampled last time and are projected to remain below the up sample level
-            if ((projected_buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100)) ||
-                (last_kf_resampled && (projected_buffer_level < (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))))
-                //( ((cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100))) &&
-                //  ((projected_buffer_level < (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))) ))
-                resample_trigger = TRUE;
-            else
-                resample_trigger = FALSE;
-        }
-        else
+        // The trigger for spatial resampling depends on the various parameters.
         {
             int64_t clip_bits = (int64_t)(cpi->twopass.total_stats->count * cpi->oxcf.target_bandwidth / DOUBLE_DIVIDE_CHECK((double)cpi->oxcf.frame_rate));
             int64_t over_spend = cpi->oxcf.starting_buffer_level - cpi->buffer_level;
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1231,8 +1231,6 @@
 
     cpi->oxcf = *oxcf;
 
-    cpi->auto_gold = 1;
-    cpi->auto_adjust_gold_quantizer = 1;
     cpi->goldfreq = 7;
 
     cm->version = oxcf->Version;
@@ -1320,38 +1318,12 @@
         break;
     }
 
-
     cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q];
     cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q];
     cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level];
 
-    if (oxcf->fixed_q >= 0)
-    {
-        if (oxcf->worst_allowed_q < 0)
-            cpi->oxcf.fixed_q = q_trans[0];
-        else
-            cpi->oxcf.fixed_q = q_trans[oxcf->worst_allowed_q];
+    cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
 
-        if (oxcf->alt_q < 0)
-            cpi->oxcf.alt_q = q_trans[0];
-        else
-            cpi->oxcf.alt_q = q_trans[oxcf->alt_q];
-
-        if (oxcf->key_q < 0)
-            cpi->oxcf.key_q = q_trans[0];
-        else
-            cpi->oxcf.key_q = q_trans[oxcf->key_q];
-
-        if (oxcf->gold_q < 0)
-            cpi->oxcf.gold_q = q_trans[0];
-        else
-            cpi->oxcf.gold_q = q_trans[oxcf->gold_q];
-
-    }
-
-    cpi->baseline_gf_interval =
-        cpi->oxcf.alt_freq ? cpi->oxcf.alt_freq : DEFAULT_GF_INTERVAL;
-
     cpi->ref_frame_flags = VP8_ALT_FLAG | VP8_GOLD_FLAG | VP8_LAST_FLAG;
 
     //cpi->use_golden_frame_only = 0;
@@ -2434,10 +2406,6 @@
 {
     VP8_COMMON *cm = &cpi->common;
 
-    // Select an interval before next GF or altref
-    if (!cpi->auto_gold)
-        cpi->frames_till_gf_update_due = cpi->goldfreq;
-
     // Update data structure that monitors level of reference to last GF
     vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
     cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
@@ -2460,10 +2428,6 @@
     // Update the Golden frame usage counts.
     if (cm->refresh_golden_frame)
     {
-        // Select an interval before next GF
-        if (!cpi->auto_gold)
-            cpi->frames_till_gf_update_due = cpi->goldfreq;
-
         // Update data structure that monitors level of reference to last GF
         vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
         cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
@@ -3110,37 +3074,6 @@
         return;
     }
 
-    // Reduce active_worst_allowed_q for CBR if our buffer is getting too full.
-    // This has a knock on effect on active best quality as well.
-    // For CBR if the buffer reaches its maximum level then we can no longer
-    // save up bits for later frames so we might as well use them up
-    // on the current frame.
-    if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-        (cpi->buffer_level >= cpi->oxcf.optimal_buffer_level) && cpi->buffered_mode)
-    {
-        int Adjustment = cpi->active_worst_quality / 4;       // Max adjustment is 1/4
-
-        if (Adjustment)
-        {
-            int buff_lvl_step;
-
-            if (cpi->buffer_level < cpi->oxcf.maximum_buffer_size)
-            {
-                buff_lvl_step = (cpi->oxcf.maximum_buffer_size - cpi->oxcf.optimal_buffer_level) / Adjustment;
-
-                if (buff_lvl_step)
-                    Adjustment = (cpi->buffer_level - cpi->oxcf.optimal_buffer_level) / buff_lvl_step;
-                else
-                    Adjustment = 0;
-            }
-
-            cpi->active_worst_quality -= Adjustment;
-
-            if(cpi->active_worst_quality < cpi->active_best_quality)
-                cpi->active_worst_quality = cpi->active_best_quality;
-        }
-    }
-
     vp8_clear_system_state();
 
     // Set an active best quality and if necessary active worst quality
@@ -3221,24 +3154,6 @@
         }
     }
 
-    // If CBR and the buffer is as full then it is reasonable to allow
-    // higher quality on the frames to prevent bits just going to waste.
-    if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
-    {
-        // Note that the use of >= here elliminates the risk of a devide
-        // by 0 error in the else if clause
-        if (cpi->buffer_level >= cpi->oxcf.maximum_buffer_size)
-            cpi->active_best_quality = cpi->best_quality;
-
-        else if (cpi->buffer_level > cpi->oxcf.optimal_buffer_level)
-        {
-            int Fraction = ((cpi->buffer_level - cpi->oxcf.optimal_buffer_level) * 128) / (cpi->oxcf.maximum_buffer_size - cpi->oxcf.optimal_buffer_level);
-            int min_qadjustment = ((cpi->active_best_quality - cpi->best_quality) * Fraction) / 128;
-
-            cpi->active_best_quality -= min_qadjustment;
-        }
-    }
-
     // Clip the active best and worst quality values to limits
     if (cpi->active_worst_quality > cpi->worst_quality)
         cpi->active_worst_quality = cpi->worst_quality;
@@ -3428,28 +3343,8 @@
         if (frame_over_shoot_limit == 0)
             frame_over_shoot_limit = 1;
 
-        // Are we are overshooting and up against the limit of active max Q.
-        if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)     &&
-            (Q == cpi->active_worst_quality)                      &&
-            (cpi->active_worst_quality < cpi->worst_quality)      &&
-            (cpi->projected_frame_size > frame_over_shoot_limit))
-        {
-            int over_size_percent = ((cpi->projected_frame_size - frame_over_shoot_limit) * 100) / frame_over_shoot_limit;
+        active_worst_qchanged = FALSE;
 
-            // If so is there any scope for relaxing it
-            while ((cpi->active_worst_quality < cpi->worst_quality) && (over_size_percent > 0))
-            {
-                cpi->active_worst_quality++;
-                top_index = cpi->active_worst_quality;
-                over_size_percent = (int)(over_size_percent * 0.96);        // Assume 1 qstep = about 4% on frame size.
-            }
-
-            // If we have updated the active max Q do not call vp8_update_rate_correction_factors() this loop.
-            active_worst_qchanged = TRUE;
-        }
-        else
-            active_worst_qchanged = FALSE;
-
         // Special case handling for forced key frames
         if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
         {
@@ -3803,19 +3698,6 @@
         cpi->ni_tot_qi += Q;
         cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
     }
-
-#if 0
-
-    // If the frame was massively oversize and we are below optimal buffer level drop next frame
-    if ((cpi->drop_frames_allowed) &&
-        (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-        (cpi->buffer_level < cpi->oxcf.drop_frames_water_mark * cpi->oxcf.optimal_buffer_level / 100) &&
-        (cpi->projected_frame_size > (4 * cpi->this_frame_target)))
-    {
-        cpi->drop_frame = TRUE;
-    }
-
-#endif
 
     // Set the count for maximum consequative dropped frames based upon the ratio of
     // this frame size to the target average per frame bandwidth.
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -486,8 +486,6 @@
     int compressor_speed;
 
     int interquantizer;
-    int auto_gold;
-    int auto_adjust_gold_quantizer;
     int goldfreq;
     int auto_worst_q;
     int cpu_used;
--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -232,12 +232,8 @@
     //cpi->common.filter_level = 0;      // Reset every key frame.
     cpi->common.filter_level = cpi->common.base_qindex * 3 / 8 ;
 
-    // Provisional interval before next GF
-    if (cpi->auto_gold)
-        //cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
-        cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-    else
-        cpi->frames_till_gf_update_due = cpi->goldfreq;
+    // interval before next GF
+    cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
 
     cpi->common.refresh_golden_frame = TRUE;
     cpi->common.refresh_alt_ref_frame = TRUE;
@@ -308,19 +304,9 @@
     // Clear down mmx registers to allow floating point in what follows
     vp8_clear_system_state();  //__asm emms;
 
-    if (cpi->oxcf.fixed_q >= 0)
-    {
-        int Q = cpi->oxcf.key_q;
+    // New Two pass RC
+    target = cpi->per_frame_bandwidth;
 
-        target = estimate_bits_at_q(INTRA_FRAME, Q, cpi->common.MBs,
-                                    cpi->key_frame_rate_correction_factor);
-    }
-    else
-    {
-        // New Two pass RC
-        target = cpi->per_frame_bandwidth;
-    }
-
     if (cpi->oxcf.rc_max_intra_bitrate_pct)
     {
         unsigned int max_rate = cpi->per_frame_bandwidth
@@ -337,29 +323,11 @@
 
 //  Do the best we can to define the parameteres for the next GF based
 //  on what information we have available.
-//  In this experimental code only two pass is supported.
+//
+//  In this experimental code only two pass is supported
+//  so we just use the interval determined in the two pass code.
 static void calc_gf_params(VP8_COMP *cpi)
 {
-    int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
-    int Boost = 0;
-
-    int gf_frame_useage = 0;      // Golden frame useage since last GF
-    int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME]  +
-                  cpi->recent_ref_frame_usage[LAST_FRAME]   +
-                  cpi->recent_ref_frame_usage[GOLDEN_FRAME] +
-                  cpi->recent_ref_frame_usage[ALTREF_FRAME];
-
-    int pct_gf_active = (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols);
-
-    // Reset the last boost indicator
-    //cpi->last_boost = 100;
-
-    if (tot_mbs)
-        gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * 100 / tot_mbs;
-
-    if (pct_gf_active > gf_frame_useage)
-        gf_frame_useage = pct_gf_active;
-
     // Set the gf interval
     cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
 }
@@ -404,112 +372,44 @@
         // Note the baseline target data rate for this inter frame.
         cpi->inter_frame_target = cpi->this_frame_target;
 
-    // Test to see if we have to drop a frame
-    // The auto-drop frame code is only used in buffered mode.
-    // In unbufferd mode (eg vide conferencing) the descision to
-    // code or drop a frame is made outside the codec in response to real
-    // world comms or buffer considerations.
-    if (cpi->drop_frames_allowed && cpi->buffered_mode &&
-        (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
-        ((cpi->common.frame_type != KEY_FRAME))) //|| !cpi->oxcf.allow_spatial_resampling) )
-    {
-        // Check for a buffer underun-crisis in which case we have to drop a frame
-        if ((cpi->buffer_level < 0))
-        {
-#if 0
-            FILE *f = fopen("dec.stt", "a");
-            fprintf(f, "%10d %10d %10d %10d ***** BUFFER EMPTY\n",
-                    (int) cpi->common.current_video_frame,
-                    cpi->decimation_factor, cpi->common.horiz_scale,
-                    (cpi->buffer_level * 100) / cpi->oxcf.optimal_buffer_level);
-            fclose(f);
-#endif
-            //vpx_log("Decoder: Drop frame due to bandwidth: %d \n",cpi->buffer_level, cpi->av_per_frame_bandwidth);
-
-            cpi->drop_frame = TRUE;
-        }
-
-        if (cpi->drop_frame)
-        {
-            // Update the buffer level variable.
-            cpi->bits_off_target += cpi->av_per_frame_bandwidth;
-
-            // Clip the buffer level at the maximum buffer size
-            if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
-                cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
-
-            cpi->buffer_level = cpi->bits_off_target;
-        }
-        else
-            cpi->drop_count = 0;
-    }
-
     // Adjust target frame size for Golden Frames:
-    if (cpi->oxcf.error_resilient_mode == 0 &&
-        (cpi->frames_till_gf_update_due == 0) && !cpi->drop_frame)
+    if ( cpi->oxcf.error_resilient_mode == 0 &&
+         (cpi->frames_till_gf_update_due == 0) )
     {
         //int Boost = 0;
         int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q;
 
-        int gf_frame_useage = 0;      // Golden frame useage since last GF
-        int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME]  +
-                      cpi->recent_ref_frame_usage[LAST_FRAME]   +
-                      cpi->recent_ref_frame_usage[GOLDEN_FRAME] +
-                      cpi->recent_ref_frame_usage[ALTREF_FRAME];
+        cpi->common.refresh_golden_frame = TRUE;
 
-        int pct_gf_active = (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols);
+        calc_gf_params(cpi);
 
-        // Reset the last boost indicator
-        //cpi->last_boost = 100;
-
-        if (tot_mbs)
-            gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * 100 / tot_mbs;
-
-        if (pct_gf_active > gf_frame_useage)
-            gf_frame_useage = pct_gf_active;
-
-        // Is a fixed manual GF frequency being used
-        if (cpi->auto_gold)
+        // If we are using alternate ref instead of gf then do not apply the boost
+        // It will instead be applied to the altref update
+        // Jims modified boost
+        if (!cpi->source_alt_ref_active)
         {
-            cpi->common.refresh_golden_frame = TRUE;
-        }
-
-        if (cpi->common.refresh_golden_frame == TRUE)
-        {
-            if (cpi->auto_adjust_gold_quantizer)
+            if (cpi->oxcf.fixed_q < 0)
             {
-                calc_gf_params(cpi);
+                // The spend on the GF is defined in the two pass code
+                // for two pass encodes
+                cpi->this_frame_target = cpi->per_frame_bandwidth;
             }
-
-            // If we are using alternate ref instead of gf then do not apply the boost
-            // It will instead be applied to the altref update
-            // Jims modified boost
-            if (!cpi->source_alt_ref_active)
-            {
-                if (cpi->oxcf.fixed_q < 0)
-                {
-                    // The spend on the GF is defined in the two pass code
-                    // for two pass encodes
-                    cpi->this_frame_target = cpi->per_frame_bandwidth;
-                }
-                else
-                    cpi->this_frame_target =
-                        (estimate_bits_at_q(1, Q, cpi->common.MBs, 1.0)
-                         * cpi->last_boost) / 100;
-
-            }
-            // If there is an active ARF at this location use the minimum
-            // bits on this frame even if it is a contructed arf.
-            // The active maximum quantizer insures that an appropriate
-            // number of bits will be spent if needed for contstructed ARFs.
             else
-            {
-                cpi->this_frame_target = 0;
-            }
+                cpi->this_frame_target =
+                    (estimate_bits_at_q(1, Q, cpi->common.MBs, 1.0)
+                     * cpi->last_boost) / 100;
 
-            cpi->current_gf_interval = cpi->frames_till_gf_update_due;
-
         }
+        // If there is an active ARF at this location use the minimum
+        // bits on this frame even if it is a contructed arf.
+        // The active maximum quantizer insures that an appropriate
+        // number of bits will be spent if needed for contstructed ARFs.
+        else
+        {
+            cpi->this_frame_target = 0;
+        }
+
+        cpi->current_gf_interval = cpi->frames_till_gf_update_due;
     }
 }
 
@@ -624,128 +524,93 @@
 {
     int Q = cpi->active_worst_quality;
 
+    int i;
+    int last_error = INT_MAX;
+    int target_bits_per_mb;
+    int bits_per_mb_at_this_q;
+    double correction_factor;
+
     // Reset Zbin OQ value
     cpi->zbin_over_quant = 0;
 
-    if (cpi->oxcf.fixed_q >= 0)
+    // Select the appropriate correction factor based upon type of frame.
+    if (cpi->common.frame_type == KEY_FRAME)
+        correction_factor = cpi->key_frame_rate_correction_factor;
+    else
     {
-        Q = cpi->oxcf.fixed_q;
-
-        if (cpi->common.frame_type == KEY_FRAME)
-        {
-            Q = cpi->oxcf.key_q;
-        }
-        else if (cpi->common.refresh_alt_ref_frame)
-        {
-            Q = cpi->oxcf.alt_q;
-        }
-        else if (cpi->common.refresh_golden_frame)
-        {
-            Q = cpi->oxcf.gold_q;
-        }
-
+        if (cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_frame)
+            correction_factor = cpi->gf_rate_correction_factor;
+        else
+            correction_factor = cpi->rate_correction_factor;
     }
+
+    // Calculate required scaling factor based on target frame size and size of frame produced using previous Q
+    if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS))
+        target_bits_per_mb = (target_bits_per_frame / cpi->common.MBs) << BPER_MB_NORMBITS;       // Case where we would overflow int
     else
+        target_bits_per_mb = (target_bits_per_frame << BPER_MB_NORMBITS) / cpi->common.MBs;
+
+    i = cpi->active_best_quality;
+
+    do
     {
-        int i;
-        int last_error = INT_MAX;
-        int target_bits_per_mb;
-        int bits_per_mb_at_this_q;
-        double correction_factor;
+        bits_per_mb_at_this_q =
+            (int)(.5 + correction_factor *
+                       vp8_bits_per_mb(cpi->common.frame_type, i ));
 
-        // Select the appropriate correction factor based upon type of frame.
-        if (cpi->common.frame_type == KEY_FRAME)
-            correction_factor = cpi->key_frame_rate_correction_factor;
-        else
+        if (bits_per_mb_at_this_q <= target_bits_per_mb)
         {
-            if (cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_frame)
-                correction_factor = cpi->gf_rate_correction_factor;
+            if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error)
+                Q = i;
             else
-                correction_factor = cpi->rate_correction_factor;
-        }
+                Q = i - 1;
 
-        // Calculate required scaling factor based on target frame size and size of frame produced using previous Q
-        if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS))
-            target_bits_per_mb = (target_bits_per_frame / cpi->common.MBs) << BPER_MB_NORMBITS;       // Case where we would overflow int
+            break;
+        }
         else
-            target_bits_per_mb = (target_bits_per_frame << BPER_MB_NORMBITS) / cpi->common.MBs;
+            last_error = bits_per_mb_at_this_q - target_bits_per_mb;
+    }
+    while (++i <= cpi->active_worst_quality);
 
-        i = cpi->active_best_quality;
 
-        do
-        {
-            bits_per_mb_at_this_q =
-                (int)(.5 + correction_factor *
-                           vp8_bits_per_mb(cpi->common.frame_type, i ));
+    // If we are at MAXQ then enable Q over-run which seeks to claw back additional bits through things like
+    // the RD multiplier and zero bin size.
+    if (Q >= MAXQ)
+    {
+        int zbin_oqmax;
 
-            if (bits_per_mb_at_this_q <= target_bits_per_mb)
-            {
-                if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error)
-                    Q = i;
-                else
-                    Q = i - 1;
+        double Factor = 0.99;
+        double factor_adjustment = 0.01 / 256.0; //(double)ZBIN_OQ_MAX;
 
-                break;
-            }
-            else
-                last_error = bits_per_mb_at_this_q - target_bits_per_mb;
-        }
-        while (++i <= cpi->active_worst_quality);
+        if (cpi->common.frame_type == KEY_FRAME)
+            zbin_oqmax = 0; //ZBIN_OQ_MAX/16
+        else if (cpi->common.refresh_alt_ref_frame || (cpi->common.refresh_golden_frame && !cpi->source_alt_ref_active))
+            zbin_oqmax = 16;
+        else
+            zbin_oqmax = ZBIN_OQ_MAX;
 
-
-        // If we are at MAXQ then enable Q over-run which seeks to claw back additional bits through things like
-        // the RD multiplier and zero bin size.
-        if (Q >= MAXQ)
+        // Each incrment in the zbin is assumed to have a fixed effect on bitrate. This is not of course true.
+        // The effect will be highly clip dependent and may well have sudden steps.
+        // The idea here is to acheive higher effective quantizers than the normal maximum by expanding the zero
+        // bin and hence decreasing the number of low magnitude non zero coefficients.
+        while (cpi->zbin_over_quant < zbin_oqmax)
         {
-            int zbin_oqmax;
+            cpi->zbin_over_quant ++;
 
-            double Factor = 0.99;
-            double factor_adjustment = 0.01 / 256.0; //(double)ZBIN_OQ_MAX;
+            if (cpi->zbin_over_quant > zbin_oqmax)
+                cpi->zbin_over_quant = zbin_oqmax;
 
-            if (cpi->common.frame_type == KEY_FRAME)
-                zbin_oqmax = 0; //ZBIN_OQ_MAX/16
-            else if (cpi->common.refresh_alt_ref_frame || (cpi->common.refresh_golden_frame && !cpi->source_alt_ref_active))
-                zbin_oqmax = 16;
-            else
-                zbin_oqmax = ZBIN_OQ_MAX;
+            // Adjust bits_per_mb_at_this_q estimate
+            bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q);
+            Factor += factor_adjustment;
 
-            /*{
-                double Factor = (double)target_bits_per_mb/(double)bits_per_mb_at_this_q;
-                double Oq;
+            if (Factor  >= 0.999)
+                Factor = 0.999;
 
-                Factor = Factor/1.2683;
-
-                Oq = pow( Factor, (1.0/-0.165) );
-
-                if ( Oq > zbin_oqmax )
-                    Oq = zbin_oqmax;
-
-                cpi->zbin_over_quant = (int)Oq;
-            }*/
-
-            // Each incrment in the zbin is assumed to have a fixed effect on bitrate. This is not of course true.
-            // The effect will be highly clip dependent and may well have sudden steps.
-            // The idea here is to acheive higher effective quantizers than the normal maximum by expanding the zero
-            // bin and hence decreasing the number of low magnitude non zero coefficients.
-            while (cpi->zbin_over_quant < zbin_oqmax)
-            {
-                cpi->zbin_over_quant ++;
-
-                if (cpi->zbin_over_quant > zbin_oqmax)
-                    cpi->zbin_over_quant = zbin_oqmax;
-
-                // Adjust bits_per_mb_at_this_q estimate
-                bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q);
-                Factor += factor_adjustment;
-
-                if (Factor  >= 0.999)
-                    Factor = 0.999;
-
-                if (bits_per_mb_at_this_q <= target_bits_per_mb)    // Break out if we get down to the target rate
-                    break;
-            }
-
+            if (bits_per_mb_at_this_q <= target_bits_per_mb)    // Break out if we get down to the target rate
+                break;
         }
+
     }
 
     return Q;
@@ -840,42 +705,16 @@
             }
             else
             {
-                // For CBR take buffer fullness into account
-                if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
+                // Stron overshoot limit for constrained quality
+                if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
                 {
-                    if (cpi->buffer_level >= ((cpi->oxcf.optimal_buffer_level + cpi->oxcf.maximum_buffer_size) >> 1))
-                    {
-                        // Buffer is too full so relax overshoot and tighten undershoot
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 12 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 6 / 8;
-                    }
-                    else if (cpi->buffer_level <= (cpi->oxcf.optimal_buffer_level >> 1))
-                    {
-                        // Buffer is too low so relax undershoot and tighten overshoot
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 10 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 4 / 8;
-                    }
-                    else
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 5 / 8;
-                    }
+                    *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
+                    *frame_under_shoot_limit = cpi->this_frame_target * 2 / 8;
                 }
-                // VBR and CQ mode
-                // Note that tighter restrictions here can help quality but hurt encode speed
                 else
                 {
-                    // Stron overshoot limit for constrained quality
-                    if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 2 / 8;
-                    }
-                    else
-                    {
-                        *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
-                        *frame_under_shoot_limit = cpi->this_frame_target * 5 / 8;
-                    }
+                    *frame_over_shoot_limit  = cpi->this_frame_target * 11 / 8;
+                    *frame_under_shoot_limit = cpi->this_frame_target * 5 / 8;
                 }
             }
         }
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -2390,13 +2390,6 @@
         int dualmode_cost = 0;
         int mode_excluded = 0;
 
-        // Experimental debug code.
-        // Record of rd values recorded for this MB. -1 indicates not measured
-        //all_rds[mode_index] = -1;
-        //all_rates[mode_index] = -1;
-        //all_dist[mode_index] = -1;
-        //intermodecost[mode_index] = -1;
-
         // Test best rd so far against threshold for trying this mode.
         if (best_rd <= cpi->rd_threshes[mode_index])
             continue;
--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -276,18 +276,14 @@
     oxcf->resample_up_water_mark   = cfg.rc_resize_up_thresh;
     oxcf->resample_down_water_mark = cfg.rc_resize_down_thresh;
 
-    if (cfg.rc_end_usage == VPX_VBR)
-    {
-        oxcf->end_usage          = USAGE_LOCAL_FILE_PLAYBACK;
-    }
-    else if (cfg.rc_end_usage == VPX_CBR)
-    {
-        oxcf->end_usage          = USAGE_STREAM_FROM_SERVER;
-    }
-    else if (cfg.rc_end_usage == VPX_CQ)
-    {
-        oxcf->end_usage          = USAGE_CONSTRAINED_QUALITY;
-    }
+    // VBR only supported for now.
+    // CBR code has been deprectated for experimental phase.
+    // CQ mode not yet tested
+    oxcf->end_usage          = USAGE_LOCAL_FILE_PLAYBACK;
+    /*if (cfg.rc_end_usage == VPX_CQ)
+        oxcf->end_usage      = USAGE_CONSTRAINED_QUALITY;
+    else
+        oxcf->end_usage      = USAGE_LOCAL_FILE_PLAYBACK;*/
 
     oxcf->target_bandwidth       = cfg.rc_target_bitrate;
     oxcf->rc_max_intra_bitrate_pct = vp8_cfg.rc_max_intra_bitrate_pct;
@@ -599,35 +595,10 @@
     unsigned int new_qc;
 
     /* Use best quality mode if no deadline is given. */
-    new_qc = MODE_BESTQUALITY;
-
     if (deadline)
-    {
-        uint64_t     duration_us;
-
-        /* Convert duration parameter from stream timebase to microseconds */
-        duration_us = (uint64_t)duration * 1000000
-                      * (uint64_t)ctx->cfg.g_timebase.num
-                      / (uint64_t)ctx->cfg.g_timebase.den;
-
-        /* If the deadline is more that the duration this frame is to be shown,
-         * use good quality mode. Otherwise use realtime mode.
-         */
-        new_qc = (deadline > duration_us) ? MODE_GOODQUALITY : MODE_REALTIME;
-    }
-
-    switch (ctx->deprecated_mode)
-    {
-    case VP8_BEST_QUALITY_ENCODING:
-        new_qc = MODE_BESTQUALITY;
-        break;
-    case VP8_GOOD_QUALITY_ENCODING:
         new_qc = MODE_GOODQUALITY;
-        break;
-    case VP8_REAL_TIME_ENCODING:
-        new_qc = MODE_REALTIME;
-        break;
-    }
+    else
+        new_qc = MODE_BESTQUALITY;
 
     if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS)
         new_qc = MODE_FIRSTPASS;