diff --git a/mpp/codec/dec/h265/h265d_parser.c b/mpp/codec/dec/h265/h265d_parser.c index ebaf67f7..ce7443fd 100644 --- a/mpp/codec/dec/h265/h265d_parser.c +++ b/mpp/codec/dec/h265/h265d_parser.c @@ -1313,7 +1313,19 @@ RK_S32 mpp_hevc_extract_rbsp(HEVCContext *s, const RK_U8 *src, int length, } if (i >= length - 1) { // no escaped 0 - nal->data = src; + if (length + MPP_INPUT_BUFFER_PADDING_SIZE > nal->rbsp_buffer_size) { + RK_S32 min_size = length + MPP_INPUT_BUFFER_PADDING_SIZE; + mpp_free(nal->rbsp_buffer); + nal->rbsp_buffer = NULL; + min_size = MPP_MAX(17 * min_size / 16 + 32, min_size); + nal->rbsp_buffer = mpp_malloc(RK_U8, min_size); + if (nal->rbsp_buffer == NULL) { + min_size = 0; + } + nal->rbsp_buffer_size = min_size; + } + memcpy(nal->rbsp_buffer, src, length); + nal->data = nal->rbsp_buffer; nal->size = length; return length; } @@ -1534,6 +1546,12 @@ static RK_S32 parser_nal_units(HEVCContext *s) fail: return ret; } + +RK_U16 U16_AT(const RK_U8 *ptr) +{ + return ptr[0] << 8 | ptr[1]; +} + static RK_S32 hevc_parser_extradata(HEVCContext *s) { H265dContext_t *h265dctx = s->h265dctx; @@ -1545,8 +1563,48 @@ static RK_S32 hevc_parser_extradata(HEVCContext *s) * Temporarily, we support configurationVersion==0 until 14496-15 3rd * is finalized. When finalized, configurationVersion will be 1 and we * can recognize hvcC by checking if h265dctx->extradata[0]==1 or not. */ - mpp_err("extradata is encoded as hvcC format"); + const RK_U8 *ptr = (const uint8_t *)h265dctx->extradata; + RK_U32 size = h265dctx->extradata_size; + RK_U32 numofArrays = 0, numofNals = 0; + RK_U32 j = 0, i = 0; + if (size < 7) { + return MPP_NOK; + } + + mpp_log("extradata is encoded as hvcC format"); s->is_nalff = 1; + s->nal_length_size = 1 + (ptr[14 + 7] & 3); + ptr += 22; + size -= 22; + numofArrays = (char)ptr[0]; + ptr += 1; + size -= 1; + for (i = 0; i < numofArrays; i++) { + ptr += 1; + size -= 1; + // Num of nals + numofNals = U16_AT(ptr); + ptr += 2; + size -= 2; + + for (j = 0; j < numofNals; j++) { + RK_U32 length = 0; + if (size < 2) { + return MPP_NOK; + } + + length = U16_AT(ptr); + + ptr += 2; + size -= 2; + if (size < length) { + return MPP_NOK; + } + parser_nal_unit(s, ptr, length); + ptr += length; + size -= length; + } + } } else { s->is_nalff = 0; ret = split_nal_units(s, h265dctx->extradata, h265dctx->extradata_size); @@ -1585,7 +1643,7 @@ MPP_RET h265d_prepare(void *ctx, MppPacket pkt, HalDecTask *task) mpp_packet_set_pos(pkt, pos); return MPP_OK; } - if (h265dctx->need_split) { + if (h265dctx->need_split && !s->is_nalff) { RK_S32 consume = 0; RK_U8 *split_out_buf = NULL; RK_S32 split_size = 0; @@ -1604,6 +1662,10 @@ MPP_RET h265d_prepare(void *ctx, MppPacket pkt, HalDecTask *task) } else { return MPP_FAIL_SPLIT_FRAME; } + } else { + pos = buf + length; + s->pts = pts; + mpp_packet_set_pos(pkt, pos); } ret = (MPP_RET)split_nal_units(s, buf, length); diff --git a/mpp/codec/inc/mpp_buf_slot.h b/mpp/codec/inc/mpp_buf_slot.h index 7a5cd2e0..911d7c44 100644 --- a/mpp/codec/inc/mpp_buf_slot.h +++ b/mpp/codec/inc/mpp_buf_slot.h @@ -221,8 +221,8 @@ typedef enum SlotPropType_e { SLOT_EOS, SLOT_FRAME, SLOT_BUFFER, - SLOT_FRAME_PTR, - SLOT_PROP_BUTT, + SLOT_FRAME_PTR, + SLOT_PROP_BUTT, } SlotPropType; MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type, void *val); diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index 40cfe2ae..1ae1902b 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -193,7 +193,7 @@ static RK_U32 reset_dec_task(Mpp *mpp, DecTask *task) task->status.dec_pkt_copy_rdy = 0; task_dec->input = -1; } - + task->status.task_parsed_rdy = 0; parser->unlock(THREAD_RESET); @@ -605,11 +605,11 @@ void *mpp_dec_hal_thread(void *data) RK_S32 index; while (MPP_OK == mpp_buf_slot_dequeue(frame_slots, &index, QUEUE_DISPLAY)) { MppFrame frame; - RK_U32 display; + //RK_U32 display; mpp_buf_slot_get_prop(frame_slots, index, SLOT_FRAME, &frame); - display = mpp_frame_get_display(frame); - if (!dec->reset_flag && display) { - mpp_put_frame(mpp, frame); + // display = mpp_frame_get_display(frame); + if (!dec->reset_flag) { + mpp_put_frame(mpp, frame); } else { mpp_frame_deinit(&frame); } diff --git a/mpp/legacy/ppOp.cpp b/mpp/legacy/ppOp.cpp index c9345614..aa9e72bf 100644 --- a/mpp/legacy/ppOp.cpp +++ b/mpp/legacy/ppOp.cpp @@ -32,7 +32,8 @@ #ifdef ANDROID -namespace android { +namespace android +{ status_t ppOpInit(PP_OP_HANDLE *hnd, PP_OPERATION *init) { @@ -70,7 +71,7 @@ status_t ppOpSync(PP_OP_HANDLE hnd) status_t ppOpRelease(PP_OP_HANDLE hnd) { - (void)hnd; + (void)hnd; return 0; } @@ -93,22 +94,22 @@ status_t ppOpRelease(PP_OP_HANDLE hnd) int main() { FILE *fpr, *fpw; - int wid_alig16 = ((SRC_WIDTH+15)&(~0xf)); - int hei_alig16 = ((SRC_HEIGHT+15)&(~0xf)); + int wid_alig16 = ((SRC_WIDTH + 15) & (~0xf)); + int hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf)); int src_vir_width = 1920;//2048; int src_vir_height = 1088;//1088; int dst_vir_width = 800;//800; int dst_vir_height = 1280;//1280; int framecnt = 0; - char *tmpbuf = (char *)malloc(src_vir_width*src_vir_height/2); + char *tmpbuf = (char *)malloc(src_vir_width * src_vir_height / 2); RK_S32 ret = 0, i, j; ALOGI("ppOp test start\n"); VPUMemLinear_t src, dst; android::PP_OP_HANDLE hnd; int vpuFd = VPUClientInit(VPU_PP); - ret |= VPUMallocLinear(&src, src_vir_width*src_vir_height*2);//SRC_SIZE); - ret |= VPUMallocLinear(&dst, dst_vir_width*dst_vir_height*2);//DST_SIZE); + ret |= VPUMallocLinear(&src, src_vir_width * src_vir_height * 2); //SRC_SIZE); + ret |= VPUMallocLinear(&dst, dst_vir_width * dst_vir_height * 2); //DST_SIZE); if (ret) { ALOGE("failed to malloc vpu_mem"); goto end; @@ -119,51 +120,46 @@ int main() } { - #if 0 +#if 0 int i, j; char *tmp = (char *)src.vir_addr; - for(i=0; i= 1) + if (framecnt++ >= 1) break; - wid_alig16 = ((SRC_WIDTH+15)&(~0xf)); - hei_alig16 = ((SRC_HEIGHT+15)&(~0xf)); + wid_alig16 = ((SRC_WIDTH + 15) & (~0xf)); + hei_alig16 = ((SRC_HEIGHT + 15) & (~0xf)); android::PP_OPERATION opt; memset(&opt, 0, sizeof(opt)); @@ -175,13 +171,13 @@ int main() opt.srcVStride = src_vir_height; opt.srcX = 0; opt.srcY = 0; - if(wid_alig16 != SRC_WIDTH) + if (wid_alig16 != SRC_WIDTH) opt.srcCrop8R = 1; - if(hei_alig16 != SRC_HEIGHT) - opt.srcCrop8D= 1; + if (hei_alig16 != SRC_HEIGHT) + opt.srcCrop8D = 1; - wid_alig16 = ((DST_WIDTH+15)&(~0xf)); - hei_alig16 = ((DST_HEIGHT+15)&(~0xf)); + wid_alig16 = ((DST_WIDTH + 15) & (~0xf)); + hei_alig16 = ((DST_HEIGHT + 15) & (~0xf)); opt.dstAddr = dst.phy_addr; opt.dstFormat = PP_OUT_FORMAT_YUV420INTERLAVE; @@ -218,7 +214,7 @@ int main() VPUMemInvalidate(&dst); { - #if 0 +#if 0 int i, j, ret = 0; char *tmp = (char *)dst.vir_addr; /*for(i=0; i<3; i++) @@ -229,37 +225,35 @@ int main() { printf("las out_pos=%d, 0x%x\n", (DST_HEIGHT-1-i)*DST_WIDTH, tmp[(DST_HEIGHT-1-i)*DST_WIDTH]); }*/ - for(i=0; i 0) VPUClientRelease(vpuFd); diff --git a/mpp/legacy/ppOp.h b/mpp/legacy/ppOp.h index 344b80e0..c74dbd76 100644 --- a/mpp/legacy/ppOp.h +++ b/mpp/legacy/ppOp.h @@ -32,7 +32,8 @@ typedef int32_t status_t; -namespace android { +namespace android +{ #define PP_IN_FORMAT_YUV422INTERLAVE 0 #define PP_IN_FORMAT_YUV420SEMI 1 diff --git a/mpp/legacy/vpu_api.cpp b/mpp/legacy/vpu_api.cpp index 67d2d09a..e25c59c7 100644 --- a/mpp/legacy/vpu_api.cpp +++ b/mpp/legacy/vpu_api.cpp @@ -200,8 +200,8 @@ RK_S32 open_orign_vpu(VpuCodecContext **ctx) if (rkapi_hdl == NULL) { mpp_log("dlopen librk_vpuapi library fail\n"); rkapi_hdl = dlopen("/system/lib/librk_on2.so", RTLD_LAZY); - if(rkapi_hdl == NULL){ - return -1; + if (rkapi_hdl == NULL) { + return -1; } } rkvpu_open_cxt = (RK_S32 (*)(VpuCodecContext **ctx))dlsym(rkapi_hdl, "vpu_open_context"); @@ -224,8 +224,8 @@ RK_S32 close_orign_vpu(VpuCodecContext **ctx) if (rkapi_hdl == NULL) { mpp_log("dlopen librk_vpuapi library fail\n"); rkapi_hdl = dlopen("/system/lib/librk_on2.so", RTLD_LAZY); - if(rkapi_hdl == NULL){ - return -1; + if (rkapi_hdl == NULL) { + return -1; } } rkvpu_close_cxt = (RK_S32 (*)(VpuCodecContext **ctx))dlsym(rkapi_hdl, "vpu_close_context"); @@ -260,8 +260,8 @@ RK_S32 vpu_open_context(VpuCodecContext **ctx) if (s != NULL) { mpp_log("s->videoCoding = %d", s->videoCoding); if (s->videoCoding == OMX_RK_VIDEO_CodingHEVC - ||(s->videoCoding == OMX_RK_VIDEO_CodingAVC && - s->codecType == CODEC_DECODER)) { + || (s->videoCoding == OMX_RK_VIDEO_CodingAVC && + s->codecType == CODEC_DECODER)) { free(s); s = NULL; s = mpp_malloc(VpuCodecContext, 1); diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index 3c4224c0..818a4f6b 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -79,7 +79,9 @@ RK_S32 VpuApi::flush(VpuCodecContext *ctx) { (void)ctx; mpp_log_f("in\n"); - mpi->flush(mpp_ctx); + if (mpi && mpi->flush) { + mpi->flush(mpp_ctx); + } mpp_log_f("ok\n"); return 0; } @@ -208,6 +210,9 @@ RK_S32 VpuApi::control(VpuCodecContext *ctx, VPU_API_CMD cmd, void *param) { mpp_log_f("in\n"); MpiCmd mpicmd; + if (mpi == NULL) { + return 0; + } (void)ctx; switch (cmd) { case VPU_API_SET_VPUMEM_CONTEXT: { diff --git a/mpp/legacy/vpu_mem_legacy.c b/mpp/legacy/vpu_mem_legacy.c index 817368ef..17f77990 100644 --- a/mpp/legacy/vpu_mem_legacy.c +++ b/mpp/legacy/vpu_mem_legacy.c @@ -62,25 +62,25 @@ static void* get_free_memory_vpumem(vpu_display_mem_pool *p) } static RK_S32 inc_used_memory_handle_ref(vpu_display_mem_pool *p, void * hdl) -{ +{ VPUMemLinear_t *dmabuf = (VPUMemLinear_t *)hdl; MppBuffer buffer = (MppBuffer)dmabuf->offset; if (buffer != NULL) { mpp_buffer_inc_ref(buffer); } - (void)p; + (void)p; return MPP_OK; } static RK_S32 put_used_memory_handle(vpu_display_mem_pool *p, void *hdl) -{ +{ VPUMemLinear_t *dmabuf = (VPUMemLinear_t *)hdl; MppBuffer buf = (MppBuffer)dmabuf->offset; if (buf != NULL) { mpp_buffer_put(buf); } - (void)p; + (void)p; return MPP_OK; } @@ -103,10 +103,10 @@ static RK_S32 reset_vpu_mem_pool(vpu_display_mem_pool *p) vpu_display_mem_pool* open_vpu_memory_pool() -{ +{ vpu_display_mem_pool_impl *p_mempool = mpp_calloc(vpu_display_mem_pool_impl, 1); - - mpp_err("open_vpu_memory_pool in\n"); + + mpp_err("open_vpu_memory_pool in\n"); if (NULL == p_mempool) { return NULL; } @@ -126,18 +126,18 @@ vpu_display_mem_pool* open_vpu_memory_pool() } void close_vpu_memory_pool(vpu_display_mem_pool *p) -{ +{ vpu_display_mem_pool_impl *p_mempool = (vpu_display_mem_pool_impl *)p; - - mpp_err("close_vpu_memory_pool in xxxxxxxxxxxxxxx"); - mpp_buffer_group_put(p_mempool->group); + + mpp_err("close_vpu_memory_pool in xxxxxxxxxxxxxxx"); + mpp_buffer_group_put(p_mempool->group); mpp_free(p_mempool); return; } int create_vpu_memory_pool_allocator(vpu_display_mem_pool **ipool, int num, int size) { - + vpu_display_mem_pool_impl *p_mempool = mpp_calloc(vpu_display_mem_pool_impl, 1); if (NULL == p_mempool) { return -1; @@ -156,7 +156,7 @@ int create_vpu_memory_pool_allocator(vpu_display_mem_pool **ipool, int num, int p_mempool->buff_size = size; *ipool = (vpu_display_mem_pool*)p_mempool; - (void)num; + (void)num; return 0; } diff --git a/mpp/mpp_frame_impl.h b/mpp/mpp_frame_impl.h index c48718e8..18edbe48 100644 --- a/mpp/mpp_frame_impl.h +++ b/mpp/mpp_frame_impl.h @@ -43,17 +43,17 @@ struct MppFrameImpl_t { * 7 - deinterlaced paired field */ RK_U32 mode; - /* + /* * current decoded frame whether to display * * 0 - display * 1 - display */ - RK_U32 display; - /* + RK_U32 display; + /* * send decoded frame belong which view */ - RK_U32 viewid; + RK_U32 viewid; /* * pts - display time stamp