blob: cec7d9ef72cc2064a1a421074c0af32e424594c8 [file] [log] [blame]
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001/*
2 * Copyright (c) 2014 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 */
11
Mirko Bonadei95adedb2018-11-19 09:52:37 +010012#ifdef RTC_ENABLE_VP9
13
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/video_coding/codecs/vp9/vp9_impl.h"
marpan@webrtc.org5b883172014-11-01 06:10:48 +000015
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +020016#include <algorithm>
Sergey Silkind45b3452018-05-31 16:00:24 +020017#include <limits>
marpan@webrtc.org5b883172014-11-01 06:10:48 +000018#include <vector>
19
marpan@webrtc.org5b883172014-11-01 06:10:48 +000020#include "vpx/vp8cx.h"
21#include "vpx/vp8dx.h"
Yves Gerey665174f2018-06-19 15:03:05 +020022#include "vpx/vpx_decoder.h"
23#include "vpx/vpx_encoder.h"
marpan@webrtc.org5b883172014-11-01 06:10:48 +000024
Karl Wiberg918f50c2018-07-05 11:40:33 +020025#include "absl/memory/memory.h"
Emircan Uysaler800787f2018-07-16 10:01:49 -070026#include "api/video/color_space.h"
Emircan Uysaler0823eec2018-07-13 17:10:00 -070027#include "api/video/i010_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "common_video/include/video_frame_buffer.h"
29#include "common_video/libyuv/include/webrtc_libyuv.h"
Sergey Silkind902d582018-05-18 17:31:19 +020030#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Sergey Silkin86684962018-03-28 19:32:37 +020031#include "modules/video_coding/codecs/vp9/svc_rate_allocator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_base/checks.h"
33#include "rtc_base/keep_ref_until_done.h"
34#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/timeutils.h"
36#include "rtc_base/trace_event.h"
Sergey Silkin390f3582018-10-01 17:13:50 +020037#include "system_wrappers/include/field_trial.h"
marpan@webrtc.org5b883172014-11-01 06:10:48 +000038
39namespace webrtc {
40
Sergey Silkind902d582018-05-18 17:31:19 +020041namespace {
Erik Språngd3438aa2018-11-08 16:56:43 +010042const char kVp9TrustedRateControllerFieldTrial[] =
43 "WebRTC-LibvpxVp9TrustedRateController";
44
Sergey Silkin390f3582018-10-01 17:13:50 +020045// Maps from gof_idx to encoder internal reference frame buffer index. These
46// maps work for 1,2 and 3 temporal layers with GOF length of 1,2 and 4 frames.
47uint8_t kRefBufIdx[4] = {0, 0, 0, 1};
48uint8_t kUpdBufIdx[4] = {0, 0, 1, 0};
49
Sergey Silkinb674cd12018-10-09 10:59:06 +020050int kMaxNumTiles4kVideo = 8;
51
Marco6e89b252015-07-07 14:40:38 -070052// Only positive speeds, range for real-time coding currently is: 5 - 8.
53// Lower means slower/better quality, higher means fastest/lower quality.
54int GetCpuSpeed(int width, int height) {
Alex Glaznevfecb7c32016-03-31 14:23:27 -070055#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) || defined(ANDROID)
Marco002f0d02015-12-17 09:49:31 -080056 return 8;
57#else
Marco6e89b252015-07-07 14:40:38 -070058 // For smaller resolutions, use lower speed setting (get some coding gain at
59 // the cost of increased encoding complexity).
60 if (width * height <= 352 * 288)
61 return 5;
62 else
63 return 7;
Marco002f0d02015-12-17 09:49:31 -080064#endif
Marco6e89b252015-07-07 14:40:38 -070065}
Emircan Uysaler715cc232018-07-23 17:50:43 -070066// Helper class for extracting VP9 colorspace.
67ColorSpace ExtractVP9ColorSpace(vpx_color_space_t space_t,
68 vpx_color_range_t range_t,
69 unsigned int bit_depth) {
70 ColorSpace::PrimaryID primaries = ColorSpace::PrimaryID::kInvalid;
71 ColorSpace::TransferID transfer = ColorSpace::TransferID::kInvalid;
72 ColorSpace::MatrixID matrix = ColorSpace::MatrixID::kInvalid;
73 switch (space_t) {
74 case VPX_CS_BT_601:
75 case VPX_CS_SMPTE_170:
76 primaries = ColorSpace::PrimaryID::kSMPTE170M;
77 transfer = ColorSpace::TransferID::kSMPTE170M;
78 matrix = ColorSpace::MatrixID::kSMPTE170M;
79 break;
80 case VPX_CS_SMPTE_240:
81 primaries = ColorSpace::PrimaryID::kSMPTE240M;
82 transfer = ColorSpace::TransferID::kSMPTE240M;
83 matrix = ColorSpace::MatrixID::kSMPTE240M;
84 break;
85 case VPX_CS_BT_709:
86 primaries = ColorSpace::PrimaryID::kBT709;
87 transfer = ColorSpace::TransferID::kBT709;
88 matrix = ColorSpace::MatrixID::kBT709;
89 break;
90 case VPX_CS_BT_2020:
91 primaries = ColorSpace::PrimaryID::kBT2020;
92 switch (bit_depth) {
93 case 8:
94 transfer = ColorSpace::TransferID::kBT709;
95 break;
96 case 10:
97 transfer = ColorSpace::TransferID::kBT2020_10;
98 break;
99 default:
100 RTC_NOTREACHED();
101 break;
102 }
103 matrix = ColorSpace::MatrixID::kBT2020_NCL;
104 break;
105 case VPX_CS_SRGB:
106 primaries = ColorSpace::PrimaryID::kBT709;
107 transfer = ColorSpace::TransferID::kIEC61966_2_1;
108 matrix = ColorSpace::MatrixID::kBT709;
109 break;
110 default:
111 break;
112 }
113
114 ColorSpace::RangeID range = ColorSpace::RangeID::kInvalid;
115 switch (range_t) {
116 case VPX_CR_STUDIO_RANGE:
117 range = ColorSpace::RangeID::kLimited;
118 break;
119 case VPX_CR_FULL_RANGE:
120 range = ColorSpace::RangeID::kFull;
121 break;
122 default:
123 break;
124 }
125 return ColorSpace(primaries, transfer, matrix, range);
126}
127} // namespace
Marco6e89b252015-07-07 14:40:38 -0700128
asaperssona9455ab2015-07-31 06:10:09 -0700129void VP9EncoderImpl::EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt,
130 void* user_data) {
philipelcce46fc2015-12-21 03:04:49 -0800131 VP9EncoderImpl* enc = static_cast<VP9EncoderImpl*>(user_data);
asaperssona9455ab2015-07-31 06:10:09 -0700132 enc->GetEncodedLayerFrame(pkt);
133}
134
Emircan Uysaler98badbc2018-06-28 10:59:02 -0700135VP9EncoderImpl::VP9EncoderImpl(const cricket::VideoCodec& codec)
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000136 : encoded_image_(),
sprang3958ed82017-08-17 08:12:10 -0700137 encoded_complete_callback_(nullptr),
Emircan Uysaler98badbc2018-06-28 10:59:02 -0700138 profile_(
139 ParseSdpForVP9Profile(codec.params).value_or(VP9Profile::kProfile0)),
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000140 inited_(false),
141 timestamp_(0),
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000142 cpu_speed_(3),
143 rc_max_intra_target_(0),
sprang3958ed82017-08-17 08:12:10 -0700144 encoder_(nullptr),
145 config_(nullptr),
146 raw_(nullptr),
147 input_image_(nullptr),
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200148 force_key_frame_(true),
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200149 pics_since_key_(0),
asaperssona9455ab2015-07-31 06:10:09 -0700150 num_temporal_layers_(0),
philipelcfc319b2015-11-10 07:17:23 -0800151 num_spatial_layers_(0),
Sergey Silkin390f3582018-10-01 17:13:50 +0200152 num_active_spatial_layers_(0),
Erik Språngd3438aa2018-11-08 16:56:43 +0100153 layer_deactivation_requires_key_frame_(
154 field_trial::IsEnabled("WebRTC-Vp9IssueKeyFrameOnLayerDeactivation")),
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200155 is_svc_(false),
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200156 inter_layer_pred_(InterLayerPredMode::kOn),
Sergey Silkin390f3582018-10-01 17:13:50 +0200157 external_ref_control_(
Erik Språngd3438aa2018-11-08 16:56:43 +0100158 field_trial::IsEnabled("WebRTC-Vp9ExternalRefCtrl")),
159 trusted_rate_controller_(
160 field_trial::IsEnabled(kVp9TrustedRateControllerFieldTrial)),
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100161 full_superframe_drop_(true),
162 first_frame_in_picture_(true),
Sergey Silkinbe71a1e2018-05-17 16:46:43 +0200163 is_flexible_mode_(false) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000164 memset(&codec_, 0, sizeof(codec_));
johannkoenig8225c402017-01-26 13:23:44 -0800165 memset(&svc_params_, 0, sizeof(vpx_svc_extra_cfg_t));
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000166}
167
168VP9EncoderImpl::~VP9EncoderImpl() {
169 Release();
170}
171
172int VP9EncoderImpl::Release() {
Sergey Silkin3e871ea2018-03-02 13:11:04 +0100173 int ret_val = WEBRTC_VIDEO_CODEC_OK;
174
sprang3958ed82017-08-17 08:12:10 -0700175 if (encoded_image_._buffer != nullptr) {
philipelcce46fc2015-12-21 03:04:49 -0800176 delete[] encoded_image_._buffer;
sprang3958ed82017-08-17 08:12:10 -0700177 encoded_image_._buffer = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000178 }
sprang3958ed82017-08-17 08:12:10 -0700179 if (encoder_ != nullptr) {
Sergey Silkin90399692018-03-02 14:44:10 +0100180 if (inited_) {
181 if (vpx_codec_destroy(encoder_)) {
182 ret_val = WEBRTC_VIDEO_CODEC_MEMORY;
183 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000184 }
185 delete encoder_;
sprang3958ed82017-08-17 08:12:10 -0700186 encoder_ = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000187 }
sprang3958ed82017-08-17 08:12:10 -0700188 if (config_ != nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000189 delete config_;
sprang3958ed82017-08-17 08:12:10 -0700190 config_ = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000191 }
sprang3958ed82017-08-17 08:12:10 -0700192 if (raw_ != nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000193 vpx_img_free(raw_);
sprang3958ed82017-08-17 08:12:10 -0700194 raw_ = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000195 }
196 inited_ = false;
Sergey Silkin3e871ea2018-03-02 13:11:04 +0100197 return ret_val;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000198}
199
sprangce4aef12015-11-02 07:23:20 -0800200bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const {
201 // We check target_bitrate_bps of the 0th layer to see if the spatial layers
202 // (i.e. bitrates) were explicitly configured.
Sergey Silkinbeba1b22018-09-11 11:40:25 +0200203 return codec_.spatialLayers[0].targetBitrate > 0;
sprangce4aef12015-11-02 07:23:20 -0800204}
205
Erik Språng566124a2018-04-23 12:32:22 +0200206bool VP9EncoderImpl::SetSvcRates(
207 const VideoBitrateAllocation& bitrate_allocation) {
Sergey Silkin86684962018-03-28 19:32:37 +0200208 config_->rc_target_bitrate = bitrate_allocation.get_sum_kbps();
Sergey Silkin86684962018-03-28 19:32:37 +0200209
sprangce4aef12015-11-02 07:23:20 -0800210 if (ExplicitlyConfiguredSpatialLayers()) {
Sergey Silkine7ce8882018-10-03 18:04:57 +0200211 const bool layer_activation_requires_key_frame =
212 inter_layer_pred_ == InterLayerPredMode::kOff ||
213 inter_layer_pred_ == InterLayerPredMode::kOnKeyPic;
214
Sergey Silkin86684962018-03-28 19:32:37 +0200215 for (size_t sl_idx = 0; sl_idx < num_spatial_layers_; ++sl_idx) {
Sergey Silkine7ce8882018-10-03 18:04:57 +0200216 const bool was_layer_active = (config_->ss_target_bitrate[sl_idx] > 0);
Sergey Silkin86684962018-03-28 19:32:37 +0200217 config_->ss_target_bitrate[sl_idx] =
218 bitrate_allocation.GetSpatialLayerSum(sl_idx) / 1000;
219
220 for (size_t tl_idx = 0; tl_idx < num_temporal_layers_; ++tl_idx) {
221 config_->layer_target_bitrate[sl_idx * num_temporal_layers_ + tl_idx] =
222 bitrate_allocation.GetTemporalLayerSum(sl_idx, tl_idx) / 1000;
223 }
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200224
Sergey Silkine7ce8882018-10-03 18:04:57 +0200225 const bool is_active_layer = (config_->ss_target_bitrate[sl_idx] > 0);
226 if (!was_layer_active && is_active_layer &&
227 layer_activation_requires_key_frame) {
228 force_key_frame_ = true;
229 } else if (was_layer_active && !is_active_layer &&
230 layer_deactivation_requires_key_frame_) {
231 force_key_frame_ = true;
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200232 }
Sergey Silkin96f2c972018-09-05 21:07:17 +0200233
Sergey Silkine7ce8882018-10-03 18:04:57 +0200234 if (!was_layer_active) {
Sergey Silkin96f2c972018-09-05 21:07:17 +0200235 // Reset frame rate controller if layer is resumed after pause.
236 framerate_controller_[sl_idx].Reset();
237 }
238
239 framerate_controller_[sl_idx].SetTargetRate(
Sergey Silkinbeba1b22018-09-11 11:40:25 +0200240 std::min(static_cast<float>(codec_.maxFramerate),
241 codec_.spatialLayers[sl_idx].maxFramerate));
sprangce4aef12015-11-02 07:23:20 -0800242 }
243 } else {
244 float rate_ratio[VPX_MAX_LAYERS] = {0};
245 float total = 0;
Sergey Silkin908689d2018-08-20 09:28:45 +0200246 for (int i = 0; i < num_spatial_layers_; ++i) {
johannkoenig8225c402017-01-26 13:23:44 -0800247 if (svc_params_.scaling_factor_num[i] <= 0 ||
248 svc_params_.scaling_factor_den[i] <= 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100249 RTC_LOG(LS_ERROR) << "Scaling factors not specified!";
sprangce4aef12015-11-02 07:23:20 -0800250 return false;
251 }
Yves Gerey665174f2018-06-19 15:03:05 +0200252 rate_ratio[i] = static_cast<float>(svc_params_.scaling_factor_num[i]) /
253 svc_params_.scaling_factor_den[i];
sprangce4aef12015-11-02 07:23:20 -0800254 total += rate_ratio[i];
255 }
256
Sergey Silkin908689d2018-08-20 09:28:45 +0200257 for (int i = 0; i < num_spatial_layers_; ++i) {
Rasmus Brandt58cd3852018-06-26 13:41:16 +0200258 RTC_CHECK_GT(total, 0);
sprangce4aef12015-11-02 07:23:20 -0800259 config_->ss_target_bitrate[i] = static_cast<unsigned int>(
260 config_->rc_target_bitrate * rate_ratio[i] / total);
261 if (num_temporal_layers_ == 1) {
262 config_->layer_target_bitrate[i] = config_->ss_target_bitrate[i];
263 } else if (num_temporal_layers_ == 2) {
264 config_->layer_target_bitrate[i * num_temporal_layers_] =
265 config_->ss_target_bitrate[i] * 2 / 3;
266 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
267 config_->ss_target_bitrate[i];
268 } else if (num_temporal_layers_ == 3) {
269 config_->layer_target_bitrate[i * num_temporal_layers_] =
270 config_->ss_target_bitrate[i] / 2;
271 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
272 config_->layer_target_bitrate[i * num_temporal_layers_] +
273 (config_->ss_target_bitrate[i] / 4);
274 config_->layer_target_bitrate[i * num_temporal_layers_ + 2] =
275 config_->ss_target_bitrate[i];
276 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100277 RTC_LOG(LS_ERROR) << "Unsupported number of temporal layers: "
278 << num_temporal_layers_;
sprangce4aef12015-11-02 07:23:20 -0800279 return false;
280 }
Sergey Silkin96f2c972018-09-05 21:07:17 +0200281
282 framerate_controller_[i].SetTargetRate(codec_.maxFramerate);
asaperssona9455ab2015-07-31 06:10:09 -0700283 }
284 }
Sergey Silkin908689d2018-08-20 09:28:45 +0200285
286 num_active_spatial_layers_ = 0;
287 for (int i = 0; i < num_spatial_layers_; ++i) {
288 if (config_->ss_target_bitrate[i] > 0) {
289 ++num_active_spatial_layers_;
290 }
291 }
292 RTC_DCHECK_GT(num_active_spatial_layers_, 0);
293
asaperssona9455ab2015-07-31 06:10:09 -0700294 return true;
295}
296
Erik Språng08127a92016-11-16 16:41:30 +0100297int VP9EncoderImpl::SetRateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +0200298 const VideoBitrateAllocation& bitrate_allocation,
Erik Språng08127a92016-11-16 16:41:30 +0100299 uint32_t frame_rate) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000300 if (!inited_) {
301 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
302 }
303 if (encoder_->err) {
304 return WEBRTC_VIDEO_CODEC_ERROR;
305 }
Erik Språng08127a92016-11-16 16:41:30 +0100306 if (frame_rate < 1) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000307 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
308 }
309 // Update bit rate
Erik Språng08127a92016-11-16 16:41:30 +0100310 if (codec_.maxBitrate > 0 &&
311 bitrate_allocation.get_sum_kbps() > codec_.maxBitrate) {
312 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000313 }
Erik Språng08127a92016-11-16 16:41:30 +0100314
Erik Språng08127a92016-11-16 16:41:30 +0100315 codec_.maxFramerate = frame_rate;
asaperssona9455ab2015-07-31 06:10:09 -0700316
Sergey Silkin86684962018-03-28 19:32:37 +0200317 if (!SetSvcRates(bitrate_allocation)) {
asaperssona9455ab2015-07-31 06:10:09 -0700318 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
319 }
320
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000321 // Update encoder context
322 if (vpx_codec_enc_config_set(encoder_, config_)) {
323 return WEBRTC_VIDEO_CODEC_ERROR;
324 }
325 return WEBRTC_VIDEO_CODEC_OK;
326}
327
328int VP9EncoderImpl::InitEncode(const VideoCodec* inst,
329 int number_of_cores,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000330 size_t /*max_payload_size*/) {
sprang3958ed82017-08-17 08:12:10 -0700331 if (inst == nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000332 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
333 }
334 if (inst->maxFramerate < 1) {
335 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
336 }
337 // Allow zero to represent an unspecified maxBitRate
338 if (inst->maxBitrate > 0 && inst->startBitrate > inst->maxBitrate) {
339 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
340 }
341 if (inst->width < 1 || inst->height < 1) {
342 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
343 }
344 if (number_of_cores < 1) {
345 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
346 }
hta257dc392016-10-25 09:05:06 -0700347 if (inst->VP9().numberOfTemporalLayers > 3) {
asaperssona9455ab2015-07-31 06:10:09 -0700348 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
349 }
ilnik2a8c2f52017-02-15 02:23:28 -0800350 // libvpx probably does not support more than 3 spatial layers.
351 if (inst->VP9().numberOfSpatialLayers > 3) {
asaperssona9455ab2015-07-31 06:10:09 -0700352 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
353 }
philipelcfc319b2015-11-10 07:17:23 -0800354
asapersson86956de2016-01-26 01:05:20 -0800355 int ret_val = Release();
356 if (ret_val < 0) {
357 return ret_val;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000358 }
sprang3958ed82017-08-17 08:12:10 -0700359 if (encoder_ == nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000360 encoder_ = new vpx_codec_ctx_t;
361 }
sprang3958ed82017-08-17 08:12:10 -0700362 if (config_ == nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000363 config_ = new vpx_codec_enc_cfg_t;
364 }
365 timestamp_ = 0;
366 if (&codec_ != inst) {
367 codec_ = *inst;
368 }
asaperssona9455ab2015-07-31 06:10:09 -0700369
Sergey Silkinb0bd03b2018-09-28 14:56:39 +0200370 force_key_frame_ = true;
371 pics_since_key_ = 0;
372
hta257dc392016-10-25 09:05:06 -0700373 num_spatial_layers_ = inst->VP9().numberOfSpatialLayers;
Niels Möller65fb4042018-04-25 14:46:06 +0200374 RTC_DCHECK_GT(num_spatial_layers_, 0);
hta257dc392016-10-25 09:05:06 -0700375 num_temporal_layers_ = inst->VP9().numberOfTemporalLayers;
Sergey Silkin96f2c972018-09-05 21:07:17 +0200376 if (num_temporal_layers_ == 0) {
asaperssona9455ab2015-07-31 06:10:09 -0700377 num_temporal_layers_ = 1;
Sergey Silkin042661b2018-09-10 10:39:35 +0000378 }
Sergey Silkinae9e1882018-09-05 21:07:17 +0200379
Sergey Silkin96f2c972018-09-05 21:07:17 +0200380 framerate_controller_ = std::vector<FramerateController>(
381 num_spatial_layers_, FramerateController(codec_.maxFramerate));
382
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200383 is_svc_ = (num_spatial_layers_ > 1 || num_temporal_layers_ > 1);
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200384
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000385 // Allocate memory for encoded image
sprang3958ed82017-08-17 08:12:10 -0700386 if (encoded_image_._buffer != nullptr) {
philipelcce46fc2015-12-21 03:04:49 -0800387 delete[] encoded_image_._buffer;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000388 }
nisseeb44b392017-04-28 07:18:05 -0700389 encoded_image_._size =
390 CalcBufferSize(VideoType::kI420, codec_.width, codec_.height);
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000391 encoded_image_._buffer = new uint8_t[encoded_image_._size];
392 encoded_image_._completeFrame = true;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000393 // Populate encoder configuration with default values.
394 if (vpx_codec_enc_config_default(vpx_codec_vp9_cx(), config_, 0)) {
395 return WEBRTC_VIDEO_CODEC_ERROR;
396 }
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700397
398 vpx_img_fmt img_fmt = VPX_IMG_FMT_NONE;
399 unsigned int bits_for_storage = 8;
400 switch (profile_) {
401 case VP9Profile::kProfile0:
402 img_fmt = VPX_IMG_FMT_I420;
403 bits_for_storage = 8;
404 config_->g_bit_depth = VPX_BITS_8;
405 config_->g_profile = 0;
406 config_->g_input_bit_depth = 8;
407 break;
408 case VP9Profile::kProfile2:
409 img_fmt = VPX_IMG_FMT_I42016;
410 bits_for_storage = 16;
411 config_->g_bit_depth = VPX_BITS_10;
412 config_->g_profile = 2;
413 config_->g_input_bit_depth = 10;
414 break;
415 }
416
417 // Creating a wrapper to the image - setting image data to nullptr. Actual
418 // pointer will be set in encode. Setting align to 1, as it is meaningless
419 // (actual memory is not allocated).
420 raw_ =
421 vpx_img_wrap(nullptr, img_fmt, codec_.width, codec_.height, 1, nullptr);
422 raw_->bit_depth = bits_for_storage;
423
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000424 config_->g_w = codec_.width;
425 config_->g_h = codec_.height;
426 config_->rc_target_bitrate = inst->startBitrate; // in kbit/s
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200427 config_->g_error_resilient = is_svc_ ? VPX_ERROR_RESILIENT_DEFAULT : 0;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000428 // Setting the time base of the codec.
429 config_->g_timebase.num = 1;
430 config_->g_timebase.den = 90000;
431 config_->g_lag_in_frames = 0; // 0- no frame lagging
432 config_->g_threads = 1;
433 // Rate control settings.
hta257dc392016-10-25 09:05:06 -0700434 config_->rc_dropframe_thresh = inst->VP9().frameDroppingOn ? 30 : 0;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000435 config_->rc_end_usage = VPX_CBR;
436 config_->g_pass = VPX_RC_ONE_PASS;
437 config_->rc_min_quantizer = 2;
marpan@webrtc.orgdc8a9da2015-01-27 23:08:24 +0000438 config_->rc_max_quantizer = 52;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000439 config_->rc_undershoot_pct = 50;
440 config_->rc_overshoot_pct = 50;
441 config_->rc_buf_initial_sz = 500;
442 config_->rc_buf_optimal_sz = 600;
443 config_->rc_buf_sz = 1000;
444 // Set the maximum target size of any key-frame.
445 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz);
hta257dc392016-10-25 09:05:06 -0700446 if (inst->VP9().keyFrameInterval > 0) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000447 config_->kf_mode = VPX_KF_AUTO;
hta257dc392016-10-25 09:05:06 -0700448 config_->kf_max_dist = inst->VP9().keyFrameInterval;
Åsa Perssonff24c042015-12-04 10:58:08 +0100449 // Needs to be set (in svc mode) to get correct periodic key frame interval
450 // (will have no effect in non-svc).
451 config_->kf_min_dist = config_->kf_max_dist;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000452 } else {
453 config_->kf_mode = VPX_KF_DISABLED;
454 }
hta257dc392016-10-25 09:05:06 -0700455 config_->rc_resize_allowed = inst->VP9().automaticResizeOn ? 1 : 0;
marpan@webrtc.org38d11b82015-01-26 15:21:36 +0000456 // Determine number of threads based on the image size and #cores.
philipelcce46fc2015-12-21 03:04:49 -0800457 config_->g_threads =
458 NumberOfThreads(config_->g_w, config_->g_h, number_of_cores);
asaperssona9455ab2015-07-31 06:10:09 -0700459
Marco6e89b252015-07-07 14:40:38 -0700460 cpu_speed_ = GetCpuSpeed(config_->g_w, config_->g_h);
asaperssona9455ab2015-07-31 06:10:09 -0700461
hta257dc392016-10-25 09:05:06 -0700462 is_flexible_mode_ = inst->VP9().flexibleMode;
Sergey Silkinbe71a1e2018-05-17 16:46:43 +0200463
Sergey Silkinbe71a1e2018-05-17 16:46:43 +0200464 if (num_temporal_layers_ == 1) {
asaperssona9455ab2015-07-31 06:10:09 -0700465 gof_.SetGofInfoVP9(kTemporalStructureMode1);
466 config_->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING;
467 config_->ts_number_layers = 1;
468 config_->ts_rate_decimator[0] = 1;
469 config_->ts_periodicity = 1;
470 config_->ts_layer_id[0] = 0;
471 } else if (num_temporal_layers_ == 2) {
472 gof_.SetGofInfoVP9(kTemporalStructureMode2);
473 config_->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0101;
474 config_->ts_number_layers = 2;
475 config_->ts_rate_decimator[0] = 2;
476 config_->ts_rate_decimator[1] = 1;
477 config_->ts_periodicity = 2;
478 config_->ts_layer_id[0] = 0;
479 config_->ts_layer_id[1] = 1;
480 } else if (num_temporal_layers_ == 3) {
481 gof_.SetGofInfoVP9(kTemporalStructureMode3);
482 config_->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212;
483 config_->ts_number_layers = 3;
484 config_->ts_rate_decimator[0] = 4;
485 config_->ts_rate_decimator[1] = 2;
486 config_->ts_rate_decimator[2] = 1;
487 config_->ts_periodicity = 4;
488 config_->ts_layer_id[0] = 0;
489 config_->ts_layer_id[1] = 2;
490 config_->ts_layer_id[2] = 1;
491 config_->ts_layer_id[3] = 2;
492 } else {
493 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
494 }
495
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200496 inter_layer_pred_ = inst->VP9().interLayerPred;
497
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200498 ref_buf_.clear();
499
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000500 return InitAndSetControlSettings(inst);
501}
502
marpan@webrtc.org38d11b82015-01-26 15:21:36 +0000503int VP9EncoderImpl::NumberOfThreads(int width,
504 int height,
505 int number_of_cores) {
506 // Keep the number of encoder threads equal to the possible number of column
507 // tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS.
508 if (width * height >= 1280 * 720 && number_of_cores > 4) {
509 return 4;
jianj23173a32017-07-12 16:11:09 -0700510 } else if (width * height >= 640 * 360 && number_of_cores > 2) {
marpan@webrtc.org38d11b82015-01-26 15:21:36 +0000511 return 2;
512 } else {
Yves Gerey665174f2018-06-19 15:03:05 +0200513// Use 2 threads for low res on ARM.
Jerome Jiang831af372017-12-05 10:44:35 -0800514#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) || \
515 defined(WEBRTC_ANDROID)
516 if (width * height >= 320 * 180 && number_of_cores > 2) {
517 return 2;
518 }
519#endif
marpan@webrtc.org38d11b82015-01-26 15:21:36 +0000520 // 1 thread less than VGA.
521 return 1;
522 }
523}
524
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000525int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
Åsa Perssonff24c042015-12-04 10:58:08 +0100526 // Set QP-min/max per spatial and temporal layer.
527 int tot_num_layers = num_spatial_layers_ * num_temporal_layers_;
528 for (int i = 0; i < tot_num_layers; ++i) {
johannkoenig8225c402017-01-26 13:23:44 -0800529 svc_params_.max_quantizers[i] = config_->rc_max_quantizer;
530 svc_params_.min_quantizers[i] = config_->rc_min_quantizer;
Åsa Perssonff24c042015-12-04 10:58:08 +0100531 }
asaperssona9455ab2015-07-31 06:10:09 -0700532 config_->ss_number_layers = num_spatial_layers_;
sprangce4aef12015-11-02 07:23:20 -0800533 if (ExplicitlyConfiguredSpatialLayers()) {
534 for (int i = 0; i < num_spatial_layers_; ++i) {
535 const auto& layer = codec_.spatialLayers[i];
Rasmus Brandt58cd3852018-06-26 13:41:16 +0200536 RTC_CHECK_GT(layer.width, 0);
Sergey Silkin13e74342018-03-02 12:28:00 +0100537 const int scale_factor = codec_.width / layer.width;
538 RTC_DCHECK_GT(scale_factor, 0);
539
540 // Ensure scaler factor is integer.
541 if (scale_factor * layer.width != codec_.width) {
542 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
543 }
544
545 // Ensure scale factor is the same in both dimensions.
546 if (scale_factor * layer.height != codec_.height) {
547 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
548 }
549
550 // Ensure scale factor is power of two.
551 const bool is_pow_of_two = (scale_factor & (scale_factor - 1)) == 0;
552 if (!is_pow_of_two) {
553 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
554 }
555
556 svc_params_.scaling_factor_num[i] = 1;
557 svc_params_.scaling_factor_den[i] = scale_factor;
Sergey Silkin96f2c972018-09-05 21:07:17 +0200558
559 RTC_DCHECK_GT(codec_.spatialLayers[i].maxFramerate, 0);
560 RTC_DCHECK_LE(codec_.spatialLayers[i].maxFramerate, codec_.maxFramerate);
561 if (i > 0) {
562 // Frame rate of high spatial layer is supposed to be equal or higher
563 // than frame rate of low spatial layer.
564 RTC_DCHECK_GE(codec_.spatialLayers[i].maxFramerate,
565 codec_.spatialLayers[i - 1].maxFramerate);
566 }
sprangce4aef12015-11-02 07:23:20 -0800567 }
568 } else {
569 int scaling_factor_num = 256;
570 for (int i = num_spatial_layers_ - 1; i >= 0; --i) {
sprangce4aef12015-11-02 07:23:20 -0800571 // 1:2 scaling in each dimension.
johannkoenig8225c402017-01-26 13:23:44 -0800572 svc_params_.scaling_factor_num[i] = scaling_factor_num;
573 svc_params_.scaling_factor_den[i] = 256;
sprangce4aef12015-11-02 07:23:20 -0800574 }
asaperssona9455ab2015-07-31 06:10:09 -0700575 }
576
Sergey Silkin86684962018-03-28 19:32:37 +0200577 SvcRateAllocator init_allocator(codec_);
Erik Språng566124a2018-04-23 12:32:22 +0200578 VideoBitrateAllocation allocation = init_allocator.GetAllocation(
Sergey Silkin86684962018-03-28 19:32:37 +0200579 inst->startBitrate * 1000, inst->maxFramerate);
580 if (!SetSvcRates(allocation)) {
asaperssona9455ab2015-07-31 06:10:09 -0700581 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
582 }
583
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700584 const vpx_codec_err_t rv = vpx_codec_enc_init(
585 encoder_, vpx_codec_vp9_cx(), config_,
586 config_->g_bit_depth == VPX_BITS_8 ? 0 : VPX_CODEC_USE_HIGHBITDEPTH);
587 if (rv != VPX_CODEC_OK) {
588 RTC_LOG(LS_ERROR) << "Init error: " << vpx_codec_err_to_string(rv);
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000589 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
590 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000591 vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_);
592 vpx_codec_control(encoder_, VP8E_SET_MAX_INTRA_BITRATE_PCT,
593 rc_max_intra_target_);
594 vpx_codec_control(encoder_, VP9E_SET_AQ_MODE,
hta257dc392016-10-25 09:05:06 -0700595 inst->VP9().adaptiveQpMode ? 3 : 0);
asaperssona9455ab2015-07-31 06:10:09 -0700596
jianj822e5932017-07-12 16:09:58 -0700597 vpx_codec_control(encoder_, VP9E_SET_FRAME_PARALLEL_DECODING, 0);
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200598
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200599 if (is_svc_) {
600 vpx_codec_control(encoder_, VP9E_SET_SVC, 1);
601 vpx_codec_control(encoder_, VP9E_SET_SVC_PARAMETERS, &svc_params_);
asaperssona9455ab2015-07-31 06:10:09 -0700602 }
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200603
604 if (num_spatial_layers_ > 1) {
605 switch (inter_layer_pred_) {
606 case InterLayerPredMode::kOn:
607 vpx_codec_control(encoder_, VP9E_SET_SVC_INTER_LAYER_PRED, 0);
608 break;
609 case InterLayerPredMode::kOff:
610 vpx_codec_control(encoder_, VP9E_SET_SVC_INTER_LAYER_PRED, 1);
611 break;
612 case InterLayerPredMode::kOnKeyPic:
613 vpx_codec_control(encoder_, VP9E_SET_SVC_INTER_LAYER_PRED, 2);
614 break;
615 default:
616 RTC_NOTREACHED();
617 }
Sergey Silkinbe71a1e2018-05-17 16:46:43 +0200618
Sergey Silkinee203362018-05-30 11:34:08 +0200619 // Configure encoder to drop entire superframe whenever it needs to drop
620 // a layer. This mode is prefered over per-layer dropping which causes
621 // quality flickering and is not compatible with RTP non-flexible mode.
622 vpx_svc_frame_drop_t svc_drop_frame;
623 memset(&svc_drop_frame, 0, sizeof(svc_drop_frame));
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100624 svc_drop_frame.framedrop_mode =
625 full_superframe_drop_ ? FULL_SUPERFRAME_DROP : CONSTRAINED_LAYER_DROP;
Sergey Silkind45b3452018-05-31 16:00:24 +0200626 svc_drop_frame.max_consec_drop = std::numeric_limits<int>::max();
Sergey Silkinee203362018-05-30 11:34:08 +0200627 for (size_t i = 0; i < num_spatial_layers_; ++i) {
628 svc_drop_frame.framedrop_thresh[i] = config_->rc_dropframe_thresh;
Sergey Silkinbe71a1e2018-05-17 16:46:43 +0200629 }
Sergey Silkinee203362018-05-30 11:34:08 +0200630 vpx_codec_control(encoder_, VP9E_SET_SVC_FRAME_DROP_LAYER, &svc_drop_frame);
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200631 }
632
asaperssona9455ab2015-07-31 06:10:09 -0700633 // Register callback for getting each spatial layer.
634 vpx_codec_priv_output_cx_pkt_cb_pair_t cbp = {
philipelcce46fc2015-12-21 03:04:49 -0800635 VP9EncoderImpl::EncoderOutputCodedPacketCallback,
636 reinterpret_cast<void*>(this)};
637 vpx_codec_control(encoder_, VP9E_REGISTER_CX_CALLBACK,
638 reinterpret_cast<void*>(&cbp));
asaperssona9455ab2015-07-31 06:10:09 -0700639
marpan@webrtc.org38d11b82015-01-26 15:21:36 +0000640 // Control function to set the number of column tiles in encoding a frame, in
641 // log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns.
642 // The number tile columns will be capped by the encoder based on image size
643 // (minimum width of tile column is 256 pixels, maximum is 4096).
644 vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1));
jianjcb5d1152017-03-28 23:56:08 -0700645
646 // Turn on row-based multithreading.
647 vpx_codec_control(encoder_, VP9E_SET_ROW_MT, 1);
jianj6bf57e32017-06-05 13:43:49 -0700648
Alex Glaznevfecb7c32016-03-31 14:23:27 -0700649#if !defined(WEBRTC_ARCH_ARM) && !defined(WEBRTC_ARCH_ARM64) && \
Yves Gerey665174f2018-06-19 15:03:05 +0200650 !defined(ANDROID)
jianj6bf57e32017-06-05 13:43:49 -0700651 // Do not enable the denoiser on ARM since optimization is pending.
652 // Denoiser is on by default on other platforms.
marpan@webrtc.org16a87b92015-03-05 22:19:00 +0000653 vpx_codec_control(encoder_, VP9E_SET_NOISE_SENSITIVITY,
hta257dc392016-10-25 09:05:06 -0700654 inst->VP9().denoisingOn ? 1 : 0);
marpan@webrtc.org16a87b92015-03-05 22:19:00 +0000655#endif
jianj6bf57e32017-06-05 13:43:49 -0700656
Niels Möllere3cf3d02018-06-13 11:52:16 +0200657 if (codec_.mode == VideoCodecMode::kScreensharing) {
ivica242d6382015-09-04 06:13:23 -0700658 // Adjust internal parameters to screen content.
659 vpx_codec_control(encoder_, VP9E_SET_TUNE_CONTENT, 1);
ivica242d6382015-09-04 06:13:23 -0700660 }
Marco2520e722015-09-16 14:05:00 -0700661 // Enable encoder skip of static/low content blocks.
662 vpx_codec_control(encoder_, VP8E_SET_STATIC_THRESHOLD, 1);
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000663 inited_ = true;
664 return WEBRTC_VIDEO_CODEC_OK;
665}
666
667uint32_t VP9EncoderImpl::MaxIntraTarget(uint32_t optimal_buffer_size) {
668 // Set max to the optimal buffer level (normalized by target BR),
669 // and scaled by a scale_par.
670 // Max target size = scale_par * optimal_buffer_size * targetBR[Kbps].
671 // This value is presented in percentage of perFrameBw:
672 // perFrameBw = targetBR[Kbps] * 1000 / framerate.
673 // The target in % is as follows:
674 float scale_par = 0.5;
675 uint32_t target_pct =
676 optimal_buffer_size * scale_par * codec_.maxFramerate / 10;
677 // Don't go below 3 times the per frame bandwidth.
678 const uint32_t min_intra_size = 300;
philipelcce46fc2015-12-21 03:04:49 -0800679 return (target_pct < min_intra_size) ? min_intra_size : target_pct;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000680}
681
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700682int VP9EncoderImpl::Encode(const VideoFrame& input_image,
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000683 const CodecSpecificInfo* codec_specific_info,
pbos22993e12015-10-19 02:39:06 -0700684 const std::vector<FrameType>* frame_types) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000685 if (!inited_) {
686 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
687 }
sprang3958ed82017-08-17 08:12:10 -0700688 if (encoded_complete_callback_ == nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000689 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
690 }
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200691
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000692 // We only support one stream at the moment.
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200693 if (frame_types && !frame_types->empty()) {
694 if ((*frame_types)[0] == kVideoFrameKey) {
695 force_key_frame_ = true;
696 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000697 }
Sergey Silkind902d582018-05-18 17:31:19 +0200698
Niels Möllere3cf3d02018-06-13 11:52:16 +0200699 if (VideoCodecMode::kScreensharing == codec_.mode && !force_key_frame_) {
Sergey Silkin96f2c972018-09-05 21:07:17 +0200700 // Skip encoding spatial layer frames if their target frame rate is lower
701 // than actual input frame rate.
702 vpx_svc_layer_id_t layer_id = {0};
703 const size_t gof_idx = (pics_since_key_ + 1) % gof_.num_frames_in_gof;
704 layer_id.temporal_layer_id = gof_.temporal_idx[gof_idx];
705
706 const uint32_t frame_timestamp_ms =
707 1000 * input_image.timestamp() / kVideoPayloadTypeFrequency;
708
709 for (uint8_t sl_idx = 0; sl_idx < num_active_spatial_layers_; ++sl_idx) {
710 if (framerate_controller_[sl_idx].DropFrame(frame_timestamp_ms)) {
711 ++layer_id.spatial_layer_id;
712 } else {
713 break;
714 }
715 }
716
717 RTC_DCHECK_LE(layer_id.spatial_layer_id, num_active_spatial_layers_);
718 if (layer_id.spatial_layer_id >= num_active_spatial_layers_) {
719 // Drop entire picture.
Sergey Silkind902d582018-05-18 17:31:19 +0200720 return WEBRTC_VIDEO_CODEC_OK;
721 }
Sergey Silkin96f2c972018-09-05 21:07:17 +0200722
723 vpx_codec_control(encoder_, VP9E_SET_SVC_LAYER_ID, &layer_id);
Sergey Silkind902d582018-05-18 17:31:19 +0200724 }
725
kwiberg352444f2016-11-28 15:58:53 -0800726 RTC_DCHECK_EQ(input_image.width(), raw_->d_w);
727 RTC_DCHECK_EQ(input_image.height(), raw_->d_h);
asaperssona9455ab2015-07-31 06:10:09 -0700728
729 // Set input image for use in the callback.
730 // This was necessary since you need some information from input_image.
731 // You can save only the necessary information (such as timestamp) instead of
732 // doing this.
733 input_image_ = &input_image;
734
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700735 // Keep reference to buffer until encode completes.
736 rtc::scoped_refptr<I420BufferInterface> i420_buffer;
737 rtc::scoped_refptr<I010BufferInterface> i010_buffer;
738 switch (profile_) {
739 case VP9Profile::kProfile0: {
740 i420_buffer = input_image.video_frame_buffer()->ToI420();
741 // Image in vpx_image_t format.
742 // Input image is const. VPX's raw image is not defined as const.
743 raw_->planes[VPX_PLANE_Y] = const_cast<uint8_t*>(i420_buffer->DataY());
744 raw_->planes[VPX_PLANE_U] = const_cast<uint8_t*>(i420_buffer->DataU());
745 raw_->planes[VPX_PLANE_V] = const_cast<uint8_t*>(i420_buffer->DataV());
746 raw_->stride[VPX_PLANE_Y] = i420_buffer->StrideY();
747 raw_->stride[VPX_PLANE_U] = i420_buffer->StrideU();
748 raw_->stride[VPX_PLANE_V] = i420_buffer->StrideV();
749 break;
750 }
751 case VP9Profile::kProfile2: {
752 // We can inject kI010 frames directly for encode. All other formats
753 // should be converted to it.
754 switch (input_image.video_frame_buffer()->type()) {
755 case VideoFrameBuffer::Type::kI010: {
756 i010_buffer = input_image.video_frame_buffer()->GetI010();
757 break;
758 }
759 default: {
760 i010_buffer =
761 I010Buffer::Copy(*input_image.video_frame_buffer()->ToI420());
762 }
763 }
764 raw_->planes[VPX_PLANE_Y] = const_cast<uint8_t*>(
765 reinterpret_cast<const uint8_t*>(i010_buffer->DataY()));
766 raw_->planes[VPX_PLANE_U] = const_cast<uint8_t*>(
767 reinterpret_cast<const uint8_t*>(i010_buffer->DataU()));
768 raw_->planes[VPX_PLANE_V] = const_cast<uint8_t*>(
769 reinterpret_cast<const uint8_t*>(i010_buffer->DataV()));
770 raw_->stride[VPX_PLANE_Y] = i010_buffer->StrideY() * 2;
771 raw_->stride[VPX_PLANE_U] = i010_buffer->StrideU() * 2;
772 raw_->stride[VPX_PLANE_V] = i010_buffer->StrideV() * 2;
773 break;
774 }
775 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000776
philipelcfc319b2015-11-10 07:17:23 -0800777 vpx_enc_frame_flags_t flags = 0;
Sergey Silkinbd0954e2018-05-03 14:14:09 +0200778 if (force_key_frame_) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000779 flags = VPX_EFLAG_FORCE_KF;
780 }
philipelcfc319b2015-11-10 07:17:23 -0800781
Sergey Silkin390f3582018-10-01 17:13:50 +0200782 if (external_ref_control_) {
783 vpx_svc_ref_frame_config_t ref_config = SetReferences(force_key_frame_);
Sergey Silkina85995a2018-10-02 10:28:10 +0200784
785 if (VideoCodecMode::kScreensharing == codec_.mode) {
786 for (uint8_t sl_idx = 0; sl_idx < num_active_spatial_layers_; ++sl_idx) {
787 ref_config.duration[sl_idx] = static_cast<int64_t>(
788 90000 / framerate_controller_[sl_idx].GetTargetRate());
789 }
790 }
791
Sergey Silkin390f3582018-10-01 17:13:50 +0200792 vpx_codec_control(encoder_, VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_config);
793 }
794
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100795 first_frame_in_picture_ = true;
796
Sergey Silkin96f2c972018-09-05 21:07:17 +0200797 // TODO(ssilkin): Frame duration should be specified per spatial layer
798 // since their frame rate can be different. For now calculate frame duration
799 // based on target frame rate of the highest spatial layer, which frame rate
800 // is supposed to be equal or higher than frame rate of low spatial layers.
801 // Also, timestamp should represent actual time passed since previous frame
802 // (not 'expected' time). Then rate controller can drain buffer more
803 // accurately.
804 RTC_DCHECK_GE(framerate_controller_.size(), num_active_spatial_layers_);
Sergey Silkinf87bb462018-09-17 09:37:37 +0200805 float target_framerate_fps =
806 (codec_.mode == VideoCodecMode::kScreensharing)
807 ? framerate_controller_[num_active_spatial_layers_ - 1]
808 .GetTargetRate()
809 : codec_.maxFramerate;
810 uint32_t duration = static_cast<uint32_t>(90000 / target_framerate_fps);
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700811 const vpx_codec_err_t rv = vpx_codec_encode(encoder_, raw_, timestamp_,
812 duration, flags, VPX_DL_REALTIME);
813 if (rv != VPX_CODEC_OK) {
814 RTC_LOG(LS_ERROR) << "Encoding error: " << vpx_codec_err_to_string(rv)
815 << "\n"
816 << "Details: " << vpx_codec_error(encoder_) << "\n"
817 << vpx_codec_error_detail(encoder_);
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000818 return WEBRTC_VIDEO_CODEC_ERROR;
819 }
820 timestamp_ += duration;
asaperssona9455ab2015-07-31 06:10:09 -0700821
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100822 if (!full_superframe_drop_) {
823 const bool end_of_picture = true;
824 DeliverBufferedFrame(end_of_picture);
825 }
Sergey Silkin2a1f1832018-04-04 11:45:41 +0200826
asaperssona9455ab2015-07-31 06:10:09 -0700827 return WEBRTC_VIDEO_CODEC_OK;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000828}
829
830void VP9EncoderImpl::PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
Niels Möllerd3b8c632018-08-27 15:33:42 +0200831 absl::optional<int>* spatial_idx,
philipelcce46fc2015-12-21 03:04:49 -0800832 const vpx_codec_cx_pkt& pkt,
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100833 uint32_t timestamp) {
sprang3958ed82017-08-17 08:12:10 -0700834 RTC_CHECK(codec_specific != nullptr);
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000835 codec_specific->codecType = kVideoCodecVP9;
philipelcce46fc2015-12-21 03:04:49 -0800836 CodecSpecificInfoVP9* vp9_info = &(codec_specific->codecSpecific.VP9);
Sergey Silkin07f80cc2018-04-09 13:11:59 +0200837
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100838 vp9_info->first_frame_in_picture = first_frame_in_picture_;
Sergey Silkin738b7e92018-08-23 16:37:27 +0200839 vp9_info->flexible_mode = is_flexible_mode_;
hta257dc392016-10-25 09:05:06 -0700840 vp9_info->ss_data_available =
Sergey Silkin738b7e92018-08-23 16:37:27 +0200841 (pkt.data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
asaperssona9455ab2015-07-31 06:10:09 -0700842
843 vpx_svc_layer_id_t layer_id = {0};
844 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id);
845
sprang3958ed82017-08-17 08:12:10 -0700846 RTC_CHECK_GT(num_temporal_layers_, 0);
“Michael23c5a992018-06-21 11:07:21 -0500847 RTC_CHECK_GT(num_active_spatial_layers_, 0);
asaperssona9455ab2015-07-31 06:10:09 -0700848 if (num_temporal_layers_ == 1) {
sprang3958ed82017-08-17 08:12:10 -0700849 RTC_CHECK_EQ(layer_id.temporal_layer_id, 0);
asaperssona9455ab2015-07-31 06:10:09 -0700850 vp9_info->temporal_idx = kNoTemporalIdx;
851 } else {
852 vp9_info->temporal_idx = layer_id.temporal_layer_id;
853 }
“Michael23c5a992018-06-21 11:07:21 -0500854 if (num_active_spatial_layers_ == 1) {
sprang3958ed82017-08-17 08:12:10 -0700855 RTC_CHECK_EQ(layer_id.spatial_layer_id, 0);
Niels Möllerd3b8c632018-08-27 15:33:42 +0200856 *spatial_idx = absl::nullopt;
asaperssona9455ab2015-07-31 06:10:09 -0700857 } else {
Niels Möllerd3b8c632018-08-27 15:33:42 +0200858 *spatial_idx = layer_id.spatial_layer_id;
asaperssona9455ab2015-07-31 06:10:09 -0700859 }
860 if (layer_id.spatial_layer_id != 0) {
861 vp9_info->ss_data_available = false;
862 }
863
asaperssona9455ab2015-07-31 06:10:09 -0700864 // TODO(asapersson): this info has to be obtained from the encoder.
asaperssoncb50c962015-11-18 01:58:55 -0800865 vp9_info->temporal_up_switch = false;
asaperssona9455ab2015-07-31 06:10:09 -0700866
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200867 if (pkt.data.frame.flags & VPX_FRAME_IS_KEY) {
868 pics_since_key_ = 0;
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100869 } else if (first_frame_in_picture_) {
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200870 ++pics_since_key_;
asaperssona9455ab2015-07-31 06:10:09 -0700871 }
872
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200873 const bool is_key_pic = (pics_since_key_ == 0);
874 const bool is_inter_layer_pred_allowed =
875 (inter_layer_pred_ == InterLayerPredMode::kOn ||
876 (inter_layer_pred_ == InterLayerPredMode::kOnKeyPic && is_key_pic));
877
878 // Always set inter_layer_predicted to true on high layer frame if inter-layer
879 // prediction (ILP) is allowed even if encoder didn't actually use it.
880 // Setting inter_layer_predicted to false would allow receiver to decode high
881 // layer frame without decoding low layer frame. If that would happen (e.g.
882 // if low layer frame is lost) then receiver won't be able to decode next high
883 // layer frame which uses ILP.
884 vp9_info->inter_layer_predicted =
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100885 first_frame_in_picture_ ? false : is_inter_layer_pred_allowed;
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200886
Sergey Silkinc5f152d2018-09-26 13:28:50 +0200887 // Mark all low spatial layer frames as references (not just frames of
888 // active low spatial layers) if inter-layer prediction is enabled since
889 // these frames are indirect references of high spatial layer, which can
890 // later be enabled without key frame.
Sergey Silkin6a8f30e2018-04-26 11:03:49 +0200891 vp9_info->non_ref_for_inter_layer_pred =
Sergey Silkinc5f152d2018-09-26 13:28:50 +0200892 !is_inter_layer_pred_allowed ||
893 layer_id.spatial_layer_id + 1 == num_spatial_layers_;
asapersson00ac85e2015-11-11 05:30:48 -0800894
ivica7f6a6fc2015-09-08 02:40:29 -0700895 // Always populate this, so that the packetizer can properly set the marker
896 // bit.
“Michael23c5a992018-06-21 11:07:21 -0500897 vp9_info->num_spatial_layers = num_active_spatial_layers_;
philipelcfc319b2015-11-10 07:17:23 -0800898
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200899 vp9_info->num_ref_pics = 0;
900 if (vp9_info->flexible_mode) {
901 vp9_info->gof_idx = kNoGofIdx;
902 FillReferenceIndices(pkt, pics_since_key_, vp9_info->inter_layer_predicted,
903 vp9_info);
Sergey Silkin390f3582018-10-01 17:13:50 +0200904 // TODO(webrtc:9794): Add fake reference to empty reference list to
905 // workaround the frame buffer issue on receiver.
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200906 } else {
907 vp9_info->gof_idx =
908 static_cast<uint8_t>(pics_since_key_ % gof_.num_frames_in_gof);
909 vp9_info->temporal_up_switch = gof_.temporal_up_switch[vp9_info->gof_idx];
910 vp9_info->num_ref_pics = gof_.num_ref_pics[vp9_info->gof_idx];
911 }
912
913 vp9_info->inter_pic_predicted = (!is_key_pic && vp9_info->num_ref_pics > 0);
914
asaperssona9455ab2015-07-31 06:10:09 -0700915 if (vp9_info->ss_data_available) {
asaperssona9455ab2015-07-31 06:10:09 -0700916 vp9_info->spatial_layer_resolution_present = true;
“Michael23c5a992018-06-21 11:07:21 -0500917 for (size_t i = 0; i < num_active_spatial_layers_; ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200918 vp9_info->width[i] = codec_.width * svc_params_.scaling_factor_num[i] /
johannkoenig8225c402017-01-26 13:23:44 -0800919 svc_params_.scaling_factor_den[i];
Yves Gerey665174f2018-06-19 15:03:05 +0200920 vp9_info->height[i] = codec_.height * svc_params_.scaling_factor_num[i] /
johannkoenig8225c402017-01-26 13:23:44 -0800921 svc_params_.scaling_factor_den[i];
asaperssona9455ab2015-07-31 06:10:09 -0700922 }
Sergey Silkin738b7e92018-08-23 16:37:27 +0200923 if (vp9_info->flexible_mode) {
924 vp9_info->gof.num_frames_in_gof = 0;
925 } else {
asaperssona9455ab2015-07-31 06:10:09 -0700926 vp9_info->gof.CopyGofInfoVP9(gof_);
927 }
928 }
Sergey Silkin88ce4ef2018-11-23 13:59:24 +0100929
930 first_frame_in_picture_ = false;
marpan@webrtc.org5b883172014-11-01 06:10:48 +0000931}
932
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200933void VP9EncoderImpl::FillReferenceIndices(const vpx_codec_cx_pkt& pkt,
934 const size_t pic_num,
935 const bool inter_layer_predicted,
936 CodecSpecificInfoVP9* vp9_info) {
937 vpx_svc_layer_id_t layer_id = {0};
938 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id);
939
Sergey Silkin76be2952018-08-21 12:30:33 +0200940 const bool is_key_frame =
941 (pkt.data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200942
943 std::vector<RefFrameBuffer> ref_buf_list;
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200944
Sergey Silkin76be2952018-08-21 12:30:33 +0200945 if (is_svc_) {
946 vpx_svc_ref_frame_config_t enc_layer_conf = {{0}};
947 vpx_codec_control(encoder_, VP9E_GET_SVC_REF_FRAME_CONFIG, &enc_layer_conf);
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200948
Sergey Silkin76be2952018-08-21 12:30:33 +0200949 if (enc_layer_conf.reference_last[layer_id.spatial_layer_id]) {
950 const size_t fb_idx =
951 enc_layer_conf.lst_fb_idx[layer_id.spatial_layer_id];
952 RTC_DCHECK(ref_buf_.find(fb_idx) != ref_buf_.end());
Sergey Silkin82276592018-08-27 14:54:20 +0200953 if (std::find(ref_buf_list.begin(), ref_buf_list.end(),
954 ref_buf_.at(fb_idx)) == ref_buf_list.end()) {
955 ref_buf_list.push_back(ref_buf_.at(fb_idx));
956 }
Sergey Silkin76be2952018-08-21 12:30:33 +0200957 }
958
959 if (enc_layer_conf.reference_alt_ref[layer_id.spatial_layer_id]) {
960 const size_t fb_idx =
961 enc_layer_conf.alt_fb_idx[layer_id.spatial_layer_id];
962 RTC_DCHECK(ref_buf_.find(fb_idx) != ref_buf_.end());
Sergey Silkin82276592018-08-27 14:54:20 +0200963 if (std::find(ref_buf_list.begin(), ref_buf_list.end(),
964 ref_buf_.at(fb_idx)) == ref_buf_list.end()) {
965 ref_buf_list.push_back(ref_buf_.at(fb_idx));
966 }
Sergey Silkin76be2952018-08-21 12:30:33 +0200967 }
968
969 if (enc_layer_conf.reference_golden[layer_id.spatial_layer_id]) {
970 const size_t fb_idx =
971 enc_layer_conf.gld_fb_idx[layer_id.spatial_layer_id];
972 RTC_DCHECK(ref_buf_.find(fb_idx) != ref_buf_.end());
Sergey Silkin82276592018-08-27 14:54:20 +0200973 if (std::find(ref_buf_list.begin(), ref_buf_list.end(),
974 ref_buf_.at(fb_idx)) == ref_buf_list.end()) {
975 ref_buf_list.push_back(ref_buf_.at(fb_idx));
976 }
Sergey Silkin76be2952018-08-21 12:30:33 +0200977 }
978 } else if (!is_key_frame) {
979 RTC_DCHECK_EQ(num_spatial_layers_, 1);
980 RTC_DCHECK_EQ(num_temporal_layers_, 1);
981 // In non-SVC mode encoder doesn't provide reference list. Assume each frame
982 // refers previous one, which is stored in buffer 0.
983 ref_buf_list.push_back(ref_buf_.at(0));
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +0200984 }
985
986 size_t max_ref_temporal_layer_id = 0;
987
988 vp9_info->num_ref_pics = 0;
989 for (const RefFrameBuffer& ref_buf : ref_buf_list) {
990 RTC_DCHECK_LE(ref_buf.pic_num, pic_num);
991 if (ref_buf.pic_num < pic_num) {
992 if (inter_layer_pred_ != InterLayerPredMode::kOn) {
993 // RTP spec limits temporal prediction to the same spatial layer.
994 // It is safe to ignore this requirement if inter-layer prediction is
995 // enabled for all frames when all base frames are relayed to receiver.
996 RTC_DCHECK_EQ(ref_buf.spatial_layer_id, layer_id.spatial_layer_id);
997 }
998 RTC_DCHECK_LE(ref_buf.temporal_layer_id, layer_id.temporal_layer_id);
999
1000 const size_t p_diff = pic_num - ref_buf.pic_num;
1001 RTC_DCHECK_LE(p_diff, 127UL);
1002
1003 vp9_info->p_diff[vp9_info->num_ref_pics] = static_cast<uint8_t>(p_diff);
1004 ++vp9_info->num_ref_pics;
1005
1006 max_ref_temporal_layer_id =
1007 std::max(max_ref_temporal_layer_id, ref_buf.temporal_layer_id);
1008 } else {
1009 RTC_DCHECK(inter_layer_predicted);
1010 // RTP spec only allows to use previous spatial layer for inter-layer
1011 // prediction.
1012 RTC_DCHECK_EQ(ref_buf.spatial_layer_id + 1, layer_id.spatial_layer_id);
1013 }
1014 }
1015
1016 vp9_info->temporal_up_switch =
1017 (max_ref_temporal_layer_id <
1018 static_cast<size_t>(layer_id.temporal_layer_id));
1019}
1020
1021void VP9EncoderImpl::UpdateReferenceBuffers(const vpx_codec_cx_pkt& pkt,
1022 const size_t pic_num) {
1023 vpx_svc_layer_id_t layer_id = {0};
1024 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id);
1025
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +02001026 const bool is_key_frame =
1027 (pkt.data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
1028
1029 RefFrameBuffer frame_buf(pic_num, layer_id.spatial_layer_id,
1030 layer_id.temporal_layer_id);
1031
1032 if (is_key_frame && layer_id.spatial_layer_id == 0) {
1033 // Key frame updates all ref buffers.
1034 for (size_t i = 0; i < kNumVp9Buffers; ++i) {
1035 ref_buf_[i] = frame_buf;
1036 }
Sergey Silkin76be2952018-08-21 12:30:33 +02001037 } else if (is_svc_) {
1038 vpx_svc_ref_frame_config_t enc_layer_conf = {{0}};
1039 vpx_codec_control(encoder_, VP9E_GET_SVC_REF_FRAME_CONFIG, &enc_layer_conf);
1040
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +02001041 if (enc_layer_conf.update_last[layer_id.spatial_layer_id]) {
1042 ref_buf_[enc_layer_conf.lst_fb_idx[layer_id.spatial_layer_id]] =
1043 frame_buf;
1044 }
1045
1046 if (enc_layer_conf.update_alt_ref[layer_id.spatial_layer_id]) {
1047 ref_buf_[enc_layer_conf.alt_fb_idx[layer_id.spatial_layer_id]] =
1048 frame_buf;
1049 }
1050
1051 if (enc_layer_conf.update_golden[layer_id.spatial_layer_id]) {
1052 ref_buf_[enc_layer_conf.gld_fb_idx[layer_id.spatial_layer_id]] =
1053 frame_buf;
1054 }
Sergey Silkin76be2952018-08-21 12:30:33 +02001055 } else {
1056 RTC_DCHECK_EQ(num_spatial_layers_, 1);
1057 RTC_DCHECK_EQ(num_temporal_layers_, 1);
1058 // In non-svc mode encoder doesn't provide reference list. Assume each frame
1059 // is reference and stored in buffer 0.
1060 ref_buf_[0] = frame_buf;
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +02001061 }
1062}
1063
Sergey Silkin390f3582018-10-01 17:13:50 +02001064vpx_svc_ref_frame_config_t VP9EncoderImpl::SetReferences(bool is_key_pic) {
1065 // kRefBufIdx, kUpdBufIdx need to be updated to support longer GOFs.
1066 RTC_DCHECK_LE(gof_.num_frames_in_gof, 4);
1067
1068 vpx_svc_ref_frame_config_t ref_config;
1069 memset(&ref_config, 0, sizeof(ref_config));
1070
1071 const size_t num_temporal_refs = std::max(1, num_temporal_layers_ - 1);
1072 const bool is_inter_layer_pred_allowed =
1073 inter_layer_pred_ == InterLayerPredMode::kOn ||
1074 (inter_layer_pred_ == InterLayerPredMode::kOnKeyPic && is_key_pic);
1075 absl::optional<int> last_updated_buf_idx;
1076
1077 // Put temporal reference to LAST and spatial reference to GOLDEN. Update
1078 // frame buffer (i.e. store encoded frame) if current frame is a temporal
1079 // reference (i.e. it belongs to a low temporal layer) or it is a spatial
1080 // reference. In later case, always store spatial reference in the last
1081 // reference frame buffer.
1082 // For the case of 3 temporal and 3 spatial layers we need 6 frame buffers
1083 // for temporal references plus 1 buffer for spatial reference. 7 buffers
1084 // in total.
1085
1086 for (size_t sl_idx = 0; sl_idx < num_active_spatial_layers_; ++sl_idx) {
1087 const size_t gof_idx = pics_since_key_ % gof_.num_frames_in_gof;
1088
1089 if (!is_key_pic) {
1090 // Set up temporal reference.
1091 const int buf_idx = sl_idx * num_temporal_refs + kRefBufIdx[gof_idx];
1092
1093 // Last reference frame buffer is reserved for spatial reference. It is
1094 // not supposed to be used for temporal prediction.
1095 RTC_DCHECK_LT(buf_idx, kNumVp9Buffers - 1);
1096
1097 // Sanity check that reference picture number is smaller than current
1098 // picture number.
1099 const size_t curr_pic_num = pics_since_key_ + 1;
1100 RTC_DCHECK_LT(ref_buf_[buf_idx].pic_num, curr_pic_num);
1101 const size_t pid_diff = curr_pic_num - ref_buf_[buf_idx].pic_num;
1102
1103 // Below code assumes single temporal referecence.
1104 RTC_DCHECK_EQ(gof_.num_ref_pics[gof_idx], 1);
1105 if (pid_diff == gof_.pid_diff[gof_idx][0]) {
1106 ref_config.lst_fb_idx[sl_idx] = buf_idx;
1107 ref_config.reference_last[sl_idx] = 1;
1108 } else {
1109 // This reference doesn't match with one specified by GOF. This can
1110 // only happen if spatial layer is enabled dynamically without key
1111 // frame. Spatial prediction is supposed to be enabled in this case.
1112 RTC_DCHECK(is_inter_layer_pred_allowed);
1113 }
1114 }
1115
1116 if (is_inter_layer_pred_allowed && sl_idx > 0) {
1117 // Set up spatial reference.
1118 RTC_DCHECK(last_updated_buf_idx);
1119 ref_config.gld_fb_idx[sl_idx] = *last_updated_buf_idx;
1120 ref_config.reference_golden[sl_idx] = 1;
1121 } else {
1122 RTC_DCHECK(ref_config.reference_last[sl_idx] != 0 || sl_idx == 0 ||
1123 inter_layer_pred_ == InterLayerPredMode::kOff);
1124 }
1125
1126 last_updated_buf_idx.reset();
1127
1128 if (gof_.temporal_idx[gof_idx] <= num_temporal_layers_ - 1) {
1129 last_updated_buf_idx = sl_idx * num_temporal_refs + kUpdBufIdx[gof_idx];
1130
1131 // Ensure last frame buffer is not used for temporal prediction (it is
1132 // reserved for spatial reference).
1133 RTC_DCHECK_LT(*last_updated_buf_idx, kNumVp9Buffers - 1);
1134 } else if (is_inter_layer_pred_allowed) {
1135 last_updated_buf_idx = kNumVp9Buffers - 1;
1136 }
1137
1138 if (last_updated_buf_idx) {
1139 ref_config.update_buffer_slot[sl_idx] = 1 << *last_updated_buf_idx;
1140 }
1141 }
1142
1143 return ref_config;
1144}
1145
asaperssona9455ab2015-07-31 06:10:09 -07001146int VP9EncoderImpl::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) {
asapersson86956de2016-01-26 01:05:20 -08001147 RTC_DCHECK_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT);
asaperssona9455ab2015-07-31 06:10:09 -07001148
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001149 if (pkt->data.frame.sz == 0) {
1150 // Ignore dropped frame.
1151 return WEBRTC_VIDEO_CODEC_OK;
1152 }
1153
Sergey Silkin07f80cc2018-04-09 13:11:59 +02001154 vpx_svc_layer_id_t layer_id = {0};
1155 vpx_codec_control(encoder_, VP9E_GET_SVC_LAYER_ID, &layer_id);
1156
Sergey Silkin88ce4ef2018-11-23 13:59:24 +01001157 if (!full_superframe_drop_) {
1158 // Deliver buffered low spatial layer frame.
1159 const bool end_of_picture = false;
1160 DeliverBufferedFrame(end_of_picture);
1161 }
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001162
asaperssond9f641e2016-01-21 01:11:35 -08001163 if (pkt->data.frame.sz > encoded_image_._size) {
1164 delete[] encoded_image_._buffer;
1165 encoded_image_._size = pkt->data.frame.sz;
1166 encoded_image_._buffer = new uint8_t[encoded_image_._size];
1167 }
asapersson86956de2016-01-26 01:05:20 -08001168 memcpy(encoded_image_._buffer, pkt->data.frame.buf, pkt->data.frame.sz);
1169 encoded_image_._length = pkt->data.frame.sz;
asaperssond9f641e2016-01-21 01:11:35 -08001170
Sergey Silkinbd0954e2018-05-03 14:14:09 +02001171 const bool is_key_frame =
1172 (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
1173 // Ensure encoder issued key frame on request.
1174 RTC_DCHECK(is_key_frame || !force_key_frame_);
1175
asaperssona9455ab2015-07-31 06:10:09 -07001176 // Check if encoded frame is a key frame.
asapersson86956de2016-01-26 01:05:20 -08001177 encoded_image_._frameType = kVideoFrameDelta;
Sergey Silkinbd0954e2018-05-03 14:14:09 +02001178 if (is_key_frame) {
Peter Boström49e196a2015-10-23 15:58:18 +02001179 encoded_image_._frameType = kVideoFrameKey;
Sergey Silkinbd0954e2018-05-03 14:14:09 +02001180 force_key_frame_ = false;
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001181 }
asapersson86956de2016-01-26 01:05:20 -08001182 RTC_DCHECK_LE(encoded_image_._length, encoded_image_._size);
1183
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001184 memset(&codec_specific_, 0, sizeof(codec_specific_));
Niels Möllerd3b8c632018-08-27 15:33:42 +02001185 absl::optional<int> spatial_index;
1186 PopulateCodecSpecific(&codec_specific_, &spatial_index, *pkt,
Sergey Silkin88ce4ef2018-11-23 13:59:24 +01001187 input_image_->timestamp());
Niels Möllerd3b8c632018-08-27 15:33:42 +02001188 encoded_image_.SetSpatialIndex(spatial_index);
asaperssona9455ab2015-07-31 06:10:09 -07001189
Sergey Silkin4e6cd5e2018-05-28 12:26:36 +02001190 if (is_flexible_mode_) {
1191 UpdateReferenceBuffers(*pkt, pics_since_key_);
1192 }
1193
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001194 TRACE_COUNTER1("webrtc", "EncodedFrameSize", encoded_image_._length);
Niels Möller23775882018-08-16 10:24:12 +02001195 encoded_image_.SetTimestamp(input_image_->timestamp());
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001196 encoded_image_.capture_time_ms_ = input_image_->render_time_ms();
1197 encoded_image_.rotation_ = input_image_->rotation();
Niels Möllere3cf3d02018-06-13 11:52:16 +02001198 encoded_image_.content_type_ = (codec_.mode == VideoCodecMode::kScreensharing)
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001199 ? VideoContentType::SCREENSHARE
1200 : VideoContentType::UNSPECIFIED;
1201 encoded_image_._encodedHeight =
1202 pkt->data.frame.height[layer_id.spatial_layer_id];
1203 encoded_image_._encodedWidth =
1204 pkt->data.frame.width[layer_id.spatial_layer_id];
Ilya Nikolaevskiyb6c462d2018-06-05 15:21:32 +02001205 encoded_image_.timing_.flags = VideoSendTiming::kInvalid;
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001206 int qp = -1;
1207 vpx_codec_control(encoder_, VP8E_GET_LAST_QUANTIZER, &qp);
1208 encoded_image_.qp_ = qp;
Johannes Kron4749e4e2018-11-21 10:18:18 +01001209 encoded_image_.SetColorSpace(input_image_->color_space());
ilnik04f4d122017-06-19 07:18:55 -07001210
Sergey Silkin88ce4ef2018-11-23 13:59:24 +01001211 if (full_superframe_drop_) {
1212 const bool end_of_picture = encoded_image_.SpatialIndex().value_or(0) + 1 ==
1213 num_active_spatial_layers_;
1214 DeliverBufferedFrame(end_of_picture);
1215 }
1216
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001217 return WEBRTC_VIDEO_CODEC_OK;
1218}
1219
Sergey Silkinbc0f0d32018-04-24 21:29:14 +02001220void VP9EncoderImpl::DeliverBufferedFrame(bool end_of_picture) {
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001221 if (encoded_image_._length > 0) {
Sergey Silkinbc0f0d32018-04-24 21:29:14 +02001222 codec_specific_.codecSpecific.VP9.end_of_picture = end_of_picture;
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001223
1224 // No data partitioning in VP9, so 1 partition only.
1225 int part_idx = 0;
1226 RTPFragmentationHeader frag_info;
1227 frag_info.VerifyAndAllocateFragmentationHeader(1);
1228 frag_info.fragmentationOffset[part_idx] = 0;
1229 frag_info.fragmentationLength[part_idx] = encoded_image_._length;
1230 frag_info.fragmentationPlType[part_idx] = 0;
1231 frag_info.fragmentationTimeDiff[part_idx] = 0;
1232
1233 encoded_complete_callback_->OnEncodedImage(encoded_image_, &codec_specific_,
1234 &frag_info);
1235 encoded_image_._length = 0;
Sergey Silkind902d582018-05-18 17:31:19 +02001236
Sergey Silkin96f2c972018-09-05 21:07:17 +02001237 if (codec_.mode == VideoCodecMode::kScreensharing) {
1238 const uint8_t spatial_idx = encoded_image_.SpatialIndex().value_or(0);
1239 const uint32_t frame_timestamp_ms =
Niels Möller23775882018-08-16 10:24:12 +02001240 1000 * encoded_image_.Timestamp() / kVideoPayloadTypeFrequency;
Sergey Silkin96f2c972018-09-05 21:07:17 +02001241 framerate_controller_[spatial_idx].AddFrame(frame_timestamp_ms);
Sergey Silkind902d582018-05-18 17:31:19 +02001242 }
Sergey Silkin2a1f1832018-04-04 11:45:41 +02001243 }
1244}
1245
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001246int VP9EncoderImpl::RegisterEncodeCompleteCallback(
1247 EncodedImageCallback* callback) {
1248 encoded_complete_callback_ = callback;
1249 return WEBRTC_VIDEO_CODEC_OK;
1250}
1251
Erik Språng727d1642018-11-07 16:54:15 +01001252VideoEncoder::EncoderInfo VP9EncoderImpl::GetEncoderInfo() const {
1253 EncoderInfo info;
1254 info.supports_native_handle = false;
1255 info.implementation_name = "libvpx";
1256 info.scaling_settings = VideoEncoder::ScalingSettings::kOff;
Erik Språngd3438aa2018-11-08 16:56:43 +01001257 info.has_trusted_rate_controller = trusted_rate_controller_;
Erik Språng727d1642018-11-07 16:54:15 +01001258 return info;
Peter Boströmb7d9a972015-12-18 16:01:11 +01001259}
1260
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001261VP9DecoderImpl::VP9DecoderImpl()
sprang3958ed82017-08-17 08:12:10 -07001262 : decode_complete_callback_(nullptr),
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001263 inited_(false),
sprang3958ed82017-08-17 08:12:10 -07001264 decoder_(nullptr),
philipel9d7d75b2018-04-04 13:03:01 +02001265 key_frame_required_(true) {}
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001266
1267VP9DecoderImpl::~VP9DecoderImpl() {
1268 inited_ = true; // in order to do the actual release
1269 Release();
Henrik Boström9695d852015-05-06 10:42:15 +02001270 int num_buffers_in_use = frame_buffer_pool_.GetNumBuffersInUse();
1271 if (num_buffers_in_use > 0) {
1272 // The frame buffers are reference counted and frames are exposed after
1273 // decoding. There may be valid usage cases where previous frames are still
1274 // referenced after ~VP9DecoderImpl that is not a leak.
Mirko Bonadei675513b2017-11-09 11:09:25 +01001275 RTC_LOG(LS_INFO) << num_buffers_in_use << " Vp9FrameBuffers are still "
1276 << "referenced during ~VP9DecoderImpl.";
Henrik Boström9695d852015-05-06 10:42:15 +02001277 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001278}
1279
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001280int VP9DecoderImpl::InitDecode(const VideoCodec* inst, int number_of_cores) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001281 int ret_val = Release();
1282 if (ret_val < 0) {
1283 return ret_val;
1284 }
Sergey Silkinb674cd12018-10-09 10:59:06 +02001285
sprang3958ed82017-08-17 08:12:10 -07001286 if (decoder_ == nullptr) {
pbos@webrtc.orge728ee02014-12-17 13:43:55 +00001287 decoder_ = new vpx_codec_ctx_t;
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001288 }
philipelcce46fc2015-12-21 03:04:49 -08001289 vpx_codec_dec_cfg_t cfg;
Sergey Silkinb674cd12018-10-09 10:59:06 +02001290 memset(&cfg, 0, sizeof(cfg));
1291
1292 // We want to use multithreading when decoding high resolution videos. But,
1293 // since we don't know resolution of input stream at this stage, we always
1294 // enable it.
1295 cfg.threads = std::min(number_of_cores, kMaxNumTiles4kVideo);
1296
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001297 vpx_codec_flags_t flags = 0;
1298 if (vpx_codec_dec_init(decoder_, vpx_codec_vp9_dx(), &cfg, flags)) {
1299 return WEBRTC_VIDEO_CODEC_MEMORY;
1300 }
Henrik Boström9695d852015-05-06 10:42:15 +02001301
1302 if (!frame_buffer_pool_.InitializeVpxUsePool(decoder_)) {
1303 return WEBRTC_VIDEO_CODEC_MEMORY;
1304 }
1305
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001306 inited_ = true;
1307 // Always start with a complete key frame.
1308 key_frame_required_ = true;
1309 return WEBRTC_VIDEO_CODEC_OK;
1310}
1311
1312int VP9DecoderImpl::Decode(const EncodedImage& input_image,
1313 bool missing_frames,
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001314 const CodecSpecificInfo* codec_specific_info,
1315 int64_t /*render_time_ms*/) {
1316 if (!inited_) {
1317 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
1318 }
sprang3958ed82017-08-17 08:12:10 -07001319 if (decode_complete_callback_ == nullptr) {
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001320 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
1321 }
1322 // Always start with a complete key frame.
1323 if (key_frame_required_) {
Peter Boström49e196a2015-10-23 15:58:18 +02001324 if (input_image._frameType != kVideoFrameKey)
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001325 return WEBRTC_VIDEO_CODEC_ERROR;
1326 // We have a key frame - is it complete?
1327 if (input_image._completeFrame) {
1328 key_frame_required_ = false;
1329 } else {
1330 return WEBRTC_VIDEO_CODEC_ERROR;
1331 }
1332 }
sprang3958ed82017-08-17 08:12:10 -07001333 vpx_codec_iter_t iter = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001334 vpx_image_t* img;
1335 uint8_t* buffer = input_image._buffer;
1336 if (input_image._length == 0) {
sprang3958ed82017-08-17 08:12:10 -07001337 buffer = nullptr; // Triggers full frame concealment.
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001338 }
Henrik Boström9695d852015-05-06 10:42:15 +02001339 // During decode libvpx may get and release buffers from |frame_buffer_pool_|.
1340 // In practice libvpx keeps a few (~3-4) buffers alive at a time.
philipelcce46fc2015-12-21 03:04:49 -08001341 if (vpx_codec_decode(decoder_, buffer,
1342 static_cast<unsigned int>(input_image._length), 0,
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001343 VPX_DL_REALTIME)) {
1344 return WEBRTC_VIDEO_CODEC_ERROR;
1345 }
Henrik Boström9695d852015-05-06 10:42:15 +02001346 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer.
1347 // It may be released by libvpx during future vpx_codec_decode or
1348 // vpx_codec_destroy calls.
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001349 img = vpx_codec_get_frame(decoder_, &iter);
sakal7adadb12017-02-23 02:54:57 -08001350 int qp;
1351 vpx_codec_err_t vpx_ret =
1352 vpx_codec_control(decoder_, VPXD_GET_LAST_QUANTIZER, &qp);
1353 RTC_DCHECK_EQ(vpx_ret, VPX_CODEC_OK);
Johannes Kron9973fa82018-11-07 14:39:26 +01001354 int ret = ReturnFrame(img, input_image.Timestamp(), input_image.ntp_time_ms_,
Johannes Kron4749e4e2018-11-21 10:18:18 +01001355 qp, input_image.ColorSpace());
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001356 if (ret != 0) {
1357 return ret;
1358 }
1359 return WEBRTC_VIDEO_CODEC_OK;
1360}
1361
asapersson1490f7a2016-09-23 02:09:46 -07001362int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img,
1363 uint32_t timestamp,
sakal7adadb12017-02-23 02:54:57 -08001364 int64_t ntp_time_ms,
Johannes Kron9973fa82018-11-07 14:39:26 +01001365 int qp,
Johannes Kron4749e4e2018-11-21 10:18:18 +01001366 const ColorSpace* explicit_color_space) {
sprang3958ed82017-08-17 08:12:10 -07001367 if (img == nullptr) {
1368 // Decoder OK and nullptr image => No show frame.
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001369 return WEBRTC_VIDEO_CODEC_NO_OUTPUT;
1370 }
Henrik Boström9695d852015-05-06 10:42:15 +02001371
1372 // This buffer contains all of |img|'s image data, a reference counted
perkj14f41442015-11-30 22:15:45 -08001373 // Vp9FrameBuffer. (libvpx is done with the buffers after a few
Henrik Boström9695d852015-05-06 10:42:15 +02001374 // vpx_codec_decode calls or vpx_codec_destroy).
1375 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer =
1376 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv);
Emircan Uysaler0823eec2018-07-13 17:10:00 -07001377
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07001378 // The buffer can be used directly by the VideoFrame (without copy) by
Emircan Uysaler0823eec2018-07-13 17:10:00 -07001379 // using a Wrapped*Buffer.
1380 rtc::scoped_refptr<VideoFrameBuffer> img_wrapped_buffer;
1381 switch (img->bit_depth) {
1382 case 8:
1383 img_wrapped_buffer = WrapI420Buffer(
philipelcce46fc2015-12-21 03:04:49 -08001384 img->d_w, img->d_h, img->planes[VPX_PLANE_Y],
1385 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U],
1386 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V],
1387 img->stride[VPX_PLANE_V],
Henrik Boström9695d852015-05-06 10:42:15 +02001388 // WrappedI420Buffer's mechanism for allowing the release of its frame
1389 // buffer is through a callback function. This is where we should
1390 // release |img_buffer|.
Emircan Uysaler0823eec2018-07-13 17:10:00 -07001391 rtc::KeepRefUntilDone(img_buffer));
1392 break;
1393 case 10:
1394 img_wrapped_buffer = WrapI010Buffer(
1395 img->d_w, img->d_h,
1396 reinterpret_cast<const uint16_t*>(img->planes[VPX_PLANE_Y]),
1397 img->stride[VPX_PLANE_Y] / 2,
1398 reinterpret_cast<const uint16_t*>(img->planes[VPX_PLANE_U]),
1399 img->stride[VPX_PLANE_U] / 2,
1400 reinterpret_cast<const uint16_t*>(img->planes[VPX_PLANE_V]),
1401 img->stride[VPX_PLANE_V] / 2, rtc::KeepRefUntilDone(img_buffer));
1402 break;
1403 default:
1404 RTC_NOTREACHED();
1405 return WEBRTC_VIDEO_CODEC_NO_OUTPUT;
1406 }
nisseca6d5d12016-06-17 05:03:04 -07001407
Johannes Kron4749e4e2018-11-21 10:18:18 +01001408 auto builder = VideoFrame::Builder()
1409 .set_video_frame_buffer(img_wrapped_buffer)
1410 .set_timestamp_ms(0)
1411 .set_timestamp_rtp(timestamp)
1412 .set_ntp_time_ms(ntp_time_ms)
1413 .set_rotation(webrtc::kVideoRotation_0);
1414 if (explicit_color_space) {
1415 builder.set_color_space(explicit_color_space);
1416 } else {
1417 builder.set_color_space(
1418 ExtractVP9ColorSpace(img->cs, img->range, img->bit_depth));
1419 }
1420
1421 VideoFrame decoded_image = builder.build();
1422
Danil Chapovalov0040b662018-06-18 10:48:16 +02001423 decode_complete_callback_->Decoded(decoded_image, absl::nullopt, qp);
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001424 return WEBRTC_VIDEO_CODEC_OK;
1425}
1426
1427int VP9DecoderImpl::RegisterDecodeCompleteCallback(
1428 DecodedImageCallback* callback) {
1429 decode_complete_callback_ = callback;
1430 return WEBRTC_VIDEO_CODEC_OK;
1431}
1432
1433int VP9DecoderImpl::Release() {
Sergey Silkin3e871ea2018-03-02 13:11:04 +01001434 int ret_val = WEBRTC_VIDEO_CODEC_OK;
1435
sprang3958ed82017-08-17 08:12:10 -07001436 if (decoder_ != nullptr) {
Sergey Silkin90399692018-03-02 14:44:10 +01001437 if (inited_) {
1438 // When a codec is destroyed libvpx will release any buffers of
1439 // |frame_buffer_pool_| it is currently using.
1440 if (vpx_codec_destroy(decoder_)) {
1441 ret_val = WEBRTC_VIDEO_CODEC_MEMORY;
1442 }
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001443 }
1444 delete decoder_;
sprang3958ed82017-08-17 08:12:10 -07001445 decoder_ = nullptr;
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001446 }
Henrik Boström9695d852015-05-06 10:42:15 +02001447 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers
1448 // still referenced externally are deleted once fully released, not returning
1449 // to the pool.
1450 frame_buffer_pool_.ClearPool();
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001451 inited_ = false;
Sergey Silkin3e871ea2018-03-02 13:11:04 +01001452 return ret_val;
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001453}
Peter Boströmb7d9a972015-12-18 16:01:11 +01001454
1455const char* VP9DecoderImpl::ImplementationName() const {
1456 return "libvpx";
1457}
1458
marpan@webrtc.org5b883172014-11-01 06:10:48 +00001459} // namespace webrtc
Mirko Bonadei95adedb2018-11-19 09:52:37 +01001460
1461#endif // RTC_ENABLE_VP9