OLD | NEW |
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 Loading... |
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 Loading... |
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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 frame_buffer_pool_.ClearPool(); | 1001 frame_buffer_pool_.ClearPool(); |
997 inited_ = false; | 1002 inited_ = false; |
998 return WEBRTC_VIDEO_CODEC_OK; | 1003 return WEBRTC_VIDEO_CODEC_OK; |
999 } | 1004 } |
1000 | 1005 |
1001 const char* VP9DecoderImpl::ImplementationName() const { | 1006 const char* VP9DecoderImpl::ImplementationName() const { |
1002 return "libvpx"; | 1007 return "libvpx"; |
1003 } | 1008 } |
1004 | 1009 |
1005 } // namespace webrtc | 1010 } // namespace webrtc |
OLD | NEW |