-
Notifications
You must be signed in to change notification settings - Fork 207
Only advertise internal H264 decode formats if the decoder works #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0506f8
3475c50
9090990
ad71ad1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
| auto decoder = webrtc::H264Decoder::Create(); | ||
|
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 | ||
|
|
@@ -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() | ||
|
|
@@ -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_) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
MaxHeimbrock marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| formats.push_back(webrtc::SdpVideoFormat( | ||
| webrtc::SdpVideoFormat::AV1Profile0(), | ||
|
|
@@ -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) && | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.