diff options
-rw-r--r-- | vp9/encoder/vp9_bitstream.c | 3 | ||||
-rw-r--r-- | vp9/encoder/vp9_encodemv.c | 8 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 57 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_int.h | 14 | ||||
-rw-r--r-- | vp9/encoder/vp9_pickmode.c | 4 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 18 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.h | 3 | ||||
-rw-r--r-- | vpxdec.c | 60 |
8 files changed, 74 insertions, 93 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 7188d7674..2ab4c7907 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -746,6 +746,7 @@ static void update_coef_probs(VP9_COMP* cpi, vp9_writer* w) { const TX_MODE tx_mode = cpi->common.tx_mode; const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; TX_SIZE tx_size; + vp9_clear_system_state(); for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) build_tree_distribution(cpi, tx_size); @@ -1295,6 +1296,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size) { active_section = 7; #endif + vp9_clear_system_state(); // __asm emms; + first_part_size = write_compressed_header(cpi, data); data += first_part_size; vp9_wb_write_literal(&saved_wb, first_part_size, 16); diff --git a/vp9/encoder/vp9_encodemv.c b/vp9/encoder/vp9_encodemv.c index 853094b29..af710a8f4 100644 --- a/vp9/encoder/vp9_encodemv.c +++ b/vp9/encoder/vp9_encodemv.c @@ -224,9 +224,13 @@ void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w, } } -void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2], +void vp9_build_nmv_cost_table(int *mvjoint, + int *mvcost[2], const nmv_context* const mvctx, - int usehp, int mvc_flag_v, int mvc_flag_h) { + int usehp, + int mvc_flag_v, + int mvc_flag_h) { + vp9_clear_system_state(); vp9_cost_tokens(mvjoint, mvctx->joints, vp9_mv_joint_tree); if (mvc_flag_v) build_nmv_component_cost_table(mvcost[0], &mvctx->comps[0], usehp); diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 56872682a..2aad6c79e 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -927,7 +927,7 @@ static int estimate_max_q(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats, int section_target_bandwitdh) { int q; - int num_mbs = cpi->common.MBs; + const int num_mbs = cpi->common.MBs; int target_norm_bits_per_mb; RATE_CONTROL *const rc = &cpi->rc; @@ -953,9 +953,8 @@ static int estimate_max_q(VP9_COMP *cpi, } // Restriction on active max q for constrained quality mode. - if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY && - q < cpi->cq_target_quality) - q = cpi->cq_target_quality; + if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) + q = MAX(q, cpi->cq_target_quality); return q; } @@ -1018,6 +1017,7 @@ void vp9_init_second_pass(VP9_COMP *cpi) { FIRSTPASS_STATS this_frame; FIRSTPASS_STATS *start_pos; struct twopass_rc *const twopass = &cpi->twopass; + const VP9_CONFIG *const oxcf = &cpi->oxcf; zero_stats(&twopass->total_stats); zero_stats(&twopass->total_left_stats); @@ -1036,9 +1036,9 @@ void vp9_init_second_pass(VP9_COMP *cpi) { vp9_new_framerate(cpi, 10000000.0 * twopass->total_stats.count / twopass->total_stats.duration); - cpi->output_framerate = cpi->oxcf.framerate; + cpi->output_framerate = oxcf->framerate; twopass->bits_left = (int64_t)(twopass->total_stats.duration * - cpi->oxcf.target_bandwidth / 10000000.0); + oxcf->target_bandwidth / 10000000.0); // Calculate a minimum intra value to be used in determining the IIratio // scores used in the second pass. We have this minimum to make sure @@ -1054,15 +1054,12 @@ void vp9_init_second_pass(VP9_COMP *cpi) { // ratio for the sequence. { double sum_iiratio = 0.0; - double IIRatio; - start_pos = twopass->stats_in; // Note the starting "file" position. while (input_stats(twopass, &this_frame) != EOF) { - IIRatio = this_frame.intra_error - / DOUBLE_DIVIDE_CHECK(this_frame.coded_error); - IIRatio = (IIRatio < 1.0) ? 1.0 : (IIRatio > 20.0) ? 20.0 : IIRatio; - sum_iiratio += IIRatio; + const double iiratio = this_frame.intra_error / + DOUBLE_DIVIDE_CHECK(this_frame.coded_error); + sum_iiratio += fclamp(iiratio, 1.0, 20.0); } twopass->avg_iiratio = sum_iiratio / @@ -1082,9 +1079,9 @@ void vp9_init_second_pass(VP9_COMP *cpi) { twopass->modified_error_total = 0.0; twopass->modified_error_min = - (av_error * cpi->oxcf.two_pass_vbrmin_section) / 100; + (av_error * oxcf->two_pass_vbrmin_section) / 100; twopass->modified_error_max = - (av_error * cpi->oxcf.two_pass_vbrmax_section) / 100; + (av_error * oxcf->two_pass_vbrmax_section) / 100; while (input_stats(twopass, &this_frame) != EOF) { twopass->modified_error_total += @@ -1188,9 +1185,6 @@ static void accumulate_frame_motion_stats( double *mv_in_out_accumulator, double *abs_mv_in_out_accumulator, double *mv_ratio_accumulator) { - // double this_frame_mv_in_out; - double this_frame_mvr_ratio; - double this_frame_mvc_ratio; double motion_pct; // Accumulate motion stats. @@ -1205,29 +1199,25 @@ static void accumulate_frame_motion_stats( // Accumulate a measure of how uniform (or conversely how random) // the motion field is. (A ratio of absmv / mv) if (motion_pct > 0.05) { - this_frame_mvr_ratio = fabs(this_frame->mvr_abs) / + double this_frame_mvr_ratio = fabs(this_frame->mvr_abs) / DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVr)); - this_frame_mvc_ratio = fabs(this_frame->mvc_abs) / + double this_frame_mvc_ratio = fabs(this_frame->mvc_abs) / DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVc)); - *mv_ratio_accumulator += - (this_frame_mvr_ratio < this_frame->mvr_abs) + *mv_ratio_accumulator += (this_frame_mvr_ratio < this_frame->mvr_abs) ? (this_frame_mvr_ratio * motion_pct) : this_frame->mvr_abs * motion_pct; - *mv_ratio_accumulator += - (this_frame_mvc_ratio < this_frame->mvc_abs) + *mv_ratio_accumulator += (this_frame_mvc_ratio < this_frame->mvc_abs) ? (this_frame_mvc_ratio * motion_pct) : this_frame->mvc_abs * motion_pct; } } // Calculate a baseline boost number for the current frame. -static double calc_frame_boost( - VP9_COMP *cpi, - FIRSTPASS_STATS *this_frame, - double this_frame_mv_in_out) { +static double calc_frame_boost(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame, + double this_frame_mv_in_out) { double frame_boost; // Underlying boost factor is based on inter intra error ratio @@ -1248,11 +1238,7 @@ static double calc_frame_boost( else frame_boost += frame_boost * (this_frame_mv_in_out / 2.0); - // Clip to maximum - if (frame_boost > GF_RMAX) - frame_boost = GF_RMAX; - - return frame_boost; + return MIN(frame_boost, GF_RMAX); } static int calc_arf_boost(VP9_COMP *cpi, int offset, @@ -2137,7 +2123,6 @@ static int test_candidate_kf(VP9_COMP *cpi, double boost_score = 0.0; double old_boost_score = 0.0; double decay_accumulator = 1.0; - double next_iiratio; local_next_frame = *next_frame; @@ -2146,8 +2131,8 @@ static int test_candidate_kf(VP9_COMP *cpi, // Examine how well the key frame predicts subsequent frames for (i = 0; i < 16; i++) { - next_iiratio = (IIKFACTOR1 * local_next_frame.intra_error / - DOUBLE_DIVIDE_CHECK(local_next_frame.coded_error)); + double next_iiratio = (IIKFACTOR1 * local_next_frame.intra_error / + DOUBLE_DIVIDE_CHECK(local_next_frame.coded_error)); if (next_iiratio > RMAX) next_iiratio = RMAX; @@ -2405,7 +2390,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { // How fast is prediction quality decaying if (!detect_flash(cpi, 0)) { loop_decay_rate = get_prediction_decay_rate(cpi, &next_frame); - decay_accumulator = decay_accumulator * loop_decay_rate; + decay_accumulator *= loop_decay_rate; decay_accumulator = decay_accumulator < MIN_DECAY_FACTOR ? MIN_DECAY_FACTOR : decay_accumulator; } diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index a665bf859..6f4c9a40f 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -780,7 +780,8 @@ typedef struct VP9_COMP { PARTITION_CONTEXT left_seg_context[8]; } VP9_COMP; -static int get_ref_frame_idx(VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { +static int get_ref_frame_idx(const VP9_COMP *cpi, + MV_REFERENCE_FRAME ref_frame) { if (ref_frame == LAST_FRAME) { return cpi->lst_fb_idx; } else if (ref_frame == GOLDEN_FRAME) { @@ -790,17 +791,6 @@ static int get_ref_frame_idx(VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { } } -static int get_scale_ref_frame_idx(VP9_COMP *cpi, - MV_REFERENCE_FRAME ref_frame) { - if (ref_frame == LAST_FRAME) { - return 0; - } else if (ref_frame == GOLDEN_FRAME) { - return 1; - } else { - return 2; - } -} - static YV12_BUFFER_CONFIG *get_ref_frame_buffer(VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { VP9_COMMON *const cm = &cpi->common; diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index f317f2a0d..210d15f0d 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -60,8 +60,8 @@ static int full_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, int buf_offset; int stride = xd->plane[0].pre[0].stride; - YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, ref); - + const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, + ref); if (scaled_ref_frame) { int i; // Swap out the reference frame for a version that's been scaled to diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 242aa8710..706dde519 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2304,13 +2304,12 @@ void vp9_setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, ref_frame, block_size); } -YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(VP9_COMP *cpi, int ref_frame) { - YV12_BUFFER_CONFIG *scaled_ref_frame = NULL; - int fb = get_ref_frame_idx(cpi, ref_frame); - int fb_scale = get_scale_ref_frame_idx(cpi, ref_frame); - if (cpi->scaled_ref_idx[fb_scale] != cpi->common.ref_frame_map[fb]) - scaled_ref_frame = &cpi->common.yv12_fb[cpi->scaled_ref_idx[fb_scale]]; - return scaled_ref_frame; +const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, + int ref_frame) { + const VP9_COMMON *const cm = &cpi->common; + const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; + const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1]; + return (scaled_idx != ref_idx) ? &cm->yv12_fb[scaled_idx] : NULL; } static INLINE int get_switchable_rate(const MACROBLOCK *x) { @@ -2342,7 +2341,8 @@ static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, int tmp_row_min = x->mv_row_min; int tmp_row_max = x->mv_row_max; - YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, ref); + const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, + ref); int_mv pred_mv[3]; pred_mv[0] = mbmi->ref_mvs[ref][0]; @@ -2489,7 +2489,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, struct buf_2d backup_yv12[2][MAX_MB_PLANE]; struct buf_2d scaled_first_yv12 = xd->plane[0].pre[0]; int last_besterr[2] = {INT_MAX, INT_MAX}; - YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { + const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]), vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1]) }; diff --git a/vp9/encoder/vp9_rdopt.h b/vp9/encoder/vp9_rdopt.h index 9ac1f5404..604236462 100644 --- a/vp9/encoder/vp9_rdopt.h +++ b/vp9/encoder/vp9_rdopt.h @@ -46,7 +46,8 @@ void vp9_setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, int_mv frame_near_mv[MAX_REF_FRAMES], struct buf_2d yv12_mb[4][MAX_MB_PLANE]); -YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(VP9_COMP *cpi, int ref_frame); +const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, + int ref_frame); void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, int *r, int64_t *d, BLOCK_SIZE bsize, @@ -839,13 +839,12 @@ int main_loop(int argc, const char **argv_) { if (progress) show_progress(frame_in, frame_out, dx_time); - if (!noblit) { - if (frame_out == 1 && img && single_file && !do_md5 && use_y4m) - y4m_write_file_header(outfile, - vpx_input_ctx.width, vpx_input_ctx.height, - &vpx_input_ctx.framerate, img->fmt); + if (!noblit && img) { + const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; + const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; + const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; - if (img && do_scale) { + if (do_scale) { if (frame_out == 1) { // If the output frames are to be scaled to a fixed display size then // use the width and height specified in the container. If either of @@ -876,33 +875,32 @@ int main_loop(int argc, const char **argv_) { } } - if (img) { - const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; - const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; - - const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; - - if (!single_file) { - generate_filename(outfile_pattern, outfile_name, PATH_MAX, - img->d_w, img->d_h, frame_in); - if (do_md5) { - MD5Init(&md5_ctx); - update_image_md5(img, planes, &md5_ctx); - MD5Final(md5_digest, &md5_ctx); - print_md5(md5_digest, outfile_name); - } else { - outfile = open_outfile(outfile_name); - write_image_file(img, planes, outfile); - fclose(outfile); - } + if (single_file) { + if (do_md5) { + update_image_md5(img, planes, &md5_ctx); } else { - if (do_md5) { - update_image_md5(img, planes, &md5_ctx); - } else { - if (use_y4m) - y4m_write_frame_header(outfile); - write_image_file(img, planes, outfile); + if (use_y4m) { + if (frame_out == 1) { + y4m_write_file_header(outfile, + vpx_input_ctx.width, vpx_input_ctx.height, + &vpx_input_ctx.framerate, img->fmt); + } + y4m_write_frame_header(outfile); } + write_image_file(img, planes, outfile); + } + } else { + generate_filename(outfile_pattern, outfile_name, PATH_MAX, + img->d_w, img->d_h, frame_in); + if (do_md5) { + MD5Init(&md5_ctx); + update_image_md5(img, planes, &md5_ctx); + MD5Final(md5_digest, &md5_ctx); + print_md5(md5_digest, outfile_name); + } else { + outfile = open_outfile(outfile_name); + write_image_file(img, planes, outfile); + fclose(outfile); } } } |