From b674cd103847da8639a58b60aba4df093314ae8c Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Tue, 9 Oct 2018 10:59:06 +0200 Subject: [PATCH] Enable multithreading in libvpx VP9 decoder. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set number of decode threads equal to number of available cores and limit the maximum value to the maximum number of tiles possible for HD resolution. Bug: webrtc:9829, b/117291409 Change-Id: Ib5ccd5cc412011d4438258491efc060cdd050fc7 Reviewed-on: https://webrtc-review.googlesource.com/c/104064 Reviewed-by: Erik Språng Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/master@{#25059} --- modules/video_coding/codecs/vp9/vp9_impl.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index 6b982a8a13..d8f5877e24 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -42,6 +42,8 @@ namespace { uint8_t kRefBufIdx[4] = {0, 0, 0, 1}; uint8_t kUpdBufIdx[4] = {0, 0, 1, 0}; +int kMaxNumTiles4kVideo = 8; + // Only positive speeds, range for real-time coding currently is: 5 - 8. // Lower means slower/better quality, higher means fastest/lower quality. int GetCpuSpeed(int width, int height) { @@ -1272,13 +1274,18 @@ int VP9DecoderImpl::InitDecode(const VideoCodec* inst, int number_of_cores) { if (ret_val < 0) { return ret_val; } + if (decoder_ == nullptr) { decoder_ = new vpx_codec_ctx_t; } vpx_codec_dec_cfg_t cfg; - // Setting number of threads to a constant value (1) - cfg.threads = 1; - cfg.h = cfg.w = 0; // set after decode + memset(&cfg, 0, sizeof(cfg)); + + // We want to use multithreading when decoding high resolution videos. But, + // since we don't know resolution of input stream at this stage, we always + // enable it. + cfg.threads = std::min(number_of_cores, kMaxNumTiles4kVideo); + vpx_codec_flags_t flags = 0; if (vpx_codec_dec_init(decoder_, vpx_codec_vp9_dx(), &cfg, flags)) { return WEBRTC_VIDEO_CODEC_MEMORY;