Skip to content

media: apple: prores: fix 1-byte shift in v1 frame header colour offsets - #3713

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
tully-8888:fix/prores-v1-frame-header-offsets
Dec 1, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
tully-8888:fix/prores-v1-frame-header-offsets

Conversation

@tully-8888

@tully-8888 tully-8888 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: Fix a 1-byte shift in the v1 ProRes encode descriptor's frame-header colour offsets (D_FH_PRIMARIES..D_FH_ALPHA in drivers/media/platform/apple/prores/apple-prores-desc.c) and update the KUnit descriptor test to check distinct colour codes (1/16/9) across 0x88..0x8f.

Tested:

  • Reproduced unpatched on a 14-inch MacBook Pro M5 Pro (apple,j714s / apple,t6050, firmware 27.2, linux-aurora 7.3.0-17.v272-24-ARCH): 1920x1080 4:2:2 hardware encode wrote header[12..19] = 80 01 01 01 00 00 00 03, shifting primaries into the SMPTE RDD 36 aspect/frame-rate byte (header[13]) and alpha = 0 into matrix (header[16]), so ffprobe reported color_space=gbr.
  • Verified patched at 2a7359b5d916 by @e-fu on a 14-inch MacBook Pro M4 Pro (apple,j614s / apple,t6040, firmware 27.2, v1 ProRes id 0x40008): header[12..18] changed from 80 01 01 01 00 00 00 (gbr / bt709 / bt709) to 80 00 01 01 01 00 00 (bt709 / bt709 / bt709), 83.6 dB HW vs SW decode, 65.9 dB round trip.

Risk: two-way door · all Macs using apr_build_desc() (v1 ProRes engines: T6041, T8132, T6050, T8140, T8142); T6000 (apr_build_desc_v0()) is untouched.

Not yet: CI KUnit run (prores suite).

Details and evidence

Root cause

apr_build_desc() defined D_FH_PRIMARIES..D_FH_ALPHA at 0x089..0x08c, omitting the SMPTE RDD 36 aspect/frame-rate byte at 0x089 that apr_build_desc_v0() documents at 0x065 (+0x24 base shift from 0x058 to 0x07c) and apr_parse_frame() skips at header[13].

Field header[i] v0 offset (base 0x058) Expected v1 (v0 + 0x24) Previous v1
format [12] 0x064 0x088 0x088
aspect/rate [13] 0x065 0x089 (omitted)
primaries [14] 0x066 0x08a 0x089
transfer [15] 0x067 0x08b 0x08a
matrix [16] 0x068 0x08c 0x08b
alpha [17] 0x069 0x08d 0x08c
flags [19] 0x06b 0x08f 0x08f

Observed unpatched J714s hardware encode (od -A d -t x1 -N 32):

0000000 00 03 a3 2b 69 63 70 66 00 94 00 00 61 75 72 72
0000016 07 80 04 38 80 01 01 01 00 00 00 03 04 04 05 05

header[13..16] is 01 01 01 00 (primaries=1, transfer=1, matrix=1, alpha=0 shifted left by 1 byte). The existing KUnit test masked the shift because apr_test_frame() set primaries = transfer = matrix = 1.

In apr_build_desc() (v1 descriptor), D_FH_PRIMARIES..D_FH_ALPHA were
defined at 0x089..0x08c, omitting the SMPTE RDD 36 aspect/frame-rate
byte at 0x089 (which apr_build_desc_v0() leaves at 0x065 and
apr_parse_frame() skips at header[13]). As a result, v1 hardware
encodes on T6050 (J714s M5 Pro) signalled frame-rate code 1 (23.976 fps)
at header[13] and wrote the constant alpha byte (0) into the matrix
slot at header[16], causing decoders/ffprobe to report color_space=gbr.

Shift D_FH_PRIMARIES..D_FH_ALPHA up by one byte to 0x08a..0x08d so
0x089 stays zero (unspecified aspect/rate), matching SMPTE RDD 36 and
apr_build_desc_v0(). Update the KUnit test to use distinct colour codes
(1, 16, 9) and assert every byte from format (0x88) through flags (0x8f).

Signed-off-by: vlad <[email protected]>
@e-fu

e-fu commented Dec 1, 2026

Copy link
Copy Markdown

Hardware encode row from 2a7359b5d916 on a 14-inch MacBook Pro M4 Pro (J614s, T6040, system firmware 27.2, kernel 7.3.0-47 plus local cherry-picks). The ProRes block loads prores-t6041-init.bin and reports id 0x40008, so it uses the v1 apr_build_desc() path. I built apple-prores.ko out of tree from this head's drivers/media/platform/apple/prores/ (the other files there match my tree) and swapped it in with rmmod/insmod.

Encode: ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=30 -t 1 -pix_fmt nv16 -c:v prores_v4l2m2m out.mov

Module header[12..18] ffprobe color_space / primaries / transfer
unpatched (my -47 build) 80 01 01 01 00 00 00 gbr / bt709 / bt709
2a7359b5d916 80 00 01 01 01 00 00 bt709 / bt709 / bt709

header[13] = 0x00 and header[16] = 0x01, as expected. Untagged input and input tagged with -colorspace bt709 give the same bytes.

The picture is unchanged. A raw NV16 round trip (30 frames, 1080p) gives 65.9 dB with the software decoder and 65.6 dB with prores_v4l2m2m. Hardware decode against software decode of the new file is 83.6 dB, about the same as before the fix (83 dB).

I did not run the KUnit test.

@tully-8888
tully-8888 marked this pull request as ready for review December 1, 2026 10:40
@tully-8888
tully-8888 requested review from a team as code owners December 1, 2026 10:40
@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 2a7359b5: not ready yet

Check Detail
CI at head no failing: host-tests, KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 2a7359b5
Conflicts ok none
PR text ok Risk: two-way · all Macs using aprbuilddesc() (v1 ProRes engines: T6041, T8132, T6050, T8140, T8142); T6000 (aprbuilddescv0()) is untouched.

Areas: area:media

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@tully-8888

Copy link
Copy Markdown
Contributor Author

Additional hardware encode row from 2a7359b5d916 on a 14-inch MacBook Pro M5 Pro (J714s, T6050, system firmware 27.2 / 26B123, kernel 7.3.0-j714s-test+ built on a17872841 with this commit):

  • Device: apple-prores 48d000000.prores (id 0x40018, /dev/video11), 640x480 NV16 (V4L2_COLORSPACE_REC709, V4L2_XFER_FUNC_709, V4L2_YCBCR_ENC_709, V4L2_QUANTIZATION_LIM_RANGE) -> PRES (3014 bytes)
  • Frame header [0..23]: 00 94 00 00 61 75 72 72 02 80 01 e0 80 00 01 01 01 00 00 03 04 04 05 05
    • header[13] (reserved) = 0x00
    • header[14] (primaries) = 0x01
    • header[15] (transfer) = 0x01
    • header[16] (matrix) = 0x01
  • ffprobe on muxed .mov: codec_name=prores, pix_fmt=yuv422p10le, color_primaries=bt709, color_transfer=bt709, color_space=bt709

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The v1 descriptor now places primaries, transfer, matrix and alpha after the reserved byte. The new distinct test values catch the offset error, and the v0 layout is unchanged. The exact-head J614s and J714s encodes both confirm the corrected header. The hosted ProRes KUnit check still needs a result.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 2a7359b5d916 (B2 merge train, 12-01 merge bar). Approval at this head: DjDeveloperr. Row: the hardware row at 2a7359b that the readiness check found (PR body or comment). CI: train L12 = main 645b086 + #3595 #3777 #3713 #3508 #3491: Apple build + DTBs pass, KUnit dcp-fabric/dcp-topology/dcp-display/prores/asahi pass, host tests apple-dcp/dcp/g16 93 ok; hosted reds at these heads = Ubuntu apt outage (Install the tools exit 100) or main's known ave/brcmf host-test fails Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit ae9d644 into aurora-silicon:main Dec 1, 2026
12 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants