drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c- Extension
.c- Size
- 30051 bytes
- Lines
- 1042
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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_drv.hmtk_vcodec_dec.hvdec_drv_if.hmtk_vcodec_dec_pm.h
Detected Declarations
function Copyrightfunction mtk_vdec_get_cap_fmtfunction stateful_try_decoder_cmdfunction stateful_decoder_cmdfunction stateless_try_decoder_cmdfunction stateless_decoder_cmdfunction vidioc_try_decoder_cmdfunction vidioc_decoder_cmdfunction mtk_vdec_unlockfunction mtk_vdec_lockfunction mtk_vcodec_dec_releasefunction mtk_vcodec_dec_set_default_paramsfunction vidioc_vdec_qbuffunction vidioc_vdec_dqbuffunction vidioc_vdec_querycapfunction vidioc_vdec_subscribe_evtfunction vidioc_try_fmtfunction vidioc_try_fmt_vid_cap_mplanefunction vidioc_try_fmt_vid_out_mplanefunction vidioc_vdec_g_selectionfunction vidioc_vdec_s_selectionfunction vidioc_vdec_s_fmtfunction vb2_is_busyfunction vb2_is_busyfunction vidioc_enum_framesizesfunction vidioc_enum_fmtfunction vidioc_vdec_enum_fmt_vid_capfunction vidioc_vdec_enum_fmt_vid_outfunction vidioc_vdec_g_fmtfunction vb2ops_vdec_queue_setupfunction vb2ops_vdec_buf_preparefunction vb2ops_vdec_buf_finishfunction vb2ops_vdec_buf_initfunction vb2ops_vdec_start_streamingfunction vb2ops_vdec_stop_streamingfunction m2mops_vdec_device_runfunction m2mops_vdec_job_readyfunction m2mops_vdec_job_abortfunction mtk_vcodec_dec_queue_init
Annotated Snippet
if (!vb2_is_streaming(src_vq)) {
mtk_v4l2_vdec_dbg(1, ctx, "Output stream is off. No need to flush.");
return 0;
}
if (!vb2_is_streaming(dst_vq)) {
mtk_v4l2_vdec_dbg(1, ctx, "Capture stream is off. No need to flush.");
return 0;
}
v4l2_m2m_buf_queue(ctx->m2m_ctx, &ctx->empty_flush_buf.vb);
v4l2_m2m_try_schedule(ctx->m2m_ctx);
break;
case V4L2_DEC_CMD_START:
vb2_clear_last_buffer_dequeued(dst_vq);
break;
default:
return -EINVAL;
}
return 0;
}
static int stateless_try_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
{
return v4l2_m2m_ioctl_stateless_try_decoder_cmd(file, priv, cmd);
}
static int stateless_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
{
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
int ret;
ret = v4l2_m2m_ioctl_stateless_try_decoder_cmd(file, priv, cmd);
if (ret)
return ret;
mtk_v4l2_vdec_dbg(3, ctx, "decoder cmd=%u", cmd->cmd);
switch (cmd->cmd) {
case V4L2_DEC_CMD_FLUSH:
/*
* If the flag of the output buffer is equals V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF,
* this command will prevent dequeueing the capture buffer containing the last
* decoded frame. Or do nothing
*/
break;
default:
mtk_v4l2_vdec_err(ctx, "invalid stateless decoder cmd=%u", cmd->cmd);
return -EINVAL;
}
return 0;
}
static int vidioc_try_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
{
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
if (ctx->dev->vdec_pdata->uses_stateless_api)
return stateless_try_decoder_cmd(file, priv, cmd);
return stateful_try_decoder_cmd(file, priv, cmd);
}
static int vidioc_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
{
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
if (ctx->dev->vdec_pdata->uses_stateless_api)
return stateless_decoder_cmd(file, priv, cmd);
return stateful_decoder_cmd(file, priv, cmd);
}
void mtk_vdec_unlock(struct mtk_vcodec_dec_ctx *ctx)
{
mutex_unlock(&ctx->dev->dec_mutex[ctx->hw_id]);
}
void mtk_vdec_lock(struct mtk_vcodec_dec_ctx *ctx)
{
mutex_lock(&ctx->dev->dec_mutex[ctx->hw_id]);
}
void mtk_vcodec_dec_release(struct mtk_vcodec_dec_ctx *ctx)
{
vdec_if_deinit(ctx);
ctx->state = MTK_STATE_FREE;
}
Annotation
- Immediate include surface: `media/v4l2-event.h`, `media/v4l2-mem2mem.h`, `media/videobuf2-dma-contig.h`, `mtk_vcodec_dec_drv.h`, `mtk_vcodec_dec.h`, `vdec_drv_if.h`, `mtk_vcodec_dec_pm.h`.
- Detected declarations: `function Copyright`, `function mtk_vdec_get_cap_fmt`, `function stateful_try_decoder_cmd`, `function stateful_decoder_cmd`, `function stateless_try_decoder_cmd`, `function stateless_decoder_cmd`, `function vidioc_try_decoder_cmd`, `function vidioc_decoder_cmd`, `function mtk_vdec_unlock`, `function mtk_vdec_lock`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.