mpp解码得到全0数据
MPP_DECODER *CreaterDecode(){
MPP_RET ret = MPP_OK;
// MppCtx ctx;
// MppApi *mpi;
MppPacket packet = NULL;
MppFrameframe = NULL;
MpiCmd mpi_cmd = MPP_CMD_BASE;
MppParam param = NULL;
RK_U32 need_split = 0;
MPP_DECODER * coder= new MPP_DECODER;
MppDecCfg cfg = NULL;
coder->mpi=NULL;
coder->ctx=NULL;
coder->packet=NULL;
mpp_show_support_format();
// RK_S32 size = 512*1024;
// char *buf = (char *)malloc(size);
// if (NULL == buf) {
// printf("mpi_test malloc failed\n");
// return NULL;
// }
// ret = mpp_packet_init(&(coder->packet), NULL, 0);
// if (ret) {
// printf("mpp_packet_init failed\n");
// return NULL;
// }
ret = mpp_create(&(coder->ctx), &(coder->mpi));
if (MPP_OK != ret) {
printf("mpp_create failed\n");
return NULL;
}
// mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
// param = &need_split;
// ret = coder->mpi->control(coder->ctx, mpi_cmd, param);
// if (MPP_OK != ret) {
// printf("mpi->control failed\n");
// return NULL;
// }
// mpi_cmd = MPP_DEC_SET_IMMEDIATE_OUT;//H264即时输出
// param = &need_split;
// ret = coder->mpi->control(coder->ctx, mpi_cmd, param);
// if (MPP_OK != ret) {
// printf("mpi->control failed\n");
// return NULL;
// }
// MppFrameFormat format=MPP_FMT_YUV420SP;
// mpi_cmd = MPP_DEC_SET_OUTPUT_FORMAT;
// param = &format;
// ret = coder->mpi->control(coder->ctx, mpi_cmd, param);
// if (MPP_OK != ret) {
// printf("mpi->control failed\n");
// return NULL;
// }
printf("mpp_init type:%d\r\n",MPP_VIDEO_CodingAVC);
ret = mpp_init(coder->ctx, MPP_CTX_DEC,MPP_VIDEO_CodingAVC);//MPP_VIDEO_CodingRV//MPP_VIDEO_CodingAVC
if (MPP_OK != ret) {
printf("mpp_init failed\n");
return NULL;
}
printf("%x,%x,%x\r\n",coder->mpi,coder->ctx,coder->packet);
return coder;
}
以上是解码器初始化,
iLen = mUdp.Recv(buf,sizeof(buf));
if(iLen>0)
{
#if 0
#else
if(!UnpackRtpH264((const unsigned char*)buf+12,iLen-12,(unsigned char *)pu8Buf,iOutLen,m_nH264FrmeSize))
{
//if((buf&0x80)==0&&(buf&0x40)==0)
{
continue;
}
}
fwrite(pu8Buf,1,iOutLen,fp);
fflush(fp);
mpp_packet_init(&(channel1->packet),NULL, 0);
#endif
mpp_packet_set_data(channel1->packet, pu8Buf);
mpp_packet_set_pos(channel1->packet, pu8Buf);
mpp_packet_set_length(channel1->packet, iOutLen);
ret = channel1->mpi->decode_put_packet(channel1->ctx, channel1->packet);
if (MPP_OK != ret)
{
// printf("put error\r\n");
}
mpp_packet_deinit(&(channel1->packet));
m_nH264FrmeSize = 0;
}else{
break;
}
这是喂数据
mpp_ret = channel1->mpi->decode_get_frame(channel1->ctx, &frame);
if (MPP_OK !=mpp_ret)
{
usleep(5);
continue;
}
if (frame)
{
// printf("decode_get_frame OK\r\n");
static RK_U32 width;
static RK_U32 height;
static RK_U32 hor_stride;
static RK_U32 ver_stride;
static RK_U32 buf_size;
if (mpp_frame_get_info_change(frame))
{
width = mpp_frame_get_width(frame);
height = mpp_frame_get_height(frame);
hor_stride = mpp_frame_get_hor_stride(frame);
ver_stride = mpp_frame_get_ver_stride(frame);
buf_size = mpp_frame_get_buf_size(frame);
MppFrameFormat fmt = mpp_frame_get_fmt(frame);
printf("decoder require buffer w:h [%d:%d] stride [%d:%d] size %d,format:%d\n",
width, height, hor_stride, ver_stride, buf_size,fmt);
mpp_ret = channel1->mpi->control(channel1->ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
if (mpp_ret) {
printf("%p info change ready failed ret %d\n", channel1->ctx, mpp_ret);
break;
}
}
// width = mpp_frame_get_width(frame);
// height = mpp_frame_get_height(frame);
// hor_stride = mpp_frame_get_hor_stride(frame);
// ver_stride = mpp_frame_get_ver_stride(frame);
// buf_size = mpp_frame_get_buf_size(frame);
#define SAVE_FILE 1
#ifdef SAVE_FILE
char fileName={0};
static int yuvIndex=0;
sprintf(fileName,"%d.yuv",yuvIndex++);
FILE *fp=fopen(fileName,"w+");
#endif
MppBuffer buffer = NULL;
buffer = mpp_frame_get_buffer(frame);
if(buffer!=NULL)
{
RK_U8 *base = NULL;
#ifdef FILE_SHOW
base = (RK_U8 *)dataBuf;//(RK_U8 *)mpp_buffer_get_ptr(buffer);
#else
base = (RK_U8 *)mpp_buffer_get_ptr(buffer);
#endif
rga_buffer_t src;
rga_buffer_t dst;
im_rect src_rect;
im_rect dst_rect;
char* src_buf = NULL;
char* dst_buf = NULL;
memset(&src_rect, 0, sizeof(src_rect));
memset(&dst_rect, 0, sizeof(dst_rect));
memset(&src, 0, sizeof(src));
memset(&dst, 0, sizeof(dst));
int srcLen=width*height*get_bpp_from_format(RK_FORMAT_YCbCr_420_SP);
int desLen=width*height*get_bpp_from_format(RK_FORMAT_RGB_888);
src_buf = (char*)malloc(srcLen);
dst_buf = (char*)malloc(desLen);
if (src_buf == NULL || dst_buf == NULL) {
printf("GraphicBuff init error!\n");
return 0;
}
// memcpy(src_buf,base,srcLen);
int index=0;
RK_U8 *base_y = base;
RK_U8 *base_c = base + hor_stride * ver_stride;
#ifdef SAVE_FILE
for (i = 0; i < height; i++, base_y += hor_stride) {
fwrite(base_y, 1, width, fp);
}
for (i = 0; i < height / 2; i++, base_c += hor_stride) {
fwrite(base_c, 1, width, fp);
}
fflush(fp);
#endif
这个是保存的
关于mpp解码问题,发现最终得到的YUV数据都是全0数据 兄弟问题解决了吗
页:
[1]