From 9de164cfba8ac6384f7c87e5dab4d20a0bd26dfe Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 14 Feb 2020 10:05:10 +1100 Subject: [PATCH] ffmpeg: disable multithreading in favor of our own Our renderer system is already heavily multithreaded and prioritized to keep the main thread active. As a result, FFmpeg receives little benefits from being multithreaded and is actually detrimental to our main thread as it hasn't been prioritized to keep the main thread as active as possible. --- app/codec/ffmpeg/ffmpegdecoder.cpp | 12 +++++++++--- app/codec/ffmpeg/ffmpegdecoder.h | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 3e0398c6f..f5cd7e2f7 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -47,7 +47,8 @@ FFmpegDecoder::FFmpegDecoder() : scale_ctx_(nullptr), pkt_(nullptr), frame_(nullptr), - opts_(nullptr) + opts_(nullptr), + multithreading_(false) { } @@ -125,8 +126,8 @@ bool FFmpegDecoder::Open() return false; } - // enable multithreading on decoding - error_code = av_dict_set(&opts_, "threads", "auto", 0); + // Set multithreading setting + error_code = av_dict_set(&opts_, "threads", multithreading_ ? "auto" : "1", 0); // Handle failure to set multithreaded decoding if (error_code < 0) { @@ -524,6 +525,11 @@ bool FFmpegDecoder::SupportsAudio() return true; } +void FFmpegDecoder::SetMultithreading(bool e) +{ + multithreading_ = e; +} + void FFmpegDecoder::ConformInternal(SwrContext* resampler, WaveOutput* output, const char* in_data, int in_sample_count) { // Determine how many samples the output will be diff --git a/app/codec/ffmpeg/ffmpegdecoder.h b/app/codec/ffmpeg/ffmpegdecoder.h index 2d80ffbaf..e88010957 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.h +++ b/app/codec/ffmpeg/ffmpegdecoder.h @@ -61,6 +61,8 @@ public: virtual bool SupportsVideo() override; virtual bool SupportsAudio() override; + void SetMultithreading(bool e); + private: void ConformInternal(SwrContext *resampler, WaveOutput *output, const char *in_data, int in_sample_count); @@ -145,6 +147,8 @@ private: QVector frame_index_; + bool multithreading_; + }; #endif // FFMPEGDECODER_H