Skip to content

WIP: HEVC encoder, guest side: kernel gen codec, the archive in kernel.kc, device faults fixed, a real stand-in for the PC - #59

Draft
akshaynexus wants to merge 3 commits into
mainfrom
hevc-guest
Draft

akshaynexus wants to merge 3 commits into
mainfrom
hevc-guest

Conversation

@akshaynexus

Copy link
Copy Markdown
Owner

Follows #48 (the host side). Draft: stopped by the owner before the PC boot finished. Do not merge yet.

Done and tested (Linux PC)

  • oneios-tool kernel gen codec builds liboneioscodec.a (UniXNU-droidvm's DroidVMVirtioMedia.c, DroidVMVTParavirt.cpp, DroidVMVTHost.cpp with one edit, OneiOSCodec.c); kernel/build-hosted.sh builds it after audio and force-loads it. cargo test ... --test golden 13 of 13; compare-golden.sh the same after UPDATE=1.
  • Kernel built here: xnu.macho 972b9132...; kernel.kc e4ffcabd1d95f25eb542b7226be3235ac2317743d667f22dcc094a5b59198d8b, audit: 2711 paired, 93 functions on the stub, 9 data unpaired; 0 failures; prelink stubs-check: 666 good, 0 bad. No pairing record was needed.
  • Four faults of the host device against the real guest transport, fixed (each would have stopped the first encode on the phone; encoder: real HEVC/HEIC host path so CMPhoto writes HEIC (widget snapshots) #48's test guest shared the assumptions): MMAP answered the guest address where the guest expects the place in the pool; CLOSE (sent with no answer buffer) was dropped, so no session ever closed; ENUM_FMT answered nothing; an oversized coded unit errored at every poll. The device's worker no longer polls 50 times a second when nobody uses it.
  • The hvcC's profile, tier and level were copied from the SPS with its emulation prevention bytes (level 0 in every hvcC); fixed in the staged DroidVMVTHost.cpp.
  • The PC stand-in encoder writes a real stream (HEVC I_PCM at the bit depth that fits the guest's buffer; H.264 I_PCM or grey): make -C runtime/bridges/encoder test: 173 checks, ffmpeg decodes all 16 streams to exactly the picture given, and 214 device checks (through the helper process and in process). xnuhost runs it with encoder=auto when the bridges are off (a PC boot) and with encoder=sim; xnuhost unit tests 14036 checks.
  • Android binaries built here with the NDK and packaged by runtime/package.sh (ELF and Apple-file checks pass): bin/oneios-encoder 28,184 bytes, bin/encctl 29,824 bytes as packaged before the last encctl change (the stage rebuilt after it passed the same checks).
  • A PC boot with --set encoder=auto, its first 40 s:
    xnuhost I encoder: on: stand-in backend, media pool 48 MiB at 0x20fbe04000 (2 session slots)
    guest     ONEIOS CODEC: 1 virtio-media device(s), 1 up; VideoToolbox paravirtualization registered (stage 2)
    guest     ONEIOS CODEC: device 0: oneios-encoder caps 0x4004000 out: NV12 cap: HEVC H264
    

Changed but unproven

  • That iOS takes the service: no process was seen opening it (the boot was ended at 40 s). OneiOSCodec.c's counters, message and session lines are there to show it.
  • The IOSurface lookup offsets and the encode path of DroidVMVTHost.cpp on this iPhone build (upstream proved them on iPadOS 27).
  • Everything on the phone: backend_ndk.c (NV12 ByteBuffer input to c2.qti.hevc.encoder), the helper, encctl.
  • The Mac's commands in the READMEs are from the docs, not run.

Still to do

  1. Next step: the PC boot to the home screen with encoder=auto and the same boot without it; count chronod's CMPhotoCompressionSessionAddImage ... 'hvc1' errors and WidgetRenderer's Content load failed in oneios-tool ioslog for both. Three finished PC boots of other work have neither line at all, so the PC may not reach the widget snapshot without a GPU; then only the phone can show the count.
  2. On the phone (the Mac): encctl hevc, encctl h264 640 480 as root, then a session with encoder=auto (runtime/bridges/encoder/README.md, "On the phone"; kernel/patches/oneios-hosted/codec/README.md, "What a session on the phone must show").
  3. Limits to look at after the first session: a frame above about 2.7 megapixels gets no encoder (the pool's two slots).

🤖 Generated with Claude Code

akshaynexus and others added 3 commits November 15, 2026 19:55
…kernel.kc, four device faults fixed, a real stand-in encoder for the PC

Stopped by the owner before the PC boot finished: built and tested as below, the iOS-side proof is not done.

Guest (kernel):
- oneios-tool kernel gen codec (build_oneios_codec.rs, staged/codec.rs): liboneioscodec.a from UniXNU-droidvm's
  DroidVMVirtioMedia.c, DroidVMVTParavirt.cpp (late object), DroidVMVTHost.cpp (staged with one edit) and
  OneiOSCodec.c; kernel/build-hosted.sh builds it after audio and force-loads it.
- The edit: the hvcC's profile, tier and level bytes were copied from the SPS with its emulation prevention bytes,
  which every HEVC SPS has there (level 0 and 03 bytes as flags in the hvcC); taken without them.
- OneiOSCodec.c: the start line says "registered" only at stage 2; the device's own line; every 30 s while a figure
  moves the counters, the messages (process, type) and DroidVMVTHost's session lines.

Host (runtime/bridges/encoder), read against the real guest transport:
- MMAP answered the buffer's guest address; the guest expects its place in the pool (every buffer was refused).
- CLOSE comes with no answer buffer and was dropped: no session ever closed, two slots, gone after one encode.
- ENUM_FMT answered nothing; a coded unit larger than the guest's buffer came back as an error at every poll.
- The worker polled its backend 50 times a second for ever; it sleeps until a command with no session open.
- The stand-in encoder writes a real stream: HEVC with I_PCM coding units (the standard's CABAC encoder for
  part_mode and the terminating bins) at the PCM bit depth that fits the guest's buffer, H.264 I_PCM or grey.
- xnuhost: encoder=auto with the bridges off (a PC boot) and encoder=sim run the stand-in inside xnuhost; in a
  session auto stays the MediaCodec helper. encctl: MMAP and CLOSE as the guest does, NAL types, an output file.

Tested on the Linux PC: make -C runtime/bridges/encoder test (test_standin 173 checks, ffmpeg decodes its 16
streams to exactly the picture given, test_encoder 214 checks through the helper and in process); xnuhost unit
tests 14036 checks; cargo test golden 13 of 13; the hosted kernel built (xnu.macho 972b9132), kernel.kc e4ffcabd
with audit 0 failures and stubs-check 666 good; compare-golden.sh the same after UPDATE=1 (which no longer removes
golden/synthetic). A PC boot with encoder=auto, its first 40 s: "ONEIOS CODEC: 1 virtio-media device(s), 1 up;
VideoToolbox paravirtualization registered (stage 2)" and "device 0: oneios-encoder caps 0x4004000 out: NV12 cap:
HEVC H264".

Not done: that boot to the home screen, iOS's log (chronod's hvc1 errors, WidgetRenderer's Content load failed)
before and after, the phone.

Docs: hardware.md 7g, booter.md, building.md, the codec and encoder READMEs, the hosted and prelink READMEs,
tools/oneios-tool/README.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main's fix-audio-latency changed the staged audio (speaker ring cap,
output latency 6480 -> 720 frames); keep main's audio lines and add the
guest-side codec lines (build order: audio then codec). No numbered
patch collisions: the codec is an unnumbered archive, main's
0076/0078/0080 kept. Host unit tests after the merge: encoder standin
173/173 with 16 ffmpeg-decoded streams, encoder 214/214; xnuhost 14081
checks 0 failed; cargo test all green including kernel golden 13/13.
The hunk appended at the create() done: label with one line of context
('done:', five of them in the file) and a line number four off pristine,
so git apply refused it and every hosted build after 7b81012 failed at
patch 0080. Anchor it with the four lines that only occur at create()'s
done: (if (shared_region) {, the TRACE_INFO, its format line). No
behaviour change: the inserted block is byte-identical.

Proved by the hevc-guest merge build (HOSTED_OUT=hevc): 0080 applies,
xnu.macho links, compare-golden.sh 17/17 + 11 hashes + stdout, kernel.kc
with audit 0 failures, image set built, 10-min PC boot with encoder=auto
clean (codec registered, cameracaptured 'encs' answered, no panic).
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