From 180cd5faa52e00a77df13da15d846cfd909fc531 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Wed, 27 Mar 2013 14:22:30 -0700 Subject: General code cleanup. Removing redundant code, lower case variable names, better indentation, better parameter names, adding const to readonly parameters. Change-Id: Ibfdee00f60316fdc5b3f024028c7aaa76a627483 --- vp9/common/vp9_entropymv.c | 87 ++++++++---------- vp9/common/vp9_extend.c | 216 ++++++++++++++++++++------------------------ vp9/common/vp9_extend.h | 10 +- vp9/common/vp9_postproc.c | 7 +- vp9/common/vp9_postproc.h | 4 +- vp9/decoder/vp9_dboolhuff.h | 38 ++++---- vp9/decoder/vp9_onyxd_if.c | 36 ++++---- vp9/encoder/vp9_onyx_if.c | 123 +++++++++---------------- 8 files changed, 222 insertions(+), 299 deletions(-) (limited to 'vp9') diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c index 89dea4edc..a4a9d5465 100644 --- a/vp9/common/vp9_entropymv.c +++ b/vp9/common/vp9_entropymv.c @@ -116,11 +116,8 @@ MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset) { } int vp9_use_nmv_hp(const MV *ref) { - if ((abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH && - (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH) - return 1; - else - return 0; + return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH && + (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; } int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { @@ -231,13 +228,13 @@ static void adapt_prob(vp9_prob *dest, vp9_prob prep, } } -void vp9_counts_process(nmv_context_counts *NMVcount, int usehp) { - counts_to_context(&NMVcount->comps[0], usehp); - counts_to_context(&NMVcount->comps[1], usehp); +void vp9_counts_process(nmv_context_counts *nmv_count, int usehp) { + counts_to_context(&nmv_count->comps[0], usehp); + counts_to_context(&nmv_count->comps[1], usehp); } void vp9_counts_to_nmv_context( - nmv_context_counts *NMVcount, + nmv_context_counts *nmv_count, nmv_context *prob, int usehp, unsigned int (*branch_ct_joint)[2], @@ -250,29 +247,29 @@ void vp9_counts_to_nmv_context( unsigned int (*branch_ct_class0_hp)[2], unsigned int (*branch_ct_hp)[2]) { int i, j, k; - vp9_counts_process(NMVcount, usehp); + vp9_counts_process(nmv_count, usehp); vp9_tree_probs_from_distribution(vp9_mv_joint_tree, prob->joints, branch_ct_joint, - NMVcount->joints, 0); + nmv_count->joints, 0); for (i = 0; i < 2; ++i) { - prob->comps[i].sign = get_binary_prob(NMVcount->comps[i].sign[0], - NMVcount->comps[i].sign[1]); - branch_ct_sign[i][0] = NMVcount->comps[i].sign[0]; - branch_ct_sign[i][1] = NMVcount->comps[i].sign[1]; + prob->comps[i].sign = get_binary_prob(nmv_count->comps[i].sign[0], + nmv_count->comps[i].sign[1]); + branch_ct_sign[i][0] = nmv_count->comps[i].sign[0]; + branch_ct_sign[i][1] = nmv_count->comps[i].sign[1]; vp9_tree_probs_from_distribution(vp9_mv_class_tree, prob->comps[i].classes, branch_ct_classes[i], - NMVcount->comps[i].classes, 0); + nmv_count->comps[i].classes, 0); vp9_tree_probs_from_distribution(vp9_mv_class0_tree, prob->comps[i].class0, branch_ct_class0[i], - NMVcount->comps[i].class0, 0); + nmv_count->comps[i].class0, 0); for (j = 0; j < MV_OFFSET_BITS; ++j) { - prob->comps[i].bits[j] = get_binary_prob(NMVcount->comps[i].bits[j][0], - NMVcount->comps[i].bits[j][1]); - branch_ct_bits[i][j][0] = NMVcount->comps[i].bits[j][0]; - branch_ct_bits[i][j][1] = NMVcount->comps[i].bits[j][1]; + prob->comps[i].bits[j] = get_binary_prob(nmv_count->comps[i].bits[j][0], + nmv_count->comps[i].bits[j][1]); + branch_ct_bits[i][j][0] = nmv_count->comps[i].bits[j][0]; + branch_ct_bits[i][j][1] = nmv_count->comps[i].bits[j][1]; } } for (i = 0; i < 2; ++i) { @@ -280,25 +277,25 @@ void vp9_counts_to_nmv_context( vp9_tree_probs_from_distribution(vp9_mv_fp_tree, prob->comps[i].class0_fp[k], branch_ct_class0_fp[i][k], - NMVcount->comps[i].class0_fp[k], 0); + nmv_count->comps[i].class0_fp[k], 0); } vp9_tree_probs_from_distribution(vp9_mv_fp_tree, prob->comps[i].fp, branch_ct_fp[i], - NMVcount->comps[i].fp, 0); + nmv_count->comps[i].fp, 0); } if (usehp) { for (i = 0; i < 2; ++i) { prob->comps[i].class0_hp = - get_binary_prob(NMVcount->comps[i].class0_hp[0], - NMVcount->comps[i].class0_hp[1]); - branch_ct_class0_hp[i][0] = NMVcount->comps[i].class0_hp[0]; - branch_ct_class0_hp[i][1] = NMVcount->comps[i].class0_hp[1]; - - prob->comps[i].hp = get_binary_prob(NMVcount->comps[i].hp[0], - NMVcount->comps[i].hp[1]); - branch_ct_hp[i][0] = NMVcount->comps[i].hp[0]; - branch_ct_hp[i][1] = NMVcount->comps[i].hp[1]; + get_binary_prob(nmv_count->comps[i].class0_hp[0], + nmv_count->comps[i].class0_hp[1]); + branch_ct_class0_hp[i][0] = nmv_count->comps[i].class0_hp[0]; + branch_ct_class0_hp[i][1] = nmv_count->comps[i].class0_hp[1]; + + prob->comps[i].hp = get_binary_prob(nmv_count->comps[i].hp[0], + nmv_count->comps[i].hp[1]); + branch_ct_hp[i][0] = nmv_count->comps[i].hp[0]; + branch_ct_hp[i][1] = nmv_count->comps[i].hp[1]; } } } @@ -308,32 +305,26 @@ static unsigned int adapt_probs(unsigned int i, vp9_prob this_probs[], const vp9_prob last_probs[], const unsigned int num_events[]) { - unsigned int left, right, weight; vp9_prob this_prob; - if (tree[i] <= 0) { - left = num_events[-tree[i]]; - } else { - left = adapt_probs(tree[i], tree, this_probs, last_probs, - num_events); - } - if (tree[i + 1] <= 0) { - right = num_events[-tree[i + 1]]; - } else { - right = adapt_probs(tree[i + 1], tree, this_probs, last_probs, - num_events); - } + const uint32_t left = tree[i] <= 0 + ? num_events[-tree[i]] + : adapt_probs(tree[i], tree, this_probs, last_probs, num_events); + + const uint32_t right = tree[i + 1] <= 0 + ? num_events[-tree[i + 1]] + : adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events); - weight = left + right; + uint32_t weight = left + right; if (weight) { this_prob = get_binary_prob(left, right); weight = weight > MV_COUNT_SAT ? MV_COUNT_SAT : weight; - this_prob = weighted_prob(last_probs[i>>1], this_prob, + this_prob = weighted_prob(last_probs[i >> 1], this_prob, MV_MAX_UPDATE_FACTOR * weight / MV_COUNT_SAT); } else { this_prob = last_probs[i >> 1]; } - this_probs[i>>1] = this_prob; + this_probs[i >> 1] = this_prob; return left + right; } diff --git a/vp9/common/vp9_extend.c b/vp9/common/vp9_extend.c index d3e66f696..6aac90537 100644 --- a/vp9/common/vp9_extend.c +++ b/vp9/common/vp9_extend.c @@ -11,159 +11,137 @@ #include "vp9/common/vp9_extend.h" #include "vpx_mem/vpx_mem.h" -static void copy_and_extend_plane(uint8_t *s, /* source */ - int sp, /* source pitch */ - uint8_t *d, /* destination */ - int dp, /* destination pitch */ - int h, /* height */ - int w, /* width */ - int et, /* extend top border */ - int el, /* extend left border */ - int eb, /* extend bottom border */ - int er) { /* extend right border */ - int i; - uint8_t *src_ptr1, *src_ptr2; - uint8_t *dest_ptr1, *dest_ptr2; - int linesize; - - /* copy the left and right most columns out */ - src_ptr1 = s; - src_ptr2 = s + w - 1; - dest_ptr1 = d - el; - dest_ptr2 = d + w; +static void copy_and_extend_plane(const uint8_t *src, int src_pitch, + uint8_t *dst, int dst_pitch, + int w, int h, + int extend_top, int extend_left, + int extend_bottom, int extend_right) { + int i, linesize; + + // copy the left and right most columns out + const uint8_t *src_ptr1 = src; + const uint8_t *src_ptr2 = src + w - 1; + uint8_t *dst_ptr1 = dst - extend_left; + uint8_t *dst_ptr2 = dst + w; for (i = 0; i < h; i++) { - vpx_memset(dest_ptr1, src_ptr1[0], el); - vpx_memcpy(dest_ptr1 + el, src_ptr1, w); - vpx_memset(dest_ptr2, src_ptr2[0], er); - src_ptr1 += sp; - src_ptr2 += sp; - dest_ptr1 += dp; - dest_ptr2 += dp; + vpx_memset(dst_ptr1, src_ptr1[0], extend_left); + vpx_memcpy(dst_ptr1 + extend_left, src_ptr1, w); + vpx_memset(dst_ptr2, src_ptr2[0], extend_right); + src_ptr1 += src_pitch; + src_ptr2 += src_pitch; + dst_ptr1 += dst_pitch; + dst_ptr2 += dst_pitch; } - /* Now copy the top and bottom lines into each line of the respective - * borders - */ - src_ptr1 = d - el; - src_ptr2 = d + dp * (h - 1) - el; - dest_ptr1 = d + dp * (-et) - el; - dest_ptr2 = d + dp * (h) - el; - linesize = el + er + w; - - for (i = 0; i < et; i++) { - vpx_memcpy(dest_ptr1, src_ptr1, linesize); - dest_ptr1 += dp; + // Now copy the top and bottom lines into each line of the respective + // borders + src_ptr1 = dst - extend_left; + src_ptr2 = dst + dst_pitch * (h - 1) - extend_left; + dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left; + dst_ptr2 = dst + dst_pitch * (h) - extend_left; + linesize = extend_left + extend_right + w; + + for (i = 0; i < extend_top; i++) { + vpx_memcpy(dst_ptr1, src_ptr1, linesize); + dst_ptr1 += dst_pitch; } - for (i = 0; i < eb; i++) { - vpx_memcpy(dest_ptr2, src_ptr2, linesize); - dest_ptr2 += dp; + for (i = 0; i < extend_bottom; i++) { + vpx_memcpy(dst_ptr2, src_ptr2, linesize); + dst_ptr2 += dst_pitch; } } -void vp9_copy_and_extend_frame(YV12_BUFFER_CONFIG *src, +void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst) { - int et = dst->border; - int el = dst->border; - int eb = dst->border + dst->y_height - src->y_height; - int er = dst->border + dst->y_width - src->y_width; + const int et_y = dst->border; + const int el_y = dst->border; + const int eb_y = dst->border + dst->y_height - src->y_height; + const int er_y = dst->border + dst->y_width - src->y_width; + + const int et_uv = dst->border >> 1; + const int el_uv = dst->border >> 1; + const int eb_uv = (dst->border >> 1) + dst->uv_height - src->uv_height; + const int er_uv = (dst->border >> 1) + dst->uv_width - src->uv_width; copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer, dst->y_stride, - src->y_height, src->y_width, - et, el, eb, er); - - et = dst->border >> 1; - el = dst->border >> 1; - eb = (dst->border >> 1) + dst->uv_height - src->uv_height; - er = (dst->border >> 1) + dst->uv_width - src->uv_width; + src->y_width, src->y_height, + et_y, el_y, eb_y, er_y); copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer, dst->uv_stride, - src->uv_height, src->uv_width, - et, el, eb, er); + src->uv_width, src->uv_height, + et_uv, el_uv, eb_uv, er_uv); copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer, dst->uv_stride, - src->uv_height, src->uv_width, - et, el, eb, er); + src->uv_width, src->uv_height, + et_y, el_y, eb_uv, er_uv); } -void vp9_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src, +void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, int srcy, int srcx, int srch, int srcw) { - int et = dst->border; - int el = dst->border; - int eb = dst->border + dst->y_height - src->y_height; - int er = dst->border + dst->y_width - src->y_width; - int src_y_offset = srcy * src->y_stride + srcx; - int dst_y_offset = srcy * dst->y_stride + srcx; - int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); - int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); - // If the side is not touching the bounder then don't extend. - if (srcy) - et = 0; - if (srcx) - el = 0; - if (srcy + srch != src->y_height) - eb = 0; - if (srcx + srcw != src->y_width) - er = 0; - - copy_and_extend_plane(src->y_buffer + src_y_offset, - src->y_stride, - dst->y_buffer + dst_y_offset, - dst->y_stride, - srch, srcw, - et, el, eb, er); - - et = (et + 1) >> 1; - el = (el + 1) >> 1; - eb = (eb + 1) >> 1; - er = (er + 1) >> 1; - srch = (srch + 1) >> 1; - srcw = (srcw + 1) >> 1; - - copy_and_extend_plane(src->u_buffer + src_uv_offset, - src->uv_stride, - dst->u_buffer + dst_uv_offset, - dst->uv_stride, - srch, srcw, - et, el, eb, er); - - copy_and_extend_plane(src->v_buffer + src_uv_offset, - src->uv_stride, - dst->v_buffer + dst_uv_offset, - dst->uv_stride, - srch, srcw, - et, el, eb, er); + const int et_y = srcy ? 0 : dst->border; + const int el_y = srcx ? 0 : dst->border; + const int eb_y = srcy + srch != src->y_height ? 0 : + dst->border + dst->y_height - src->y_height; + const int er_y = srcx + srcw != src->y_width ? 0 : + dst->border + dst->y_width - src->y_width; + const int src_y_offset = srcy * src->y_stride + srcx; + const int dst_y_offset = srcy * dst->y_stride + srcx; + + const int et_uv = (et_y + 1) >> 1; + const int el_uv = (el_y + 1) >> 1; + const int eb_uv = (eb_y + 1) >> 1; + const int er_uv = (er_y + 1) >> 1; + const int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); + const int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); + const int srch_uv = (srch + 1) >> 1; + const int srcw_uv = (srcw + 1) >> 1; + + copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride, + dst->y_buffer + dst_y_offset, dst->y_stride, + srcw, srch, + et_y, el_y, eb_y, er_y); + + copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride, + dst->u_buffer + dst_uv_offset, dst->uv_stride, + srcw_uv, srch_uv, + et_uv, el_uv, eb_uv, er_uv); + + copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride, + dst->v_buffer + dst_uv_offset, dst->uv_stride, + srcw_uv, srch_uv, + et_uv, el_uv, eb_uv, er_uv); } -/* note the extension is only for the last row, for intra prediction purpose */ -void vp9_extend_mb_row(YV12_BUFFER_CONFIG *ybf, uint8_t *YPtr, - uint8_t *UPtr, uint8_t *VPtr) { +// note the extension is only for the last row, for intra prediction purpose +void vp9_extend_mb_row(YV12_BUFFER_CONFIG *buf, + uint8_t *y, uint8_t *u, uint8_t *v) { int i; - YPtr += ybf->y_stride * 14; - UPtr += ybf->uv_stride * 6; - VPtr += ybf->uv_stride * 6; + y += buf->y_stride * 14; + u += buf->uv_stride * 6; + v += buf->uv_stride * 6; for (i = 0; i < 4; i++) { - YPtr[i] = YPtr[-1]; - UPtr[i] = UPtr[-1]; - VPtr[i] = VPtr[-1]; + y[i] = y[-1]; + u[i] = u[-1]; + v[i] = v[-1]; } - YPtr += ybf->y_stride; - UPtr += ybf->uv_stride; - VPtr += ybf->uv_stride; + y += buf->y_stride; + u += buf->uv_stride; + v += buf->uv_stride; for (i = 0; i < 4; i++) { - YPtr[i] = YPtr[-1]; - UPtr[i] = UPtr[-1]; - VPtr[i] = VPtr[-1]; + y[i] = y[-1]; + u[i] = u[-1]; + v[i] = v[-1]; } } diff --git a/vp9/common/vp9_extend.h b/vp9/common/vp9_extend.h index 847c2c5b9..6ec75c992 100644 --- a/vp9/common/vp9_extend.h +++ b/vp9/common/vp9_extend.h @@ -14,15 +14,17 @@ #include "vpx_scale/yv12config.h" #include "vpx/vpx_integer.h" -void vp9_extend_mb_row(YV12_BUFFER_CONFIG *ybf, uint8_t *YPtr, - uint8_t *UPtr, uint8_t *VPtr); -void vp9_copy_and_extend_frame(YV12_BUFFER_CONFIG *src, +void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst); -void vp9_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src, +void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, int srcy, int srcx, int srch, int srcw); +void vp9_extend_mb_row(YV12_BUFFER_CONFIG *buf, + uint8_t *y, uint8_t *u, uint8_t *v); + + #endif // VP9_COMMON_VP9_EXTEND_H_ diff --git a/vp9/common/vp9_postproc.c b/vp9/common/vp9_postproc.c index e59bc5038..06dadfca5 100644 --- a/vp9/common/vp9_postproc.c +++ b/vp9/common/vp9_postproc.c @@ -336,11 +336,8 @@ void vp9_deblock(YV12_BUFFER_CONFIG *source, source->uv_height, source->uv_width, ppl); } -void vp9_de_noise(YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *post, - int q, - int low_var_thresh, - int flag) { +void vp9_denoise(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *post, + int q, int low_var_thresh, int flag) { double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; int ppl = (int)(level + .5); (void) post; diff --git a/vp9/common/vp9_postproc.h b/vp9/common/vp9_postproc.h index 0a637f011..c2f556e61 100644 --- a/vp9/common/vp9_postproc.h +++ b/vp9/common/vp9_postproc.h @@ -29,8 +29,8 @@ struct postproc_state { int vp9_post_proc_frame(struct VP9Common *oci, YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *flags); -void vp9_de_noise(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, - int q, int low_var_thresh, int flag); +void vp9_denoise(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, + int q, int low_var_thresh, int flag); void vp9_deblock(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int q, int low_var_thresh, int flag); diff --git a/vp9/decoder/vp9_dboolhuff.h b/vp9/decoder/vp9_dboolhuff.h index eeb5c35d4..02ae1d3c8 100644 --- a/vp9/decoder/vp9_dboolhuff.h +++ b/vp9/decoder/vp9_dboolhuff.h @@ -88,34 +88,28 @@ static int decode_value(BOOL_DECODER *br, int bits) { int bit; for (bit = bits - 1; bit >= 0; bit--) { - z |= (decode_bool(br, 0x80) << bit); + z |= decode_bool(br, 0x80) << bit; } return z; } static int bool_error(BOOL_DECODER *br) { - /* Check if we have reached the end of the buffer. - * - * Variable 'count' stores the number of bits in the 'value' buffer, minus - * 8. The top byte is part of the algorithm, and the remainder is buffered - * to be shifted into it. So if count == 8, the top 16 bits of 'value' are - * occupied, 8 for the algorithm and 8 in the buffer. - * - * When reading a byte from the user's buffer, count is filled with 8 and - * one byte is filled into the value buffer. When we reach the end of the - * data, count is additionally filled with VP9_LOTS_OF_BITS. So when - * count == VP9_LOTS_OF_BITS - 1, the user's data has been exhausted. - */ - if ((br->count > VP9_BD_VALUE_SIZE) && (br->count < VP9_LOTS_OF_BITS)) { - /* We have tried to decode bits after the end of - * stream was encountered. - */ - return 1; - } - - /* No error. */ - return 0; + // Check if we have reached the end of the buffer. + // + // Variable 'count' stores the number of bits in the 'value' buffer, minus + // 8. The top byte is part of the algorithm, and the remainder is buffered + // to be shifted into it. So if count == 8, the top 16 bits of 'value' are + // occupied, 8 for the algorithm and 8 in the buffer. + // + // When reading a byte from the user's buffer, count is filled with 8 and + // one byte is filled into the value buffer. When we reach the end of the + // data, count is additionally filled with VP9_LOTS_OF_BITS. So when + // count == VP9_LOTS_OF_BITS - 1, the user's data has been exhausted. + // + // 1 if we have tried to decode bits after the end of stream was encountered. + // 0 No error. + return br->count > VP9_BD_VALUE_SIZE && br->count < VP9_LOTS_OF_BITS; } int vp9_decode_unsigned_max(BOOL_DECODER *br, int max); diff --git a/vp9/decoder/vp9_onyxd_if.c b/vp9/decoder/vp9_onyxd_if.c index bcb5897e6..2b61f0aff 100644 --- a/vp9/decoder/vp9_onyxd_if.c +++ b/vp9/decoder/vp9_onyxd_if.c @@ -154,8 +154,8 @@ void vp9_remove_decompressor(VP9D_PTR ptr) { if (!pbi) return; - // Delete sementation map - if (pbi->common.last_frame_seg_map != 0) + // Delete segmentation map + if (pbi->common.last_frame_seg_map) vpx_free(pbi->common.last_frame_seg_map); vp9_remove_common(&pbi->common); @@ -163,6 +163,10 @@ void vp9_remove_decompressor(VP9D_PTR ptr) { vpx_free(pbi); } +static int equal_dimensions(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) { + return a->y_height == b->y_height && a->y_width == b->y_width && + a->uv_height == b->uv_height && a->uv_width == b->uv_width; +} vpx_codec_err_t vp9_copy_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, @@ -176,22 +180,20 @@ vpx_codec_err_t vp9_copy_reference_dec(VP9D_PTR ptr, * vpxenc --test-decode functionality working, and will be replaced in a * later commit that adds VP9-specific controls for this functionality. */ - if (ref_frame_flag == VP9_LAST_FLAG) + if (ref_frame_flag == VP9_LAST_FLAG) { ref_fb_idx = pbi->common.ref_frame_map[0]; - else { + } else { vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR, "Invalid reference frame"); return pbi->common.error.error_code; } - if (cm->yv12_fb[ref_fb_idx].y_height != sd->y_height || - cm->yv12_fb[ref_fb_idx].y_width != sd->y_width || - cm->yv12_fb[ref_fb_idx].uv_height != sd->uv_height || - cm->yv12_fb[ref_fb_idx].uv_width != sd->uv_width) { + if (!equal_dimensions(&cm->yv12_fb[ref_fb_idx], sd)) { vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR, "Incorrect buffer dimensions"); - } else + } else { vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd); + } return pbi->common.error.error_code; } @@ -202,7 +204,6 @@ vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, VP9D_COMP *pbi = (VP9D_COMP *) ptr; VP9_COMMON *cm = &pbi->common; int *ref_fb_ptr = NULL; - int free_fb; /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the * encoder is using the frame buffers for. This is just a stub to keep the @@ -221,20 +222,17 @@ vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, return pbi->common.error.error_code; } - if (cm->yv12_fb[*ref_fb_ptr].y_height != sd->y_height || - cm->yv12_fb[*ref_fb_ptr].y_width != sd->y_width || - cm->yv12_fb[*ref_fb_ptr].uv_height != sd->uv_height || - cm->yv12_fb[*ref_fb_ptr].uv_width != sd->uv_width) { + if (!equal_dimensions(&cm->yv12_fb[*ref_fb_ptr], sd)) { vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR, "Incorrect buffer dimensions"); } else { - /* Find an empty frame buffer. */ - free_fb = get_free_fb(cm); - /* Decrease fb_idx_ref_cnt since it will be increased again in - * ref_cnt_fb() below. */ + // Find an empty frame buffer. + const int free_fb = get_free_fb(cm); + // Decrease fb_idx_ref_cnt since it will be increased again in + // ref_cnt_fb() below. cm->fb_idx_ref_cnt[free_fb]--; - /* Manage the reference counters and copy image. */ + // Manage the reference counters and copy image. ref_cnt_fb(cm->fb_idx_ref_cnt, ref_fb_ptr, free_fb); vp8_yv12_copy_frame(sd, &cm->yv12_fb[*ref_fb_ptr]); } diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 490a63954..656975aa4 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -156,31 +156,24 @@ static int inter_minq[QINDEX_RANGE]; // The formulae were derived from computing a 3rd order polynomial best // fit to the original data (after plotting real maxq vs minq (not q index)) static int calculate_minq_index(double maxq, - double x3, double x2, double x, double c) { + double x3, double x2, double x1, double c) { int i; - double minqtarget; - - minqtarget = ((x3 * maxq * maxq * maxq) + - (x2 * maxq * maxq) + - (x * maxq) + - c); - - if (minqtarget > maxq) - minqtarget = maxq; + const double minqtarget = MIN(((x3 * maxq + x2) * maxq + x1) * maxq + c, + maxq); for (i = 0; i < QINDEX_RANGE; i++) { if (minqtarget <= vp9_convert_qindex_to_q(i)) return i; } + return QINDEX_RANGE - 1; } static void init_minq_luts(void) { int i; - double maxq; for (i = 0; i < QINDEX_RANGE; i++) { - maxq = vp9_convert_qindex_to_q(i); + const double maxq = vp9_convert_qindex_to_q(i); kf_low_motion_minq[i] = calculate_minq_index(maxq, @@ -216,7 +209,6 @@ static void set_mvcost(MACROBLOCK *mb) { if (mb->e_mbd.allow_high_precision_mv) { mb->mvcost = mb->nmvcost_hp; mb->mvsadcost = mb->nmvsadcost_hp; - } else { mb->mvcost = mb->nmvcost; mb->mvsadcost = mb->nmvsadcost; @@ -224,15 +216,13 @@ static void set_mvcost(MACROBLOCK *mb) { } static void init_base_skip_probs(void) { int i; - double q; - int t; for (i = 0; i < QINDEX_RANGE; i++) { - q = vp9_convert_qindex_to_q(i); + const double q = vp9_convert_qindex_to_q(i); // Exponential decay caluclation of baseline skip prob with clamping // Based on crude best fit of old table. - t = (int)(564.25 * pow(2.71828, (-0.012 * q))); + const int t = (int)(564.25 * pow(2.71828, (-0.012 * q))); base_skip_false_prob[i][1] = clip_prob(t); base_skip_false_prob[i][2] = clip_prob(t * 3 / 4); @@ -268,7 +258,6 @@ static void update_base_skip_probs(VP9_COMP *cpi) { cm->mbskip_pred_probs[k]; } } - } void vp9_initialize_enc() { @@ -309,7 +298,6 @@ static void setup_features(VP9_COMP *cpi) { vpx_memset(xd->last_mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas)); set_default_lf_deltas(cpi); - } @@ -527,17 +515,13 @@ static void print_seg_map(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; int row, col; int map_index = 0; - FILE *statsfile; + FILE *statsfile = fopen("segmap.stt", "a"); - statsfile = fopen("segmap.stt", "a"); - - fprintf(statsfile, "%10d\n", - cm->current_video_frame); + fprintf(statsfile, "%10d\n", cm->current_video_frame); for (row = 0; row < cpi->common.mb_rows; row++) { for (col = 0; col < cpi->common.mb_cols; col++) { - fprintf(statsfile, "%10d", - cpi->segmentation_map[map_index]); + fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]); map_index++; } fprintf(statsfile, "\n"); @@ -1153,10 +1137,7 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { VP9_COMP *cpi = (VP9_COMP *)(ptr); VP9_COMMON *const cm = &cpi->common; - if (!cpi) - return; - - if (!oxcf) + if (!cpi || !oxcf) return; if (cm->version != oxcf->version) { @@ -1197,11 +1178,11 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { cpi->oxcf.lossless = oxcf->lossless; if (cpi->oxcf.lossless) { - cpi->mb.e_mbd.inv_txm4x4_1 = vp9_short_iwalsh4x4_1; - cpi->mb.e_mbd.inv_txm4x4 = vp9_short_iwalsh4x4; + cpi->mb.e_mbd.inv_txm4x4_1 = vp9_short_iwalsh4x4_1; + cpi->mb.e_mbd.inv_txm4x4 = vp9_short_iwalsh4x4; } else { - cpi->mb.e_mbd.inv_txm4x4_1 = vp9_short_idct4x4_1; - cpi->mb.e_mbd.inv_txm4x4 = vp9_short_idct4x4; + cpi->mb.e_mbd.inv_txm4x4_1 = vp9_short_idct4x4_1; + cpi->mb.e_mbd.inv_txm4x4 = vp9_short_idct4x4; } cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL; @@ -1239,31 +1220,28 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { // Convert target bandwidth from Kbit/s to Bit/s cpi->oxcf.target_bandwidth *= 1000; - cpi->oxcf.starting_buffer_level = - rescale(cpi->oxcf.starting_buffer_level, - cpi->oxcf.target_bandwidth, 1000); + cpi->oxcf.starting_buffer_level = rescale(cpi->oxcf.starting_buffer_level, + cpi->oxcf.target_bandwidth, 1000); // Set or reset optimal and maximum buffer levels. if (cpi->oxcf.optimal_buffer_level == 0) cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; else - cpi->oxcf.optimal_buffer_level = - rescale(cpi->oxcf.optimal_buffer_level, - cpi->oxcf.target_bandwidth, 1000); + cpi->oxcf.optimal_buffer_level = rescale(cpi->oxcf.optimal_buffer_level, + cpi->oxcf.target_bandwidth, 1000); if (cpi->oxcf.maximum_buffer_size == 0) cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; else - cpi->oxcf.maximum_buffer_size = - rescale(cpi->oxcf.maximum_buffer_size, - cpi->oxcf.target_bandwidth, 1000); + cpi->oxcf.maximum_buffer_size = rescale(cpi->oxcf.maximum_buffer_size, + cpi->oxcf.target_bandwidth, 1000); // Set up frame rate and related parameters rate control values. vp9_new_frame_rate(cpi, cpi->oxcf.frame_rate); // Set absolute upper and lower quality limits - cpi->worst_quality = cpi->oxcf.worst_allowed_q; - cpi->best_quality = cpi->oxcf.best_allowed_q; + cpi->worst_quality = cpi->oxcf.worst_allowed_q; + cpi->best_quality = cpi->oxcf.best_allowed_q; // active values should only be modified if out of new range if (cpi->active_worst_quality > cpi->oxcf.worst_allowed_q) { @@ -1356,30 +1334,30 @@ static void cal_nmvjointsadcost(int *mvjointsadcost) { static void cal_nmvsadcosts(int *mvsadcost[2]) { int i = 1; - mvsadcost [0] [0] = 0; - mvsadcost [1] [0] = 0; + mvsadcost[0][0] = 0; + mvsadcost[1][0] = 0; do { double z = 256 * (2 * (log2f(8 * i) + .6)); - mvsadcost [0][i] = (int) z; - mvsadcost [1][i] = (int) z; - mvsadcost [0][-i] = (int) z; - mvsadcost [1][-i] = (int) z; + mvsadcost[0][i] = (int)z; + mvsadcost[1][i] = (int)z; + mvsadcost[0][-i] = (int)z; + mvsadcost[1][-i] = (int)z; } while (++i <= MV_MAX); } static void cal_nmvsadcosts_hp(int *mvsadcost[2]) { int i = 1; - mvsadcost [0] [0] = 0; - mvsadcost [1] [0] = 0; + mvsadcost[0][0] = 0; + mvsadcost[1][0] = 0; do { double z = 256 * (2 * (log2f(8 * i) + .6)); - mvsadcost [0][i] = (int) z; - mvsadcost [1][i] = (int) z; - mvsadcost [0][-i] = (int) z; - mvsadcost [1][-i] = (int) z; + mvsadcost[0][i] = (int)z; + mvsadcost[1][i] = (int)z; + mvsadcost[0][-i] = (int)z; + mvsadcost[1][-i] = (int)z; } while (++i <= MV_MAX); } @@ -2920,7 +2898,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, #if CONFIG_POSTPROC if (cpi->oxcf.noise_sensitivity > 0) { - uint8_t *src; int l = 0; switch (cpi->oxcf.noise_sensitivity) { @@ -2934,7 +2911,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, l = 60; break; case 4: - case 5: l = 100; break; @@ -2943,18 +2919,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, break; } - - if (cm->frame_type == KEY_FRAME) { - vp9_de_noise(cpi->Source, cpi->Source, l, 1, 0); - } else { - vp9_de_noise(cpi->Source, cpi->Source, l, 1, 0); - - src = cpi->Source->y_buffer; - - if (cpi->Source->y_stride < 0) { - src += cpi->Source->y_stride * (cpi->Source->y_height - 1); - } - } + vp9_denoise(cpi->Source, cpi->Source, l, 1, 0); } #endif @@ -3189,12 +3154,9 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, } // Clamp Q to upper and lower limits: - if (Q > q_high) - Q = q_high; - else if (Q < q_low) - Q = q_low; + Q = clamp(Q, q_low, q_high); - Loop = ((Q != last_q)) ? TRUE : FALSE; + Loop = Q != last_q; } else Loop = FALSE; @@ -4156,16 +4118,17 @@ int vp9_set_internal_size(VP9_PTR comp, int vp9_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest) { int i, j; - int Total = 0; + int total = 0; uint8_t *src = source->y_buffer; uint8_t *dst = dest->y_buffer; - // Loop through the Y plane raw and reconstruction data summing (square differences) + // Loop through the Y plane raw and reconstruction data summing + // (square differences) for (i = 0; i < source->y_height; i += 16) { for (j = 0; j < source->y_width; j += 16) { unsigned int sse; - Total += vp9_mse16x16(src + j, source->y_stride, dst + j, dest->y_stride, + total += vp9_mse16x16(src + j, source->y_stride, dst + j, dest->y_stride, &sse); } @@ -4173,7 +4136,7 @@ int vp9_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest) { dst += 16 * dest->y_stride; } - return Total; + return total; } -- cgit v1.2.3