diff mbox series

[FFmpeg-devel,3/3] lavu/hwcontext_qsv: limit the number of threads used for hwupload & hwdownload to 2

Message ID 20210408070929.860244-3-haihao.xiang@intel.com
State New
Headers show
Series [FFmpeg-devel,1/3] lavc/qsv: apply AVCodecContext AVOption -threads to QSV
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Xiang, Haihao April 8, 2021, 7:09 a.m. UTC
The session for hwupload & hwdownload is used to copy data between
system and video memory, 2 threads are sufficient for the copy in the
SDK.
---
 libavutil/hwcontext_qsv.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 84cf5015ff..5dbe2b1701 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -456,8 +456,25 @@  static int qsv_init_internal_session(AVHWFramesContext *ctx,
 
     mfxVideoParam par;
     mfxStatus err;
+    mfxInitParam init_par = { MFX_IMPL_AUTO_ANY };
 
-    err = MFXInit(device_priv->impl, &device_priv->ver, session);
+#if QSV_VERSION_ATLEAST(1, 15)
+    mfxExtBuffer *ext_params[1];
+    mfxExtThreadsParam thread_param;
+
+    memset(&thread_param, 0, sizeof(thread_param));
+    thread_param.Header.BufferId = MFX_EXTBUFF_THREADS_PARAM;
+    thread_param.Header.BufferSz = sizeof(thread_param);
+    thread_param.NumThread       = 2;
+    ext_params[0]                = (mfxExtBuffer *)&thread_param;
+    init_par.ExtParam            = (mfxExtBuffer **)&ext_params;
+    init_par.NumExtParam         = 1;
+#endif
+
+    init_par.Implementation      = device_priv->impl;
+    init_par.Version             = device_priv->ver;
+
+    err = MFXInitEx(init_par, session);
     if (err != MFX_ERR_NONE) {
         av_log(ctx, AV_LOG_ERROR, "Error initializing an internal session\n");
         return AVERROR_UNKNOWN;