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

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

Issue 2510583002: Reland #2 of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Addressed comments Created 4 years, 1 month 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 cpu_speed_(3), 70 cpu_speed_(3),
71 rc_max_intra_target_(0), 71 rc_max_intra_target_(0),
72 encoder_(NULL), 72 encoder_(NULL),
73 config_(NULL), 73 config_(NULL),
74 raw_(NULL), 74 raw_(NULL),
75 input_image_(NULL), 75 input_image_(NULL),
76 tl0_pic_idx_(0), 76 tl0_pic_idx_(0),
77 frames_since_kf_(0), 77 frames_since_kf_(0),
78 num_temporal_layers_(0), 78 num_temporal_layers_(0),
79 num_spatial_layers_(0), 79 num_spatial_layers_(0),
80 is_flexible_mode_(false),
80 frames_encoded_(0), 81 frames_encoded_(0),
81 // Use two spatial when screensharing with flexible mode. 82 // Use two spatial when screensharing with flexible mode.
82 spatial_layer_(new ScreenshareLayersVP9(2)) { 83 spatial_layer_(new ScreenshareLayersVP9(2)) {
83 memset(&codec_, 0, sizeof(codec_)); 84 memset(&codec_, 0, sizeof(codec_));
84 memset(&svc_internal_.svc_params, 0, sizeof(vpx_svc_extra_cfg_t)); 85 memset(&svc_internal_.svc_params, 0, sizeof(vpx_svc_extra_cfg_t));
85 uint32_t seed = rtc::Time32(); 86 uint32_t seed = rtc::Time32();
86 srand(seed); 87 srand(seed);
87 } 88 }
88 89
89 VP9EncoderImpl::~VP9EncoderImpl() { 90 VP9EncoderImpl::~VP9EncoderImpl() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // For now, temporal layers only supported when having one spatial layer. 187 // For now, temporal layers only supported when having one spatial layer.
187 if (num_spatial_layers_ == 1) { 188 if (num_spatial_layers_ == 1) {
188 for (i = 0; i < num_temporal_layers_; ++i) { 189 for (i = 0; i < num_temporal_layers_; ++i) {
189 config_->ts_target_bitrate[i] = config_->layer_target_bitrate[i]; 190 config_->ts_target_bitrate[i] = config_->layer_target_bitrate[i];
190 } 191 }
191 } 192 }
192 193
193 return true; 194 return true;
194 } 195 }
195 196
196 int VP9EncoderImpl::SetRates(uint32_t new_bitrate_kbit, 197 int VP9EncoderImpl::SetRateAllocation(
197 uint32_t new_framerate) { 198 const BitrateAllocation& bitrate_allocation,
199 uint32_t frame_rate) {
198 if (!inited_) { 200 if (!inited_) {
199 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; 201 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
200 } 202 }
201 if (encoder_->err) { 203 if (encoder_->err) {
202 return WEBRTC_VIDEO_CODEC_ERROR; 204 return WEBRTC_VIDEO_CODEC_ERROR;
203 } 205 }
204 if (new_framerate < 1) { 206 if (frame_rate < 1) {
205 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 207 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
206 } 208 }
207 // Update bit rate 209 // Update bit rate
208 if (codec_.maxBitrate > 0 && new_bitrate_kbit > codec_.maxBitrate) { 210 if (codec_.maxBitrate > 0 &&
209 new_bitrate_kbit = codec_.maxBitrate; 211 bitrate_allocation.get_sum_kbps() > codec_.maxBitrate) {
212 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
210 } 213 }
211 config_->rc_target_bitrate = new_bitrate_kbit; 214
212 codec_.maxFramerate = new_framerate; 215 // TODO(sprang): Actually use BitrateAllocation layer info.
213 spatial_layer_->ConfigureBitrate(new_bitrate_kbit, 0); 216 config_->rc_target_bitrate = bitrate_allocation.get_sum_kbps();
217 codec_.maxFramerate = frame_rate;
218 spatial_layer_->ConfigureBitrate(bitrate_allocation.get_sum_kbps(), 0);
214 219
215 if (!SetSvcRates()) { 220 if (!SetSvcRates()) {
216 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 221 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
217 } 222 }
218 223
219 // Update encoder context 224 // Update encoder context
220 if (vpx_codec_enc_config_set(encoder_, config_)) { 225 if (vpx_codec_enc_config_set(encoder_, config_)) {
221 return WEBRTC_VIDEO_CODEC_ERROR; 226 return WEBRTC_VIDEO_CODEC_ERROR;
222 } 227 }
223 return WEBRTC_VIDEO_CODEC_OK; 228 return WEBRTC_VIDEO_CODEC_OK;
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 frame_buffer_pool_.ClearPool(); 999 frame_buffer_pool_.ClearPool();
995 inited_ = false; 1000 inited_ = false;
996 return WEBRTC_VIDEO_CODEC_OK; 1001 return WEBRTC_VIDEO_CODEC_OK;
997 } 1002 }
998 1003
999 const char* VP9DecoderImpl::ImplementationName() const { 1004 const char* VP9DecoderImpl::ImplementationName() const {
1000 return "libvpx"; 1005 return "libvpx";
1001 } 1006 }
1002 1007
1003 } // namespace webrtc 1008 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp9/vp9_impl.h ('k') | webrtc/modules/video_coding/generic_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698