From: Paul Wilkins Date: Fri, 24 Feb 2012 23:58:24 +0000 (+0000) Subject: Code Simplification. X-Git-Tag: v1.3.0~1217^2~380^2~32^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69e80a028c0c8e92edb68e4d5be43f5040b8672d;p=libvpx Code Simplification. Removal of code relating to spatial re sampling Change-Id: Iff1bc651c62cd528f960c4b27f9673b172e68835 --- diff --git a/vp8/common/onyx.h b/vp8/common/onyx.h index ab490f231..8bbdbf27d 100644 --- a/vp8/common/onyx.h +++ b/vp8/common/onyx.h @@ -154,11 +154,6 @@ extern "C" int best_allowed_q; int cq_level; - // allow internal resizing ( currently disabled in the build !!!!!) - int allow_spatial_resampling; - int resample_down_water_mark; - int resample_up_water_mark; - // allow internal frame rate alterations int allow_df; int drop_frames_water_mark; diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c index 1b6d8b95e..ef0d3d745 100644 --- a/vp8/encoder/firstpass.c +++ b/vp8/encoder/firstpass.c @@ -2980,129 +2980,4 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) // Adjust the count of total modified error left. // The count of bits left is adjusted elsewhere based on real coded frame sizes cpi->twopass.modified_error_left -= kf_group_err; - - if (cpi->oxcf.allow_spatial_resampling) - { - int resample_trigger = FALSE; - int last_kf_resampled = FALSE; - int kf_q; - int scale_val = 0; - int hr, hs, vr, vs; - int new_width = cpi->oxcf.Width; - int new_height = cpi->oxcf.Height; - - int projected_buffer_level = cpi->buffer_level; - int tmp_q; - - double projected_bits_perframe; - double group_iiratio = (kf_group_intra_err - first_frame.intra_error) / (kf_group_coded_err - first_frame.coded_error); - double err_per_frame = kf_group_err / cpi->twopass.frames_to_key; - double bits_per_frame; - double av_bits_per_frame; - double effective_size_ratio; - - if ((cpi->common.Width != cpi->oxcf.Width) || (cpi->common.Height != cpi->oxcf.Height)) - last_kf_resampled = TRUE; - - // Set back to unscaled by defaults - cpi->common.horiz_scale = NORMAL; - cpi->common.vert_scale = NORMAL; - - // Calculate Average bits per frame. - //av_bits_per_frame = cpi->twopass.bits_left/(double)(cpi->twopass.total_stats->count - cpi->common.current_video_frame); - av_bits_per_frame = cpi->oxcf.target_bandwidth / DOUBLE_DIVIDE_CHECK((double)cpi->oxcf.frame_rate); - //if ( av_bits_per_frame < 0.0 ) - // av_bits_per_frame = 0.0 - - // 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 - // 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... - - if (bits_per_frame < av_bits_per_frame) // Dont turn to resampling in easy sections just because they have been assigned a small number of bits - bits_per_frame = av_bits_per_frame; - } - - // bits_per_frame should comply with our minimum - if (bits_per_frame < (cpi->oxcf.target_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100)) - bits_per_frame = (cpi->oxcf.target_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100); - - // Work out if spatial resampling is necessary - kf_q = estimate_kf_group_q(cpi, err_per_frame, bits_per_frame, group_iiratio); - - // If we project a required Q higher than the maximum allowed Q then make a guess at the actual size of frames in this section - projected_bits_perframe = bits_per_frame; - tmp_q = kf_q; - - while (tmp_q > cpi->worst_quality) - { - projected_bits_perframe *= 1.04; - tmp_q--; - } - - // Guess at buffer level at the end of the section - projected_buffer_level = cpi->buffer_level - (int)((projected_bits_perframe - av_bits_per_frame) * cpi->twopass.frames_to_key); - - if (0) - { - FILE *f = fopen("Subsamle.stt", "a"); - fprintf(f, " %8d %8d %8d %8d %12.0f %8d %8d %8d\n", cpi->common.current_video_frame, kf_q, cpi->common.horiz_scale, cpi->common.vert_scale, kf_group_err / cpi->twopass.frames_to_key, (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), new_height, new_width); - fclose(f); - } - - // 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; - - if ((last_kf_resampled && (kf_q > cpi->worst_quality)) || // If triggered last time the threshold for triggering again is reduced - ((kf_q > cpi->worst_quality) && // Projected Q higher than allowed and ... - (over_spend > clip_bits / 20))) // ... Overspend > 5% of total bits - resample_trigger = TRUE; - else - resample_trigger = FALSE; - - } - - if (resample_trigger) - { - while ((kf_q >= cpi->worst_quality) && (scale_val < 6)) - { - scale_val ++; - - cpi->common.vert_scale = vscale_lookup[scale_val]; - cpi->common.horiz_scale = hscale_lookup[scale_val]; - - Scale2Ratio(cpi->common.horiz_scale, &hr, &hs); - Scale2Ratio(cpi->common.vert_scale, &vr, &vs); - - new_width = ((hs - 1) + (cpi->oxcf.Width * hr)) / hs; - new_height = ((vs - 1) + (cpi->oxcf.Height * vr)) / vs; - - // Reducing the area to 1/4 does not reduce the complexity (err_per_frame) to 1/4... - // effective_sizeratio attempts to provide a crude correction for this - effective_size_ratio = (double)(new_width * new_height) / (double)(cpi->oxcf.Width * cpi->oxcf.Height); - effective_size_ratio = (1.0 + (3.0 * effective_size_ratio)) / 4.0; - - // Now try again and see what Q we get with the smaller image size - kf_q = estimate_kf_group_q(cpi, err_per_frame * effective_size_ratio, bits_per_frame, group_iiratio); - - if (0) - { - FILE *f = fopen("Subsamle.stt", "a"); - fprintf(f, "******** %8d %8d %8d %12.0f %8d %8d %8d\n", kf_q, cpi->common.horiz_scale, cpi->common.vert_scale, kf_group_err / cpi->twopass.frames_to_key, (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), new_height, new_width); - fclose(f); - } - } - } - - if ((cpi->common.Width != new_width) || (cpi->common.Height != new_height)) - { - cpi->common.Width = new_width; - cpi->common.Height = new_height; - vp8_alloc_compressor_data(cpi); - } - } } diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index d6c956dbe..9214a2fbd 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -2321,87 +2321,6 @@ void vp8_write_yuv_rec_frame(VP8_COMMON *cm) } #endif - -static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi) -{ - VP8_COMMON *cm = &cpi->common; - - // are we resizing the image - if (cm->horiz_scale != 0 || cm->vert_scale != 0) - { -#if CONFIG_SPATIAL_RESAMPLING - int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs); - int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs); - int tmp_height; - - if (cm->vert_scale == 3) - tmp_height = 9; - else - tmp_height = 11; - - Scale2Ratio(cm->horiz_scale, &hr, &hs); - Scale2Ratio(cm->vert_scale, &vr, &vs); - - vp8_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer, - tmp_height, hs, hr, vs, vr, 0); - - vp8_yv12_extend_frame_borders(&cpi->scaled_source); - cpi->Source = &cpi->scaled_source; -#endif - } - else - cpi->Source = sd; -} - - -static void resize_key_frame(VP8_COMP *cpi) -{ -#if CONFIG_SPATIAL_RESAMPLING - VP8_COMMON *cm = &cpi->common; - - // Do we need to apply resampling for one pass cbr. - // In one pass this is more limited than in two pass cbr - // The test and any change is only made one per key frame sequence - if (cpi->oxcf.allow_spatial_resampling && (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) - { - int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs); - int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs); - int new_width, new_height; - - // If we are below the resample DOWN watermark then scale down a notch. - if (cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100)) - { - cm->horiz_scale = (cm->horiz_scale < ONETWO) ? cm->horiz_scale + 1 : ONETWO; - cm->vert_scale = (cm->vert_scale < ONETWO) ? cm->vert_scale + 1 : ONETWO; - } - // Should we now start scaling back up - else if (cpi->buffer_level > (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100)) - { - cm->horiz_scale = (cm->horiz_scale > NORMAL) ? cm->horiz_scale - 1 : NORMAL; - cm->vert_scale = (cm->vert_scale > NORMAL) ? cm->vert_scale - 1 : NORMAL; - } - - // Get the new hieght and width - Scale2Ratio(cm->horiz_scale, &hr, &hs); - Scale2Ratio(cm->vert_scale, &vr, &vs); - new_width = ((hs - 1) + (cpi->oxcf.Width * hr)) / hs; - new_height = ((vs - 1) + (cpi->oxcf.Height * vr)) / vs; - - // If the image size has changed we need to reallocate the buffers - // and resample the source image - if ((cm->Width != new_width) || (cm->Height != new_height)) - { - cm->Width = new_width; - cm->Height = new_height; - vp8_alloc_compressor_data(cpi); - scale_and_extend_source(cpi->un_scaled_source, cpi); - } - } - -#endif -} - - static void update_alt_ref_frame_stats(VP8_COMP *cpi) { VP8_COMMON *cm = &cpi->common; @@ -2557,8 +2476,6 @@ static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, vp8_set_quantizer(cpi, find_fp_qindex()); - - scale_and_extend_source(cpi->un_scaled_source, cpi); vp8_first_pass(cpi); } //#define WRITE_RECON_BUFFER 1 @@ -3038,7 +2955,7 @@ static void encode_frame_to_data_rate } // Note that we should not throw out a key frame (especially when spatial resampling is enabled). - if ((cm->frame_type == KEY_FRAME)) // && cpi->oxcf.allow_spatial_resampling ) + if ((cm->frame_type == KEY_FRAME)) { cpi->decimation_count = cpi->decimation_factor; } @@ -3199,8 +3116,6 @@ static void encode_frame_to_data_rate loop_count = 0; - - scale_and_extend_source(cpi->un_scaled_source, cpi); #if CONFIG_POSTPROC if (cpi->oxcf.noise_sensitivity > 0) @@ -3320,17 +3235,11 @@ static void encode_frame_to_data_rate } } + // Set up entropy depending on frame type. if (cm->frame_type == KEY_FRAME) - { - resize_key_frame(cpi); vp8_setup_key_frame(cpi); - } else - { - /* setup entropy for nonkey frame */ vp8_setup_inter_frame(cpi); - } - // transform / motion compensation build reconstruction frame vp8_encode_frame(cpi); diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c index d01faf7e7..670811a10 100644 --- a/vp8/vp8_cx_iface.c +++ b/vp8/vp8_cx_iface.c @@ -272,10 +272,6 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, oxcf->allow_df = (cfg.rc_dropframe_thresh > 0); oxcf->drop_frames_water_mark = cfg.rc_dropframe_thresh; - oxcf->allow_spatial_resampling = cfg.rc_resize_allowed; - oxcf->resample_up_water_mark = cfg.rc_resize_up_thresh; - oxcf->resample_down_water_mark = cfg.rc_resize_down_thresh; - // VBR only supported for now. // CBR code has been deprectated for experimental phase. // CQ mode not yet tested @@ -347,9 +343,6 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, printf("fixed_q: %d\n", oxcf->fixed_q); printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q); printf("best_allowed_q: %d\n", oxcf->best_allowed_q); - printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling); - printf("resample_down_water_mark: %d\n", oxcf->resample_down_water_mark); - printf("resample_up_water_mark: %d\n", oxcf->resample_up_water_mark); printf("allow_df: %d\n", oxcf->allow_df); printf("drop_frames_water_mark: %d\n", oxcf->drop_frames_water_mark); printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias); diff --git a/vpx_scale/generic/scalesystemdependent.c b/vpx_scale/generic/scalesystemdependent.c index 926feb7cd..92cebc4f4 100644 --- a/vpx_scale/generic/scalesystemdependent.c +++ b/vpx_scale/generic/scalesystemdependent.c @@ -44,33 +44,6 @@ extern void vp8_yv12_copy_frame(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG ****************************************************************************/ void vp8_scale_machine_specific_config() { -#if CONFIG_SPATIAL_RESAMPLING - vp8_horizontal_line_1_2_scale = vp8cx_horizontal_line_1_2_scale_c; - vp8_vertical_band_1_2_scale = vp8cx_vertical_band_1_2_scale_c; - vp8_last_vertical_band_1_2_scale = vp8cx_last_vertical_band_1_2_scale_c; - vp8_horizontal_line_3_5_scale = vp8cx_horizontal_line_3_5_scale_c; - vp8_vertical_band_3_5_scale = vp8cx_vertical_band_3_5_scale_c; - vp8_last_vertical_band_3_5_scale = vp8cx_last_vertical_band_3_5_scale_c; - vp8_horizontal_line_3_4_scale = vp8cx_horizontal_line_3_4_scale_c; - vp8_vertical_band_3_4_scale = vp8cx_vertical_band_3_4_scale_c; - vp8_last_vertical_band_3_4_scale = vp8cx_last_vertical_band_3_4_scale_c; - vp8_horizontal_line_2_3_scale = vp8cx_horizontal_line_2_3_scale_c; - vp8_vertical_band_2_3_scale = vp8cx_vertical_band_2_3_scale_c; - vp8_last_vertical_band_2_3_scale = vp8cx_last_vertical_band_2_3_scale_c; - vp8_horizontal_line_4_5_scale = vp8cx_horizontal_line_4_5_scale_c; - vp8_vertical_band_4_5_scale = vp8cx_vertical_band_4_5_scale_c; - vp8_last_vertical_band_4_5_scale = vp8cx_last_vertical_band_4_5_scale_c; - - - vp8_vertical_band_5_4_scale = vp8cx_vertical_band_5_4_scale_c; - vp8_vertical_band_5_3_scale = vp8cx_vertical_band_5_3_scale_c; - vp8_vertical_band_2_1_scale = vp8cx_vertical_band_2_1_scale_c; - vp8_vertical_band_2_1_scale_i = vp8cx_vertical_band_2_1_scale_i_c; - vp8_horizontal_line_2_1_scale = vp8cx_horizontal_line_2_1_scale_c; - vp8_horizontal_line_5_3_scale = vp8cx_horizontal_line_5_3_scale_c; - vp8_horizontal_line_5_4_scale = vp8cx_horizontal_line_5_4_scale_c; -#endif - vp8_yv12_extend_frame_borders_ptr = vp8_yv12_extend_frame_borders; vp8_yv12_copy_frame_yonly_ptr = vp8_yv12_copy_frame_yonly; vp8_yv12_copy_frame_ptr = vp8_yv12_copy_frame;