From d08826f038f6fe9a275ba66ff8d0af60a78a7f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 13 Dec 2017 15:27:06 +0100 Subject: [PATCH] encoder: use max 16 threads for video, 4 for audio Audio encoding is usually mono-threaded and doesn't require as much CPU as video encoding. Limit to 4 threads since more would not be useful and might introduce latency and decrease performance. Video encoding takes significantly more resources, however for live encoding, using more than 16 threads might introduce unreasonable latency. Since new customer CPUs (AMD Ryzen and Intel Core i7/i9) now have more than 16 logical cores, setting a higher bound of 16 threads. Change-Id: I5dc2d3f51019c563b8cec3fbddffa13cbafdb9a5 --- src/media/media_encoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/media/media_encoder.cpp b/src/media/media_encoder.cpp index 6d924939bb..21dfe25365 100644 --- a/src/media/media_encoder.cpp +++ b/src/media/media_encoder.cpp @@ -521,7 +521,7 @@ void MediaEncoder::prepareEncoderContext(bool is_video) encoderName = "encoder?"; - encoderCtx_->thread_count = std::thread::hardware_concurrency(); + encoderCtx_->thread_count = std::min(std::thread::hardware_concurrency(), is_video ? 16u : 4u); RING_DBG("[%s] Using %d threads", encoderName, encoderCtx_->thread_count); -- GitLab