blob: 28e336deb03a2679652c77e84f28cb0941bfb6c8 [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) {
67 switch (CodecTypeFromName(codec.name)) {
68 case webrtc::kVideoCodecH264:
69 return webrtc::H264Encoder::Create();
70 case webrtc::kVideoCodecVP8:
71 return webrtc::VP8Encoder::Create();
72 case webrtc::kVideoCodecVP9:
73 return webrtc::VP9Encoder::Create();
74 default:
75 return nullptr;
76 }
77}
78
79const std::vector<cricket::VideoCodec>&
80InternalEncoderFactory::supported_codecs() const {
81 return supported_codecs_;
82}
83
84void InternalEncoderFactory::DestroyVideoEncoder(
85 webrtc::VideoEncoder* encoder) {
86 delete encoder;
87}
88
89} // namespace cricket