6.6 KiB
6.6 KiB
AMD AMF AV1 Decoder Design Document
Overview
This document describes the design and implementation of the AMD AMF (Advanced Media Framework) AV1 decoder integration within the VavCore library. The AMF decoder provides hardware-accelerated AV1 decoding on AMD GPUs.
Architecture
Class Hierarchy
IVideoDecoder (interface)
└── AMFAV1Decoder (implementation)
Key Components
- AMFAV1Decoder: Main decoder class implementing IVideoDecoder interface
- VideoDecoderFactory: Factory class extended to support AMF decoder creation
- AMF SDK Integration: Direct integration with AMD AMF SDK headers and libraries
Implementation Details
File Structure
VavCore/src/Decoder/
├── AMFAV1Decoder.h # AMF decoder header
├── AMFAV1Decoder.cpp # AMF decoder implementation
├── VideoDecoderFactory.h # Updated factory header
└── VideoDecoderFactory.cpp # Updated factory implementation
Dependencies
- Headers:
D:\Project\video-av1\include\amf\amf/core/Factory.hamf/core/Context.hamf/components/VideoDecoderUVD.hamf/core/Surface.h
- Libraries:
D:\Project\video-av1\lib\amf\amf.lib(Release)amf-debug.lib(Debug)amf.dll/amf-debug.dll(Runtime)
Core Functionality
Initialization Process
- AMF Library Loading: Load external AMF component via
g_AMFFactory.LoadExternalComponent() - Context Creation: Create AMF context using
CreateContext() - Graphics API Initialization: Initialize DirectX 11 (fallback to DirectX 9)
- Decoder Component Creation: Create AV1 decoder using
AMFVideoDecoderHW_AV1 - Property Configuration: Set decoder properties (surface copy, reorder mode)
Decoding Pipeline
AV1 Packet → AMFBuffer → AMF Decoder → AMFSurface → VideoFrame
- Input Processing: Create AMFBuffer and copy packet data
- Submission: Submit input buffer to decoder via
SubmitInput() - Output Query: Poll for decoded frames using
QueryOutput() - Surface Conversion: Convert AMFSurface to VideoFrame with proper format handling
Surface Format Support
- NV12: Primary format with interleaved UV plane conversion
- YUV420P: Planar YUV 4:2:0 format
- YUV422P: Planar YUV 4:2:2 format (if supported)
- YUV444P: Planar YUV 4:4:4 format (if supported)
Error Handling
AMF Error Codes
Comprehensive mapping of AMF result codes to human-readable messages:
AMF_OK: SuccessAMF_FAIL: General failureAMF_NOT_SUPPORTED: Feature not supportedAMF_NO_DEVICE: No compatible AMD deviceAMF_INPUT_FULL: Input queue full (retry required)AMF_REPEAT: Output not ready (normal for some frames)
Error Recovery
- Initialization Failure: Graceful fallback to other decoders
- Runtime Errors: Frame-level error handling with statistics tracking
- GPU Context Loss: Automatic cleanup and re-initialization capability
Integration with VideoDecoderFactory
Decoder Priority Order (AUTO mode)
- ADAPTIVE_NVDEC: NVIDIA adaptive decoder (highest priority)
- AMF: AMD AMF decoder (new addition)
- ADAPTIVE_DAV1D: dav1d adaptive decoder
- NVDEC: NVIDIA hardware decoder
- DAV1D: dav1d software decoder
- MEDIA_FOUNDATION: Windows Media Foundation (fallback)
Factory Enhancements
- Added
DecoderType::AMFenumeration - Implemented
CheckAMFAvailability()method - Updated decoder creation logic with AMF support
- Added AMF decoder to supported decoders list
Performance Characteristics
Expected Benefits
- Hardware Acceleration: GPU-based decoding for reduced CPU usage
- Low Latency: Optimized for real-time playback scenarios
- Memory Efficiency: Direct GPU memory handling
- Power Efficiency: Lower power consumption compared to software decoding
Potential Limitations
- AMD GPU Requirement: Only works on systems with AMD GPUs
- Driver Dependency: Requires recent AMD graphics drivers with AMF support
- Format Restrictions: Limited to AMF-supported pixel formats
Configuration Options
Decoder Properties
- Surface Copy Mode: Enables CPU access to decoded surfaces
- Reorder Mode: Set to low latency for real-time applications
- Memory Type: Host memory for easier CPU access
Customizable Parameters
- Maximum Resolution: Default 4096x4096, can be adjusted
- Output Format: Configurable surface format preference
Testing and Validation
Availability Testing
bool IsAMFAvailable() const {
amf::AMFFactoryPtr temp_factory;
AMF_RESULT result = amf::g_AMFFactory.LoadExternalComponent(temp_factory, L"AMFFactory");
return (result == AMF_OK && temp_factory);
}
Performance Metrics
- Decode Time Tracking: Per-frame decode time measurement
- Error Rate Monitoring: Failed decode attempts tracking
- Throughput Analysis: Frames per second performance
Future Enhancements
Potential Improvements
- Adaptive Quality Control: Dynamic resolution scaling based on performance
- Multi-GPU Support: Load balancing across multiple AMD GPUs
- Advanced Memory Management: Zero-copy optimization with GPU memory
- HDR Support: High Dynamic Range content decoding
- Hardware-specific Optimizations: RDNA/RDNA2 specific enhancements
Integration Possibilities
- Vulkan Context: Alternative to DirectX for cross-platform support
- OpenCL Integration: Compute shader-based post-processing
- Multi-threaded Decoding: Parallel decode streams
Dependencies and Build Configuration
Required Libraries
# AMF libraries (to be added to VavCore.vcxproj)
target_include_directories(VavCore PRIVATE
"D:/Project/video-av1/include/amf"
)
target_link_libraries(VavCore PRIVATE
debug "D:/Project/video-av1/lib/amf/amf-debug.lib"
optimized "D:/Project/video-av1/lib/amf/amf.lib"
)
Runtime Requirements
- AMD GPU with AMF support (Radeon HD 7000 series or newer)
- AMD graphics driver with AMF runtime (Adrenalin 19.7.1 or newer)
- DirectX 11 runtime (fallback to DirectX 9)
Troubleshooting Guide
Common Issues
- AMF Library Not Found: Check AMD driver installation
- Context Creation Failed: Verify DirectX runtime availability
- Decoder Creation Failed: Confirm AV1 hardware support
- Surface Conversion Errors: Check pixel format compatibility
Debug Output
Comprehensive logging system with categorized messages:
[AMFAV1Decoder]prefix for all decoder messages- AMF error code translation with operation context
- Performance statistics in debug builds
Document Version: 1.0 Last Updated: 2025-09-26 Author: Claude Code Assistant