magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/engine/internaldecoderfactory.h" |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 12 | |
Anders Carlsson | dd8c165 | 2018-01-30 10:32:13 +0100 | [diff] [blame] | 13 | #include "api/video_codecs/sdp_video_format.h" |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 14 | #include "media/base/mediaconstants.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "modules/video_coding/codecs/h264/include/h264.h" |
Anders Carlsson | b330688 | 2018-05-14 10:11:42 +0200 | [diff] [blame] | 16 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
| 17 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/logging.h" |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 20 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 21 | namespace webrtc { |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 22 | |
Magnus Jedvert | d528ad5 | 2018-08-06 10:10:51 +0200 | [diff] [blame^] | 23 | namespace { |
| 24 | |
| 25 | bool IsFormatSupported( |
| 26 | const std::vector<webrtc::SdpVideoFormat>& supported_formats, |
| 27 | const webrtc::SdpVideoFormat& format) { |
| 28 | for (const webrtc::SdpVideoFormat& supported_format : supported_formats) { |
| 29 | if (cricket::IsSameCodec(format.name, format.parameters, |
| 30 | supported_format.name, |
| 31 | supported_format.parameters)) { |
| 32 | return true; |
| 33 | } |
| 34 | } |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | } // namespace |
| 39 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 40 | std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats() |
| 41 | const { |
| 42 | std::vector<SdpVideoFormat> formats; |
| 43 | formats.push_back(SdpVideoFormat(cricket::kVp8CodecName)); |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 44 | for (const SdpVideoFormat& format : SupportedVP9Codecs()) |
| 45 | formats.push_back(format); |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 46 | for (const SdpVideoFormat& h264_format : SupportedH264Codecs()) |
| 47 | formats.push_back(h264_format); |
| 48 | return formats; |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 51 | std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder( |
| 52 | const SdpVideoFormat& format) { |
Magnus Jedvert | d528ad5 | 2018-08-06 10:10:51 +0200 | [diff] [blame^] | 53 | if (!IsFormatSupported(GetSupportedFormats(), format)) { |
| 54 | RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format"; |
| 55 | return nullptr; |
| 56 | } |
| 57 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 58 | if (cricket::CodecNamesEq(format.name, cricket::kVp8CodecName)) |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 59 | return VP8Decoder::Create(); |
Emircan Uysaler | 98badbc | 2018-06-28 10:59:02 -0700 | [diff] [blame] | 60 | if (cricket::CodecNamesEq(format.name, cricket::kVp9CodecName)) |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 61 | return VP9Decoder::Create(); |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 62 | if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName)) |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 63 | return H264Decoder::Create(); |
Magnus Jedvert | d528ad5 | 2018-08-06 10:10:51 +0200 | [diff] [blame^] | 64 | |
| 65 | RTC_NOTREACHED(); |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 66 | return nullptr; |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 69 | } // namespace webrtc |