blob: e55ca914954e3ecc9fdc07592db558f93914fc39 [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"
18#include "system_wrappers/include/field_trial.h"
magjed509e4fe2016-11-18 01:34:11 -080019
20namespace cricket {
21
brandtr468da7c2016-11-22 02:16:47 -080022namespace {
23
brandtr340e3fd2017-02-28 15:43:10 -080024// If this field trial is enabled, the "flexfec-03" codec will be advertised
25// as being supported by the InternalEncoderFactory. This means that
brandtrdbb1be52017-04-26 00:02:34 -070026// "flexfec-03" will appear in the default SDP offer, and we therefore need to
27// be ready to receive FlexFEC packets from the remote. It also means that
28// FlexFEC SSRCs will be generated by MediaSession and added as "a=ssrc:" and
29// "a=ssrc-group:" lines in the local SDP.
brandtr340e3fd2017-02-28 15:43:10 -080030bool IsFlexfecAdvertisedFieldTrialEnabled() {
brandtrdbb1be52017-04-26 00:02:34 -070031 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03-Advertised");
brandtr468da7c2016-11-22 02:16:47 -080032}
33
34} // namespace
35
magjed509e4fe2016-11-18 01:34:11 -080036InternalEncoderFactory::InternalEncoderFactory() {
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020037 supported_codecs_.push_back(VideoCodec(kVp8CodecName));
magjed509e4fe2016-11-18 01:34:11 -080038 if (webrtc::VP9Encoder::IsSupported())
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020039 supported_codecs_.push_back(VideoCodec(kVp9CodecName));
magjed509e4fe2016-11-18 01:34:11 -080040
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020041 for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs())
42 supported_codecs_.push_back(VideoCodec(format));
43
44 supported_codecs_.push_back(VideoCodec(kRedCodecName));
45 supported_codecs_.push_back(VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080046
brandtr340e3fd2017-02-28 15:43:10 -080047 if (IsFlexfecAdvertisedFieldTrialEnabled()) {
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020048 VideoCodec flexfec_codec(kFlexfecCodecName);
brandtr468da7c2016-11-22 02:16:47 -080049 // This value is currently arbitrarily set to 10 seconds. (The unit
50 // is microseconds.) This parameter MUST be present in the SDP, but
51 // we never use the actual value anywhere in our code however.
52 // TODO(brandtr): Consider honouring this value in the sender and receiver.
53 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
brandtr36e7d702017-01-13 07:15:54 -080054 flexfec_codec.AddFeedbackParam(
55 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
56 flexfec_codec.AddFeedbackParam(
57 FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
brandtr468da7c2016-11-22 02:16:47 -080058 supported_codecs_.push_back(flexfec_codec);
59 }
magjed509e4fe2016-11-18 01:34:11 -080060}
61
62InternalEncoderFactory::~InternalEncoderFactory() {}
63
64// WebRtcVideoEncoderFactory implementation.
65webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder(
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020066 const VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080067 const webrtc::VideoCodecType codec_type =
kthelgason1cdddc92017-08-24 03:52:48 -070068 webrtc::PayloadStringToCodecType(codec.name);
magjed10165ab2016-11-22 10:16:57 -080069 switch (codec_type) {
magjed509e4fe2016-11-18 01:34:11 -080070 case webrtc::kVideoCodecH264:
magjedceecea42016-11-28 07:20:21 -080071 return webrtc::H264Encoder::Create(codec);
magjed509e4fe2016-11-18 01:34:11 -080072 case webrtc::kVideoCodecVP8:
73 return webrtc::VP8Encoder::Create();
74 case webrtc::kVideoCodecVP9:
75 return webrtc::VP9Encoder::Create();
76 default:
77 return nullptr;
78 }
79}
80
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020081const std::vector<VideoCodec>&
magjed509e4fe2016-11-18 01:34:11 -080082InternalEncoderFactory::supported_codecs() const {
83 return supported_codecs_;
84}
85
86void InternalEncoderFactory::DestroyVideoEncoder(
87 webrtc::VideoEncoder* encoder) {
88 delete encoder;
89}
90
91} // namespace cricket