drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateful.c- Extension
.c- Size
- 19063 bytes
- Lines
- 622
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
media/v4l2-event.hmedia/v4l2-mem2mem.hmedia/videobuf2-dma-contig.hmtk_vcodec_dec.hmtk_vcodec_dec_pm.hvdec_drv_if.h
Detected Declarations
function clean_display_bufferfunction clean_free_bufferfunction mtk_vdec_queue_res_chg_eventfunction mtk_vdec_flush_decoderfunction mtk_vdec_update_fmtfunction mtk_vdec_pic_info_updatefunction mtk_vdec_workerfunction vb2ops_vdec_stateful_buf_queuefunction mtk_vdec_g_v_ctrlfunction mtk_vcodec_dec_ctrls_setupfunction mtk_init_vdec_params
Annotated Snippet
if (fmt->fourcc == pixelformat) {
mtk_v4l2_vdec_dbg(1, ctx, "Update cap fourcc(%d -> %d)",
dst_q_data->fmt->fourcc, pixelformat);
dst_q_data->fmt = fmt;
return;
}
}
mtk_v4l2_vdec_err(ctx, "Cannot get fourcc(%d), using init value", pixelformat);
}
static int mtk_vdec_pic_info_update(struct mtk_vcodec_dec_ctx *ctx)
{
unsigned int dpbsize = 0;
int ret;
if (vdec_if_get_param(ctx, GET_PARAM_PIC_INFO,
&ctx->last_decoded_picinfo)) {
mtk_v4l2_vdec_err(ctx, "[%d]Error!! Cannot get param : GET_PARAM_PICTURE_INFO ERR",
ctx->id);
return -EINVAL;
}
if (ctx->last_decoded_picinfo.pic_w == 0 ||
ctx->last_decoded_picinfo.pic_h == 0 ||
ctx->last_decoded_picinfo.buf_w == 0 ||
ctx->last_decoded_picinfo.buf_h == 0) {
mtk_v4l2_vdec_err(ctx, "Cannot get correct pic info");
return -EINVAL;
}
if (ctx->last_decoded_picinfo.cap_fourcc != ctx->picinfo.cap_fourcc &&
ctx->picinfo.cap_fourcc != 0)
mtk_vdec_update_fmt(ctx, ctx->picinfo.cap_fourcc);
if (ctx->last_decoded_picinfo.pic_w == ctx->picinfo.pic_w ||
ctx->last_decoded_picinfo.pic_h == ctx->picinfo.pic_h)
return 0;
mtk_v4l2_vdec_dbg(1, ctx, "[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)", ctx->id,
ctx->last_decoded_picinfo.pic_w,
ctx->last_decoded_picinfo.pic_h, ctx->picinfo.pic_w,
ctx->picinfo.pic_h, ctx->last_decoded_picinfo.buf_w,
ctx->last_decoded_picinfo.buf_h);
ret = vdec_if_get_param(ctx, GET_PARAM_DPB_SIZE, &dpbsize);
if (dpbsize == 0)
mtk_v4l2_vdec_err(ctx, "Incorrect dpb size, ret=%d", ret);
ctx->dpb_size = dpbsize;
return ret;
}
static void mtk_vdec_worker(struct work_struct *work)
{
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_vcodec_mem buf;
struct vdec_fb *pfb;
bool res_chg = false;
int ret;
struct mtk_video_dec_buf *dst_buf_info, *src_buf_info;
src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
if (!src_buf) {
v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
mtk_v4l2_vdec_dbg(1, ctx, "[%d] src_buf empty!!", ctx->id);
return;
}
dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
if (!dst_buf) {
v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
mtk_v4l2_vdec_dbg(1, ctx, "[%d] dst_buf empty!!", ctx->id);
return;
}
dst_buf_info =
container_of(dst_buf, struct mtk_video_dec_buf, m2m_buf.vb);
pfb = &dst_buf_info->frame_buffer;
pfb->base_y.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 0);
pfb->base_y.dma_addr =
vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
pfb->base_y.size = ctx->picinfo.fb_sz[0];
pfb->base_c.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 1);
Annotation
- Immediate include surface: `media/v4l2-event.h`, `media/v4l2-mem2mem.h`, `media/videobuf2-dma-contig.h`, `mtk_vcodec_dec.h`, `mtk_vcodec_dec_pm.h`, `vdec_drv_if.h`.
- Detected declarations: `function clean_display_buffer`, `function clean_free_buffer`, `function mtk_vdec_queue_res_chg_event`, `function mtk_vdec_flush_decoder`, `function mtk_vdec_update_fmt`, `function mtk_vdec_pic_info_update`, `function mtk_vdec_worker`, `function vb2ops_vdec_stateful_buf_queue`, `function mtk_vdec_g_v_ctrl`, `function mtk_vcodec_dec_ctrls_setup`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.