116 files changed, 25845 insertions, 36303 deletions
diff --git a/drivers/amvdec_ports/decoder/vdec_hevc_if.c b/drivers/amvdec_ports/decoder/vdec_hevc_if.c index cd4d361..10c6b48 100644 --- a/drivers/amvdec_ports/decoder/vdec_hevc_if.c +++ b/drivers/amvdec_ports/decoder/vdec_hevc_if.c @@ -122,11 +122,13 @@ static void get_pic_info(struct vdec_hevc_inst *inst, { *pic = inst->vsi->pic; - aml_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)", - pic->visible_width, pic->visible_height, - pic->coded_width, pic->coded_height); - aml_vcodec_debug(inst, "Y(%d, %d), C(%d, %d)", pic->y_bs_sz, - pic->y_len_sz, pic->c_bs_sz, pic->c_len_sz); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO, + "pic(%d, %d), buf(%d, %d)\n", + pic->visible_width, pic->visible_height, + pic->coded_width, pic->coded_height); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO, + "Y(%d, %d), C(%d, %d)\n", pic->y_bs_sz, + pic->y_len_sz, pic->c_bs_sz, pic->c_len_sz); } static void get_crop_info(struct vdec_hevc_inst *inst, struct v4l2_rect *cr) @@ -136,14 +138,15 @@ static void get_crop_info(struct vdec_hevc_inst *inst, struct v4l2_rect *cr) cr->width = inst->vsi->crop.width; cr->height = inst->vsi->crop.height; - aml_vcodec_debug(inst, "l=%d, t=%d, w=%d, h=%d", - cr->left, cr->top, cr->width, cr->height); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO, + "l=%d, t=%d, w=%d, h=%d\n", + cr->left, cr->top, cr->width, cr->height); } static void get_dpb_size(struct vdec_hevc_inst *inst, unsigned int *dpb_sz) { *dpb_sz = inst->vsi->dec.dpb_sz; - aml_vcodec_debug(inst, "sz=%d", *dpb_sz); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_EXINFO, "sz=%d\n", *dpb_sz); } static u32 vdec_config_default_parms(u8 *parm) @@ -223,13 +226,15 @@ static int vdec_hevc_init(struct aml_vcodec_ctx *ctx, unsigned long *h_vdec) inst->vfm.ada_ctx = &inst->vdec; ret = vcodec_vfm_init(&inst->vfm); if (ret) { - pr_err("%s, init vfm failed.\n", __func__); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "init vfm failed.\n"); goto err; } ret = video_decoder_init(&inst->vdec); if (ret) { - aml_vcodec_err(inst, "vdec_hevc init err=%d", ret); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "vdec_hevc init err=%d\n", ret); goto err; } @@ -242,14 +247,15 @@ static int vdec_hevc_init(struct aml_vcodec_ctx *ctx, unsigned long *h_vdec) /* alloc the header buffer to be used cache sps or spp etc.*/ inst->vsi->header_buf = kzalloc(HEADER_BUFFER_SIZE, GFP_KERNEL); - if (!inst->vsi) { + if (!inst->vsi->header_buf) { ret = -ENOMEM; goto err; } init_completion(&inst->comp); - aml_vcodec_debug(inst, "hevc Instance >> %p", inst); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "hevc Instance >> %lx\n", (ulong) inst); ctx->ada_ctx = &inst->vdec; *h_vdec = (unsigned long)inst; @@ -286,7 +292,7 @@ static int refer_buffer_num(struct h265_SPS_t *sps) used_buf_num = sps->temporal_layer[0].num_reorder_pics; sps_pic_buf_diff = sps->temporal_layer[0].max_dec_pic_buffering - - sps->temporal_layer[0].num_reorder_pics + 1; + sps->temporal_layer[0].num_reorder_pics - 1; if (sps_pic_buf_diff >= 4) used_buf_num += 1; @@ -396,20 +402,42 @@ static void fill_vdec_params(struct vdec_hevc_inst *inst, struct h265_SPS_t *sps inst->parms.ps.dpb_size = dec->dpb_sz; inst->parms.parms_status |= V4L2_CONFIG_PARM_DECODE_PSINFO; - pr_info("[%d] The stream infos, dw: %d, coded:(%d x %d), visible:(%d x %d), DPB: %d, margin: %d\n", - inst->ctx->id, dw, pic->coded_width, pic->coded_height, + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_BUFMGR, + "The stream infos, dw: %d, coded:(%d x %d), visible:(%d x %d), DPB: %d, margin: %d\n", + dw, pic->coded_width, pic->coded_height, pic->visible_width, pic->visible_height, dec->dpb_sz - margin, margin); } -static int stream_parse_by_ucode(struct vdec_hevc_inst *inst, u8 *buf, u32 size) +static int parse_stream_ucode(struct vdec_hevc_inst *inst, u8 *buf, u32 size) { int ret = 0; struct aml_vdec_adapt *vdec = &inst->vdec; ret = vdec_vframe_write(vdec, buf, size, 0); if (ret < 0) { - pr_err("write frame data failed. err: %d\n", ret); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "write frame data failed. err: %d\n", ret); + return ret; + } + + /* wait ucode parse ending. */ + wait_for_completion_timeout(&inst->comp, + msecs_to_jiffies(1000)); + + return inst->vsi->dec.dpb_sz ? 0 : -1; +} + +static int parse_stream_ucode_dma(struct vdec_hevc_inst *inst, + ulong buf, u32 size, u32 handle) +{ + int ret = 0; + struct aml_vdec_adapt *vdec = &inst->vdec; + + ret = vdec_vframe_write_with_dma(vdec, buf, size, 0, handle); + if (ret < 0) { + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "write frame data failed. err: %d\n", ret); return ret; } @@ -420,7 +448,7 @@ static int stream_parse_by_ucode(struct vdec_hevc_inst *inst, u8 *buf, u32 size) return inst->vsi->dec.dpb_sz ? 0 : -1; } -static int stream_parse(struct vdec_hevc_inst *inst, u8 *buf, u32 size) +static int parse_stream_cpu(struct vdec_hevc_inst *inst, u8 *buf, u32 size) { int ret = 0; struct h265_param_sets *ps = NULL; @@ -431,7 +459,8 @@ static int stream_parse(struct vdec_hevc_inst *inst, u8 *buf, u32 size) ret = h265_decode_extradata_ps(buf, size, ps); if (ret) { - pr_err("parse extra data failed. err: %d\n", ret); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "parse extra data failed. err: %d\n", ret); goto out; } @@ -450,22 +479,35 @@ static int vdec_hevc_probe(unsigned long h_vdec, { struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; - struct stream_info *st; u8 *buf = (u8 *)bs->vaddr; u32 size = bs->size; int ret = 0; - st = (struct stream_info *)buf; - if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) - return 0; - - if (st->magic == NORe || st->magic == NORn) - ret = stream_parse(inst, st->data, st->length); - else { - if (inst->ctx->param_sets_from_ucode) - ret = stream_parse_by_ucode(inst, buf, size); - else - ret = stream_parse(inst, buf, size); + if (inst->ctx->is_drm_mode) { + if (bs->model == VB2_MEMORY_MMAP) { + struct aml_video_stream *s = + (struct aml_video_stream *) buf; + + if ((s->magic != AML_VIDEO_MAGIC) && + (s->type != V4L_STREAM_TYPE_MATEDATA)) + return -1; + + if (inst->ctx->param_sets_from_ucode) { + ret = parse_stream_ucode(inst, s->data, s->len); + } else { + ret = parse_stream_cpu(inst, s->data, s->len); + } + } else if (bs->model == VB2_MEMORY_DMABUF || + bs->model == VB2_MEMORY_USERPTR) { + ret = parse_stream_ucode_dma(inst, bs->addr, size, + BUFF_IDX(bs, bs->index)); + } + } else { + if (inst->ctx->param_sets_from_ucode) { + ret = parse_stream_ucode(inst, buf, size); + } else { + ret = parse_stream_cpu(inst, buf, size); + } } inst->vsi->cur_pic = inst->vsi->pic; @@ -479,8 +521,6 @@ static void vdec_hevc_deinit(unsigned long h_vdec) struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; struct aml_vcodec_ctx *ctx = inst->ctx; - aml_vcodec_debug_enter(inst); - video_decoder_release(&inst->vdec); vcodec_vfm_release(&inst->vfm); @@ -512,14 +552,16 @@ static void vdec_hevc_get_vf(struct vdec_hevc_inst *inst, struct vdec_v4l2_buffe vf = peek_video_frame(&inst->vfm); if (!vf) { - aml_vcodec_debug(inst, "there is no vframe."); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "there is no vframe.\n"); *out = NULL; return; } vf = get_video_frame(&inst->vfm); if (!vf) { - aml_vcodec_debug(inst, "the vframe is avalid."); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "the vframe is avalid.\n"); *out = NULL; return; } @@ -568,7 +610,7 @@ static bool monitor_res_change(struct vdec_hevc_inst *inst, u8 *buf, u32 size) break; if (type == HEVC_NAL_SPS) { - ret = stream_parse(inst, p, len); + ret = parse_stream_cpu(inst, p, len); if (ret) break; } @@ -593,9 +635,8 @@ static int vdec_hevc_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, { struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; struct aml_vdec_adapt *vdec = &inst->vdec; - struct stream_info *st; - u8 *buf; - u32 size; + u8 *buf = (u8 *) bs->vaddr; + u32 size = bs->size; int ret = -1; if (bs == NULL) @@ -604,23 +645,37 @@ static int vdec_hevc_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, if (vdec_input_full(vdec)) return -EAGAIN; - buf = (u8 *)bs->vaddr; - size = bs->size; - st = (struct stream_info *)buf; - - if (inst->ctx->is_drm_mode && (st->magic == DRMe || st->magic == DRMn)) - ret = vdec_vbuf_write(vdec, st->m.buf, sizeof(st->m.drm)); - else if (st->magic == NORe) - ret = vdec_vbuf_write(vdec, st->data, st->length); - else if (st->magic == NORn) - ret = vdec_write_nalu(inst, st->data, st->length, timestamp); - else if (inst->ctx->is_stream_mode) - ret = vdec_vbuf_write(vdec, buf, size); - else { - /*checked whether the resolution changes.*/ - if ((*res_chg = monitor_res_change(inst, buf, size))) - return 0; + if (inst->ctx->is_drm_mode) { + if (bs->model == VB2_MEMORY_MMAP) { + struct aml_video_stream *s = + (struct aml_video_stream *) buf; + if (s->magic != AML_VIDEO_MAGIC) + return -1; + + if (!inst->ctx->param_sets_from_ucode && + (s->type == V4L_STREAM_TYPE_MATEDATA)) { + if ((*res_chg = monitor_res_change(inst, + s->data, s->len))) + return 0; + } + + ret = vdec_vframe_write(vdec, + s->data, + s->len, + timestamp); + } else if (bs->model == VB2_MEMORY_DMABUF || + bs->model == VB2_MEMORY_USERPTR) { + ret = vdec_vframe_write_with_dma(vdec, + bs->addr, size, timestamp, + BUFF_IDX(bs, bs->index)); + } + } else { + if (!inst->ctx->param_sets_from_ucode) { + /*checked whether the resolution changes.*/ + if ((*res_chg = monitor_res_change(inst, buf, size))) + return 0; + } ret = vdec_write_nalu(inst, buf, size, timestamp); } @@ -641,7 +696,8 @@ static int vdec_hevc_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, parms->parms_status |= inst->parms.parms_status; - aml_vcodec_debug(inst, "parms status: %u", parms->parms_status); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "parms status: %u\n", parms->parms_status); } static int vdec_hevc_get_param(unsigned long h_vdec, @@ -651,7 +707,8 @@ static int vdec_hevc_get_param(unsigned long h_vdec, struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; if (!inst) { - pr_err("the hevc inst of dec is invalid.\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "the hevc inst of dec is invalid.\n"); return -1; } @@ -680,7 +737,8 @@ static int vdec_hevc_get_param(unsigned long h_vdec, get_param_config_info(inst, out); break; default: - aml_vcodec_err(inst, "invalid get parameter type=%d", type); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "invalid get parameter type=%d\n", type); ret = -EINVAL; } @@ -710,8 +768,9 @@ static void set_param_ps_info(struct vdec_hevc_inst *inst, rect->height = pic->visible_height; /* config canvas size that be used for decoder. */ - pic->coded_width = ALIGN(ps->coded_width, 64); - pic->coded_height = ALIGN(ps->coded_height, 64); + + pic->coded_width = ps->coded_width; + pic->coded_height = ps->coded_height; pic->y_len_sz = pic->coded_width * pic->coded_height; pic->c_len_sz = pic->y_len_sz >> 1; @@ -724,7 +783,8 @@ static void set_param_ps_info(struct vdec_hevc_inst *inst, /*wake up*/ complete(&inst->comp); - pr_info("Parse from ucode, crop(%d x %d), coded(%d x %d) dpb: %d\n", + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "Parse from ucode, crop(%d x %d), coded(%d x %d) dpb: %d\n", pic->visible_width, pic->visible_height, pic->coded_width, pic->coded_height, dec->dpb_sz); @@ -740,14 +800,16 @@ static void set_param_hdr_info(struct vdec_hevc_inst *inst, V4L2_CONFIG_PARM_DECODE_HDRINFO; aml_vdec_dispatch_event(inst->ctx, V4L2_EVENT_SRC_CH_HDRINFO); - pr_info("H265 set HDR infos\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "H265 set HDR infos\n"); } } static void set_param_post_event(struct vdec_hevc_inst *inst, u32 *event) { aml_vdec_dispatch_event(inst->ctx, *event); - pr_info("H265 post event: %d\n", *event); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "H265 post event: %d\n", *event); } static int vdec_hevc_set_param(unsigned long h_vdec, @@ -757,7 +819,8 @@ static int vdec_hevc_set_param(unsigned long h_vdec, struct vdec_hevc_inst *inst = (struct vdec_hevc_inst *)h_vdec; if (!inst) { - pr_err("the hevc inst of dec is invalid.\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "the hevc inst of dec is invalid.\n"); return -1; } @@ -778,7 +841,8 @@ static int vdec_hevc_set_param(unsigned long h_vdec, set_param_post_event(inst, in); break; default: - aml_vcodec_err(inst, "invalid set parameter type=%d", type); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "invalid set parameter type=%d\n", type); ret = -EINVAL; } |