blob: c2d4d5eb04684e47d059ab203f8242b207e9f39d [file] [log] [blame]
magjed509e4fe2016-11-18 01:34:11 -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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/engine/internalencoderfactory.h"
magjed509e4fe2016-11-18 01:34:11 -080012
13#include <utility>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/video_coding/codecs/h264/include/h264.h"
16#include "modules/video_coding/codecs/vp8/include/vp8.h"
17#include "modules/video_coding/codecs/vp9/include/vp9.h"
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010018#include "rtc_base/logging.h"
Oleh Prypinda850ef2017-11-16 11:59:29 +000019#include "system_wrappers/include/field_trial.h"
magjed509e4fe2016-11-18 01:34:11 -080020
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010021namespace webrtc {
magjed509e4fe2016-11-18 01:34:11 -080022
Oleh Prypinda850ef2017-11-16 11:59:29 +000023namespace {
24
25// If this field trial is enabled, the "flexfec-03" codec will be advertised
26// as being supported by the InternalEncoderFactory. This means that
27// "flexfec-03" will appear in the default SDP offer, and we therefore need to
28// be ready to receive FlexFEC packets from the remote. It also means that
29// FlexFEC SSRCs will be generated by MediaSession and added as "a=ssrc:" and
30// "a=ssrc-group:" lines in the local SDP.
31bool IsFlexfecAdvertisedFieldTrialEnabled() {
32 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03-Advertised");
33}
34
35} // namespace
36
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010037std::vector<SdpVideoFormat> InternalEncoderFactory::GetSupportedFormats()
38 const {
39 std::vector<SdpVideoFormat> supported_codecs;
40 supported_codecs.push_back(SdpVideoFormat(cricket::kVp8CodecName));
magjed509e4fe2016-11-18 01:34:11 -080041 if (webrtc::VP9Encoder::IsSupported())
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010042 supported_codecs.push_back(SdpVideoFormat(cricket::kVp9CodecName));
magjed509e4fe2016-11-18 01:34:11 -080043
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020044 for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs())
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010045 supported_codecs.push_back(format);
Oleh Prypinda850ef2017-11-16 11:59:29 +000046
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010047 supported_codecs.push_back(SdpVideoFormat(cricket::kRedCodecName));
48 supported_codecs.push_back(SdpVideoFormat(cricket::kUlpfecCodecName));
Oleh Prypinda850ef2017-11-16 11:59:29 +000049
50 if (IsFlexfecAdvertisedFieldTrialEnabled()) {
Oleh Prypinda850ef2017-11-16 11:59:29 +000051 // This value is currently arbitrarily set to 10 seconds. (The unit
52 // is microseconds.) This parameter MUST be present in the SDP, but
53 // we never use the actual value anywhere in our code however.
54 // TODO(brandtr): Consider honouring this value in the sender and receiver.
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010055 SdpVideoFormat::Parameters params = {
56 {cricket::kFlexfecFmtpRepairWindow, "10000000"}};
57 supported_codecs.push_back(
58 SdpVideoFormat(cricket::kFlexfecCodecName, params));
Oleh Prypinda850ef2017-11-16 11:59:29 +000059 }
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010060
61 return supported_codecs;
magjed509e4fe2016-11-18 01:34:11 -080062}
63
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010064VideoEncoderFactory::CodecInfo InternalEncoderFactory::QueryVideoEncoder(
65 const SdpVideoFormat& format) const {
66 CodecInfo info;
67 info.is_hardware_accelerated = false;
68 info.has_internal_source = false;
69 return info;
magjed509e4fe2016-11-18 01:34:11 -080070}
71
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010072std::unique_ptr<VideoEncoder> InternalEncoderFactory::CreateVideoEncoder(
73 const SdpVideoFormat& format) {
74 if (cricket::CodecNamesEq(format.name, cricket::kVp8CodecName))
75 return VP8Encoder::Create();
76
77 if (cricket::CodecNamesEq(format.name, cricket::kVp9CodecName))
78 return VP9Encoder::Create();
79
80 if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName))
81 return H264Encoder::Create(cricket::VideoCodec(format));
82
83 RTC_LOG(LS_ERROR) << "Trying to created encoder of unsupported format "
84 << format.name;
85 return nullptr;
magjed509e4fe2016-11-18 01:34:11 -080086}
87
Magnus Jedvert2c8c8e22017-11-16 16:56:39 +010088} // namespace webrtc