blob: 096388689481ee354c4ae09016377908b8376b79 [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;
56 h264_settings.spsData = nullptr;
57 h264_settings.spsLen = 0;
58 h264_settings.ppsData = nullptr;
59 h264_settings.ppsLen = 0;
60 h264_settings.profile = H264::kProfileConstrainedBaseline;
61
62 return h264_settings;
63}
64
Niels Möller225c7872018-02-22 15:03:53 +010065VideoEncoder::ScalingSettings::ScalingSettings() = default;
mflodman351424e2017-08-10 02:43:14 -070066
Niels Möller225c7872018-02-22 15:03:53 +010067VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
68
69VideoEncoder::ScalingSettings::ScalingSettings(int low, int high)
70 : thresholds(QpThresholds(low, high)) {}
71
72VideoEncoder::ScalingSettings::ScalingSettings(int low,
asapersson142fcc92017-08-17 08:58:54 -070073 int high,
74 int min_pixels)
Niels Möller225c7872018-02-22 15:03:53 +010075 : thresholds(QpThresholds(low, high)), min_pixels_per_frame(min_pixels) {}
asapersson142fcc92017-08-17 08:58:54 -070076
Niels Möller225c7872018-02-22 15:03:53 +010077VideoEncoder::ScalingSettings::ScalingSettings(const ScalingSettings&) =
78 default;
mflodman351424e2017-08-10 02:43:14 -070079
80VideoEncoder::ScalingSettings::~ScalingSettings() {}
81
Niels Möller225c7872018-02-22 15:03:53 +010082// static
83constexpr VideoEncoder::ScalingSettings::KOff
84 VideoEncoder::ScalingSettings::kOff;
mflodman351424e2017-08-10 02:43:14 -070085
Erik Språnge2fd86a2018-10-24 11:32:39 +020086VideoEncoder::EncoderInfo::EncoderInfo()
87 : scaling_settings(VideoEncoder::ScalingSettings::kOff),
88 supports_native_handle(false),
89 implementation_name("unknown") {}
90
Erik Språnge2fd86a2018-10-24 11:32:39 +020091VideoEncoder::EncoderInfo::~EncoderInfo() = default;
92
mflodman351424e2017-08-10 02:43:14 -070093int32_t VideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) {
94 RTC_NOTREACHED() << "SetRate(uint32_t, uint32_t) is deprecated.";
95 return -1;
96}
97
98int32_t VideoEncoder::SetRateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +020099 const VideoBitrateAllocation& allocation,
mflodman351424e2017-08-10 02:43:14 -0700100 uint32_t framerate) {
101 return SetRates(allocation.get_sum_kbps(), framerate);
102}
103
104VideoEncoder::ScalingSettings VideoEncoder::GetScalingSettings() const {
Niels Möller225c7872018-02-22 15:03:53 +0100105 return ScalingSettings::kOff;
mflodman351424e2017-08-10 02:43:14 -0700106}
107
mflodman351424e2017-08-10 02:43:14 -0700108bool VideoEncoder::SupportsNativeHandle() const {
109 return false;
110}
111
112const char* VideoEncoder::ImplementationName() const {
113 return "unknown";
114}
Erik Språnge2fd86a2018-10-24 11:32:39 +0200115
Erik Språngff7020a2018-11-06 15:32:48 +0100116// TODO(webrtc:9722): Remove and make pure virtual when the three legacy
117// methods called here are gone.
Erik Språnge2fd86a2018-10-24 11:32:39 +0200118VideoEncoder::EncoderInfo VideoEncoder::GetEncoderInfo() const {
Erik Språngff7020a2018-11-06 15:32:48 +0100119 EncoderInfo info;
120 info.scaling_settings = GetScalingSettings();
121 info.supports_native_handle = SupportsNativeHandle();
122 info.implementation_name = ImplementationName();
123 return info;
Erik Språnge2fd86a2018-10-24 11:32:39 +0200124}
philipelee49f702018-11-05 17:30:22 +0100125
126int32_t VideoEncoder::SetChannelParameters(uint32_t packet_loss, int64_t rtt) {
127 return 0;
128}
mflodman351424e2017-08-10 02:43:14 -0700129} // namespace webrtc