blob: 004db791609647b69981d8397c4e1d5517ba9a32 [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
11#include "webrtc/media/engine/internalencoderfactory.h"
12
13#include <utility>
14
15#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
16#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
17#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
brandtr468da7c2016-11-22 02:16:47 -080018#include "webrtc/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() {
37 supported_codecs_.push_back(cricket::VideoCodec(kVp8CodecName));
38 if (webrtc::VP9Encoder::IsSupported())
39 supported_codecs_.push_back(cricket::VideoCodec(kVp9CodecName));
40 if (webrtc::H264Encoder::IsSupported()) {
41 cricket::VideoCodec codec(kH264CodecName);
42 // TODO(magjed): Move setting these parameters into webrtc::H264Encoder
43 // instead.
magjed509e4fe2016-11-18 01:34:11 -080044 codec.SetParam(kH264FmtpProfileLevelId,
45 kH264ProfileLevelConstrainedBaseline);
46 codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1");
magjed509e4fe2016-11-18 01:34:11 -080047 supported_codecs_.push_back(std::move(codec));
48 }
49
50 supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName));
51 supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080052
brandtr340e3fd2017-02-28 15:43:10 -080053 if (IsFlexfecAdvertisedFieldTrialEnabled()) {
brandtr468da7c2016-11-22 02:16:47 -080054 cricket::VideoCodec flexfec_codec(kFlexfecCodecName);
55 // This value is currently arbitrarily set to 10 seconds. (The unit
56 // is microseconds.) This parameter MUST be present in the SDP, but
57 // we never use the actual value anywhere in our code however.
58 // TODO(brandtr): Consider honouring this value in the sender and receiver.
59 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
brandtr36e7d702017-01-13 07:15:54 -080060 flexfec_codec.AddFeedbackParam(
61 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
62 flexfec_codec.AddFeedbackParam(
63 FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
brandtr468da7c2016-11-22 02:16:47 -080064 supported_codecs_.push_back(flexfec_codec);
65 }
magjed509e4fe2016-11-18 01:34:11 -080066}
67
68InternalEncoderFactory::~InternalEncoderFactory() {}
69
70// WebRtcVideoEncoderFactory implementation.
71webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder(
72 const cricket::VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080073 const webrtc::VideoCodecType codec_type =
kthelgason1cdddc92017-08-24 03:52:48 -070074 webrtc::PayloadStringToCodecType(codec.name);
magjed10165ab2016-11-22 10:16:57 -080075 switch (codec_type) {
magjed509e4fe2016-11-18 01:34:11 -080076 case webrtc::kVideoCodecH264:
magjedceecea42016-11-28 07:20:21 -080077 return webrtc::H264Encoder::Create(codec);
magjed509e4fe2016-11-18 01:34:11 -080078 case webrtc::kVideoCodecVP8:
79 return webrtc::VP8Encoder::Create();
80 case webrtc::kVideoCodecVP9:
81 return webrtc::VP9Encoder::Create();
82 default:
83 return nullptr;
84 }
85}
86
87const std::vector<cricket::VideoCodec>&
88InternalEncoderFactory::supported_codecs() const {
89 return supported_codecs_;
90}
91
92void InternalEncoderFactory::DestroyVideoEncoder(
93 webrtc::VideoEncoder* encoder) {
94 delete encoder;
95}
96
97} // namespace cricket