[mpp_enc]: remove mpp_enc_get_extra_data and mpp_enc_get_extra_data_size function and use control to get sps/pps of H.264 encoder

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1104 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2016-07-27 06:27:32 +00:00
parent 1407f07185
commit abc3e78078
12 changed files with 91 additions and 39 deletions

View File

@@ -263,8 +263,6 @@ MPP_RET mpp_destroy(MppCtx ctx);
// coding type format function // coding type format function
MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding); MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding);
void mpp_show_support_format(); void mpp_show_support_format();
RK_U8 *mpp_enc_get_extra_data(MppCtx ctx);
RK_U32 mpp_enc_get_extra_data_size(MppCtx ctx);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -273,7 +273,7 @@ typedef struct VpuCodecContext {
RK_U32 width; RK_U32 width;
RK_U32 height; RK_U32 height;
RK_U8 *extradata; void *extradata;
RK_S32 extradata_size; RK_S32 extradata_size;
RK_U8 enableparsing; RK_U8 enableparsing;

View File

@@ -36,6 +36,9 @@ struct MppEnc_t {
RK_U32 reset_flag; RK_U32 reset_flag;
void *mpp; void *mpp;
/*
* configuration parameter to controller and hal
*/
H264EncConfig enc_cfg; H264EncConfig enc_cfg;
H264EncRateCtrl enc_rc_cfg; H264EncRateCtrl enc_rc_cfg;
h264e_control_extra_info_cfg extra_info_cfg; h264e_control_extra_info_cfg extra_info_cfg;

View File

@@ -411,7 +411,7 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param)
H264EncRateCtrl *enc_rc_cfg = &(enc->enc_rc_cfg); H264EncRateCtrl *enc_rc_cfg = &(enc->enc_rc_cfg);
switch (cmd) { switch (cmd) {
case MPP_ENC_SET_CFG: case MPP_ENC_SET_CFG : {
//H264ENC_NAL_UNIT_STREAM; // decide whether stream start with start code,e.g."00 00 00 01" //H264ENC_NAL_UNIT_STREAM; // decide whether stream start with start code,e.g."00 00 00 01"
enc_cfg->streamType = H264ENC_BYTE_STREAM; enc_cfg->streamType = H264ENC_BYTE_STREAM;
enc_cfg->frameRateDenom = 1; enc_cfg->frameRateDenom = 1;
@@ -487,11 +487,13 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param)
mpp_extra_info_generate(enc); mpp_extra_info_generate(enc);
mpp_hal_control(enc->hal, MPP_ENC_SET_EXTRA_INFO, (void*)(&(enc->extra_info_cfg))); mpp_hal_control(enc->hal, MPP_ENC_SET_EXTRA_INFO, (void*)(&(enc->extra_info_cfg)));
mpp_hal_control(enc->hal, MPP_ENC_GET_EXTRA_INFO, (void*)(&(enc->extra_info)));
break; } break;
default: case MPP_ENC_GET_EXTRA_INFO : {
break; mpp_hal_control(enc->hal, cmd, param);
} break;
default : {
} break;
} }
return MPP_OK; return MPP_OK;

View File

@@ -20,6 +20,8 @@
#include "vpu.h" #include "vpu.h"
#include "mpp_log.h" #include "mpp_log.h"
#include "mpp_hal.h" #include "mpp_hal.h"
#include "mpp_packet.h"
#include "h264e_syntax.h" #include "h264e_syntax.h"
#define H264E_HAL_LOG_MODE 0x00000111 #define H264E_HAL_LOG_MODE 0x00000111
@@ -301,6 +303,10 @@ typedef struct h264e_hal_context_t {
h264e_hal_param param; h264e_hal_param param;
RK_U32 enc_mode; RK_U32 enc_mode;
void *dump_files; void *dump_files;
void *param_buf;
size_t param_size;
MppPacket packeted_param;
} h264e_hal_context; } h264e_hal_context;
#endif #endif

View File

@@ -22,6 +22,8 @@
#include "hal_h264e.h" #include "hal_h264e.h"
#include "hal_h264e_vpu.h" #include "hal_h264e_vpu.h"
#define H264E_MAX_PACKETED_PARAM_SIZE 256
/* H.264 motion estimation parameters */ /* H.264 motion estimation parameters */
static const RK_U32 h264_prev_mode_favor[52] = { static const RK_U32 h264_prev_mode_favor[52] = {
7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18,
@@ -1555,6 +1557,10 @@ MPP_RET hal_h264e_vpu_init(void *hal, MppHalCfg *cfg)
ctx->buffers = mpp_calloc(h264e_hal_vpu_buffers, 1); ctx->buffers = mpp_calloc(h264e_hal_vpu_buffers, 1);
ctx->extra_info = mpp_calloc(h264e_hal_vpu_extra_info, 1); ctx->extra_info = mpp_calloc(h264e_hal_vpu_extra_info, 1);
ctx->dump_files = mpp_calloc(h264e_hal_vpu_dump_files, 1); ctx->dump_files = mpp_calloc(h264e_hal_vpu_dump_files, 1);
ctx->param_size = H264E_MAX_PACKETED_PARAM_SIZE;
ctx->param_buf = mpp_calloc_size(void, ctx->param_size);
mpp_packet_init(&ctx->packeted_param, ctx->param_buf, ctx->param_size);
hal_h264e_vpu_init_extra_info(ctx->extra_info); hal_h264e_vpu_init_extra_info(ctx->extra_info);
#ifdef H264E_DUMP_DATA_TO_FILE #ifdef H264E_DUMP_DATA_TO_FILE
hal_h264e_vpu_open_dump_files(ctx->dump_files); hal_h264e_vpu_open_dump_files(ctx->dump_files);
@@ -1590,12 +1596,26 @@ MPP_RET hal_h264e_vpu_deinit(void *hal)
{ {
h264e_hal_context *ctx = (h264e_hal_context *)hal; h264e_hal_context *ctx = (h264e_hal_context *)hal;
h264e_hal_debug_enter(); h264e_hal_debug_enter();
MPP_FREE(ctx->regs); MPP_FREE(ctx->regs);
if (ctx->extra_info) { if (ctx->extra_info) {
hal_h264e_vpu_deinit_extra_info(ctx->extra_info); hal_h264e_vpu_deinit_extra_info(ctx->extra_info);
MPP_FREE(ctx->extra_info); MPP_FREE(ctx->extra_info);
} }
if (ctx->packeted_param) {
mpp_packet_deinit(&ctx->packeted_param);
ctx->packeted_param = NULL;
}
if (ctx->param_buf) {
mpp_free(ctx->param_buf);
ctx->param_buf = NULL;
}
ctx->param_size = 0;
if (ctx->buffers) { if (ctx->buffers) {
hal_h264e_vpu_free_buffers(ctx); hal_h264e_vpu_free_buffers(ctx);
MPP_FREE(ctx->buffers); MPP_FREE(ctx->buffers);
@@ -2049,8 +2069,26 @@ MPP_RET hal_h264e_vpu_control(void *hal, RK_S32 cmd_type, void *param)
break; break;
} }
case MPP_ENC_GET_EXTRA_INFO: { case MPP_ENC_GET_EXTRA_INFO: {
hal_h264e_vpu_get_extra_info(param, ctx->extra_info); MppPacket pkt = ctx->packeted_param;
MppPacket *pkt_out = (MppPacket *)param;
h264e_hal_vpu_extra_info *src = (h264e_hal_vpu_extra_info *)ctx->extra_info;
h264e_hal_vpu_stream *sps_stream = &src->sps_stream;
h264e_hal_vpu_stream *pps_stream = &src->pps_stream;
size_t offset = 0;
mpp_packet_write(pkt, offset, sps_stream->buffer, sps_stream->byte_cnt);
offset += sps_stream->byte_cnt;
mpp_packet_write(pkt, offset, pps_stream->buffer, pps_stream->byte_cnt);
offset += pps_stream->byte_cnt;
mpp_packet_set_length(pkt, offset);
*pkt_out = pkt;
#ifdef H264E_DUMP_DATA_TO_FILE #ifdef H264E_DUMP_DATA_TO_FILE
hal_h264e_vpu_get_extra_info(param, ctx->extra_info);
hal_h264e_vpu_dump_mpp_strm_out_header(param, ctx); hal_h264e_vpu_dump_mpp_strm_out_header(param, ctx);
#endif #endif
break; break;
@@ -2063,3 +2101,4 @@ MPP_RET hal_h264e_vpu_control(void *hal, RK_S32 cmd_type, void *param)
h264e_hal_debug_leave(); h264e_hal_debug_leave();
return MPP_OK; return MPP_OK;
} }

View File

@@ -86,11 +86,11 @@ VpuApiLegacy::~VpuApiLegacy()
mpp_free(fp_buf); mpp_free(fp_buf);
fp_buf = NULL; fp_buf = NULL;
} }
if (outData != NULL) { if (outData) {
mpp_free(outData); mpp_free(outData);
outData = NULL; outData = NULL;
} }
if (memGroup != NULL) { if (memGroup) {
mpp_err("memGroup deInit"); mpp_err("memGroup deInit");
mpp_buffer_group_put(memGroup); mpp_buffer_group_put(memGroup);
} }
@@ -186,13 +186,17 @@ RK_S32 VpuApiLegacy::init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_s
mpi->control(mpp_ctx, MPP_ENC_SET_CFG, &mpp_cfg); mpi->control(mpp_ctx, MPP_ENC_SET_CFG, &mpp_cfg);
if (mpp_enc_get_extra_data_size(mpp_ctx) > 0) { mpi->control(mpp_ctx, MPP_ENC_GET_EXTRA_INFO, &pkt);
ctx->extradata_size = mpp_enc_get_extra_data_size(mpp_ctx);
ctx->extradata = mpp_enc_get_extra_data(mpp_ctx); if (pkt) {
ctx->extradata_size = mpp_packet_get_length(pkt);
ctx->extradata = mpp_packet_get_data(pkt);
mpp_log("Mpp generate extra data!"); mpp_log("Mpp generate extra data!");
} else } else {
mpp_err("No extra data generate!"); mpp_err("No extra data generate!");
} }
pkt = NULL;
}
VPU_GENERIC vpug; VPU_GENERIC vpug;
vpug.CodecType = ctx->codecType; vpug.CodecType = ctx->codecType;
@@ -584,7 +588,7 @@ RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm,
aEncOut->timeUs = pts; aEncOut->timeUs = pts;
aEncOut->keyFrame = (flag & MPP_PACKET_FLAG_INTRA) ? (1) : (0); aEncOut->keyFrame = (flag & MPP_PACKET_FLAG_INTRA) ? (1) : (0);
if (!use_fd_flag) { if (!use_fd_flag) {
aEncOut->data = outData; mpp_assert(aEncOut->data);
memcpy(aEncOut->data, (RK_U8*) mpp_buffer_get_ptr(outbufMem), aEncOut->size); memcpy(aEncOut->data, (RK_U8*) mpp_buffer_get_ptr(outbufMem), aEncOut->size);
} }
mpp_buffer_put(outbufMem); mpp_buffer_put(outbufMem);

View File

@@ -460,21 +460,3 @@ void mpp_show_support_format()
} }
} }
RK_U32 mpp_enc_get_extra_data_size(MppCtx ctx)
{
mpi_dbg_func("enter ctx %p\n", ctx);
MpiImpl *p = (MpiImpl*)ctx;
RK_U32 ret = p->ctx->mEnc->extra_info.size;
mpi_dbg_func("leave\n");
return ret;
}
RK_U8 *mpp_enc_get_extra_data(MppCtx ctx)
{
mpi_dbg_func("enter ctx %p\n", ctx);
MpiImpl *p = (MpiImpl*)ctx;
RK_U8 *extra_data = p->ctx->mEnc->extra_info.buf;
mpp_log("Mpp get extra data now!");
mpi_dbg_func("leave\n");
return extra_data;
}

View File

@@ -645,7 +645,8 @@ MPP_RET Mpp::control_enc(MpiCmd cmd, MppParam param)
MPP_RET ret = MPP_NOK; MPP_RET ret = MPP_NOK;
switch (cmd) { switch (cmd) {
case MPP_ENC_SET_CFG : { case MPP_ENC_SET_CFG :
case MPP_ENC_GET_EXTRA_INFO : {
mpp_assert(mEnc); mpp_assert(mEnc);
ret = mpp_enc_control(mEnc, cmd, param); ret = mpp_enc_control(mEnc, cmd, param);
} break; } break;

View File

@@ -170,10 +170,27 @@ int mpi_enc_test(MpiEncTestCmd *cmd)
ret = mpi->control(ctx, MPP_ENC_SET_CFG, &mpp_cfg); ret = mpi->control(ctx, MPP_ENC_SET_CFG, &mpp_cfg);
if (MPP_OK != ret) { if (MPP_OK != ret) {
mpp_err("mpi control failed\n"); mpp_err("mpi control enc set cfg failed\n");
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
ret = mpi->control(ctx, MPP_ENC_GET_EXTRA_INFO, &packet);
if (MPP_OK != ret) {
mpp_err("mpi control enc get extra info failed\n");
goto MPP_TEST_OUT;
}
/* get and write sps/pps for H.264 */
if (packet) {
void *ptr = mpp_packet_get_pos(packet);
size_t len = mpp_packet_get_length(packet);
if (fp_output)
fwrite(ptr, 1, len, fp_output);
packet = NULL;
}
ret = mpp_frame_init(&frame); ret = mpp_frame_init(&frame);
if (MPP_OK != ret) { if (MPP_OK != ret) {
mpp_err("mpp_frame_init failed\n"); mpp_err("mpp_frame_init failed\n");