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 24 matching lines...) Expand all Loading... | |
35 // VP9DecoderImpl::ReturnFrame helper function used with WrappedI420Buffer. | 35 // VP9DecoderImpl::ReturnFrame helper function used with WrappedI420Buffer. |
36 static void WrappedI420BufferNoLongerUsedCb( | 36 static void WrappedI420BufferNoLongerUsedCb( |
37 webrtc::Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer) { | 37 webrtc::Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer) { |
38 img_buffer->Release(); | 38 img_buffer->Release(); |
39 } | 39 } |
40 | 40 |
41 } // anonymous namespace | 41 } // anonymous namespace |
42 | 42 |
43 namespace webrtc { | 43 namespace webrtc { |
44 | 44 |
45 // Only positive speeds, range for real-time coding currently is: 5 - 8. | |
46 // Lower means slower/better quality, higher means fastest/lower quality. | |
47 int GetCpuSpeed(int width, int height) { | |
tommi
2015/07/08 09:13:39
Can this be in an anonymous namespace?
Also, I fin
| |
48 // For smaller resolutions, use lower speed setting (get some coding gain at | |
49 // the cost of increased encoding complexity). | |
50 if (width * height <= 352 * 288) | |
51 return 5; | |
52 else | |
53 return 7; | |
54 } | |
55 | |
45 VP9Encoder* VP9Encoder::Create() { | 56 VP9Encoder* VP9Encoder::Create() { |
46 return new VP9EncoderImpl(); | 57 return new VP9EncoderImpl(); |
47 } | 58 } |
48 | 59 |
49 VP9EncoderImpl::VP9EncoderImpl() | 60 VP9EncoderImpl::VP9EncoderImpl() |
50 : encoded_image_(), | 61 : encoded_image_(), |
51 encoded_complete_callback_(NULL), | 62 encoded_complete_callback_(NULL), |
52 inited_(false), | 63 inited_(false), |
53 timestamp_(0), | 64 timestamp_(0), |
54 picture_id_(0), | 65 picture_id_(0), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 config_->rc_buf_optimal_sz = 600; | 198 config_->rc_buf_optimal_sz = 600; |
188 config_->rc_buf_sz = 1000; | 199 config_->rc_buf_sz = 1000; |
189 // Set the maximum target size of any key-frame. | 200 // Set the maximum target size of any key-frame. |
190 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); | 201 rc_max_intra_target_ = MaxIntraTarget(config_->rc_buf_optimal_sz); |
191 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { | 202 if (inst->codecSpecific.VP9.keyFrameInterval > 0) { |
192 config_->kf_mode = VPX_KF_AUTO; | 203 config_->kf_mode = VPX_KF_AUTO; |
193 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; | 204 config_->kf_max_dist = inst->codecSpecific.VP9.keyFrameInterval; |
194 } else { | 205 } else { |
195 config_->kf_mode = VPX_KF_DISABLED; | 206 config_->kf_mode = VPX_KF_DISABLED; |
196 } | 207 } |
197 | |
198 // Determine number of threads based on the image size and #cores. | 208 // Determine number of threads based on the image size and #cores. |
199 config_->g_threads = NumberOfThreads(config_->g_w, | 209 config_->g_threads = NumberOfThreads(config_->g_w, |
200 config_->g_h, | 210 config_->g_h, |
201 number_of_cores); | 211 number_of_cores); |
212 cpu_speed_ = GetCpuSpeed(config_->g_w, config_->g_h); | |
202 return InitAndSetControlSettings(inst); | 213 return InitAndSetControlSettings(inst); |
203 } | 214 } |
204 | 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; | |
tommi
2015/07/08 09:13:39
cpu_speed_ is in my opinion not a great variable n
| |
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 |