Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
libwebrtc: patch
livekit: patch
livekit-ffi: patch
webrtc-sys: patch
---

Only advertise internal H264 decode formats if the decoder works - #1313 (@MaxHeimbrock)
1 change: 1 addition & 0 deletions webrtc-sys/include/livekit/video_decoder_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class VideoDecoderFactory : public webrtc::VideoDecoderFactory {

private:
std::vector<std::unique_ptr<webrtc::VideoDecoderFactory>> factories_;
const bool internal_h264_decoder_works_;
};
} // namespace livekit_ffi
48 changes: 43 additions & 5 deletions webrtc-sys/src/video_decoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,36 @@

namespace livekit_ffi {

VideoDecoderFactory::VideoDecoderFactory() {
namespace {
// H264Decoder::IsSupported() only reflects the WEBRTC_USE_H264 build flag;
// desktop prebuilts link an FFmpeg without the H.264 codec, which only
// surfaces when Configure() fails at runtime ("FFmpeg H.264 decoder not
// found"). Probe once so the SDP does not advertise decode support the
// internal decoder cannot deliver.
bool IsInternalH264DecoderAvailable() {
if (!webrtc::H264Decoder::IsSupported()) {
RTC_LOG(LS_WARNING) << "Internal H264 decoder not compiled in "
"(WEBRTC_USE_H264 off)";
return false;
Comment thread
MaxHeimbrock marked this conversation as resolved.
}
auto decoder = webrtc::H264Decoder::Create();
Comment thread
MaxHeimbrock marked this conversation as resolved.
if (!decoder) {
RTC_LOG(LS_WARNING) << "H264Decoder::Create() returned null";
return false;
}
webrtc::VideoDecoder::Settings settings;
settings.set_codec_type(webrtc::kVideoCodecH264);
if (!decoder->Configure(settings)) {
RTC_LOG(LS_WARNING) << "Internal H264 decoder failed to configure; "
"FFmpeg likely lacks the H.264 codec";
return false;
}
return true;
}
} // namespace

VideoDecoderFactory::VideoDecoderFactory()
: internal_h264_decoder_works_(IsInternalH264DecoderAvailable()) {
#ifdef __APPLE__
factories_.push_back(livekit_ffi::CreateObjCVideoDecoderFactory());
#endif
Expand All @@ -55,6 +84,11 @@ VideoDecoderFactory::VideoDecoderFactory() {
factories_.push_back(std::make_unique<webrtc::NvidiaVideoDecoderFactory>());
}
#endif

if (!internal_h264_decoder_works_) {
RTC_LOG(LS_WARNING) << "Internal H264 decoder is unavailable, "
"not advertising its formats";
}
}

std::vector<webrtc::SdpVideoFormat> VideoDecoderFactory::GetSupportedFormats()
Expand All @@ -71,9 +105,12 @@ std::vector<webrtc::SdpVideoFormat> VideoDecoderFactory::GetSupportedFormats()
for (const webrtc::SdpVideoFormat& format :
webrtc::SupportedVP9DecoderCodecs())
formats.push_back(format);
for (const webrtc::SdpVideoFormat& h264_format :
webrtc::SupportedH264DecoderCodecs())
formats.push_back(h264_format);
if (internal_h264_decoder_works_) {

@MaxHeimbrock MaxHeimbrock Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Filter the supported formats based on if a working h264 decoder is present in this lib at runtime.

for (const webrtc::SdpVideoFormat& h264_format :
webrtc::SupportedH264DecoderCodecs()) {
formats.push_back(h264_format);
Comment thread
MaxHeimbrock marked this conversation as resolved.
}
}

formats.push_back(webrtc::SdpVideoFormat(
webrtc::SdpVideoFormat::AV1Profile0(),
Expand Down Expand Up @@ -131,7 +168,8 @@ std::unique_ptr<webrtc::VideoDecoder> VideoDecoderFactory::Create(
return webrtc::CreateVp8Decoder(env);
if (absl::EqualsIgnoreCase(format.name, webrtc::kVp9CodecName))
return webrtc::VP9Decoder::Create();
if (absl::EqualsIgnoreCase(format.name, webrtc::kH264CodecName))
if (absl::EqualsIgnoreCase(format.name, webrtc::kH264CodecName) &&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If at runtime for whatever reason we try to create the decoder and it is not supported, error

internal_h264_decoder_works_)
return webrtc::H264Decoder::Create();


Expand Down
Loading