blob: 23c85cb9565162e07fd7b8efc3f7f0c263f3d32c [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/engine/internalencoderfactory.h"
magjed509e4fe2016-11-18 01:34:11 -080012
13#include <utility>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/video_coding/codecs/h264/include/h264.h"
16#include "modules/video_coding/codecs/vp8/include/vp8.h"
17#include "modules/video_coding/codecs/vp9/include/vp9.h"
18#include "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() {
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020037 supported_codecs_.push_back(VideoCodec(kVp8CodecName));
magjed509e4fe2016-11-18 01:34:11 -080038 if (webrtc::VP9Encoder::IsSupported())
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020039 supported_codecs_.push_back(VideoCodec(kVp9CodecName));
magjed509e4fe2016-11-18 01:34:11 -080040
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020041 for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs())
42 supported_codecs_.push_back(VideoCodec(format));
43
44 supported_codecs_.push_back(VideoCodec(kRedCodecName));
45 supported_codecs_.push_back(VideoCodec(kUlpfecCodecName));
brandtr468da7c2016-11-22 02:16:47 -080046
brandtr340e3fd2017-02-28 15:43:10 -080047 if (IsFlexfecAdvertisedFieldTrialEnabled()) {
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020048 VideoCodec flexfec_codec(kFlexfecCodecName);
brandtr468da7c2016-11-22 02:16:47 -080049 // This value is currently arbitrarily set to 10 seconds. (The unit
50 // is microseconds.) This parameter MUST be present in the SDP, but
51 // we never use the actual value anywhere in our code however.
52 // TODO(brandtr): Consider honouring this value in the sender and receiver.
53 flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000");
54 supported_codecs_.push_back(flexfec_codec);
55 }
magjed509e4fe2016-11-18 01:34:11 -080056}
57
58InternalEncoderFactory::~InternalEncoderFactory() {}
59
60// WebRtcVideoEncoderFactory implementation.
61webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder(
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020062 const VideoCodec& codec) {
magjed10165ab2016-11-22 10:16:57 -080063 const webrtc::VideoCodecType codec_type =
kthelgason1cdddc92017-08-24 03:52:48 -070064 webrtc::PayloadStringToCodecType(codec.name);
magjed10165ab2016-11-22 10:16:57 -080065 switch (codec_type) {
magjed509e4fe2016-11-18 01:34:11 -080066 case webrtc::kVideoCodecH264:
magjedceecea42016-11-28 07:20:21 -080067 return webrtc::H264Encoder::Create(codec);
magjed509e4fe2016-11-18 01:34:11 -080068 case webrtc::kVideoCodecVP8:
69 return webrtc::VP8Encoder::Create();
70 case webrtc::kVideoCodecVP9:
71 return webrtc::VP9Encoder::Create();
72 default:
73 return nullptr;
74 }
75}
76
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020077const std::vector<VideoCodec>&
magjed509e4fe2016-11-18 01:34:11 -080078InternalEncoderFactory::supported_codecs() const {
79 return supported_codecs_;
80}
81
82void InternalEncoderFactory::DestroyVideoEncoder(
83 webrtc::VideoEncoder* encoder) {
84 delete encoder;
85}
86
87} // namespace cricket