blob: 43f959ba5afb637ed0f60cc70fc7e569dcd1fdf7 [file] [log] [blame]
mflodman351424e2017-08-10 02:43:14 -07001/*
2 * Copyright (c) 2017 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 "api/video_codecs/video_encoder.h"
mflodman351424e2017-08-10 02:43:14 -070012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <string.h>
14
15#include "rtc_base/checks.h"
16
mflodman351424e2017-08-10 02:43:14 -070017namespace webrtc {
18
19// TODO(mflodman): Add default complexity for VP9 and VP9.
20VideoCodecVP8 VideoEncoder::GetDefaultVp8Settings() {
21 VideoCodecVP8 vp8_settings;
22 memset(&vp8_settings, 0, sizeof(vp8_settings));
23
mflodman351424e2017-08-10 02:43:14 -070024 vp8_settings.numberOfTemporalLayers = 1;
25 vp8_settings.denoisingOn = true;
mflodman351424e2017-08-10 02:43:14 -070026 vp8_settings.automaticResizeOn = false;
27 vp8_settings.frameDroppingOn = true;
28 vp8_settings.keyFrameInterval = 3000;
29
30 return vp8_settings;
31}
32
33VideoCodecVP9 VideoEncoder::GetDefaultVp9Settings() {
34 VideoCodecVP9 vp9_settings;
35 memset(&vp9_settings, 0, sizeof(vp9_settings));
36
mflodman351424e2017-08-10 02:43:14 -070037 vp9_settings.numberOfTemporalLayers = 1;
38 vp9_settings.denoisingOn = true;
39 vp9_settings.frameDroppingOn = true;
40 vp9_settings.keyFrameInterval = 3000;
41 vp9_settings.adaptiveQpMode = true;
42 vp9_settings.automaticResizeOn = true;
43 vp9_settings.numberOfSpatialLayers = 1;
44 vp9_settings.flexibleMode = false;
Sergey Silkin6a8f30e2018-04-26 11:03:49 +020045 vp9_settings.interLayerPred = InterLayerPredMode::kOn;
mflodman351424e2017-08-10 02:43:14 -070046
47 return vp9_settings;
48}
49
50VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
51 VideoCodecH264 h264_settings;
52 memset(&h264_settings, 0, sizeof(h264_settings));
53
54 h264_settings.frameDroppingOn = true;
55 h264_settings.keyFrameInterval = 3000;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050056 h264_settings.numberOfTemporalLayers = 1;
mflodman351424e2017-08-10 02:43:14 -070057
58 return h264_settings;
59}
60
Niels Möller225c7872018-02-22 15:03:53 +010061VideoEncoder::ScalingSettings::ScalingSettings() = default;
mflodman351424e2017-08-10 02:43:14 -070062
Niels Möller225c7872018-02-22 15:03:53 +010063VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
64
65VideoEncoder::ScalingSettings::ScalingSettings(int low, int high)
66 : thresholds(QpThresholds(low, high)) {}
67
68VideoEncoder::ScalingSettings::ScalingSettings(int low,
asapersson142fcc92017-08-17 08:58:54 -070069 int high,
70 int min_pixels)
Niels Möller225c7872018-02-22 15:03:53 +010071 : thresholds(QpThresholds(low, high)), min_pixels_per_frame(min_pixels) {}
asapersson142fcc92017-08-17 08:58:54 -070072
Niels Möller225c7872018-02-22 15:03:53 +010073VideoEncoder::ScalingSettings::ScalingSettings(const ScalingSettings&) =
74 default;
mflodman351424e2017-08-10 02:43:14 -070075
76VideoEncoder::ScalingSettings::~ScalingSettings() {}
77
Niels Möller225c7872018-02-22 15:03:53 +010078// static
79constexpr VideoEncoder::ScalingSettings::KOff
80 VideoEncoder::ScalingSettings::kOff;
Erik Språngdbdd8392019-01-17 15:27:50 +010081// static
82constexpr uint8_t VideoEncoder::EncoderInfo::kMaxFramerateFraction;
mflodman351424e2017-08-10 02:43:14 -070083
Erik Språnge2fd86a2018-10-24 11:32:39 +020084VideoEncoder::EncoderInfo::EncoderInfo()
85 : scaling_settings(VideoEncoder::ScalingSettings::kOff),
86 supports_native_handle(false),
Erik Språngd3438aa2018-11-08 16:56:43 +010087 implementation_name("unknown"),
Mirta Dvornicic897a9912018-11-30 13:12:21 +010088 has_trusted_rate_controller(false),
Mirta Dvornicicccc1b572019-01-15 12:42:18 +010089 is_hardware_accelerated(true),
Erik Språngdbdd8392019-01-17 15:27:50 +010090 has_internal_source(false),
91 fps_allocation{absl::InlinedVector<uint8_t, kMaxTemporalStreams>(
92 1,
Erik Språngf4e0c292019-10-01 18:50:03 +020093 kMaxFramerateFraction)},
94 supports_simulcast(false) {}
Mirta Dvornicic897a9912018-11-30 13:12:21 +010095
96VideoEncoder::EncoderInfo::EncoderInfo(const EncoderInfo&) = default;
Erik Språnge2fd86a2018-10-24 11:32:39 +020097
Erik Språnge2fd86a2018-10-24 11:32:39 +020098VideoEncoder::EncoderInfo::~EncoderInfo() = default;
99
Erik Språng4c6ca302019-04-08 15:14:01 +0200100VideoEncoder::RateControlParameters::RateControlParameters()
101 : bitrate(VideoBitrateAllocation()),
102 framerate_fps(0.0),
103 bandwidth_allocation(DataRate::Zero()) {}
104
105VideoEncoder::RateControlParameters::RateControlParameters(
106 const VideoBitrateAllocation& bitrate,
Erik Språng16cb8f52019-04-12 13:59:09 +0200107 double framerate_fps)
108 : bitrate(bitrate),
109 framerate_fps(framerate_fps),
110 bandwidth_allocation(DataRate::bps(bitrate.get_sum_bps())) {}
111
112VideoEncoder::RateControlParameters::RateControlParameters(
113 const VideoBitrateAllocation& bitrate,
Erik Språng4c6ca302019-04-08 15:14:01 +0200114 double framerate_fps,
115 DataRate bandwidth_allocation)
116 : bitrate(bitrate),
117 framerate_fps(framerate_fps),
118 bandwidth_allocation(bandwidth_allocation) {}
119
Evan Shrubsole7c079f62019-09-26 09:55:03 +0200120bool VideoEncoder::RateControlParameters::operator==(
121 const VideoEncoder::RateControlParameters& rhs) const {
122 return std::tie(bitrate, framerate_fps, bandwidth_allocation) ==
123 std::tie(rhs.bitrate, rhs.framerate_fps, rhs.bandwidth_allocation);
124}
125
126bool VideoEncoder::RateControlParameters::operator!=(
127 const VideoEncoder::RateControlParameters& rhs) const {
128 return !(rhs == *this);
129}
130
Erik Språng4c6ca302019-04-08 15:14:01 +0200131VideoEncoder::RateControlParameters::~RateControlParameters() = default;
132
Elad Alon8f01c4e2019-06-28 15:19:43 +0200133void VideoEncoder::SetFecControllerOverride(
134 FecControllerOverride* fec_controller_override) {}
135
Elad Alon370f93a2019-06-11 14:57:57 +0200136int32_t VideoEncoder::InitEncode(const VideoCodec* codec_settings,
137 int32_t number_of_cores,
138 size_t max_payload_size) {
139 const VideoEncoder::Capabilities capabilities(/* loss_notification= */ false);
140 const VideoEncoder::Settings settings(capabilities, number_of_cores,
141 max_payload_size);
142 // In theory, this and the other version of InitEncode() could end up calling
143 // each other in a loop until we get a stack overflow.
144 // In practice, any subclass of VideoEncoder would overload at least one
145 // of these, and we have a TODO in the header file to make this pure virtual.
146 return InitEncode(codec_settings, settings);
147}
148
149int VideoEncoder::InitEncode(const VideoCodec* codec_settings,
150 const VideoEncoder::Settings& settings) {
151 // In theory, this and the other version of InitEncode() could end up calling
152 // each other in a loop until we get a stack overflow.
153 // In practice, any subclass of VideoEncoder would overload at least one
154 // of these, and we have a TODO in the header file to make this pure virtual.
155 return InitEncode(codec_settings, settings.number_of_cores,
156 settings.max_payload_size);
157}
158
Elad Aloncde8ab22019-03-20 11:56:20 +0100159void VideoEncoder::OnPacketLossRateUpdate(float packet_loss_rate) {}
160
161void VideoEncoder::OnRttUpdate(int64_t rtt_ms) {}
162
Elad Alon6c371ca2019-04-04 12:28:51 +0200163void VideoEncoder::OnLossNotification(
164 const LossNotification& loss_notification) {}
165
Erik Språng6ed4f142018-11-26 13:42:39 +0100166// TODO(webrtc:9722): Remove and make pure virtual.
Erik Språnge2fd86a2018-10-24 11:32:39 +0200167VideoEncoder::EncoderInfo VideoEncoder::GetEncoderInfo() const {
Erik Språng6ed4f142018-11-26 13:42:39 +0100168 return EncoderInfo();
Erik Språnge2fd86a2018-10-24 11:32:39 +0200169}
Erik Språng6ed4f142018-11-26 13:42:39 +0100170
mflodman351424e2017-08-10 02:43:14 -0700171} // namespace webrtc