diff mbox

[FFmpeg-devel] avcodec/libaom: fix setting amount of threads

Message ID 20180913162651.11916-1-jamrial@gmail.com
State Accepted
Commit 309c3a0e81be553626711912e90015c26f4b09ba
Headers show

Commit Message

James Almer Sept. 13, 2018, 4:26 p.m. UTC
The libaom doxy says that a value of 0 for the threads fields is
equivalent to a value of 1, whereas for avctx->thread_count it means
the maximum amount of threads possible for the host system.

Use av_cpu_count() to get the correct thread count when auto threads
is requested.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libaomdec.c | 2 +-
 libavcodec/libaomenc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Jan Ekström Sept. 13, 2018, 4:32 p.m. UTC | #1
On Thu, Sep 13, 2018 at 7:26 PM, James Almer <jamrial@gmail.com> wrote:
> The libaom doxy says that a value of 0 for the threads fields is
> equivalent to a value of 1, whereas for avctx->thread_count it means
> the maximum amount of threads possible for the host system.
>
> Use av_cpu_count() to get the correct thread count when auto threads
> is requested.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---

Same things as in our libvpx wrappers, LGTM.

Jan
James Almer Sept. 13, 2018, 4:59 p.m. UTC | #2
On 9/13/2018 1:32 PM, Jan Ekström wrote:
> On Thu, Sep 13, 2018 at 7:26 PM, James Almer <jamrial@gmail.com> wrote:
>> The libaom doxy says that a value of 0 for the threads fields is
>> equivalent to a value of 1, whereas for avctx->thread_count it means
>> the maximum amount of threads possible for the host system.
>>
>> Use av_cpu_count() to get the correct thread count when auto threads
>> is requested.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
> 
> Same things as in our libvpx wrappers, LGTM.
> 
> Jan

Pushed, thanks.
diff mbox

Patch

diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
index 6a2de6d47a..2530c9f76b 100644
--- a/libavcodec/libaomdec.c
+++ b/libavcodec/libaomdec.c
@@ -43,7 +43,7 @@  static av_cold int aom_init(AVCodecContext *avctx,
     AV1DecodeContext *ctx           = avctx->priv_data;
     struct aom_codec_dec_cfg deccfg = {
         /* token partitions+1 would be a decent choice */
-        .threads = FFMIN(avctx->thread_count, 16)
+        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16)
     };
 
     av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str());
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index bbf4cf8b64..6a79d9b873 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -319,7 +319,7 @@  static av_cold int aom_init(AVCodecContext *avctx,
     enccfg.g_h            = avctx->height;
     enccfg.g_timebase.num = avctx->time_base.num;
     enccfg.g_timebase.den = avctx->time_base.den;
-    enccfg.g_threads      = avctx->thread_count;
+    enccfg.g_threads      = avctx->thread_count ? avctx->thread_count : av_cpu_count();
 
     if (ctx->lag_in_frames >= 0)
         enccfg.g_lag_in_frames = ctx->lag_in_frames;