diff --git a/mpp/codec/enc/vp8/vp8e_api_v2.c b/mpp/codec/enc/vp8/vp8e_api_v2.c index 09061f35..d775ba79 100644 --- a/mpp/codec/enc/vp8/vp8e_api_v2.c +++ b/mpp/codec/enc/vp8/vp8e_api_v2.c @@ -77,7 +77,9 @@ static MPP_RET vp8e_init(void *ctx, EncImplCfg *ctrl_cfg) prep->ver_stride = 720; prep->format = MPP_FMT_YUV420SP; prep->rotation = MPP_ENC_ROT_0; + prep->rotation_ext = MPP_ENC_ROT_0; prep->mirroring = 0; + prep->mirroring_ext = 0; prep->denoise = 0; /* @@ -158,21 +160,8 @@ static MPP_RET vp8e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) mpp_assert(change); if (change) { - if (change & MPP_ENC_PREP_CFG_CHANGE_INPUT) { - if ((src->width < 0 || src->width > 1920) || - (src->height < 0 || src->height > 3840) || - (src->hor_stride < 0 || src->hor_stride > 7680) || - (src->ver_stride < 0 || src->ver_stride > 3840)) { - mpp_err("invalid input w:h [%d:%d] [%d:%d]\n", - src->width, src->height, - src->hor_stride, src->ver_stride); - ret = MPP_NOK; - } - dst->width = src->width; - dst->height = src->height; - dst->ver_stride = src->ver_stride; - dst->hor_stride = src->hor_stride; - } + RK_S32 mirroring; + RK_S32 rotation; if (change & MPP_ENC_PREP_CFG_CHANGE_FORMAT) { if ((src->format < MPP_FRAME_FMT_RGB && @@ -183,7 +172,76 @@ static MPP_RET vp8e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) } dst->format = src->format; } + + if (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION) + dst->rotation_ext = src->rotation_ext; + + if (change & MPP_ENC_PREP_CFG_CHANGE_MIRRORING) + dst->mirroring_ext = src->mirroring_ext; + + if (change & MPP_ENC_PREP_CFG_CHANGE_FLIP) + dst->flip = src->flip; + + // parameter checking + if (dst->rotation_ext >= MPP_ENC_ROT_BUTT || dst->rotation_ext < 0 || + dst->mirroring_ext < 0 || dst->flip < 0) { + mpp_err("invalid trans: rotation %d, mirroring %d\n", dst->rotation_ext, dst->mirroring_ext); + ret = MPP_ERR_VALUE; + } + + rotation = dst->rotation_ext; + mirroring = dst->mirroring_ext; + + if (dst->flip) { + mirroring = !mirroring; + rotation += MPP_ENC_ROT_180; + rotation &= MPP_ENC_ROT_270; + } + + dst->mirroring = mirroring; + dst->rotation = rotation; + + /* vp8 encoder do not have denoise/sharpen feature */ + + if (change & MPP_ENC_PREP_CFG_CHANGE_INPUT || + (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION)) { + if ((src->width < 0 || src->width > 1920) || + (src->height < 0 || src->height > 3840) || + (src->hor_stride < 0 || src->hor_stride > 7680) || + (src->ver_stride < 0 || src->ver_stride > 3840)) { + mpp_err("invalid input w:h [%d:%d] [%d:%d]\n", + src->width, src->height, + src->hor_stride, src->ver_stride); + ret = MPP_NOK; + } + + if (dst->rotation == MPP_ENC_ROT_90 || dst->rotation == MPP_ENC_ROT_270) { + dst->width = src->height; + dst->height = src->width; + } else { + dst->width = src->width; + dst->height = src->height; + } + dst->ver_stride = src->ver_stride; + dst->hor_stride = src->hor_stride; + } + dst->change |= src->change; + + if (dst->rotation == MPP_ENC_ROT_90 || dst->rotation == MPP_ENC_ROT_270) { + if (dst->height > dst->hor_stride || dst->width > dst->ver_stride) { + mpp_err("invalid size w:h [%d:%d] stride [%d:%d]\n", + dst->width, dst->height, dst->hor_stride, dst->ver_stride); + ret = MPP_ERR_VALUE; + } + } else { + if (dst->width > dst->hor_stride || dst->height > dst->ver_stride) { + mpp_err("invalid size w:h [%d:%d] stride [%d:%d]\n", + dst->width, dst->height, dst->hor_stride, dst->ver_stride); + ret = MPP_ERR_VALUE; + } + } + vp8e_dbg_cfg("width %d height %d hor_stride %d ver_srtride %d format 0x%x\n", dst->width, dst->height, dst->hor_stride, dst->ver_stride, dst->format); } diff --git a/mpp/hal/vpu/vp8e/hal_vp8e_base.c b/mpp/hal/vpu/vp8e/hal_vp8e_base.c index cba70b9c..80f1a905 100644 --- a/mpp/hal/vpu/vp8e/hal_vp8e_base.c +++ b/mpp/hal/vpu/vp8e/hal_vp8e_base.c @@ -26,7 +26,6 @@ #include "hal_vp8e_putbit.h" #include "hal_vp8e_table.h" #include "hal_vp8e_debug.h" -#include "vepu_common.h" static MPP_RET set_frame_params(void *hal) { @@ -862,6 +861,10 @@ static MPP_RET set_frame_tag(void *hal) HalVp8ePicBuf *pic_buf = &ctx->picbuf; HalVp8eRefPic *cur_pic = pic_buf->cur_pic; Vp8ePutBitBuf *bitbuf = &ctx->bitbuf[0]; + RK_S32 pic_height_in_pixel; + RK_S32 pic_width_in_pixel; + RK_S32 h_scaling; + RK_S32 v_scaling; tmp = ((ctx->bitbuf[1].byte_cnt) << 5) | ((cur_pic->show ? 1 : 0) << 4) | @@ -881,11 +884,23 @@ static MPP_RET set_frame_tag(void *hal) vp8e_put_byte(bitbuf, 0x01); vp8e_put_byte(bitbuf, 0x2a); - tmp = ctx->sps.pic_width_in_pixel | (ctx->sps.horizontal_scaling << 14); + if (ctx->hw_cfg.input_rotation) { + pic_height_in_pixel = ctx->sps.pic_width_in_pixel; + pic_width_in_pixel = ctx->sps.pic_height_in_pixel; + h_scaling = ctx->sps.vertical_scaling; + v_scaling = ctx->sps.horizontal_scaling; + } else { + pic_height_in_pixel = ctx->sps.pic_height_in_pixel; + pic_width_in_pixel = ctx->sps.pic_width_in_pixel; + h_scaling = ctx->sps.horizontal_scaling; + v_scaling = ctx->sps.vertical_scaling; + } + + tmp = pic_width_in_pixel | (h_scaling << 14); vp8e_put_byte(bitbuf, tmp & 0xff); vp8e_put_byte(bitbuf, tmp >> 8); - tmp = ctx->sps.pic_height_in_pixel | (ctx->sps.vertical_scaling << 14); + tmp = pic_height_in_pixel | (v_scaling << 14); vp8e_put_byte(bitbuf, tmp & 0xff); vp8e_put_byte(bitbuf, tmp >> 8); @@ -967,20 +982,40 @@ static MPP_RET set_parameter(void *hal) Vp8eHwCfg *hw_cfg = &ctx->hw_cfg; MppEncPrepCfg *set = &ctx->cfg->prep; - RK_S32 width = 16 * ((set->width + 15) / 16); - RK_S32 height = 16 * ((set->height + 15) / 16); - RK_U32 stride = MPP_ALIGN(width, 16); + RK_S32 width = set->width; + RK_S32 height = set->height; + RK_S32 width_align = MPP_ALIGN(set->width, 16); + RK_S32 height_align = MPP_ALIGN(set->height, 16); + RK_U32 stride; + RK_U32 rotation = 0; - //TODO handle rotation + // do not support mirroring + if (set->mirroring) + mpp_err_f("Warning: do not support mirroring\n"); - ctx->mb_per_frame = width / 16 * height / 16; - ctx->mb_per_row = width / 16; - ctx->mb_per_col = height / 16; + if (set->rotation == MPP_ENC_ROT_90) + rotation = 1; + else if (set->rotation == MPP_ENC_ROT_270) + rotation = 2; + else if (set->rotation != MPP_ENC_ROT_0) + mpp_err_f("Warning: only support 90 or 270 degree rotate, request rotate %d", rotation); - sps->pic_width_in_pixel = width; - sps->pic_height_in_pixel = height; - sps->pic_width_in_mbs = width / 16; - sps->pic_height_in_mbs = height / 16; + if (rotation) { + MPP_SWAP(RK_S32, width, height); + MPP_SWAP(RK_S32, width_align, height_align); + } + + stride = get_vepu_pixel_stride(&ctx->stride_cfg, width, + set->hor_stride, set->format); + + ctx->mb_per_frame = width_align / 16 * height_align / 16; + ctx->mb_per_row = width_align / 16; + ctx->mb_per_col = height_align / 16; + + sps->pic_width_in_pixel = width_align; + sps->pic_height_in_pixel = height_align; + sps->pic_width_in_mbs = width_align / 16; + sps->pic_height_in_mbs = height_align / 16; sps->horizontal_scaling = 0; sps->vertical_scaling = 0; sps->color_type = 0; @@ -1002,7 +1037,7 @@ static MPP_RET set_parameter(void *hal) memset(sps->ref_delta, 0, sizeof(sps->ref_delta)); memset(sps->mode_delta, 0, sizeof(sps->mode_delta)); - hw_cfg->input_rotation = set->rotation; + hw_cfg->input_rotation = rotation; { RK_U32 tmp = 0; @@ -1062,17 +1097,17 @@ static MPP_RET set_parameter(void *hal) hw_cfg->vs_next_luma_base += (tmp & (~7)); } - hw_cfg->mbs_in_row = (set->width + 15) / 16; - hw_cfg->mbs_in_col = (set->height + 15) / 16; + hw_cfg->mbs_in_row = width_align / 16; + hw_cfg->mbs_in_col = height_align / 16; hw_cfg->pixels_on_row = stride; } - if (set->width & 0x0F) - hw_cfg->x_fill = (16 - (set->width & 0x0F)) / 4; + if (width & 0x0F) + hw_cfg->x_fill = (16 - (width & 0x0F)) / 4; else hw_cfg->x_fill = 0; - if (set->height & 0x0F) - hw_cfg->y_fill = 16 - (set->height & 0x0F); + if (height & 0x0F) + hw_cfg->y_fill = 16 - (height & 0x0F); else hw_cfg->y_fill = 0; diff --git a/mpp/hal/vpu/vp8e/hal_vp8e_base.h b/mpp/hal/vpu/vp8e/hal_vp8e_base.h index a661476b..803c60c7 100644 --- a/mpp/hal/vpu/vp8e/hal_vp8e_base.h +++ b/mpp/hal/vpu/vp8e/hal_vp8e_base.h @@ -18,10 +18,10 @@ #define __HAL_VP8E_BASE_H__ #include "mpp_device.h" -#include "hal_enc_task.h" #include "vp8e_syntax.h" - +#include "vepu_common.h" +#include "hal_enc_task.h" #include "hal_vp8e_entropy.h" #define VP8_PROB_COUNT_MV_OFFSET (222) @@ -364,6 +364,7 @@ typedef struct hal_vp8e_ctx_s { RK_U32 mb_per_frame; RK_U32 mb_per_row; RK_U32 mb_per_col; + VepuStrideCfg stride_cfg; } HalVp8eCtx; #ifdef __cplusplus