Skip to content

feat(mac-o4): publish encode path and gpu-direct-stream-encode; Mac GPU stream gates (Phase 4 Task 6) - #1256

Merged
iamfatness merged 1 commit into
mainfrom
mac-outputs-phase4-o4e
Nov 26, 2026
Merged

iamfatness merged 1 commit into
mainfrom
mac-outputs-phase4-o4e

Conversation

@iamfatness

@iamfatness iamfatness commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

2026-11-26: rebased onto main 103604c0 (after #1250, its base, merged) and force-pushed, so CI runs. The rebase was clean.

2026-11-26: replayed onto the rebased #1250 and force-pushed. No conflicts.

2026-11-26: replayed onto the updated #1250 and force-pushed. No conflicts.

2026-11-26: replayed onto the rebased #1250 and force-pushed. No conflicts. Because it now includes #1255, --force-raw is expected to pass on this stack.

Phase 4 Task 6 (O4e) of the Mac parity plan (docs/superpowers/plans/2026-11-22-mac-outputs-ingest-browser-phase4.md). Stacked on #1250 (O4d); merge order is #1245 → #1248 → #1250 → this.

What it adds

  • encodePath {path, reason, codec} on every sender row. It is JSON null until a start decides it, and it reports the path the start took:
    • a GPU encoder that fails to start reads cpu-fallback / encoder-start-failed;
    • a start refused by admission still names its path;
    • a later start refused before it decides clears the old value.
  • New capability gpu-direct-stream-encode. It is available (detail videotoolbox / media-foundation) only when the build has a platform GPU encoder and the compositor exports the encoder texture (ICompositor::supportsEncoderTextureExport: Metal and D3D11). Otherwise it is omitted with the reason. Task 7's 60 fps and H.265 pickers read it. It is added to Protocol.h, and ContractParity is green.
  • VideoToolbox start log. The VideoToolbox encoder prints the MF encoder's [gpu-encode] started line. The slow-sink gate counts these lines to prove the encoder was never rebuilt.
  • validate-gpu-encode.mjs runs on the Mac.
    • --build-dir native/build-metal.
    • --ffmpeg-bin-dir: the bundled LGPL ffmpeg for the sender. Homebrew's is used for the receiver only.
    • A POSIX ffmpeg census. It matches the executable, so it no longer counts corevideo-child-guard, whose argv carries the ffmpeg command line.
    • --force-raw now fails when the raw stream stops delivering. It used to print PASS on about 11 KB.
  • mac-show-drill.py --stream-srt PORT. An SRT receiver, re-armed per connection, plus the core's srt destination at 1080p60 for the whole drill. The verdict checks the GPU-direct path, 1920x1080, at least 58 fps, and the number of sender starts.

Found by running the gates end to end

  1. POSIX unified-TS audio. It declared a second -f aac -i pipe:0 input. Fixed on macOS Phase 4 slice 7: AudioToolbox shared AAC; one-clock TS mux on POSIX (O4d) #1250 (its own commit, test, and mutation M5e).
  2. Mac raw-fallback stream wedged since macOS Phase 4 slice 2: Apple HEVC policy + real POSIX encoder probe (O3) #1234. Fixed in its own draft PR off main: fix(mac-stream): raw-fallback stream wedges after #1234; never trial-encode a single encoder candidate #1255. This branch does not include that fix, so --force-raw here fails until fix(mac-stream): raw-fallback stream wedges after #1234; never trial-encode a single encoder candidate #1255 merges and the stack is rebased.

Tests and mutations

Tests:

  • OutputSenderAdapter.PublishesTheChosenEncodePath
  • …AnEncoderThatFailsToStartPublishesTheFallback
  • …ARefusedRestartDoesNotKeepThePreviousPath
  • MediaCoreCommand.OutputSenderRowsPublishTheEncodePath
  • MediaCore.AdvertisesGpuDirectStreamEncode

Mutations (all red):

Mutation Change
M6a publish the desired path
M6a′ no after-start publication
M6b available without the export
M6c the null key omitted
M6d no per-start reset

Full native suite: 2350 passed, 0 failed.

Independent review: three findings fixed (stale path, the drill listener race and leak, two script crashes). The details are in the outcomes doc.

Functional runs (loaded machine, not the gate numbers)

Run Result
h264 1080p60 RTMP PASS, 58.4 fps
hevc path and decode OK, 57.9 fps
bitrate 6.026 Mbps of 6
--slow-sink 0.85 PASS: 1 encoder build, peak 1 egress child
--burst-sink 4 overflow-discard resyncs, 0 sender failures
drill --stream-srt 1 sender start, 20.8 s received, h264 1920x1080

Owed on a quiet machine: plan Task 6 Step 3, items 1–6.

Candidate issue: on POSIX the raw path writes Program PCM to a blocking pipe on the same worker as the video.

🤖 Generated with Claude Code

@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4e branch from d2694ee to 8d3765a Compare November 26, 2026 17:57
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4d branch from 7311762 to 5ae42da Compare November 26, 2026 17:57
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4e branch from 8d3765a to a53774e Compare November 26, 2026 19:17
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4d branch from 5ae42da to 67200f1 Compare November 26, 2026 19:17
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4e branch from a53774e to a1c607b Compare November 26, 2026 20:18
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4d branch from 67200f1 to 6d8fa28 Compare November 26, 2026 20:18
@iamfatness
iamfatness changed the base branch from mac-outputs-phase4-o4d to main November 26, 2026 20:53
Phase 4 Task 6 (O4e).

- Sender rows carry encodePath {path, reason, codec}: null until a start
  decides it, the STARTED path (a failed GPU encoder start reads
  cpu-fallback/encoder-start-failed), published before admission, and
  reset at every start so a refused restart never shows the old path.
- Capability gpu-direct-stream-encode: available (videotoolbox /
  media-foundation) only with a platform GPU encoder AND a compositor that
  exports the encoder texture (ICompositor::supportsEncoderTextureExport).
- VideoToolbox prints the MF encoder's "[gpu-encode] started" line.
- validate-gpu-encode.mjs runs on the Mac: --build-dir, --ffmpeg-bin-dir
  (the bundled LGPL sender), a POSIX census that matches the executable
  (not the child guard carrying its argv), and --force-raw fails when the
  raw stream stops delivering.
- mac-show-drill.py --stream-srt PORT: a re-armed SRT receiver, the core's
  srt destination at 1080p60, and a verdict (GPU-direct, 1920x1080, >= 58 fps).

Mutations M6a, M6a', M6b, M6c, M6d each red. Full native suite: 2350 passed.
Functional runs on a loaded Mac: h264 1080p60 PASS 58.4 fps; slow sink
PASS with 1 encoder build; drill stream 1 sender start, 20.8 s received.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamfatness
iamfatness force-pushed the mac-outputs-phase4-o4e branch from a1c607b to b7e168b Compare November 26, 2026 20:53
@iamfatness
iamfatness marked this pull request as ready for review November 26, 2026 21:41
@iamfatness
iamfatness merged commit 250618a into main Nov 26, 2026
18 checks passed
@iamfatness
iamfatness deleted the mac-outputs-phase4-o4e branch November 26, 2026 21:41
iamfatness pushed a commit that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

# Conflicts:
#	mac-shell/Sources/CoreVideoProShell/ShellTests.swift
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