drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c- Extension
.c- Size
- 42963 bytes
- Lines
- 1427
- 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.hlinux/pm_runtime.hmtk_vcodec_enc.hvenc_drv_if.h
Detected Declarations
function vidioc_venc_s_ctrlfunction vidioc_enum_fmtfunction mtk_venc_find_formatfunction vidioc_enum_framesizesfunction vidioc_enum_fmt_vid_capfunction vidioc_enum_fmt_vid_outfunction mtk_vcodec_enc_get_chip_namefunction vidioc_venc_querycapfunction vidioc_venc_s_parmfunction vidioc_venc_g_parmfunction vidioc_try_fmt_capfunction vidioc_try_fmt_outfunction mtk_venc_set_paramfunction vidioc_venc_s_fmt_capfunction vidioc_venc_s_fmt_outfunction vidioc_venc_g_fmtfunction vidioc_try_fmt_vid_cap_mplanefunction vidioc_try_fmt_vid_out_mplanefunction vidioc_venc_g_selectionfunction vidioc_venc_s_selectionfunction vidioc_venc_qbuffunction vidioc_venc_dqbuffunction vidioc_encoder_cmdfunction vb2ops_venc_queue_setupfunction vb2ops_venc_buf_preparefunction vb2ops_venc_buf_queuefunction vb2ops_venc_start_streamingfunction vb2ops_venc_stop_streamingfunction v4l2_m2m_for_each_src_buf_safefunction vb2ops_venc_buf_out_validatefunction mtk_venc_encode_headerfunction mtk_venc_param_changefunction v4l2_m2m_streamofffunction m2mops_venc_device_runfunction m2mops_venc_job_readyfunction m2mops_venc_job_abortfunction mtk_vcodec_enc_set_default_paramsfunction mtk_vcodec_enc_ctrls_setupfunction mtk_vcodec_enc_queue_initfunction mtk_venc_unlockfunction mtk_venc_lockfunction mtk_vcodec_enc_release
Annotated Snippet
if (ctrl->val != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) {
mtk_v4l2_venc_err(ctx, "Unsupported bitrate mode =%d", ctrl->val);
ret = -EINVAL;
}
break;
case V4L2_CID_MPEG_VIDEO_BITRATE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_BITRATE val = %d", ctrl->val);
p->bitrate = ctrl->val;
ctx->param_change |= MTK_ENCODE_PARAM_BITRATE;
break;
case V4L2_CID_MPEG_VIDEO_B_FRAMES:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_B_FRAMES val = %d", ctrl->val);
p->num_b_frame = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE val = %d",
ctrl->val);
p->rc_frame = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_MAX_QP val = %d", ctrl->val);
p->h264_max_qp = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_HEADER_MODE val = %d", ctrl->val);
p->seq_hdr_mode = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE val = %d", ctrl->val);
p->rc_mb = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_PROFILE val = %d", ctrl->val);
p->h264_profile = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_LEVEL val = %d", ctrl->val);
p->h264_level = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_I_PERIOD val = %d", ctrl->val);
p->intra_period = ctrl->val;
ctx->param_change |= MTK_ENCODE_PARAM_INTRA_PERIOD;
break;
case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_GOP_SIZE val = %d", ctrl->val);
p->gop_size = ctrl->val;
ctx->param_change |= MTK_ENCODE_PARAM_GOP_SIZE;
break;
case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
/*
* FIXME - what vp8 profiles are actually supported?
* The ctrl is added (with only profile 0 supported) for now.
*/
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_VP8_PROFILE val = %d", ctrl->val);
break;
case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME");
p->force_intra = 1;
ctx->param_change |= MTK_ENCODE_PARAM_FORCE_INTRA;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static const struct v4l2_ctrl_ops mtk_vcodec_enc_ctrl_ops = {
.s_ctrl = vidioc_venc_s_ctrl,
};
static int vidioc_enum_fmt(struct v4l2_fmtdesc *f,
const struct mtk_video_fmt *formats,
size_t num_formats)
{
if (f->index >= num_formats)
return -EINVAL;
f->pixelformat = formats[f->index].fourcc;
return 0;
}
static const struct mtk_video_fmt *
mtk_venc_find_format(u32 fourcc, const struct mtk_vcodec_enc_pdata *pdata)
{
const struct mtk_video_fmt *fmt;
unsigned int k;
Annotation
- Immediate include surface: `media/v4l2-event.h`, `media/v4l2-mem2mem.h`, `media/videobuf2-dma-contig.h`, `linux/pm_runtime.h`, `mtk_vcodec_enc.h`, `venc_drv_if.h`.
- Detected declarations: `function vidioc_venc_s_ctrl`, `function vidioc_enum_fmt`, `function mtk_venc_find_format`, `function vidioc_enum_framesizes`, `function vidioc_enum_fmt_vid_cap`, `function vidioc_enum_fmt_vid_out`, `function mtk_vcodec_enc_get_chip_name`, `function vidioc_venc_querycap`, `function vidioc_venc_s_parm`, `function vidioc_venc_g_parm`.
- 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.