Make internal video decoder factory more resilient to incorrect usage
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 <sakal@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24220}
This commit is contained in:

committed by
Commit Bot

parent
3ed46bd83b
commit
d528ad542e
@ -20,6 +20,23 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool IsFormatSupported(
|
||||||
|
const std::vector<webrtc::SdpVideoFormat>& 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<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
|
std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
|
||||||
const {
|
const {
|
||||||
std::vector<SdpVideoFormat> formats;
|
std::vector<SdpVideoFormat> formats;
|
||||||
@ -33,13 +50,19 @@ std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
|
|||||||
|
|
||||||
std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder(
|
std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder(
|
||||||
const SdpVideoFormat& format) {
|
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))
|
if (cricket::CodecNamesEq(format.name, cricket::kVp8CodecName))
|
||||||
return VP8Decoder::Create();
|
return VP8Decoder::Create();
|
||||||
if (cricket::CodecNamesEq(format.name, cricket::kVp9CodecName))
|
if (cricket::CodecNamesEq(format.name, cricket::kVp9CodecName))
|
||||||
return VP9Decoder::Create();
|
return VP9Decoder::Create();
|
||||||
if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName))
|
if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName))
|
||||||
return H264Decoder::Create();
|
return H264Decoder::Create();
|
||||||
RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format";
|
|
||||||
|
RTC_NOTREACHED();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user