blob: ad3a4be0c6d03ce4e06bf331a9596aedb6c30aae [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
24const char kFlexfecFieldTrialName[] = "WebRTC-FlexFEC-03";
25
26bool IsFlexfecFieldTrialEnabled() {
27 return webrtc::field_trial::FindFullName(kFlexfecFieldTrialName) == "Enabled";
28}
29
30} // namespace
31
magjed509e4fe2016-11-18 01:34:11 -080032InternalEncoderFactory::InternalEncoderFactory() {
33 supported_codecs_.push_back(cricket::VideoCodec(kVp8CodecName));
34 if (webrtc::VP9Encoder::IsSupported())
35 supported_codecs_.push_back(cricket::VideoCodec(kVp9CodecName));
36 if (webrtc::H264Encoder::IsSupported()) {
37 cricket::VideoCodec codec(kH264CodecName);
38 // TODO(magjed): Move setting these parameters into webrtc::H264Encoder
39 // instead.
magjed509e4fe2016-11-18 01:34:11 -080040 codec.SetParam(kH264FmtpProfileLevelId,
41 kH264ProfileLevelConstrainedBaseline);
42 codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1");
magjed509e4fe2016-11-18 01:34:11 -080043 supported_codecs_.push_back(std::move(codec));
44 }
45
46 supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName));
47 supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080048
49 if (IsFlexfecFieldTrialEnabled()) {
50 cricket::VideoCodec flexfec_codec(kFlexfecCodecName);
51 // 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.
55 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
brandtr36e7d702017-01-13 07:15:54 -080056 flexfec_codec.AddFeedbackParam(
57 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
58 flexfec_codec.AddFeedbackParam(
59 FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
brandtr468da7c2016-11-22 02:16:47 -080060 supported_codecs_.push_back(flexfec_codec);
61 }
magjed509e4fe2016-11-18 01:34:11 -080062}
63
64InternalEncoderFactory::~InternalEncoderFactory() {}
65
66// WebRtcVideoEncoderFactory implementation.
67webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder(
68 const cricket::VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080069 const webrtc::VideoCodecType codec_type =
70 webrtc::PayloadNameToCodecType(codec.name)
71 .value_or(webrtc::kVideoCodecUnknown);
72 switch (codec_type) {
magjed509e4fe2016-11-18 01:34:11 -080073 case webrtc::kVideoCodecH264:
magjedceecea42016-11-28 07:20:21 -080074 return webrtc::H264Encoder::Create(codec);
magjed509e4fe2016-11-18 01:34:11 -080075 case webrtc::kVideoCodecVP8:
76 return webrtc::VP8Encoder::Create();
77 case webrtc::kVideoCodecVP9:
78 return webrtc::VP9Encoder::Create();
79 default:
80 return nullptr;
81 }
82}
83
84const std::vector<cricket::VideoCodec>&
85InternalEncoderFactory::supported_codecs() const {
86 return supported_codecs_;
87}
88
89void InternalEncoderFactory::DestroyVideoEncoder(
90 webrtc::VideoEncoder* encoder) {
91 delete encoder;
92}
93
94} // namespace cricket