Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Haihao Xiang <haihao.xiang@intel.com>
Subject: [FFmpeg-devel] [PATCH 08/13] lavc/qsvdec: require a dynamic frame pool if possible
Date: Wed,  6 Sep 2023 14:00:47 +0800
Message-ID: <20230906060052.698620-8-haihao.xiang@intel.com> (raw)
In-Reply-To: <20230906060052.698620-1-haihao.xiang@intel.com>

From: Haihao Xiang <haihao.xiang@intel.com>

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 libavcodec/qsvdec.c | 57 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index da700f25e9..5549df304a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -42,6 +42,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/mastering_display_metadata.h"
+#include "libavutil/avassert.h"
 
 #include "avcodec.h"
 #include "codec_internal.h"
@@ -67,6 +68,8 @@ static const AVRational mfx_tb = { 1, 90000 };
     AV_NOPTS_VALUE : pts_tb.num ? \
     av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 typedef struct QSVAsyncFrame {
     mfxSyncPoint *sync;
     QSVFrame     *frame;
@@ -76,6 +79,7 @@ typedef struct QSVContext {
     // the session used for decoding
     mfxSession session;
     mfxVersion ver;
+    mfxHandleType handle_type;
 
     // the session we allocated internally, in case the caller did not provide
     // one
@@ -182,6 +186,7 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
                             AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
 {
     int ret;
+    mfxIMPL impl;
 
     if (q->gpu_copy == MFX_GPUCOPY_ON &&
         !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
@@ -239,27 +244,52 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
         q->session = q->internal_qs.session;
     }
 
-    if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
-        av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
-        q->session = NULL;
+    if (MFXQueryIMPL(q->session, &impl) == MFX_ERR_NONE) {
+        switch (MFX_IMPL_VIA_MASK(impl)) {
+        case MFX_IMPL_VIA_VAAPI:
+            q->handle_type = MFX_HANDLE_VA_DISPLAY;
+            break;
 
-        if (q->internal_qs.session) {
-            MFXClose(q->internal_qs.session);
-            q->internal_qs.session = NULL;
-        }
+        case MFX_IMPL_VIA_D3D11:
+            q->handle_type = MFX_HANDLE_D3D11_DEVICE;
+            break;
+
+        case MFX_IMPL_VIA_D3D9:
+            q->handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+            break;
 
-        if (q->internal_qs.loader) {
-            MFXUnload(q->internal_qs.loader);
-            q->internal_qs.loader = NULL;
+        default:
+            av_assert0(!"should not reach here");
         }
+    } else {
+        av_log(avctx, AV_LOG_ERROR, "Error querying the implementation. \n");
+        goto fail;
+    }
 
-        return AVERROR_EXTERNAL;
+    if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
+        av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
+        goto fail;
     }
 
     /* make sure the decoder is uninitialized */
     MFXVideoDECODE_Close(q->session);
 
     return 0;
+
+fail:
+    q->session = NULL;
+
+    if (q->internal_qs.session) {
+        MFXClose(q->internal_qs.session);
+        q->internal_qs.session = NULL;
+    }
+
+    if (q->internal_qs.loader) {
+        MFXUnload(q->internal_qs.loader);
+        q->internal_qs.loader = NULL;
+    }
+
+    return AVERROR_EXTERNAL;
 }
 
 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
@@ -309,7 +339,10 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
         hwframes_ctx->height            = FFALIGN(avctx->coded_height, 32);
         hwframes_ctx->format            = AV_PIX_FMT_QSV;
         hwframes_ctx->sw_format         = avctx->sw_pix_fmt;
-        hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
+        if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && q->handle_type != MFX_HANDLE_D3D9_DEVICE_MANAGER)
+            hwframes_ctx->initial_pool_size = 0;
+        else
+            hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
         frames_hwctx->frame_type        = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
 
         ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-09-06  6:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06  6:00 [FFmpeg-devel] [PATCH 01/13] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 02/13] lavu/hwcontext_qsv: create dynamic frame pool if required Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 03/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 04/13] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 05/13] lavc/qsv: fix qsv_frame_get_hdl callback to support dynamic frame pools Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 06/13] lavc/qsv: set right mfxFrameInfo for frames in " Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 07/13] lavc/qsv: needn't QSVMid array " Xiang, Haihao
2023-09-06  6:00 ` Xiang, Haihao [this message]
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 09/13] lavfi/qsvvpp: set right mfxFrameInfo " Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 10/13] lavfi/qsvvpp: require a dynamic frame pool for output if possible Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 11/13] lavu/hwcontext_vaapi: relax the requirement when using libva2 (VAAPI 1) Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 12/13] lavc/vaapi_decode: use dynamic frame pool for output frames with libva2 Xiang, Haihao
2023-09-06  6:00 ` [FFmpeg-devel] [PATCH 13/13] lavfi/vaapi_vpp: use dynamic frame pool for output link " Xiang, Haihao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230906060052.698620-8-haihao.xiang@intel.com \
    --to=haihao.xiang-at-intel.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=haihao.xiang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git