Enable multithreading in libvpx VP9 decoder.

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 <sprang@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25059}
This commit is contained in:
Sergey Silkin
2018-10-09 10:59:06 +02:00
committed by Commit Bot
parent d0bc462556
commit b674cd1038

View File

@ -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;