Skip to content

Conversation

@chenosaurus
Copy link
Contributor

No description provided.

@chenosaurus chenosaurus changed the title Enable H265 encoding with nvenc Enable H265 encoding & decoding on Nvidia GPU Nov 1, 2025
@chenosaurus chenosaurus requested a review from Copilot November 1, 2025 21:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +66 to 74
}

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);
}
}
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
}
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;
}

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +112
}
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());
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
}
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;

Copilot uses AI. Check for mistakes.
Comment on lines +93 to +94


Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

Remove extra blank line at end of file (line 93).

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +380 to +381


Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

Remove extra blank line at end of file (line 380).

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +47


Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

Remove extra blank line at end of file (line 46).

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +161 to +162


Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

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

Remove extra blank line at end of file (line 161).

Suggested change

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@cloudwebrtc cloudwebrtc left a comment

Choose a reason for hiding this comment

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

lgtm!

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.

3 participants