From c58df3f3f9ca329b9881511cc59f7fa81eb0d278 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Thu, 8 Sep 2016 20:03:14 +0800 Subject: [PATCH] [mpp_enc]: Implement new encoder framework 1. Separate encoder configure to four parts 2. Add Preprocess / OSD / Extra configs 3. Implement mv_info interface Change-Id: I2350a25c9f40b199cee8ef6c75ac6ca099f143c4 Signed-off-by: Herman Chen Signed-off-by: Lin Kesheng --- inc/rk_mpi.h | 63 +---- inc/rk_mpi_cmd.h | 371 ++++++++++++++++++++++++++++ mpp/codec/inc/mpp_controller.h | 1 + mpp/codec/inc/mpp_enc.h | 136 ++++++++++ mpp/codec/mpp_controller.cpp | 4 +- mpp/codec/mpp_enc.cpp | 9 + mpp/hal/inc/hal_task.h | 3 + mpp/hal/rkenc/h264e/hal_h264e_rkv.c | 11 +- mpp/legacy/vpu_api_legacy.cpp | 2 +- test/mpi_enc_test.c | 21 +- 10 files changed, 551 insertions(+), 70 deletions(-) create mode 100644 inc/rk_mpi_cmd.h diff --git a/inc/rk_mpi.h b/inc/rk_mpi.h index af98339f..f1ba44bc 100644 --- a/inc/rk_mpi.h +++ b/inc/rk_mpi.h @@ -18,6 +18,7 @@ #define __RK_MPI_H__ #include "mpp_task.h" +#include "rk_mpi_cmd.h" typedef enum { MPP_CTX_DEC, @@ -59,68 +60,6 @@ typedef enum { MPP_VIDEO_CodingMax = 0x7FFFFFFF } MppCodingType; -/* - * Command id bit usage is defined as follows: - * bit 20 - 23 - module id - * bit 16 - 19 - contex id - * bit 0 - 15 - command id - */ -#define CMD_MODULE_ID_MASK (0x00F00000) -#define CMD_MODULE_OSAL (0x00100000) -#define CMD_MODULE_MPP (0x00200000) -#define CMD_MODULE_CODEC (0x00300000) -#define CMD_MODULE_HAL (0x00400000) -#define CMD_CTX_ID_MASK (0x000F0000) -#define CMD_CTX_ID_DEC (0x00010000) -#define CMD_CTX_ID_ENC (0x00020000) -#define CMD_CTX_ID_ISP (0x00030000) -#define CMD_ID_MASK (0x0000FFFF) - -typedef enum { - MPP_OSAL_CMD_BASE = CMD_MODULE_OSAL, - MPP_OSAL_CMD_END, - - MPP_CMD_BASE = CMD_MODULE_MPP, - MPP_ENABLE_DEINTERLACE, - MPP_SET_INPUT_BLOCK, - MPP_SET_OUTPUT_BLOCK, - MPP_CMD_END, - - MPP_CODEC_CMD_BASE = CMD_MODULE_CODEC, - MPP_CODEC_GET_FRAME_INFO, - MPP_CODEC_CMD_END, - - MPP_DEC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_DEC, - MPP_DEC_SET_FRAME_INFO, /* vpu api legacy control for buffer slot dimension init */ - MPP_DEC_SET_EXT_BUF_GROUP, /* IMPORTANT: set external buffer group to mpp decoder */ - MPP_DEC_SET_INFO_CHANGE_READY, - MPP_DEC_SET_INTERNAL_PTS_ENABLE, - MPP_DEC_SET_PARSER_SPLIT_MODE, /* Need to setup before init */ - MPP_DEC_SET_PARSER_FAST_MODE, /* Need to setup before init */ - MPP_DEC_GET_STREAM_COUNT, - MPP_DEC_GET_VPUMEM_USED_COUNT, - MPP_DEC_SET_VC1_EXTRA_DATA, - MPP_DEC_SET_OUTPUT_FORMAT, - MPP_DEC_CMD_END, - - MPP_ENC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ENC, - MPP_ENC_SET_CFG, - MPP_ENC_GET_CFG, - MPP_ENC_SET_EXTRA_INFO, - MPP_ENC_GET_EXTRA_INFO, - MPP_ENC_SET_FORMAT, - MPP_ENC_SET_IDR_FRAME, - MPP_ENC_CMD_END, - - MPP_ISP_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ISP, - MPP_ISP_CMD_END, - - MPP_HAL_CMD_BASE = CMD_MODULE_HAL, - MPP_HAL_CMD_END, - - MPI_CMD_BUTT, -} MpiCmd; - typedef void* MppCtx; typedef void* MppParam; diff --git a/inc/rk_mpi_cmd.h b/inc/rk_mpi_cmd.h new file mode 100644 index 00000000..bc24fbfe --- /dev/null +++ b/inc/rk_mpi_cmd.h @@ -0,0 +1,371 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __RK_MPI_CMD_H__ +#define __RK_MPI_CMD_H__ + +#include "rk_type.h" + +/* + * Command id bit usage is defined as follows: + * bit 20 - 23 - module id + * bit 16 - 19 - contex id + * bit 0 - 15 - command id + */ +#define CMD_MODULE_ID_MASK (0x00F00000) +#define CMD_MODULE_OSAL (0x00100000) +#define CMD_MODULE_MPP (0x00200000) +#define CMD_MODULE_CODEC (0x00300000) +#define CMD_MODULE_HAL (0x00400000) +#define CMD_CTX_ID_MASK (0x000F0000) +#define CMD_CTX_ID_DEC (0x00010000) +#define CMD_CTX_ID_ENC (0x00020000) +#define CMD_CTX_ID_ISP (0x00030000) +#define CMD_ID_MASK (0x0000FFFF) + +typedef enum { + MPP_OSAL_CMD_BASE = CMD_MODULE_OSAL, + MPP_OSAL_CMD_END, + + MPP_CMD_BASE = CMD_MODULE_MPP, + MPP_ENABLE_DEINTERLACE, + MPP_SET_INPUT_BLOCK, + MPP_SET_OUTPUT_BLOCK, + MPP_CMD_END, + + MPP_CODEC_CMD_BASE = CMD_MODULE_CODEC, + MPP_CODEC_GET_FRAME_INFO, + MPP_CODEC_CMD_END, + + MPP_DEC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_DEC, + MPP_DEC_SET_FRAME_INFO, /* vpu api legacy control for buffer slot dimension init */ + MPP_DEC_SET_EXT_BUF_GROUP, /* IMPORTANT: set external buffer group to mpp decoder */ + MPP_DEC_SET_INFO_CHANGE_READY, + MPP_DEC_SET_INTERNAL_PTS_ENABLE, + MPP_DEC_SET_PARSER_SPLIT_MODE, /* Need to setup before init */ + MPP_DEC_SET_PARSER_FAST_MODE, /* Need to setup before init */ + MPP_DEC_GET_STREAM_COUNT, + MPP_DEC_GET_VPUMEM_USED_COUNT, + MPP_DEC_SET_VC1_EXTRA_DATA, + MPP_DEC_SET_OUTPUT_FORMAT, + MPP_DEC_CMD_END, + + MPP_ENC_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ENC, + MPP_ENC_SET_RC_CFG, + MPP_ENC_GET_RC_CFG, + MPP_ENC_SET_PREP_CFG, + MPP_ENC_GET_PREP_CFG, + MPP_ENC_SET_OSD_CFG, + MPP_ENC_GET_OSD_CFG, + MPP_ENC_SET_CFG, + MPP_ENC_GET_CFG, + MPP_ENC_SET_EXTRA_INFO, + MPP_ENC_GET_EXTRA_INFO, + MPP_ENC_SET_FORMAT, + MPP_ENC_SET_IDR_FRAME, + MPP_ENC_CMD_END, + + MPP_ISP_CMD_BASE = CMD_MODULE_CODEC | CMD_CTX_ID_ISP, + MPP_ISP_CMD_END, + + MPP_HAL_CMD_BASE = CMD_MODULE_HAL, + MPP_HAL_CMD_END, + + MPI_CMD_BUTT, +} MpiCmd; + +/* + * Configure of encoder is separated into four parts. + * + * 1. Rate control parameter + * This is quality and bitrate request from user. + * For controller only + * + * 2. Data source MppFrame parameter + * This is data source buffer information. + * For both controller and hal + * + * 3. Video codec infomation + * This is user custormized stream information. + * For hal only + * + * 4. Extra parameter + * including: + * PreP : encoder Preprocess configuration + * ROI : Region Of Interest + * OSD : On Screen Display + * MD : Motion Detection + * extra : SEI for h.264 / Exif for mjpeg + * For hal only + * + * The module transcation flow is as follows: + * + * + + + * User | Mpi/Mpp | Controller + * | | Hal + * | | + * +----------+ | +---------+ | +------------+ + * | | | | +-----RcCfg-----> | + * | RcCfg +---------> | | | Controller | + * | | | | | +-Frame-----> | + * +----------+ | | | | | +---+-----^--+ + * | | | | | | | + * | | | | | | | + * +----------+ | | | | | syntax | + * | | | | | | | | | + * | MppFrame +---------> MppEnc +---+ | | result + * | | | | | | | | | + * +----------+ | | | | | | | + * | | | | | +---v-----+--+ + * | | | +-Frame-----> | + * +----------+ | | | | | | + * | | | | +---CodecCfg----> Hal | + * | CodecCfg +---------> | | | | + * | | | | <-----Extra-----> | + * +----------+ | +---------+ | +------------+ + * | | + * | | + * + + + * + * The function call flow is shown below: + * + * mpi mpp_enc controller hal + * + + + + + * | | | | + * | | | | + * +----------init------------> | | + * | | | | + * | | | | + * | MppFrame | | | + * +---------control----------> MppFrame | | + * | +-----control-----> | + * | | | MppFrame | + * | +--------------------------control--------> + * | | | allocate + * | | | buffer + * | | | | + * | RcCfg | | | + * +---------control----------> RcCfg | | + * | +-----control-----> | + * | | rc_init | + * | | | | + * | | | | + * | CodecCfg | | | + * +---------control----------> | CodecCfg | + * | +--------------------------control--------> + * | | | generate + * | | | sps/pps + * | | | Get extra info | + * | +--------------------------control--------> + * | Get extra info | | | + * +---------control----------> | | + * | | | | + * | | | | + * | PrepCfg | | | + * +---------control----------> | PrepCfg | + * | +--------------------------control--------> + * | | | | + * | ROICfg | | | + * +---------control----------> | ROICfg | + * | +--------------------------control--------> + * | | | | + * | OSDCfg | | | + * +---------control----------> | OSDCfg | + * | +--------------------------control--------> + * | | | | + * | MDCfg | | | + * +---------control----------> | MDCfg | + * | +--------------------------control--------> + * | | | | + * | Set extra info | | | + * +---------control----------> | Set extra info | + * | +--------------------------control--------> + * | | | | + * | task | | | + * +----------encode----------> task | | + * | +-----encode------> | + * | | encode | + * | | | syntax | + * | +--------------------------gen_reg--------> + * | | | | + * | | | | + * | +---------------------------start---------> + * | | | | + * | | | | + * | +---------------------------wait----------> + * | | | | + * | | callback | | + * | +-----------------> | + * +--OSD-MD--encode----------> | | + * | . | | | + * | . | | | + * | . | | | + * +--OSD-MD--encode----------> | | + * | | | | + * +----------deinit----------> | | + * + + + + + */ + +/* + * Rate control parameter + * + * rc_mode - rate control mode + * Mpp balances quality and bit rate by the mode index + * Mpp provide 5 level of balance mode of quality and bit rate + * 1 - only quality mode: only quality parameter takes effect + * 2 - more quality mode: quality parameter takes more effect + * 3 - balance mode : balance quality and bitrate 50 to 50 + * 4 - more bitrate mode: bitrate parameter takes more effect + * 5 - only bitrate mode: only bitrate parameter takes effect + * + * quality - quality parameter + * mpp does not give the direct parameter in different protocol. + * mpp provide total 5 quality level 1 ~ 5 + * 0 - auto + * 1 - worst + * 2 - worse + * 3 - medium + * 4 - better + * 5 - best + * + * bit rate parameters + * mpp gives three bit rate control parameter for control + * bps_target - target bit rate, unit: bit per second + * bps_max - maximun bit rate, unit: bit per second + * bps_min - minimun bit rate, unit: bit per second + * if user need constant bit rate set parameters to the similar value + * if user need variable bit rate set parameters as they need + * + * frame rate parameters have great effect on rate control + * all fps parameter is in 32bit + * low 16bit is denominator + * high 16bit is numerator + * if high 16bit is zero then the whole integer is just fps + * fps_in - input frame rate, unit: frame per second + * if 0 then default set to 30 + * fps_out - output frame rate, unit: frame per second + * if 0 then default set to fps_in + * gop - gap between Intra frame + * 0 for only 1 I frame the rest are all P frames + * 1 for all I frame + * 2 for I P I P I P + * 3 for I P P I P P + * etc... + * skip_cnt - max continuous frame skip count + * 0 - frame skip is not allow + * + */ +typedef struct MppEncRcCfg_t { + RK_S32 rc_mode; + RK_S32 quality; + RK_S32 bps_target; + RK_S32 bps_max; + RK_S32 bps_min; + RK_S32 fps_in; + RK_S32 fps_out; + RK_S32 gop; + RK_S32 skip_cnt; +} MppEncRcCfg; + +/* + * Mpp frame parameter + * direct use MppFrame to store information + */ + +/* + * Mpp codec parameter + * parameter is defined in different syntax header + */ + +/* + * Mpp preprocess parameter + */ +typedef struct MppEncPrepCfg_t { + MppFrameFormat format_in; + MppFrameFormat format_out; + RK_U32 rotation; +} MppEncPrepCfg; + +/* + * Mpp ROI parameter + * Region configture define a rectangle as ROI + */ +typedef struct MppEncROIRegion_t { + RK_U16 x; + RK_U16 y; + RK_U16 w; + RK_U16 h; + RK_U16 intra; + RK_U16 quality; +} MppEncROIRegion; + +typedef struct MppEncROICfg_t { + RK_U32 number; + MppEncROIRegion *regions; +} MppEncROICfg; + +/* + * Mpp OSD parameter + * + * Mpp OSD support total 8 regions + * Mpp OSD support 256-color palette two mode palette: + * 1. Configurable OSD palette + * When palette is set. + * 2. fixed OSD palette + * When palette is NULL. + */ +typedef struct MppEncOSDRegion_t { + RK_U16 x; + RK_U16 y; + RK_U16 w; + RK_U16 h; + RK_U8 *data; +} MppEncOSDRegion; + +typedef struct MppEncOSDCfg_t { + RK_U32 number; + RK_U8 *palette; + MppEncOSDRegion *regions; +} MppEncOSDCfg; + +/* + * Mpp Motion Detection parameter + * + * Mpp can output Motion Detection infomation for each frame. + * If user euqueue a encode task with KEY_MOTION_INFO by following function + * then encoder will output Motion Detection information to the buffer. + * + * mpp_task_meta_set_buffer(task, KEY_MOTION_INFO, buffer); + * + * Motion Detection information will be organized in this way: + * 1. Each 16x16 block will have a 32 bit block information which contains + * 15 bit SAD(Sum of Abstract Difference value + * 9 bit signed horizontal motion vector + * 8 bit signed vertical motion vector + * 2. The sequence of MD information in the buffer is corresponding to the + * block position in the frame, left-to right, top-to-bottom. + * 3. If the width of the frame is not a multiple of 256 pixels (16 macro + * blocks), DMA would extend the frame to a multiple of 256 pixels and + * the extended blocks' MD information are 32'h0000_0000. + * 4. Buffer must be ion buffer and 1024 byte aligned. + */ +typedef struct MppEncMDBlkInfo_t { + RK_U32 sad :15; /* bit 0~14 - SAD */ + RK_S32 mvx :9; /* bit 15~23 - signed horizontal mv */ + RK_S32 mvy :8; /* bit 24~31 - signed vertical mv */ +} MppEncMDBlkInfo; + +#endif /*__RK_MPI_CMD_H__*/ diff --git a/mpp/codec/inc/mpp_controller.h b/mpp/codec/inc/mpp_controller.h index fc6d5357..1de894c4 100644 --- a/mpp/codec/inc/mpp_controller.h +++ b/mpp/codec/inc/mpp_controller.h @@ -39,6 +39,7 @@ typedef struct EncTask_t { #ifdef __cplusplus extern "C" { #endif + MPP_RET controller_init(Controller *ctrl, ControllerCfg *cfg); MPP_RET controller_deinit(Controller ctrl); MPP_RET controller_encode(Controller ctrl, HalEncTask *task); diff --git a/mpp/codec/inc/mpp_enc.h b/mpp/codec/inc/mpp_enc.h index 31d45c57..cb8e0c73 100644 --- a/mpp/codec/inc/mpp_enc.h +++ b/mpp/codec/inc/mpp_enc.h @@ -21,6 +21,138 @@ #include "mpp_controller.h" #include "mpp_hal.h" +/* + * Configure of encoder is separated into four parts. + * + * 1. Rate control parameter + * This is quality and bitrate request from user. + * For controller only + * + * 2. Data source MppFrame parameter + * This is data source buffer information. + * For both controller and hal + * + * 3. Video codec infomation + * This is user custormized stream information. + * For hal only + * + * 4. Extra parameter + * including: + * PreP : encoder Preprocess configuration + * ROI : Region Of Interest + * OSD : On Screen Display + * MD : Motion Detection + * extra : SEI for h.264 / Exif for mjpeg + * For hal only + * + * The module transcation flow is as follows: + * + * + + + * User | Mpi/Mpp | Controller + * | | Hal + * | | + * +----------+ | +---------+ | +------------+ + * | | | | +-----RcCfg-----> | + * | RcCfg +---------> | | | Controller | + * | | | | | +-Frame-----> | + * +----------+ | | | | | +---+-----^--+ + * | | | | | | | + * | | | | | | | + * +----------+ | | | | | syntax | + * | | | | | | | | | + * | MppFrame +---------> MppEnc +---+ | | result + * | | | | | | | | | + * +----------+ | | | | | | | + * | | | | | +---v-----+--+ + * | | | +-Frame-----> | + * +----------+ | | | | | | + * | | | | +---CodecCfg----> Hal | + * | CodecCfg +---------> | | | | + * | | | | <-----Extra-----> | + * +----------+ | +---------+ | +------------+ + * | | + * | | + * + + + * + * The function call flow is shown below: + * + * mpi mpp_enc controller hal + * + + + + + * | | | | + * | | | | + * +----------init------------> | | + * | | | | + * | | | | + * | MppFrame | | | + * +---------control----------> MppFrame | | + * | +-----control-----> | + * | | | MppFrame | + * | +--------------------------control--------> + * | | | allocate + * | | | buffer + * | | | | + * | RcCfg | | | + * +---------control----------> RcCfg | | + * | +-----control-----> | + * | | rc_init | + * | | | | + * | | | | + * | CodecCfg | | | + * +---------control----------> | CodecCfg | + * | +--------------------------control--------> + * | | | generate + * | | | sps/pps + * | | | Get extra info | + * | +--------------------------control--------> + * | Get extra info | | | + * +---------control----------> | | + * | | | | + * | | | | + * | PrepCfg | | | + * +---------control----------> | PrepCfg | + * | +--------------------------control--------> + * | | | | + * | ROICfg | | | + * +---------control----------> | ROICfg | + * | +--------------------------control--------> + * | | | | + * | OSDCfg | | | + * +---------control----------> | OSDCfg | + * | +--------------------------control--------> + * | | | | + * | MDCfg | | | + * +---------control----------> | MDCfg | + * | +--------------------------control--------> + * | | | | + * | Set extra info | | | + * +---------control----------> | Set extra info | + * | +--------------------------control--------> + * | | | | + * | task | | | + * +----------encode----------> task | | + * | +-----encode------> | + * | | encode | + * | | | syntax | + * | +--------------------------gen_reg--------> + * | | | | + * | | | | + * | +---------------------------start---------> + * | | | | + * | | | | + * | +---------------------------wait----------> + * | | | | + * | | callback | | + * | +-----------------> | + * +--OSD-MD--encode----------> | | + * | . | | | + * | . | | | + * | . | | | + * +--OSD-MD--encode----------> | | + * | | | | + * +----------deinit----------> | | + * + + + + + */ + typedef struct MppEnc_t MppEnc; struct MppEnc_t { @@ -36,6 +168,10 @@ struct MppEnc_t { RK_U32 reset_flag; void *mpp; + /* Encoder configure set */ + MppEncRcCfg rc_cfg; + MppFrame data_cfg; + /* * configuration parameter to controller and hal */ diff --git a/mpp/codec/mpp_controller.cpp b/mpp/codec/mpp_controller.cpp index ec4baa8d..2931f154 100644 --- a/mpp/codec/mpp_controller.cpp +++ b/mpp/codec/mpp_controller.cpp @@ -25,7 +25,7 @@ #include "mpp_controller.h" /* - * all decoder static register here + * all encoder controller static register here */ static const ControlApi *controllers[] = { #if HAVE_H264E @@ -78,7 +78,7 @@ MPP_RET controller_init(Controller *ctrl, ControllerCfg *cfg) return MPP_ERR_MALLOC; } - MPP_RET ret = api->init(ctx, cfg); // FIXME need to be thinked by lance 2016.05.18 + MPP_RET ret = api->init(ctx, cfg); if (MPP_OK != ret) { mpp_err_f("failed to init controller\n"); mpp_free(p); diff --git a/mpp/codec/mpp_enc.cpp b/mpp/codec/mpp_enc.cpp index 423349a6..fbf4e3fc 100644 --- a/mpp/codec/mpp_enc.cpp +++ b/mpp/codec/mpp_enc.cpp @@ -81,6 +81,7 @@ void *mpp_enc_control_thread(void *data) MPP_RET ret = MPP_OK; MppFrame frame = NULL; MppPacket packet = NULL; + MppBuffer mv_info = NULL; memset(&task_info, 0, sizeof(HalTaskInfo)); @@ -95,6 +96,7 @@ void *mpp_enc_control_thread(void *data) if (mpp_task != NULL) { mpp_task_meta_get_frame (mpp_task, KEY_INPUT_FRAME, &frame); mpp_task_meta_get_packet(mpp_task, KEY_OUTPUT_PACKET, &packet); + mpp_task_meta_get_buffer(mpp_task, KEY_MOTION_INFO, &mv_info); if (NULL == frame) { mpp_port_enqueue(input, mpp_task); @@ -124,6 +126,7 @@ void *mpp_enc_control_thread(void *data) enc_task->input = mpp_frame_get_buffer(frame); enc_task->output = mpp_packet_get_buffer(packet); + enc_task->mv_info = mv_info; controller_encode(mpp->mEnc->controller, enc_task); mpp_hal_reg_gen((mpp->mEnc->hal), &task_info); @@ -420,6 +423,12 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param) case MPP_ENC_GET_EXTRA_INFO : { ret = mpp_hal_control(enc->hal, cmd, param); } break; + case MPP_ENC_SET_RC_CFG : { + ret = mpp_hal_control(enc->hal, cmd, param); + } break; + case MPP_ENC_GET_RC_CFG : { + ret = mpp_hal_control(enc->hal, cmd, param); + } break; default : { } break; } diff --git a/mpp/hal/inc/hal_task.h b/mpp/hal/inc/hal_task.h index 66845f93..1fdb1b36 100644 --- a/mpp/hal/inc/hal_task.h +++ b/mpp/hal/inc/hal_task.h @@ -146,6 +146,9 @@ typedef struct HalEncTask_t { // current tesk input slot buffer MppBuffer input; + // current mv info output buffer + MppBuffer mv_info; + RK_U32 is_intra; HalEncTaskFlag flags; diff --git a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c index c4964c91..c50ec8f7 100644 --- a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c +++ b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c @@ -3074,7 +3074,9 @@ MPP_RET hal_h264e_rkv_gen_regs(void *hal, HalTaskInfo *task) h264e_hal_rkv_buffers *bufs = (h264e_hal_rkv_buffers *)ctx->buffers; RK_U32 mul_buf_idx = ctx->frame_cnt % RKV_H264E_LINKTABLE_FRAME_NUM; RK_U32 buf2_idx = ctx->frame_cnt % 2; - //RK_S32 pic_height_align64 = (syn->pic_luma_height + 63) & (~63); + + MppBuffer mv_info_buf = task->enc.mv_info; + ctx->enc_mode = RKV_H264E_ENC_MODE; h264e_hal_debug_enter(); @@ -3157,7 +3159,6 @@ MPP_RET hal_h264e_rkv_gen_regs(void *hal, HalTaskInfo *task) regs->swreg10.enc_stnd = 0; //H264 regs->swreg10.cur_frm_ref = ((ctx->frame_cnt + 1) % sps->keyframe_max_interval) != 0; //syn->swreg10.cur_frm_ref; //Current frame should be refered in future - regs->swreg10.mei_stor = 0; //syn->swreg10.mei_stor; regs->swreg10.bs_scp = 1; //syn->swreg10.bs_scp; regs->swreg10.slice_int = 0; //syn->swreg10.slice_int; regs->swreg10.node_int = 0; //syn->swreg10.node_int;//node_int_frame_pos @@ -3199,7 +3200,11 @@ MPP_RET hal_h264e_rkv_gen_regs(void *hal, HalTaskInfo *task) if (bufs->hw_dsp_buf[1 - buf2_idx]) regs->swreg35_dspr_addr = mpp_buffer_get_fd(bufs->hw_dsp_buf[1 - buf2_idx]); //syn->addr_cfg.dspr_addr; - regs->swreg36_meiw_addr = 0; //mpp_buffer_get_fd(bufs->hw_mei_buf[mul_buf_idx]); + if(mv_info_buf) { + regs->swreg10.mei_stor = 1; //syn->swreg10.mei_stor; + regs->swreg36_meiw_addr = mpp_buffer_get_fd(mv_info_buf); //mpp_buffer_get_fd(bufs->hw_mei_buf[mul_buf_idx]); + } + regs->swreg38_bsbb_addr = syn->output_strm_addr; if (VPUClientGetIOMMUStatus() > 0) regs->swreg37_bsbt_addr = regs->swreg38_bsbb_addr | (syn->output_strm_limit_size << 10); // TODO: stream size relative with syntax diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index 4ec899d7..d6c347df 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -729,7 +729,7 @@ RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, mpp_err("mpi pointer is NULL, failed!"); } - // copy encoded stream into output buffer, and set outpub stream size + // copy encoded stream into output buffer, and set output stream size if (packet != NULL) { RK_U32 eos = mpp_packet_get_eos(packet); RK_S64 pts = mpp_packet_get_pts(packet); diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index 27da441b..078b982d 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -140,6 +140,7 @@ int mpi_enc_test(MpiEncTestCmd *cmd) MppPacket packet = NULL; MppBuffer frm_buf[MPI_ENC_IO_COUNT] = { NULL }; MppBuffer pkt_buf[MPI_ENC_IO_COUNT] = { NULL }; + MppBuffer md_buf[MPI_ENC_IO_COUNT] = { NULL }; // paramter for resource malloc RK_U32 width = cmd->width; @@ -151,7 +152,10 @@ int mpi_enc_test(MpiEncTestCmd *cmd) // resources size_t frame_size = hor_stride * ver_stride * 3 / 2; - size_t packet_size = width * height; /* NOTE: packet buffer may overflow */ + /* NOTE: packet buffer may overflow */ + size_t packet_size = width * height; + /* 32 for each 16x16 block */ + size_t mdinfo_size = (((hor_stride + 255)&(~255))/16) * (ver_stride / 16) * 4; //NOTE: hor_stride should be 16-MB aligned size_t read_size = 0; RK_U32 frame_count = 0; RK_U64 stream_size = 0; @@ -199,6 +203,12 @@ int mpi_enc_test(MpiEncTestCmd *cmd) mpp_err("failed to get buffer for input frame ret %d\n", ret); goto MPP_TEST_OUT; } + + ret = mpp_buffer_get(pkt_grp, &md_buf[i], mdinfo_size); + if (ret) { + mpp_err("failed to get buffer for motion detection info ret %d\n", ret); + goto MPP_TEST_OUT; + } } mpp_log("mpi_enc_test encoder test start w %d h %d type %d\n", width, height, type); @@ -276,6 +286,7 @@ int mpi_enc_test(MpiEncTestCmd *cmd) RK_S32 index = i++; MppBuffer frm_buf_in = frm_buf[index]; MppBuffer pkt_buf_out = pkt_buf[index]; + MppBuffer md_info_buf = md_buf[index]; void *buf = mpp_buffer_get_ptr(frm_buf_in); if (i == MPI_ENC_IO_COUNT) @@ -310,7 +321,7 @@ int mpi_enc_test(MpiEncTestCmd *cmd) } else { MppFrame frame_out = NULL; - mpp_task_meta_get_frame (task, KEY_INPUT_FRAME, &frame_out); + mpp_task_meta_get_frame(task, KEY_INPUT_FRAME, &frame_out); if (frame_out) mpp_assert(frame_out == frame); @@ -321,6 +332,7 @@ int mpi_enc_test(MpiEncTestCmd *cmd) mpp_task_meta_set_frame (task, KEY_INPUT_FRAME, frame); mpp_task_meta_set_packet(task, KEY_OUTPUT_PACKET, packet); + mpp_task_meta_set_buffer(task, KEY_MOTION_INFO, md_info_buf); ret = mpi->enqueue(ctx, MPP_PORT_INPUT, task); if (ret) { @@ -405,6 +417,11 @@ MPP_TEST_OUT: mpp_buffer_put(pkt_buf[i]); pkt_buf[i] = NULL; } + + if (md_buf[i]) { + mpp_buffer_put(md_buf[i]); + md_buf[i] = NULL; + } } if (frm_grp) {