2017-08-10 02:43:14 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video_codecs/video_encoder.h"
|
2017-08-10 02:43:14 -07:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
|
2017-08-10 02:43:14 -07:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// TODO(mflodman): Add default complexity for VP9 and VP9.
|
|
|
|
|
VideoCodecVP8 VideoEncoder::GetDefaultVp8Settings() {
|
|
|
|
|
VideoCodecVP8 vp8_settings;
|
|
|
|
|
memset(&vp8_settings, 0, sizeof(vp8_settings));
|
|
|
|
|
|
|
|
|
|
vp8_settings.numberOfTemporalLayers = 1;
|
|
|
|
|
vp8_settings.denoisingOn = true;
|
|
|
|
|
vp8_settings.automaticResizeOn = false;
|
|
|
|
|
vp8_settings.frameDroppingOn = true;
|
|
|
|
|
vp8_settings.keyFrameInterval = 3000;
|
|
|
|
|
|
|
|
|
|
return vp8_settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoCodecVP9 VideoEncoder::GetDefaultVp9Settings() {
|
|
|
|
|
VideoCodecVP9 vp9_settings;
|
|
|
|
|
memset(&vp9_settings, 0, sizeof(vp9_settings));
|
|
|
|
|
|
|
|
|
|
vp9_settings.numberOfTemporalLayers = 1;
|
|
|
|
|
vp9_settings.denoisingOn = true;
|
|
|
|
|
vp9_settings.frameDroppingOn = true;
|
|
|
|
|
vp9_settings.keyFrameInterval = 3000;
|
|
|
|
|
vp9_settings.adaptiveQpMode = true;
|
|
|
|
|
vp9_settings.automaticResizeOn = true;
|
|
|
|
|
vp9_settings.numberOfSpatialLayers = 1;
|
|
|
|
|
vp9_settings.flexibleMode = false;
|
2018-04-26 11:03:49 +02:00
|
|
|
vp9_settings.interLayerPred = InterLayerPredMode::kOn;
|
2017-08-10 02:43:14 -07:00
|
|
|
|
|
|
|
|
return vp9_settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
|
|
|
|
|
VideoCodecH264 h264_settings;
|
|
|
|
|
memset(&h264_settings, 0, sizeof(h264_settings));
|
|
|
|
|
|
|
|
|
|
h264_settings.frameDroppingOn = true;
|
|
|
|
|
h264_settings.keyFrameInterval = 3000;
|
2019-02-08 14:25:40 -05:00
|
|
|
h264_settings.numberOfTemporalLayers = 1;
|
2017-08-10 02:43:14 -07:00
|
|
|
|
|
|
|
|
return h264_settings;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 15:03:53 +01:00
|
|
|
VideoEncoder::ScalingSettings::ScalingSettings() = default;
|
2017-08-10 02:43:14 -07:00
|
|
|
|
2018-02-22 15:03:53 +01:00
|
|
|
VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
|
|
|
|
|
|
|
|
|
|
VideoEncoder::ScalingSettings::ScalingSettings(int low, int high)
|
|
|
|
|
: thresholds(QpThresholds(low, high)) {}
|
|
|
|
|
|
|
|
|
|
VideoEncoder::ScalingSettings::ScalingSettings(int low,
|
2017-08-17 08:58:54 -07:00
|
|
|
int high,
|
|
|
|
|
int min_pixels)
|
2018-02-22 15:03:53 +01:00
|
|
|
: thresholds(QpThresholds(low, high)), min_pixels_per_frame(min_pixels) {}
|
2017-08-17 08:58:54 -07:00
|
|
|
|
2018-02-22 15:03:53 +01:00
|
|
|
VideoEncoder::ScalingSettings::ScalingSettings(const ScalingSettings&) =
|
|
|
|
|
default;
|
2017-08-10 02:43:14 -07:00
|
|
|
|
|
|
|
|
VideoEncoder::ScalingSettings::~ScalingSettings() {}
|
|
|
|
|
|
2018-02-22 15:03:53 +01:00
|
|
|
// static
|
|
|
|
|
constexpr VideoEncoder::ScalingSettings::KOff
|
|
|
|
|
VideoEncoder::ScalingSettings::kOff;
|
2019-01-17 15:27:50 +01:00
|
|
|
// static
|
|
|
|
|
constexpr uint8_t VideoEncoder::EncoderInfo::kMaxFramerateFraction;
|
2017-08-10 02:43:14 -07:00
|
|
|
|
2018-10-24 11:32:39 +02:00
|
|
|
VideoEncoder::EncoderInfo::EncoderInfo()
|
|
|
|
|
: scaling_settings(VideoEncoder::ScalingSettings::kOff),
|
|
|
|
|
supports_native_handle(false),
|
2018-11-08 16:56:43 +01:00
|
|
|
implementation_name("unknown"),
|
2018-11-30 13:12:21 +01:00
|
|
|
has_trusted_rate_controller(false),
|
2019-01-15 12:42:18 +01:00
|
|
|
is_hardware_accelerated(true),
|
2019-01-17 15:27:50 +01:00
|
|
|
has_internal_source(false),
|
|
|
|
|
fps_allocation{absl::InlinedVector<uint8_t, kMaxTemporalStreams>(
|
|
|
|
|
1,
|
|
|
|
|
kMaxFramerateFraction)} {}
|
2018-11-30 13:12:21 +01:00
|
|
|
|
|
|
|
|
VideoEncoder::EncoderInfo::EncoderInfo(const EncoderInfo&) = default;
|
2018-10-24 11:32:39 +02:00
|
|
|
|
|
|
|
|
VideoEncoder::EncoderInfo::~EncoderInfo() = default;
|
|
|
|
|
|
2019-04-08 15:14:01 +02:00
|
|
|
VideoEncoder::RateControlParameters::RateControlParameters()
|
|
|
|
|
: bitrate(VideoBitrateAllocation()),
|
|
|
|
|
framerate_fps(0.0),
|
|
|
|
|
bandwidth_allocation(DataRate::Zero()) {}
|
|
|
|
|
|
2019-04-12 13:59:09 +02:00
|
|
|
VideoEncoder::RateControlParameters::RateControlParameters(
|
|
|
|
|
const VideoBitrateAllocation& bitrate,
|
|
|
|
|
double framerate_fps)
|
|
|
|
|
: bitrate(bitrate),
|
|
|
|
|
framerate_fps(framerate_fps),
|
|
|
|
|
bandwidth_allocation(DataRate::bps(bitrate.get_sum_bps())) {}
|
|
|
|
|
|
2019-04-08 15:14:01 +02:00
|
|
|
VideoEncoder::RateControlParameters::RateControlParameters(
|
|
|
|
|
const VideoBitrateAllocation& bitrate,
|
|
|
|
|
double framerate_fps,
|
|
|
|
|
DataRate bandwidth_allocation)
|
|
|
|
|
: bitrate(bitrate),
|
|
|
|
|
framerate_fps(framerate_fps),
|
|
|
|
|
bandwidth_allocation(bandwidth_allocation) {}
|
|
|
|
|
|
2019-09-26 09:55:03 +02:00
|
|
|
bool VideoEncoder::RateControlParameters::operator==(
|
|
|
|
|
const VideoEncoder::RateControlParameters& rhs) const {
|
|
|
|
|
return std::tie(bitrate, framerate_fps, bandwidth_allocation) ==
|
|
|
|
|
std::tie(rhs.bitrate, rhs.framerate_fps, rhs.bandwidth_allocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoEncoder::RateControlParameters::operator!=(
|
|
|
|
|
const VideoEncoder::RateControlParameters& rhs) const {
|
|
|
|
|
return !(rhs == *this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 15:14:01 +02:00
|
|
|
VideoEncoder::RateControlParameters::~RateControlParameters() = default;
|
|
|
|
|
|
2019-06-28 15:19:43 +02:00
|
|
|
void VideoEncoder::SetFecControllerOverride(
|
|
|
|
|
FecControllerOverride* fec_controller_override) {}
|
|
|
|
|
|
2019-06-11 14:57:57 +02:00
|
|
|
int32_t VideoEncoder::InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
int32_t number_of_cores,
|
|
|
|
|
size_t max_payload_size) {
|
|
|
|
|
const VideoEncoder::Capabilities capabilities(/* loss_notification= */ false);
|
|
|
|
|
const VideoEncoder::Settings settings(capabilities, number_of_cores,
|
|
|
|
|
max_payload_size);
|
|
|
|
|
// In theory, this and the other version of InitEncode() could end up calling
|
|
|
|
|
// each other in a loop until we get a stack overflow.
|
|
|
|
|
// In practice, any subclass of VideoEncoder would overload at least one
|
|
|
|
|
// of these, and we have a TODO in the header file to make this pure virtual.
|
|
|
|
|
return InitEncode(codec_settings, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VideoEncoder::InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
const VideoEncoder::Settings& settings) {
|
|
|
|
|
// In theory, this and the other version of InitEncode() could end up calling
|
|
|
|
|
// each other in a loop until we get a stack overflow.
|
|
|
|
|
// In practice, any subclass of VideoEncoder would overload at least one
|
|
|
|
|
// of these, and we have a TODO in the header file to make this pure virtual.
|
|
|
|
|
return InitEncode(codec_settings, settings.number_of_cores,
|
|
|
|
|
settings.max_payload_size);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 11:56:20 +01:00
|
|
|
void VideoEncoder::OnPacketLossRateUpdate(float packet_loss_rate) {}
|
|
|
|
|
|
|
|
|
|
void VideoEncoder::OnRttUpdate(int64_t rtt_ms) {}
|
|
|
|
|
|
2019-04-04 12:28:51 +02:00
|
|
|
void VideoEncoder::OnLossNotification(
|
|
|
|
|
const LossNotification& loss_notification) {}
|
|
|
|
|
|
2018-11-26 13:42:39 +01:00
|
|
|
// TODO(webrtc:9722): Remove and make pure virtual.
|
2018-10-24 11:32:39 +02:00
|
|
|
VideoEncoder::EncoderInfo VideoEncoder::GetEncoderInfo() const {
|
2018-11-26 13:42:39 +01:00
|
|
|
return EncoderInfo();
|
2018-10-24 11:32:39 +02:00
|
|
|
}
|
2018-11-26 13:42:39 +01:00
|
|
|
|
2017-08-10 02:43:14 -07:00
|
|
|
} // namespace webrtc
|