Re: [FFmpeg-devel] [PATCH v12 11/13] lavc/qsv: create mfx session using oneVPL for decoding/encoding

2022-08-02 Thread Anton Khirnov
Quoting Xiang, Haihao (2022-08-02 10:20:16)
> Thanks for the comment. I planed to cleanup qsv code, including duplicated 
> code
> in the current qsv filters. Does it make sense to enable/merge oneVPL firstly
> then cleanup qsv in new patches?

Sure, I do not insist it's done right now, given that duplication
already exists.
It would be nice to do it at some point though.

-- 
Anton Khirnov
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v12 11/13] lavc/qsv: create mfx session using oneVPL for decoding/encoding

2022-08-02 Thread Xiang, Haihao
On Mon, 2022-08-01 at 15:33 +0200, Anton Khirnov wrote:
> Quoting Xiang, Haihao (2022-07-25 06:11:49)
> > From: Haihao Xiang 
> > 
> > If qsv hwdevice is available, use the mfxLoader handle in qsv hwdevice
> > to create mfx session. Otherwise create mfx session with a new mfxLoader
> > handle.
> > 
> > This is in preparation for oneVPL support
> > ---
> >  libavcodec/qsv.c  | 226 +++---
> >  libavcodec/qsv_internal.h |   1 +
> >  libavcodec/qsvdec.c   |  11 ++
> >  libavcodec/qsvenc.h   |   3 +
> >  libavcodec/qsvenc_h264.c  |   1 -
> >  libavcodec/qsvenc_hevc.c  |   1 -
> >  libavcodec/qsvenc_jpeg.c  |   1 -
> >  libavcodec/qsvenc_mpeg2.c |   1 -
> >  libavcodec/qsvenc_vp9.c   |   1 -
> >  9 files changed, 223 insertions(+), 23 deletions(-)
> > 
> > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> > index 432675bccf..fe998c9649 100644
> > --- a/libavcodec/qsv.c
> > +++ b/libavcodec/qsv.c
> > @@ -45,6 +45,12 @@
> >  #include 
> >  #endif
> >  
> > +#if QSV_ONEVPL
> > +#include 
> > +#else
> > +#define MFXUnload(a) do { } while(0)
> > +#endif
> > +
> >  int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
> >  {
> >  switch (codec_id) {
> > @@ -419,6 +425,193 @@ static int ff_qsv_set_display_handle(AVCodecContext
> > *avctx, QSVSession *qs)
> >  }
> >  #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
> >  
> > +#if QSV_ONEVPL
> > +static int qsv_new_mfx_loader(AVCodecContext *avctx,
> > +  mfxIMPL implementation,
> > +  mfxVersion *pver,
> > +  void **ploader)
> > +{
> > +mfxStatus sts;
> > +mfxLoader loader = NULL;
> > +mfxConfig cfg;
> > +mfxVariant impl_value;
> > +
> > +loader = MFXLoad();
> > +if (!loader) {
> > +av_log(avctx, AV_LOG_ERROR, "Error creating a MFX loader\n");
> > +goto fail;
> > +}
> > +
> > +/* Create configurations for implementation */
> > +cfg = MFXCreateConfig(loader);
> > +if (!cfg) {
> > +av_log(avctx, AV_LOG_ERROR, "Error creating a MFX
> > configurations\n");
> > +goto fail;
> > +}
> > +
> > +impl_value.Type = MFX_VARIANT_TYPE_U32;
> > +impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
> > +MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
> > +sts = MFXSetConfigFilterProperty(cfg,
> > + (const mfxU8
> > *)"mfxImplDescription.Impl", impl_value);
> > +if (sts != MFX_ERR_NONE) {
> > +av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
> > +   "property: %d\n", sts);
> > +goto fail;
> > +}
> > +
> > +impl_value.Type = MFX_VARIANT_TYPE_U32;
> > +impl_value.Data.U32 = pver->Version;
> > +sts = MFXSetConfigFilterProperty(cfg,
> > + (const mfxU8
> > *)"mfxImplDescription.ApiVersion.Version",
> > + impl_value);
> > +if (sts != MFX_ERR_NONE) {
> > +av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
> > +   "property: %d\n", sts);
> > +goto fail;
> > +}
> > +
> > +*ploader = loader;
> > +
> > +return 0;
> > +
> > +fail:
> > +if (loader)
> > +MFXUnload(loader);
> > +
> > +*ploader = NULL;
> > +return AVERROR_UNKNOWN;
> > +}
> > +
> > +static int qsv_create_mfx_session_from_loader(void *ctx, mfxLoader loader,
> > mfxSession *psession)
> > +{
> > +mfxStatus sts;
> > +mfxSession session = NULL;
> > +uint32_t impl_idx = 0;
> > +
> > +while (1) {
> > +/* Enumerate all implementations */
> > +mfxImplDescription *impl_desc;
> > +
> > +sts = MFXEnumImplementations(loader, impl_idx,
> > + MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
> > + (mfxHDL *)_desc);
> > +/* Failed to find an available implementation */
> > +if (sts == MFX_ERR_NOT_FOUND)
> > +break;
> > +else if (sts != MFX_ERR_NONE) {
> > +impl_idx++;
> > +continue;
> > +}
> > +
> > +sts = MFXCreateSession(loader, impl_idx, );
> > +MFXDispReleaseImplDescription(loader, impl_desc);
> > +if (sts == MFX_ERR_NONE)
> > +break;
> > +
> > +impl_idx++;
> > +}
> > +
> > +if (sts != MFX_ERR_NONE) {
> > +av_log(ctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n",
> > sts);
> > +goto fail;
> > +}
> > +
> > +*psession = session;
> > +
> > +return 0;
> > +
> > +fail:
> > +if (session)
> > +MFXClose(session);
> > +
> > +*psession = NULL;
> > +return AVERROR_UNKNOWN;
> > +}
> > +
> > +static int qsv_create_mfx_session(AVCodecContext *avctx,
> > +  mfxIMPL implementation,
> > +  mfxVersion *pver,
> > +  int gpu_copy,
> > +  

Re: [FFmpeg-devel] [PATCH v12 11/13] lavc/qsv: create mfx session using oneVPL for decoding/encoding

2022-08-01 Thread Anton Khirnov
Quoting Xiang, Haihao (2022-07-25 06:11:49)
> From: Haihao Xiang 
> 
> If qsv hwdevice is available, use the mfxLoader handle in qsv hwdevice
> to create mfx session. Otherwise create mfx session with a new mfxLoader
> handle.
> 
> This is in preparation for oneVPL support
> ---
>  libavcodec/qsv.c  | 226 +++---
>  libavcodec/qsv_internal.h |   1 +
>  libavcodec/qsvdec.c   |  11 ++
>  libavcodec/qsvenc.h   |   3 +
>  libavcodec/qsvenc_h264.c  |   1 -
>  libavcodec/qsvenc_hevc.c  |   1 -
>  libavcodec/qsvenc_jpeg.c  |   1 -
>  libavcodec/qsvenc_mpeg2.c |   1 -
>  libavcodec/qsvenc_vp9.c   |   1 -
>  9 files changed, 223 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 432675bccf..fe998c9649 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -45,6 +45,12 @@
>  #include 
>  #endif
>  
> +#if QSV_ONEVPL
> +#include 
> +#else
> +#define MFXUnload(a) do { } while(0)
> +#endif
> +
>  int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
>  {
>  switch (codec_id) {
> @@ -419,6 +425,193 @@ static int ff_qsv_set_display_handle(AVCodecContext 
> *avctx, QSVSession *qs)
>  }
>  #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
>  
> +#if QSV_ONEVPL
> +static int qsv_new_mfx_loader(AVCodecContext *avctx,
> +  mfxIMPL implementation,
> +  mfxVersion *pver,
> +  void **ploader)
> +{
> +mfxStatus sts;
> +mfxLoader loader = NULL;
> +mfxConfig cfg;
> +mfxVariant impl_value;
> +
> +loader = MFXLoad();
> +if (!loader) {
> +av_log(avctx, AV_LOG_ERROR, "Error creating a MFX loader\n");
> +goto fail;
> +}
> +
> +/* Create configurations for implementation */
> +cfg = MFXCreateConfig(loader);
> +if (!cfg) {
> +av_log(avctx, AV_LOG_ERROR, "Error creating a MFX configurations\n");
> +goto fail;
> +}
> +
> +impl_value.Type = MFX_VARIANT_TYPE_U32;
> +impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
> +MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
> +sts = MFXSetConfigFilterProperty(cfg,
> + (const mfxU8 
> *)"mfxImplDescription.Impl", impl_value);
> +if (sts != MFX_ERR_NONE) {
> +av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
> +   "property: %d\n", sts);
> +goto fail;
> +}
> +
> +impl_value.Type = MFX_VARIANT_TYPE_U32;
> +impl_value.Data.U32 = pver->Version;
> +sts = MFXSetConfigFilterProperty(cfg,
> + (const mfxU8 
> *)"mfxImplDescription.ApiVersion.Version",
> + impl_value);
> +if (sts != MFX_ERR_NONE) {
> +av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
> +   "property: %d\n", sts);
> +goto fail;
> +}
> +
> +*ploader = loader;
> +
> +return 0;
> +
> +fail:
> +if (loader)
> +MFXUnload(loader);
> +
> +*ploader = NULL;
> +return AVERROR_UNKNOWN;
> +}
> +
> +static int qsv_create_mfx_session_from_loader(void *ctx, mfxLoader loader, 
> mfxSession *psession)
> +{
> +mfxStatus sts;
> +mfxSession session = NULL;
> +uint32_t impl_idx = 0;
> +
> +while (1) {
> +/* Enumerate all implementations */
> +mfxImplDescription *impl_desc;
> +
> +sts = MFXEnumImplementations(loader, impl_idx,
> + MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
> + (mfxHDL *)_desc);
> +/* Failed to find an available implementation */
> +if (sts == MFX_ERR_NOT_FOUND)
> +break;
> +else if (sts != MFX_ERR_NONE) {
> +impl_idx++;
> +continue;
> +}
> +
> +sts = MFXCreateSession(loader, impl_idx, );
> +MFXDispReleaseImplDescription(loader, impl_desc);
> +if (sts == MFX_ERR_NONE)
> +break;
> +
> +impl_idx++;
> +}
> +
> +if (sts != MFX_ERR_NONE) {
> +av_log(ctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", 
> sts);
> +goto fail;
> +}
> +
> +*psession = session;
> +
> +return 0;
> +
> +fail:
> +if (session)
> +MFXClose(session);
> +
> +*psession = NULL;
> +return AVERROR_UNKNOWN;
> +}
> +
> +static int qsv_create_mfx_session(AVCodecContext *avctx,
> +  mfxIMPL implementation,
> +  mfxVersion *pver,
> +  int gpu_copy,
> +  mfxSession *psession,
> +  void **ploader)
> +{
> +mfxLoader loader = NULL;
> +
> +/* Don't create a new MFX loader if the input loader is valid */
> +if (*ploader == NULL) {
> +av_log(avctx, AV_LOG_VERBOSE,
> +   "Use Intel(R) oneVPL to create MFX session, the 

[FFmpeg-devel] [PATCH v12 11/13] lavc/qsv: create mfx session using oneVPL for decoding/encoding

2022-07-24 Thread Xiang, Haihao
From: Haihao Xiang 

If qsv hwdevice is available, use the mfxLoader handle in qsv hwdevice
to create mfx session. Otherwise create mfx session with a new mfxLoader
handle.

This is in preparation for oneVPL support
---
 libavcodec/qsv.c  | 226 +++---
 libavcodec/qsv_internal.h |   1 +
 libavcodec/qsvdec.c   |  11 ++
 libavcodec/qsvenc.h   |   3 +
 libavcodec/qsvenc_h264.c  |   1 -
 libavcodec/qsvenc_hevc.c  |   1 -
 libavcodec/qsvenc_jpeg.c  |   1 -
 libavcodec/qsvenc_mpeg2.c |   1 -
 libavcodec/qsvenc_vp9.c   |   1 -
 9 files changed, 223 insertions(+), 23 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 432675bccf..fe998c9649 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -45,6 +45,12 @@
 #include 
 #endif
 
+#if QSV_ONEVPL
+#include 
+#else
+#define MFXUnload(a) do { } while(0)
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -419,6 +425,193 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+static int qsv_new_mfx_loader(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  void **ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+
+loader = MFXLoad();
+if (!loader) {
+av_log(avctx, AV_LOG_ERROR, "Error creating a MFX loader\n");
+goto fail;
+}
+
+/* Create configurations for implementation */
+cfg = MFXCreateConfig(loader);
+if (!cfg) {
+av_log(avctx, AV_LOG_ERROR, "Error creating a MFX configurations\n");
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U32;
+impl_value.Data.U32 = (implementation == MFX_IMPL_SOFTWARE) ?
+MFX_IMPL_TYPE_SOFTWARE : MFX_IMPL_TYPE_HARDWARE;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 *)"mfxImplDescription.Impl", 
impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
+   "property: %d\n", sts);
+goto fail;
+}
+
+impl_value.Type = MFX_VARIANT_TYPE_U32;
+impl_value.Data.U32 = pver->Version;
+sts = MFXSetConfigFilterProperty(cfg,
+ (const mfxU8 
*)"mfxImplDescription.ApiVersion.Version",
+ impl_value);
+if (sts != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error adding a MFX configuration "
+   "property: %d\n", sts);
+goto fail;
+}
+
+*ploader = loader;
+
+return 0;
+
+fail:
+if (loader)
+MFXUnload(loader);
+
+*ploader = NULL;
+return AVERROR_UNKNOWN;
+}
+
+static int qsv_create_mfx_session_from_loader(void *ctx, mfxLoader loader, 
mfxSession *psession)
+{
+mfxStatus sts;
+mfxSession session = NULL;
+uint32_t impl_idx = 0;
+
+while (1) {
+/* Enumerate all implementations */
+mfxImplDescription *impl_desc;
+
+sts = MFXEnumImplementations(loader, impl_idx,
+ MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
+ (mfxHDL *)_desc);
+/* Failed to find an available implementation */
+if (sts == MFX_ERR_NOT_FOUND)
+break;
+else if (sts != MFX_ERR_NONE) {
+impl_idx++;
+continue;
+}
+
+sts = MFXCreateSession(loader, impl_idx, );
+MFXDispReleaseImplDescription(loader, impl_desc);
+if (sts == MFX_ERR_NONE)
+break;
+
+impl_idx++;
+}
+
+if (sts != MFX_ERR_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", sts);
+goto fail;
+}
+
+*psession = session;
+
+return 0;
+
+fail:
+if (session)
+MFXClose(session);
+
+*psession = NULL;
+return AVERROR_UNKNOWN;
+}
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  void **ploader)
+{
+mfxLoader loader = NULL;
+
+/* Don't create a new MFX loader if the input loader is valid */
+if (*ploader == NULL) {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session, the required "
+   "implementation version is %d.%d\n",
+   pver->Major, pver->Minor);
+
+if (qsv_new_mfx_loader(avctx, implementation, pver, (void **)))
+goto fail;
+
+av_assert0(loader);
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX