Enable H265 encoding & decoding on Nvidia GPU - #776
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds H265/HEVC hardware encoding and decoding support to the NVIDIA encoder/decoder factory using NVENC/NVDEC. The implementation mirrors the existing H264 codec support.
Key changes:
- New H265 encoder and decoder implementations with full initialization, encoding/decoding, and rate control logic
- Updated factory classes to support both "H265" and "HEVC" codec names
- Added logging for codec initialization
- Build system updated to compile new H265 source files
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| webrtc-sys/src/nvidia/nvidia_encoder_factory.cpp | Added H265/HEVC format registration and codec-specific encoder instantiation |
| webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp | Added H265/HEVC format registration and codec-specific decoder instantiation with corrected comment |
| webrtc-sys/src/nvidia/h265_encoder_impl.h | New header defining NvidiaH265EncoderImpl class with encoding interfaces |
| webrtc-sys/src/nvidia/h265_encoder_impl.cpp | Full H265 encoder implementation including initialization, encoding, and rate control |
| webrtc-sys/src/nvidia/h265_decoder_impl.h | New header defining NvidiaH265DecoderImpl class with decoding interfaces |
| webrtc-sys/src/nvidia/h265_decoder_impl.cpp | Full H265 decoder implementation including configuration, decoding, and format conversion |
| webrtc-sys/src/nvidia/h264_encoder_impl.cpp | Added initialization logging for consistency |
| webrtc-sys/build.rs | Added H265 source files to build configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| if (format.name == "H265" || format.name == "HEVC") { | ||
| RTC_LOG(LS_INFO) << "Using NVIDIA HW encoder (NVENC) for H265/HEVC"; | ||
| return std::make_unique<NvidiaH265EncoderImpl>( | ||
| env, cu_context_->GetContext(), CU_MEMORYTYPE_DEVICE, | ||
| NV_ENC_BUFFER_FORMAT_IYUV, format); | ||
| } | ||
| } |
There was a problem hiding this comment.
Missing fallback logic after codec-specific checks. If a supported format is matched but is neither H264 nor H265/HEVC, the function will fall through and return nullptr without logging. Add an else clause with error logging or move the return nullptr outside the loop to make the control flow explicit.
| } | |
| if (format.name == "H265" || format.name == "HEVC") { | |
| RTC_LOG(LS_INFO) << "Using NVIDIA HW encoder (NVENC) for H265/HEVC"; | |
| return std::make_unique<NvidiaH265EncoderImpl>( | |
| env, cu_context_->GetContext(), CU_MEMORYTYPE_DEVICE, | |
| NV_ENC_BUFFER_FORMAT_IYUV, format); | |
| } | |
| } | |
| } else if (format.name == "H265" || format.name == "HEVC") { | |
| RTC_LOG(LS_INFO) << "Using NVIDIA HW encoder (NVENC) for H265/HEVC"; | |
| return std::make_unique<NvidiaH265EncoderImpl>( | |
| env, cu_context_->GetContext(), CU_MEMORYTYPE_DEVICE, | |
| NV_ENC_BUFFER_FORMAT_IYUV, format); | |
| } else { | |
| RTC_LOG(LS_ERROR) << "Matched supported format '" << format.name | |
| << "' but no encoder implementation is available for this codec."; | |
| return nullptr; | |
| } |
| } | ||
| if (format.name == "H265" || format.name == "HEVC") { | ||
| RTC_LOG(LS_INFO) << "Using NVIDIA HW decoder (NVDEC) for H265/HEVC"; | ||
| return std::make_unique<NvidiaH265DecoderImpl>(cu_context_->GetContext()); |
There was a problem hiding this comment.
Missing fallback logic after codec-specific checks. If a supported format is matched but is neither H264 nor H265/HEVC, the function will fall through and return nullptr without logging. Add an else clause with error logging or move the return nullptr outside the loop to make the control flow explicit.
| } | |
| if (format.name == "H265" || format.name == "HEVC") { | |
| RTC_LOG(LS_INFO) << "Using NVIDIA HW decoder (NVDEC) for H265/HEVC"; | |
| return std::make_unique<NvidiaH265DecoderImpl>(cu_context_->GetContext()); | |
| } else if (format.name == "H265" || format.name == "HEVC") { | |
| RTC_LOG(LS_INFO) << "Using NVIDIA HW decoder (NVDEC) for H265/HEVC"; | |
| return std::make_unique<NvidiaH265DecoderImpl>(cu_context_->GetContext()); | |
| } else { | |
| RTC_LOG(LS_ERROR) << "Supported format '" << format.name << "' is not handled by NvidiaVideoDecoderFactory."; | |
| return nullptr; |
|
|
||
|
|
There was a problem hiding this comment.
Remove extra blank line at end of file (line 93).
|
|
||
|
|
There was a problem hiding this comment.
Remove extra blank line at end of file (line 380).
|
|
||
|
|
There was a problem hiding this comment.
Remove extra blank line at end of file (line 46).
|
|
||
|
|
There was a problem hiding this comment.
Remove extra blank line at end of file (line 161).
No description provided.