diff mbox series

[FFmpeg-devel,2/3] lavu/hwcontext_qsv: limit the number of threads for QSV HW device to 2

Message ID 20210408070929.860244-2-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 created for QSV HW device will be used as parent session
only, so we needn't create more threads for this session
---
 libavutil/hwcontext_qsv.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 30b0d81f84..84cf5015ff 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1142,6 +1142,12 @@  static int qsv_device_derive_from_child(AVHWDeviceContext *ctx,
     mfxHandleType handle_type;
     mfxStatus     err;
     int ret;
+    mfxInitParam  init_par = { MFX_IMPL_AUTO_ANY };
+
+#if QSV_VERSION_ATLEAST(1, 15)
+    mfxExtBuffer *ext_params[1];
+    mfxExtThreadsParam thread_param;
+#endif
 
     switch (child_device_ctx->type) {
 #if CONFIG_VAAPI
@@ -1167,7 +1173,20 @@  static int qsv_device_derive_from_child(AVHWDeviceContext *ctx,
         goto fail;
     }
 
-    err = MFXInit(implementation, &ver, &hwctx->session);
+    init_par.Implementation = implementation;
+    init_par.Version        = ver;
+
+#if QSV_VERSION_ATLEAST(1, 15)
+    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
+
+    err = MFXInitEx(init_par, &hwctx->session);
     if (err != MFX_ERR_NONE) {
         av_log(ctx, AV_LOG_ERROR, "Error initializing an MFX session: "
                "%d.\n", err);
@@ -1188,7 +1207,8 @@  static int qsv_device_derive_from_child(AVHWDeviceContext *ctx,
 
     MFXClose(hwctx->session);
 
-    err = MFXInit(implementation, &ver, &hwctx->session);
+    init_par.Version = ver;
+    err = MFXInitEx(init_par, &hwctx->session);
     if (err != MFX_ERR_NONE) {
         av_log(ctx, AV_LOG_ERROR,
                "Error initializing an MFX session: %d.\n", err);