mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/video_codecs/video_encoder.h" |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
| 15 | #include "rtc_base/checks.h" |
| 16 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
| 19 | // TODO(mflodman): Add default complexity for VP9 and VP9. |
| 20 | VideoCodecVP8 VideoEncoder::GetDefaultVp8Settings() { |
| 21 | VideoCodecVP8 vp8_settings; |
| 22 | memset(&vp8_settings, 0, sizeof(vp8_settings)); |
| 23 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 24 | vp8_settings.numberOfTemporalLayers = 1; |
| 25 | vp8_settings.denoisingOn = true; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 26 | vp8_settings.automaticResizeOn = false; |
| 27 | vp8_settings.frameDroppingOn = true; |
| 28 | vp8_settings.keyFrameInterval = 3000; |
| 29 | |
| 30 | return vp8_settings; |
| 31 | } |
| 32 | |
| 33 | VideoCodecVP9 VideoEncoder::GetDefaultVp9Settings() { |
| 34 | VideoCodecVP9 vp9_settings; |
| 35 | memset(&vp9_settings, 0, sizeof(vp9_settings)); |
| 36 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 37 | 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 Silkin | 6a8f30e | 2018-04-26 11:03:49 +0200 | [diff] [blame] | 45 | vp9_settings.interLayerPred = InterLayerPredMode::kOn; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 46 | |
| 47 | return vp9_settings; |
| 48 | } |
| 49 | |
| 50 | VideoCodecH264 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öller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 65 | VideoEncoder::ScalingSettings::ScalingSettings() = default; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 66 | |
Niels Möller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 67 | VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {} |
| 68 | |
| 69 | VideoEncoder::ScalingSettings::ScalingSettings(int low, int high) |
| 70 | : thresholds(QpThresholds(low, high)) {} |
| 71 | |
| 72 | VideoEncoder::ScalingSettings::ScalingSettings(int low, |
asapersson | 142fcc9 | 2017-08-17 08:58:54 -0700 | [diff] [blame] | 73 | int high, |
| 74 | int min_pixels) |
Niels Möller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 75 | : thresholds(QpThresholds(low, high)), min_pixels_per_frame(min_pixels) {} |
asapersson | 142fcc9 | 2017-08-17 08:58:54 -0700 | [diff] [blame] | 76 | |
Niels Möller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 77 | VideoEncoder::ScalingSettings::ScalingSettings(const ScalingSettings&) = |
| 78 | default; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 79 | |
| 80 | VideoEncoder::ScalingSettings::~ScalingSettings() {} |
| 81 | |
Niels Möller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 82 | // static |
| 83 | constexpr VideoEncoder::ScalingSettings::KOff |
| 84 | VideoEncoder::ScalingSettings::kOff; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 85 | |
Erik Språng | e2fd86a | 2018-10-24 11:32:39 +0200 | [diff] [blame] | 86 | VideoEncoder::EncoderInfo::EncoderInfo() |
| 87 | : scaling_settings(VideoEncoder::ScalingSettings::kOff), |
| 88 | supports_native_handle(false), |
| 89 | implementation_name("unknown") {} |
| 90 | |
| 91 | VideoEncoder::EncoderInfo::EncoderInfo(const ScalingSettings& scaling_settings, |
| 92 | bool supports_native_handle, |
| 93 | const std::string& implementation_name) |
| 94 | : scaling_settings(scaling_settings), |
| 95 | supports_native_handle(supports_native_handle), |
| 96 | implementation_name(implementation_name) {} |
| 97 | |
| 98 | VideoEncoder::EncoderInfo::~EncoderInfo() = default; |
| 99 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 100 | int32_t VideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) { |
| 101 | RTC_NOTREACHED() << "SetRate(uint32_t, uint32_t) is deprecated."; |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | int32_t VideoEncoder::SetRateAllocation( |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 106 | const VideoBitrateAllocation& allocation, |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 107 | uint32_t framerate) { |
| 108 | return SetRates(allocation.get_sum_kbps(), framerate); |
| 109 | } |
| 110 | |
| 111 | VideoEncoder::ScalingSettings VideoEncoder::GetScalingSettings() const { |
Niels Möller | 225c787 | 2018-02-22 15:03:53 +0100 | [diff] [blame] | 112 | return ScalingSettings::kOff; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 113 | } |
| 114 | |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 115 | bool VideoEncoder::SupportsNativeHandle() const { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | const char* VideoEncoder::ImplementationName() const { |
| 120 | return "unknown"; |
| 121 | } |
Erik Språng | e2fd86a | 2018-10-24 11:32:39 +0200 | [diff] [blame] | 122 | |
| 123 | VideoEncoder::EncoderInfo VideoEncoder::GetEncoderInfo() const { |
| 124 | return EncoderInfo(GetScalingSettings(), SupportsNativeHandle(), |
| 125 | ImplementationName()); |
| 126 | } |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 127 | } // namespace webrtc |