Phase 8.6: dmabuf + AV1 + H.264 + stateless controls

Removes the Phase 8.5 64 KiB frame-size cap by exporting CAPTURE
buffers as dmabuf-fds the daemon mmaps and writes pixels into
directly. Adds AV1 + H.264 codec support, V4L2 stateless control
registration, and the compliance polish that brings the driver
to 47/48 v4l2-compliance pass.

Protocol (include/daedalus_v4l2_proto.h):
- struct daedalus_req_decode grew capture-buffer metadata
  (width/height/pix_fmt/num_planes + per-plane size+stride).
- New DAEDALUS_IOC_GET_DMABUF ioctl on the chardev: daemon
  asks for a per-plane dmabuf fd, kernel calls vb2_core_expbuf
  in daemon task context so the fd lands in the daemon's table.

Kernel m2m driver (kernel/daedalus_v4l2_main.c):
- Both queues switched to vb2_dma_contig_memops. OUTPUT was
  vmalloc in 8.5; the switch is needed because vmalloc doesn't
  honour V4L2_MEMORY_FLAG_NON_COHERENT and v4l2-compliance's
  REQBUFS test rejected the driver because of it. We still
  read bitstream via vb2_plane_vaddr (dma_contig gives a
  kernel virtual address just like vmalloc did).
- dma_coerce_mask_and_coherent(DMA_BIT_MASK(32)) in probe.
- queue_setup populates alloc_devs[plane] = &pdev->dev for
  both queues; allow_cache_hints=1 on both.
- daedalus_export_capture_dmabuf(cookie, plane, flags, *fd):
  walks inflight list, calls vb2_core_expbuf on the CAPTURE
  buffer in the caller's (daemon's) task context.
- device_run fills the new REQ_DECODE capture fields from
  ctx->dst_fmt and maps ctx->src_fmt.pixelformat to
  DAEDALUS_CODEC_VP9 / _AV1 / _H264 (was hard-wired to VP9).
- daedalus_complete_resp_frame handles both the 8.5 inline
  path (kept for debugging) and the 8.6 dmabuf path (pixels
  already in CAPTURE buffer, just set payload from metadata).
- enum_fmt advertises all 3 OUTPUT formats (VP9F, AV1F, S264).
- try_fmt preserves userspace colorspace fields instead of
  overwriting with REC709 defaults (fixes 8.5 compliance fail).
- s_fmt propagates OUTPUT colorspace → CAPTURE (stateless
  decoder round-trip test at v4l2-test-formats.cpp:958).
- 12 V4L2 stateless controls registered per open (VP9_FRAME,
  VP9_COMPRESSED_HDR, H264_SPS/PPS/SCALING/PRED_WEIGHTS/
  SLICE_PARAMS/DECODE_PARAMS, AV1_FRAME/SEQUENCE/
  TILE_GROUP_ENTRY/FILM_GRAIN). Daemon ignores values (FFmpeg
  re-parses); registration is what makes libva-v4l2-request
  see us.

Kernel chardev (kernel/daedalus_v4l2_chardev.c):
- New unlocked_ioctl dispatching DAEDALUS_IOC_GET_DMABUF to
  daedalus_export_capture_dmabuf.
- debugfs test_decode cookies unified with the m2m cookie
  allocator via shared daedalus_next_cookie() — kills the
  Phase 8.5 namespace collision.

Daemon (daemon/src/...):
- New dmabuf_capture.{c,h}: GET_DMABUF + mmap each plane on
  REQ_DECODE; munmap + close on completion. O_RDWR | O_CLOEXEC
  is essential — vb2_core_expbuf extracts O_ACCMODE from flags
  and exports read-only by default (caught on first run; mmap
  -EACCES on PROT_WRITE).
- decoder.{c,h}: lazily opens AV1 + H.264 AVCodecContexts in
  addition to VP9 (dropped the -ENOSYS stubs). pack_nv12_to_planes
  writes Y line-by-line into planes[0] with planes[0].stride;
  interleaves Cb/Cr into planes[1] with planes[1].stride.
- chardev_client.c handle_req_decode: opens dmabuf planes,
  runs decode (pixels land in CAPTURE buffer directly), closes
  planes, sends metadata-only RESP_FRAME. No wire-pixel
  allocation.

Test harness (tools/test_m2m_decode.c):
- Optional 5th arg `codec` (vp9 | av1 | h264). Same client
  drives all three codecs.

Verification on hertz (Pi 5, 6.12.75+rpt-rpi-2712):

Bit-exact end-to-end vs `ffmpeg -pix_fmt nv12`:
  VP9   1920x1080  3,110,400 bytes  MATCH
  AV1     128x96      18,432 bytes  MATCH
  H.264   128x96      18,432 bytes  MATCH

VP9 1080p went through the full dmabuf path with no chardev
payload bloat — the same chardev that capped at 64 KiB in 8.5
now ferries metadata only and lets the daemon mmap+write a
3.1 MB frame directly into the V4L2 client's buffer.

v4l2-compliance:
  Phase 8.1: 44/48
  Phase 8.5: 44/48 (different fails after m2m landed)
  Phase 8.6: 47/48
  Only remaining: VIDIOC_(TRY_)DECODER_CMD (needs media
  controller — explicitly Phase 8.7 work).

11 standard compound controls visible:
  vp9_frame_decode_parameters, vp9_probabilities_updates,
  h264_sequence_parameter_set, h264_picture_parameter_set,
  h264_scaling_matrix, h264_prediction_weight_table,
  h264_slice_parameters, h264_decode_parameters,
  av1_sequence_parameters, av1_frame_parameters,
  av1_film_grain (av1_tile_group_entry refused by hdl->error
  on this kernel — skipped silently).

Clean SIGTERM + rmmod, no oops/WARN.

Roadmap update (docs/roadmap.md):
- Phase 8.6 marked closed with the closure-doc reference.
- Phase 8.7 reshaped to (1) media controller, (2) perf +
  daedalus_dispatch_* substitution, (3) HDR/10-bit, (4)
  long-form multi-frame streaming.

Per correctness-before-speed:
- Real V4L2 dmabuf via vb2_core_expbuf (not a sideband
  fd-passing hack).
- O_RDWR access mode threaded through correctly.
- Strict pixel-byte comparison against ffmpeg, not "looks
  right" eyeballing.
- Each compliance edge documented with the underlying test
  source-line + the fix.
- All resource paths cleaned (munmap + close per plane on
  every exit, including error paths).

Phase 8.7 next: media controller binding (closes last
compliance fail), per-frame profiling, QPU dispatch
substitution targeting 30fps@1080p from
30fps-floor-is-fine memory.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 16:16:06 +00:00
parent 6f4b580f7c
commit c7f6fb90cb
13 changed files with 1085 additions and 193 deletions
+292 -50
View File
@@ -34,6 +34,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/dma-mapping.h>
#include <media/v4l2-device.h>
#include <media/v4l2-dev.h>
@@ -42,7 +43,7 @@
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>
#include <media/videobuf2-dma-contig.h>
#include "daedalus_v4l2_chardev.h"
#include "daedalus_v4l2_proto.h"
@@ -51,9 +52,34 @@
#define DAEDALUS_DRV_NAME "daedalus_v4l2"
#define DAEDALUS_VIDEO_NAME "daedalus"
/* Coding-format coverage Phase 8.5: VP9 only. 8.6 adds AV1+H.264. */
#define DAEDALUS_OUTPUT_FOURCC V4L2_PIX_FMT_VP9_FRAME
#define DAEDALUS_CAPTURE_FOURCC V4L2_PIX_FMT_NV12M /* planar Y + interleaved CbCr */
/*
* Phase 8.6: OUTPUT side advertises VP9 + AV1 + H.264 stateless
* formats (the daemon decodes all three via FFmpeg dlopen).
* CAPTURE is NV12M for now; HDR / 10-bit comes later.
*/
static const u32 daedalus_output_formats[] = {
V4L2_PIX_FMT_VP9_FRAME,
V4L2_PIX_FMT_AV1_FRAME,
V4L2_PIX_FMT_H264_SLICE,
};
#define DAEDALUS_NUM_OUTPUT_FMTS ARRAY_SIZE(daedalus_output_formats)
#define DAEDALUS_DEFAULT_OUTPUT_FOURCC V4L2_PIX_FMT_VP9_FRAME
#define DAEDALUS_CAPTURE_FOURCC V4L2_PIX_FMT_NV12M /* planar Y + interleaved CbCr */
static u32 daedalus_fourcc_to_codec_id(u32 fourcc)
{
switch (fourcc) {
case V4L2_PIX_FMT_VP9_FRAME: return DAEDALUS_CODEC_VP9;
case V4L2_PIX_FMT_AV1_FRAME: return DAEDALUS_CODEC_AV1;
case V4L2_PIX_FMT_H264_SLICE: return DAEDALUS_CODEC_H264;
default: return 0;
}
}
static bool daedalus_is_supported_output(u32 fourcc)
{
return daedalus_fourcc_to_codec_id(fourcc) != 0;
}
/* Conservative defaults; userspace S_FMT overrides. */
#define DAEDALUS_DEFAULT_W 320
@@ -101,6 +127,61 @@ static inline struct daedalus_ctx *file_to_ctx(struct file *file)
return container_of(file->private_data, struct daedalus_ctx, fh);
}
/* -- V4L2 stateless control registration (skeleton) ----------------- */
/*
* Register the per-codec stateless controls so userspace
* (libva-v4l2-request and v4l2-compliance) recognises us as a
* proper stateless decoder. We don't act on the values — the
* daemon parses VP9/H.264/AV1 headers itself via FFmpeg — but
* we accept stores so libva can drive standard decode flows.
*
* Per-codec control IDs that ship in v6.12 headers:
* VP9: V4L2_CID_STATELESS_VP9_FRAME, V4L2_CID_STATELESS_VP9_COMPRESSED_HDR
* H264: V4L2_CID_STATELESS_H264_{SPS,PPS,SCALING_MATRIX,PRED_WEIGHTS,
* SLICE_PARAMS,DECODE_PARAMS}
* AV1: V4L2_CID_STATELESS_AV1_FRAME (+ TILE_GROUP_ENTRY, SEQUENCE,
* FILM_GRAIN where available)
*/
static const u32 daedalus_stateless_ctrls[] = {
V4L2_CID_STATELESS_VP9_FRAME,
V4L2_CID_STATELESS_VP9_COMPRESSED_HDR,
V4L2_CID_STATELESS_H264_SPS,
V4L2_CID_STATELESS_H264_PPS,
V4L2_CID_STATELESS_H264_SCALING_MATRIX,
V4L2_CID_STATELESS_H264_PRED_WEIGHTS,
V4L2_CID_STATELESS_H264_SLICE_PARAMS,
V4L2_CID_STATELESS_H264_DECODE_PARAMS,
V4L2_CID_STATELESS_AV1_FRAME,
V4L2_CID_STATELESS_AV1_SEQUENCE,
V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY,
V4L2_CID_STATELESS_AV1_FILM_GRAIN,
};
static int daedalus_register_stateless_ctrls(struct v4l2_ctrl_handler *hdl)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(daedalus_stateless_ctrls); i++) {
v4l2_ctrl_new_std_compound(hdl, NULL,
daedalus_stateless_ctrls[i],
v4l2_ctrl_ptr_create(NULL));
/*
* Errors here mean the v4l2-core doesn't know about
* this CID on this kernel (e.g. older trees missing
* AV1_FILM_GRAIN). hdl->error captures it; we
* tolerate it — the codec just won't appear as
* supported through that control.
*/
if (hdl->error) {
pr_debug("daedalus_v4l2: skipping unsupported CID 0x%x (err=%d)\n",
daedalus_stateless_ctrls[i], hdl->error);
hdl->error = 0;
}
}
return 0;
}
/* -- format helpers -------------------------------------------------- */
/* NV12M = 2 planes: plane 0 = Y (W*H), plane 1 = interleaved CbCr (W*H/2). */
@@ -121,16 +202,19 @@ static void daedalus_fill_capture_fmt(struct v4l2_pix_format_mplane *f,
}
/*
* OUTPUT is a parsed VP9 access unit. V4L2 convention for
* compressed bitstream formats: single plane, sizeimage =
* worst-case bitstream size we're willing to accept.
* OUTPUT is a parsed access unit (VP9 frame / AV1 frame / H.264
* slice). V4L2 convention for compressed bitstream formats:
* single plane, sizeimage = worst-case bitstream size we're
* willing to accept. fourcc carries the codec selector.
*/
static void daedalus_fill_output_fmt(struct v4l2_pix_format_mplane *f,
u32 w, u32 h)
u32 fourcc, u32 w, u32 h)
{
if (!daedalus_is_supported_output(fourcc))
fourcc = DAEDALUS_DEFAULT_OUTPUT_FOURCC;
f->width = w;
f->height = h;
f->pixelformat = DAEDALUS_OUTPUT_FOURCC;
f->pixelformat = fourcc;
f->field = V4L2_FIELD_NONE;
f->colorspace = V4L2_COLORSPACE_REC709;
f->num_planes = 1;
@@ -158,15 +242,22 @@ static int daedalus_queue_setup(struct vb2_queue *vq,
for (p = 0; p < *nplanes; p++)
if (sizes[p] < fmt->plane_fmt[p].sizeimage)
return -EINVAL;
return 0;
} else {
*nplanes = fmt->num_planes;
for (p = 0; p < *nplanes; p++)
sizes[p] = fmt->plane_fmt[p].sizeimage;
if (*nbuffers < 2)
*nbuffers = 2;
}
*nplanes = fmt->num_planes;
/*
* Both queues use vb2_dma_contig now (OUTPUT switched in
* Phase 8.6 to satisfy v4l2-compliance's non-coherent
* REQBUFS test). Point both at the platform device as
* the CMA-backed allocation parent.
*/
for (p = 0; p < *nplanes; p++)
sizes[p] = fmt->plane_fmt[p].sizeimage;
if (*nbuffers < 2)
*nbuffers = 2;
alloc_devs[p] = &ctx->dev->pdev->dev;
return 0;
}
@@ -243,26 +334,39 @@ static int daedalus_queue_init(void *priv, struct vb2_queue *src_vq,
int ret;
src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
src_vq->drv_priv = ctx;
src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
src_vq->ops = &daedalus_qops;
src_vq->mem_ops = &vb2_vmalloc_memops;
/*
* Phase 8.6: OUTPUT switched from vb2_vmalloc to
* vb2_dma_contig so v4l2-compliance's REQBUFS test passes
* V4L2_MEMORY_FLAG_NON_COHERENT (vmalloc memops don't
* honour the flag; dma_contig does). We still use
* vb2_plane_vaddr in device_run to read the bitstream —
* dma_contig provides a kernel virtual address just like
* vmalloc did.
*/
src_vq->mem_ops = &vb2_dma_contig_memops;
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->lock = &ctx->dev->m2m_lock;
src_vq->dev = &ctx->dev->pdev->dev;
src_vq->allow_cache_hints = 1;
ret = vb2_queue_init(src_vq);
if (ret)
return ret;
dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
dst_vq->io_modes = VB2_MMAP;
dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
dst_vq->drv_priv = ctx;
dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
dst_vq->ops = &daedalus_qops;
dst_vq->mem_ops = &vb2_vmalloc_memops;
dst_vq->mem_ops = &vb2_dma_contig_memops;
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->lock = &ctx->dev->m2m_lock;
dst_vq->dev = &ctx->dev->pdev->dev;
dst_vq->allow_cache_hints = 1;
return vb2_queue_init(dst_vq);
}
@@ -300,10 +404,63 @@ daedalus_inflight_pop_locked(struct daedalus_dev *dev, u32 cookie)
return NULL;
}
/* -- chardev GET_DMABUF backend (called in daemon task context) ----- */
int daedalus_export_capture_dmabuf(u32 cookie, u32 plane, u32 flags,
int *out_fd)
{
struct daedalus_dev *dev = g_daedalus_dev;
struct daedalus_inflight *e, *match = NULL;
struct vb2_queue *vq;
struct vb2_buffer *vb;
int rc;
if (!dev || !out_fd)
return -EINVAL;
/*
* Walk the inflight list under the lock to look up the
* V4L2 request. Hold a transient reference via the lock
* — once we drop the lock the entry could be popped by a
* concurrent RESP_FRAME, but we only need the dst_buf +
* its vb2_queue, both of which are stable for the
* lifetime of the in-flight request (RESP_FRAME is what
* pops the entry, so daemon completing the export then
* sending RESP_FRAME is the canonical ordering).
*/
mutex_lock(&dev->inflight_lock);
list_for_each_entry(e, &dev->inflight, list) {
if (e->cookie == cookie) {
match = e;
break;
}
}
if (!match) {
mutex_unlock(&dev->inflight_lock);
return -EINVAL;
}
vb = &match->dst_buf->vb2_buf;
vq = vb->vb2_queue;
mutex_unlock(&dev->inflight_lock);
if (plane >= vb->num_planes)
return -EINVAL;
rc = vb2_core_expbuf(vq, out_fd, vq->type, vb, plane, flags);
if (rc)
return rc;
return 0;
}
/* -- v4l2_m2m_ops.device_run ----------------------------------------- */
static atomic_t daedalus_cookie_seq = ATOMIC_INIT(0);
u32 daedalus_next_cookie(void)
{
return (u32) atomic_inc_return(&daedalus_cookie_seq);
}
static void daedalus_device_run(void *priv)
{
struct daedalus_ctx *ctx = priv;
@@ -342,16 +499,37 @@ static void daedalus_device_run(void *priv)
req = kmalloc(payload_len, GFP_KERNEL);
if (!req)
goto fail_buf_error;
memset(req, 0, sizeof(*req));
req->codec_id = DAEDALUS_CODEC_VP9;
req->codec_id = daedalus_fourcc_to_codec_id(ctx->src_fmt.pixelformat);
if (!req->codec_id) {
v4l2_err(&dev->v4l2_dev,
"device_run: unsupported OUTPUT pixelformat 0x%08x\n",
ctx->src_fmt.pixelformat);
kfree(req);
req = NULL;
goto fail_buf_error;
}
req->bitstream_len = (u32) blen;
req->flags = 0;
req->capture_width = ctx->dst_fmt.width;
req->capture_height = ctx->dst_fmt.height;
req->capture_pix_fmt = ctx->dst_fmt.pixelformat;
req->capture_num_planes = ctx->dst_fmt.num_planes;
{
unsigned int p;
for (p = 0; p < ctx->dst_fmt.num_planes && p < 3; p++) {
req->capture_plane_size[p] =
ctx->dst_fmt.plane_fmt[p].sizeimage;
req->capture_plane_stride[p] =
ctx->dst_fmt.plane_fmt[p].bytesperline;
}
}
memcpy((u8 *) req + sizeof(*req), bitstream, blen);
inf = kzalloc(sizeof(*inf), GFP_KERNEL);
if (!inf)
goto fail_buf_error;
cookie = (u32) atomic_inc_return(&daedalus_cookie_seq);
cookie = daedalus_next_cookie();
inf->cookie = cookie;
inf->ctx = ctx;
inf->src_buf = src_buf;
@@ -430,35 +608,46 @@ void daedalus_complete_resp_frame(u32 cookie,
? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
/*
* Copy inline pixel data into the CAPTURE buffer if the
* daemon supplied any. Phase 8.5: bytes-after-header in the
* RESP_FRAME payload carry the Y plane followed by the
* interleaved CbCr plane (NV12M layout), truncated to fit
* the 64 KiB chardev payload cap. Phase 8.6 swaps this for
* dmabuf-export so big frames don't get truncated.
* Two routes the daemon can take, both supported:
*
* (a) Phase 8.6 dmabuf path — daemon called
* DAEDALUS_IOC_GET_DMABUF, mmap'd the CAPTURE buffer,
* wrote pixels in place. RESP_FRAME carries metadata
* only (pixels_len == 0). We just set the payload
* per plane from the daemon's reported sizes.
*
* (b) Phase 8.5 inline path — daemon shipped raw NV12 in
* the chardev payload (≤ 64 KiB cap). We memcpy
* into the vb2 buffer's vmalloc-backed plane. Still
* supported for small frames where the daemon hasn't
* picked up the GET_DMABUF path.
*/
if (state == VB2_BUF_STATE_DONE && pixels_len) {
if (state == VB2_BUF_STATE_DONE) {
struct vb2_buffer *vb = &inf->dst_buf->vb2_buf;
dst_y = vb2_plane_vaddr(vb, 0);
dst_uv = vb2_plane_vaddr(vb, 1);
y_size = min_t(u32, fr->luma_len,
(u32) vb2_plane_size(vb, 0));
uv_size = min_t(u32, fr->chroma_len,
(u32) vb2_plane_size(vb, 1));
if (dst_y && y_size && pixels_len >= y_size) {
memcpy(dst_y, pixels, y_size);
vb2_set_plane_payload(vb, 0, y_size);
} else {
vb2_set_plane_payload(vb, 0, 0);
if (pixels_len) {
/* (b) inline copy */
dst_y = vb2_plane_vaddr(vb, 0);
dst_uv = vb2_plane_vaddr(vb, 1);
if (dst_y && y_size && pixels_len >= y_size)
memcpy(dst_y, pixels, y_size);
else
y_size = 0;
if (dst_uv && uv_size &&
pixels_len >= y_size + uv_size)
memcpy(dst_uv, pixels + y_size, uv_size);
else
uv_size = 0;
}
if (dst_uv && uv_size && pixels_len >= y_size + uv_size) {
memcpy(dst_uv, pixels + y_size, uv_size);
/* (a) dmabuf path: pixels already there; just set payload */
vb2_set_plane_payload(vb, 0, y_size);
if (vb->num_planes > 1)
vb2_set_plane_payload(vb, 1, uv_size);
} else {
vb2_set_plane_payload(vb, 1, 0);
}
}
/*
@@ -491,13 +680,16 @@ static int daedalus_querycap(struct file *file, void *priv,
static int daedalus_enum_fmt(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
if (f->index >= DAEDALUS_NUM_OUTPUT_FMTS)
return -EINVAL;
f->pixelformat = daedalus_output_formats[f->index];
f->flags |= V4L2_FMT_FLAG_COMPRESSED;
return 0;
}
if (f->index != 0)
return -EINVAL;
f->pixelformat = (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
? DAEDALUS_OUTPUT_FOURCC
: DAEDALUS_CAPTURE_FOURCC;
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
f->flags |= V4L2_FMT_FLAG_COMPRESSED;
f->pixelformat = DAEDALUS_CAPTURE_FOURCC;
return 0;
}
@@ -521,14 +713,35 @@ static int daedalus_try_fmt(struct file *file, void *priv,
struct v4l2_pix_format_mplane *p = &f->fmt.pix_mp;
u32 w = clamp_t(u32, p->width, 16, 1920);
u32 h = clamp_t(u32, p->height, 16, 1088);
u32 cs, xfer, ycbcr, quant;
/*
* Preserve userspace-supplied colorspace fields verbatim
* (fixes the Phase 8.5 v4l2-compliance S_FMT colorspace
* round-trip failure) — fill_*_fmt overwrites these to
* REC709 defaults, but TRY_FMT must echo what the caller
* asked for if it's at all sensible.
*/
cs = p->colorspace;
xfer = p->xfer_func;
ycbcr = p->ycbcr_enc;
quant = p->quantization;
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
daedalus_fill_output_fmt(p, w, h);
u32 fourcc = p->pixelformat;
if (!daedalus_is_supported_output(fourcc))
fourcc = DAEDALUS_DEFAULT_OUTPUT_FOURCC;
daedalus_fill_output_fmt(p, fourcc, w, h);
} else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
daedalus_fill_capture_fmt(p, w, h);
} else {
return -EINVAL;
}
if (cs) p->colorspace = cs;
if (xfer) p->xfer_func = xfer;
if (ycbcr) p->ycbcr_enc = ycbcr;
if (quant) p->quantization = quant;
return 0;
}
@@ -548,10 +761,23 @@ static int daedalus_s_fmt(struct file *file, void *priv,
ret = daedalus_try_fmt(file, priv, f);
if (ret)
return ret;
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
ctx->src_fmt = f->fmt.pix_mp;
else
/*
* Stateless decoder convention: colorspace metadata
* on the OUTPUT (bitstream) side describes what the
* codec will produce. Propagate to CAPTURE so a
* follow-up G_FMT on CAPTURE returns matching values
* (v4l2-compliance v4l2-test-formats.cpp:958
* round-trip test).
*/
ctx->dst_fmt.colorspace = ctx->src_fmt.colorspace;
ctx->dst_fmt.xfer_func = ctx->src_fmt.xfer_func;
ctx->dst_fmt.ycbcr_enc = ctx->src_fmt.ycbcr_enc;
ctx->dst_fmt.quantization = ctx->src_fmt.quantization;
} else {
ctx->dst_fmt = f->fmt.pix_mp;
}
return 0;
}
@@ -598,10 +824,12 @@ static int daedalus_open(struct file *file)
v4l2_fh_init(&ctx->fh, &dev->vdev);
file->private_data = &ctx->fh;
v4l2_ctrl_handler_init(&ctx->hdl, 0);
v4l2_ctrl_handler_init(&ctx->hdl, ARRAY_SIZE(daedalus_stateless_ctrls));
daedalus_register_stateless_ctrls(&ctx->hdl);
ctx->fh.ctrl_handler = &ctx->hdl;
daedalus_fill_output_fmt(&ctx->src_fmt,
DAEDALUS_DEFAULT_OUTPUT_FOURCC,
DAEDALUS_DEFAULT_W, DAEDALUS_DEFAULT_H);
daedalus_fill_capture_fmt(&ctx->dst_fmt,
DAEDALUS_DEFAULT_W, DAEDALUS_DEFAULT_H);
@@ -666,6 +894,20 @@ static int daedalus_probe(struct platform_device *pdev)
mutex_init(&dev->inflight_lock);
INIT_LIST_HEAD(&dev->inflight);
/*
* vb2_dma_contig (used by the CAPTURE queue for dmabuf
* export) needs the parent device's DMA mask configured.
* Pi 5 CMA supports 32-bit DMA; that's sufficient for
* NV12/NV12M up to 4K (4K NV12 = ~12.4 MiB, well under
* the 4 GiB ceiling).
*/
ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (ret) {
dev_err(&pdev->dev,
"dma_coerce_mask_and_coherent: %d\n", ret);
return ret;
}
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
if (ret) {
dev_err(&pdev->dev, "v4l2_device_register: %d\n", ret);