116 files changed, 25845 insertions, 36303 deletions
diff --git a/drivers/amvdec_ports/decoder/vdec_h264_if.c b/drivers/amvdec_ports/decoder/vdec_h264_if.c index eada4ea..04173d6 100644 --- a/drivers/amvdec_ports/decoder/vdec_h264_if.c +++ b/drivers/amvdec_ports/decoder/vdec_h264_if.c @@ -211,11 +211,13 @@ static void get_pic_info(struct vdec_h264_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_h264_inst *inst, struct v4l2_rect *cr) @@ -225,14 +227,15 @@ static void get_crop_info(struct vdec_h264_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_h264_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 void skip_aud_data(u8 **data, u32 *size) @@ -314,13 +317,15 @@ static int vdec_h264_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_h264 init err=%d", ret); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "vdec_h264 init err=%d\n", ret); goto err; } @@ -333,14 +338,15 @@ static int vdec_h264_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, "H264 Instance >> %p", inst); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "H264 Instance >> %lx", (ulong) inst); ctx->ada_ctx = &inst->vdec; *h_vdec = (unsigned long)inst; @@ -485,7 +491,7 @@ static void fill_vdec_params(struct vdec_h264_inst *inst, struct h264_SPS_t *sps pic->y_len_sz = pic->coded_width * pic->coded_height; pic->c_len_sz = pic->y_len_sz >> 1; pic->profile_idc = sps->profile_idc; - + pic->ref_frame_count= sps->ref_frame_count; /* calc DPB size */ dec->dpb_sz = sps->num_reorder_frames + margin; @@ -503,8 +509,9 @@ static void fill_vdec_params(struct vdec_h264_inst *inst, struct h264_SPS_t *sps vdec_config_dw_mode(pic, dw); - aml_vcodec_debug(inst, "[%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); } @@ -552,14 +559,15 @@ static int vdec_search_startcode(u8 *buf, u32 range) return pos; } -static int stream_parse_by_ucode(struct vdec_h264_inst *inst, u8 *buf, u32 size) +static int parse_stream_ucode(struct vdec_h264_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; } @@ -570,7 +578,27 @@ static int stream_parse_by_ucode(struct vdec_h264_inst *inst, u8 *buf, u32 size) return inst->vsi->dec.dpb_sz ? 0 : -1; } -static int stream_parse(struct vdec_h264_inst *inst, u8 *buf, u32 size) +static int parse_stream_ucode_dma(struct vdec_h264_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; + } + + /* 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_cpu(struct vdec_h264_inst *inst, u8 *buf, u32 size) { int ret = 0; struct h264_param_sets *ps; @@ -591,7 +619,8 @@ static int stream_parse(struct vdec_h264_inst *inst, u8 *buf, u32 size) ret = h264_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; } @@ -610,26 +639,38 @@ static int vdec_h264_probe(unsigned long h_vdec, { struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; - struct stream_info *st; - u8 *buf = (u8 *)bs->vaddr; + 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) { - buf = st->data; - size = st->length; - } + if (inst->ctx->is_drm_mode) { + if (bs->model == VB2_MEMORY_MMAP) { + struct aml_video_stream *s = + (struct aml_video_stream *) buf; - skip_aud_data(&buf, &size); + if ((s->magic != AML_VIDEO_MAGIC) && + (s->type != V4L_STREAM_TYPE_MATEDATA)) + return -1; - 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->param_sets_from_ucode) { + ret = parse_stream_ucode(inst, s->data, s->len); + } else { + skip_aud_data((u8 **)&s->data, &s->len); + 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 { + skip_aud_data(&buf, &size); + ret = parse_stream_cpu(inst, buf, size); + } + } inst->vsi->cur_pic = inst->vsi->pic; @@ -642,8 +683,6 @@ static void vdec_h264_deinit(unsigned long h_vdec) struct vdec_h264_inst *inst = (struct vdec_h264_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); @@ -675,14 +714,16 @@ static void vdec_h264_get_vf(struct vdec_h264_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; } @@ -690,8 +731,10 @@ static void vdec_h264_get_vf(struct vdec_h264_inst *inst, struct vdec_v4l2_buffe atomic_set(&vf->use_cnt, 1); fb = (struct vdec_v4l2_buffer *)vf->v4l_mem_handle; - fb->vf_handle = (unsigned long)vf; - fb->status = FB_ST_DISPLAY; + if (fb) { + fb->vf_handle = (unsigned long)vf; + fb->status = FB_ST_DISPLAY; + } *out = fb; @@ -719,7 +762,7 @@ static int vdec_write_nalu(struct vdec_h264_inst *inst, goto err; nal_type = AVC_NAL_TYPE(buf[nalu_pos]); - //aml_vcodec_debug(inst, "NALU type: %d, size: %u", nal_type, size); + //v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, "NALU type: %d, size: %u\n", nal_type, size); if (nal_type == NAL_H264_SPS && !is_combine) { if (inst->vsi->head_offset + size > HEADER_BUFFER_SIZE) { @@ -775,7 +818,7 @@ static int vdec_write_nalu(struct vdec_h264_inst *inst, return ret; err: - aml_vcodec_err(inst, "%s err(%d)", __func__, ret); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, "err(%d)", ret); return ret; } @@ -796,7 +839,7 @@ static bool monitor_res_change(struct vdec_h264_inst *inst, u8 *buf, u32 size) break; if (type == NAL_H264_SPS) { - ret = stream_parse(inst, p, len); + ret = parse_stream_cpu(inst, p, len); if (ret) break; } @@ -810,8 +853,10 @@ static bool monitor_res_change(struct vdec_h264_inst *inst, u8 *buf, u32 size) inst->vsi->cur_pic.coded_height != inst->vsi->pic.coded_height) || (inst->vsi->pic.profile_idc != - inst->vsi->cur_pic.profile_idc))) { - pr_info("res change\n"); + inst->vsi->cur_pic.profile_idc) || + (inst->vsi->pic.ref_frame_count != + inst->vsi->cur_pic.ref_frame_count))) { + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, "res change\n"); inst->vsi->cur_pic = inst->vsi->pic; return true; } @@ -824,9 +869,8 @@ static int vdec_h264_decode(unsigned long h_vdec, struct aml_vcodec_mem *bs, { struct vdec_h264_inst *inst = (struct vdec_h264_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) @@ -835,23 +879,44 @@ static int vdec_h264_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) { + int nal_idx = 0; + /* if the st compose from csd + slice that is the combine data. */ + inst->vsi->is_combine = check_frame_combine(buf, size, &nal_idx); + /*if (nal_idx < 0) + return -1;*/ + } else { + /*checked whether the resolution changes.*/ + if ((*res_chg = monitor_res_change(inst, buf, size))) { + return 0; + } + } ret = vdec_write_nalu(inst, buf, size, timestamp); } @@ -872,7 +937,8 @@ static void get_param_config_info(struct vdec_h264_inst *inst, 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_h264_get_param(unsigned long h_vdec, @@ -882,7 +948,8 @@ static int vdec_h264_get_param(unsigned long h_vdec, struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; if (!inst) { - pr_err("the h264 inst of dec is invalid.\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "the h264 inst of dec is invalid.\n"); return -1; } @@ -911,7 +978,8 @@ static int vdec_h264_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; } @@ -929,6 +997,7 @@ static void set_param_ps_info(struct vdec_h264_inst *inst, struct vdec_pic_info *pic = &inst->vsi->pic; struct vdec_h264_dec_info *dec = &inst->vsi->dec; struct v4l2_rect *rect = &inst->vsi->crop; + int dw = inst->parms.cfg.double_write_mode; /* fill visible area size that be used for EGL. */ pic->visible_width = ps->visible_width; @@ -945,17 +1014,21 @@ static void set_param_ps_info(struct vdec_h264_inst *inst, 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; - + pic->profile_idc = ps->profile; + pic->ref_frame_count = ps->ref_frames; dec->dpb_sz = ps->dpb_size; inst->parms.ps = *ps; inst->parms.parms_status |= V4L2_CONFIG_PARM_DECODE_PSINFO; + vdec_config_dw_mode(pic, dw); + /*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", ps->visible_width, ps->visible_height, ps->coded_width, ps->coded_height, dec->dpb_sz); @@ -972,14 +1045,16 @@ static void set_param_hdr_info(struct vdec_h264_inst *inst, V4L2_CONFIG_PARM_DECODE_HDRINFO; aml_vdec_dispatch_event(inst->ctx, V4L2_EVENT_SRC_CH_HDRINFO); - pr_info("H264 set HDR infos\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "H264 set HDR infos\n"); } } static void set_param_post_event(struct vdec_h264_inst *inst, u32 *event) { aml_vdec_dispatch_event(inst->ctx, *event); - pr_info("H264 post event: %d\n", *event); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_PRINFO, + "H264 post event: %d\n", *event); } static int vdec_h264_set_param(unsigned long h_vdec, @@ -989,7 +1064,8 @@ static int vdec_h264_set_param(unsigned long h_vdec, struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; if (!inst) { - pr_err("the h264 inst of dec is invalid.\n"); + v4l_dbg(inst->ctx, V4L_DEBUG_CODEC_ERROR, + "the h264 inst of dec is invalid.\n"); return -1; } @@ -1010,7 +1086,8 @@ static int vdec_h264_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; } |