[FFmpeg-devel] [PATCH 3/3] lavc/qsvenc_hevc: accept HDR metadata if have

2022-10-17 Thread haihao . xiang-at-intel . com
From: Haihao Xiang 

The SDK may accept HDR metadata via mfxEncodeCtrl::ExtParam

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvenc_hevc.c | 80 
 1 file changed, 80 insertions(+)

diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 2a3f34b915..28d2cfcae1 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -26,6 +26,7 @@
 
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
+#include "libavutil/mastering_display_metadata.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -160,6 +161,83 @@ static int generate_fake_vps(QSVEncContext *q, 
AVCodecContext *avctx)
 return 0;
 }
 
+static int qsv_hevc_set_encode_ctrl(AVCodecContext *avctx,
+const AVFrame *frame, mfxEncodeCtrl 
*enc_ctrl)
+{
+QSVHEVCEncContext *q = avctx->priv_data;
+AVFrameSideData *sd;
+
+if (!frame || !QSV_RUNTIME_VERSION_ATLEAST(q->qsv.ver, 1, 25))
+return 0;
+
+sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd) {
+AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata 
*)sd->data;
+
+// SEI is needed when both the primaries and luminance are set
+if (mdm->has_primaries && mdm->has_luminance) {
+const int mapping[3] = {1, 2, 0};
+const int chroma_den = 5;
+const int luma_den   = 1;
+int i;
+mfxExtMasteringDisplayColourVolume *mdcv = 
av_mallocz(sizeof(mfxExtMasteringDisplayColourVolume));
+
+if (!mdcv)
+return AVERROR(ENOMEM);
+
+mdcv->Header.BufferId = 
MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
+mdcv->Header.BufferSz = sizeof(*mdcv);
+
+for (i = 0; i < 3; i++) {
+const int j = mapping[i];
+
+mdcv->DisplayPrimariesX[i] =
+FFMIN(lrint(chroma_den *
+av_q2d(mdm->display_primaries[j][0])),
+  chroma_den);
+mdcv->DisplayPrimariesY[i] =
+FFMIN(lrint(chroma_den *
+av_q2d(mdm->display_primaries[j][1])),
+  chroma_den);
+}
+
+mdcv->WhitePointX =
+FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
+  chroma_den);
+mdcv->WhitePointY =
+FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
+  chroma_den);
+
+mdcv->MaxDisplayMasteringLuminance =
+lrint(luma_den * av_q2d(mdm->max_luminance));
+mdcv->MinDisplayMasteringLuminance =
+FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
+  mdcv->MaxDisplayMasteringLuminance);
+
+enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)mdcv;
+}
+}
+
+sd = av_frame_get_side_data(frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd) {
+AVContentLightMetadata *clm = (AVContentLightMetadata *)sd->data;
+mfxExtContentLightLevelInfo * clli = 
av_mallocz(sizeof(mfxExtContentLightLevelInfo));
+
+if (!clli)
+return AVERROR(ENOMEM);
+
+clli->Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
+clli->Header.BufferSz = sizeof(*clli);
+
+clli->MaxContentLightLevel  = FFMIN(clm->MaxCLL,  65535);
+clli->MaxPicAverageLightLevel   = FFMIN(clm->MaxFALL, 65535);
+
+enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)clli;
+}
+
+return 0;
+}
+
 static av_cold int qsv_enc_init(AVCodecContext *avctx)
 {
 QSVHEVCEncContext *q = avctx->priv_data;
@@ -189,6 +267,8 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx)
 // HEVC and H264 meaning of the value is shifted by 1, make it consistent
 q->qsv.idr_interval++;
 
+q->qsv.set_encode_ctrl_cb = qsv_hevc_set_encode_ctrl;
+
 ret = ff_qsv_enc_init(avctx, >qsv);
 if (ret < 0)
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/3] lavc/qsvenc: enlarge the maximum number of ExtParam buffers on mfxEncodeCtrl

2022-10-17 Thread haihao . xiang-at-intel . com
From: Haihao Xiang 

The next commit and other commits in future will use more ExtParam
buffers.

And combine 2 free functions into single one

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsv_internal.h |  2 +-
 libavcodec/qsvenc.c   | 27 ---
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 768f707ffa..5119ef4dff 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -51,7 +51,7 @@
 #define ASYNC_DEPTH_DEFAULT 4   // internal parallelism
 
 #define QSV_MAX_ENC_PAYLOAD 2   // # of mfxEncodeCtrl payloads supported
-#define QSV_MAX_ENC_EXTPARAM 2
+#define QSV_MAX_ENC_EXTPARAM 8  // # of mfxEncodeCtrl extparam supported
 
 #define QSV_MAX_ROI_NUM 256
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 19fe6e59a2..690a076016 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1434,25 +1434,16 @@ int ff_qsv_enc_init(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
-static void free_encoder_ctrl_payloads(mfxEncodeCtrl* enc_ctrl)
+static void free_encoder_ctrl(mfxEncodeCtrl* enc_ctrl)
 {
 if (enc_ctrl) {
-int i;
-for (i = 0; i < enc_ctrl->NumPayload && i < QSV_MAX_ENC_PAYLOAD; i++) {
+for (int i = 0; i < enc_ctrl->NumPayload && i < QSV_MAX_ENC_PAYLOAD; 
i++)
 av_freep(_ctrl->Payload[i]);
-}
-enc_ctrl->NumPayload = 0;
-}
-}
 
-static void free_encoder_ctrl_extparam(mfxEncodeCtrl* enc_ctrl)
-{
-if (enc_ctrl) {
-int i;
-for (i = 0; i < enc_ctrl->NumExtParam && i < QSV_MAX_ENC_EXTPARAM; 
i++) {
-if (enc_ctrl->ExtParam[i])
-av_freep(&(enc_ctrl->ExtParam[i]));
-}
+for (int i = 0; i < enc_ctrl->NumExtParam && i < QSV_MAX_ENC_EXTPARAM; 
i++)
+av_freep(_ctrl->ExtParam[i]);
+
+enc_ctrl->NumPayload = 0;
 enc_ctrl->NumExtParam = 0;
 }
 }
@@ -1462,8 +1453,7 @@ static void clear_unused_frames(QSVEncContext *q)
 QSVFrame *cur = q->work_frames;
 while (cur) {
 if (cur->used && !cur->surface.Data.Locked) {
-free_encoder_ctrl_payloads(>enc_ctrl);
-free_encoder_ctrl_extparam(>enc_ctrl);
+free_encoder_ctrl(>enc_ctrl);
 //do not reuse enc_ctrl from previous frame
 memset(>enc_ctrl, 0, sizeof(cur->enc_ctrl));
 cur->enc_ctrl.Payload = cur->payloads;
@@ -2231,8 +2221,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext 
*q)
 while (cur) {
 q->work_frames = cur->next;
 av_frame_free(>frame);
-free_encoder_ctrl_extparam(>enc_ctrl);
-free_encoder_ctrl_payloads(>enc_ctrl);
+free_encoder_ctrl(>enc_ctrl);
 av_freep();
 cur = q->work_frames;
 }
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/3] lavc/qsvenc: fix check to avoid segfault

2022-10-17 Thread haihao . xiang-at-intel . com
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 15e6936a65..19fe6e59a2 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -2093,8 +2093,8 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 pkt.bs->ExtParam = enc_buf;
 }
 
-if (q->set_encode_ctrl_cb) {
-q->set_encode_ctrl_cb(avctx, frame, _frame->enc_ctrl);
+if (q->set_encode_ctrl_cb && enc_ctrl) {
+q->set_encode_ctrl_cb(avctx, frame, enc_ctrl);
 }
 
 if ((avctx->codec_id == AV_CODEC_ID_H264 ||
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] qsv: check for libmfx.pc instead of mfx.pc

2022-05-25 Thread Haihao Xiang
This fixed the regression caused by commit 478e1a98a

Reported-by: Timo Rothenpieler 
Signed-off-by: Haihao Xiang 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 6cf7d89674..5a167613a4 100755
--- a/configure
+++ b/configure
@@ -6565,7 +6565,7 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx "mfx >= 1.28" 
"mfx/mfxvideo.h" MFXInit ||
+enabled libmfx&& { check_pkg_config libmfx "libmfx >= 1.28" 
"mfx/mfxvideo.h" MFXInit ||
{ require libmfx "mfx/mfxvideo.h mfx/mfxdefs.h" 
MFXInit "-llibmfx $advapi32_extralibs" &&
  { test_cpp_condition mfx/mfxdefs.h 
"MFX_VERSION >= 1028" || die "ERROR: libmfx version must be >= 1.28"; }  &&
  warn "using libmfx without pkg-config"; } }
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] qsv: add requirement for the mininal version of libmfx

2022-05-22 Thread Haihao Xiang
libmfx 1.28 was released 3 years ago, it is easy to get a greater
version than 1.28. We may remove lots of compile-time checks if adding
the requirement for the minimal version in the configure script.
---
 configure  |   7 +-
 libavcodec/qsv.c   |  24 --
 libavcodec/qsvenc.c| 471 +
 libavcodec/qsvenc.h|  51 +---
 libavcodec/qsvenc_h264.c   |   6 -
 libavcodec/qsvenc_hevc.c   |  10 -
 libavfilter/vf_scale_qsv.c |  13 +-
 libavfilter/vf_vpp_qsv.c   | 143 ++-
 libavutil/hwcontext_qsv.c  |   2 -
 9 files changed, 249 insertions(+), 478 deletions(-)

diff --git a/configure b/configure
index f115b21064..2337f0a8f2 100755
--- a/configure
+++ b/configure
@@ -6566,8 +6566,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { check_pkg_config libmfx "mfx >= 1.28" 
"mfx/mfxvideo.h" MFXInit ||
+   { require libmfx "mfx/mfxvideo.h mfx/mfxdefs.h" 
MFXInit "-llibmfx $advapi32_extralibs" &&
+ { test_cpp_condition mfx/mfxdefs.h 
"MFX_VERSION >= 1028" || die "ERROR: libmfx version must be >= 1.28"; }  &&
+ warn "using libmfx without pkg-config"; } }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b86c20b153..385b43bb6c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -38,34 +38,26 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
-#if QSV_VERSION_ATLEAST(1, 12)
 #include "mfx/mfxvp8.h"
-#endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
 case AV_CODEC_ID_H264:
 return MFX_CODEC_AVC;
-#if QSV_VERSION_ATLEAST(1, 8)
 case AV_CODEC_ID_HEVC:
 return MFX_CODEC_HEVC;
-#endif
 case AV_CODEC_ID_MPEG1VIDEO:
 case AV_CODEC_ID_MPEG2VIDEO:
 return MFX_CODEC_MPEG2;
 case AV_CODEC_ID_VC1:
 return MFX_CODEC_VC1;
-#if QSV_VERSION_ATLEAST(1, 12)
 case AV_CODEC_ID_VP8:
 return MFX_CODEC_VP8;
-#endif
 case AV_CODEC_ID_MJPEG:
 return MFX_CODEC_JPEG;
-#if QSV_VERSION_ATLEAST(1, 19)
 case AV_CODEC_ID_VP9:
 return MFX_CODEC_VP9;
-#endif
 #if QSV_VERSION_ATLEAST(1, 34)
 case AV_CODEC_ID_AV1:
 return MFX_CODEC_AV1;
@@ -189,17 +181,11 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
 case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
 case MFX_FOURCC_P010: return AV_PIX_FMT_P010;
 case MFX_FOURCC_P8:   return AV_PIX_FMT_PAL8;
-#if QSV_VERSION_ATLEAST(1, 9)
 case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10;
-#endif
-#if QSV_VERSION_ATLEAST(1, 17)
 case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA;
-#endif
 #if CONFIG_VAAPI
 case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422;
-#if QSV_VERSION_ATLEAST(1, 27)
 case MFX_FOURCC_Y210: return AV_PIX_FMT_Y210;
-#endif
 #endif
 }
 return AV_PIX_FMT_NONE;
@@ -217,27 +203,21 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t 
*fourcc)
 case AV_PIX_FMT_P010:
 *fourcc = MFX_FOURCC_P010;
 return AV_PIX_FMT_P010;
-#if QSV_VERSION_ATLEAST(1, 9)
 case AV_PIX_FMT_X2RGB10:
 *fourcc = MFX_FOURCC_A2RGB10;
 return AV_PIX_FMT_X2RGB10;
-#endif
-#if QSV_VERSION_ATLEAST(1, 17)
 case AV_PIX_FMT_BGRA:
 *fourcc = MFX_FOURCC_RGB4;
 return AV_PIX_FMT_BGRA;
-#endif
 #if CONFIG_VAAPI
 case AV_PIX_FMT_YUV422P:
 case AV_PIX_FMT_YUYV422:
 *fourcc = MFX_FOURCC_YUY2;
 return AV_PIX_FMT_YUYV422;
-#if QSV_VERSION_ATLEAST(1, 27)
 case AV_PIX_FMT_YUV422P10:
 case AV_PIX_FMT_Y210:
 *fourcc = MFX_FOURCC_Y210;
 return AV_PIX_FMT_Y210;
-#endif
 #endif
 default:
 return AVERROR(ENOSYS);
@@ -438,9 +418,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 const char *desc;
 int ret;
 
-#if QSV_VERSION_ATLEAST(1, 16)
 init_par.GPUCopy= gpu_copy;
-#endif
 init_par.Implementation = impl;
 init_par.Version= ver;
 ret = MFXInitEx(init_par, >session);
@@ -791,9 +769,7 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
"from the session\n");
 }
 
-#if QSV_VERSION_ATLEAST(1, 16)
 init_par.GPUCopy= gpu_copy;
-#endif
 init_par.Implementation = impl;
 init_par.Version= ver;
 err = MFXInitEx(init_par, );
diff --git 

[FFmpeg-devel] [PATCH v08 10/10] configure: add --enable-libvpl option

2022-04-28 Thread Haihao Xiang
This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.6
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

Note the preferred child device type is d3d11va for libvpl on Windows.
The commands below will use d3d11va if d3d11va is available on Windows.
$ ffmpeg -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -qsv_device 0 -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any -hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0 -hwaccel qsv -c:v 
h264_qsv ...

User may use child_device_type option to specify child device type to
dxva2 or derive a qsv device from a dxva2 device
$ ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0,child_device_type=dxva2 
-hwaccel qsv -c:v h264_qsv ...
$ ffmpeg -init_hw_device dxva2=d3d9:0 -init_hw_device qsv=qsv@d3d9 -hwaccel qsv 
-c:v h264_qsv ...

[1] 
https://www.intel.com/content/www/us/en/develop/documentation/upgrading-from-msdk-to-onevpl/top.html
---
 configure | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index e163c743e1..cea185fc9b 100755
--- a/configure
+++ b/configure
@@ -341,6 +341,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1921,6 +1922,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6559,22 +6561,35 @@ enabled libjxl&& require_pkg_config libjxl 
"libjxl >= 0.7.0" jxl/dec
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I${libmfx_incdir}/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still passed to 
check_pkg_config function for --enable-libvpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check. The package name
+# is extracted from "vpl >= 2.6"
+check_pkg_config libmfx "vpl >= 2.6" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.6+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+

[FFmpeg-devel] [PATCH v08 09/10] qsv: use a new method to create mfx session when using oneVPL

2022-04-28 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add config filters for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Co-authored-by: galinart 
Signed-off-by: galinart 
---
 libavcodec/qsv.c | 197 ++--
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |  10 +
 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 -
 libavfilter/qsvvpp.c | 113 ++-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_d3d11va.c|   7 +
 libavutil/hwcontext_qsv.c| 515 ---
 libavutil/hwcontext_qsv.h|   1 +
 libavutil/hwcontext_vaapi.c  |  13 +
 libavutil/hwcontext_vaapi.h  |   4 +
 18 files changed, 812 insertions(+), 88 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index ad9f4df3f2..2892699728 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -47,6 +47,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) {
@@ -439,6 +445,164 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  void **ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = 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);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX loader\n");
+
+loader = *ploader;
+}
+
+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 

[FFmpeg-devel] [PATCH v08 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2022-04-28 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2ba4b8e90c..fa8960a0ad 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -153,7 +153,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2022-04-28 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 57 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 4e35003ad5..ad9f4df3f2 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,10 +89,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 4c1ccc7342..5c26914b4c 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -63,6 +63,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index b75559f083..cd0a0f9cc1 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -187,7 +187,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -300,10 +304,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index fa8960a0ad..decb49b4f5 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1275,6 +1275,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1311,6 +1312,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1326,7 +1328,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+ 

[FFmpeg-devel] [PATCH v08 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2022-04-28 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 58d1ab346c..8aa1e251b3 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -67,7 +67,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2022-04-28 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index f66b388625..4e35003ad5 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -137,8 +138,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -148,7 +151,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 954f882637..3647891d13 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 typedef struct QSVAsyncFrame {
@@ -100,8 +102,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -111,7 +115,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 543c58a967..802abd987d 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2022-04-28 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 95e721566a..f66b388625 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,11 +36,16 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -343,6 +347,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -386,6 +391,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 49d5797fbc..4c1ccc7342 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -62,6 +62,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 03/10] qsv: remove mfx/ prefix from mfx headers

2022-04-28 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 939c6e86f9..e163c743e1 100755
--- a/configure
+++ b/configure
@@ -6565,13 +6565,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b86c20b153..95e721566a 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -39,7 +39,7 @@
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index e2aecdcbd6..49d5797fbc 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 5fc5bed4c8..b75559f083 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index fbb22ca436..2ba4b8e90c 100644
--- 

[FFmpeg-devel] [PATCH v08 02/10] configure: fix the check for MFX_CODEC_VP9

2022-04-28 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 81e7d43d22..939c6e86f9 100755
--- a/configure
+++ b/configure
@@ -6571,7 +6571,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2022-04-28 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 196873c4aa..81e7d43d22 100755
--- a/configure
+++ b/configure
@@ -6565,8 +6565,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v08 00/10] make QSV works with the Intel's oneVPL

2022-04-28 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1][2]. oneVPL is a successor to Intel(R) 
Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[3].

It is recommended to use oneVPL for new work, even for currently available
hardwares[4]. Hence, this patchset added a new option --enable-onevpl to bring
the support for oneVPL in QSV, new features for oneVPL will be implemented in
other patchset, for example, we are implementing av1_qsv encoder
(https://github.com/intel-media-ci/ffmpeg/pull/515).

option --enble-libmfx still works with Intel(R) Media SDK.

Note user can't enable onevpl and libmfx together.

oneVPL dispatcher:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v8:
  - Fix mfx session creation for D3D11VA and DXVA2
  - Rebased this patchset against the latest master

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://www.intel.com/content/www/us/en/developer/tools/oneapi/onevpl.html
[3] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix
[4] 
https://www.intel.com/content/www/us/en/develop/documentation/upgrading-from-msdk-to-onevpl/top.html

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using oneVPL
  configure: add --enable-libvpl option

 configure|  29 +-
 libavcodec/qsv.c | 220 ++--
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  21 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 145 +++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  73 ++--
 libavfilter/vf_scale_qsv.c   |  88 ++---
 libavutil/hwcontext_d3d11va.c|   7 +
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 573 ---
 libavutil/hwcontext_qsv.h|   3 +-
 libavutil/hwcontext_vaapi.c  |  13 +
 libavutil/hwcontext_vaapi.h  |   4 +
 22 files changed, 1062 insertions(+), 187 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] qsvenc: fix typo

2022-04-07 Thread Haihao Xiang
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2514d5b256..fbb22ca436 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1003,7 +1003,7 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extco3.LowDelayBRC = q->low_delay_brc ? MFX_CODINGOPTION_ON 
: MFX_CODINGOPTION_OFF;
 #endif
 #if QSV_VERSION_ATLEAST(1, 19)
-if (q->max_frame_size_p >= 0)
+if (q->max_frame_size_i >= 0)
 q->extco3.MaxFrameSizeI = q->max_frame_size_i;
 if (q->max_frame_size_p >= 0)
 q->extco3.MaxFrameSizeP = q->max_frame_size_p;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/qsvenc: add tile encoding support for VP9

2022-01-12 Thread Haihao Xiang
Add -tile_rows and -tile_cols options to specify the number of tile
rows and columns

Signed-off-by: Haihao Xiang 
---
v2: add option descriptions in the doc

 doc/encoders.texi   |  6 ++
 libavcodec/qsvenc.c |  4 
 libavcodec/qsvenc.h |  1 +
 libavcodec/qsvenc_vp9.c | 10 ++
 4 files changed, 21 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..a4176089d5 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3457,6 +3457,12 @@ These options are used by vp9_qsv
 @item profile2
 @item profile3
 @end table
+
+@item @var{tile_cols}
+Number of columns for tiled encoding (requires libmfx >= 1.29).
+
+@item @var{tile_rows}
+Number of rows for tiled encoding (requires libmfx  >= 1.29).
 @end table
 
 @section snow
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4e7a15f060..4cbc9ff4dc 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -939,6 +939,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
 q->extvp9param.Header.BufferSz = sizeof(q->extvp9param);
 q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
+#if QSV_HAVE_EXT_VP9_TILES
+q->extvp9param.NumTileColumns  = q->tile_cols;
+q->extvp9param.NumTileRows = q->tile_rows;
+#endif
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extvp9param;
 }
 #endif
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 31516b8e55..00ee52a5d1 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -41,6 +41,7 @@
 
 #define QSV_HAVE_EXT_HEVC_TILES QSV_VERSION_ATLEAST(1, 13)
 #define QSV_HAVE_EXT_VP9_PARAM QSV_VERSION_ATLEAST(1, 26)
+#define QSV_HAVE_EXT_VP9_TILES QSV_VERSION_ATLEAST(1, 29)
 
 #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c
index 9329990d11..1168ddda0e 100644
--- a/libavcodec/qsvenc_vp9.c
+++ b/libavcodec/qsvenc_vp9.c
@@ -73,6 +73,16 @@ static const AVOption options[] = {
 { "profile2",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_2   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 { "profile3",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_3   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 
+#if QSV_HAVE_EXT_VP9_TILES
+/* The minimum tile width in luma pixels is 256, set maximum tile_cols to 
32 for 8K video */
+{ "tile_cols",  "Number of columns for tiled encoding",   
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 32, VE },
+/* Set maximum tile_rows to 4 per VP9 spec */
+{ "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE },
+#else
+{ "tile_cols",  "(not supported)",
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+{ "tile_rows",  "(not supported)",
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+#endif
+
 { NULL },
 };
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/qsvenc: add encode support for screen content coding extension

2022-01-12 Thread Haihao Xiang
Enables HEVC Screen Content Coding extension support on ICL+ platform

Signed-off-by: Haihao Xiang 
---
v2: rebased it against the latest master and added scc to the doc

 doc/encoders.texi| 3 +++
 libavcodec/qsvenc.c  | 3 +++
 libavcodec/qsvenc_hevc.c | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..78518629cd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3411,12 +3411,15 @@ an internal session.
 Depth of look ahead in number frames, available when extbrc option is enabled.
 
 @item @var{profile}
+Set the encoding profile (scc requires libmfx >= 1.32).
+
 @table @samp
 @item unknown
 @item main
 @item main10
 @item mainsp
 @item rext
+@item scc
 @end table
 
 @item @var{gpb}
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4e7a15f060..269386624d 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -74,6 +74,9 @@ static const struct profile_names hevc_profiles[] = {
 { MFX_PROFILE_HEVC_MAINSP,  "hevc mainsp"},
 { MFX_PROFILE_HEVC_REXT,"hevc rext"  },
 #endif
+#if QSV_VERSION_ATLEAST(1, 32)
+{ MFX_PROFILE_HEVC_SCC, "hevc scc"   },
+#endif
 };
 
 static const struct profile_names vp9_profiles[] = {
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 08aba3011d..07010c698e 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -244,6 +244,9 @@ static const AVOption options[] = {
 { "main10",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAIN10  
}, INT_MIN, INT_MAX, VE, "profile" },
 { "mainsp",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_MAINSP  
}, INT_MIN, INT_MAX, VE, "profile" },
 { "rext",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_REXT
}, INT_MIN, INT_MAX, VE, "profile" },
+#if QSV_VERSION_ATLEAST(1, 32)
+{ "scc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_HEVC_SCC 
}, INT_MIN, INT_MAX, VE, "profile" },
+#endif
 
 { "gpb", "1: GPB (generalized P/B frame); 0: regular P frame", 
OFFSET(qsv.gpb), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE},
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/qsvenc_hevc: add -pic_timing_sei option

2022-01-11 Thread Haihao Xiang
The SDK may insert picture timing SEI for hevc and the code to set mfx
parameter has been added in qsvenc, however the corresponding option is
missing in the hevc option array

Reviewed-by: Limin Wang 
Signed-off-by: Haihao Xiang 
---
v2: added option description in the doc

 doc/encoders.texi| 3 +++
 libavcodec/qsvenc_hevc.c | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7cc8be1209..1679f389d7 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3432,6 +3432,9 @@ Number of rows for tiled encoding.
 
 @item @var{aud}
 Insert the Access Unit Delimiter NAL.
+
+@item @var{pic_timing_sei}
+Insert picture timing SEI with pic_struct_syntax element.
 @end table
 
 @subsection MPEG2 Options
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 08aba3011d..342b6bdea7 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -251,6 +251,7 @@ static const AVOption options[] = {
 { "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
 { "recovery_point_sei", "Insert recovery point SEI messages",   
OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64 = -1 },
   -1,  1, VE },
 { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
+{ "pic_timing_sei","Insert picture timing SEI with pic_struct_syntax 
element", OFFSET(qsv.pic_timing_sei), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE 
},
 
 { NULL },
 };
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] MAINTAINERS: add my gpg fingerprint

2021-12-22 Thread Haihao Xiang
Signed-off-by: Haihao Xiang 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 50ee5efecc..c065e94498 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -611,6 +611,7 @@ Daniel Verkamp78A6 07ED 782C 653E C628 B8B9 
F0EB 8DD8 2F0E 21C7
 FFmpeg release signing keyFCF9 86EA 15E6 E293 A564 4F10 B432 2F04 D676 58D8
 Ganesh AjjanagaddeC96A 848E 97C3 CEA2 AB72 5CE4 45F9 6A2D 3C36 FB1B
 Gwenole Beauchesne2E63 B3A6 3E44 37E2 017D 2704 53C7 6266 B153 99C4
+Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 DC99 E0F5 76D4 76FC 437F
 Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368
 James Almer   7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 59E0
 Jean Delvare  7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 4E6A
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/qsvenc: add tile encoding support for VP9

2021-12-13 Thread Haihao Xiang
Add -tile_rows and -tile_cols options to specify the number of tile
rows and columns
---
 libavcodec/qsvenc.c |  4 
 libavcodec/qsvenc_vp9.c | 10 ++
 2 files changed, 14 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 26a94cd419..270bdad544 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -793,6 +793,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
 q->extvp9param.Header.BufferSz = sizeof(q->extvp9param);
 q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
+#if (MFX_VERSION >= 1029)
+q->extvp9param.NumTileColumns  = q->tile_cols;
+q->extvp9param.NumTileRows = q->tile_rows;
+#endif
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extvp9param;
 }
 #endif
diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c
index 9329990d11..0013932f0d 100644
--- a/libavcodec/qsvenc_vp9.c
+++ b/libavcodec/qsvenc_vp9.c
@@ -73,6 +73,16 @@ static const AVOption options[] = {
 { "profile2",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_2   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 { "profile3",  NULL, 0,   AV_OPT_TYPE_CONST, { .i64 = 
MFX_PROFILE_VP9_3   },  INT_MIN,  INT_MAX,  VE,  "profile" },
 
+#if (MFX_VERSION >= 1029)
+/* The minimum tile width in luma pixels is 256, set maximum tile_cols to 
32 for 8K video */
+{ "tile_cols",  "Number of columns for tiled encoding",   
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 32, VE },
+/* Set maximum tile_rows to 4 per VP9 spec */
+{ "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE },
+#else
+{ "tile_cols",  "(not supported)",
OFFSET(qsv.tile_cols),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+{ "tile_rows",  "(not supported)",
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0, VE },
+#endif
+
 { NULL },
 };
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/5] lavc/qsvenc: dump parameters for mjpeg encoding in verbose mode

2021-12-12 Thread Haihao Xiang
---
 libavcodec/qsvenc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 106438f227..92a8b49fe3 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -421,6 +421,18 @@ static void dump_video_vp9_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #endif
 }
 
+static void dump_video_mjpeg_param(AVCodecContext *avctx, QSVEncContext *q)
+{
+mfxInfoMFX *info = >param.mfx;
+
+av_log(avctx, AV_LOG_VERBOSE, "Interleaved: %"PRIu16" \n", 
info->Interleaved);
+av_log(avctx, AV_LOG_VERBOSE, "Quality: %"PRIu16" \n", info->Quality);
+av_log(avctx, AV_LOG_VERBOSE, "RestartInterval: %"PRIu16" \n", 
info->RestartInterval);
+
+av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: 
%"PRIu32" \n",
+   info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
+}
+
 static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
 {
 const char *rc_desc;
@@ -970,6 +982,8 @@ static int qsv_retrieve_enc_jpeg_params(AVCodecContext 
*avctx, QSVEncContext *q)
 if (q->packet_size == 0)
 q->packet_size = q->param.mfx.FrameInfo.Height * 
q->param.mfx.FrameInfo.Width * 4;
 
+dump_video_mjpeg_param(avctx, q);
+
 return 0;
 }
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/5] lavc/qsvenc: dump parameters for VP9 encoding in verbose mode

2021-12-12 Thread Haihao Xiang
---
 libavcodec/qsvenc.c | 80 +
 1 file changed, 80 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a2a8a79189..106438f227 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -343,6 +343,84 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 
 }
 
+static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q,
+ mfxExtBuffer **coding_opts)
+{
+mfxInfoMFX *info = >param.mfx;
+#if QSV_HAVE_EXT_VP9_PARAM
+mfxExtVP9Param *vp9_param = (mfxExtVP9Param *)coding_opts[0];
+#endif
+#if QSV_HAVE_CO2
+mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
+#endif
+
+av_log(avctx, AV_LOG_VERBOSE, "profile: %s \n",
+   print_profile(avctx->codec_id, info->CodecProfile));
+
+av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: 
%"PRIu16"; GopOptFlag: ",
+   info->GopPicSize, info->GopRefDist);
+if (info->GopOptFlag & MFX_GOP_CLOSED)
+av_log(avctx, AV_LOG_VERBOSE, "closed ");
+if (info->GopOptFlag & MFX_GOP_STRICT)
+av_log(avctx, AV_LOG_VERBOSE, "strict ");
+av_log(avctx, AV_LOG_VERBOSE, "; IdrInterval: %"PRIu16"\n", 
info->IdrInterval);
+
+av_log(avctx, AV_LOG_VERBOSE, "TargetUsage: %"PRIu16"; RateControlMethod: 
%s\n",
+   info->TargetUsage, print_ratecontrol(info->RateControlMethod));
+
+if (info->RateControlMethod == MFX_RATECONTROL_CBR ||
+info->RateControlMethod == MFX_RATECONTROL_VBR) {
+av_log(avctx, AV_LOG_VERBOSE,
+   "BufferSizeInKB: %"PRIu16"; InitialDelayInKB: %"PRIu16"; 
TargetKbps: %"PRIu16"; MaxKbps: %"PRIu16"; BRCParamMultiplier: %"PRIu16"\n",
+   info->BufferSizeInKB, info->InitialDelayInKB, info->TargetKbps, 
info->MaxKbps, info->BRCParamMultiplier);
+} else if (info->RateControlMethod == MFX_RATECONTROL_CQP) {
+av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16"; QPB: 
%"PRIu16"\n",
+   info->QPI, info->QPP, info->QPB);
+}
+#if QSV_HAVE_ICQ
+else if (info->RateControlMethod == MFX_RATECONTROL_ICQ) {
+av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"\n", 
info->ICQQuality);
+}
+#endif
+else {
+av_log(avctx, AV_LOG_VERBOSE, "Unsupported ratecontrol method: %d \n", 
info->RateControlMethod);
+}
+
+av_log(avctx, AV_LOG_VERBOSE, "NumRefFrame: %"PRIu16"\n", 
info->NumRefFrame);
+
+#if QSV_HAVE_CO2
+av_log(avctx, AV_LOG_VERBOSE,
+   "IntRefType: %"PRIu16"; IntRefCycleSize: %"PRIu16"; IntRefQPDelta: 
%"PRId16"\n",
+   co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
+
+av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d; ", co2->MaxFrameSize);
+av_log(avctx, AV_LOG_VERBOSE, "\n");
+
+av_log(avctx, AV_LOG_VERBOSE,
+   "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
+   print_threestate(co2->BitrateLimit), print_threestate(co2->MBBRC),
+   print_threestate(co2->ExtBRC));
+
+#if QSV_HAVE_VDENC
+av_log(avctx, AV_LOG_VERBOSE, "VDENC: %s\n", 
print_threestate(info->LowPower));
+#endif
+
+#if QSV_VERSION_ATLEAST(1, 9)
+av_log(avctx, AV_LOG_VERBOSE,
+   "MinQPI: %"PRIu8"; MaxQPI: %"PRIu8"; MinQPP: %"PRIu8"; MaxQPP: 
%"PRIu8"; MinQPB: %"PRIu8"; MaxQPB: %"PRIu8"\n",
+   co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, 
co2->MaxQPB);
+#endif
+#endif
+
+av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: 
%"PRIu32" \n",
+   info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
+
+#if QSV_HAVE_EXT_VP9_PARAM
+av_log(avctx, AV_LOG_VERBOSE, "WriteIVFHeaders: %s \n",
+   print_threestate(vp9_param->WriteIVFHeaders));
+#endif
+}
+
 static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
 {
 const char *rc_desc;
@@ -941,6 +1019,8 @@ static int qsv_retrieve_enc_vp9_params(AVCodecContext 
*avctx, QSVEncContext *q)
 
 q->packet_size = q->param.mfx.BufferSizeInKB * 
q->param.mfx.BRCParamMultiplier * 1000;
 
+dump_video_vp9_param(avctx, q, ext_buffers);
+
 return 0;
 }
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/5] lavc/qsvenc: add VP9 profiles

2021-12-12 Thread Haihao Xiang
---
 libavcodec/qsvenc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7dab8bab0f..a2a8a79189 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -76,6 +76,15 @@ static const struct profile_names hevc_profiles[] = {
 #endif
 };
 
+static const struct profile_names vp9_profiles[] = {
+#if QSV_VERSION_ATLEAST(1, 19)
+{ MFX_PROFILE_VP9_0,"0" },
+{ MFX_PROFILE_VP9_1,"1" },
+{ MFX_PROFILE_VP9_2,"2" },
+{ MFX_PROFILE_VP9_3,"3" },
+#endif
+};
+
 static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile)
 {
 const struct profile_names *profiles;
@@ -97,6 +106,11 @@ static const char *print_profile(enum AVCodecID codec_id, 
mfxU16 profile)
 num_profiles = FF_ARRAY_ELEMS(hevc_profiles);
 break;
 
+case AV_CODEC_ID_VP9:
+profiles = vp9_profiles;
+num_profiles = FF_ARRAY_ELEMS(vp9_profiles);
+break;
+
 default:
 return "unknown";
 }
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/5] lavc/qsvenc: define profile array per codec

2021-12-12 Thread Haihao Xiang
The SDK defines HEVC, VP9 and AV1 profiles in the same values
e.g.
MFX_PROFILE_HEVC_MAIN =1,
MFX_PROFILE_VP9_0 =1,
MFX_PROFILE_AV1_MAIN  =1,

To avoid potential errors when adding VP9, AV1 profiles later,
this patch defines profile array per codec.
---
 libavcodec/qsvenc.c | 47 +
 1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index dc0c45dc45..7dab8bab0f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -41,10 +41,12 @@
 #include "qsv_internal.h"
 #include "qsvenc.h"
 
-static const struct {
+struct profile_names {
 mfxU16 profile;
 const char *name;
-} profile_names[] = {
+};
+
+static const struct profile_names avc_profiles[] = {
 { MFX_PROFILE_AVC_BASELINE, "baseline"  },
 { MFX_PROFILE_AVC_MAIN, "main"  },
 { MFX_PROFILE_AVC_EXTENDED, "extended"  },
@@ -57,9 +59,15 @@ static const struct {
 { MFX_PROFILE_AVC_CONSTRAINED_HIGH, "constrained high"  },
 { MFX_PROFILE_AVC_PROGRESSIVE_HIGH, "progressive high"  },
 #endif
+};
+
+static const struct profile_names mpeg2_profiles[] = {
 { MFX_PROFILE_MPEG2_SIMPLE, "simple"},
 { MFX_PROFILE_MPEG2_MAIN,   "main"  },
 { MFX_PROFILE_MPEG2_HIGH,   "high"  },
+};
+
+static const struct profile_names hevc_profiles[] = {
 #if QSV_VERSION_ATLEAST(1, 8)
 { MFX_PROFILE_HEVC_MAIN,"main"  },
 { MFX_PROFILE_HEVC_MAIN10,  "main10"},
@@ -68,12 +76,35 @@ static const struct {
 #endif
 };
 
-static const char *print_profile(mfxU16 profile)
+static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile)
 {
-int i;
-for (i = 0; i < FF_ARRAY_ELEMS(profile_names); i++)
-if (profile == profile_names[i].profile)
-return profile_names[i].name;
+const struct profile_names *profiles;
+int i, num_profiles;
+
+switch (codec_id) {
+case AV_CODEC_ID_H264:
+profiles = avc_profiles;
+num_profiles = FF_ARRAY_ELEMS(avc_profiles);
+break;
+
+case AV_CODEC_ID_MPEG2VIDEO:
+profiles = mpeg2_profiles;
+num_profiles = FF_ARRAY_ELEMS(mpeg2_profiles);
+break;
+
+case AV_CODEC_ID_HEVC:
+profiles = hevc_profiles;
+num_profiles = FF_ARRAY_ELEMS(hevc_profiles);
+break;
+
+default:
+return "unknown";
+}
+
+for (i = 0; i < num_profiles; i++)
+if (profile == profiles[i].profile)
+return profiles[i].name;
+
 return "unknown";
 }
 
@@ -143,7 +174,7 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #endif
 
 av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n",
-   print_profile(info->CodecProfile), info->CodecLevel);
+   print_profile(avctx->codec_id, info->CodecProfile), 
info->CodecLevel);
 
 av_log(avctx, AV_LOG_VERBOSE, "GopPicSize: %"PRIu16"; GopRefDist: 
%"PRIu16"; GopOptFlag: ",
info->GopPicSize, info->GopRefDist);
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/5] lavc/qsvenc: remove VC1 profiles

2021-12-12 Thread Haihao Xiang
The SDK doesn't support VC1 encoding. In addition, both
MFX_PROFILE_VC1_SIMPLE and MFX_PROFILE_HEVC_MAIN are 1 in the SDK, HEVC
main profile is recognized as simple profile in the verbose output if
don't remove VC1 profiles.

$ ffmpeg -v verbose -qsv_device /dev/dri/renderD129 -f lavfi -i
yuvtestsrc -c:v hevc_qsv -f null -

[hevc_qsv @ 0x55bdf7eb4eb0] profile: simple; level: 21
---
 libavcodec/qsvenc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 26a94cd419..dc0c45dc45 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -60,9 +60,6 @@ static const struct {
 { MFX_PROFILE_MPEG2_SIMPLE, "simple"},
 { MFX_PROFILE_MPEG2_MAIN,   "main"  },
 { MFX_PROFILE_MPEG2_HIGH,   "high"  },
-{ MFX_PROFILE_VC1_SIMPLE,   "simple"},
-{ MFX_PROFILE_VC1_MAIN, "main"  },
-{ MFX_PROFILE_VC1_ADVANCED, "advanced"  },
 #if QSV_VERSION_ATLEAST(1, 8)
 { MFX_PROFILE_HEVC_MAIN,"main"  },
 { MFX_PROFILE_HEVC_MAIN10,  "main10"},
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/qsvenc: set base address for V plane

2021-12-12 Thread Haihao Xiang
The SDK checks Data.V when using system memory for VP9 encoding. This
fixed the error below:

$ ffmpeg -qsv_device /dev/dri/renderD129 -f lavfi -i yuvtestsrc -c:v
vp9_qsv -f null -

[vp9_qsv @ 0x55b8387cbe90] Error during encoding: NULL pointer (-2)
Video encoding failed
---
 libavcodec/qsvenc.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 26a94cd419..7431ccfca5 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1389,8 +1389,23 @@ static int submit_frame(QSVEncContext *q, const AVFrame 
*frame,
 qf->surface.Data.PitchLow  = qf->frame->linesize[0];
 qf->surface.Data.Y = qf->frame->data[0];
 qf->surface.Data.UV= qf->frame->data[1];
-}
 
+/* The SDK checks Data.V when using system memory for VP9 encoding */
+switch (frame->format) {
+case AV_PIX_FMT_NV12:
+qf->surface.Data.V = qf->surface.Data.UV + 1;
+break;
+
+case AV_PIX_FMT_P010:
+qf->surface.Data.V = qf->surface.Data.UV + 2;
+break;
+
+default:
+/* should not reach here */
+av_assert0(0);
+break;
+}
+}
 qf->surface.Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, 
(AVRational){1, 9});
 
 *new_frame = qf;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2021-10-15 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7eaa680ae4..6c6494745f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -100,7 +100,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2021-10-15 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7a71ffe98f..93af4d1198 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -64,7 +64,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 10/10] configure: add --enable-libvpl option

2021-10-15 Thread Haihao Xiang
This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.2
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

Note the preferred child device type is d3d11va for libvpl on Windows.
The commands below will use d3d11va if d3d11va is available on Windows.
$> ffmpeg -hwaccel qsv -c:v h264_qsv ...
$> ffmpeg -qsv_device 0 -hwaccel qsv -c:v h264_qsv ...
$> ffmpeg -init_hw_device qsv=qsv:hw_any -hwaccel qsv -c:v h264_qsv ...
$> ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0 -hwaccel qsv -c:v 
h264_qsv ...

User may use child_device_type option to specify child device type to
dxva2 or derive a qsv device from a dxva2 device
$> ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=0,child_device_type=dxva2 
-hwaccel qsv -c:v h264_qsv ...
$> ffmpeg -init_hw_device dxva2=d3d9:0 -init_hw_device qsv=qsv@d3d9 -hwaccel 
qsv -c:v h264_qsv ...

[1] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html
---
 configure | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index cc5894dcac..88dc2bda91 100755
--- a/configure
+++ b/configure
@@ -337,6 +337,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1898,6 +1899,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6432,22 +6434,35 @@ enabled libilbc   && require libilbc ilbc.h 
WebRtcIlbcfix_InitDecode -li
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I${libmfx_incdir}/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still passed to 
check_pkg_config function for --enable-libvpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check. The package name
+# is extracted from "vpl >= 2.2"
+check_pkg_config libmfx "vpl >= 2.2" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.2+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+  

[FFmpeg-devel] [PATCH v6 09/10] qsv: use a new method to create mfx session when using oneVPL

2021-10-15 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add AccelerationMode config filter for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Signed-off-by: galinart 
---
 libavcodec/qsv.c | 197 +++--
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |  10 +
 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 -
 libavfilter/qsvvpp.c | 113 +-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_d3d11va.c|  13 ++
 libavutil/hwcontext_d3d11va.h|   5 +
 libavutil/hwcontext_dxva2.c  |   8 +
 libavutil/hwcontext_dxva2.h  |   4 +
 libavutil/hwcontext_qsv.c| 365 +++
 libavutil/hwcontext_qsv.h|   1 +
 libavutil/hwcontext_vaapi.c  |  13 ++
 libavutil/hwcontext_vaapi.h  |   4 +
 21 files changed, 684 insertions(+), 89 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index d6f77908e4..46d3ac95eb 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -47,6 +47,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) {
@@ -387,6 +393,164 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  void **ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = 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);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX loader\n");
+
+loader = *ploader;
+}
+
+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, );
+

[FFmpeg-devel] [PATCH v6 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2021-10-15 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 57 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e0a124a5cb..d6f77908e4 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,10 +89,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 659417ded8..ff50b41de8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -61,6 +61,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1cadb846f5..9395a1fd9a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -171,7 +171,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -282,10 +286,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 6c6494745f..546efd9668 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1029,6 +1029,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1065,6 +1066,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1080,7 +1082,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+

[FFmpeg-devel] [PATCH v6 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2021-10-15 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 83056e5976..e0a124a5cb 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -137,8 +138,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -148,7 +151,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..1113d27ba1 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 static const struct {
@@ -95,8 +97,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -106,7 +110,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 8c0cf3ed95..46e90c1d2c 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2021-10-15 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 84f0401b0f..83056e5976 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,11 +36,16 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -291,6 +295,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -334,6 +339,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 24c3e9307e..659417ded8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 03/10] qsv: remove mfx/ prefix from mfx headers

2021-10-15 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 0204d230c7..cc5894dcac 100755
--- a/configure
+++ b/configure
@@ -6438,13 +6438,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I${libmfx_incdir}/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 9d08485c92..84f0401b0f 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -39,7 +39,7 @@
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 8090b748b3..24c3e9307e 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8bce9f2cf0..1cadb846f5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -25,7 +25,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 06f55604b5..7eaa680ae4 100644
--- 

[FFmpeg-devel] [PATCH v6 02/10] configure: fix the check for MFX_CODEC_VP9

2021-10-15 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index f89e769684..0204d230c7 100755
--- a/configure
+++ b/configure
@@ -6444,7 +6444,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2021-10-15 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 92610c7edc..f89e769684 100755
--- a/configure
+++ b/configure
@@ -6438,8 +6438,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 00/10] make QSV works with the Intel's oneVPL

2021-10-15 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1]. oneVPL is a successor to Intel(R) Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[2].

It is recommended to use oneVPL for new work, even for currently available
hardwares[3]. Hence, this patchset added a new option --enable-onevpl to bring
the support for oneVPL in QSV. New features for oneVPL will be implemented in
other patchset. --enble-libmfx option still works with Intel(R) Media SDK.

Note user can't enable onevpl and libmfx together.

oneVPL dispatcher source code:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v6:
  - Use ${libmfx_incdir} in configure
  - Don't define mfx related function in an exported header
  - Rebased this patchset against the latest master and fixed bugs

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix
[3] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using oneVPL
  configure: add --enable-libvpl option

 configure|  29 ++-
 libavcodec/qsv.c | 220 ++--
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  21 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 145 ++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  73 +++---
 libavfilter/vf_scale_qsv.c   |  88 ---
 libavutil/hwcontext_d3d11va.c|  13 +
 libavutil/hwcontext_d3d11va.h|   5 +
 libavutil/hwcontext_dxva2.c  |   8 +
 libavutil/hwcontext_dxva2.h  |   4 +
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 423 +++
 libavutil/hwcontext_qsv.h|   3 +-
 libavutil/hwcontext_vaapi.c  |  13 +
 libavutil/hwcontext_vaapi.h  |   4 +
 25 files changed, 934 insertions(+), 188 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] qsvenc_hevc: Enable look ahead with ExtBRC

2021-10-08 Thread Haihao Xiang
From: Daniel Socek 

Signed-off-by: Daniel Socek 
Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvenc.c  | 3 +++
 libavcodec/qsvenc_hevc.c | 1 +
 2 files changed, 4 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 06f55604b5..e21a9b1207 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -610,6 +610,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 switch (q->param.mfx.RateControlMethod) {
 case MFX_RATECONTROL_CBR:
 case MFX_RATECONTROL_VBR:
+if (q->extbrc) {
+q->extco2.LookAheadDepth = q->look_ahead_depth;
+}
 #if QSV_HAVE_VCM
 case MFX_RATECONTROL_VCM:
 #endif
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index b7b2f5633e..8af2aa0c07 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -248,6 +248,7 @@ static const AVOption options[] = {
 { "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
 { "recovery_point_sei", "Insert recovery point SEI messages",   
OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64 = -1 },
   -1,  1, VE },
 { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE},
+{ "look_ahead_depth", "Depth of look ahead in number frames", 
OFFSET(qsv.look_ahead_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, VE },
 
 { NULL },
 };
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2021-10-08 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7eaa680ae4..6c6494745f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -100,7 +100,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 10/10] configure: add --enable-libvpl option

2021-10-08 Thread Haihao Xiang
This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.2
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

[1] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html
---
 configure | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index b7691d3218..5ccb2592a6 100755
--- a/configure
+++ b/configure
@@ -337,6 +337,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1895,6 +1896,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6429,22 +6431,34 @@ enabled libilbc   && require libilbc ilbc.h 
WebRtcIlbcfix_InitDecode -li
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I$($pkg_config --variable=includedir libmfx)/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still used in the following 
check for --enable-libvpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check.
+check_pkg_config libmfx "vpl >= 2.2" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.2+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+die "ERROR: libvpl >= 2.2 not found"
+fi
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 09/10] qsv: use a new method to create mfx session when using oneVPL

2021-10-08 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add AccelerationMode config filter for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Signed-off-by: galinart 
---
 libavcodec/qsv.c | 197 +--
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |  10 +
 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 -
 libavfilter/qsvvpp.c | 113 ++-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_qsv.c| 325 +++
 libavutil/hwcontext_qsv.h|   1 +
 15 files changed, 597 insertions(+), 89 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index d6f77908e4..46d3ac95eb 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -47,6 +47,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) {
@@ -387,6 +393,164 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  void **ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = 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);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX loader\n");
+
+loader = *ploader;
+}
+
+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(avctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", 
sts);
+goto fail;
+

[FFmpeg-devel] [PATCH v5 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2021-10-08 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7a71ffe98f..93af4d1198 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -64,7 +64,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 02/10] configure: fix the check for MFX_CODEC_VP9

2021-10-08 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 960b030e24..b4a8c04a26 100755
--- a/configure
+++ b/configure
@@ -6441,7 +6441,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2021-10-08 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 57 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e0a124a5cb..d6f77908e4 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,10 +89,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 659417ded8..ff50b41de8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -61,6 +61,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1cadb846f5..9395a1fd9a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -171,7 +171,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -282,10 +286,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 6c6494745f..546efd9668 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1029,6 +1029,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1065,6 +1066,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1080,7 +1082,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+

[FFmpeg-devel] [PATCH v5 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2021-10-08 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 83056e5976..e0a124a5cb 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -137,8 +138,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -148,7 +151,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..1113d27ba1 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 static const struct {
@@ -95,8 +97,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -106,7 +110,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 8c0cf3ed95..46e90c1d2c 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2021-10-08 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 5e630e6e5d..960b030e24 100755
--- a/configure
+++ b/configure
@@ -6435,8 +6435,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2021-10-08 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 84f0401b0f..83056e5976 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,11 +36,16 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -291,6 +295,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -334,6 +339,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 24c3e9307e..659417ded8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 03/10] qsv: remove mfx/ prefix from mfx headers

2021-10-08 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index b4a8c04a26..b7691d3218 100755
--- a/configure
+++ b/configure
@@ -6435,13 +6435,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 9d08485c92..84f0401b0f 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -39,7 +39,7 @@
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 8090b748b3..24c3e9307e 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8bce9f2cf0..1cadb846f5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -25,7 +25,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 

[FFmpeg-devel] [PATCH v5 00/10] make QSV works with the Intel's oneVPL

2021-10-08 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1]. oneVPL is a successor to Intel(R) Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[2].

It is recommended to use oneVPL for new work, even for currently available
hardwares[3]. Hence, this patchset added a new option --enable-onevpl to bring
the support for oneVPL in QSV. New features for oneVPL will be implemented in
other patchset. --enble-libmfx option still works with Intel(R) Media SDK.

Note user can't enable onevpl and libmfx together.

oneVPL dispatcher source code:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v5:
 - Rebased this patchset against the latest master
 - Do not define mfx related API in an export header

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix
[3] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using oneVPL
  configure: add --enable-libvpl option

 configure|  28 ++-
 libavcodec/qsv.c | 220 --
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  21 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 145 +++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  73 +++---
 libavfilter/vf_scale_qsv.c   |  88 +++
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 383 ++-
 libavutil/hwcontext_qsv.h|   3 +-
 19 files changed, 846 insertions(+), 188 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2021-09-23 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 5e76299372..69fbc2b53b 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -100,7 +100,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 10/10] configure: add --enable-libvpl option

2021-09-23 Thread Haihao Xiang
This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.2
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.

It is recommended to use oneVPL for new work, even for currently available
hardwares [1]

[1] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html
---
 configure | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index 9655a5823e..e9d2564819 100755
--- a/configure
+++ b/configure
@@ -337,6 +337,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1895,6 +1896,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6428,22 +6430,34 @@ enabled libilbc   && require libilbc ilbc.h 
WebRtcIlbcfix_InitDecode -li
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I$($pkg_config --variable=includedir libmfx)/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still used in the following 
check for --enable-libvpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check.
+check_pkg_config libmfx "vpl >= 2.2" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.2+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+die "ERROR: libvpl >= 2.2 not found"
+fi
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 09/10] qsv: use a new method to create mfx session when using oneVPL

2021-09-23 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add AccelerationMode config filter for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Signed-off-by: galinart 
---
 libavcodec/qsv.c | 191 --
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |   4 +
 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 -
 libavfilter/qsvvpp.c | 107 ++-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_qsv.c| 319 +++
 libavutil/hwcontext_qsv.h|  16 ++
 15 files changed, 588 insertions(+), 89 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index d6f77908e4..f00bb4db8a 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -387,6 +387,164 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  mfxLoader *ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = 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);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX loader\n");
+
+loader = *ploader;
+}
+
+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(avctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", 
sts);
+goto fail;
+}
+
+*psession = session;
+
+if (!*ploader)
+*ploader = loader;
+
+return 0;
+
+fail:
+if (!*ploader && loader)
+MFXUnload(loader);
+
+return AVERROR_UNKNOWN;
+}

[FFmpeg-devel] [PATCH v4 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2021-09-23 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7a71ffe98f..93af4d1198 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -64,7 +64,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2021-09-23 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 57 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e0a124a5cb..d6f77908e4 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,10 +89,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 659417ded8..ff50b41de8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -61,6 +61,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1cadb846f5..9395a1fd9a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -171,7 +171,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -282,10 +286,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 69fbc2b53b..bf106264c7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1029,6 +1029,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1065,6 +1066,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1080,7 +1082,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+

[FFmpeg-devel] [PATCH v4 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2021-09-23 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 83056e5976..e0a124a5cb 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -137,8 +138,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -148,7 +151,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..1113d27ba1 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 static const struct {
@@ -95,8 +97,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -106,7 +110,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 8c0cf3ed95..46e90c1d2c 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2021-09-23 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 84f0401b0f..83056e5976 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,11 +36,16 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -291,6 +295,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -334,6 +339,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 24c3e9307e..659417ded8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 03/10] qsv: remove mfx/ prefix from mfx headers

2021-09-23 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 21c744e627..9655a5823e 100755
--- a/configure
+++ b/configure
@@ -6434,13 +6434,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 9d08485c92..84f0401b0f 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -39,7 +39,7 @@
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 8090b748b3..24c3e9307e 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8bce9f2cf0..1cadb846f5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -25,7 +25,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 

[FFmpeg-devel] [PATCH v4 02/10] configure: fix the check for MFX_CODEC_VP9

2021-09-23 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 34e9a7c863..21c744e627 100755
--- a/configure
+++ b/configure
@@ -6440,7 +6440,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2021-09-23 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 231d0398a8..34e9a7c863 100755
--- a/configure
+++ b/configure
@@ -6434,8 +6434,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 00/10] make QSV works with the Intel's oneVPL

2021-09-23 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1]. oneVPL is a successor to Intel(R) Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[2].

It is recommended to use oneVPL for new work, even for currently available
hardwares[3]. Hence, this patchset added a new option --enable-onevpl to bring
the support for oneVPL in QSV. New features for oneVPL will be implemented in
other patchset. --enble-libmfx option still works with Intel(R) Media SDK.

Note user can't enable onevpl and libmfx together.

oneVPL dispatcher source code:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v4: rebased this patchset against the latest master and fixed bugs

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix
[3] 
https://software.intel.com/content/www/us/en/develop/articles/upgrading-from-msdk-to-onevpl.html

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using oneVPL
  configure: add --enable-libvpl option

 configure|  28 ++-
 libavcodec/qsv.c | 214 --
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  15 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 139 +++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  73 +++---
 libavfilter/vf_scale_qsv.c   |  88 
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 377 ++-
 libavutil/hwcontext_qsv.h|  18 +-
 19 files changed, 837 insertions(+), 188 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] ffmpeg_opt: consider HW acceleration method when selecting decoder

2021-09-22 Thread Haihao Xiang
Usually a HW decoder is expected when user specifies a HW acceleration
method via -hwaccel option, however the current implementation doesn't
take HW acceleration method into account, it is possible to select a SW
decoder.

For example:

$> ffmpeg -hwaccel vaapi -i av1.ivf -f null -
...
Stream #0:0 -> #0:0 (av1 (libdav1d) -> wrapped_avframe (native))

libdav1d is selected in this case even if vaapi is specified.

After applying this patch, the native av1 decoder (with vaapi support)
is selected.
...
Stream #0:0 -> #0:0 (av1 (native) -> wrapped_avframe (native))
---
 fftools/ffmpeg_opt.c | 44 +++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 2d9a8a2ea0..914078add9 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -804,6 +804,48 @@ static const AVCodec *choose_decoder(OptionsContext *o, 
AVFormatContext *s, AVSt
 return avcodec_find_decoder(st->codecpar->codec_id);
 }
 
+static const AVCodec *choose_decoder2(InputStream *ist, OptionsContext *o, 
AVFormatContext *s, AVStream *st)
+{
+char *codec_name = NULL;
+
+MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
+if (codec_name) {
+const AVCodec *codec = find_codec_or_die(codec_name, 
st->codecpar->codec_type, 0);
+st->codecpar->codec_id = codec->id;
+if (recast_media && st->codecpar->codec_type != codec->type)
+st->codecpar->codec_type = codec->type;
+return codec;
+} else {
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+ist->hwaccel_id == HWACCEL_GENERIC &&
+ist->hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
+const AVCodec *p;
+void *i = 0;
+
+while ((p = av_codec_iterate())) {
+int j;
+
+if (p->id != st->codecpar->codec_id ||
+!av_codec_is_decoder(p) ||
+!avcodec_get_hw_config(p, 0))
+continue;
+
+for (j = 0; ;j++) {
+const AVCodecHWConfig *config = avcodec_get_hw_config(p, 
j);
+
+if (!config)
+break;
+
+if (config->device_type == ist->hwaccel_device_type)
+return p;
+}
+}
+}
+
+return avcodec_find_decoder(st->codecpar->codec_id);
+}
+}
+
 /* Add all the streams from the given input file to the global
  * list of input streams. */
 static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
@@ -932,7 +974,7 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
 }
 
-ist->dec = choose_decoder(o, ic, st);
+ist->dec = choose_decoder2(ist, o, ic, st);
 ist->decoder_opts = filter_codec_opts(o->g->codec_opts, 
ist->st->codecpar->codec_id, ic, st, ist->dec);
 
 ist->reinit_filters = -1;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] ffmpeg_opt: select a decoder after getting values for per-stream hwdec options

2021-09-22 Thread Haihao Xiang
After applying this patch, the desired HW acceleration method is known
before selecting decoder, so we may take HW acceleration method into
account when selecting decoder for input stream in the next commit

There should be no functional changes in this patch
---
 fftools/ffmpeg_opt.c | 116 ++-
 1 file changed, 59 insertions(+), 57 deletions(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 1d6d29cfc9..2d9a8a2ea0 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -853,63 +853,7 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 st->codecpar->codec_tag = tag;
 }
 
-ist->dec = choose_decoder(o, ic, st);
-ist->decoder_opts = filter_codec_opts(o->g->codec_opts, 
ist->st->codecpar->codec_id, ic, st, ist->dec);
-
-ist->reinit_filters = -1;
-MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
-
-MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
-ist->user_set_discard = AVDISCARD_NONE;
-
-if ((o->video_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) ||
-(o->audio_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO) ||
-(o->subtitle_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_SUBTITLE) ||
-(o->data_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_DATA))
-ist->user_set_discard = AVDISCARD_ALL;
-
-if (discard_str && av_opt_eval_int(, discard_opt, discard_str, 
>user_set_discard) < 0) {
-av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
-discard_str);
-exit_program(1);
-}
-
-ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
-
-ist->dec_ctx = avcodec_alloc_context3(ist->dec);
-if (!ist->dec_ctx) {
-av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder 
context.\n");
-exit_program(1);
-}
-
-ret = avcodec_parameters_to_context(ist->dec_ctx, par);
-if (ret < 0) {
-av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder 
context.\n");
-exit_program(1);
-}
-
-if (o->bitexact)
-ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
-
-switch (par->codec_type) {
-case AVMEDIA_TYPE_VIDEO:
-if(!ist->dec)
-ist->dec = avcodec_find_decoder(par->codec_id);
-
-// avformat_find_stream_info() doesn't set this for us anymore.
-ist->dec_ctx->framerate = st->avg_frame_rate;
-
-MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
-if (framerate && av_parse_video_rate(>framerate,
- framerate) < 0) {
-av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
-   framerate);
-exit_program(1);
-}
-
-ist->top_field_first = -1;
-MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, 
st);
-
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
 MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
  hwaccel_output_format, ic, st);
@@ -986,6 +930,64 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 }
 
 ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
+}
+
+ist->dec = choose_decoder(o, ic, st);
+ist->decoder_opts = filter_codec_opts(o->g->codec_opts, 
ist->st->codecpar->codec_id, ic, st, ist->dec);
+
+ist->reinit_filters = -1;
+MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
+
+MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
+ist->user_set_discard = AVDISCARD_NONE;
+
+if ((o->video_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) ||
+(o->audio_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO) ||
+(o->subtitle_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_SUBTITLE) ||
+(o->data_disable && ist->st->codecpar->codec_type == 
AVMEDIA_TYPE_DATA))
+ist->user_set_discard = AVDISCARD_ALL;
+
+if (discard_str && av_opt_eval_int(, discard_opt, discard_str, 
>user_set_discard) < 0) {
+av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
+discard_str);
+exit_program(1);
+}
+
+ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
+
+ist->dec_ctx = avcodec_alloc_context3(ist->dec);
+if (!ist->dec_ctx) {
+av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder 
context.\n");
+exit_program(1);
+}
+
+ret = avcodec_parameters_to_context(ist->dec_ctx, par);
+if (ret < 

[FFmpeg-devel] [PATCH v3 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2021-09-17 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 56 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 56 +---
 11 files changed, 180 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 53403ef9fc..780bc3c4ec 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -89,10 +89,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 659417ded8..ff50b41de8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -61,6 +61,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1cadb846f5..9395a1fd9a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -171,7 +171,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -282,10 +286,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 57e95a2aa1..1b467cf2cd 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1029,6 +1029,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1065,6 +1066,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1080,7 +1082,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+

[FFmpeg-devel] [PATCH v3 10/10] configure: add --enable-libvpl option

2021-09-17 Thread Haihao Xiang
This allows user to build FFmpeg against Intel oneVPL. oneVPL 2.2
is the required minimum version when building Intel oneVPL code.

It will fail to run configure script if both libmfx and libvpl are
enabled.
---
 configure | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index 34fe342c3b..0d9cb67490 100755
--- a/configure
+++ b/configure
@@ -337,6 +337,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL code via libvpl if libmfx is 
not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1895,6 +1896,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6426,22 +6428,34 @@ enabled libilbc   && require libilbc ilbc.h 
WebRtcIlbcfix_InitDecode -li
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I$($pkg_config --variable=includedir libmfx)/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still used in the following 
check for --enable-libvpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check.
+check_pkg_config libmfx "vpl >= 2.2" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.2+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+die "ERROR: libvpl >= 2.2 not found"
+fi
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2021-09-17 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index d977ed6ab3..57e95a2aa1 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -100,7 +100,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 09/10] qsv: use a new method to create mfx session when using oneVPL

2021-09-17 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add AccelerationMode config filter for D3D9/D3D11 session (galinart)

The default device is changed to d3d11va for oneVPL when both d3d11va
and dxva2 are enabled on Microsoft Windows

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Signed-off-by: galinart 
---
 libavcodec/qsv.c | 191 --
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |   4 +
 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 -
 libavfilter/qsvvpp.c | 107 +-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_qsv.c| 322 +++
 libavutil/hwcontext_qsv.h|  16 ++
 15 files changed, 591 insertions(+), 89 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 780bc3c4ec..92a59457ea 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -387,6 +387,164 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  mfxLoader *ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = 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);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use Intel(R) oneVPL to create MFX session with the specified 
MFX loader\n");
+
+loader = *ploader;
+}
+
+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(avctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", 
sts);
+goto fail;
+}
+
+*psession = session;
+
+if (!*ploader)
+*ploader = loader;
+
+return 0;
+
+fail:
+if (!*ploader && loader)
+MFXUnload(loader);
+
+return AVERROR_UNKNOWN;
+}
+

[FFmpeg-devel] [PATCH v3 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2021-09-17 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7a71ffe98f..93af4d1198 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -64,7 +64,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2021-09-17 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index fc2bf6b85d..53403ef9fc 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -37,6 +37,7 @@
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -137,8 +138,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -148,7 +151,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 /**
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 135d4c4e36..0f7f76b971 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -38,6 +38,8 @@
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const AVRational default_tb = { 1, 9 };
 
 static const struct {
@@ -95,8 +97,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -106,7 +110,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 8c0cf3ed95..46e90c1d2c 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2021-09-17 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 8 +++-
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index dbaeed503c..fc2bf6b85d 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -37,11 +36,16 @@
 #include "qsv_internal.h"
 
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -291,6 +295,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -334,6 +339,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 24c3e9307e..659417ded8 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDLPair *handle_pair;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 03/10] qsv: remove mfx/ prefix from mfx headers

2021-09-17 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index d811a06698..34fe342c3b 100755
--- a/configure
+++ b/configure
@@ -6432,13 +6432,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 2f332092a1..dbaeed503c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -39,7 +39,7 @@
 #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 8090b748b3..24c3e9307e 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8bce9f2cf0..1cadb846f5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -25,7 +25,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 

[FFmpeg-devel] [PATCH v3 02/10] configure: fix the check for MFX_CODEC_VP9

2021-09-17 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 48fde41b68..d811a06698 100755
--- a/configure
+++ b/configure
@@ -6438,7 +6438,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2021-09-17 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 7ac23123c7..48fde41b68 100755
--- a/configure
+++ b/configure
@@ -6432,8 +6432,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 00/10] make QSV works with the Intel's oneVPL

2021-09-17 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1]. oneVPL is a successor to Intel(R) Media
SDK, but removed obsolete features. Intel(R) Media SDK lifetime comes to an
end now, new features for new Intel Gen platforms will be supported in oneVPL
only[2].

This patchset added a new option --enable-onevpl to bring the support for oneVPL
in QSV, new features for oneVPL will be implemented in other patchset. 
--enble-libmfx
option still works with Intel(R) Media SDK. Note user can't enable onevpl and
libmfx together.

oneVPL dispatcher source code:
https://github.com/oneapi-src/oneVPL

oneVPL GPU runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

v3:
  - Rebased this patchset against the latest master
  - Added support for d3d11va

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using oneVPL
  configure: add --enable-libvpl option

 configure|  28 ++-
 libavcodec/qsv.c | 214 +++--
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  15 +-
 libavcodec/qsvenc.c  |  25 +-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 139 ++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  72 +++---
 libavfilter/vf_scale_qsv.c   |  88 +++
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 380 ++-
 libavutil/hwcontext_qsv.h|  18 +-
 19 files changed, 839 insertions(+), 188 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavcodec/hevc_mp4toannexb_bsf: ignore extra data if possible

2021-09-09 Thread Haihao Xiang
It is possible that an IRAP frame in input AVPacket has SPS and PPS, and
these headers should take effect. Hence we should not prepend extra data
to IRAP frame in this case, otherwise an IRAP frame in output AVPacket
will have 2 SPS/PPS when extra data also has SPS and PPS, the second
SPS/PPS will override the first SPS/PPS and take effect.
---
 libavcodec/hevc_mp4toannexb_bsf.c | 7 +--
 tests/fate/hevc.mak   | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 790dfb0394..3b3732bbd0 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -121,7 +121,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 HEVCBSFContext *s = ctx->priv_data;
 AVPacket *in;
 GetByteContext gb;
-
+int has_sps = 0, has_pps = 0;
 int got_irap = 0;
 int i, ret = 0;
 
@@ -155,10 +155,13 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, 
AVPacket *out)
 }
 
 nalu_type = (bytestream2_peek_byte() >> 1) & 0x3f;
+has_sps = (has_sps || nalu_type == HEVC_NAL_SPS);
+has_pps = (has_pps || nalu_type == HEVC_NAL_PPS);
 
 /* prepend extradata to IRAP frames */
 is_irap   = nalu_type >= 16 && nalu_type <= 23;
-add_extradata = is_irap && !got_irap;
+/* ignore the extradata if IRAP frame has sps and pps */
+add_extradata = is_irap && !got_irap && !(has_sps && has_pps);
 extra_size= add_extradata * ctx->par_out->extradata_size;
 got_irap |= is_irap;
 
diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index f6ea1df9a5..a4dac99b6a 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -251,7 +251,7 @@ FATE_HEVC-$(call ALLYES, HEVC_DEMUXER MOV_DEMUXER 
HEVC_MP4TOANNEXB_BSF MOV_MUXER
 fate-hevc-bsf-mp4toannexb: tests/data/hevc-mp4.mov
 fate-hevc-bsf-mp4toannexb: CMD = md5 -i $(TARGET_PATH)/tests/data/hevc-mp4.mov 
-c:v copy -fflags +bitexact -f hevc
 fate-hevc-bsf-mp4toannexb: CMP = oneline
-fate-hevc-bsf-mp4toannexb: REF = 1873662a3af1848c37e4eb25722c8df9
+fate-hevc-bsf-mp4toannexb: REF = 3c9d998a3aa2b9e0fb1c1f434952bf8b
 
 fate-hevc-skiploopfilter: CMD = framemd5 -skip_loop_filter nokey -i 
$(TARGET_SAMPLES)/hevc-conformance/SAO_D_Samsung_5.bit -sws_flags bitexact
 FATE_HEVC += fate-hevc-skiploopfilter
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 04/10] qsv: load user plugin for MFX_VERSION < 2.0

2021-08-16 Thread Haihao Xiang
User plugin isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL Support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c  | 9 -
 libavcodec/qsv_internal.h | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 93cd4892dc..8ac2293b57 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 #include 
 
 #include 
@@ -36,10 +35,16 @@
 #include "avcodec.h"
 #include "qsv_internal.h"
 
+#define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
 #endif
 
+#if QSV_HAVE_USER_PLUGIN
+#include 
+#endif
+
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
 switch (codec_id) {
@@ -286,6 +291,7 @@ enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
 static int qsv_load_plugins(mfxSession session, const char *load_plugins,
 void *logctx)
 {
+#if QSV_HAVE_USER_PLUGIN
 if (!load_plugins || !*load_plugins)
 return 0;
 
@@ -329,6 +335,7 @@ load_plugin_fail:
 if (err < 0)
 return err;
 }
+#endif
 
 return 0;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 3eed35c13a..10114f1c00 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDL handle;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 10/10] configure: add --enable-libvpl option

2021-08-16 Thread Haihao Xiang
This allows user to build FFmpeg against Intel's oneVPL SDK. oneVPL 2.2
is the required minimum version when building Intel oneVPL SDK code.

It will fail to run configure script if both libmfx and libvpl are
enabled.
---
 configure | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index d3c0f63f85..b2e819a695 100755
--- a/configure
+++ b/configure
@@ -337,6 +337,7 @@ External library support:
   --disable-ffnvcodec  disable dynamically linked Nvidia code [autodetect]
   --enable-libdrm  enable DRM code (Linux) [no]
   --enable-libmfx  enable Intel MediaSDK (AKA Quick Sync Video) code 
via libmfx [no]
+  --enable-libvpl  enable Intel oneVPL SDK code via libvpl if libmfx 
is not used [no]
   --enable-libnpp  enable Nvidia Performance Primitives-based code [no]
   --enable-mmalenable Broadcom Multi-Media Abstraction Layer 
(Raspberry Pi) via MMAL [no]
   --disable-nvdec  disable Nvidia video decoding acceleration (via 
hwaccel) [autodetect]
@@ -1895,6 +1896,7 @@ HWACCEL_LIBRARY_NONFREE_LIST="
 HWACCEL_LIBRARY_LIST="
 $HWACCEL_LIBRARY_NONFREE_LIST
 libmfx
+libvpl
 mmal
 omx
 opencl
@@ -6430,22 +6432,34 @@ enabled libilbc   && require libilbc ilbc.h 
WebRtcIlbcfix_InitDecode -li
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
+
+if enabled libmfx && enabled libvpl; then
+   die "ERROR: can not use libmfx and libvpl together"
 # While it may appear that require is being used as a pkg-config
 # fallback for libmfx, it is actually being used to detect a different
 # installation route altogether.  If libmfx is installed via the Intel
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+elif enabled libmfx; then
+{ check_pkg_config libmfx "libmfx < 2.0" "mfxvideo.h" MFXInit || \
 # Some old versions of libmfx have the following settings in libmfx.pc:
 #   includedir=/usr/include
 #   Cflags: -I${includedir}
 # So add -I${includedir}/mfx to CFLAGS
- { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
- { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
-   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
-"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+  { check_pkg_config libmfx "libmfx < 2.0" "mfx/mfxvideo.h" MFXInit && 
add_cflags -I$($pkg_config --variable=includedir libmfx)/mfx; } ||
+  { require "libmfx < 2.0" "mfxvideo.h" MFXInit "-llibmfx 
$advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
+warn "build FFmpeg against libmfx 1.x, obsolete features of libmfx such as 
OPAQUE memory,\n"\
+ "multi-frame encode, user plugins and LA_EXT rate control mode are 
enabled"
+elif enabled libvpl; then
+# Consider pkg-config only. The name of libmfx is still used in the following 
check for --enable-vpl option
+# because QSV has dependency on libmfx, we can use the same dependency if 
using libmfx in this check.
+check_pkg_config libmfx "vpl >= 2.2" "mfxvideo.h mfxdispatcher.h" MFXLoad 
&& \
+warn "build FFmpeg against oneVPL 2.2+, OPAQUE memory, multi-frame 
encode, user plugins\n"\
+ "and LA_EXT rate control mode in FFmpeg QSV won't be supported." 
||
+die "ERROR: libvpl >= 2.2 not found"
+fi
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 09/10] qsv: use a new method to create mfx session when using the oneVPL SDK

2021-08-16 Thread Haihao Xiang
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

Add AccelerationMode config filter for D3D9 session (galinart)

This is in preparation for oneVPL support

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Signed-off-by: galinart 
---
 libavcodec/qsv.c | 191 +---
 libavcodec/qsv_internal.h|   1 +
 libavcodec/qsvdec.c  |   4 +
 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 -
 libavfilter/qsvvpp.c | 107 ++-
 libavfilter/qsvvpp.h |   5 +
 libavfilter/vf_deinterlace_qsv.c |  14 +-
 libavfilter/vf_scale_qsv.c   |  12 +-
 libavutil/hwcontext_qsv.c| 300 ++-
 libavutil/hwcontext_qsv.h|  16 ++
 15 files changed, 569 insertions(+), 89 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 98fc6a92b6..bfa9cad8a2 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -383,25 +383,176 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 }
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 
+#if QSV_ONEVPL
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  mfxIMPL implementation,
+  mfxVersion *pver,
+  int gpu_copy,
+  mfxSession *psession,
+  mfxLoader *ploader)
+{
+mfxStatus sts;
+mfxLoader loader = NULL;
+mfxSession session = NULL;
+mfxConfig cfg;
+mfxVariant impl_value;
+uint32_t impl_idx = 0;
+
+*psession = NULL;
+
+/* Don't create a new MFX loader if the input loader is valid */
+if (*ploader == NULL) {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use the Intel oneVPL SDK to create MFX session, the required "
+   "implementation version is %d.%d\n",
+   pver->Major, pver->Minor);
+
+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;
+}
+} else {
+av_log(avctx, AV_LOG_VERBOSE,
+   "Use the Intel oneVPL SDK to create MFX session with the 
specified MFX loader\n");
+
+loader = *ploader;
+}
+
+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(avctx, AV_LOG_ERROR, "Error creating a MFX session: %d.\n", 
sts);
+goto fail;
+}
+
+*psession = session;
+
+if (!*ploader)
+*ploader = loader;
+
+return 0;
+
+fail:
+if (!*ploader && loader)
+MFXUnload(loader);
+
+return AVERROR_UNKNOWN;
+}
+
+#else
+
+static int qsv_create_mfx_session(AVCodecContext *avctx,
+  

[FFmpeg-devel] [PATCH v2 08/10] qsv: support OPAQUE memory when MFX_VERSION < 2.0

2021-08-16 Thread Haihao Xiang
OPAQUE memory isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c |  4 ++
 libavcodec/qsv.h |  2 +
 libavcodec/qsv_internal.h|  1 +
 libavcodec/qsvdec.c  |  9 
 libavcodec/qsvenc.c  | 21 +
 libavcodec/qsvenc.h  |  2 +
 libavfilter/qsvvpp.c | 26 ++-
 libavfilter/qsvvpp.h |  3 ++
 libavfilter/vf_deinterlace_qsv.c | 56 +---
 libavfilter/vf_scale_qsv.c   | 74 ++--
 libavutil/hwcontext_qsv.c| 57 +---
 11 files changed, 181 insertions(+), 74 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b1d50f8999..98fc6a92b6 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -88,10 +88,14 @@ static const struct {
 } qsv_iopatterns[] = {
 {MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface"
 },
 {MFX_IOPATTERN_IN_SYSTEM_MEMORY,"input is system memory surface"   
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_IN_OPAQUE_MEMORY,"input is opaque memory surface"   
 },
+#endif
 {MFX_IOPATTERN_OUT_VIDEO_MEMORY,"output is video memory surface"   
 },
 {MFX_IOPATTERN_OUT_SYSTEM_MEMORY,   "output is system memory surface"  
 },
+#if QSV_HAVE_OPAQUE
 {MFX_IOPATTERN_OUT_OPAQUE_MEMORY,   "output is opaque memory surface"  
 },
+#endif
 };
 
 int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..c156b08d07 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
  * required by the encoder and the user-provided value nb_opaque_surfaces.
  * The array of the opaque surfaces will be exported to the caller through
  * the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (MFX_VERSION >= 2.0)
  */
 int opaque_alloc;
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 10114f1c00..2afb46167d 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -61,6 +61,7 @@
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
 #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+#define QSV_HAVE_OPAQUE  !QSV_ONEVPL
 
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1cadb846f5..9395a1fd9a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -171,7 +171,11 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->iopattern == 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
  q->gpu_copy);
 if (ret < 0) {
 av_buffer_unref(>frames_ctx.hw_frames_ctx);
@@ -282,10 +286,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 
 if (!iopattern) {
+#if QSV_HAVE_OPAQUE
 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
 else if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+if (frames_hwctx->frame_type & 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
 }
 }
 
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 542eaca7a4..5e600afca4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1029,6 +1029,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
+#if QSV_HAVE_OPAQUE
 static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
 {
 AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1065,6 +1066,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, 
QSVEncContext *q)
 
 return 0;
 }
+#endif
 
 static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
 {
@@ -1080,7 +1082,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 
 ret = ff_qsv_init_session_frames(avctx, >internal_qs.session,
  >frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
  q->param.IOPattern == 
MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+

[FFmpeg-devel] [PATCH v2 07/10] qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0

2021-08-16 Thread Haihao Xiang
MFX_RATECONTROL_LA_EXT isn't supported for MFX_VERSION >= 2.0[1][2].
This is in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index b561e20971..542eaca7a4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -100,7 +100,7 @@ static const struct {
 #if QSV_HAVE_VCM
 { MFX_RATECONTROL_VCM, "VCM" },
 #endif
-#if QSV_VERSION_ATLEAST(1, 10)
+#if QSV_VERSION_ATLEAST(1, 10) && !QSV_ONEVPL
 { MFX_RATECONTROL_LA_EXT,  "LA_EXT" },
 #endif
 #if QSV_HAVE_LA_HRD
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 03/10] qsv: remove mfx/ prefix from mfx headers

2021-08-16 Thread Haihao Xiang
The following Cflags has been added to libmfx.pc, so mfx/ prefix is no
longer needed when including mfx headers in FFmpeg.
   Cflags: -I${includedir} -I${includedir}/mfx

Some old versions of libmfx have the following Cflags in libmfx.pc
   Cflags: -I${includedir}

We may add -I${includedir}/mfx to CFLAGS when running 'configure
--enable-libmfx' for old versions of libmfx, if so, mfx headers without
mfx/ prefix can be included too.

If libmfx comes without pkg-config support, we may do a small change to
the settings of the environment(e.g. set -I/opt/intel/mediasdk/include/mfx
instead of -I/opt/intel/mediasdk/include to CFLAGS), then the build can
find the mfx headers without mfx/ prefix

After applying this change, we won't need to change #include for mfx
headers when mfx headers are installed under a new directory.

This is in preparation for oneVPL support (mfx headers in oneVPL are
installed under vpl directory)
---
 configure| 13 +
 libavcodec/qsv.c |  8 
 libavcodec/qsv.h |  2 +-
 libavcodec/qsv_internal.h|  2 +-
 libavcodec/qsvdec.c  |  2 +-
 libavcodec/qsvenc.c  |  2 +-
 libavcodec/qsvenc.h  |  2 +-
 libavcodec/qsvenc_h264.c |  2 +-
 libavcodec/qsvenc_hevc.c |  2 +-
 libavcodec/qsvenc_jpeg.c |  2 +-
 libavcodec/qsvenc_mpeg2.c|  2 +-
 libavcodec/qsvenc_vp9.c  |  2 +-
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_deinterlace_qsv.c |  2 +-
 libavfilter/vf_scale_qsv.c   |  2 +-
 libavutil/hwcontext_opencl.c |  2 +-
 libavutil/hwcontext_qsv.c|  2 +-
 libavutil/hwcontext_qsv.h|  2 +-
 18 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index b10a7b5a52..d3c0f63f85 100755
--- a/configure
+++ b/configure
@@ -6436,13 +6436,18 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
- { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfxvideo.h" MFXInit ||
+# Some old versions of libmfx have the following settings in libmfx.pc:
+#   includedir=/usr/include
+#   Cflags: -I${includedir}
+# So add -I${includedir}/mfx to CFLAGS
+ { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit && add_cflags -I$($pkg_config --variable=includedir 
libmfx)/mfx; } ||
+ { require "libmfx < 2.0" "mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } &&
warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
-
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfxdefs.h mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index c53e2e3b07..93cd4892dc 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,9 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -37,7 +37,7 @@
 #include "qsv_internal.h"
 
 #if QSV_VERSION_ATLEAST(1, 12)
-#include "mfx/mfxvp8.h"
+#include "mfxvp8.h"
 #endif
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index b77158ec26..04ae0d6f34 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -21,7 +21,7 @@
 #ifndef AVCODEC_QSV_H
 #define AVCODEC_QSV_H
 
-#include 
+#include 
 
 #include "libavutil/buffer.h"
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 327a8d3385..3eed35c13a 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -39,7 +39,7 @@
 #include "libavutil/hwcontext_vaapi.h"
 #endif
 
-#include 
+#include 
 
 #include "libavutil/frame.h"
 
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8bce9f2cf0..1cadb846f5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -25,7 +25,7 @@
 #include 
 #include 
 
-#include 
+#include 
 
 #include "libavutil/common.h"
 #include "libavutil/fifo.h"
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 50ec7065ca..b561e20971 100644
--- 

[FFmpeg-devel] [PATCH v2 06/10] qsvenc: support multi-frame encode when MFX_VERSION < 2.0

2021-08-16 Thread Haihao Xiang
Multi-frame encode isn't supported for MFX_VERSION >= 2.0[1][2]. This is
in preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7a71ffe98f..93af4d1198 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -64,7 +64,7 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 28)
-#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25) && !QSV_ONEVPL
 #endif
 
 #if !QSV_HAVE_LA_DS
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 02/10] configure: fix the check for MFX_CODEC_VP9

2021-08-16 Thread Haihao Xiang
The data structures for VP9 in mfxvp9.h is wrapped by
MFX_VERSION_NEXT, which means those data structures have never been used
in a public release. Actually MFX_CODEC_VP9 and other VP9 stuffs is
added in mfxstructures.h. In addition, mfxdefs.h is included in
mfxvp9.h, so we may use the check in this patch for MFX_CODEC_VP9

This is in preparation for oneVPL support because mfxvp9.h is removed
from oneVPL [1]

[1]: https://github.com/oneapi-src/oneVPL
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 4bdb8bac18..b10a7b5a52 100755
--- a/configure
+++ b/configure
@@ -6442,7 +6442,7 @@ enabled libmfx&& { { check_pkg_config libmfx 
"libmfx < 2.0" "mfx/mfx
 "multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
 
 if enabled libmfx; then
-   check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
+   check_cc MFX_CODEC_VP9 "mfx/mfxdefs.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
 
 enabled libmodplug&& require_pkg_config libmodplug libmodplug 
libmodplug/modplug.h ModPlug_Load
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 05/10] qsv: build audio related code when MFX_VERSION < 2.0

2021-08-16 Thread Haihao Xiang
Audio isn't supported for MFX_VERSION >= 2.0[1][2]. This is in
preparation for oneVPL support

[1]: 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html#msdk-full-name-feature-removals
[2]: https://github.com/oneapi-src/oneVPL
---
 libavcodec/qsv.c | 5 +
 libavfilter/qsvvpp.c | 6 ++
 libavfilter/qsvvpp.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 8ac2293b57..b1d50f8999 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -36,6 +36,7 @@
 #include "qsv_internal.h"
 
 #define QSV_HAVE_USER_PLUGIN!QSV_ONEVPL
+#define QSV_HAVE_AUDIO  !QSV_ONEVPL
 
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfxvp8.h"
@@ -136,8 +137,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -147,7 +150,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 int ff_qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index c7ef8a915f..73fcfecb46 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -37,6 +37,8 @@
 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
 
+#define QSV_HAVE_AUDIO !QSV_ONEVPL
+
 static const mfxHandleType handle_types[] = {
 MFX_HANDLE_VA_DISPLAY,
 MFX_HANDLE_D3D9_DEVICE_MANAGER,
@@ -100,8 +102,10 @@ static const struct {
 { MFX_ERR_INVALID_VIDEO_PARAM,  AVERROR(EINVAL), "invalid video 
parameters" },
 { MFX_ERR_UNDEFINED_BEHAVIOR,   AVERROR_BUG, "undefined behavior"  
 },
 { MFX_ERR_DEVICE_FAILED,AVERROR(EIO),"device failed"   
 },
+#if QSV_HAVE_AUDIO
 { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio 
parameters"},
 { MFX_ERR_INVALID_AUDIO_PARAM,  AVERROR(EINVAL), "invalid audio 
parameters" },
+#endif
 
 { MFX_WRN_IN_EXECUTION, 0,   "operation in 
execution"   },
 { MFX_WRN_DEVICE_BUSY,  0,   "device busy" 
 },
@@ -111,7 +115,9 @@ static const struct {
 { MFX_WRN_VALUE_NOT_CHANGED,0,   "value is saturated"  
 },
 { MFX_WRN_OUT_OF_RANGE, 0,   "value out of range"  
 },
 { MFX_WRN_FILTER_SKIPPED,   0,   "filter skipped"  
 },
+#if QSV_HAVE_AUDIO
 { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0,   "incompatible audio 
parameters"},
+#endif
 };
 
 static int qsv_map_error(mfxStatus mfx_err, const char **desc)
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 8c0cf3ed95..46e90c1d2c 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -40,6 +40,8 @@
 ((MFX_VERSION.Major > (MAJOR)) ||   \
 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
 
+#define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
+
 typedef struct QSVFrame {
 AVFrame  *frame;
 mfxFrameSurface1 surface;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 00/10] make QSV works with Intel's oneVPL

2021-08-16 Thread Haihao Xiang
The oneAPI Video Processing Library (oneVPL) is a single interface for
encode, decode and video processing[1]. oneVPL is a successor to Intel's Media
SDK (MediaSDK), but removed obsolete features. MediaSDK lifetime comes to an
end now[2].

This patchset fixes compiler errors when building FFmpeg against oneVPL and uses
a new way to create MFX session for oneVPL. New features for oneVPL will be
implemented in other patchset.

The oneVPL source code:
https://github.com/oneapi-src/oneVPL
The oneVPL runtime for new Intel Gen platforms:
https://github.com/oneapi-src/oneVPL-intel-gpu

[1] https://spec.oneapi.io/versions/latest/elements/oneVPL/source/index.html
[2] https://github.com/Intel-Media-SDK/MediaSDK/#media-sdk-support-matrix

Haihao Xiang (10):
  configure: ensure --enable-libmfx uses libmfx 1.x
  configure: fix the check for MFX_CODEC_VP9
  qsv: remove mfx/ prefix from mfx headers
  qsv: load user plugin for MFX_VERSION < 2.0
  qsv: build audio related code when MFX_VERSION < 2.0
  qsvenc: support multi-frame encode when MFX_VERSION < 2.0
  qsvenc: support MFX_RATECONTROL_LA_EXT when MFX_VERSION < 2.0
  qsv: support OPAQUE memory when MFX_VERSION < 2.0
  qsv: use a new method to create mfx session when using the oneVPL SDK
  configure: add --enable-libvpl option

 configure|  28 ++-
 libavcodec/qsv.c | 215 +++---
 libavcodec/qsv.h |   4 +-
 libavcodec/qsv_internal.h|   6 +-
 libavcodec/qsvdec.c  |  15 +-
 libavcodec/qsvenc.c  |  25 ++-
 libavcodec/qsvenc.h  |   9 +-
 libavcodec/qsvenc_h264.c |   3 +-
 libavcodec/qsvenc_hevc.c |   3 +-
 libavcodec/qsvenc_jpeg.c |   3 +-
 libavcodec/qsvenc_mpeg2.c|   3 +-
 libavcodec/qsvenc_vp9.c  |   3 +-
 libavfilter/qsvvpp.c | 139 +++-
 libavfilter/qsvvpp.h |  12 +-
 libavfilter/vf_deinterlace_qsv.c |  72 ---
 libavfilter/vf_scale_qsv.c   |  88 
 libavutil/hwcontext_opencl.c |   2 +-
 libavutil/hwcontext_qsv.c| 359 ++-
 libavutil/hwcontext_qsv.h|  18 +-
 19 files changed, 819 insertions(+), 188 deletions(-)

-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 01/10] configure: ensure --enable-libmfx uses libmfx 1.x

2021-08-16 Thread Haihao Xiang
Intel's oneVPL is a successor to MediaSDK, but removed some obsolete
features of MediaSDK[1]. Some early versions of oneVPL still uses libmfx
as library name[2], however some of obsolete features, including OPAQUE
memory, multi-frame encode, user plugins and LA_EXT rate control mode
etc, have been enabled in QSV, so user can not use --enable-libmfx to
enable QSV if using an early version of oneVPL SDK. In order to make
sure user builds FFmpeg against a right version of libmfx, this patch
added a check for the version of libmfx and warning message about the
used obsolete features.

[1] 
https://spec.oneapi.io/versions/latest/elements/oneVPL/source/appendix/VPL_intel_media_sdk.html
[2] https://github.com/oneapi-src/oneVPL
---
 configure | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index af8a934af9..4bdb8bac18 100755
--- a/configure
+++ b/configure
@@ -6436,8 +6436,11 @@ enabled liblensfun&& require_pkg_config 
liblensfun lensfun lensfun.h lf_
 # Media SDK or Intel Media Server Studio, these don't come with
 # pkg-config support.  Instead, users should make sure that the build
 # can find the libraries and headers through other means.
-enabled libmfx&& { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" 
MFXInit ||
-   { require libmfx "mfx/mfxvideo.h" MFXInit 
"-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
+enabled libmfx&& { { check_pkg_config libmfx "libmfx < 2.0" 
"mfx/mfxvideo.h" MFXInit ||
+ { require "libmfx < 2.0" "mfx/mfxvideo.h" 
MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without 
pkg-config"; } } &&
+   warn "build FFmpeg against libmfx 1.x, obsolete 
features of libmfx such as OPAQUE memory,\n"\
+"multi-frame encode, user plugins and 
LA_EXT rate control mode are enabled"; }
+
 if enabled libmfx; then
check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9"
 fi
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/qsvenc: allows the SDK runtime to choose LowPower/non-LowPower modes

2021-08-11 Thread Haihao Xiang
The SDK supports LowPower and non-LowPower modes, but some features are
available only under one of the two modes. Currently non-LowPower mode
is always chosen in FFmpeg if the mode is not set to LowPower
explicitly. User will experience some SDK errors if a LowPower related
feature is specified but the mode is not set to LowPower. With this
patch, the mode is set to unknown by default in FFmpeg, the SDK is able
to choose a workable mode for the specified features.
---
v2: update commit log and rebase the patch against the current master

 libavcodec/qsvenc.c | 6 --
 libavcodec/qsvenc.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index e7e65ebfcf..50ec7065ca 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -514,7 +514,7 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 }
 }
 
-if (q->low_power) {
+if (q->low_power == 1) {
 #if QSV_HAVE_VDENC
 q->param.mfx.LowPower = MFX_CODINGOPTION_ON;
 #else
@@ -523,7 +523,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->low_power = 0;
 q->param.mfx.LowPower = MFX_CODINGOPTION_OFF;
 #endif
-} else
+} else if (q->low_power == -1)
+q->param.mfx.LowPower = MFX_CODINGOPTION_UNKNOWN;
+else
 q->param.mfx.LowPower = MFX_CODINGOPTION_OFF;
 
 q->param.mfx.CodecProfile   = q->profile;
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index ba20b6f906..31516b8e55 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -96,7 +96,7 @@
 { "adaptive_b", "Adaptive B-frame placement", 
OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,  1, VE 
}, \
-{ "low_power", "enable low power mode(experimental: many limitations by mfx 
version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = 
0}, 0, 1, VE},\
+{ "low_power", "enable low power mode(experimental: many limitations by mfx 
version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = 
-1}, -1, 1, VE},\
 
 extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] ffmpeg_hw: Don't ignore key parameters when initializing a hw device

2021-08-11 Thread Haihao Xiang
Currently user may use '-init_hw_device type=name' to initialize a hw
device, however the key parameter is ignored when use '-init_hw_device
type=name,key=value'. After applying this patch, user may set key
parameter if needed.
---
 fftools/ffmpeg_hw.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index fc4a5d31d6..c55c459aa7 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -93,6 +93,8 @@ static char *hw_device_default_name(enum AVHWDeviceType type)
 
 int hw_device_init_from_string(const char *arg, HWDevice **dev_out)
 {
+// "type=name"
+// "type=name,key=value,key2=value2"
 // "type=name:device,key=value,key2=value2"
 // "type:device,key=value,key2=value2"
 // -> av_hwdevice_ctx_create()
@@ -124,7 +126,7 @@ int hw_device_init_from_string(const char *arg, HWDevice 
**dev_out)
 }
 
 if (*p == '=') {
-k = strcspn(p + 1, ":@");
+k = strcspn(p + 1, ":@,");
 
 name = av_strndup(p + 1, k);
 if (!name) {
@@ -190,6 +192,18 @@ int hw_device_init_from_string(const char *arg, HWDevice 
**dev_out)
  src->device_ref, 0);
 if (err < 0)
 goto fail;
+} else if (*p == ',') {
+err = av_dict_parse_string(, p + 1, "=", ",", 0);
+
+if (err < 0) {
+errmsg = "failed to parse options";
+goto invalid;
+}
+
+err = av_hwdevice_ctx_create(_ref, type,
+ NULL, options, 0);
+if (err < 0)
+goto fail;
 } else {
 errmsg = "parse error";
 goto invalid;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/2] doc/examples/qsvdec: simplify this example via hw_device_ctx interface

2021-08-11 Thread Haihao Xiang
---
 doc/examples/qsvdec.c | 45 +--
 1 file changed, 9 insertions(+), 36 deletions(-)

diff --git a/doc/examples/qsvdec.c b/doc/examples/qsvdec.c
index 7415eefca5..571d868f93 100644
--- a/doc/examples/qsvdec.c
+++ b/doc/examples/qsvdec.c
@@ -44,38 +44,10 @@
 #include "libavutil/hwcontext_qsv.h"
 #include "libavutil/mem.h"
 
-typedef struct DecodeContext {
-AVBufferRef *hw_device_ref;
-} DecodeContext;
-
 static int get_format(AVCodecContext *avctx, const enum AVPixelFormat 
*pix_fmts)
 {
 while (*pix_fmts != AV_PIX_FMT_NONE) {
 if (*pix_fmts == AV_PIX_FMT_QSV) {
-DecodeContext *decode = avctx->opaque;
-AVHWFramesContext  *frames_ctx;
-AVQSVFramesContext *frames_hwctx;
-int ret;
-
-/* create a pool of surfaces to be used by the decoder */
-avctx->hw_frames_ctx = av_hwframe_ctx_alloc(decode->hw_device_ref);
-if (!avctx->hw_frames_ctx)
-return AV_PIX_FMT_NONE;
-frames_ctx   = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
-frames_hwctx = frames_ctx->hwctx;
-
-frames_ctx->format= AV_PIX_FMT_QSV;
-frames_ctx->sw_format = avctx->sw_pix_fmt;
-frames_ctx->width = FFALIGN(avctx->coded_width,  32);
-frames_ctx->height= FFALIGN(avctx->coded_height, 32);
-frames_ctx->initial_pool_size = 32;
-
-frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
-
-ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
-if (ret < 0)
-return AV_PIX_FMT_NONE;
-
 return AV_PIX_FMT_QSV;
 }
 
@@ -87,7 +59,7 @@ static int get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *pix_fmts)
 return AV_PIX_FMT_NONE;
 }
 
-static int decode_packet(DecodeContext *decode, AVCodecContext *decoder_ctx,
+static int decode_packet(AVCodecContext *decoder_ctx,
  AVFrame *frame, AVFrame *sw_frame,
  AVPacket *pkt, AVIOContext *output_ctx)
 {
@@ -144,12 +116,12 @@ int main(int argc, char **argv)
 AVPacket pkt = { 0 };
 AVFrame *frame = NULL, *sw_frame = NULL;
 
-DecodeContext decode = { NULL };
-
 AVIOContext *output_ctx = NULL;
 
 int ret, i;
 
+AVBufferRef *device_ref = NULL;
+
 if (argc < 3) {
 fprintf(stderr, "Usage: %s  \n", argv[0]);
 return 1;
@@ -177,7 +149,7 @@ int main(int argc, char **argv)
 }
 
 /* open the hardware device */
-ret = av_hwdevice_ctx_create(_device_ref, AV_HWDEVICE_TYPE_QSV,
+ret = av_hwdevice_ctx_create(_ref, AV_HWDEVICE_TYPE_QSV,
  "auto", NULL, 0);
 if (ret < 0) {
 fprintf(stderr, "Cannot open the hardware device\n");
@@ -209,7 +181,8 @@ int main(int argc, char **argv)
 decoder_ctx->extradata_size = video_st->codecpar->extradata_size;
 }
 
-decoder_ctx->opaque  = 
+
+decoder_ctx->hw_device_ctx = av_buffer_ref(device_ref);
 decoder_ctx->get_format  = get_format;
 
 ret = avcodec_open2(decoder_ctx, NULL, NULL);
@@ -239,7 +212,7 @@ int main(int argc, char **argv)
 break;
 
 if (pkt.stream_index == video_st->index)
-ret = decode_packet(, decoder_ctx, frame, sw_frame, , 
output_ctx);
+ret = decode_packet(decoder_ctx, frame, sw_frame, , 
output_ctx);
 
 av_packet_unref();
 }
@@ -247,7 +220,7 @@ int main(int argc, char **argv)
 /* flush the decoder */
 pkt.data = NULL;
 pkt.size = 0;
-ret = decode_packet(, decoder_ctx, frame, sw_frame, , 
output_ctx);
+ret = decode_packet(decoder_ctx, frame, sw_frame, , output_ctx);
 
 finish:
 if (ret < 0) {
@@ -263,7 +236,7 @@ finish:
 
 avcodec_free_context(_ctx);
 
-av_buffer_unref(_device_ref);
+av_buffer_unref(_ref);
 
 avio_close(output_ctx);
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/2] qsvdec: add support for HW_DEVICE_CTX method

2021-08-11 Thread Haihao Xiang
This allows user set hw_device_ctx instead of hw_frames_ctx for QSV
decoders, hence we may remove the ad-hoc libmfx setup code from FFmpeg.

"-hwaccel_output_format format" is applied to QSV decoders after
removing the ad-hoc libmfx code. In order to keep compatibility with old
commandlines, the default format is set to AV_PIX_FMT_QSV, but this
behavior will be removed in the future. Please set "-hwaccel_output_format qsv"
explicitly if AV_PIX_FMT_QSV is expected.

The normal device stuff works for QSV decoders now, user may use
"-init_hw_device args" to initialise device and "-hwaccel_device
devicename" to select a device for QSV decoders.

"-qsv_device device" which was added for workarounding device selection
in the ad-hoc libmfx code still works

For example:

$> ffmpeg -init_hw_device qsv=qsv:hw_any,child_device=/dev/dri/card0
-hwaccel qsv -c:v h264_qsv -i input.h264  -f null -

/dev/dri/renderD128 is actually open for h264_qsv decoder in the above
command without this patch. After applying this patch, /dev/dri/card0
is used.

$> ffmpeg -init_hw_device vaapi=va:/dev/dri/card0 -init_hw_device
qsv=hw@va -hwaccel_device hw -hwaccel qsv -c:v h264_qsv -i input.h264
-f null -

device hw of type qsv is not usable in the above command without this
patch. After applying this patch, this command works as expected.
---
v3:
 Don't deprecate -qsv_device option
 Use single-shot device initialization to implement qsv_device option
 Update the commit log

 fftools/Makefile |   1 -
 fftools/ffmpeg.h |   1 -
 fftools/ffmpeg_hw.c  |  12 +
 fftools/ffmpeg_opt.c |  28 +--
 fftools/ffmpeg_qsv.c | 109 ---
 libavcodec/qsvdec.c  |  31 +++-
 6 files changed, 66 insertions(+), 116 deletions(-)
 delete mode 100644 fftools/ffmpeg_qsv.c

diff --git a/fftools/Makefile b/fftools/Makefile
index 5affaa3f56..5234932ab0 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -10,7 +10,6 @@ ALLAVPROGS   = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
 ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
 
 OBJS-ffmpeg+= fftools/ffmpeg_opt.o 
fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
-OBJS-ffmpeg-$(CONFIG_LIBMFX)   += fftools/ffmpeg_qsv.o
 ifndef CONFIG_VIDEOTOOLBOX
 OBJS-ffmpeg-$(CONFIG_VDA)  += fftools/ffmpeg_videotoolbox.o
 endif
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d9c0628657..d2dd7ca092 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -61,7 +61,6 @@ enum HWAccelID {
 HWACCEL_AUTO,
 HWACCEL_GENERIC,
 HWACCEL_VIDEOTOOLBOX,
-HWACCEL_QSV,
 };
 
 typedef struct HWAccel {
diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index fc4a5d31d6..6923c4c5a1 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -339,6 +339,18 @@ int hw_device_setup_for_decode(InputStream *ist)
 } else if (ist->hwaccel_id == HWACCEL_GENERIC) {
 type = ist->hwaccel_device_type;
 dev = hw_device_get_by_type(type);
+
+// When "-qsv_device device" is used, an internal QSV device named
+// as "__qsv_device" is created. Another QSV device is created too
+// if "-init_hw_device qsv=name:device" is used. There are 2 QSV 
devices
+// if both "-qsv_device device" and "-init_hw_device 
qsv=name:device"
+// are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns 
NULL.
+// To keep back-compatibility with the removed ad-hoc libmfx setup 
code,
+// call hw_device_get_by_name("__qsv_device") to select the 
internal QSV
+// device.
+if (!dev && type == AV_HWDEVICE_TYPE_QSV)
+dev = hw_device_get_by_name("__qsv_device");
+
 if (!dev)
 err = hw_device_init_from_type(type, NULL, );
 } else {
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 34cc6c4fd3..428934a3d8 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -137,9 +137,6 @@ static const char *const opt_name_enc_time_bases[]  
  = {"enc_time_base"
 const HWAccel hwaccels[] = {
 #if CONFIG_VIDEOTOOLBOX
 { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, 
AV_PIX_FMT_VIDEOTOOLBOX },
-#endif
-#if CONFIG_LIBMFX
-{ "qsv",   qsv_init,   HWACCEL_QSV,   AV_PIX_FMT_QSV },
 #endif
 { 0 },
 };
@@ -571,6 +568,23 @@ static int opt_vaapi_device(void *optctx, const char *opt, 
const char *arg)
 }
 #endif
 
+#if CONFIG_QSV
+static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
+{
+const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
+int err;
+char *tmp = av_asprintf("%s%s", prefix, arg);
+
+if (!tmp)
+return AVERROR(ENOMEM);
+
+err = hw_device_init_from_string(tmp, NULL);
+av_free(tmp);
+
+return err;
+}
+#endif
+
 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
 {
 if (!strcmp(arg, "list")) {
@@ -898,6 +912,12 @@ static void 

[FFmpeg-devel] [PATCH v2] avfilter: add QSV variants of the stack filters

2021-08-05 Thread Haihao Xiang
Include hstack_qsv, vstack_qsv and xstack_qsv, some code is copy and
pasted from other filters

Example:
$> ffmpeg -hwaccel qsv -c:v hevc_qsv -i input.h265 -filter_complex
"[0:v][0:v]hstack_qsv" -f null -
---
v2: fix wrong reference in filters.texi

 configure  |   6 +
 doc/filters.texi   |  81 ++
 libavfilter/Makefile   |   3 +
 libavfilter/allfilters.c   |   3 +
 libavfilter/vf_stack_qsv.c | 498 +
 5 files changed, 591 insertions(+)
 create mode 100644 libavfilter/vf_stack_qsv.c

diff --git a/configure b/configure
index f9fdf58bc3..96c95ac062 100755
--- a/configure
+++ b/configure
@@ -3696,6 +3696,12 @@ vpp_qsv_filter_select="qsvvpp"
 xfade_opencl_filter_deps="opencl"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
+hstack_qsv_filter_deps="libmfx"
+hstack_qsv_filter_select="qsvvpp"
+vstack_qsv_filter_deps="libmfx"
+vstack_qsv_filter_select="qsvvpp"
+xstack_qsv_filter_deps="libmfx"
+xstack_qsv_filter_select="qsvvpp"
 
 # examples
 avio_list_dir_deps="avformat avutil"
diff --git a/doc/filters.texi b/doc/filters.texi
index 790d165433..5d656a9351 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -13487,6 +13487,7 @@ Set the scaling dimension: @code{2} for @code{hq2x}, 
@code{3} for
 Default is @code{3}.
 @end table
 
+@anchor{hstack}
 @section hstack
 Stack input videos horizontally.
 
@@ -21861,6 +21862,7 @@ Example:
 ffmpeg -i ref.mpg -vf vmafmotion -f null -
 @end example
 
+@anchor{vstack}
 @section vstack
 Stack input videos vertically.
 
@@ -22307,6 +22309,7 @@ minimum values, and @code{1} maximum values.
 
 This filter supports all above options as @ref{commands}, excluding option 
@code{inputs}.
 
+@anchor{xstack}
 @section xstack
 Stack video inputs into custom layout.
 
@@ -24004,6 +24007,84 @@ tonemap_vaapi=format=p010:t=bt2020-10
 
 @c man end VAAPI VIDEO FILTERS
 
+@chapter QSV Video Filters
+@c man begin QSV VIDEO FILTERS
+
+Below is a description of the currently available QSV video filters.
+
+To enable compilation of these filters you need to configure FFmpeg with
+@code{--enable-libmfx}.
+
+To use QSV filters, you need to setup the QSV device correctly. For more 
information, please read @url{https://trac.ffmpeg.org/wiki/Hardware/QuickSync}
+
+@section hstack_qsv
+Stack input videos horizontally.
+
+This is the QSV variant of the @ref{hstack} filter.
+
+It accepts the following options:
+
+@table @option
+@item inputs
+Set number of input streams. Allowed range is from 2 to 72.
+Default value is 2.
+
+@item shortest
+See @ref{hstack}.
+
+@item scale
+Set factor to zoom in or out all videos. Allowed range is from 0.125 to 8.
+Default value is 1.
+@end table
+
+@section vstack_qsv
+Stack input videos vertically.
+
+This is the QSV variant of the @ref{vstack} filter.
+
+It accepts the following options:
+
+@table @option
+@item inputs
+Set number of input streams. Allowed range is from 2 to 72.
+Default value is 2.
+
+@item shortest
+See @ref{vstack}.
+
+@item scale
+Set factor to zoom in or out all videos. Allowed range is from 0.125 to 8.
+Default value is 1.
+@end table
+
+@section xstack_qsv
+Stack video inputs into custom layout.
+
+This is the QSV variant of the @ref{xstack} filter.
+
+It accepts the following options:
+
+@table @option
+@item inputs
+Set number of input streams. Allowed range is from 2 to 72.
+Default value is 2.
+
+@item shortest
+See @ref{xstack}.
+
+@item scale
+Set factor to zoom in or out all videos. Allowed range is from 0.125 to 8.
+Default value is 1.
+
+@item layout
+See @ref{xstack}.
+
+@item fill
+See @ref{xstack}.
+@end table
+
+@c man end QSV VIDEO FILTERS
+
 @chapter Video Sources
 @c man begin VIDEO SOURCES
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 49c0c8342b..03e8558635 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -496,6 +496,9 @@ OBJS-$(CONFIG_YAEPBLUR_FILTER)   += 
vf_yaepblur.o
 OBJS-$(CONFIG_ZMQ_FILTER)+= f_zmq.o
 OBJS-$(CONFIG_ZOOMPAN_FILTER)+= vf_zoompan.o
 OBJS-$(CONFIG_ZSCALE_FILTER) += vf_zscale.o
+OBJS-$(CONFIG_HSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
+OBJS-$(CONFIG_VSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
+OBJS-$(CONFIG_XSTACK_QSV_FILTER) += vf_stack_qsv.o framesync.o
 
 OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o
 OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index ae74f9c891..16bc0c6429 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -472,6 +472,9 @@ extern const AVFilter ff_vf_yaepblur;
 extern const AVFilter ff_vf_zmq;
 extern const AVFilter ff_vf_zoompan;
 extern const AVFilter ff_vf_zscale;
+extern const AVFilter ff_vf_hstack_qsv;
+extern const AVFilter ff_vf_vstack_qsv;
+extern const AVFilter ff_vf_xstack_qsv;
 
 extern const AVFilter 

[FFmpeg-devel] [PATCH] lavc/qsvenc_hevc: add -pic_timing_sei option

2021-08-05 Thread Haihao Xiang
The SDK may insert picture timing SEI for hevc and the code to set mfx
parameter has been added in qsvenc, however the corresponding option is
missing in the hevc option array
---
 libavcodec/qsvenc_hevc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index b7b2f5633e..1e31968673 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -248,6 +248,7 @@ static const AVOption options[] = {
 { "tile_rows",  "Number of rows for tiled encoding",  
OFFSET(qsv.tile_rows),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
 { "recovery_point_sei", "Insert recovery point SEI messages",   
OFFSET(qsv.recovery_point_sei),  AV_OPT_TYPE_INT, { .i64 = -1 },
   -1,  1, VE },
 { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE},
+{ "pic_timing_sei","Insert picture timing SEI with pic_struct_syntax 
element", OFFSET(qsv.pic_timing_sei), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
 
 { NULL },
 };
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 20/20] lavfi/deinterlace_qsv: add more input / output pixel formats

2021-08-05 Thread Haihao Xiang
NV12 is added in system memory and the command below may work now.

$ ffmpeg -init_hw_device qsv -c:v h264_qsv -i input.h264 -vf
deinterlace_qsv -f null -
---
 libavfilter/vf_vpp_qsv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index edd10f5af6..619d530745 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -737,7 +737,9 @@ static const AVOption qsvdeint_options[] = {
 static int qsvdeint_query_formats(AVFilterContext *ctx)
 {
 static const enum AVPixelFormat pixel_formats[] = {
-AV_PIX_FMT_QSV, AV_PIX_FMT_NONE,
+AV_PIX_FMT_NV12,
+AV_PIX_FMT_QSV,
+AV_PIX_FMT_NONE,
 };
 AVFilterFormats *pix_fmts  = ff_make_format_list(pixel_formats);
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 16/20] lavfi/vpp_qsv: check output format string against NULL pointer

2021-08-05 Thread Haihao Xiang
This is in preparation for re-using VPPContext but with a different
option array for deinterlacing_qsv filter
---
 libavfilter/vf_vpp_qsv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 3eddefea31..f7854f81bf 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -234,7 +234,7 @@ static av_cold int vpp_init(AVFilterContext *ctx)
 {
 VPPContext  *vpp  = ctx->priv;
 
-if (!strcmp(vpp->output_format_str, "same")) {
+if (!vpp->output_format_str || !strcmp(vpp->output_format_str, "same")) {
 vpp->out_format = AV_PIX_FMT_NONE;
 } else {
 vpp->out_format = av_get_pix_fmt(vpp->output_format_str);
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 18/20] lavfi/deinterlace_qsv: re-use VPPContext for deinterlace_qsv filter

2021-08-05 Thread Haihao Xiang
All features are implemented in vpp_qsv filter now, so deinterlace_qsv
can be taken as a specical case of vpp_qsv filter, we re-use VPPContext
with a different option array and pix formats for deinterlace_qsv filter

A new option -rate is used to control the output frame rate, by default
it will output frame for each field
---
 libavfilter/Makefile |   2 +-
 libavfilter/vf_deinterlace_qsv.c | 179 ---
 libavfilter/vf_vpp_qsv.c |  35 +-
 3 files changed, 35 insertions(+), 181 deletions(-)
 delete mode 100644 libavfilter/vf_deinterlace_qsv.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 760099ba2c..dafd0c610c 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -230,7 +230,7 @@ OBJS-$(CONFIG_DECONVOLVE_FILTER) += 
vf_convolve.o framesync.o
 OBJS-$(CONFIG_DEDOT_FILTER)  += vf_dedot.o
 OBJS-$(CONFIG_DEFLATE_FILTER)+= vf_neighbor.o
 OBJS-$(CONFIG_DEFLICKER_FILTER)  += vf_deflicker.o
-OBJS-$(CONFIG_DEINTERLACE_QSV_FILTER)+= vf_deinterlace_qsv.o
+OBJS-$(CONFIG_DEINTERLACE_QSV_FILTER)+= vf_vpp_qsv.o
 OBJS-$(CONFIG_DEINTERLACE_VAAPI_FILTER)  += vf_deinterlace_vaapi.o 
vaapi_vpp.o
 OBJS-$(CONFIG_DEJUDDER_FILTER)   += vf_dejudder.o
 OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o
diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
deleted file mode 100644
index 50ff553e6a..00
--- a/libavfilter/vf_deinterlace_qsv.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * deinterlace video filter - QSV
- */
-
-#include 
-
-#include 
-#include 
-
-#include "libavutil/avstring.h"
-#include "libavutil/common.h"
-#include "libavutil/hwcontext.h"
-#include "libavutil/hwcontext_qsv.h"
-#include "libavutil/internal.h"
-#include "libavutil/mathematics.h"
-#include "libavutil/opt.h"
-#include "libavutil/pixdesc.h"
-#include "libavutil/time.h"
-#include "libavfilter/qsvvpp.h"
-
-#include "avfilter.h"
-#include "formats.h"
-#include "internal.h"
-#include "video.h"
-
-typedef struct QSVDeintContext {
-QSVVPPContext qsv;
-
-mfxExtVPPDeinterlacing deint_conf;
-
-/* option for Deinterlacing algorithm to be used */
-int mode;
-} QSVDeintContext;
-
-static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
-{
-ff_qsvvpp_close(ctx);
-}
-
-static int qsvdeint_query_formats(AVFilterContext *ctx)
-{
-static const enum AVPixelFormat pixel_formats[] = {
-AV_PIX_FMT_QSV, AV_PIX_FMT_NONE,
-};
-AVFilterFormats *pix_fmts  = ff_make_format_list(pixel_formats);
-int ret;
-
-if ((ret = ff_set_common_formats(ctx, pix_fmts)) < 0)
-return ret;
-
-return 0;
-}
-
-static int qsvdeint_config_props(AVFilterLink *outlink)
-{
-AVFilterContext *ctx = outlink->src;
-AVFilterLink *inlink = ctx->inputs[0];
-QSVDeintContext   *s = ctx->priv;
-QSVVPPParamparam = { NULL };
-mfxExtBuffer *ext_buf[1];
-enum AVPixelFormat in_format;
-
-qsvdeint_uninit(ctx);
-
-outlink->w  = inlink->w;
-outlink->h  = inlink->h;
-outlink->frame_rate = av_mul_q(inlink->frame_rate,
-   (AVRational){ 2, 1 });
-outlink->time_base  = av_mul_q(inlink->time_base,
-   (AVRational){ 1, 2 });
-
-if (inlink->format == AV_PIX_FMT_QSV) {
-if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)
-return AVERROR(EINVAL);
-else
-in_format = 
((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format;
-} else
-in_format = inlink->format;
-
-param.out_sw_format = in_format;
-param.ext_buf   = ext_buf;
-
-memset(>deint_conf, 0, sizeof(mfxExtVPPDeinterlacing));
-s->deint_conf.Header.BufferId  = MFX_EXTBUFF_VPP_DEINTERLACING;
-s->deint_conf.Header.BufferSz  = sizeof(s->deint_conf);
-s->deint_conf.Mode = s->mode;
-param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)>deint_conf;
-
-return ff_qsvvpp_init(ctx, );
-}
-
-static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
-{
-AVFilterContext  *ctx = link->dst;
-

[FFmpeg-devel] [PATCH v5 19/20] lavfi/deinterlace_qsv: add async_depth option

2021-08-05 Thread Haihao Xiang
Allow user to set async depth for deinterlace_qsv
---
 libavfilter/vf_vpp_qsv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 518595d91e..edd10f5af6 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -730,6 +730,7 @@ static const AVOption qsvdeint_options[] = {
 { "field", "Output at field rate (one frame of output for each field)",
   0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "rate" },
 
+{ "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 
0, INT_MAX, .flags = FLAGS },
 { NULL },
 };
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 17/20] lavfi/deinterlace_qsv: simplify deinterlace_qsv filter

2021-08-05 Thread Haihao Xiang
Like what we did for scale_qsv filter, we use QSVVPPContext as a base
context to manage MFX session for deinterlace_qsv filter
---
 libavfilter/vf_deinterlace_qsv.c | 492 ++-
 1 file changed, 30 insertions(+), 462 deletions(-)

diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 3c2d87c7c8..50ff553e6a 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -42,34 +42,10 @@
 #include "internal.h"
 #include "video.h"
 
-enum {
-QSVDEINT_MORE_OUTPUT = 1,
-QSVDEINT_MORE_INPUT,
-};
-
 typedef struct QSVDeintContext {
-const AVClass *class;
-
-AVBufferRef *hw_frames_ctx;
-/* a clone of the main session, used internally for deinterlacing */
-mfxSession   session;
-
-mfxMemId *mem_ids;
-intnb_mem_ids;
-
-mfxFrameSurface1 **surface_ptrs;
-int nb_surface_ptrs;
+QSVVPPContext qsv;
 
-mfxExtOpaqueSurfaceAlloc opaque_alloc;
-mfxExtVPPDeinterlacing   deint_conf;
-mfxExtBuffer*ext_buffers[2];
-int  num_ext_buffers;
-
-QSVFrame *work_frames;
-
-int64_t last_pts;
-
-int eof;
+mfxExtVPPDeinterlacing deint_conf;
 
 /* option for Deinterlacing algorithm to be used */
 int mode;
@@ -77,28 +53,7 @@ typedef struct QSVDeintContext {
 
 static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
 {
-QSVDeintContext *s = ctx->priv;
-QSVFrame *cur;
-
-if (s->session) {
-MFXClose(s->session);
-s->session = NULL;
-}
-av_buffer_unref(>hw_frames_ctx);
-
-cur = s->work_frames;
-while (cur) {
-s->work_frames = cur->next;
-av_frame_free(>frame);
-av_freep();
-cur = s->work_frames;
-}
-
-av_freep(>mem_ids);
-s->nb_mem_ids = 0;
-
-av_freep(>surface_ptrs);
-s->nb_surface_ptrs = 0;
+ff_qsvvpp_close(ctx);
 }
 
 static int qsvdeint_query_formats(AVFilterContext *ctx)
@@ -115,441 +70,54 @@ static int qsvdeint_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
-static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
- mfxFrameAllocResponse *resp)
-{
-AVFilterContext *ctx = pthis;
-QSVDeintContext   *s = ctx->priv;
-
-if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
-!(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
-!(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
-return MFX_ERR_UNSUPPORTED;
-
-resp->mids   = s->mem_ids;
-resp->NumFrameActual = s->nb_mem_ids;
-
-return MFX_ERR_NONE;
-}
-
-static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
-{
-return MFX_ERR_NONE;
-}
-
-static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
-{
-return MFX_ERR_UNSUPPORTED;
-}
-
-static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
-{
-return MFX_ERR_UNSUPPORTED;
-}
-
-static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
-{
-*hdl = mid;
-return MFX_ERR_NONE;
-}
-
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
-static int init_out_session(AVFilterContext *ctx)
-{
-
-QSVDeintContext  *s = ctx->priv;
-AVHWFramesContext*hw_frames_ctx = 
(AVHWFramesContext*)s->hw_frames_ctx->data;
-AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
-AVQSVDeviceContext*device_hwctx = hw_frames_ctx->device_ctx->hwctx;
-
-int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
-
-mfxHDL handle = NULL;
-mfxHandleType handle_type;
-mfxVersion ver;
-mfxIMPL impl;
-mfxVideoParam par;
-mfxStatus err;
-int i;
-
-/* extract the properties of the "master" session given to us */
-err = MFXQueryIMPL(device_hwctx->session, );
-if (err == MFX_ERR_NONE)
-err = MFXQueryVersion(device_hwctx->session, );
-if (err != MFX_ERR_NONE) {
-av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
-return AVERROR_UNKNOWN;
-}
-
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
-}
-
-if (err < 0)
-return ff_qsvvpp_print_error(ctx, err, "Error getting the session 
handle");
-else if (err > 0) {
-ff_qsvvpp_print_warning(ctx, err, "Warning in getting the session 
handle");
-return AVERROR_UNKNOWN;
-}
-
-/* create a "slave" session with those same properties, to be used for
- * actual deinterlacing */
-err = MFXInit(impl, , >session);
-if (err < 0)
-return ff_qsvvpp_print_error(ctx, err, "Error initializing a session 
for deinterlacing");
-else if (err > 0) 

[FFmpeg-devel] [PATCH v5 15/20] lavfi/qsvvpp: set PTS for output frame

2021-08-05 Thread Haihao Xiang
When the SDK returns MFX_ERR_MORE_SURFACE, the PTS is not set for the
output frame. We assign a PTS calculated from the input frame to the
output frame. After applying this patch, we may avoid the error below:

[null @ 0x56395cab4ae0] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 456 >= 0

Note this patch only fixes PTS issue when deinterlacing is enabled
---
 libavfilter/qsvvpp.c | 21 +++--
 libavfilter/qsvvpp.h |  3 +++
 libavfilter/vf_vpp_qsv.c |  2 ++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 82a8e29387..01d9d754d3 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -653,6 +653,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam 
*param)
 int ret;
 QSVVPPContext *s = avctx->priv;
 
+s->last_in_pts   = AV_NOPTS_VALUE;
 s->filter_frame  = param->filter_frame;
 if (!s->filter_frame)
 s->filter_frame = ff_filter_frame;
@@ -769,6 +770,8 @@ int ff_qsvvpp_close(AVFilterContext *avctx)
 s->session = NULL;
 }
 
+s->last_in_pts = AV_NOPTS_VALUE;
+
 /* release all the resources */
 clear_frame_list(>in_frame_list);
 clear_frame_list(>out_frame_list);
@@ -788,6 +791,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 mfxSyncPoint  sync;
 QSVFrame *in_frame, *out_frame, *tmp;
 int   ret, ret1, filter_ret;
+int64_t   dpts = 0;
 
 while (s->eof && qsv_fifo_size(s->async_fifo)) {
 av_fifo_generic_read(s->async_fifo, , sizeof(tmp), NULL);
@@ -836,8 +840,19 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 ret = AVERROR(EAGAIN);
 break;
 }
-out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
- default_tb, outlink->time_base);
+
+/* TODO: calculate the PTS for other cases */
+if (s->deinterlace_enabled &&
+s->last_in_pts != AV_NOPTS_VALUE &&
+ret == MFX_ERR_MORE_SURFACE &&
+out_frame->surface.Data.TimeStamp == MFX_TIMESTAMP_UNKNOWN)
+dpts = (in_frame->frame->pts - s->last_in_pts) / 2;
+else
+dpts = 0;
+
+out_frame->frame->pts = av_rescale_q(in_frame->frame->pts - dpts,
+ inlink->time_base,
+ outlink->time_base);
 
 out_frame->queued++;
 av_fifo_generic_write(s->async_fifo, _frame, sizeof(out_frame), 
NULL);
@@ -870,5 +885,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 }
 } while(ret == MFX_ERR_MORE_SURFACE);
 
+s->last_in_pts = in_frame->frame->pts;
+
 return ret;
 }
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index b6fe0d3fa7..8627c8c868 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -74,8 +74,11 @@ typedef struct QSVVPPContext {
 int got_frame;
 int async_depth;
 int eof;
+int deinterlace_enabled;
 /** order with frame_out, sync */
 AVFifoBuffer *async_fifo;
+
+int64_t last_in_pts;
 } QSVVPPContext;
 
 typedef struct QSVVPPCrop {
diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index c642d4e2a4..3eddefea31 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -364,6 +364,8 @@ static int config_output(AVFilterLink *outlink)
 vpp->extbuf.field = value; \
 } while (0)
 
+vpp->qsv.deinterlace_enabled = !!vpp->deinterlace;
+
 if (vpp->deinterlace) {
 INIT_MFX_EXTBUF(deinterlace_conf, MFX_EXTBUFF_VPP_DEINTERLACING);
 SET_MFX_PARAM_FIELD(deinterlace_conf, Mode, (vpp->deinterlace == 1 ?
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 14/20] lavfi/qsvvpp: avoid overriding the returned value

2021-08-05 Thread Haihao Xiang
Currently the returned value from MFXVideoVPP_RunFrameVPPAsync() is
overridden, so the check of 'ret == MFX_ERR_MORE_SURFACE' is always
false when MFX_ERR_MORE_SURFACE is returned from
MFXVideoVPP_RunFrameVPPAsync()
---
 libavfilter/qsvvpp.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 5b0b30e23c..82a8e29387 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -787,7 +787,7 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 AVFilterLink *outlink = ctx->outputs[0];
 mfxSyncPoint  sync;
 QSVFrame *in_frame, *out_frame, *tmp;
-int   ret, filter_ret;
+int   ret, ret1, filter_ret;
 
 while (s->eof && qsv_fifo_size(s->async_fifo)) {
 av_fifo_generic_read(s->async_fifo, , sizeof(tmp), NULL);
@@ -849,8 +849,13 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 av_fifo_generic_read(s->async_fifo, , sizeof(sync), NULL);
 
 do {
-ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
-} while (ret == MFX_WRN_IN_EXECUTION);
+ret1 = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
+} while (ret1 == MFX_WRN_IN_EXECUTION);
+
+if (ret1 < 0) {
+ret = ret1;
+break;
+}
 
 filter_ret = s->filter_frame(outlink, tmp->frame);
 if (filter_ret < 0) {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


  1   2   3   >