Enable encoder multi-threading for VP9.

R=stefan@webrtc.org
TBR=stefan@webrtc.org
BUG=

Review URL: https://webrtc-codereview.appspot.com/41489004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@8150 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
marpan@webrtc.org 2015-01-26 15:21:36 +00:00
parent 6f200b5b87
commit 38d11b8529
2 changed files with 28 additions and 0 deletions

View File

@ -181,9 +181,29 @@ int VP9EncoderImpl::InitEncode(const VideoCodec* inst,
} else {
config_->kf_mode = VPX_KF_DISABLED;
}
// Determine number of threads based on the image size and #cores.
config_->g_threads = NumberOfThreads(config_->g_w,
config_->g_h,
number_of_cores);
return InitAndSetControlSettings(inst);
}
int VP9EncoderImpl::NumberOfThreads(int width,
int height,
int number_of_cores) {
// Keep the number of encoder threads equal to the possible number of column
// tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS.
if (width * height >= 1280 * 720 && number_of_cores > 4) {
return 4;
} else if (width * height >= 640 * 480 && number_of_cores > 2) {
return 2;
} else {
// 1 thread less than VGA.
return 1;
}
}
int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
@ -198,6 +218,11 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
rc_max_intra_target_);
vpx_codec_control(encoder_, VP9E_SET_AQ_MODE,
inst->codecSpecific.VP9.adaptiveQpMode ? 3 : 0);
// Control function to set the number of column tiles in encoding a frame, in
// log2 unit: e.g., 0 = 1 tile column, 1 = 2 tile columns, 2 = 4 tile columns.
// The number tile columns will be capped by the encoder based on image size
// (minimum width of tile column is 256 pixels, maximum is 4096).
vpx_codec_control(encoder_, VP9E_SET_TILE_COLUMNS, (config_->g_threads >> 1));
// TODO(marpan): Enable in future libvpx roll: waiting for SSE2 optimization.
// #if !defined(WEBRTC_ARCH_ARM)
// vpx_codec_control(encoder_, VP9E_SET_NOISE_SENSITIVITY,

View File

@ -43,6 +43,9 @@ class VP9EncoderImpl : public VP9Encoder {
virtual int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) OVERRIDE;
private:
// Determine number of encoder threads to use.
int NumberOfThreads(int width, int height, int number_of_cores);
// Call encoder initialize function and set control settings.
int InitAndSetControlSettings(const VideoCodec* inst);