From d528ad542e719686441ed00d84320120483548f8 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Mon, 6 Aug 2018 10:10:51 +0200 Subject: [PATCH] Make internal video decoder factory more resilient to incorrect usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If SW H264 is not supported and a client tries to create such a decoder from InternalDecoderFactory, we currently crash. This CL changes so that we log an error and return null from CreateDecoder() instead. Bug: webrtc:7925 Change-Id: I0c495f62dae25ac0bf4931c02527eb9977db3d92 Reviewed-on: https://webrtc-review.googlesource.com/92395 Reviewed-by: Sami Kalliomäki Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#24220} --- media/engine/internaldecoderfactory.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/media/engine/internaldecoderfactory.cc b/media/engine/internaldecoderfactory.cc index 08e29cfa6a..df74773c86 100644 --- a/media/engine/internaldecoderfactory.cc +++ b/media/engine/internaldecoderfactory.cc @@ -20,6 +20,23 @@ namespace webrtc { +namespace { + +bool IsFormatSupported( + const std::vector& supported_formats, + const webrtc::SdpVideoFormat& format) { + for (const webrtc::SdpVideoFormat& supported_format : supported_formats) { + if (cricket::IsSameCodec(format.name, format.parameters, + supported_format.name, + supported_format.parameters)) { + return true; + } + } + return false; +} + +} // namespace + std::vector InternalDecoderFactory::GetSupportedFormats() const { std::vector formats; @@ -33,13 +50,19 @@ std::vector InternalDecoderFactory::GetSupportedFormats() std::unique_ptr InternalDecoderFactory::CreateVideoDecoder( const SdpVideoFormat& format) { + if (!IsFormatSupported(GetSupportedFormats(), format)) { + RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format"; + return nullptr; + } + if (cricket::CodecNamesEq(format.name, cricket::kVp8CodecName)) return VP8Decoder::Create(); if (cricket::CodecNamesEq(format.name, cricket::kVp9CodecName)) return VP9Decoder::Create(); if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName)) return H264Decoder::Create(); - RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format"; + + RTC_NOTREACHED(); return nullptr; }