Skip to content

fix: advertise HEVC only when the GPU can decode it - #232

Merged
swellweb merged 2 commits into
swellweb:maint-3.6from
faithpricejp-source:fix/hevc-hw-probe
Nov 12, 2026
Merged

swellweb merged 2 commits into
swellweb:maint-3.6from
faithpricejp-source:fix/hevc-hw-probe

Conversation

@faithpricejp-source

Copy link
Copy Markdown

Problem

tb_dec_supports_hevc_hwdecode() decides whether the receiver advertises supportsHEVCDecode (Bonjour TXT record and display-profile JSON). It only checks that FFmpeg has a VideoToolbox hwaccel config for HEVC and that av_hwdevice_ctx_create() succeeds. Both are true on every Mac, including ones whose GPU has no HEVC decode block. On those Macs VideoToolbox silently falls back to its software HEVC decoder (inside VTDecoderXPCService).

The receiver therefore claims HEVC support, the sender's automatic codec choice picks HEVC, and the iMac decodes every frame on the CPU.

Observed on an iMac15,1 (Late 2014 5K, i5-4690 Haswell, R9 M290X), 5K extended session with automatic codec selection:

  • the sender log shows VTCompressionSession ... codec hvc1
  • on the receiver, VTDecoderXPCService sits at 118–132 % CPU, while TargetBridgeReceiver itself is at ~20 %
  • the pointer and scrolling lag noticeably

Fix

  1. Receiver (decoder.c): on Apple platforms, also require VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC). It has been available since macOS 10.13, so it fits the receiver's 11.0 deployment target. Linux and Windows paths are unchanged.
  2. Sender (chooseCodec): fixing (1) alone would turn a lagging 5K session into no session. Apple Silicon has no hardware H.264 encoder at 5120×2880, HEVC is no longer marked available, so chooseCodec returns nil → "codec unavailable". I added a last-resort branch: if neither path is available but the sender can hardware-encode HEVC, use HEVC (usedFallback: true), software-decoded on the receiver. For these receivers 5K behaves exactly as before. Sizes that H.264 can encode (≤ 4K) now get H.264, which the receiver decodes in hardware.

Verification

I built a tiny harness that links decoder.c and prints tb_dec_supports_hevc_hwdecode(), once against maint-3.6 and once against this branch:

Machine before after
iMac15,1 (Haswell), macOS 11.7.11 1 0
Mac Studio M3 Ultra, macOS 27.2 1 1

A direct VideoToolbox probe on the same iMac (decode sessions created with kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder) confirms the hardware limits:

codec resolution hardware decoder
H.264 2560×1440 / 3840×2160 / 4096×2304 yes (229 / 164 / 143 fps)
H.264 5120×2880 no (-12913)
HEVC 3840×2160 / 5120×2880 no (-12906)

So on this class of Mac, a codec choice that respects the corrected flag lands on hardware decode at up to 4096×2304. 5K stays CPU-bound either way, but it is no longer forced onto the CPU by a false capability flag.

Tests:

  • Receiver: make builds cleanly with no new warnings; make test passes.
  • Sender: xcodebuild test passes for TBSenderAutomationParsingTests (55 tests). The new test testCodecSelectionUsesSoftwareDecodedHEVCWhenH264CannotEncodeTheSize fails without the chooseCodec change and passes with it. The existing testCodecSelectionFailsCleanlyWhenNoHardwarePathExists (no HEVC encoder either) still returns nil.

Caveat on the test setup: the official x86_64 receiver package does not launch on Big Sur (#167), so the iMac numbers come from a receiver built locally against FFmpeg 8.1.2 targeting macOS 11. I could not test an OCLP macOS 14 install. VTIsHardwareDecodeSupported reports the GPU's capability, so the same result is expected there, but that has not been verified.

FYI, while investigating this I also built a separate experiment for these iMacs that avoids video codecs entirely: BC7 texture tiles, decoded by the receiver GPU. It gives native 5K with ~0 % receiver CPU. Code and measurements: https://github.com/faithpricejp-source/imac-bcdisplay. Happy to discuss in an issue if a transport like that is of interest for TargetBridge.

🤖 Generated with Claude Code

faithpricejp-source and others added 2 commits November 3, 2026 13:35
tb_dec_supports_hevc_hwdecode() only checked that FFmpeg has a VideoToolbox
hwaccel config and that a hwdevice context can be created. Both succeed on
Macs without an HEVC decode block, where VideoToolbox silently falls back to
its software decoder. The receiver then advertised supportsHEVCDecode=1 and
the sender's automatic codec choice picked HEVC, which a 2014 iMac 5K can
only decode on the CPU (VTDecoderXPCService at ~120% CPU, laggy pointer).

Ask VideoToolbox directly with VTIsHardwareDecodeSupported (macOS 10.13+).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…size

With the receiver now advertising HEVC only when it has a hardware decoder,
an automatic 5K session to e.g. a Haswell iMac would find no codec at all:
Apple Silicon has no hardware H.264 encoder at 5120x2880, and HEVC is no
longer marked available. Fall back to HEVC (software-decoded on the receiver)
so such sessions keep working exactly as before, while sizes H.264 can encode
now get hardware-decoded H.264.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants