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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 config_->rc_buf_optimal_sz = 600; | 187 config_->rc_buf_optimal_sz = 600; |
188 config_->rc_buf_sz = 1000; | 188 config_->rc_buf_sz = 1000; |
189 // Set the maximum target size of any key-frame. | 189 // Set the maximum target size of any key-frame. |
190 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); | 190 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); |
191 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { | 191 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { |
192 config_->kf_mode = VPX_KF_AUTO; | 192 config_->kf_mode = VPX_KF_AUTO; |
193 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; | 193 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; |
194 } else { | 194 } else { |
195 config_->kf_mode = VPX_KF_DISABLED; | 195 config_->kf_mode = VPX_KF_DISABLED; |
196 } | 196 } |
197 | |
198 // Determine number of threads based on the image size and #cores. | 197 // Determine number of threads based on the image size and #cores. |
199 config_->g_threads = NumberOfThreads(config_->g_w, | 198 config_->g_threads = NumberOfThreads(config_->g_w, |
200 config_->g_h, | 199 config_->g_h, |
201 number_of_cores); | 200 number_of_cores); |
201 cpu_speed_ = SetCpuSpeed(config_->g_w, config_->g_h); | |
202 return InitAndSetControlSettings(inst); | 202 return InitAndSetControlSettings(inst); |
203 } | 203 } |
204 | 204 |
205 // Only positive speeds, range for real-time coding currently is: 5 - 8. | |
206 // Lower means slower/better quality, higher means fastest/lower quality. | |
207 int VP9EncoderImpl::SetCpuSpeed(int width, int height) { | |
stefan-webrtc
2015/06/25 15:26:02
GetCpuSpeed
stefan-webrtc
2015/06/25 15:26:49
And actually, please make this a regular function
| |
208 // For smaller resolutions, use lower speed setting (get some coding gain at | |
209 // the cost of increased encoding complexity). | |
210 if (width * height <= 352 * 288) | |
211 return 5; | |
212 else | |
213 return 7; | |
214 } | |
215 | |
205 int VP9EncoderImpl::NumberOfThreads(int width, | 216 int VP9EncoderImpl::NumberOfThreads(int width, |
206 int height, | 217 int height, |
207 int number_of_cores) { | 218 int number_of_cores) { |
208 // Keep the number of encoder threads equal to the possible number of column | 219 // Keep the number of encoder threads equal to the possible number of column |
209 // tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS. | 220 // tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS. |
210 if (width * height >= 1280 * 720 && number_of_cores > 4) { | 221 if (width * height >= 1280 * 720 && number_of_cores > 4) { |
211 return 4; | 222 return 4; |
212 } else if (width * height >= 640 * 480 && number_of_cores > 2) { | 223 } else if (width * height >= 640 * 480 && number_of_cores > 2) { |
213 return 2; | 224 return 2; |
214 } else { | 225 } else { |
215 // 1 thread less than VGA. | 226 // 1 thread less than VGA. |
216 return 1; | 227 return 1; |
217 } | 228 } |
218 } | 229 } |
219 | 230 |
220 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { | 231 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { |
221 if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) { | 232 if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) { |
222 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 233 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
223 } | 234 } |
224 // Only positive speeds, currently: 0 - 8. | |
225 // O means slowest/best quality, 8 means fastest/lower quality. | |
226 cpu_speed_ = 7; | |
227 // Note: some of these codec controls still use "VP8" in the control name. | |
228 // TODO(marpan): Update this in the next/future libvpx version. | |
229 vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_); | 235 vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_); |
230 vpx_codec_control(encoder_, VP8E_SET_MAX_INTRA_BITRATE_PCT, | 236 vpx_codec_control(encoder_, VP8E_SET_MAX_INTRA_BITRATE_PCT, |
231 rc_max_intra_target_); | 237 rc_max_intra_target_); |
232 vpx_codec_control(encoder_, VP9E_SET_AQ_MODE, | 238 vpx_codec_control(encoder_, VP9E_SET_AQ_MODE, |
233 inst->codecSpecific.VP9.adaptiveQpMode ? 3 : 0); | 239 inst->codecSpecific.VP9.adaptiveQpMode ? 3 : 0); |
234 // Control function to set the number of column tiles in encoding a frame, in | 240 // Control function to set the number of column tiles in encoding a frame, in |
235 // log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns. | 241 // log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns. |
236 // The number tile columns will be capped by the encoder based on image size | 242 // The number tile columns will be capped by the encoder based on image size |
237 // (minimum width of tile column is 256 pixels, maximum is 4096). | 243 // (minimum width of tile column is 256 pixels, maximum is 4096). |
238 vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1)); | 244 vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1)); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 decoder_ = NULL; | 559 decoder_ = NULL; |
554 } | 560 } |
555 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers | 561 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers |
556 // still referenced externally are deleted once fully released, not returning | 562 // still referenced externally are deleted once fully released, not returning |
557 // to the pool. | 563 // to the pool. |
558 frame_buffer_pool_.ClearPool(); | 564 frame_buffer_pool_.ClearPool(); |
559 inited_ = false; | 565 inited_ = false; |
560 return WEBRTC_VIDEO_CODEC_OK; | 566 return WEBRTC_VIDEO_CODEC_OK; |
561 } | 567 } |
562 } // namespace webrtc | 568 } // namespace webrtc |
OLD | NEW |