You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
6.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "api/video_codecs/video_encoder.h"
  11. #include <string.h>
  12. #include "rtc_base/checks.h"
  13. namespace webrtc {
  14. // TODO(mflodman): Add default complexity for VP9 and VP9.
  15. VideoCodecVP8 VideoEncoder::GetDefaultVp8Settings() {
  16. VideoCodecVP8 vp8_settings;
  17. memset(&vp8_settings, 0, sizeof(vp8_settings));
  18. vp8_settings.numberOfTemporalLayers = 1;
  19. vp8_settings.denoisingOn = true;
  20. vp8_settings.automaticResizeOn = false;
  21. vp8_settings.frameDroppingOn = true;
  22. vp8_settings.keyFrameInterval = 3000;
  23. return vp8_settings;
  24. }
  25. VideoCodecVP9 VideoEncoder::GetDefaultVp9Settings() {
  26. VideoCodecVP9 vp9_settings;
  27. memset(&vp9_settings, 0, sizeof(vp9_settings));
  28. vp9_settings.numberOfTemporalLayers = 1;
  29. vp9_settings.denoisingOn = true;
  30. vp9_settings.frameDroppingOn = true;
  31. vp9_settings.keyFrameInterval = 3000;
  32. vp9_settings.adaptiveQpMode = true;
  33. vp9_settings.automaticResizeOn = true;
  34. vp9_settings.numberOfSpatialLayers = 1;
  35. vp9_settings.flexibleMode = false;
  36. vp9_settings.interLayerPred = InterLayerPredMode::kOn;
  37. return vp9_settings;
  38. }
  39. VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
  40. VideoCodecH264 h264_settings;
  41. memset(&h264_settings, 0, sizeof(h264_settings));
  42. h264_settings.frameDroppingOn = true;
  43. h264_settings.keyFrameInterval = 3000;
  44. h264_settings.numberOfTemporalLayers = 1;
  45. return h264_settings;
  46. }
  47. VideoEncoder::ScalingSettings::ScalingSettings() = default;
  48. VideoEncoder::ScalingSettings::ScalingSettings(KOff) : ScalingSettings() {}
  49. VideoEncoder::ScalingSettings::ScalingSettings(int low, int high)
  50. : thresholds(QpThresholds(low, high)) {}
  51. VideoEncoder::ScalingSettings::ScalingSettings(int low,
  52. int high,
  53. int min_pixels)
  54. : thresholds(QpThresholds(low, high)), min_pixels_per_frame(min_pixels) {}
  55. VideoEncoder::ScalingSettings::ScalingSettings(const ScalingSettings&) =
  56. default;
  57. VideoEncoder::ScalingSettings::~ScalingSettings() {}
  58. // static
  59. constexpr VideoEncoder::ScalingSettings::KOff
  60. VideoEncoder::ScalingSettings::kOff;
  61. // static
  62. constexpr uint8_t VideoEncoder::EncoderInfo::kMaxFramerateFraction;
  63. VideoEncoder::EncoderInfo::EncoderInfo()
  64. : scaling_settings(VideoEncoder::ScalingSettings::kOff),
  65. supports_native_handle(false),
  66. implementation_name("unknown"),
  67. has_trusted_rate_controller(false),
  68. is_hardware_accelerated(true),
  69. has_internal_source(false),
  70. fps_allocation{absl::InlinedVector<uint8_t, kMaxTemporalStreams>(
  71. 1,
  72. kMaxFramerateFraction)},
  73. supports_simulcast(false) {}
  74. VideoEncoder::EncoderInfo::EncoderInfo(const EncoderInfo&) = default;
  75. VideoEncoder::EncoderInfo::~EncoderInfo() = default;
  76. VideoEncoder::RateControlParameters::RateControlParameters()
  77. : bitrate(VideoBitrateAllocation()),
  78. framerate_fps(0.0),
  79. bandwidth_allocation(DataRate::Zero()) {}
  80. VideoEncoder::RateControlParameters::RateControlParameters(
  81. const VideoBitrateAllocation& bitrate,
  82. double framerate_fps)
  83. : bitrate(bitrate),
  84. framerate_fps(framerate_fps),
  85. bandwidth_allocation(DataRate::bps(bitrate.get_sum_bps())) {}
  86. VideoEncoder::RateControlParameters::RateControlParameters(
  87. const VideoBitrateAllocation& bitrate,
  88. double framerate_fps,
  89. DataRate bandwidth_allocation)
  90. : bitrate(bitrate),
  91. framerate_fps(framerate_fps),
  92. bandwidth_allocation(bandwidth_allocation) {}
  93. bool VideoEncoder::RateControlParameters::operator==(
  94. const VideoEncoder::RateControlParameters& rhs) const {
  95. return std::tie(bitrate, framerate_fps, bandwidth_allocation) ==
  96. std::tie(rhs.bitrate, rhs.framerate_fps, rhs.bandwidth_allocation);
  97. }
  98. bool VideoEncoder::RateControlParameters::operator!=(
  99. const VideoEncoder::RateControlParameters& rhs) const {
  100. return !(rhs == *this);
  101. }
  102. VideoEncoder::RateControlParameters::~RateControlParameters() = default;
  103. void VideoEncoder::SetFecControllerOverride(
  104. FecControllerOverride* fec_controller_override) {}
  105. int32_t VideoEncoder::InitEncode(const VideoCodec* codec_settings,
  106. int32_t number_of_cores,
  107. size_t max_payload_size) {
  108. const VideoEncoder::Capabilities capabilities(/* loss_notification= */ false);
  109. const VideoEncoder::Settings settings(capabilities, number_of_cores,
  110. max_payload_size);
  111. // In theory, this and the other version of InitEncode() could end up calling
  112. // each other in a loop until we get a stack overflow.
  113. // In practice, any subclass of VideoEncoder would overload at least one
  114. // of these, and we have a TODO in the header file to make this pure virtual.
  115. return InitEncode(codec_settings, settings);
  116. }
  117. int VideoEncoder::InitEncode(const VideoCodec* codec_settings,
  118. const VideoEncoder::Settings& settings) {
  119. // In theory, this and the other version of InitEncode() could end up calling
  120. // each other in a loop until we get a stack overflow.
  121. // In practice, any subclass of VideoEncoder would overload at least one
  122. // of these, and we have a TODO in the header file to make this pure virtual.
  123. return InitEncode(codec_settings, settings.number_of_cores,
  124. settings.max_payload_size);
  125. }
  126. void VideoEncoder::OnPacketLossRateUpdate(float packet_loss_rate) {}
  127. void VideoEncoder::OnRttUpdate(int64_t rtt_ms) {}
  128. void VideoEncoder::OnLossNotification(
  129. const LossNotification& loss_notification) {}
  130. // TODO(webrtc:9722): Remove and make pure virtual.
  131. VideoEncoder::EncoderInfo VideoEncoder::GetEncoderInfo() const {
  132. return EncoderInfo();
  133. }
  134. } // namespace webrtc