blob: e714e5a5d875bbeadd87bfec39360a8beacabd7d [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.
40 // TODO(hta): Set FMTP parameters for all codecs of type H264.
41 codec.SetParam(kH264FmtpProfileLevelId,
42 kH264ProfileLevelConstrainedBaseline);
43 codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1");
44 codec.SetParam(kH264FmtpPacketizationMode, "1");
45 supported_codecs_.push_back(std::move(codec));
46 }
47
48 supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName));
49 supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080050
51 if (IsFlexfecFieldTrialEnabled()) {
52 cricket::VideoCodec flexfec_codec(kFlexfecCodecName);
53 // This value is currently arbitrarily set to 10 seconds. (The unit
54 // is microseconds.) This parameter MUST be present in the SDP, but
55 // we never use the actual value anywhere in our code however.
56 // TODO(brandtr): Consider honouring this value in the sender and receiver.
57 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
58 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(
66 const cricket::VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080067 const webrtc::VideoCodecType codec_type =
68 webrtc::PayloadNameToCodecType(codec.name)
69 .value_or(webrtc::kVideoCodecUnknown);
70 switch (codec_type) {
magjed509e4fe2016-11-18 01:34:11 -080071 case webrtc::kVideoCodecH264:
magjedceecea42016-11-28 07:20:21 -080072 return webrtc::H264Encoder::Create(codec);
magjed509e4fe2016-11-18 01:34:11 -080073 case webrtc::kVideoCodecVP8:
74 return webrtc::VP8Encoder::Create();
75 case webrtc::kVideoCodecVP9:
76 return webrtc::VP9Encoder::Create();
77 default:
78 return nullptr;
79 }
80}
81
82const std::vector<cricket::VideoCodec>&
83InternalEncoderFactory::supported_codecs() const {
84 return supported_codecs_;
85}
86
87void InternalEncoderFactory::DestroyVideoEncoder(
88 webrtc::VideoEncoder* encoder) {
89 delete encoder;
90}
91
92} // namespace cricket