From b5337a0b651713f11575340fbb2b40f4a749e81a Mon Sep 17 00:00:00 2001 From: Chih-Yu Huang <akahuang@google.com> Date: Wed, 7 Mar 2018 11:45:43 +0900 Subject: [PATCH] Rockchip: Fix frame crop offset in H264 encoder. According to H.264 spec, when frame_mbs_only_flag is set to 1, frame_crop_bottom_offset should be (pic_height_in_map_units * 16 - height) / 2. Take 1920x1080 video for example, the value is: - height = 1080 - pic_height_in_map_units = ((1080 + 15) >> 4) = 68 - frame_crop_bottom_offset = (68 * 16 - 1080) / 2 = 4 This CL fixed the value by adding the missing "divided by 2". BUG=b:74214155 TEST=Run VideoEncoderDecoderTest#testAvcOther0Qual1920x1080 at device Change-Id: I7c70564553c9e9d62b11100e214a02bba7cbb740 Reviewed-on: https://chromium-review.googlesource.com/952584 Commit-Ready: Chih-Yu Huang <akahuang@chromium.org> Tested-by: Chih-Yu Huang <akahuang@chromium.org> Reviewed-by: Tomasz Figa <tfiga@chromium.org> --- libv4l-rockchip_v2/libvepu/h264e/h264e.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libv4l-rockchip_v2/libvepu/h264e/h264e.c b/libv4l-rockchip_v2/libvepu/h264e/h264e.c index 2976513..48047de 100644 --- a/libv4l-rockchip_v2/libvepu/h264e/h264e.c +++ b/libv4l-rockchip_v2/libvepu/h264e/h264e.c @@ -412,11 +412,14 @@ static int h264e_init(struct rk_venc *ictx, if (ctx->width != ctx->sps.pic_width_in_mbs * 16 || ctx->height != ctx->sps.pic_height_in_map_units * 16) { + assert(ctx->sps.frame_mbs_only_flag == 1); + assert(ctx->width % 2 == 0 && ctx->height % 2 == 0); ctx->sps.frame_cropping_flag = 1; ctx->sps.frame_crop_right_offset = - ctx->sps.pic_width_in_mbs * 16 - ctx->width; + (ctx->sps.pic_width_in_mbs * 16 - ctx->width) >> 1; ctx->sps.frame_crop_bottom_offset = - ctx->sps.pic_height_in_map_units * 16 - ctx->height; + (ctx->sps.pic_height_in_map_units * 16 - ctx->height) + >> 1; } h264e_init_rc(ictx); -- GitLab