Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc

Issue 1397363002: Revert of Adding support for simulcast and spatial layers into VideoQualityTest (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 * 9 *
10 */ 10 */
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 config_ = NULL; 105 config_ = NULL;
106 } 106 }
107 if (raw_ != NULL) { 107 if (raw_ != NULL) {
108 vpx_img_free(raw_); 108 vpx_img_free(raw_);
109 raw_ = NULL; 109 raw_ = NULL;
110 } 110 }
111 inited_ = false; 111 inited_ = false;
112 return WEBRTC_VIDEO_CODEC_OK; 112 return WEBRTC_VIDEO_CODEC_OK;
113 } 113 }
114 114
115 bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const {
116 // We check target_bitrate_bps of the 0th layer to see if the spatial layers
117 // (i.e. bitrates) were explicitly configured.
118 return num_spatial_layers_ > 1 &&
119 codec_.spatialLayers[0].target_bitrate_bps > 0;
120 }
121
122 bool VP9EncoderImpl::SetSvcRates() { 115 bool VP9EncoderImpl::SetSvcRates() {
116 float rate_ratio[VPX_MAX_LAYERS] = {0};
117 float total = 0;
123 uint8_t i = 0; 118 uint8_t i = 0;
124 119
125 if (ExplicitlyConfiguredSpatialLayers()) { 120 for (i = 0; i < num_spatial_layers_; ++i) {
126 if (num_temporal_layers_ > 1) { 121 if (svc_internal_.svc_params.scaling_factor_num[i] <= 0 ||
127 LOG(LS_ERROR) << "Multiple temporal layers when manually specifying " 122 svc_internal_.svc_params.scaling_factor_den[i] <= 0) {
128 "spatial layers not implemented yet!";
129 return false; 123 return false;
130 } 124 }
131 int total_bitrate_bps = 0; 125 rate_ratio[i] = static_cast<float>(
132 for (i = 0; i < num_spatial_layers_; ++i) 126 svc_internal_.svc_params.scaling_factor_num[i]) /
133 total_bitrate_bps += codec_.spatialLayers[i].target_bitrate_bps; 127 svc_internal_.svc_params.scaling_factor_den[i];
134 // If total bitrate differs now from what has been specified at the 128 total += rate_ratio[i];
135 // beginning, update the bitrates in the same ratio as before. 129 }
136 for (i = 0; i < num_spatial_layers_; ++i) {
137 config_->ss_target_bitrate[i] =
138 config_->layer_target_bitrate[i] = static_cast<int>(
139 static_cast<int64_t>(config_->rc_target_bitrate) *
140 codec_.spatialLayers[i].target_bitrate_bps / total_bitrate_bps);
141 }
142 } else {
143 float rate_ratio[VPX_MAX_LAYERS] = {0};
144 float total = 0;
145 130
146 for (i = 0; i < num_spatial_layers_; ++i) { 131 for (i = 0; i < num_spatial_layers_; ++i) {
147 if (svc_internal_.svc_params.scaling_factor_num[i] <= 0 || 132 config_->ss_target_bitrate[i] = static_cast<unsigned int>(
148 svc_internal_.svc_params.scaling_factor_den[i] <= 0) { 133 config_->rc_target_bitrate * rate_ratio[i] / total);
149 LOG(LS_ERROR) << "Scaling factors not specified!"; 134 if (num_temporal_layers_ == 1) {
150 return false; 135 config_->layer_target_bitrate[i] = config_->ss_target_bitrate[i];
151 } 136 } else if (num_temporal_layers_ == 2) {
152 rate_ratio[i] = static_cast<float>( 137 config_->layer_target_bitrate[i * num_temporal_layers_] =
153 svc_internal_.svc_params.scaling_factor_num[i]) / 138 config_->ss_target_bitrate[i] * 2 / 3;
154 svc_internal_.svc_params.scaling_factor_den[i]; 139 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
155 total += rate_ratio[i]; 140 config_->ss_target_bitrate[i];
156 } 141 } else if (num_temporal_layers_ == 3) {
157 142 config_->layer_target_bitrate[i * num_temporal_layers_] =
158 for (i = 0; i < num_spatial_layers_; ++i) { 143 config_->ss_target_bitrate[i] / 2;
159 config_->ss_target_bitrate[i] = static_cast<unsigned int>( 144 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
160 config_->rc_target_bitrate * rate_ratio[i] / total); 145 config_->layer_target_bitrate[i * num_temporal_layers_] +
161 if (num_temporal_layers_ == 1) { 146 (config_->ss_target_bitrate[i] / 4);
162 config_->layer_target_bitrate[i] = config_->ss_target_bitrate[i]; 147 config_->layer_target_bitrate[i * num_temporal_layers_ + 2] =
163 } else if (num_temporal_layers_ == 2) { 148 config_->ss_target_bitrate[i];
164 config_->layer_target_bitrate[i * num_temporal_layers_] = 149 } else {
165 config_->ss_target_bitrate[i] * 2 / 3; 150 return false;
166 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
167 config_->ss_target_bitrate[i];
168 } else if (num_temporal_layers_ == 3) {
169 config_->layer_target_bitrate[i * num_temporal_layers_] =
170 config_->ss_target_bitrate[i] / 2;
171 config_->layer_target_bitrate[i * num_temporal_layers_ + 1] =
172 config_->layer_target_bitrate[i * num_temporal_layers_] +
173 (config_->ss_target_bitrate[i] / 4);
174 config_->layer_target_bitrate[i * num_temporal_layers_ + 2] =
175 config_->ss_target_bitrate[i];
176 } else {
177 LOG(LS_ERROR) << "Unsupported number of temporal layers: "
178 << num_temporal_layers_;
179 return false;
180 }
181 } 151 }
182 } 152 }
183 153
184 // For now, temporal layers only supported when having one spatial layer. 154 // For now, temporal layers only supported when having one spatial layer.
185 if (num_spatial_layers_ == 1) { 155 if (num_spatial_layers_ == 1) {
186 for (i = 0; i < num_temporal_layers_; ++i) { 156 for (i = 0; i < num_temporal_layers_; ++i) {
187 config_->ts_target_bitrate[i] = config_->layer_target_bitrate[i]; 157 config_->ts_target_bitrate[i] = config_->layer_target_bitrate[i];
188 } 158 }
189 } 159 }
190 160
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return 2; 348 return 2;
379 } else { 349 } else {
380 // 1 thread less than VGA. 350 // 1 thread less than VGA.
381 return 1; 351 return 1;
382 } 352 }
383 } 353 }
384 354
385 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { 355 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
386 config_->ss_number_layers = num_spatial_layers_; 356 config_->ss_number_layers = num_spatial_layers_;
387 357
388 if (ExplicitlyConfiguredSpatialLayers()) { 358 int scaling_factor_num = 256;
389 for (int i = 0; i < num_spatial_layers_; ++i) { 359 for (int i = num_spatial_layers_ - 1; i >= 0; --i) {
390 const auto &layer = codec_.spatialLayers[i]; 360 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer;
391 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer; 361 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer;
392 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer; 362 // 1:2 scaling in each dimension.
393 svc_internal_.svc_params.scaling_factor_num[i] = layer.scaling_factor_num; 363 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num;
394 svc_internal_.svc_params.scaling_factor_den[i] = layer.scaling_factor_den; 364 svc_internal_.svc_params.scaling_factor_den[i] = 256;
395 } 365 scaling_factor_num /= 2;
396 } else {
397 int scaling_factor_num = 256;
398 for (int i = num_spatial_layers_ - 1; i >= 0; --i) {
399 svc_internal_.svc_params.max_quantizers[i] = config_->rc_max_quantizer;
400 svc_internal_.svc_params.min_quantizers[i] = config_->rc_min_quantizer;
401 // 1:2 scaling in each dimension.
402 svc_internal_.svc_params.scaling_factor_num[i] = scaling_factor_num;
403 svc_internal_.svc_params.scaling_factor_den[i] = 256;
404 scaling_factor_num /= 2;
405 }
406 } 366 }
407 367
408 if (!SetSvcRates()) { 368 if (!SetSvcRates()) {
409 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 369 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
410 } 370 }
411 371
412 if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) { 372 if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) {
413 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; 373 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
414 } 374 }
415 vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_); 375 vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 decoder_ = NULL; 781 decoder_ = NULL;
822 } 782 }
823 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers 783 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers
824 // still referenced externally are deleted once fully released, not returning 784 // still referenced externally are deleted once fully released, not returning
825 // to the pool. 785 // to the pool.
826 frame_buffer_pool_.ClearPool(); 786 frame_buffer_pool_.ClearPool();
827 inited_ = false; 787 inited_ = false;
828 return WEBRTC_VIDEO_CODEC_OK; 788 return WEBRTC_VIDEO_CODEC_OK;
829 } 789 }
830 } // namespace webrtc 790 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp9/vp9_impl.h ('k') | webrtc/test/layer_filtering_transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698