blob: 5180b289171bb7658b5b4cddd1848a019813551b [file] [log] [blame]
magjeddd407022016-12-01 00:27:27 -08001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "media/engine/internal_decoder_factory.h"
magjeddd407022016-12-01 00:27:27 -080012
Niels Möller039743e2018-10-23 10:07:25 +020013#include "absl/strings/match.h"
Anders Carlssondd8c1652018-01-30 10:32:13 +010014#include "api/video_codecs/sdp_video_format.h"
Yves Gerey3e707812018-11-28 16:47:49 +010015#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080016#include "media/base/media_constants.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/codecs/h264/include/h264.h"
Anders Carlssonb3306882018-05-14 10:11:42 +020018#include "modules/video_coding/codecs/vp8/include/vp8.h"
19#include "modules/video_coding/codecs/vp9/include/vp9.h"
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010020#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/logging.h"
magjeddd407022016-12-01 00:27:27 -080022
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010023namespace webrtc {
magjeddd407022016-12-01 00:27:27 -080024
Magnus Jedvertd528ad52018-08-06 10:10:51 +020025namespace {
26
27bool IsFormatSupported(
28 const std::vector<webrtc::SdpVideoFormat>& supported_formats,
29 const webrtc::SdpVideoFormat& format) {
30 for (const webrtc::SdpVideoFormat& supported_format : supported_formats) {
31 if (cricket::IsSameCodec(format.name, format.parameters,
32 supported_format.name,
33 supported_format.parameters)) {
34 return true;
35 }
36 }
37 return false;
38}
39
40} // namespace
41
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010042std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
43 const {
44 std::vector<SdpVideoFormat> formats;
45 formats.push_back(SdpVideoFormat(cricket::kVp8CodecName));
Emircan Uysaler98badbc2018-06-28 10:59:02 -070046 for (const SdpVideoFormat& format : SupportedVP9Codecs())
47 formats.push_back(format);
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010048 for (const SdpVideoFormat& h264_format : SupportedH264Codecs())
49 formats.push_back(h264_format);
50 return formats;
magjeddd407022016-12-01 00:27:27 -080051}
52
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010053std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder(
54 const SdpVideoFormat& format) {
Magnus Jedvertd528ad52018-08-06 10:10:51 +020055 if (!IsFormatSupported(GetSupportedFormats(), format)) {
56 RTC_LOG(LS_ERROR) << "Trying to create decoder for unsupported format";
57 return nullptr;
58 }
59
Niels Möller039743e2018-10-23 10:07:25 +020060 if (absl::EqualsIgnoreCase(format.name, cricket::kVp8CodecName))
Magnus Jedvert46a27652017-11-13 14:10:02 +010061 return VP8Decoder::Create();
Niels Möller039743e2018-10-23 10:07:25 +020062 if (absl::EqualsIgnoreCase(format.name, cricket::kVp9CodecName))
Magnus Jedvert46a27652017-11-13 14:10:02 +010063 return VP9Decoder::Create();
Niels Möller039743e2018-10-23 10:07:25 +020064 if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName))
Magnus Jedvert46a27652017-11-13 14:10:02 +010065 return H264Decoder::Create();
Magnus Jedvertd528ad52018-08-06 10:10:51 +020066
67 RTC_NOTREACHED();
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010068 return nullptr;
Christian Fremerey267d84b2017-11-08 23:26:44 +000069}
70
Magnus Jedvert7501b1c2017-11-09 13:43:42 +010071} // namespace webrtc