ffmpeg-v4l2-request-fourier: per-MB inspection callback for H.264 (0016) #106

Merged
marfrit merged 1 commits from claude-noether/marfrit-packages:noether/h264-mb-inspect-callback into main 2026-05-26 04:05:58 +00:00
Owner

Adds 0016-h264-mb-inspect-callback.patch to the FFmpeg fork. Foundation for option A test harness — pairs with daedalus-decoder PR-A1b (the CLI binary).

API

typedef void (*ff_h264_mb_inspect_cb)(void *opaque,
                                       const struct H264Context *h,
                                       int mb_x, int mb_y);

void ff_h264_set_mb_inspect_cb(AVCodecContext *avctx,
                                ff_h264_mb_inspect_cb cb, void *opaque);

What it does

Opt-in callback fired by ff_h264_hl_decode_mb after the existing pixel work, for every MB in coded order. Two fields appended to H264Context (internal struct in h264dec.h, no ABI surface to non-libavcodec callers). Callback receives const H264Context* so it can inspect any state — slice context via h->slice_ctx, reconstructed pixels via h->cur_pic.f->data[plane], coeffs via sl->mb, etc.

Default (cb == NULL): zero behaviour change, one load + one branch per MB.

Shape — why this is NOT the dejavu trap

The 0003-0014 patches that PR #105 reverted were per-kernel function-pointer hijacks producing one Vulkan submit per block per kernel. Per-block synchronous dispatch from libavcodec is architecturally non-competitive (~22× slower than CPU NEON on the corrected daedalus-fourier PR #37 bench).

This patch is structurally different:

  • ONE inspection point per MB (not per kernel).
  • CPU-side only — the callback just observes; no GPU work fires from inside ff_h264_hl_decode_mb.
  • Consumer (daedalus-decoder in the follow-up PR) accumulates per-MB state in CPU-side flat buffers and dispatches ONCE per frame at flush_frame.

Frame-major UMA dispatch verdict (memory: dejavu) — same architecture as the daedalus-decoder Stage 1/2 work already merged.

Used by

  • daedalus-decoder/tools/daedalus_decode_h264 (PR-A1b, follow-up) — CLI test harness that wraps libavcodec + daedalus-decoder and bit-exact-compares on real H.264 streams.
  • Future daedalus-v4l2 daemon refactor — replaces the daemon's avcodec_send_packet/receive_frame per-MB path with the inspection-callback-driven version.

Wiring

  • arch PKGBUILD: source[] + prepare().
  • debian build-deb.sh: patch sequence.
  • Both pkgrel: 12 → 13.

Refs reauktion/daedalus-decoder!12 (Stage 2 PR-b).

Adds `0016-h264-mb-inspect-callback.patch` to the FFmpeg fork. Foundation for option A test harness — pairs with daedalus-decoder PR-A1b (the CLI binary). ## API ```c typedef void (*ff_h264_mb_inspect_cb)(void *opaque, const struct H264Context *h, int mb_x, int mb_y); void ff_h264_set_mb_inspect_cb(AVCodecContext *avctx, ff_h264_mb_inspect_cb cb, void *opaque); ``` ## What it does Opt-in callback fired by `ff_h264_hl_decode_mb` **after** the existing pixel work, for every MB in coded order. Two fields appended to `H264Context` (internal struct in `h264dec.h`, no ABI surface to non-libavcodec callers). Callback receives `const H264Context*` so it can inspect any state — slice context via `h->slice_ctx`, reconstructed pixels via `h->cur_pic.f->data[plane]`, coeffs via `sl->mb`, etc. Default (`cb == NULL`): zero behaviour change, one load + one branch per MB. ## Shape — why this is NOT the dejavu trap The `0003-0014` patches that PR #105 reverted were per-kernel function-pointer hijacks producing one Vulkan submit per block per kernel. Per-block synchronous dispatch from libavcodec is architecturally non-competitive (~22× slower than CPU NEON on the corrected daedalus-fourier PR #37 bench). This patch is structurally different: - **ONE** inspection point per MB (not per kernel). - **CPU-side only** — the callback just observes; no GPU work fires from inside `ff_h264_hl_decode_mb`. - Consumer (`daedalus-decoder` in the follow-up PR) accumulates per-MB state in CPU-side flat buffers and dispatches **ONCE per frame** at `flush_frame`. Frame-major UMA dispatch verdict (memory: `dejavu`) — same architecture as the daedalus-decoder Stage 1/2 work already merged. ## Used by - daedalus-decoder/tools/daedalus_decode_h264 (PR-A1b, follow-up) — CLI test harness that wraps libavcodec + daedalus-decoder and bit-exact-compares on real H.264 streams. - Future daedalus-v4l2 daemon refactor — replaces the daemon's `avcodec_send_packet`/`receive_frame` per-MB path with the inspection-callback-driven version. ## Wiring - arch PKGBUILD: source[] + prepare(). - debian build-deb.sh: patch sequence. - Both pkgrel: 12 → 13. Refs reauktion/daedalus-decoder!12 (Stage 2 PR-b).
marfrit added 1 commit 2026-05-26 03:58:13 +00:00
Adds 0016-h264-mb-inspect-callback.patch to the FFmpeg fork.  Adds an
opt-in callback fired by ff_h264_hl_decode_mb after the existing
pixel work, for tools that need per-MB visibility into H.264 decode.

API:
  typedef void (*ff_h264_mb_inspect_cb)(void *opaque,
                                         const struct H264Context *h,
                                         int mb_x, int mb_y);
  void ff_h264_set_mb_inspect_cb(AVCodecContext *avctx,
                                  ff_h264_mb_inspect_cb cb, void *opaque);

Two new fields appended to H264Context (internal struct, declared in
h264dec.h not h264.h, no ABI surface to non-libavcodec callers).
Callback fires post-pixel-work for every MB in coded order; receives
const H264Context* so it can inspect any state (slice ctx via
h->slice_ctx, reconstructed pixels via h->cur_pic.f->data[plane],
etc.).

Default (cb==NULL): zero behaviour change, one load + one branch per
MB in the decoder hot path.

Shape distinction: per-MB observation, NOT per-kernel function-pointer
hijack (the 0003-0014 substitution-arc pattern that PR #105 reverted
+ daedalus-fourier PR #37's measurement-correction architecturally
retired).  Per-block synchronous Vulkan dispatch from libavcodec is
non-competitive; per-MB CPU-side observation feeding a per-frame
daedalus-decoder batch submit is the right shape (frame-major UMA
dispatch verdict, memory: dejavu).

Used by:
  - daedalus-decoder/tools/daedalus_decode_h264 (PR-A1b, follow-up)
  - future daedalus-v4l2 daemon refactor

Wired into arch PKGBUILD source[] + prepare() and debian build-deb.sh
patch sequence.  pkgrel bumped 12 → 13.

Refs reauktion/daedalus-decoder!12.
marfrit merged commit 59901bceca into main 2026-05-26 04:05:58 +00:00
marfrit deleted branch noether/h264-mb-inspect-callback 2026-05-26 04:05:58 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: marfrit/marfrit-packages#106