mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-18 15:10:39 +08:00
[hal_vp8e]: Add rotation function.
Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com> Change-Id: Ifdb42a8f2858e239b57fe6a8b37e7986bb2e5e9d
This commit is contained in:
@@ -77,7 +77,9 @@ static MPP_RET vp8e_init(void *ctx, EncImplCfg *ctrl_cfg)
|
|||||||
prep->ver_stride = 720;
|
prep->ver_stride = 720;
|
||||||
prep->format = MPP_FMT_YUV420SP;
|
prep->format = MPP_FMT_YUV420SP;
|
||||||
prep->rotation = MPP_ENC_ROT_0;
|
prep->rotation = MPP_ENC_ROT_0;
|
||||||
|
prep->rotation_ext = MPP_ENC_ROT_0;
|
||||||
prep->mirroring = 0;
|
prep->mirroring = 0;
|
||||||
|
prep->mirroring_ext = 0;
|
||||||
prep->denoise = 0;
|
prep->denoise = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -158,21 +160,8 @@ static MPP_RET vp8e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src)
|
|||||||
|
|
||||||
mpp_assert(change);
|
mpp_assert(change);
|
||||||
if (change) {
|
if (change) {
|
||||||
if (change & MPP_ENC_PREP_CFG_CHANGE_INPUT) {
|
RK_S32 mirroring;
|
||||||
if ((src->width < 0 || src->width > 1920) ||
|
RK_S32 rotation;
|
||||||
(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (change & MPP_ENC_PREP_CFG_CHANGE_FORMAT) {
|
if (change & MPP_ENC_PREP_CFG_CHANGE_FORMAT) {
|
||||||
if ((src->format < MPP_FRAME_FMT_RGB &&
|
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;
|
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;
|
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",
|
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);
|
dst->width, dst->height, dst->hor_stride, dst->ver_stride, dst->format);
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#include "hal_vp8e_putbit.h"
|
#include "hal_vp8e_putbit.h"
|
||||||
#include "hal_vp8e_table.h"
|
#include "hal_vp8e_table.h"
|
||||||
#include "hal_vp8e_debug.h"
|
#include "hal_vp8e_debug.h"
|
||||||
#include "vepu_common.h"
|
|
||||||
|
|
||||||
static MPP_RET set_frame_params(void *hal)
|
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;
|
HalVp8ePicBuf *pic_buf = &ctx->picbuf;
|
||||||
HalVp8eRefPic *cur_pic = pic_buf->cur_pic;
|
HalVp8eRefPic *cur_pic = pic_buf->cur_pic;
|
||||||
Vp8ePutBitBuf *bitbuf = &ctx->bitbuf[0];
|
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) |
|
tmp = ((ctx->bitbuf[1].byte_cnt) << 5) |
|
||||||
((cur_pic->show ? 1 : 0) << 4) |
|
((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, 0x01);
|
||||||
vp8e_put_byte(bitbuf, 0x2a);
|
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 & 0xff);
|
||||||
vp8e_put_byte(bitbuf, tmp >> 8);
|
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 & 0xff);
|
||||||
vp8e_put_byte(bitbuf, tmp >> 8);
|
vp8e_put_byte(bitbuf, tmp >> 8);
|
||||||
|
|
||||||
@@ -967,20 +982,40 @@ static MPP_RET set_parameter(void *hal)
|
|||||||
Vp8eHwCfg *hw_cfg = &ctx->hw_cfg;
|
Vp8eHwCfg *hw_cfg = &ctx->hw_cfg;
|
||||||
MppEncPrepCfg *set = &ctx->cfg->prep;
|
MppEncPrepCfg *set = &ctx->cfg->prep;
|
||||||
|
|
||||||
RK_S32 width = 16 * ((set->width + 15) / 16);
|
RK_S32 width = set->width;
|
||||||
RK_S32 height = 16 * ((set->height + 15) / 16);
|
RK_S32 height = set->height;
|
||||||
RK_U32 stride = MPP_ALIGN(width, 16);
|
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;
|
if (set->rotation == MPP_ENC_ROT_90)
|
||||||
ctx->mb_per_row = width / 16;
|
rotation = 1;
|
||||||
ctx->mb_per_col = height / 16;
|
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;
|
if (rotation) {
|
||||||
sps->pic_height_in_pixel = height;
|
MPP_SWAP(RK_S32, width, height);
|
||||||
sps->pic_width_in_mbs = width / 16;
|
MPP_SWAP(RK_S32, width_align, height_align);
|
||||||
sps->pic_height_in_mbs = height / 16;
|
}
|
||||||
|
|
||||||
|
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->horizontal_scaling = 0;
|
||||||
sps->vertical_scaling = 0;
|
sps->vertical_scaling = 0;
|
||||||
sps->color_type = 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->ref_delta, 0, sizeof(sps->ref_delta));
|
||||||
memset(sps->mode_delta, 0, sizeof(sps->mode_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;
|
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->vs_next_luma_base += (tmp & (~7));
|
||||||
}
|
}
|
||||||
|
|
||||||
hw_cfg->mbs_in_row = (set->width + 15) / 16;
|
hw_cfg->mbs_in_row = width_align / 16;
|
||||||
hw_cfg->mbs_in_col = (set->height + 15) / 16;
|
hw_cfg->mbs_in_col = height_align / 16;
|
||||||
hw_cfg->pixels_on_row = stride;
|
hw_cfg->pixels_on_row = stride;
|
||||||
}
|
}
|
||||||
if (set->width & 0x0F)
|
if (width & 0x0F)
|
||||||
hw_cfg->x_fill = (16 - (set->width & 0x0F)) / 4;
|
hw_cfg->x_fill = (16 - (width & 0x0F)) / 4;
|
||||||
else
|
else
|
||||||
hw_cfg->x_fill = 0;
|
hw_cfg->x_fill = 0;
|
||||||
|
|
||||||
if (set->height & 0x0F)
|
if (height & 0x0F)
|
||||||
hw_cfg->y_fill = 16 - (set->height & 0x0F);
|
hw_cfg->y_fill = 16 - (height & 0x0F);
|
||||||
else
|
else
|
||||||
hw_cfg->y_fill = 0;
|
hw_cfg->y_fill = 0;
|
||||||
|
|
||||||
|
@@ -18,10 +18,10 @@
|
|||||||
#define __HAL_VP8E_BASE_H__
|
#define __HAL_VP8E_BASE_H__
|
||||||
|
|
||||||
#include "mpp_device.h"
|
#include "mpp_device.h"
|
||||||
#include "hal_enc_task.h"
|
|
||||||
|
|
||||||
#include "vp8e_syntax.h"
|
#include "vp8e_syntax.h"
|
||||||
|
#include "vepu_common.h"
|
||||||
|
#include "hal_enc_task.h"
|
||||||
#include "hal_vp8e_entropy.h"
|
#include "hal_vp8e_entropy.h"
|
||||||
|
|
||||||
#define VP8_PROB_COUNT_MV_OFFSET (222)
|
#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_frame;
|
||||||
RK_U32 mb_per_row;
|
RK_U32 mb_per_row;
|
||||||
RK_U32 mb_per_col;
|
RK_U32 mb_per_col;
|
||||||
|
VepuStrideCfg stride_cfg;
|
||||||
} HalVp8eCtx;
|
} HalVp8eCtx;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Reference in New Issue
Block a user