blob: 544070fc4c3c7e8b35ea1b7c3086513c4fee1d74 [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
26// "flexfec-03" will appear in the default local SDP, and we therefore need to
27// be ready to receive FlexFEC packets from the remote.
28bool IsFlexfecAdvertisedFieldTrialEnabled() {
29 return webrtc::field_trial::FindFullName("WebRTC-FlexFEC-03-Advertised") ==
30 "Enabled";
brandtr468da7c2016-11-22 02:16:47 -080031}
32
33} // namespace
34
magjed509e4fe2016-11-18 01:34:11 -080035InternalEncoderFactory::InternalEncoderFactory() {
36 supported_codecs_.push_back(cricket::VideoCodec(kVp8CodecName));
37 if (webrtc::VP9Encoder::IsSupported())
38 supported_codecs_.push_back(cricket::VideoCodec(kVp9CodecName));
39 if (webrtc::H264Encoder::IsSupported()) {
40 cricket::VideoCodec codec(kH264CodecName);
41 // TODO(magjed): Move setting these parameters into webrtc::H264Encoder
42 // instead.
magjed509e4fe2016-11-18 01:34:11 -080043 codec.SetParam(kH264FmtpProfileLevelId,
44 kH264ProfileLevelConstrainedBaseline);
45 codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1");
magjed509e4fe2016-11-18 01:34:11 -080046 supported_codecs_.push_back(std::move(codec));
47 }
48
49 supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName));
50 supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080051
brandtr340e3fd2017-02-28 15:43:10 -080052 if (IsFlexfecAdvertisedFieldTrialEnabled()) {
brandtr468da7c2016-11-22 02:16:47 -080053 cricket::VideoCodec flexfec_codec(kFlexfecCodecName);
54 // This value is currently arbitrarily set to 10 seconds. (The unit
55 // is microseconds.) This parameter MUST be present in the SDP, but
56 // we never use the actual value anywhere in our code however.
57 // TODO(brandtr): Consider honouring this value in the sender and receiver.
58 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
brandtr36e7d702017-01-13 07:15:54 -080059 flexfec_codec.AddFeedbackParam(
60 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
61 flexfec_codec.AddFeedbackParam(
62 FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
brandtr468da7c2016-11-22 02:16:47 -080063 supported_codecs_.push_back(flexfec_codec);
64 }
magjed509e4fe2016-11-18 01:34:11 -080065}
66
67InternalEncoderFactory::~InternalEncoderFactory() {}
68
69// WebRtcVideoEncoderFactory implementation.
70webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder(
71 const cricket::VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080072 const webrtc::VideoCodecType codec_type =
73 webrtc::PayloadNameToCodecType(codec.name)
74 .value_or(webrtc::kVideoCodecUnknown);
75 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