Skip to content

Prepare encoder support - #5

Merged
ashie merged 13 commits into
mainfrom
prep-encoder-support
Oct 8, 2026
Merged

ashie merged 13 commits into
mainfrom
prep-encoder-support

Conversation

@ashie

@ashie ashie commented Oct 8, 2026

Copy link
Copy Markdown
Member

No description provided.

ashie added 10 commits October 7, 2026 15:14
Split the per-direction (OUTPUT/CAPTURE) state out of struct v4l_gst
into a new struct v4l_gst_stream, held as priv->out and priv->cap, and
add enum v4l_gst_media_kind (CODEC/RAW) to describe the kind of media
carried by each direction's buffers.

A decoder has OUTPUT=CODEC / CAPTURE=RAW, an encoder will have
OUTPUT=RAW / CAPTURE=CODEC. This makes the direction-agnostic core
shareable and keeps the differences localized to the media kind,
preparing the codebase for V4L2 M2M encoder support.

Move struct v4l_gst and its helper types into a new
v4l-gst-internal.h. This is a pure refactor: only the M2M decoder
role is supported and all behavior is unchanged.

Assisted-by: Qwen3.8-27B
Break the 4170-line gst-backend.c into six translation units grouped
by V4L2 ioctl domain:

  v4l-gst-core.c     init/deinit, pipeline creation, config parsing,
                     debug categories, buffer CRC quark
  v4l-gst-pipeline.c pipeline state control, pad probes, appsink
                     callbacks, decoder command ioctls
  v4l-gst-fmt.c      format ioctls (set/get/enum/try fmt, framesizes,
                     crop, selection)
  v4l-gst-buf.c      buffer ioctls (qbuf/dqbuf/reqbuf/streamon/mmap)
  v4l-gst-ctrl.c     control ioctls
  v4l-gst-event.c    event ioctls

Functions keep their original file order. The 21 functions called
across translation units become non-static and are declared in
v4l-gst-internal.h, together with the extern debug categories and
the buffer CRC quark. The GST_DEBUG_CATEGORY_STATIC definitions move
to v4l-gst-core.c with GST_CAT_DEFAULT redefined in the internal
header. The PAGE_ALIGN helper moves next to its only user in
v4l-gst-buf.c. The #if 0'd set_decoder_cmd_state stub stays with the
decoder command ioctls in v4l-gst-pipeline.c.

Also rename gst-backend.h to v4l-gst.h and
gst-backend-testhooks.{c,h} to v4l-gst-testhooks.{c,h}, and update
the plugin and test meson sources accordingly.

Exported symbols: all previous exports are preserved; the 21
cross-TU functions and 3 debug categories are newly exported as a
consequence of the multi-TU layout.

Assisted-by: Qwen3.8-27B
Each codec section may now define a decode pipeline ("pipeline") and/or
an encode pipeline ("encode-pipeline"). v4l_gst_core_setup_role()
determines the M2M role from the configuration and rebuilds the
supported format lists accordingly; with both pipelines configured the
role is derived from the first OUTPUT format set.

enum_fmt flags entries by media kind, queryctrl profile checks are
role-aware, and the encoded-stream parameter reset is skipped while the
backend acts as an encoder. Adds encode-only and dual-role test
fixtures and 14 tests covering role derivation and format contracts.

Assisted-by: Qwen3.8-27B
Support the encoder role end-to-end: OUTPUT raw NV12 frames are pushed to
the pipeline and x264enc produces an H264 bitstream on CAPTURE.

- Negotiate codec CAPTURE caps and handle encoded buffers (no buffer pool /
  no video meta) in create_cap_buffers_list, dqbuf, mmap and reqbuf.
- Push OUTPUT caps to the appsrc before the first buffer so the base source
  negotiates before the first push (avoids NOT_NEGOTIATED).
- Always dequeue the last encoded CAPTURE buffer; the encoder signals EOS
  via the appsrc EOS event rather than a held-back buffer.
- Add prepare_x264enc_backend_fixture and a streaming test asserting the
  dequeued CAPTURE buffers carry an H264 start code.

Assisted-by: Qwen3.8-27B
Add a decoder streaming test that drives
  h264parse ! avdec_h264 ! videoconvert
through the V4L2 M2M API and drains CAPTURE buffers with
V4L2_DEC_CMD_STOP until V4L2_BUF_FLAG_LAST, preserving the existing
final-buffer/EOS behavior.

In v4l-gst core, raw video buffers may lack GstVideoMeta. Instead of
failing or assuming a single plane, callers now fall back to the
GstVideoInfo from the buffer pool caps for plane count, strides,
offsets and sizes. This fixes plane validation, DQBUF plane
information, CAPTURE mmap offsets, and frame size retrieval without
changing behavior when video metadata is present.

Assisted-by: Qwen3.8-27B
Replace the x264enc and h264dec specific test fixtures with
prepare_pipeline_backend_fixture(). The tests now provide the pipeline
string, codec/raw fourccs, resolution and buffer sizes, keeping the
test hook generic.

Assisted-by: Qwen3.8-27B
Limit appsrc format=GST_FORMAT_TIME and do-timestamp=TRUE to raw
encoder input. Decoder pipelines keep the previous appsrc segment
behavior to avoid changing the event format seen by the codec parser
and decoder.

This is a fix for the real-device H.264 decoding stall introduced by
32cb908.

Assisted-by: Qwen3.8-27B
@ashie
ashie force-pushed the prep-encoder-support branch 2 times, most recently from 3a881fe to f0a1d79 Compare October 8, 2026 02:15
@ashie
ashie force-pushed the prep-encoder-support branch from 3aa0cc0 to ddc6c43 Compare October 8, 2026 02:22
@ashie
ashie merged commit 34cbc4e into main Oct 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant