static unsigned int h264_enc_wait_venc_done(struct venc_h264_inst *inst) { unsigned int irq_status = 0; struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx; if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED, WAIT_INTR_TIMEOUT_MS)) { irq_status = ctx->irq_status; mtk_vcodec_debug(inst, "irq_status %x <-", irq_status); } return irq_status; }
static int vdec_h264_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *fb, bool *res_chg) { struct vdec_h264_inst *inst = (struct vdec_h264_inst *)h_vdec; struct vdec_vpu_inst *vpu = &inst->vpu; int nal_start_idx = 0; int err = 0; unsigned int nal_start; unsigned int nal_type; unsigned char *buf; unsigned int buf_sz; unsigned int data[2]; uint64_t vdec_fb_va = (u64)(uintptr_t)fb; uint64_t y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0; uint64_t c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0; mtk_vcodec_debug(inst, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p", ++inst->num_nalu, y_fb_dma, c_fb_dma, fb); /* bs NULL means flush decoder */ if (bs == NULL) return vpu_dec_reset(vpu); buf = (unsigned char *)bs->va; buf_sz = bs->size; nal_start_idx = find_start_code(buf, buf_sz); if (nal_start_idx < 0) goto err_free_fb_out; nal_start = buf[nal_start_idx]; nal_type = NAL_TYPE(buf[nal_start_idx]); mtk_vcodec_debug(inst, "\n + NALU[%d] type %d +\n", inst->num_nalu, nal_type); if (nal_type == NAL_H264_PPS) { buf_sz -= nal_start_idx; if (buf_sz > HDR_PARSING_BUF_SZ) { err = -EILSEQ; goto err_free_fb_out; } memcpy(inst->vsi->hdr_buf, buf + nal_start_idx, buf_sz); } inst->vsi->dec.bs_dma = (uint64_t)bs->dma_addr; inst->vsi->dec.y_fb_dma = y_fb_dma; inst->vsi->dec.c_fb_dma = c_fb_dma; inst->vsi->dec.vdec_fb_va = vdec_fb_va; data[0] = buf_sz; data[1] = nal_start; err = vpu_dec_start(vpu, data, 2); if (err) goto err_free_fb_out; *res_chg = inst->vsi->dec.resolution_changed; if (*res_chg) { struct vdec_pic_info pic; mtk_vcodec_debug(inst, "- resolution changed -"); get_pic_info(inst, &pic); if (inst->vsi->dec.realloc_mv_buf) { err = alloc_mv_buf(inst, &pic); if (err) goto err_free_fb_out; } } if (nal_type == NAL_NON_IDR_SLICE || nal_type == NAL_IDR_SLICE) { /* wait decoder done interrupt */ err = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, WAIT_INTR_TIMEOUT_MS); if (err) goto err_free_fb_out; vpu_dec_end(vpu); } mtk_vcodec_debug(inst, "\n - NALU[%d] type=%d -\n", inst->num_nalu, nal_type); return 0; err_free_fb_out: put_fb_to_free(inst, fb); mtk_vcodec_err(inst, "\n - NALU[%d] err=%d -\n", inst->num_nalu, err); return err; }