Unify hardware decoding through DecoderOptions - #45
Merged
Conversation
Let network and image-sequence entry points accept the complete DecoderOptions contract while keeping protocol and sequence settings separate. Add cancellable network construction and verify merge precedence and caller ownership. Assisted-by: OpenAI Codex
Bind codec iteration, decoder classification, hardware configuration discovery, hardware device enumeration, and frame property copying. Keep every directly accessed AVCodec and AVCodecHWConfig field in the central ABI table and verify the offsets across supported release families. Assisted-by: OpenAI Codex
Route hardware acceleration through DecoderOptions and the normal Decoder lifecycle. Enumerate compatible codecs and device configurations, prefer platform-native backends, transfer GPU frames to reusable system memory, and make automatic fallback observable while preserving a required mode. Remove the duplicated public HWDecoder state machine. Decoder owns automatically created devices and borrows caller-provided devices through retained FFmpeg buffer references. Assisted-by: OpenAI Codex
Cover deep option cloning, automatic fallback diagnostics, required-mode failures at open and lazy initialization, and the unified explicit-device path. Document capability-driven selection, ownership, system-memory output, and the absence of a separate hardware decoder API. Assisted-by: OpenAI Codex
Create at most one owned device for each hardware type while trying compatible decoder implementations. This avoids repeated native allocations and duplicate probe failures without changing borrowed-device ownership. Assisted-by: OpenAI Codex
Exercise automatic hardware selection or software fallback while repeatedly opening, decoding, seeking, and closing audiovisual streams. Keep the extended torture loop opt-in for local validation. Assisted-by: OpenAI Codex
mcuadros
marked this pull request as ready for review
August 16, 2026 19:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DecoderandDecoderOptions.VideoDecoderInfo.Behavior
DecoderOptions.Hardwarecontrols video hardware acceleration:nilkeeps software decoding.&HWDecoderConfig{}enables automatic platform-aware selection with software fallback.HardwareAccelerationRequiredreturnsErrHardwareAccelerationUnavailableinstead of falling back.HardwareAccelerationDisabledexplicitly requests software decoding.HWDevicevalues are borrowed; automatically created devices are owned by the decoder.Frames returned by the regular decoder API remain CPU-accessible. GPU-backed frames are transferred to reusable system memory, while wrapper decoders that already return CPU-backed frames avoid that transfer.
VideoDecoderInforeports pending, selected, active, and fallback states because some FFmpeg accelerators initialize lazily during the first decode operation.Breaking changes
The separate
HWDecoderAPI andNewHWDecoderconstructor are removed. Hardware acceleration now uses the regular decoder:Specialized constructors now receive normal decoder options separately from their specific configuration:
This keeps stream selection, probing, raw FFmpeg options, and hardware policy consistent across decoder entry points.
Validation
go test ./...go test -race ./...go vet ./...golangci-lint1.64.8Network option merging and cancellation routing are covered deterministically. The test suite does not depend on an external streaming service.