| Index: source/libvpx/vp9/encoder/vp9_encoder.c
|
| diff --git a/source/libvpx/vp9/encoder/vp9_encoder.c b/source/libvpx/vp9/encoder/vp9_encoder.c
|
| index 8aee22756b21614d62f4d0f37ff0ab6ded7cdb64..d9ecb9a1cd534866762e222eb43e63f42e044b36 100644
|
| --- a/source/libvpx/vp9/encoder/vp9_encoder.c
|
| +++ b/source/libvpx/vp9/encoder/vp9_encoder.c
|
| @@ -18,9 +18,12 @@
|
| #include "./vpx_scale_rtcd.h"
|
| #include "vpx/internal/vpx_psnr.h"
|
| #include "vpx_dsp/vpx_filter.h"
|
| +#if CONFIG_INTERNAL_STATS
|
| +#include "vpx_dsp/ssim.h"
|
| +#endif
|
| #include "vpx_ports/mem.h"
|
| +#include "vpx_ports/system_state.h"
|
| #include "vpx_ports/vpx_timer.h"
|
| -#include "vpx_scale/vpx_scale.h"
|
|
|
| #include "vp9/common/vp9_alloccommon.h"
|
| #include "vp9/common/vp9_filter.h"
|
| @@ -30,7 +33,6 @@
|
| #endif
|
| #include "vp9/common/vp9_reconinter.h"
|
| #include "vp9/common/vp9_reconintra.h"
|
| -#include "vp9/common/vp9_systemdependent.h"
|
| #include "vp9/common/vp9_tile_common.h"
|
|
|
| #include "vp9/encoder/vp9_aq_complexity.h"
|
| @@ -51,9 +53,6 @@
|
| #include "vp9/encoder/vp9_segmentation.h"
|
| #include "vp9/encoder/vp9_skin_detection.h"
|
| #include "vp9/encoder/vp9_speed_features.h"
|
| -#if CONFIG_INTERNAL_STATS
|
| -#include "vp9/encoder/vp9_ssim.h"
|
| -#endif
|
| #include "vp9/encoder/vp9_svc_layercontext.h"
|
| #include "vp9/encoder/vp9_temporal_filter.h"
|
|
|
| @@ -381,10 +380,10 @@ static void dealloc_compressor_data(VP9_COMP *cpi) {
|
| #endif
|
| vp9_free_context_buffers(cm);
|
|
|
| - vp9_free_frame_buffer(&cpi->last_frame_uf);
|
| - vp9_free_frame_buffer(&cpi->scaled_source);
|
| - vp9_free_frame_buffer(&cpi->scaled_last_source);
|
| - vp9_free_frame_buffer(&cpi->alt_ref_buffer);
|
| + vpx_free_frame_buffer(&cpi->last_frame_uf);
|
| + vpx_free_frame_buffer(&cpi->scaled_source);
|
| + vpx_free_frame_buffer(&cpi->scaled_last_source);
|
| + vpx_free_frame_buffer(&cpi->alt_ref_buffer);
|
| vp9_lookahead_destroy(cpi->lookahead);
|
|
|
| vpx_free(cpi->tile_tok[0][0]);
|
| @@ -405,12 +404,12 @@ static void dealloc_compressor_data(VP9_COMP *cpi) {
|
| }
|
|
|
| for (i = 0; i < MAX_LAG_BUFFERS; ++i) {
|
| - vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]);
|
| + vpx_free_frame_buffer(&cpi->svc.scaled_frames[i]);
|
| }
|
| memset(&cpi->svc.scaled_frames[0], 0,
|
| MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0]));
|
|
|
| - vp9_free_frame_buffer(&cpi->svc.empty_frame.img);
|
| + vpx_free_frame_buffer(&cpi->svc.empty_frame.img);
|
| memset(&cpi->svc.empty_frame, 0, sizeof(cpi->svc.empty_frame));
|
| }
|
|
|
| @@ -627,7 +626,7 @@ static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
|
| "Failed to allocate lag buffers");
|
|
|
| // TODO(agrange) Check if ARF is enabled and skip allocation if not.
|
| - if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
|
| + if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer,
|
| oxcf->width, oxcf->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -641,7 +640,7 @@ static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
|
|
|
| static void alloc_util_frame_buffers(VP9_COMP *cpi) {
|
| VP9_COMMON *const cm = &cpi->common;
|
| - if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
|
| + if (vpx_realloc_frame_buffer(&cpi->last_frame_uf,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -652,7 +651,7 @@ static void alloc_util_frame_buffers(VP9_COMP *cpi) {
|
| vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
| "Failed to allocate last frame buffer");
|
|
|
| - if (vp9_realloc_frame_buffer(&cpi->scaled_source,
|
| + if (vpx_realloc_frame_buffer(&cpi->scaled_source,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -663,7 +662,7 @@ static void alloc_util_frame_buffers(VP9_COMP *cpi) {
|
| vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
| "Failed to allocate scaled source buffer");
|
|
|
| - if (vp9_realloc_frame_buffer(&cpi->scaled_last_source,
|
| + if (vpx_realloc_frame_buffer(&cpi->scaled_last_source,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -742,7 +741,7 @@ static void update_frame_size(VP9_COMP *cpi) {
|
| set_tile_limits(cpi);
|
|
|
| if (is_two_pass_svc(cpi)) {
|
| - if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
|
| + if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -1491,8 +1490,8 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
|
|
|
| // Under a configuration change, where maximum_buffer_size may change,
|
| // keep buffer level clipped to the maximum allowed buffer size.
|
| - rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size);
|
| - rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size);
|
| + rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size);
|
| + rc->buffer_level = VPXMIN(rc->buffer_level, rc->maximum_buffer_size);
|
|
|
| // Set up frame rate and related parameters rate control values.
|
| vp9_new_framerate(cpi, cpi->framerate);
|
| @@ -1623,6 +1622,8 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
|
| cpi->resize_buffer_underflow = 0;
|
| cpi->common.buffer_pool = pool;
|
|
|
| + cpi->rc.high_source_sad = 0;
|
| +
|
| init_config(cpi, oxcf);
|
| vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
|
|
|
| @@ -1709,7 +1710,8 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
|
| }
|
|
|
| if (cpi->b_calculate_consistency) {
|
| - cpi->ssim_vars = vpx_malloc(sizeof(*cpi->ssim_vars)*720*480);
|
| + cpi->ssim_vars = vpx_malloc(sizeof(*cpi->ssim_vars) *
|
| + 4 * cpi->common.mi_rows * cpi->common.mi_cols);
|
| cpi->worst_consistency = 100.0;
|
| }
|
|
|
| @@ -1925,7 +1927,7 @@ void vp9_remove_compressor(VP9_COMP *cpi) {
|
|
|
| if (cpi && (cm->current_video_frame > 0)) {
|
| #if CONFIG_INTERNAL_STATS
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| if (cpi->oxcf.pass != 1) {
|
| char headings[512] = {0};
|
| @@ -1957,7 +1959,7 @@ void vp9_remove_compressor(VP9_COMP *cpi) {
|
| "WstPsnr\tWstSsim\tWstFast\tWstHVS");
|
| snprintf(results, sizeof(results),
|
| "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
|
| - "%7.3f\t%7.3f\t%7.3f\t%7.3f"
|
| + "%7.3f\t%7.3f\t%7.3f\t%7.3f\t"
|
| "%7.3f\t%7.3f\t%7.3f\t%7.3f",
|
| dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr,
|
| cpi->psnrp.stat[ALL] / cpi->count, totalp_psnr,
|
| @@ -2546,7 +2548,7 @@ static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
|
| dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
| }
|
| - vp9_extend_frame_borders(dst);
|
| + vpx_extend_frame_borders(dst);
|
| }
|
|
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -2586,13 +2588,13 @@ static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
|
| kernel[y_q4 & 0xf], 16 * src_h / dst_h,
|
| 16 / factor, 16 / factor, bd);
|
| } else {
|
| - vpx_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
|
| + vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride,
|
| kernel[x_q4 & 0xf], 16 * src_w / dst_w,
|
| kernel[y_q4 & 0xf], 16 * src_h / dst_h,
|
| 16 / factor, 16 / factor);
|
| }
|
| #else
|
| - vpx_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
|
| + vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride,
|
| kernel[x_q4 & 0xf], 16 * src_w / dst_w,
|
| kernel[y_q4 & 0xf], 16 * src_h / dst_h,
|
| 16 / factor, 16 / factor);
|
| @@ -2601,7 +2603,7 @@ static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
|
| }
|
| }
|
|
|
| - vp9_extend_frame_borders(dst);
|
| + vpx_extend_frame_borders(dst);
|
| }
|
|
|
| static int scale_down(VP9_COMP *cpi, int q) {
|
| @@ -2613,7 +2615,7 @@ static int scale_down(VP9_COMP *cpi, int q) {
|
| if (rc->frame_size_selector == UNSCALED &&
|
| q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) {
|
| const int max_size_thresh = (int)(rate_thresh_mult[SCALE_STEP1]
|
| - * MAX(rc->this_frame_target, rc->avg_frame_bandwidth));
|
| + * VPXMAX(rc->this_frame_target, rc->avg_frame_bandwidth));
|
| scale = rc->projected_frame_size > max_size_thresh ? 1 : 0;
|
| }
|
| return scale;
|
| @@ -2747,7 +2749,7 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
|
| } else {
|
| struct vpx_usec_timer timer;
|
|
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| vpx_usec_timer_start(&timer);
|
|
|
| @@ -2767,7 +2769,7 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
|
| vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
|
| }
|
|
|
| - vp9_extend_frame_inner_borders(cm->frame_to_show);
|
| + vpx_extend_frame_inner_borders(cm->frame_to_show);
|
| }
|
|
|
| static INLINE void alloc_frame_mvs(const VP9_COMMON *cm,
|
| @@ -2817,7 +2819,7 @@ void vp9_scale_references(VP9_COMP *cpi) {
|
| if (force_scaling ||
|
| new_fb_ptr->buf.y_crop_width != cm->width ||
|
| new_fb_ptr->buf.y_crop_height != cm->height) {
|
| - vp9_realloc_frame_buffer(&new_fb_ptr->buf,
|
| + vpx_realloc_frame_buffer(&new_fb_ptr->buf,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| cm->use_highbitdepth,
|
| @@ -2842,7 +2844,7 @@ void vp9_scale_references(VP9_COMP *cpi) {
|
| if (force_scaling ||
|
| new_fb_ptr->buf.y_crop_width != cm->width ||
|
| new_fb_ptr->buf.y_crop_height != cm->height) {
|
| - vp9_realloc_frame_buffer(&new_fb_ptr->buf,
|
| + vpx_realloc_frame_buffer(&new_fb_ptr->buf,
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
|
| @@ -2931,7 +2933,7 @@ static void output_frame_level_debug_stats(VP9_COMP *cpi) {
|
| FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w");
|
| int64_t recon_err;
|
|
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
|
|
|
| @@ -2996,7 +2998,7 @@ static void output_frame_level_debug_stats(VP9_COMP *cpi) {
|
|
|
| static void set_mv_search_params(VP9_COMP *cpi) {
|
| const VP9_COMMON *const cm = &cpi->common;
|
| - const unsigned int max_mv_def = MIN(cm->width, cm->height);
|
| + const unsigned int max_mv_def = VPXMIN(cm->width, cm->height);
|
|
|
| // Default based on max resolution.
|
| cpi->mv_step_param = vp9_init_search_range(max_mv_def);
|
| @@ -3011,8 +3013,8 @@ static void set_mv_search_params(VP9_COMP *cpi) {
|
| // Allow mv_steps to correspond to twice the max mv magnitude found
|
| // in the previous frame, capped by the default max_mv_magnitude based
|
| // on resolution.
|
| - cpi->mv_step_param =
|
| - vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude));
|
| + cpi->mv_step_param = vp9_init_search_range(
|
| + VPXMIN(max_mv_def, 2 * cpi->max_mv_magnitude));
|
| }
|
| cpi->max_mv_magnitude = 0;
|
| }
|
| @@ -3137,7 +3139,7 @@ static void set_frame_size(VP9_COMP *cpi) {
|
| alloc_frame_mvs(cm, cm->new_fb_idx);
|
|
|
| // Reset the frame pointers to the current frame size.
|
| - vp9_realloc_frame_buffer(get_frame_new_buffer(cm),
|
| + vpx_realloc_frame_buffer(get_frame_new_buffer(cm),
|
| cm->width, cm->height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -3170,7 +3172,7 @@ static void set_frame_size(VP9_COMP *cpi) {
|
| cm->width, cm->height);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
| if (vp9_is_scaled(&ref_buf->sf))
|
| - vp9_extend_frame_borders(buf);
|
| + vpx_extend_frame_borders(buf);
|
| } else {
|
| ref_buf->buf = NULL;
|
| }
|
| @@ -3179,35 +3181,30 @@ static void set_frame_size(VP9_COMP *cpi) {
|
| set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
|
| }
|
|
|
| -static void encode_without_recode_loop(VP9_COMP *cpi) {
|
| +static void encode_without_recode_loop(VP9_COMP *cpi,
|
| + size_t *size,
|
| + uint8_t *dest) {
|
| VP9_COMMON *const cm = &cpi->common;
|
| int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
|
|
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| set_frame_size(cpi);
|
|
|
| - // For 1 pass CBR under dynamic resize mode: use faster scaling for source.
|
| - // Only for 2x2 scaling for now.
|
| + cpi->Source = vp9_scale_if_required(cm,
|
| + cpi->un_scaled_source,
|
| + &cpi->scaled_source);
|
| + if (cpi->unscaled_last_source != NULL)
|
| + cpi->Last_Source = vp9_scale_if_required(cm,
|
| + cpi->unscaled_last_source,
|
| + &cpi->scaled_last_source);
|
| +
|
| if (cpi->oxcf.pass == 0 &&
|
| cpi->oxcf.rc_mode == VPX_CBR &&
|
| - cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
|
| - cpi->un_scaled_source->y_width == (cm->width << 1) &&
|
| - cpi->un_scaled_source->y_height == (cm->height << 1)) {
|
| - cpi->Source = vp9_scale_if_required_fast(cm,
|
| - cpi->un_scaled_source,
|
| - &cpi->scaled_source);
|
| - if (cpi->unscaled_last_source != NULL)
|
| - cpi->Last_Source = vp9_scale_if_required_fast(cm,
|
| - cpi->unscaled_last_source,
|
| - &cpi->scaled_last_source);
|
| - } else {
|
| - cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
|
| - &cpi->scaled_source);
|
| - if (cpi->unscaled_last_source != NULL)
|
| - cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source,
|
| - &cpi->scaled_last_source);
|
| - }
|
| + cpi->resize_state == 0 &&
|
| + cm->frame_type != KEY_FRAME &&
|
| + cpi->oxcf.content == VP9E_CONTENT_SCREEN)
|
| + vp9_avg_source_sad(cpi);
|
|
|
| if (frame_is_intra_only(cm) == 0) {
|
| vp9_scale_references(cpi);
|
| @@ -3236,6 +3233,38 @@ static void encode_without_recode_loop(VP9_COMP *cpi) {
|
| // transform / motion compensation build reconstruction frame
|
| vp9_encode_frame(cpi);
|
|
|
| + // Check if we should drop this frame because of high overshoot.
|
| + // Only for frames where high temporal-source sad is detected.
|
| + if (cpi->oxcf.pass == 0 &&
|
| + cpi->oxcf.rc_mode == VPX_CBR &&
|
| + cpi->resize_state == 0 &&
|
| + cm->frame_type != KEY_FRAME &&
|
| + cpi->oxcf.content == VP9E_CONTENT_SCREEN &&
|
| + cpi->rc.high_source_sad == 1) {
|
| + int frame_size = 0;
|
| + // Get an estimate of the encoded frame size.
|
| + save_coding_context(cpi);
|
| + vp9_pack_bitstream(cpi, dest, size);
|
| + restore_coding_context(cpi);
|
| + frame_size = (int)(*size) << 3;
|
| + // Check if encoded frame will overshoot too much, and if so, set the q and
|
| + // adjust some rate control parameters, and return to re-encode the frame.
|
| + if (vp9_encodedframe_overshoot(cpi, frame_size, &q)) {
|
| + vpx_clear_system_state();
|
| + vp9_set_quantizer(cm, q);
|
| + vp9_set_variance_partition_thresholds(cpi, q);
|
| + suppress_active_map(cpi);
|
| + // Turn-off cyclic refresh for re-encoded frame.
|
| + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
|
| + unsigned char *const seg_map = cpi->segmentation_map;
|
| + memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
|
| + vp9_disable_segmentation(&cm->seg);
|
| + }
|
| + apply_active_map(cpi);
|
| + vp9_encode_frame(cpi);
|
| + }
|
| + }
|
| +
|
| // Update some stats from cyclic refresh, and check if we should not update
|
| // golden reference, for non-SVC 1 pass CBR.
|
| if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
|
| @@ -3247,7 +3276,7 @@ static void encode_without_recode_loop(VP9_COMP *cpi) {
|
| // Update the skip mb flag probabilities based on the distribution
|
| // seen in the last encoder iteration.
|
| // update_base_skip_probs(cpi);
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
| }
|
|
|
| static void encode_with_recode_loop(VP9_COMP *cpi,
|
| @@ -3268,7 +3297,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
| set_size_independent_vars(cpi);
|
|
|
| do {
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| set_frame_size(cpi);
|
|
|
| @@ -3332,7 +3361,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
| // seen in the last encoder iteration.
|
| // update_base_skip_probs(cpi);
|
|
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| // Dummy pack of the bitstream using up to date stats to get an
|
| // accurate estimate of output frame size to determine if we need
|
| @@ -3385,7 +3414,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
|
|
| // Adjust Q
|
| q = (int)((q * high_err_target) / kf_err);
|
| - q = MIN(q, (q_high + q_low) >> 1);
|
| + q = VPXMIN(q, (q_high + q_low) >> 1);
|
| } else if (kf_err < low_err_target &&
|
| rc->projected_frame_size >= frame_under_shoot_limit) {
|
| // The key frame is much better than the previous frame
|
| @@ -3394,7 +3423,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
|
|
| // Adjust Q
|
| q = (int)((q * low_err_target) / kf_err);
|
| - q = MIN(q, (q_high + q_low + 1) >> 1);
|
| + q = VPXMIN(q, (q_high + q_low + 1) >> 1);
|
| }
|
|
|
| // Clamp Q to upper and lower limits:
|
| @@ -3403,7 +3432,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
| loop = q != last_q;
|
| } else if (recode_loop_test(
|
| cpi, frame_over_shoot_limit, frame_under_shoot_limit,
|
| - q, MAX(q_high, top_index), bottom_index)) {
|
| + q, VPXMAX(q_high, top_index), bottom_index)) {
|
| // Is the projected frame size out of range and are we allowed
|
| // to attempt to recode.
|
| int last_q = q;
|
| @@ -3445,12 +3474,12 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
| vp9_rc_update_rate_correction_factors(cpi);
|
|
|
| q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
|
| - bottom_index, MAX(q_high, top_index));
|
| + bottom_index, VPXMAX(q_high, top_index));
|
|
|
| while (q < q_low && retries < 10) {
|
| vp9_rc_update_rate_correction_factors(cpi);
|
| q = vp9_rc_regulate_q(cpi, rc->this_frame_target,
|
| - bottom_index, MAX(q_high, top_index));
|
| + bottom_index, VPXMAX(q_high, top_index));
|
| retries++;
|
| }
|
| }
|
| @@ -3553,30 +3582,25 @@ static void set_ext_overrides(VP9_COMP *cpi) {
|
| }
|
| }
|
|
|
| -YV12_BUFFER_CONFIG *vp9_scale_if_required_fast(VP9_COMMON *cm,
|
| - YV12_BUFFER_CONFIG *unscaled,
|
| - YV12_BUFFER_CONFIG *scaled) {
|
| - if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
|
| - cm->mi_rows * MI_SIZE != unscaled->y_height) {
|
| - // For 2x2 scaling down.
|
| - vpx_scale_frame(unscaled, scaled, unscaled->y_buffer, 9, 2, 1,
|
| - 2, 1, 0);
|
| - vp9_extend_frame_borders(scaled);
|
| - return scaled;
|
| - } else {
|
| - return unscaled;
|
| - }
|
| -}
|
| -
|
| YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
|
| YV12_BUFFER_CONFIG *unscaled,
|
| YV12_BUFFER_CONFIG *scaled) {
|
| if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
|
| cm->mi_rows * MI_SIZE != unscaled->y_height) {
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| - scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth);
|
| + if (unscaled->y_width == (scaled->y_width << 1) &&
|
| + unscaled->y_height == (scaled->y_height << 1))
|
| + scale_and_extend_frame(unscaled, scaled, (int)cm->bit_depth);
|
| + else
|
| + scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth);
|
| #else
|
| - scale_and_extend_frame_nonnormative(unscaled, scaled);
|
| + // Use the faster normative (convolve8) scaling filter: for now only for
|
| + // scaling factor of 2.
|
| + if (unscaled->y_width == (scaled->y_width << 1) &&
|
| + unscaled->y_height == (scaled->y_height << 1))
|
| + scale_and_extend_frame(unscaled, scaled);
|
| + else
|
| + scale_and_extend_frame_nonnormative(unscaled, scaled);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
| return scaled;
|
| } else {
|
| @@ -3636,7 +3660,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
| TX_SIZE t;
|
|
|
| set_ext_overrides(cpi);
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| // Set the arf sign bias for this frame.
|
| set_arf_sign_bias(cpi);
|
| @@ -3727,7 +3751,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
| }
|
| }
|
|
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| #if CONFIG_INTERNAL_STATS
|
| memset(cpi->mode_chosen_counts, 0,
|
| @@ -3735,7 +3759,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
| #endif
|
|
|
| if (cpi->sf.recode_loop == DISALLOW_RECODE) {
|
| - encode_without_recode_loop(cpi);
|
| + encode_without_recode_loop(cpi, size, dest);
|
| } else {
|
| encode_with_recode_loop(cpi, size, dest);
|
| }
|
| @@ -4029,8 +4053,8 @@ static void adjust_frame_rate(VP9_COMP *cpi,
|
| // Average this frame's rate into the last second's average
|
| // frame rate. If we haven't seen 1 second yet, then average
|
| // over the whole interval seen.
|
| - const double interval = MIN((double)(source->ts_end
|
| - - cpi->first_time_stamp_ever), 10000000.0);
|
| + const double interval = VPXMIN(
|
| + (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0);
|
| double avg_duration = 10000000.0 / cpi->framerate;
|
| avg_duration *= (interval - avg_duration + this_duration);
|
| avg_duration /= interval;
|
| @@ -4084,8 +4108,8 @@ static void check_src_altref(VP9_COMP *cpi,
|
| }
|
|
|
| #if CONFIG_INTERNAL_STATS
|
| -extern double vp9_get_blockiness(const unsigned char *img1, int img1_pitch,
|
| - const unsigned char *img2, int img2_pitch,
|
| +extern double vp9_get_blockiness(const uint8_t *img1, int img1_pitch,
|
| + const uint8_t *img2, int img2_pitch,
|
| int width, int height);
|
|
|
| static void adjust_image_stat(double y, double u, double v, double all,
|
| @@ -4094,7 +4118,7 @@ static void adjust_image_stat(double y, double u, double v, double all,
|
| s->stat[U] += u;
|
| s->stat[V] += v;
|
| s->stat[ALL] += all;
|
| - s->worst = MIN(s->worst, all);
|
| + s->worst = VPXMIN(s->worst, all);
|
| }
|
| #endif // CONFIG_INTERNAL_STATS
|
|
|
| @@ -4177,7 +4201,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| if (oxcf->arnr_max_frames > 0) {
|
| // Produce the filtered ARF frame.
|
| vp9_temporal_filter(cpi, arf_src_index);
|
| - vp9_extend_frame_borders(&cpi->alt_ref_buffer);
|
| + vpx_extend_frame_borders(&cpi->alt_ref_buffer);
|
| force_src_buffer = &cpi->alt_ref_buffer;
|
| }
|
|
|
| @@ -4247,7 +4271,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| }
|
|
|
| // Clear down mmx registers
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| // adjust frame rates based on timestamps given
|
| if (cm->show_frame) {
|
| @@ -4384,7 +4408,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| PSNR_STATS psnr2;
|
| double frame_ssim2 = 0, weight = 0;
|
| #if CONFIG_VP9_POSTPROC
|
| - if (vp9_alloc_frame_buffer(&cm->post_proc_buffer,
|
| + if (vpx_alloc_frame_buffer(&cm->post_proc_buffer,
|
| recon->y_crop_width, recon->y_crop_height,
|
| cm->subsampling_x, cm->subsampling_y,
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| @@ -4399,7 +4423,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer,
|
| cm->lf.filter_level * 10 / 6);
|
| #endif
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
|
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| calc_highbd_psnr(orig, pp, &psnr2, cpi->td.mb.e_mbd.bd,
|
| @@ -4415,28 +4439,28 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
|
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| if (cm->use_highbitdepth) {
|
| - frame_ssim2 = vp9_highbd_calc_ssim(orig, recon, &weight,
|
| + frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight,
|
| (int)cm->bit_depth);
|
| } else {
|
| - frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
|
| + frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
|
| }
|
| #else
|
| - frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
|
| + frame_ssim2 = vpx_calc_ssim(orig, recon, &weight);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
|
|
| - cpi->worst_ssim= MIN(cpi->worst_ssim, frame_ssim2);
|
| + cpi->worst_ssim = VPXMIN(cpi->worst_ssim, frame_ssim2);
|
| cpi->summed_quality += frame_ssim2 * weight;
|
| cpi->summed_weights += weight;
|
|
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| if (cm->use_highbitdepth) {
|
| - frame_ssim2 = vp9_highbd_calc_ssim(
|
| + frame_ssim2 = vpx_highbd_calc_ssim(
|
| orig, &cm->post_proc_buffer, &weight, (int)cm->bit_depth);
|
| } else {
|
| - frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
|
| + frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight);
|
| }
|
| #else
|
| - frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
|
| + frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
|
|
| cpi->summedp_quality += frame_ssim2 * weight;
|
| @@ -4461,7 +4485,8 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| cpi->Source->y_buffer, cpi->Source->y_stride,
|
| cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride,
|
| cpi->Source->y_width, cpi->Source->y_height);
|
| - cpi->worst_blockiness = MAX(cpi->worst_blockiness, frame_blockiness);
|
| + cpi->worst_blockiness =
|
| + VPXMAX(cpi->worst_blockiness, frame_blockiness);
|
| cpi->total_blockiness += frame_blockiness;
|
| }
|
| }
|
| @@ -4471,7 +4496,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| if (!cm->use_highbitdepth)
|
| #endif
|
| {
|
| - double this_inconsistency = vp9_get_ssim_metrics(
|
| + double this_inconsistency = vpx_get_ssim_metrics(
|
| cpi->Source->y_buffer, cpi->Source->y_stride,
|
| cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride,
|
| cpi->Source->y_width, cpi->Source->y_height, cpi->ssim_vars,
|
| @@ -4481,8 +4506,8 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| double consistency = vpx_sse_to_psnr(samples, peak,
|
| (double)cpi->total_inconsistency);
|
| if (consistency > 0.0)
|
| - cpi->worst_consistency = MIN(cpi->worst_consistency,
|
| - consistency);
|
| + cpi->worst_consistency =
|
| + VPXMIN(cpi->worst_consistency, consistency);
|
| cpi->total_inconsistency += this_inconsistency;
|
| }
|
| }
|
| @@ -4491,14 +4516,14 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| double y, u, v, frame_all;
|
| #if CONFIG_VP9_HIGHBITDEPTH
|
| if (cm->use_highbitdepth) {
|
| - frame_all = vp9_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y,
|
| + frame_all = vpx_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y,
|
| &u, &v, (int)cm->bit_depth);
|
| } else {
|
| - frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u,
|
| + frame_all = vpx_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u,
|
| &v);
|
| }
|
| #else
|
| - frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
|
| + frame_all = vpx_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
|
| #endif // CONFIG_VP9_HIGHBITDEPTH
|
| adjust_image_stat(y, u, v, frame_all, &cpi->ssimg);
|
| }
|
| @@ -4507,7 +4532,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| #endif
|
| {
|
| double y, u, v, frame_all;
|
| - frame_all = vp9_calc_fastssim(cpi->Source, cm->frame_to_show, &y, &u,
|
| + frame_all = vpx_calc_fastssim(cpi->Source, cm->frame_to_show, &y, &u,
|
| &v);
|
| adjust_image_stat(y, u, v, frame_all, &cpi->fastssim);
|
| /* TODO(JBB): add 10/12 bit support */
|
| @@ -4517,7 +4542,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| #endif
|
| {
|
| double y, u, v, frame_all;
|
| - frame_all = vp9_psnrhvs(cpi->Source, cm->frame_to_show, &y, &u, &v);
|
| + frame_all = vpx_psnrhvs(cpi->Source, cm->frame_to_show, &y, &u, &v);
|
| adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs);
|
| }
|
| }
|
| @@ -4546,6 +4571,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
|
| cpi->svc.spatial_layer_to_encode = 0;
|
| }
|
| }
|
| + vpx_clear_system_state();
|
| return 0;
|
| }
|
|
|
| @@ -4574,7 +4600,7 @@ int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
|
| ret = -1;
|
| }
|
| #endif // !CONFIG_VP9_POSTPROC
|
| - vp9_clear_system_state();
|
| + vpx_clear_system_state();
|
| return ret;
|
| }
|
| }
|
|
|