Re: [FFmpeg-devel] mediacodec and qsv not really hwaccels ?

2024-09-23 Thread Xiang, Haihao
On Di, 2024-09-24 at 00:53 +0300, Andrew Randrianasulu wrote:
> I tried to trivially add qsv/mediacodec decode to cinelerra-gg, but
> discovered that I can't use it like vaapi/vdpau/cuda because (?)
> qsv/mediacodec not listed in
> 
> ffmpeg/libavcodec/hwconfig.h
> and (for h264) in
> ffmpeg/libavcodec/h264dec.c
> 
> so on decoding I get (in termux, cingg compiled with system ffmpeg)
> 
> 
> Decoder h264 does not support device type mediacodec.
> 
> HW device init failed, using SW decode.
> file:/data/data/com.termux/files/home/20210419_055507A.mp4
> err: Operation not permitted
> 
> yet ffmpeg -hwaccel show
> 
> ~/cinelerra/cinelerra-5.1 $ ffmpeg -hwaccels
> 
>  ffmpeg version 6.1.2 Copyright (c) 2000-2024 the FFmpeg developers
> 
> built with Android (12027248, +pgo, +bolt, +lto, +mlgo, based on r522817)
> clang version 18.0.1 (
> https://android.googlesource.com/toolchain/llvm-project
> d8003a456d14a3deb8054cdaa529ffbf02d9b262) configuration: --arch=aarch64
> --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang
> --cxx=aarch64-linux-android-clang++ --nm=llvm-nm
> --pkg-config=/home/builder/.termux-build/_cache/android-r27-api-24-v1/bin/pkg-
> config
> --strip=llvm-strip --cross-prefix=aarch64-linux-android- --disable-indevs
> --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver
> --enable-cross-compile --enable-gnutls --enable-gpl --enable-version3
> --enable-jni --enable-lcms2 --enable-libaom --enable-libass
> --enable-libbluray --enable-libdav1d --enable-libfontconfig
> --enable-libfreetype --enable-libfribidi --enable-libgme
> --enable-libharfbuzz --enable-libmp3lame --enable-libopencore-amrnb
> --enable-libopencore-amrwb --enable-libopenmpt --enable-libopus
> --enable-librav1e --enable-libsoxr --enable-libsrt --enable-libssh
> --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab
> --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
> --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
> --enable-libxvid --enable-libzimg --enable-mediacodec --enable-opencl
> --enable-shared --prefix=/data/data/com.termux/files/usr
> --target-os=android --extra-libs=-landroid-glob --disable-vulkan
> --enable-neon --disable-libfdk-aac   libavutil  58.
> 29.100 / 58. 29.100
> 
> libavcodec 60. 31.102 / 60. 31.102
> 
> libavformat    60. 16.100 / 60. 16.100
> 
>  libavdevice    60.  3.100 / 60.  3.100
> 
> libavfilter 9. 12.100 /  9. 12.100
> 
> libswscale  7.  5.100 /  7.  5.100
> 
> libswresample   4. 12.100 /  4. 12.100
> 
> libpostproc    57.  3.100 / 57.  3.100
> 
> Hardware acceleration methods:
> opencl
>     mediacodec
> 
> ===
> 
> is it oversight or some more fundamental limitation?


vaapi/cuda/vdpau is used to accelerate the native decoders in FFmpeg, however
for mediacodec/qsv, there are corresponding decoders. 

For example, both qsv and vaapi are enabled when running configuration, you may
get all supported qsv decoders with the command below:
$ ffmpeg -decoders 2>/dev/null | grep qsv
 VD av1_qsv  AV1 video (Intel Quick Sync Video acceleration) 
(codec av1)
 VD h264_qsv H264 video (Intel Quick Sync Video acceleration) 
(codec h264)
 VD hevc_qsv HEVC video (Intel Quick Sync Video acceleration) 
(codec hevc)
 VD mjpeg_qsvMJPEG video (Intel Quick Sync Video acceleration) 
(codec mjpeg)
 VD mpeg2_qsvMPEG2VIDEO video (Intel Quick Sync Video 
acceleration) (codec mpeg2video)
 VD vc1_qsv  VC1 video (Intel Quick Sync Video acceleration) 
(codec vc1)
 VD vp8_qsv  VP8 video (Intel Quick Sync Video acceleration) 
(codec vp8)
 VD vp9_qsv  VP9 video (Intel Quick Sync Video acceleration) 
(codec vp9)

However for vaapi, you will get nothing,

$ ffmpeg -decoders 2>/dev/null | grep vaapi

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h265: fix missing slice_block_cols assignment

2024-09-19 Thread Xiang, Haihao
On Vr, 2024-09-20 at 01:12 +, Wang, Fei W wrote:
> On Thu, 2024-09-19 at 20:01 +0200, Marvin Scholz wrote:
> > Instead of assigning to unit_opts.slice_block_cols, the
> > slice_block_cols
> > value from the context was incorrectly assigned to slice_block_rows.
> > 
> > Regression from 12f158ca8f2ecc172f27569af88426d0e39ce995
> > 
> > Fixes CID1619479 Unused value
> > ---
> >  libavcodec/vaapi_encode_h265.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/vaapi_encode_h265.c
> > b/libavcodec/vaapi_encode_h265.c
> > index f4a9003c823..2283bcc0b4d 100644
> > --- a/libavcodec/vaapi_encode_h265.c
> > +++ b/libavcodec/vaapi_encode_h265.c
> > @@ -273,11 +273,11 @@ static int
> > vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
> >  priv->unit_opts.cu_qp_delta_enabled_flag = (ctx->va_rc_mode !=
> > VA_RC_CQP);
> >  priv->unit_opts.tile_rows = ctx->tile_rows;
> >  priv->unit_opts.tile_cols = ctx->tile_cols;
> >  priv->unit_opts.nb_slices = ctx->nb_slices;
> >  priv->unit_opts.slice_block_rows = ctx->slice_block_rows;
> > -    priv->unit_opts.slice_block_rows = ctx->slice_block_cols;
> > +    priv->unit_opts.slice_block_cols = ctx->slice_block_cols;
> 
> LGTM.
> 
> Thanks
> Fei
> 
> >  memcpy(priv->unit_opts.col_width, ctx->col_width,
> >     ctx->tile_rows*sizeof(*priv->unit_opts.col_width));
> >  memcpy(priv->unit_opts.row_height, ctx->row_height,
> >     ctx->tile_cols*sizeof(*priv->unit_opts.row_height));
> >  
> > 
> > base-commit: dc11c12b6466795f5f9eb057b1aebd76bf129785


Applied, thx

- Haihao

> 
> ___
> 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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode_av1: Fix encode fail since 9db68ed0

2024-09-18 Thread Xiang, Haihao
On Vr, 2024-09-13 at 10:45 +0200, Lynne via ffmpeg-devel wrote:
> On 13/09/2024 05:15, fei.w.wang-at-intel@ffmpeg.org wrote:
> > From: Fei Wang 
> > 
> > Signed-off-by: Fei Wang 
> > ---
> >   libavcodec/vaapi_encode_av1.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
> > index 6d1be9fc07..1b350cd936 100644
> > --- a/libavcodec/vaapi_encode_av1.c
> > +++ b/libavcodec/vaapi_encode_av1.c
> > @@ -637,7 +637,7 @@ static int
> > vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
> >   slot = ((VAAPIEncodeAV1Picture*)ref_pic->codec_priv)->slot;
> >   av_assert0(vpic->reference_frames[slot] ==
> > VA_INVALID_SURFACE);
> >   
> > -    vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic)-
> > >recon_surface;
> > +    vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic-
> > >priv)->recon_surface;
> >   }
> >   }
> >   
> 
> LGTM
> thanks

Will apply,

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: Fix potential use of uninitialized value

2024-09-18 Thread Xiang, Haihao
On Wo, 2024-09-11 at 09:37 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_encode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 0058e1e772..16a9a364f0 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -273,7 +273,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
>  VAAPIEncodePicture *pic = base_pic->priv;
>  VAAPIEncodeSlice *slice;
>  VAStatus vas;
> -    int err, i;
> +    int err = 0, i;
>  char data[MAX_PARAM_BUFFER_SIZE];
>  size_t bit_len;
>  av_unused AVFrameSideData *sd;

LGTM, will apply,

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH 1/2] doc/av1_qsv: Fix typo

2024-08-27 Thread Xiang, Haihao
On Ma, 2024-08-26 at 09:40 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  doc/encoders.texi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 496852faeb..1035be0052 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -4105,7 +4105,7 @@ Setting this flag turns on or off LowDelayBRC feautre in
> qsv plugin, which provi
>  more accurate bitrate control to minimize the variance of bitstream size
> frame
>  by frame. Value: -1-default 0-off 1-on
>  
> -@item max_frame_size
> +@item @var{max_frame_size}
>  Set the allowed max size in bytes for each frame. If the frame size exceeds
>  the limitation, encoder will adjust the QP value to control the frame size.
>  Invalid in CQP rate control mode.

Patchset LGTM, will apply,

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: Remove duplicate include header file

2024-08-27 Thread Xiang, Haihao
On Ma, 2024-08-26 at 09:41 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/qsvenc.h | 2 --
>  libavcodec/qsvenc_av1.c | 2 --
>  2 files changed, 4 deletions(-)
> 
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index e3eb083746..4bc77f2f7c 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -26,8 +26,6 @@
>  #include 
>  #include 
>  
> -#include 
> -
>  #include "libavutil/common.h"
>  #include "libavutil/hwcontext.h"
>  #include "libavutil/hwcontext_qsv.h"
> diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
> index 56002746b9..f7505a69f8 100644
> --- a/libavcodec/qsvenc_av1.c
> +++ b/libavcodec/qsvenc_av1.c
> @@ -22,8 +22,6 @@
>  #include 
>  #include 
>  
> -#include 
> -
>  #include "libavutil/common.h"
>  #include "libavutil/mastering_display_metadata.h"
>  #include "libavutil/mem.h"

Will apply

Thanks
Haihao




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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/qsvdec: Add vvc_mp4toannexb bsf for QSV VVC decoder

2024-08-15 Thread Xiang, Haihao
On Do, 2024-08-15 at 10:19 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Fix error:
> $ ffmpeg -hwaccel qsv -i input.mp4 -f null -
> ..
> [vvc_qsv @ 026890D966C0] Error decoding stream header: unknown error (-1)
> [vvc_qsv @ 026890D966C0] Error decoding header
> 
> Signed-off-by: Fei Wang 
> ---
>  configure   | 2 +-
>  libavcodec/qsvdec.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 37178d7d81..ad82bc2d1f 100755
> --- a/configure
> +++ b/configure
> @@ -3427,7 +3427,7 @@ vp9_vaapi_encoder_select="vaapi_encode"
>  vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
>  vp9_qsv_encoder_select="qsvenc"
>  vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m"
> -vvc_qsv_decoder_select="qsvdec"
> +vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec"
>  
>  # parsers
>  aac_parser_select="adts_header mpeg4audio"
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 9ad3439991..039ba62484 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -1303,5 +1303,5 @@ DEFINE_QSV_DECODER(av1, AV1, NULL)
>  #endif
>  
>  #if CONFIG_VVC_QSV_DECODER
> -DEFINE_QSV_DECODER(vvc, VVC, NULL)
> +DEFINE_QSV_DECODER(vvc, VVC, "vvc_mp4toannexb")
>  #endif

Pushed, 

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH] lavc/qsvdec: Add vvc_mp4toannexb bsf for QSV VVC decoder

2024-08-13 Thread Xiang, Haihao
On Di, 2024-08-13 at 16:01 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Fix error:
> $ ffmpeg -hwaccel qsv -i input.mp4 -f null -
> ..
> [vvc_qsv @ 026890D966C0] Error decoding stream header: unknown error (-1)
> [vvc_qsv @ 026890D966C0] Error decoding header
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/qsvdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 9ad3439991..039ba62484 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -1303,5 +1303,5 @@ DEFINE_QSV_DECODER(av1, AV1, NULL)
>  #endif
>  
>  #if CONFIG_VVC_QSV_DECODER
> -DEFINE_QSV_DECODER(vvc, VVC, NULL)
> +DEFINE_QSV_DECODER(vvc, VVC, "vvc_mp4toannexb")
>  #endif

Please update vvc_qsv_decoder_select in configure too. 

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add option to allow to specify vendor id when init hw device

2024-08-09 Thread Xiang, Haihao
On Ma, 2024-08-05 at 02:14 +, Xiang, Haihao wrote:
> On Vr, 2024-07-26 at 09:05 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> > From: Fei Wang 
> > 
> > Vendor id will help to select desired device in case of kernel driver is
> > unknow or unsupported, for vendor may support different kernel driver on
> > different platforms.
> > 
> > Signed-off-by: Fei Wang 
> > ---
> >  doc/ffmpeg.texi |  8 
> >  libavutil/hwcontext_vaapi.c | 29 +
> >  libavutil/version.h |  2 +-
> >  3 files changed, 38 insertions(+), 1 deletion(-)
> > 
> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > index 877edae3b3..842e92ad1a 100644
> > --- a/doc/ffmpeg.texi
> > +++ b/doc/ffmpeg.texi
> > @@ -1458,6 +1458,11 @@ The following options are recognized:
> >  When @var{device} is not specified, use this option to specify the name of
> > the kernel
> >  driver associated with the desired device. This option is available only
> > when
> >  the hardware acceleration method @emph{drm} and @emph{vaapi} are enabled.
> > +@item vendor_id
> > +When @var{device} and @var{kernel_driver} are not specified, use this
> > option
> > to specify
> > +the vendor id associated with the desired device. This option is available
> > only when the
> > +hardware acceleration method @emph{drm} and @emph{vaapi} are enabled and
> > @emph{kernel_driver}
> > +is not specified.
> >  @end table
> >  
> >  Examples:
> > @@ -1473,6 +1478,9 @@ Create a vaapi device on DirectX adapter 1.
> >  
> >  @item -init_hw_device vaapi:,kernel_driver=i915
> >  Create a vaapi device on a device associated with kernel driver
> > @samp{i915}.
> > +
> > +@item -init_hw_device vaapi:,vendor_id=0x8086
> > +Create a vaapi device on a device associated with vendor id @samp{0x8086}.
> >  @end table
> >  
> >  @item vdpau
> > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> > index 4cb25dd032..014541752a 100644
> > --- a/libavutil/hwcontext_vaapi.c
> > +++ b/libavutil/hwcontext_vaapi.c
> > @@ -1748,7 +1748,9 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> > const char *device,
> >  #if CONFIG_LIBDRM
> >  drmVersion *info;
> >  const AVDictionaryEntry *kernel_driver;
> > +    const AVDictionaryEntry *vendor_id;
> >  kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0);
> > +    vendor_id = av_dict_get(opts, "vendor_id", NULL, 0);
> >  #endif
> >  for (n = 0; n < max_devices; n++) {
> >  snprintf(path, sizeof(path),
> > @@ -1803,6 +1805,33 @@ static int vaapi_device_create(AVHWDeviceContext
> > *ctx,
> > const char *device,
> >  close(priv->drm_fd);
> >  priv->drm_fd = -1;
> >  continue;
> > +    } else if (vendor_id) {
> > +    drmDevicePtr device;
> > +    char drm_vendor[8];
> > +    if (drmGetDevice(priv->drm_fd, &device)) {
> > +    av_log(ctx, AV_LOG_VERBOSE,
> > +   "Failed to get DRM device info for device
> > %d.\n", n);
> > +    close(priv->drm_fd);
> > +    priv->drm_fd = -1;
> > +    continue;
> > +    }
> > +
> > +    snprintf(drm_vendor, sizeof(drm_vendor), "0x%x",
> > device-
> > > deviceinfo.pci->vendor_id);
> > +    if (strcmp(vendor_id->value, drm_vendor)) {
> > +    av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d "
> > +   "with non-matching vendor id (%s).\n",
> > +   n, vendor_id->value);
> > +    drmFreeDevice(&device);
> > +    close(priv->drm_fd);
> > +    priv->drm_fd = -1;
> > +    continue;
> > +    }
> > +    av_log(ctx, AV_LOG_VERBOSE, "Trying to use "
> > +   "DRM render node for device %d, "
> > +   "with matching vendor id (%s).\n",
> > +   n, vendor_id->value);
> > +    drmFreeDevice(&device);
> > +

Re: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add option to allow to specify vendor id when init hw device

2024-08-04 Thread Xiang, Haihao
On Vr, 2024-07-26 at 09:05 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Vendor id will help to select desired device in case of kernel driver is
> unknow or unsupported, for vendor may support different kernel driver on
> different platforms.
> 
> Signed-off-by: Fei Wang 
> ---
>  doc/ffmpeg.texi |  8 
>  libavutil/hwcontext_vaapi.c | 29 +
>  libavutil/version.h |  2 +-
>  3 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 877edae3b3..842e92ad1a 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -1458,6 +1458,11 @@ The following options are recognized:
>  When @var{device} is not specified, use this option to specify the name of
> the kernel
>  driver associated with the desired device. This option is available only when
>  the hardware acceleration method @emph{drm} and @emph{vaapi} are enabled.
> +@item vendor_id
> +When @var{device} and @var{kernel_driver} are not specified, use this option
> to specify
> +the vendor id associated with the desired device. This option is available
> only when the
> +hardware acceleration method @emph{drm} and @emph{vaapi} are enabled and
> @emph{kernel_driver}
> +is not specified.
>  @end table
>  
>  Examples:
> @@ -1473,6 +1478,9 @@ Create a vaapi device on DirectX adapter 1.
>  
>  @item -init_hw_device vaapi:,kernel_driver=i915
>  Create a vaapi device on a device associated with kernel driver @samp{i915}.
> +
> +@item -init_hw_device vaapi:,vendor_id=0x8086
> +Create a vaapi device on a device associated with vendor id @samp{0x8086}.
>  @end table
>  
>  @item vdpau
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 4cb25dd032..014541752a 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -1748,7 +1748,9 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
>  #if CONFIG_LIBDRM
>  drmVersion *info;
>  const AVDictionaryEntry *kernel_driver;
> +    const AVDictionaryEntry *vendor_id;
>  kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0);
> +    vendor_id = av_dict_get(opts, "vendor_id", NULL, 0);
>  #endif
>  for (n = 0; n < max_devices; n++) {
>  snprintf(path, sizeof(path),
> @@ -1803,6 +1805,33 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
>  close(priv->drm_fd);
>  priv->drm_fd = -1;
>  continue;
> +    } else if (vendor_id) {
> +    drmDevicePtr device;
> +    char drm_vendor[8];
> +    if (drmGetDevice(priv->drm_fd, &device)) {
> +    av_log(ctx, AV_LOG_VERBOSE,
> +   "Failed to get DRM device info for device
> %d.\n", n);
> +    close(priv->drm_fd);
> +    priv->drm_fd = -1;
> +    continue;
> +    }
> +
> +    snprintf(drm_vendor, sizeof(drm_vendor), "0x%x", device-
> >deviceinfo.pci->vendor_id);
> +    if (strcmp(vendor_id->value, drm_vendor)) {
> +    av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d "
> +   "with non-matching vendor id (%s).\n",
> +   n, vendor_id->value);
> +    drmFreeDevice(&device);
> +    close(priv->drm_fd);
> +    priv->drm_fd = -1;
> +    continue;
> +    }
> +    av_log(ctx, AV_LOG_VERBOSE, "Trying to use "
> +   "DRM render node for device %d, "
> +   "with matching vendor id (%s).\n",
> +   n, vendor_id->value);
> +    drmFreeDevice(&device);
> +    break;
>  }
>  drmFreeVersion(info);
>  #endif
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 814892a4d5..852eeef1d6 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  59
> -#define LIBAVUTIL_VERSION_MINOR  28
> +#define LIBAVUTIL_VERSION_MINOR  29
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Patchset LGTM, I will apply these patches if there are no objections.

Thanks
Haihao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers

2024-08-04 Thread Xiang, Haihao
On Di, 2024-07-30 at 11:31 +0200, Sebastian Ramacher wrote:
> On 2024-05-07 06:59:51 +0000, Xiang, Haihao wrote:
> > On So, 2024-04-28 at 09:26 +0200, David Rosca wrote:
> > > ---
> > >  libavcodec/vaapi_av1.c    | 2 +-
> > >  libavcodec/vaapi_decode.c | 3 ++-
> > >  libavcodec/vaapi_decode.h | 1 +
> > >  libavcodec/vaapi_h264.c   | 2 +-
> > >  libavcodec/vaapi_hevc.c   | 4 ++--
> > >  libavcodec/vaapi_mjpeg.c  | 2 +-
> > >  libavcodec/vaapi_mpeg2.c  | 2 +-
> > >  libavcodec/vaapi_mpeg4.c  | 2 +-
> > >  libavcodec/vaapi_vc1.c    | 2 +-
> > >  libavcodec/vaapi_vp8.c    | 2 +-
> > >  libavcodec/vaapi_vp9.c    | 2 +-
> > >  11 files changed, 13 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> > > index 1f563483b9..4a90db1e09 100644
> > > --- a/libavcodec/vaapi_av1.c
> > > +++ b/libavcodec/vaapi_av1.c
> > > @@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext
> > > *avctx,
> > >  .tg_end    = s->tg_end,
> > >  };
> > >  
> > > -    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
> > > +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
> > > 1,
> > > 
> > > sizeof(VASliceParameterBufferAV1),
> > >  buffer,
> > >  size);
> > > diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> > > index 21b273cd0f..8e9f647c20 100644
> > > --- a/libavcodec/vaapi_decode.c
> > > +++ b/libavcodec/vaapi_decode.c
> > > @@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext
> > > *avctx,
> > >  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
> > >    VAAPIDecodePicture *pic,
> > >    const void *params_data,
> > > +  int nb_params,
> > >    size_t params_size,
> > >    const void *slice_data,
> > >    size_t slice_size)
> > > @@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext
> > > *avctx,
> > >  
> > >  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
> > >   VASliceParameterBufferType,
> > > - params_size, 1, (void*)params_data,
> > > + params_size, nb_params, (void*)params_data,
> > >   &pic->slice_buffers[index]);
> > >  if (vas != VA_STATUS_SUCCESS) {
> > >  av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
> > > diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
> > > index 6beda14e52..702171e108 100644
> > > --- a/libavcodec/vaapi_decode.h
> > > +++ b/libavcodec/vaapi_decode.h
> > > @@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext
> > > *avctx,
> > >  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
> > >    VAAPIDecodePicture *pic,
> > >    const void *params_data,
> > > +  int nb_params,
> > >    size_t params_size,
> > >    const void *slice_data,
> > >    size_t slice_size);
> > > diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> > > index 55cf5a05ee..b47531ce1c 100644
> > > --- a/libavcodec/vaapi_h264.c
> > > +++ b/libavcodec/vaapi_h264.c
> > > @@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext
> > > *avctx,
> > >     slice_param.chroma_offset_l1);
> > >  
> > >  err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> > > -    &slice_param,
> > > sizeof(slice_param),
> > > +    &slice_param, 1,
> > > sizeof(slice_param),
> > >  buffer, size);
> > >  if (err) {
> > >  ff_vaapi_decode_cancel(a

Re: [FFmpeg-devel] [PATCH] avcodec/av1_vaapi: Enable AV1Profile2 VAAPI support.

2024-08-04 Thread Xiang, Haihao
On Di, 2024-07-30 at 16:02 -0400, David (Ming Qiang) Wu via ffmpeg-devel wrote:
> AV1Profile2 VAAPI is supported and tested on AMD VCN5.
> 
> Signed-off-by: David (Ming Qiang) Wu 
> ---
>  libavcodec/av1dec.c   | 3 +++
>  libavcodec/vaapi_decode.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 1d5b9ef4f4..77f63661a0 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -599,6 +599,9 @@ static int get_pixel_format(AVCodecContext *avctx)
>  case AV_PIX_FMT_YUV420P12:
>  #if CONFIG_AV1_VULKAN_HWACCEL
>  *fmtp++ = AV_PIX_FMT_VULKAN;
> +#endif
> +#if CONFIG_AV1_VAAPI_HWACCEL
> +    *fmtp++ = AV_PIX_FMT_VAAPI;
>  #endif
>  break;
>  case AV_PIX_FMT_YUV422P:
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index a59194340f..a077e47326 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -448,6 +448,9 @@ static const struct {
>  MAP(AV1, AV1_MAIN,    AV1Profile0),
>  MAP(AV1, AV1_HIGH,    AV1Profile1),
>  #endif
> +#if VA_CHECK_VERSION(1, 23, 0)
> +    MAP(AV1, AV1_PROFESSIONAL, AV1Profile2),
> +#endif
>  
>  #undef MAP

LGTM, Please ping when libva 2.23 (VA-API 1.23) is released officially.

Thanks
Haihao


>  };

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

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


Re: [FFmpeg-devel] [PATCH v2 2/2] lavc/qsvdec: Add VVC decoder

2024-07-30 Thread Xiang, Haihao
On Vr, 2024-07-26 at 04:43 +, Xiang, Haihao wrote:
> On Vr, 2024-06-14 at 16:28 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> > From: Fei Wang 
> > 
> > Signed-off-by: Fei Wang 
> > ---
> >  Changelog  | 1 +
> >  configure  | 1 +
> >  doc/decoders.texi  | 2 +-
> >  libavcodec/allcodecs.c | 1 +
> >  libavcodec/qsv.c   | 4 
> >  libavcodec/qsvdec.c    | 7 ++-
> >  libavcodec/version.h   | 2 +-
> >  7 files changed, 15 insertions(+), 3 deletions(-)
> > 
> > diff --git a/Changelog b/Changelog
> > index 881b0e67a3..1fd1fce0c6 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -13,6 +13,7 @@ version :
> >  - VVC decoder compatible with DVB test content
> >  - xHE-AAC decoder
> >  - removed DEC Alpha DSP and support code
> > +- Intel QSV-accelerated VVC decoding
> >  
> >  
> >  version 7.0:
> > diff --git a/configure b/configure
> > index 6d31698142..d50f444141 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3421,6 +3421,7 @@ vp9_vaapi_encoder_select="vaapi_encode"
> >  vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
> >  vp9_qsv_encoder_select="qsvenc"
> >  vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m"
> > +vvc_qsv_decoder_select="qsvdec"
> >  
> >  # parsers
> >  aac_parser_select="adts_header mpeg4audio"
> > diff --git a/doc/decoders.texi b/doc/decoders.texi
> > index 293c82c2ba..2fcc761d2f 100644
> > --- a/doc/decoders.texi
> > +++ b/doc/decoders.texi
> > @@ -157,7 +157,7 @@ Force to use a specific number of threads
> >  @section QSV Decoders
> >  
> >  The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC,
> > -JPEG/MJPEG, VP8, VP9, AV1).
> > +JPEG/MJPEG, VP8, VP9, AV1, VVC).
> >  
> >  @subsection Common Options
> >  
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index b102a8069e..a73b4e1673 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > @@ -885,6 +885,7 @@ extern const FFCodec ff_vp9_mediacodec_encoder;
> >  extern const FFCodec ff_vp9_qsv_decoder;
> >  extern const FFCodec ff_vp9_vaapi_encoder;
> >  extern const FFCodec ff_vp9_qsv_encoder;
> > +extern const FFCodec ff_vvc_qsv_decoder;
> >  
> >  // null codecs
> >  extern const FFCodec ff_vnull_decoder;
> > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> > index 0c6fbd0dc0..221c1b24e5 100644
> > --- a/libavcodec/qsv.c
> > +++ b/libavcodec/qsv.c
> > @@ -73,6 +73,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
> >  case AV_CODEC_ID_AV1:
> >  return MFX_CODEC_AV1;
> >  #endif
> > +#if QSV_VERSION_ATLEAST(2, 11)
> > +    case AV_CODEC_ID_VVC:
> > +    return MFX_CODEC_VVC;
> > +#endif
> >  
> >  default:
> >  break;
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index f2cd6ae05c..9ad3439991 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -933,7 +933,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> > *q,
> >  frame->pict_type = ff_qsv_map_pictype(aframe.frame-
> > > dec_info.FrameType);
> >  
> >  if (avctx->codec_id == AV_CODEC_ID_H264 ||
> > -    avctx->codec_id == AV_CODEC_ID_HEVC) {
> > +    avctx->codec_id == AV_CODEC_ID_HEVC ||
> > +    avctx->codec_id == AV_CODEC_ID_VVC) {
> >  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
> >  frame->flags |= AV_FRAME_FLAG_KEY;
> >  else
> > @@ -1300,3 +1301,7 @@ DEFINE_QSV_DECODER(vp9, VP9, NULL)
> >  #if CONFIG_AV1_QSV_DECODER
> >  DEFINE_QSV_DECODER(av1, AV1, NULL)
> >  #endif
> > +
> > +#if CONFIG_VVC_QSV_DECODER
> > +DEFINE_QSV_DECODER(vvc, VVC, NULL)
> > +#endif
> > diff --git a/libavcodec/version.h b/libavcodec/version.h
> > index 7acb261bb3..37c4c39451 100644
> > --- a/libavcodec/version.h
> > +++ b/libavcodec/version.h
> > @@ -29,7 +29,7 @@
> >  
> >  #include "version_major.h"
> >  
> > -#define LIBAVCODEC_VERSION_MINOR   7
> > +#define LIBAVCODEC_VERSION_MINOR   8
> >  #define LIBAVCODEC_VERSION_MICRO 100
> >  
> >  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> 
> LGTM, will apply

Fixed conflict in Changelog & libavcodec/version.h and applied. 

Thanks
Haihao

> 
> 
> ___
> 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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] lavu/hwcontext_qsv: Derive bind flag from frame type if no valid surface

2024-07-30 Thread Xiang, Haihao
On Ma, 2024-07-29 at 15:27 +, Tong Wu wrote:
-Original Message-
From: ffmpeg-devel 
mailto:ffmpeg-devel-boun...@ffmpeg.org>> On 
Behalf Of
fei.w.wang-at-intel@ffmpeg.org
Sent: 2024年7月23日 9:27
To: ffmpeg-devel@ffmpeg.org
Cc: fei.w.w...@intel.com
Subject: [FFmpeg-devel] [PATCH] lavu/hwcontext_qsv: Derive bind flag from
frame type if no valid surface

From: Fei Wang mailto:fei.w.w...@intel.com>>

Fix cmd:
ffmpeg.exe -init_hw_device d3d11va=d3d -init_hw_device qsv=qsv@d3d \
-filter_hw_device d3d -hwaccel qsv -hwaccel_output_format qsv  \
-i in.h264 -vf "hwmap,format=d3d11,hwdownload,format=nv12" -y out.yuv

Signed-off-by: Fei Wang mailto:fei.w.w...@intel.com>>
---
libavutil/hwcontext_qsv.c | 7 +--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index
7cec347478..09156275ec 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1549,8 +1549,11 @@ static int
qsv_frames_derive_from(AVHWFramesContext *dst_ctx,
dst_hwctx->texture_infos[i].texture = 
(ID3D11Texture2D*)pair->first;
dst_hwctx->texture_infos[i].index = pair->second ==
(mfxMemId)MFX_INFINITE ? (intptr_t)0 : (intptr_t)pair->second;
}
-ID3D11Texture2D_GetDesc(dst_hwctx->texture_infos[0].texture,
&texDesc);
-dst_hwctx->BindFlags = texDesc.BindFlags;
+if (src_hwctx->nb_surfaces) {
+ID3D11Texture2D_GetDesc(dst_hwctx->texture_infos[0].texture,
&texDesc);
+dst_hwctx->BindFlags = texDesc.BindFlags;
+} else
+dst_hwctx->BindFlags =
+ qsv_get_d3d11va_bind_flags(src_hwctx->frame_type);
}
break;
#endif
--
2.34.1


Tested. LGTM. Thanks.

Applied, thx

- Haihao

___
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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 2/2] lavc/qsvdec: Add VVC decoder

2024-07-25 Thread Xiang, Haihao
On Vr, 2024-06-14 at 16:28 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  Changelog  | 1 +
>  configure  | 1 +
>  doc/decoders.texi  | 2 +-
>  libavcodec/allcodecs.c | 1 +
>  libavcodec/qsv.c   | 4 
>  libavcodec/qsvdec.c    | 7 ++-
>  libavcodec/version.h   | 2 +-
>  7 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/Changelog b/Changelog
> index 881b0e67a3..1fd1fce0c6 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -13,6 +13,7 @@ version :
>  - VVC decoder compatible with DVB test content
>  - xHE-AAC decoder
>  - removed DEC Alpha DSP and support code
> +- Intel QSV-accelerated VVC decoding
>  
>  
>  version 7.0:
> diff --git a/configure b/configure
> index 6d31698142..d50f444141 100755
> --- a/configure
> +++ b/configure
> @@ -3421,6 +3421,7 @@ vp9_vaapi_encoder_select="vaapi_encode"
>  vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
>  vp9_qsv_encoder_select="qsvenc"
>  vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m"
> +vvc_qsv_decoder_select="qsvdec"
>  
>  # parsers
>  aac_parser_select="adts_header mpeg4audio"
> diff --git a/doc/decoders.texi b/doc/decoders.texi
> index 293c82c2ba..2fcc761d2f 100644
> --- a/doc/decoders.texi
> +++ b/doc/decoders.texi
> @@ -157,7 +157,7 @@ Force to use a specific number of threads
>  @section QSV Decoders
>  
>  The family of Intel QuickSync Video decoders (VC1, MPEG-2, H.264, HEVC,
> -JPEG/MJPEG, VP8, VP9, AV1).
> +JPEG/MJPEG, VP8, VP9, AV1, VVC).
>  
>  @subsection Common Options
>  
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index b102a8069e..a73b4e1673 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -885,6 +885,7 @@ extern const FFCodec ff_vp9_mediacodec_encoder;
>  extern const FFCodec ff_vp9_qsv_decoder;
>  extern const FFCodec ff_vp9_vaapi_encoder;
>  extern const FFCodec ff_vp9_qsv_encoder;
> +extern const FFCodec ff_vvc_qsv_decoder;
>  
>  // null codecs
>  extern const FFCodec ff_vnull_decoder;
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 0c6fbd0dc0..221c1b24e5 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -73,6 +73,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
>  case AV_CODEC_ID_AV1:
>  return MFX_CODEC_AV1;
>  #endif
> +#if QSV_VERSION_ATLEAST(2, 11)
> +    case AV_CODEC_ID_VVC:
> +    return MFX_CODEC_VVC;
> +#endif
>  
>  default:
>  break;
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index f2cd6ae05c..9ad3439991 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -933,7 +933,8 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>  frame->pict_type = ff_qsv_map_pictype(aframe.frame-
> >dec_info.FrameType);
>  
>  if (avctx->codec_id == AV_CODEC_ID_H264 ||
> -    avctx->codec_id == AV_CODEC_ID_HEVC) {
> +    avctx->codec_id == AV_CODEC_ID_HEVC ||
> +    avctx->codec_id == AV_CODEC_ID_VVC) {
>  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
>  frame->flags |= AV_FRAME_FLAG_KEY;
>  else
> @@ -1300,3 +1301,7 @@ DEFINE_QSV_DECODER(vp9, VP9, NULL)
>  #if CONFIG_AV1_QSV_DECODER
>  DEFINE_QSV_DECODER(av1, AV1, NULL)
>  #endif
> +
> +#if CONFIG_VVC_QSV_DECODER
> +DEFINE_QSV_DECODER(vvc, VVC, NULL)
> +#endif
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 7acb261bb3..37c4c39451 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>  
>  #include "version_major.h"
>  
> -#define LIBAVCODEC_VERSION_MINOR   7
> +#define LIBAVCODEC_VERSION_MINOR   8
>  #define LIBAVCODEC_VERSION_MICRO 100
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

LGTM, will apply

-Haihao


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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_{decode, av1}: Fix memory leak in fail codepath

2024-07-08 Thread Xiang, Haihao
On Ma, 2024-07-01 at 16:36 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_av1.c    | 9 +
>  libavcodec/vaapi_decode.c | 5 +++--
>  2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index fe0852318d..5451b6055b 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -404,14 +404,15 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  
>  nb_params = s->tg_end - s->tg_start + 1;
>  if (ctx->nb_slice_params < nb_params) {
> -    ctx->slice_params = av_realloc_array(ctx->slice_params,
> - nb_params,
> - sizeof(*ctx->slice_params));
> -    if (!ctx->slice_params) {
> +    VASliceParameterBufferAV1 *tmp = av_realloc_array(ctx->slice_params,
> +  nb_params,
> +  sizeof(*ctx-
> >slice_params));
> +    if (!tmp) {
>  ctx->nb_slice_params = 0;
>  err = AVERROR(ENOMEM);
>  goto fail;
>  }
> +    ctx->slice_params    = tmp;
>  ctx->nb_slice_params = nb_params;
>  }
>  
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 7c91d50f7b..a59194340f 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -74,13 +74,14 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext
> *avctx,
>  
>  av_assert0(pic->nb_slices <= pic->slices_allocated);
>  if (pic->nb_slices == pic->slices_allocated) {
> -    pic->slice_buffers =
> +    VABufferID *tmp =
>  av_realloc_array(pic->slice_buffers,
>   pic->slices_allocated ? pic->slices_allocated *
> 2 : 64,
>   2 * sizeof(*pic->slice_buffers));
> -    if (!pic->slice_buffers)
> +    if (!tmp)
>  return AVERROR(ENOMEM);
>  
> +    pic->slice_buffers    = tmp;
>  pic->slices_allocated = pic->slices_allocated ? pic->slices_allocated
> * 2 : 64;
>  }
>  av_assert0(pic->nb_slices + 1 <= pic->slices_allocated);

LGTM, will apply

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

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


Re: [FFmpeg-devel] [PATCH v2] doc/examples/vaapi_encode: Try to check fwrite() for failure

2024-07-08 Thread Xiang, Haihao
On Di, 2024-07-02 at 01:47 +0200, Michael Niedermayer wrote:
> Fixes: CID1604548 Unused value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/examples/vaapi_encode.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
> index d5f472f6dd8..ff3ebb1e2b8 100644
> --- a/doc/examples/vaapi_encode.c
> +++ b/doc/examples/vaapi_encode.c
> @@ -88,6 +88,10 @@ static int encode_write(AVCodecContext *avctx, AVFrame
> *frame, FILE *fout)
>  enc_pkt->stream_index = 0;
>  ret = fwrite(enc_pkt->data, enc_pkt->size, 1, fout);
>  av_packet_unref(enc_pkt);
> +    if (ret != enc_pkt->size) {
> +    ret = AVERROR(errno);
> +    break;
> +    }
>  }
>  
>  end:

LGTM

- Haihao

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

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


Re: [FFmpeg-devel] [PATCH 2/6] avcodec/vaapi_h264: Do not store our error code in VASliceParameterBufferH264

2024-07-08 Thread Xiang, Haihao
On So, 2024-07-07 at 20:47 +0200, Michael Niedermayer wrote:
> I am not sure this is possible (thus this requires review)
> 
> Fixes: CID1604570 Overflowed constant
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/vaapi_h264.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index 398e92568c2..77819a64a4e 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -342,6 +342,10 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
>  const H264SliceContext *sl  = &h->slice_ctx[0];
>  VASliceParameterBufferH264 slice_param;
>  int err;
> +    int slice_type = ff_h264_get_slice_type(sl);
> +
> +    if (slice_type < 0)
> +    return slice_type;

sl->slice_type should be one of AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B,
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_SP and AV_PICTURE_TYPE_SI when this callback
function is called, I don't think the if statement is required. 

Thanks
Haihao


>  
>  slice_param = (VASliceParameterBufferH264) {
>  .slice_data_size   = size,
> @@ -349,7 +353,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
>  .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
>  .slice_data_bit_offset = get_bits_count(&sl->gb),
>  .first_mb_in_slice = (sl->mb_y >>
> FIELD_OR_MBAFF_PICTURE(h)) * h->mb_width + sl->mb_x,
> -    .slice_type    = ff_h264_get_slice_type(sl),
> +    .slice_type    = slice_type,
>  .direct_spatial_mv_pred_flag   = sl->slice_type == AV_PICTURE_TYPE_B
> ? sl->direct_spatial_mv_pred : 0,
>  .num_ref_idx_l0_active_minus1  = sl->list_count > 0 ? sl-
> >ref_count[0] - 1 : 0,
>  .num_ref_idx_l1_active_minus1  = sl->list_count > 1 ? sl-
> >ref_count[1] - 1 : 0,

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

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


Re: [FFmpeg-devel] [PATCH 3/4] avfilter/qsvvpp: Remove unreachable code

2024-06-12 Thread Xiang, Haihao
On Di, 2024-06-11 at 23:59 +0200, Michael Niedermayer wrote:
> Fixes: CID1598548 Logically dead code
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavfilter/qsvvpp.c | 5 -
>  1 file changed, 5 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 1c9773df099..6adf9f6e841 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -1099,11 +1099,6 @@ int ff_qsvvpp_create_mfx_session(void *ctx,
>  if (sts < 0)
>  return ff_qsvvpp_print_error(ctx, sts,
>   "Error creating a MFX session");
> -    else if (sts > 0) {
> -    ff_qsvvpp_print_warning(ctx, sts,
> -    "Warning in MFX session creation");
> -    return AVERROR_UNKNOWN;
> -    }
>  
>  *psession = session;
>  

LGTM, thx

-Haihao

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

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


Re: [FFmpeg-devel] [PATCH v5 1/2] configure, lavu, lavc, lavfi: Remove libva 1.x support

2024-06-11 Thread Xiang, Haihao
On Wo, 2024-06-05 at 21:13 +0100, Mark Thompson wrote:
> libva 2.0 was released in 2017 and the 2.x versions are included in all
> supported distributions nowadays.  Various features no longer need any
> configure check after this change, including all codecs except AV1.
> Note that the libva version is the API version plus one, so this is
> removing support for VAAPI 0.x and requiring VAAPI 1.x.
> ---
> Now squashed.
> 
> 
>  configure  | 25 +++
>  libavcodec/vaapi_decode.c  | 39 ++---
>  libavcodec/vaapi_encode.c  | 78 ++
>  libavcodec/vaapi_encode.h  |  9 
>  libavcodec/vaapi_encode_h264.c | 18 
>  libavcodec/vaapi_encode_h265.c |  2 -
>  libavfilter/vaapi_vpp.c    | 22 --
>  libavutil/hwcontext_vaapi.c    | 22 --
>  8 files changed, 29 insertions(+), 186 deletions(-)
> 
> diff --git a/configure b/configure
> index 6c5b8aab9a..06e6fa22f2 100755
> --- a/configure
> +++ b/configure
> @@ -2630,7 +2630,6 @@ CONFIG_EXTRA="
>  texturedsp
>  texturedspenc
>  tpeldsp
> -    vaapi_1

There still are vaapi_1 in configure

configure:pad_vaapi_filter_deps="vaapi_1"
configure:drawbox_vaapi_filter_deps="vaapi_1"

Thanks
Haihao


>  vaapi_encode
>  vc1dsp
>  videodsp
> @@ -3200,7 +3199,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
>  hevc_dxva2_hwaccel_select="hevc_decoder"
>  hevc_nvdec_hwaccel_deps="nvdec"
>  hevc_nvdec_hwaccel_select="hevc_decoder"
> -hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
> +hevc_vaapi_hwaccel_deps="vaapi"
>  hevc_vaapi_hwaccel_select="hevc_decoder"
>  hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
>  hevc_vdpau_hwaccel_select="hevc_decoder"
> @@ -3272,7 +3271,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
>  vp9_dxva2_hwaccel_select="vp9_decoder"
>  vp9_nvdec_hwaccel_deps="nvdec"
>  vp9_nvdec_hwaccel_select="vp9_decoder"
> -vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
> +vp9_vaapi_hwaccel_deps="vaapi"
>  vp9_vaapi_hwaccel_select="vp9_decoder"
>  vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
>  vp9_vdpau_hwaccel_select="vp9_decoder"
> @@ -3365,7 +3364,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
>  hevc_qsv_encoder_select="hevcparse qsvenc"
>  hevc_rkmpp_decoder_deps="rkmpp"
>  hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
> -hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
>  hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
>  hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
>  hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
> @@ -3374,7 +3372,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
>  mjpeg_qsv_decoder_select="qsvdec"
>  mjpeg_qsv_encoder_deps="libmfx"
>  mjpeg_qsv_encoder_select="qsvenc"
> -mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
>  mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
>  mp3_mf_encoder_deps="mediafoundation"
>  mpeg1_cuvid_decoder_deps="cuvid"
> @@ -3403,7 +3400,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
>  vp8_mediacodec_encoder_deps="mediacodec"
>  vp8_qsv_decoder_select="qsvdec"
>  vp8_rkmpp_decoder_deps="rkmpp"
> -vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
>  vp8_vaapi_encoder_select="vaapi_encode"
>  vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
>  vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
> @@ -3412,7 +3408,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
>  vp9_mediacodec_encoder_deps="mediacodec"
>  vp9_qsv_decoder_select="qsvdec"
>  vp9_rkmpp_decoder_deps="rkmpp"
> -vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
>  vp9_vaapi_encoder_select="vaapi_encode"
>  vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
>  vp9_qsv_encoder_select="qsvenc"
> @@ -3966,9 +3961,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
>  yadif_cuda_filter_deps="ffnvcodec"
>  yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
>  yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
> -hstack_vaapi_filter_deps="vaapi_1"
> -vstack_vaapi_filter_deps="vaapi_1"
> -xstack_vaapi_filter_deps="vaapi_1"
> +hstack_vaapi_filter_deps="vaapi"
> +vstack_vaapi_filter_deps="vaapi"
> +xstack_vaapi_filter_deps="vaapi"
>  hstack_qsv_filter_deps="libmfx"
>  hstack_qsv_filter_select="qsvvpp"
>  vstack_qsv_filter_deps="libmfx"
> @@ -7271,7 +7266,7 @@ enabled libdrm &&
>  check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2
>  
>  enabled vaapi &&
> -    check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
> +    check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize
>  
>  if enabled vaapi; then
>  case $target_os in
> @@ -7287,18 +7282,10 @@ if enabled vaapi; then
>  check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
>  fi
>  
> -    check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
> -
> -    check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
> -    check_struct "va/va.h" "VADecPictureParameterBufferVP9"

[FFmpeg-devel] [PATCH] lavu/hwcontext_vulkan: Support write on drm frame

2024-06-10 Thread Xiang, Haihao
From: Haihao Xiang 

Otherwise nothing is written into the destination when a write mapping
is requested.

For example, a vulkan frame mapped from a drm frame (which is wrapped as
a vaapi frame in the example) is used as the output of scale_vulkan
filter, it always gets a green screen without this patch.

ffmpeg -init_hw_device vaapi=va -init_hw_device vulkan=vulkan@va
-filter_hw_device vulkan -f lavfi -i testsrc=size=352x288,format=nv12
-vf
"hwupload,scale_vulkan,hwmap=derive_device=vaapi:reverse=1,format=vaapi,hwdownload,format=nv12"
-f nut - | ffplay -

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_vulkan.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index e2f92af227..675ead0ba6 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2511,7 +2511,7 @@ static inline VkFormat drm_to_vulkan_fmt(uint32_t 
drm_fourcc)
 }
 
 static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame 
**frame,
-  const AVFrame *src)
+  const AVFrame *src, int flags)
 {
 int err = 0;
 VkResult ret;
@@ -2569,6 +2569,14 @@ static int 
vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
 .pNext   = &ext_img_mod_spec,
 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
 };
+int usage = (((flags & (AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE)) 
== (AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE)) ?
+  (VK_IMAGE_USAGE_SAMPLED_BIT |
+   VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
+   VK_IMAGE_USAGE_TRANSFER_DST_BIT |
+   VK_IMAGE_USAGE_STORAGE_BIT) :
+ ((flags & AV_HWFRAME_MAP_WRITE) ?
+  (VK_IMAGE_USAGE_TRANSFER_DST_BIT | 
VK_IMAGE_USAGE_STORAGE_BIT) :
+  (VK_IMAGE_USAGE_SAMPLED_BIT | 
VK_IMAGE_USAGE_TRANSFER_SRC_BIT)));
 VkImageCreateInfo create_info = {
 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
 .pNext = &ext_img_spec,
@@ -2580,8 +2588,7 @@ static int 
vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
 .flags = 0x0,
 .tiling= VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT,
 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, /* specs say 
so */
-.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
- VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
+.usage = usage,
 .samples   = VK_SAMPLE_COUNT_1_BIT,
 .pQueueFamilyIndices   = p->img_qfs,
 .queueFamilyIndexCount = p->nb_img_qfs,
@@ -2788,7 +2795,7 @@ static int vulkan_map_from_drm(AVHWFramesContext *hwfc, 
AVFrame *dst,
 int err = 0;
 AVVkFrame *f;
 
-if ((err = vulkan_map_from_drm_frame_desc(hwfc, &f, src)))
+if ((err = vulkan_map_from_drm_frame_desc(hwfc, &f, src, flags)))
 return err;
 
 /* The unmapping function will free this */
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/vaapi_h264: Fix merging fields in DPB with missing references

2024-05-27 Thread Xiang, Haihao
On Wo, 2024-05-08 at 17:41 +0200, David Rosca wrote:
> If there are missing references, h264 decode does error concealment
> by copying previous refs which means there will be duplicated surfaces.
> Check long_ref and frame_idx in addition to surface when looking for
> the other field to avoid trying to merge with wrong picture.
> Also allow to merge with multiple pictures in case there are duplicates
> of the other field.
> ---
> v2: Check long_ref/frame_idx + multiple merge
> 
>  libavcodec/vaapi_h264.c | 14 +++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index b47531ce1c..398e92568c 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -93,14 +93,19 @@ typedef struct DPB {
>   */
>  static int dpb_add(DPB *dpb, const H264Picture *pic)
>  {
> -    int i;
> +    int i, pic_frame_idx, merged = 0;
>  
>  if (dpb->size >= dpb->max_size)
>  return -1;
>  
> +    pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
> +
>  for (i = 0; i < dpb->size; i++) {
>  VAPictureH264 * const va_pic = &dpb->va_pics[i];
> -    if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
> +    int va_pic_long_ref = !!(va_pic->flags &
> VA_PICTURE_H264_LONG_TERM_REFERENCE);
> +    if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f) &&
> +    va_pic_long_ref == pic->long_ref &&
> +    va_pic->frame_idx == pic_frame_idx) {
>  VAPictureH264 temp_va_pic;
>  fill_vaapi_pic(&temp_va_pic, pic, 0);
>  
> @@ -112,11 +117,14 @@ static int dpb_add(DPB *dpb, const H264Picture *pic)
>  } else {
>  va_pic->BottomFieldOrderCnt =
> temp_va_pic.BottomFieldOrderCnt;
>  }
> +    merged = 1;
>  }
> -    return 0;
>  }
>  }
>  
> +    if (merged)
> +    return 0;
> +
>  fill_vaapi_pic(&dpb->va_pics[dpb->size++], pic, 0);
>  return 0;
>  }

LGTM, will apply

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers

2024-05-27 Thread Xiang, Haihao
On Wo, 2024-05-08 at 09:11 +0200, David Rosca wrote:
> ---
> v2: No changes
> 
>  libavcodec/vaapi_av1.c    | 2 +-
>  libavcodec/vaapi_decode.c | 3 ++-
>  libavcodec/vaapi_decode.h | 1 +
>  libavcodec/vaapi_h264.c   | 2 +-
>  libavcodec/vaapi_hevc.c   | 4 ++--
>  libavcodec/vaapi_mjpeg.c  | 2 +-
>  libavcodec/vaapi_mpeg2.c  | 2 +-
>  libavcodec/vaapi_mpeg4.c  | 2 +-
>  libavcodec/vaapi_vc1.c    | 2 +-
>  libavcodec/vaapi_vp8.c    | 2 +-
>  libavcodec/vaapi_vp9.c    | 2 +-
>  11 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 1f563483b9..4a90db1e09 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  .tg_end    = s->tg_end,
>  };
>  
> -    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
> 
> sizeof(VASliceParameterBufferAV1),
>  buffer,
>  size);
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 21b273cd0f..8e9f647c20 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>    VAAPIDecodePicture *pic,
>    const void *params_data,
> +  int nb_params,
>    size_t params_size,
>    const void *slice_data,
>    size_t slice_size)
> @@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>  
>  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
>   VASliceParameterBufferType,
> - params_size, 1, (void*)params_data,
> + params_size, nb_params, (void*)params_data,
>   &pic->slice_buffers[index]);
>  if (vas != VA_STATUS_SUCCESS) {
>  av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
> diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
> index 6beda14e52..702171e108 100644
> --- a/libavcodec/vaapi_decode.h
> +++ b/libavcodec/vaapi_decode.h
> @@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>    VAAPIDecodePicture *pic,
>    const void *params_data,
> +  int nb_params,
>    size_t params_size,
>    const void *slice_data,
>    size_t slice_size);
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index 55cf5a05ee..b47531ce1c 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
>     slice_param.chroma_offset_l1);
>  
>  err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -    &slice_param,
> sizeof(slice_param),
> +    &slice_param, 1,
> sizeof(slice_param),
>  buffer, size);
>  if (err) {
>  ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> index 3bdd2dd1b8..3937b7574a 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
>  if (pic->last_size) {
>  last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
>  ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -    &pic->last_slice_param,
> slice_param_size,
> +    &pic->last_slice_param, 1,
> slice_param_size,
>  pic->last_buffer, pic-
> >last_size);
>  if (ret < 0)
>  goto fail;
> @@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
>  
>  if (!sh->first_slice_in_pic_flag) {
>  err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -    &pic->last_slice_param,
> slice_param_size,
> +    &pic->last_slice_param, 1,
> slice_param_size,
>  pic->last_buffer, pic-
> >last_size)

Re: [FFmpeg-devel] [PATCH 1/2] lavc/qsvdec: fix keyframes

2024-05-26 Thread Xiang, Haihao
On Vr, 2024-05-24 at 13:20 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> MFX_FRAMETYPE_IDR is ORed to the frame type for AVC and HEVC keyframes,
> and MFX_FRAMETYPE_I is taken as keyframe flag for other codecs when
> getting the output surface from the SDK, hence we may mark the output
> frame as keyframe accordingly.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/qsvdec.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index df0d49bc10..6ffd498456 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -885,12 +885,18 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>  frame->flags |= AV_FRAME_FLAG_INTERLACED *
>  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
>  frame->pict_type = ff_qsv_map_pictype(aframe.frame-
> >dec_info.FrameType);
> -    //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs
> are key frames.
> -    if (avctx->codec_id == AV_CODEC_ID_H264) {
> +
> +    if (avctx->codec_id == AV_CODEC_ID_H264 ||
> +    avctx->codec_id == AV_CODEC_ID_HEVC) {
>  if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
>  frame->flags |= AV_FRAME_FLAG_KEY;
>  else
>  frame->flags &= ~AV_FRAME_FLAG_KEY;
> +    } else {
> +    if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_I)
> +    frame->flags |= AV_FRAME_FLAG_KEY;
> +    else
> +    frame->flags &= ~AV_FRAME_FLAG_KEY;
>  }
>  
>  /* update the surface properties */

Will apply,

-Haihao


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

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


Re: [FFmpeg-devel] [PATCH 07/17] qsv: Initialize impl_value

2024-05-26 Thread Xiang, Haihao
On Ma, 2024-05-27 at 01:52 +0200, Michael Niedermayer wrote:
> Fixes: The warnings from CID1598553 Uninitialized scalar variable
> 
> Passing partly initialized structs is ugly and asking for hard to reproduce
> bugs,
> I do not know if this actually fixes a bug or just avoids the uninitialized
> fields

LGTM, it might avoid issue in the future. Fortunately the uninitialized field is
not used in the corresponding function call. 

Thanks
Haihao

> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/qsv.c  | 2 +-
>  libavutil/hwcontext_qsv.c | 8 
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 6bbfe2a5a95..0c6fbd0dc09 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -496,7 +496,7 @@ static int qsv_new_mfx_loader(AVCodecContext *avctx,
>  mfxStatus sts;
>  mfxLoader loader = NULL;
>  mfxConfig cfg;
> -    mfxVariant impl_value;
> +    mfxVariant impl_value = {0};
>  
>  loader = MFXLoad();
>  if (!loader) {
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index f3d919daea1..7cec3474786 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -839,7 +839,7 @@ static int qsv_d3d11_update_config(void *ctx, mfxHDL
> handle, mfxConfig cfg)
>  IDXGIDevice *pDXGIDevice = NULL;
>  HRESULT hr;
>  ID3D11Device *device = handle;
> -    mfxVariant impl_value;
> +    mfxVariant impl_value = {0};
>  
>  hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice,
> (void**)&pDXGIDevice);
>  if (SUCCEEDED(hr)) {
> @@ -913,7 +913,7 @@ static int qsv_d3d9_update_config(void *ctx, mfxHDL
> handle, mfxConfig cfg)
>  LUID luid;
>  D3DDEVICE_CREATION_PARAMETERS params;
>  HRESULT hr;
> -    mfxVariant impl_value;
> +    mfxVariant impl_value = {0};
>  
>  hr = IDirect3DDeviceManager9_OpenDeviceHandle(devmgr, &device_handle);
>  if (FAILED(hr)) {
> @@ -995,7 +995,7 @@ static int qsv_va_update_config(void *ctx, mfxHDL handle,
> mfxConfig cfg)
>  VADisplayAttribute attr = {
>  .type = VADisplayPCIID,
>  };
> -    mfxVariant impl_value;
> +    mfxVariant impl_value = {0};
>  
>  vas = vaGetDisplayAttributes(dpy, &attr, 1);
>  if (vas == VA_STATUS_SUCCESS && attr.flags !=
> VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
> @@ -1036,7 +1036,7 @@ static int qsv_new_mfx_loader(void *ctx,
>  mfxStatus sts;
>  mfxLoader loader = NULL;
>  mfxConfig cfg;
> -    mfxVariant impl_value;
> +    mfxVariant impl_value = {0};
>  
>  *ploader = NULL;
>  loader = MFXLoad();

___
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] lavc/qsvenc: respect user's setting for keyframes

2024-05-23 Thread Xiang, Haihao
From: Haihao Xiang 

For example:
./ffmpeg -hwaccel qsv -i input.mp4 -force_key_frames:v source -c:v
hevc_qsv -f null -

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

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3df355ce78..8200a14012 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -2482,7 +2482,7 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 
 if (frame->pict_type == AV_PICTURE_TYPE_I) {
 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
-if (q->forced_idr)
+if ((frame->flags & AV_FRAME_FLAG_KEY) || q->forced_idr)
 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
 }
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/2] lavc/qsvdec: fix keyframes

2024-05-23 Thread Xiang, Haihao
From: Haihao Xiang 

MFX_FRAMETYPE_IDR is ORed to the frame type for AVC and HEVC keyframes,
and MFX_FRAMETYPE_I is taken as keyframe flag for other codecs when
getting the output surface from the SDK, hence we may mark the output
frame as keyframe accordingly.

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

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index df0d49bc10..6ffd498456 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -885,12 +885,18 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 frame->flags |= AV_FRAME_FLAG_INTERLACED *
 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
 frame->pict_type = 
ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
-//Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs 
are key frames.
-if (avctx->codec_id == AV_CODEC_ID_H264) {
+
+if (avctx->codec_id == AV_CODEC_ID_H264 ||
+avctx->codec_id == AV_CODEC_ID_HEVC) {
 if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
 frame->flags |= AV_FRAME_FLAG_KEY;
 else
 frame->flags &= ~AV_FRAME_FLAG_KEY;
+} else {
+if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_I)
+frame->flags |= AV_FRAME_FLAG_KEY;
+else
+frame->flags &= ~AV_FRAME_FLAG_KEY;
 }
 
 /* update the surface properties */
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/4] lavc/qsvenc: rename the skip_frame private option to qsv_skip_frame

2024-05-23 Thread Xiang, Haihao
On Do, 2024-05-23 at 11:03 +0200, Anton Khirnov wrote:
> It conflicts with the AVCodecContext option of the same name.
> ---

The skip_frame option in AVCodecContext is for decoding only, may we not use
this option for encoding ? 


>  libavcodec/qsvenc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index e3eb083746..d69dd19049 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -139,7 +139,7 @@
>  { "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100
> frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
> UINT16_MAX, VE },
>  
>  #define QSV_OPTION_SKIP_FRAME \
> -{ "skip_frame", "Allow frame skipping", OFFSET(qsv.skip_frame), 
> AV_OPT_TYPE_INT, { .i64 = MFX_SKIPFRAME_NO_SKIP }, \
> +{ "qsv_skip_frame", "Allow frame skipping", OFFSET(qsv.skip_frame), 
> AV_OPT_TYPE_INT, { .i64 = MFX_SKIPFRAME_NO_SKIP }, \
>     MFX_SKIPFRAME_NO_SKIP, MFX_SKIPFRAME_BRC_ONLY, VE, .unit = "skip_frame" },

How about changing the unit to qsv_skip_frame too ? 

Thanks
Haihao


> \
>  { "no_skip",    "Frame skipping is disabled", \
>  0, AV_OPT_TYPE_CONST, { .i64 = MFX_SKIPFRAME_NO_SKIP },   .flags
> = VE, .unit = "skip_frame" },    \

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

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


Re: [FFmpeg-devel] [PATCH 1/2] lavc/qsvdec: update HDR side data on output AVFrame for AV1 decoding

2024-05-23 Thread Xiang, Haihao
On Wo, 2024-05-22 at 12:15 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> The SDK may provide HDR metadata for HDR streams via mfxExtBuffer
> attached on output mfxFrameSurface1
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/qsvdec.c | 48 -
>  1 file changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index df0d49bc10..7741baff06 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -538,7 +538,8 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext
> *q, QSVFrame *frame)
>  #endif
>  
>  #if QSV_VERSION_ATLEAST(1, 35)
> -    if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id ==
> AV_CODEC_ID_HEVC) {
> +    if ((QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id ==
> AV_CODEC_ID_HEVC) ||
> +    (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id ==
> AV_CODEC_ID_AV1)) {
>  frame->mdcv.Header.BufferId =
> MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
>  frame->mdcv.Header.BufferSz = sizeof(frame->mdcv);
>  // The data in mdcv is valid when this flag is 1
> @@ -742,6 +743,45 @@ static int qsv_export_hdr_side_data(AVCodecContext
> *avctx, mfxExtMasteringDispla
>  return 0;
>  }
>  
> +static int qsv_export_hdr_side_data_av1(AVCodecContext *avctx,
> mfxExtMasteringDisplayColourVolume *mdcv,
> +    mfxExtContentLightLevelInfo *clli,
> AVFrame *frame)
> +{
> +    if (mdcv->InsertPayloadToggle) {
> +    AVMasteringDisplayMetadata *mastering =
> av_mastering_display_metadata_create_side_data(frame);
> +    const int chroma_den   = 1 << 16;
> +    const int max_luma_den = 1 << 8;
> +    const int min_luma_den = 1 << 14;
> +
> +    if (!mastering)
> +    return AVERROR(ENOMEM);
> +
> +    for (int i = 0; i < 3; i++) {
> +    mastering->display_primaries[i][0] = av_make_q(mdcv-
> >DisplayPrimariesX[i], chroma_den);
> +    mastering->display_primaries[i][1] = av_make_q(mdcv-
> >DisplayPrimariesY[i], chroma_den);
> +    }
> +
> +    mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
> +    mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
> +
> +    mastering->max_luminance = av_make_q(mdcv-
> >MaxDisplayMasteringLuminance, max_luma_den);
> +    mastering->min_luminance = av_make_q(mdcv-
> >MinDisplayMasteringLuminance, min_luma_den);
> +
> +    mastering->has_luminance = 1;
> +    mastering->has_primaries = 1;
> +    }
> +
> +    if (clli->InsertPayloadToggle) {
> +    AVContentLightMetadata *light =
> av_content_light_metadata_create_side_data(frame);
> +    if (!light)
> +    return AVERROR(ENOMEM);
> +
> +    light->MaxCLL  = clli->MaxContentLightLevel;
> +    light->MaxFALL = clli->MaxPicAverageLightLevel;
> +    }
> +
> +    return 0;
> +}
> +
>  #endif
>  
>  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
> @@ -874,6 +914,12 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>  if (ret < 0)
>  return ret;
>  }
> +
> +    if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id ==
> AV_CODEC_ID_AV1) {
> +    ret = qsv_export_hdr_side_data_av1(avctx, &aframe.frame->mdcv,
> &aframe.frame->clli, frame);
> +    if (ret < 0)
> +    return ret;
> +    }
>  #endif
>  
>  frame->repeat_pict =

Will apply,

-Haihao


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

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


Re: [FFmpeg-devel] [PATCH v1 1/2] lavc/qsvdec: Allow decoders to export crop information

2024-05-23 Thread Xiang, Haihao
On Ma, 2024-05-20 at 10:05 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/qsvdec.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index a51ddace62..12cf630593 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -859,6 +859,10 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>  else
>  frame->flags &= ~AV_FRAME_FLAG_KEY;
>  }
> +    frame->crop_left   = outsurf->Info.CropX;
> +    frame->crop_top    = outsurf->Info.CropY;
> +    frame->crop_right  = outsurf->Info.Width - (outsurf->Info.CropX +
> outsurf->Info.CropW);
> +    frame->crop_bottom = outsurf->Info.Height - (outsurf->Info.CropY +
> outsurf->Info.CropH);
>  
>  /* update the surface properties */
>  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
> @@ -1148,7 +1152,7 @@ const FFCodec ff_##x##_qsv_decoder = { \
>  .p.priv_class   = &x##_qsv_class, \
>  .hw_configs = qsv_hw_configs, \
>  .p.wrapper_name = "qsv", \
> -    .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
> +    .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
> FF_CODEC_CAP_EXPORTS_CROPPING, \
>  }; \
>  
>  #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x,
> X, bsf_name, options)

patchset LGTM, will apply

Thanks
Haihao


___
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/x86/vvc/vvc_sad: fix assembler error

2024-05-22 Thread Xiang, Haihao
From: Haihao Xiang 

X86ASMlibavcodec/x86/vvc/vvc_sad.o
libavcodec/x86/vvc/vvc_sad.asm:85: error: invalid number of operands
libavcodec/x86/vvc/vvc_sad.asm:87: error: invalid number of operands

Signed-off-by: Haihao Xiang 
---
 libavcodec/x86/vvc/vvc_sad.asm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index 13224583a5..b468d89ac2 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -82,9 +82,9 @@ cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, row_
 vvc_sad_8:
 .loop_height:
 movu  xm0, [src1q]
-vinserti128m0, [src1q + MAX_PB_SIZE * ROWS * 2], 1
+vinserti128m0, m0, [src1q + MAX_PB_SIZE * ROWS * 2], 1
 movu  xm1, [src2q]
-vinserti128m1, [src2q + MAX_PB_SIZE * ROWS * 2], 1
+vinserti128m1, m1, [src2q + MAX_PB_SIZE * ROWS * 2], 1
 
 MIN_MAX_SADm1, m0, m2
 pmaddwdm1, m4
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/2] lavc/qsvenc_av1: accept HDR metadata if have

2024-05-21 Thread Xiang, Haihao
From: Haihao Xiang 

The sdk av1 encoder can accept HDR metadata via mfxEncodeCtrl::ExtParam.

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

diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
index 33727bb07e..56002746b9 100644
--- a/libavcodec/qsvenc_av1.c
+++ b/libavcodec/qsvenc_av1.c
@@ -25,6 +25,8 @@
 #include 
 
 #include "libavutil/common.h"
+#include "libavutil/mastering_display_metadata.h"
+#include "libavutil/mem.h"
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
@@ -39,6 +41,75 @@ typedef struct QSVAV1EncContext {
 QSVEncContext qsv;
 } QSVAV1EncContext;
 
+static int qsv_av1_set_encode_ctrl(AVCodecContext *avctx,
+   const AVFrame *frame, mfxEncodeCtrl 
*enc_ctrl)
+{
+QSVAV1EncContext *q = avctx->priv_data;
+AVFrameSideData *sd;
+
+if (!frame || !QSV_RUNTIME_VERSION_ATLEAST(q->qsv.ver, 2, 11))
+return 0;
+
+sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd) {
+AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata 
*)sd->data;
+if (mdm->has_primaries && mdm->has_luminance) {
+const int chroma_den   = 1 << 16;
+const int max_luma_den = 1 << 8;
+const int min_luma_den = 1 << 14;
+mfxExtMasteringDisplayColourVolume *mdcv = 
av_mallocz(sizeof(*mdcv));
+if (!mdcv)
+return AVERROR(ENOMEM);
+
+mdcv->Header.BufferId = 
MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
+mdcv->Header.BufferSz = sizeof(*mdcv);
+
+for (int i = 0; i < 3; i++) {
+mdcv->DisplayPrimariesX[i] =
+av_rescale(mdm->display_primaries[i][0].num, chroma_den,
+   mdm->display_primaries[i][0].den);
+mdcv->DisplayPrimariesY[i] =
+av_rescale(mdm->display_primaries[i][1].num, chroma_den,
+   mdm->display_primaries[i][1].den);
+}
+
+mdcv->WhitePointX =
+av_rescale(mdm->white_point[0].num, chroma_den,
+   mdm->white_point[0].den);
+mdcv->WhitePointY =
+av_rescale(mdm->white_point[1].num, chroma_den,
+   mdm->white_point[1].den);
+
+mdcv->MaxDisplayMasteringLuminance =
+av_rescale(mdm->max_luminance.num, max_luma_den,
+   mdm->max_luminance.den);
+mdcv->MinDisplayMasteringLuminance =
+av_rescale(mdm->min_luminance.num, min_luma_den,
+   mdm->min_luminance.den);
+
+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(*clli));
+if (!clli)
+return AVERROR(ENOMEM);
+
+clli->Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
+clli->Header.BufferSz = sizeof(*clli);
+
+clli->MaxContentLightLevel  = clm->MaxCLL;
+clli->MaxPicAverageLightLevel   = clm->MaxFALL;
+
+enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)clli;
+}
+
+return 0;
+}
+
 static av_cold int qsv_enc_init(AVCodecContext *avctx)
 {
 QSVAV1EncContext *q = avctx->priv_data;
@@ -61,6 +132,8 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx)
return ret;
 }
 
+q->qsv.set_encode_ctrl_cb = qsv_av1_set_encode_ctrl;
+
 return ff_qsv_enc_init(avctx, &q->qsv);
 }
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/2] lavc/qsvdec: update HDR side data on output AVFrame for AV1 decoding

2024-05-21 Thread Xiang, Haihao
From: Haihao Xiang 

The SDK may provide HDR metadata for HDR streams via mfxExtBuffer
attached on output mfxFrameSurface1

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 48 -
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index df0d49bc10..7741baff06 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -538,7 +538,8 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
 #endif
 
 #if QSV_VERSION_ATLEAST(1, 35)
-if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == 
AV_CODEC_ID_HEVC) {
+if ((QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == 
AV_CODEC_ID_HEVC) ||
+(QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == 
AV_CODEC_ID_AV1)) {
 frame->mdcv.Header.BufferId = 
MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
 frame->mdcv.Header.BufferSz = sizeof(frame->mdcv);
 // The data in mdcv is valid when this flag is 1
@@ -742,6 +743,45 @@ static int qsv_export_hdr_side_data(AVCodecContext *avctx, 
mfxExtMasteringDispla
 return 0;
 }
 
+static int qsv_export_hdr_side_data_av1(AVCodecContext *avctx, 
mfxExtMasteringDisplayColourVolume *mdcv,
+mfxExtContentLightLevelInfo *clli, 
AVFrame *frame)
+{
+if (mdcv->InsertPayloadToggle) {
+AVMasteringDisplayMetadata *mastering = 
av_mastering_display_metadata_create_side_data(frame);
+const int chroma_den   = 1 << 16;
+const int max_luma_den = 1 << 8;
+const int min_luma_den = 1 << 14;
+
+if (!mastering)
+return AVERROR(ENOMEM);
+
+for (int i = 0; i < 3; i++) {
+mastering->display_primaries[i][0] = 
av_make_q(mdcv->DisplayPrimariesX[i], chroma_den);
+mastering->display_primaries[i][1] = 
av_make_q(mdcv->DisplayPrimariesY[i], chroma_den);
+}
+
+mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
+mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
+
+mastering->max_luminance = 
av_make_q(mdcv->MaxDisplayMasteringLuminance, max_luma_den);
+mastering->min_luminance = 
av_make_q(mdcv->MinDisplayMasteringLuminance, min_luma_den);
+
+mastering->has_luminance = 1;
+mastering->has_primaries = 1;
+}
+
+if (clli->InsertPayloadToggle) {
+AVContentLightMetadata *light = 
av_content_light_metadata_create_side_data(frame);
+if (!light)
+return AVERROR(ENOMEM);
+
+light->MaxCLL  = clli->MaxContentLightLevel;
+light->MaxFALL = clli->MaxPicAverageLightLevel;
+}
+
+return 0;
+}
+
 #endif
 
 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
@@ -874,6 +914,12 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 if (ret < 0)
 return ret;
 }
+
+if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == 
AV_CODEC_ID_AV1) {
+ret = qsv_export_hdr_side_data_av1(avctx, &aframe.frame->mdcv, 
&aframe.frame->clli, frame);
+if (ret < 0)
+return ret;
+}
 #endif
 
 frame->repeat_pict =
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_qsv: fix GCC 14.1 warnings

2024-05-21 Thread Xiang, Haihao
On Ma, 2024-05-20 at 02:37 +, Wu, Tong1 wrote:
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of Oleg
> > Tolmatcev
> > Sent: Saturday, May 18, 2024 3:39 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_qsv: fix GCC 14.1 warnings
> > 
> > This patch fixes warnings produced by GCC 14.1 in hwcontext_qsv.c. It
> > fixes the issue https://trac.ffmpeg.org/ticket/11004.
> > 
> 
> Patch works for me. Thanks.
> 
> -Tong

Applied, thx

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

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


Re: [FFmpeg-devel] [PATCH 2/2] lavc/qsvenc_av1: accept HDR metadata if have

2024-05-21 Thread Xiang, Haihao
On Di, 2024-05-21 at 08:35 +0200, Andreas Rheinhardt wrote:
> Xiang, Haihao:
> > From: Haihao Xiang 
> > 
> > The sdk av1 encoder can accept HDR metadata via mfxEncodeCtrl::ExtParam.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  libavcodec/qsvenc_av1.c | 75 +
> >  1 file changed, 75 insertions(+)
> > 
> > diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
> > index 33727bb07e..a7d35d7bef 100644
> > --- a/libavcodec/qsvenc_av1.c
> > +++ b/libavcodec/qsvenc_av1.c
> > @@ -26,6 +26,8 @@
> >  
> >  #include "libavutil/common.h"
> >  #include "libavutil/opt.h"
> > +#include "libavutil/mem.h"
> > +#include "libavutil/mastering_display_metadata.h"
> 
> Breaks alphabetical ordering

Thanks, I will fix it in the new version.

> 
> >  
> >  #include "avcodec.h"
> >  #include "codec_internal.h"
> > @@ -39,6 +41,77 @@ typedef struct QSVAV1EncContext {
> >  QSVEncContext qsv;
> >  } QSVAV1EncContext;
> >  
> > +static int qsv_av1_set_encode_ctrl(AVCodecContext *avctx,
> > +   const AVFrame *frame, mfxEncodeCtrl
> > *enc_ctrl)
> > +{
> > +    QSVAV1EncContext *q = avctx->priv_data;
> > +    AVFrameSideData *sd;
> > +
> > +    if (!frame || !QSV_RUNTIME_VERSION_ATLEAST(q->qsv.ver, 2, 11))
> > +    return 0;
> > +
> > +    sd = av_frame_get_side_data(frame,
> > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
> > +    if (sd) {
> > +    AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd-
> > >data;
> > +
> > +    if (mdm->has_primaries && mdm->has_luminance) {
> > +    const int chroma_den   = 1 << 16;
> > +    const int max_luma_den = 1 << 8;
> > +    const int min_luma_den = 1 << 14;
> > +    int i;
> 
> Should have loop-scope

Thanks, I will fix it in the new version.

> 
> > +    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++) {
> > +    mdcv->DisplayPrimariesX[i] =
> > +    av_rescale(mdm->display_primaries[i][0].num,
> > chroma_den,
> > +   mdm->display_primaries[i][0].den);
> > +    mdcv->DisplayPrimariesY[i] =
> > +    av_rescale(mdm->display_primaries[i][1].num,
> > chroma_den,
> > +   mdm->display_primaries[i][1].den);
> > +    }
> > +
> > +    mdcv->WhitePointX =
> > +    av_rescale(mdm->white_point[0].num, chroma_den,
> > +   mdm->white_point[0].den);
> > +    mdcv->WhitePointY =
> > +    av_rescale(mdm->white_point[1].num, chroma_den,
> > +   mdm->white_point[1].den);
> > +
> > +    mdcv->MaxDisplayMasteringLuminance =
> > +    av_rescale(mdm->max_luminance.num, max_luma_den,
> > +   mdm->max_luminance.den);
> > +    mdcv->MinDisplayMasteringLuminance =
> > +    av_rescale(mdm->min_luminance.num, min_luma_den,
> > +   mdm->min_luminance.den);
> > +
> > +    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));
> 
> sizeof(*clli)
> 
> But actually, both allocations seem to be unnecessary: This callback is
> only called when there is a QSVFrame and it already contains a
> mfxExtContentLightLevelInfo and mfxExtMasteringDisplayColourVolume (used
> by the decoder), so why not simply reuse that? The type of
> set_encode_ctrl_cb would need to be changed of course.
> 
> (Btw: The relevant QSVFrame fields are under "#if QSV_VERSION_ATL

[FFmpeg-devel] [PATCH 2/2] lavc/qsvenc_av1: accept HDR metadata if have

2024-05-20 Thread Xiang, Haihao
From: Haihao Xiang 

The sdk av1 encoder can accept HDR metadata via mfxEncodeCtrl::ExtParam.

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

diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
index 33727bb07e..a7d35d7bef 100644
--- a/libavcodec/qsvenc_av1.c
+++ b/libavcodec/qsvenc_av1.c
@@ -26,6 +26,8 @@
 
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
+#include "libavutil/mem.h"
+#include "libavutil/mastering_display_metadata.h"
 
 #include "avcodec.h"
 #include "codec_internal.h"
@@ -39,6 +41,77 @@ typedef struct QSVAV1EncContext {
 QSVEncContext qsv;
 } QSVAV1EncContext;
 
+static int qsv_av1_set_encode_ctrl(AVCodecContext *avctx,
+   const AVFrame *frame, mfxEncodeCtrl 
*enc_ctrl)
+{
+QSVAV1EncContext *q = avctx->priv_data;
+AVFrameSideData *sd;
+
+if (!frame || !QSV_RUNTIME_VERSION_ATLEAST(q->qsv.ver, 2, 11))
+return 0;
+
+sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd) {
+AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata 
*)sd->data;
+
+if (mdm->has_primaries && mdm->has_luminance) {
+const int chroma_den   = 1 << 16;
+const int max_luma_den = 1 << 8;
+const int min_luma_den = 1 << 14;
+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++) {
+mdcv->DisplayPrimariesX[i] =
+av_rescale(mdm->display_primaries[i][0].num, chroma_den,
+   mdm->display_primaries[i][0].den);
+mdcv->DisplayPrimariesY[i] =
+av_rescale(mdm->display_primaries[i][1].num, chroma_den,
+   mdm->display_primaries[i][1].den);
+}
+
+mdcv->WhitePointX =
+av_rescale(mdm->white_point[0].num, chroma_den,
+   mdm->white_point[0].den);
+mdcv->WhitePointY =
+av_rescale(mdm->white_point[1].num, chroma_den,
+   mdm->white_point[1].den);
+
+mdcv->MaxDisplayMasteringLuminance =
+av_rescale(mdm->max_luminance.num, max_luma_den,
+   mdm->max_luminance.den);
+mdcv->MinDisplayMasteringLuminance =
+av_rescale(mdm->min_luminance.num, min_luma_den,
+   mdm->min_luminance.den);
+
+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  = clm->MaxCLL;
+clli->MaxPicAverageLightLevel   = clm->MaxFALL;
+
+enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)clli;
+}
+
+return 0;
+}
+
 static av_cold int qsv_enc_init(AVCodecContext *avctx)
 {
 QSVAV1EncContext *q = avctx->priv_data;
@@ -61,6 +134,8 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx)
return ret;
 }
 
+q->qsv.set_encode_ctrl_cb = qsv_av1_set_encode_ctrl;
+
 return ff_qsv_enc_init(avctx, &q->qsv);
 }
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/2] lavc/qsvdec: update HDR side data on output AVFrame for AV1 decoding

2024-05-20 Thread Xiang, Haihao
From: Haihao Xiang 

The SDK may provides HDR metadata for HDR streams via mfxExtBuffer
attached on output mfxFrameSurface1

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 49 -
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index df0d49bc10..7ffc7f0571 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -538,7 +538,8 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
 #endif
 
 #if QSV_VERSION_ATLEAST(1, 35)
-if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == 
AV_CODEC_ID_HEVC) {
+if ((QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 35) && avctx->codec_id == 
AV_CODEC_ID_HEVC) ||
+(QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == 
AV_CODEC_ID_AV1)) {
 frame->mdcv.Header.BufferId = 
MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME;
 frame->mdcv.Header.BufferSz = sizeof(frame->mdcv);
 // The data in mdcv is valid when this flag is 1
@@ -742,6 +743,46 @@ static int qsv_export_hdr_side_data(AVCodecContext *avctx, 
mfxExtMasteringDispla
 return 0;
 }
 
+static int qsv_export_hdr_side_data_av1(AVCodecContext *avctx, 
mfxExtMasteringDisplayColourVolume *mdcv,
+mfxExtContentLightLevelInfo *clli, 
AVFrame *frame)
+{
+if (mdcv->InsertPayloadToggle) {
+AVMasteringDisplayMetadata *mastering = 
av_mastering_display_metadata_create_side_data(frame);
+const int chroma_den   = 1 << 16;
+const int max_luma_den = 1 << 8;
+const int min_luma_den = 1 << 14;
+int i;
+
+if (!mastering)
+return AVERROR(ENOMEM);
+
+for (i = 0; i < 3; i++) {
+mastering->display_primaries[i][0] = 
av_make_q(mdcv->DisplayPrimariesX[i], chroma_den);
+mastering->display_primaries[i][1] = 
av_make_q(mdcv->DisplayPrimariesY[i], chroma_den);
+}
+
+mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
+mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
+
+mastering->max_luminance = 
av_make_q(mdcv->MaxDisplayMasteringLuminance, max_luma_den);
+mastering->min_luminance = 
av_make_q(mdcv->MinDisplayMasteringLuminance, min_luma_den);
+
+mastering->has_luminance = 1;
+mastering->has_primaries = 1;
+}
+
+if (clli->InsertPayloadToggle) {
+AVContentLightMetadata *light = 
av_content_light_metadata_create_side_data(frame);
+if (!light)
+return AVERROR(ENOMEM);
+
+light->MaxCLL  = clli->MaxContentLightLevel;
+light->MaxFALL = clli->MaxPicAverageLightLevel;
+}
+
+return 0;
+}
+
 #endif
 
 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
@@ -874,6 +915,12 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 if (ret < 0)
 return ret;
 }
+
+if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && avctx->codec_id == 
AV_CODEC_ID_AV1) {
+ret = qsv_export_hdr_side_data_av1(avctx, &aframe.frame->mdcv, 
&aframe.frame->clli, frame);
+if (ret < 0)
+return ret;
+}
 #endif
 
 frame->repeat_pict =
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/vaapi_decode: Reject decoding of frames with no slices

2024-05-19 Thread Xiang, Haihao
On Ma, 2024-05-13 at 09:38 +0200, David Rosca wrote:
> Matches other hwaccels.
> ---
> v2: AVERROR
> 
>  libavcodec/vaapi_decode.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 8e9f647c20..7c91d50f7b 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -157,6 +157,11 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
>  VAStatus vas;
>  int err;
>  
> +    if (pic->nb_slices <= 0) {
> +    err = AVERROR(EINVAL);
> +    goto fail;
> +    }
> +
>  av_log(avctx, AV_LOG_DEBUG, "Decode to surface %#x.\n",
>     pic->output_surface);
>  

LGTM, will apply

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH] lavu/version: fix minor version

2024-05-18 Thread Xiang, Haihao
On Vr, 2024-05-17 at 13:05 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> The latest version should be 59.18.100 since commit 01c5f4ad
> 
> $ git diff 01c5f4ad~1..HEAD doc/APIchanges
> ...
> +2024-05-10 - x - lavu 59.18.100 - cpu.h
> +  Add AV_CPU_FLAG_RV_ZVBB.
> +
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavutil/version.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 3b5a2e7aaa..b9b9baf98c 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  59
> -#define LIBAVUTIL_VERSION_MINOR  17
> +#define LIBAVUTIL_VERSION_MINOR  18
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Will apply,

- Haihao

___
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] lavu/version: fix minor version

2024-05-16 Thread Xiang, Haihao
From: Haihao Xiang 

The latest version should be 59.18.100 since commit 01c5f4ad

$ git diff 01c5f4ad~1..HEAD doc/APIchanges
...
+2024-05-10 - x - lavu 59.18.100 - cpu.h
+  Add AV_CPU_FLAG_RV_ZVBB.
+

Signed-off-by: Haihao Xiang 
---
 libavutil/version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/version.h b/libavutil/version.h
index 3b5a2e7aaa..b9b9baf98c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  17
+#define LIBAVUTIL_VERSION_MINOR  18
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_decode: Reject decoding of frames with no slices

2024-05-12 Thread Xiang, Haihao
On Vr, 2024-05-10 at 11:55 +0200, David Rosca wrote:
> Matches other hwaccels.
> ---
>  libavcodec/vaapi_decode.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 8e9f647c20..3c4030c073 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -157,6 +157,11 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
>  VAStatus vas;
>  int err;
>  
> +    if (pic->nb_slices <= 0) {
> +    err = -1;

Better to return a valid averror code, e.g. AVERROR(EINVAL).

Thanks
Haihao

> +    goto fail;
> +    }
> +
>  av_log(avctx, AV_LOG_DEBUG, "Decode to surface %#x.\n",
>     pic->output_surface);
>  

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

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


Re: [FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible

2024-05-12 Thread Xiang, Haihao
On Wo, 2024-05-08 at 14:03 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavfilter/qsvvpp.c | 52 
>  1 file changed, 29 insertions(+), 23 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index c4c338b36b..1c9773df09 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -587,6 +587,26 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
>  device_ctx   = (AVHWDeviceContext *)device_ref->data;
>  device_hwctx = device_ctx->hwctx;
>  
> +    /* extract the properties of the "master" session given to us */
> +    ret = MFXQueryIMPL(device_hwctx->session, &impl);
> +    if (ret == MFX_ERR_NONE)
> +    ret = MFXQueryVersion(device_hwctx->session, &ver);
> +    if (ret != MFX_ERR_NONE) {
> +    av_log(avctx, AV_LOG_ERROR, "Error querying the session
> attributes\n");
> +    return AVERROR_UNKNOWN;
> +    }
> +
> +    if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
> +    handle_type = MFX_HANDLE_VA_DISPLAY;
> +    } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
> +    handle_type = MFX_HANDLE_D3D11_DEVICE;
> +    } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
> +    handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
> +    } else {
> +    av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
> +    return AVERROR_UNKNOWN;
> +    }
> +
>  if (outlink->format == AV_PIX_FMT_QSV) {
>  AVHWFramesContext *out_frames_ctx;
>  AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
> @@ -608,9 +628,15 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
>  out_frames_ctx->width = FFALIGN(outlink->w, 32);
>  out_frames_ctx->height    = FFALIGN(outlink->h, 32);
>  out_frames_ctx->sw_format = s->out_sw_format;
> -    out_frames_ctx->initial_pool_size = 64;
> -    if (avctx->extra_hw_frames > 0)
> -    out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
> +
> +    if (QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9) && handle_type !=
> MFX_HANDLE_D3D9_DEVICE_MANAGER)
> +    out_frames_ctx->initial_pool_size = 0;
> +    else {
> +    out_frames_ctx->initial_pool_size = 64;
> +    if (avctx->extra_hw_frames > 0)
> +    out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
> +    }
> +
>  out_frames_hwctx->frame_type  = s->out_mem_mode;
>  
>  ret = av_hwframe_ctx_init(out_frames_ref);
> @@ -636,26 +662,6 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
>  } else
>  s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
>  
> -    /* extract the properties of the "master" session given to us */
> -    ret = MFXQueryIMPL(device_hwctx->session, &impl);
> -    if (ret == MFX_ERR_NONE)
> -    ret = MFXQueryVersion(device_hwctx->session, &ver);
> -    if (ret != MFX_ERR_NONE) {
> -    av_log(avctx, AV_LOG_ERROR, "Error querying the session
> attributes\n");
> -    return AVERROR_UNKNOWN;
> -    }
> -
> -    if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
> -    handle_type = MFX_HANDLE_VA_DISPLAY;
> -    } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
> -    handle_type = MFX_HANDLE_D3D11_DEVICE;
> -    } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
> -    handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
> -    } else {
> -    av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
> -    return AVERROR_UNKNOWN;
> -    }
> -
>  ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type,
> &handle);
>  if (ret < 0)
>  return ff_qsvvpp_print_error(avctx, ret, "Error getting the session
> handle");

Will apply the patchset

- Haihao


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

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


Re: [FFmpeg-devel] [PATCH 4/4] avcodec/qsvdec: Check av_image_get_buffer_size() for failure

2024-05-12 Thread Xiang, Haihao
On Ma, 2024-05-13 at 03:20 +0200, Michael Niedermayer wrote:
> Fixes: CID1477406 Improper use of negative value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/qsvdec.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index ed0bfe4c8b8..a51ddace622 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -379,9 +379,12 @@ static int qsv_decode_init_context(AVCodecContext *avctx,
> QSVContext *q, mfxVide
>  
>  q->frame_info = param->mfx.FrameInfo;
>  
> -    if (!avctx->hw_frames_ctx)
> -    q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx-
> >pix_fmt,
> -    FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64),
> 1), av_buffer_allocz);
> +    if (!avctx->hw_frames_ctx) {
> +    ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->width,
> 128), FFALIGN(avctx->height, 64), 1);
> +    if (ret < 0)
> +    return ret;
> +    q->pool = av_buffer_pool_init(ret, av_buffer_allocz);
> +    }
>  return 0;
>  }
>  

LGTM, thx

- Haihao




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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavc/vaapi_encode_av1: implement write_extra_header callback

2024-05-07 Thread Xiang, Haihao
On Ma, 2024-04-15 at 10:07 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> This can be used to insert a metadata OBU to the stream later.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_encode_av1.c | 42 ++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
> index 02a31b894d..4b417b05e7 100644
> --- a/libavcodec/vaapi_encode_av1.c
> +++ b/libavcodec/vaapi_encode_av1.c
> @@ -41,6 +41,8 @@ typedef struct VAAPIEncodeAV1Context {
>  VAAPIEncodeContext common;
>  AV1RawOBU sh; /**< sequence header.*/
>  AV1RawOBU fh; /**< frame header.*/
> +    AV1RawOBU mh[4]; /**< metadata header.*/
> +    int nb_mh;
>  CodedBitstreamContext *cbc;
>  CodedBitstreamFragment current_obu;
>  VAConfigAttribValEncAV1 attr;
> @@ -659,6 +661,8 @@ static int
> vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
>     2 : 1));
>  }
>  
> +    priv->nb_mh = 0;
> +
>  end:
>  ff_cbs_fragment_reset(obu);
>  return ret;
> @@ -735,6 +739,39 @@ end:
>  return ret;
>  }
>  
> +static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx,
> +   VAAPIEncodePicture *pic,
> +   int index, int *type,
> +   char *data, size_t *data_len)
> +{
> +    VAAPIEncodeAV1Context  *priv = avctx->priv_data;
> +    CodedBitstreamFragment *obu  = &priv->current_obu;
> +    AV1RawOBU *mh_obu;
> +    char mh_data[MAX_PARAM_BUFFER_SIZE];
> +    size_t mh_data_len;
> +    int ret = 0;
> +
> +    if (index >= priv->nb_mh)
> +    return AVERROR_EOF;
> +
> +    mh_obu = &priv->mh[index];
> +    ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_METADATA, mh_obu);
> +    if (ret < 0)
> +    goto end;
> +
> +    ret = vaapi_encode_av1_write_obu(avctx, mh_data, &mh_data_len, obu);
> +    if (ret < 0)
> +    goto end;
> +
> +    memcpy(data, mh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
> +    *data_len = mh_data_len;
> +    *type = VAEncPackedHeaderRawData;
> +
> +end:
> +    ff_cbs_fragment_reset(obu);
> +    return ret;
> +}
> +
>  static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = {
>  { AV_PROFILE_AV1_MAIN,  8, 3, 1, 1, VAProfileAV1Profile0 },
>  { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 },
> @@ -762,6 +799,8 @@ static const VAAPIEncodeType vaapi_encode_type_av1 = {
>  
>  .slice_params_size = sizeof(VAEncTileGroupBufferAV1),
>  .init_slice_params = &vaapi_encode_av1_init_slice_params,
> +
> +    .write_extra_header = &vaapi_encode_av1_write_extra_header,
>  };
>  
>  static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
> @@ -776,7 +815,8 @@ static av_cold int vaapi_encode_av1_init(AVCodecContext
> *avctx)
>  
>  ctx->desired_packed_headers =
>  VA_ENC_PACKED_HEADER_SEQUENCE |
> -    VA_ENC_PACKED_HEADER_PICTURE;
> +    VA_ENC_PACKED_HEADER_PICTURE |
> +    VA_ENC_PACKED_HEADER_MISC;  // Metadata
>  
>  if (avctx->profile == AV_PROFILE_UNKNOWN)
>  avctx->profile = priv->profile;

Will apply,

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH v4 1/5] configure: Remove libva 1.x support

2024-05-07 Thread Xiang, Haihao
On Di, 2024-05-07 at 21:25 +0100, Mark Thompson wrote:
> On 07/05/2024 06:27, Xiang, Haihao wrote:
> > On So, 2024-05-05 at 20:01 +0100, Mark Thompson wrote:
> > > libva 2.0 was released in 2017 and the 2.x versions are included in all
> > > supported distributions nowadays.  Various features no longer need any
> > > configure check after this command, including all codecs except AV1.
> > > Note that the libva version is the API version plus one, so this is
> > > removing support for VAAPI 0.x and requiring VAAPI 1.x.
> > > ---
> > > Changes to the series since v3:
> > > * Reorder so that the series doesn't need to be squashed.
> > > * New patch to remove the driver quirk support (deprecated in the public
> > >   header, but will have no effect if set).
> > > 
> > >  configure | 25 ++---
> > >  1 file changed, 6 insertions(+), 19 deletions(-)
> > > 
> > > diff --git a/configure b/configure
> > > index ed74583a6f..69fde0bf35 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -2625,7 +2625,6 @@ CONFIG_EXTRA="
> > >  texturedsp
> > >  texturedspenc
> > >  tpeldsp
> > > -    vaapi_1
> > 
> > CONFIG_VAAPI_1 is used in the code. Removing this only caused compiling
> > errors.
> > 
> > libavfilter/vaapi_vpp.c: In function ‘ff_vaapi_vpp_config_output’:
> > libavfilter/vaapi_vpp.c:207:9: error: ‘CONFIG_VAAPI_1’ undeclared (first use
> > in
> > this function); did you mean ‘CONFIG_VAAPI’?
> >   207 | if (CONFIG_VAAPI_1)
> >   | ^~
> >   | CONFIG_VAAPI
> 
> You are correct; I didn't think this split through carefully.
> 
> I suggest returning to the original idea of squashing before push so that the
> removal is atomic?  I'm not sure it's worth dealing with the intermediate
> states given that they have no particular use.

I'm ok if you want to use a squash commit.

BRs
Haihao

___
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 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 10d970652e..c4c338b36b 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -308,7 +308,7 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, 
AVFilterLink *link)
 
 frames_ctx   = (AVHWFramesContext *)link->hw_frames_ctx->data;
 frames_hwctx = frames_ctx->hwctx;
-*frameinfo   = frames_hwctx->surfaces[0].Info;
+*frameinfo   = frames_hwctx->nb_surfaces ? 
frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
 } else {
 pix_fmt = link->format;
 desc = av_pix_fmt_desc_get(pix_fmt);
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 52 
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index c4c338b36b..1c9773df09 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -587,6 +587,26 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 device_ctx   = (AVHWDeviceContext *)device_ref->data;
 device_hwctx = device_ctx->hwctx;
 
+/* extract the properties of the "master" session given to us */
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
+return AVERROR_UNKNOWN;
+}
+
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
+}
+
 if (outlink->format == AV_PIX_FMT_QSV) {
 AVHWFramesContext *out_frames_ctx;
 AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
@@ -608,9 +628,15 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 out_frames_ctx->width = FFALIGN(outlink->w, 32);
 out_frames_ctx->height= FFALIGN(outlink->h, 32);
 out_frames_ctx->sw_format = s->out_sw_format;
-out_frames_ctx->initial_pool_size = 64;
-if (avctx->extra_hw_frames > 0)
-out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9) && handle_type != 
MFX_HANDLE_D3D9_DEVICE_MANAGER)
+out_frames_ctx->initial_pool_size = 0;
+else {
+out_frames_ctx->initial_pool_size = 64;
+if (avctx->extra_hw_frames > 0)
+out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+}
+
 out_frames_hwctx->frame_type  = s->out_mem_mode;
 
 ret = av_hwframe_ctx_init(out_frames_ref);
@@ -636,26 +662,6 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 } else
 s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
 
-/* extract the properties of the "master" session given to us */
-ret = MFXQueryIMPL(device_hwctx->session, &impl);
-if (ret == MFX_ERR_NONE)
-ret = MFXQueryVersion(device_hwctx->session, &ver);
-if (ret != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
-return AVERROR_UNKNOWN;
-}
-
-if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_VA_DISPLAY;
-} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D11_DEVICE;
-} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
-} else {
-av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
-return AVERROR_UNKNOWN;
-}
-
 ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
 if (ret < 0)
 return ff_qsvvpp_print_error(avctx, ret, "Error getting the session 
handle");
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 7/9] lavc/qsvdec: require a dynamic frame pool if possible

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

This allows a downstream element stores more frames from qsv decoders
and fixes error in get_buffer().

$ ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i input.mp4 -vf
reverse -f null -

[vist#0:0/h264 @ 0x562248f12c50] Decoding error: Cannot allocate memory
[h264_qsv @ 0x562248f66b10] get_buffer() failed

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 57 +++--
 1 file changed, 45 insertions(+), 12 deletions(-)

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

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

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


[FFmpeg-devel] [PATCH v2 6/9] lavc/qsvenc: use the right info for encoding

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

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

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index d881c11160..3df355ce78 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -745,8 +745,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx= (AVHWFramesContext 
*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
@@ -869,8 +870,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

When the external allocator is used for dynamic frame allocation, only
video memory is supported, the SDK doesn't lock/unlock the memory block
via Lock()/Unlock() calls.

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsv.c | 68 +++-
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b07302cdf6..6bbfe2a5a9 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -825,8 +825,16 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
-mfxFrameInfo  *i1 = &frames_hwctx->surfaces[0].Info;
+mfxFrameInfo  *i1;
 
+if (!frames_hwctx->nb_surfaces) {
+av_log(ctx->logctx, AV_LOG_DEBUG,
+   "Dynamic frame pools, no frame is pre-allocated\n");
+
+return MFX_ERR_NONE;
+}
+
+i1 = &frames_hwctx->surfaces[0].Info;
 if (i->Width  > i1->Width  || i->Height > i1->Height ||
 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
 av_log(ctx->logctx, AV_LOG_ERROR, "Mismatching surface properties 
in an "
@@ -845,6 +853,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 } else if (req->Type & MFX_MEMTYPE_INTERNAL_FRAME) {
 /* internal frames -- allocate a new hw frames context */
 AVHWFramesContext *ext_frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *ext_frames_hwctx = ext_frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
 
 AVBufferRef *frames_ref;
@@ -852,6 +861,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx;
 AVQSVFramesContext *frames_hwctx;
 
+if (!ext_frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
 frames_ref = av_hwframe_ctx_alloc(ext_frames_ctx->device_ref);
 if (!frames_ref)
 return MFX_ERR_MEMORY_ALLOC;
@@ -899,6 +911,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 
 static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
 {
+if (!resp->mids)
+return MFX_ERR_NONE;
+
 av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]);
 ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]);
 av_freep(&resp->mids);
@@ -907,11 +922,20 @@ static mfxStatus qsv_frame_free(mfxHDL pthis, 
mfxFrameAllocResponse *resp)
 
 static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
 {
-QSVMid *qsv_mid = mid;
-AVHWFramesContext *hw_frames_ctx = 
(AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
-AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+AVHWFramesContext *hw_frames_ctx;
+AVQSVFramesContext *hw_frames_hwctx;
 int ret;
 
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
+qsv_mid = mid;
+hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
+hw_frames_hwctx = hw_frames_ctx->hwctx;
 if (qsv_mid->locked_frame)
 return MFX_ERR_UNDEFINED_BEHAVIOR;
 
@@ -964,8 +988,15 @@ fail:
 
 static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData 
*ptr)
 {
-QSVMid *qsv_mid = mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
 
+qsv_mid = mid;
 av_frame_free(&qsv_mid->locked_frame);
 av_frame_free(&qsv_mid->hw_frame);
 
@@ -974,9 +1005,18 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId 
mid, mfxFrameData *ptr)
 
 static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-QSVMid *qsv_mid = (QSVMid*)mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
-mfxHDLPair *pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+mfxHDLPair *pair_src;
+
+if (frames_hwctx->nb_surfaces) {
+QSVMid *qsv_mid = (QSVMid*)mid;
+pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+} else {
+pair_src = (mfxHDLPair*)mid;
+}
 
 pair_dst->first = pair_src->first;
 
@@ -1090,13 +1130,17 @@ int ff_qsv_init_session_fr

[FFmpeg-devel] [PATCH v2 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 131 +-
 1 file changed, 129 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 1d3091e6f8..8b7b4dc501 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2122,8 +2122,8 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 }
 }
 
-static int qsv_map_to(AVHWFramesContext *dst_ctx,
-  AVFrame *dst, const AVFrame *src, int flags)
+static int qsv_fixed_pool_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
 {
 AVQSVFramesContext *hwctx = dst_ctx->hwctx;
 int i, err, index = -1;
@@ -2182,6 +2182,133 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx,
 return 0;
 }
 
+static void qsv_dynamic_pool_unmap(AVHWFramesContext *ctx, HWMapDescriptor 
*hwmap)
+{
+mfxFrameSurface1 *surfaces_internal = (mfxFrameSurface1 *)hwmap->priv;
+mfxHDLPair *handle_pairs_internal = (mfxHDLPair 
*)surfaces_internal->Data.MemId;
+AVHWFramesContext *src_ctx = (AVHWFramesContext 
*)ffhwframesctx(ctx)->source_frames->data;
+
+switch (src_ctx->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+av_freep(&handle_pairs_internal->first);
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+/* Do nothing */
+break;
+}
+#endif
+default:
+av_log(ctx, AV_LOG_ERROR, "Should not reach here. \n");
+break;
+}
+
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+}
+
+static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx,
+   AVFrame *dst, const AVFrame *src, int flags)
+{
+mfxFrameSurface1 *surfaces_internal = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret = 0;
+
+surfaces_internal = av_calloc(1, sizeof(*surfaces_internal));
+if (!surfaces_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+ret = qsv_init_surface(dst_ctx, surfaces_internal);
+if (ret < 0)
+goto fail;
+
+switch (src->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal) {
+ret =AVERROR(ENOMEM);
+goto fail;
+}
+
+*surface_id_internal = (VASurfaceID)(uintptr_t)src->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+AVHWFramesContext *src_ctx = 
(AVHWFramesContext*)src->hw_frames_ctx->data;
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+handle_pairs_internal->first = (mfxMemId)src->data[0];
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+} else {
+handle_pairs_internal->second = (mfxMemId)src->data[1];
+}
+
+break;
+}
+#endif
+default:
+ret = AVERROR(ENOSYS);
+goto fail;
+}
+
+surfaces_internal->Data.MemId = (mfxMemId)handle_pairs_internal;
+
+ret = ff_hwframe_map_create(dst->hw_frames_ctx,
+dst, src, qsv_dynamic_pool_unmap, 
surfaces_internal);
+if (ret)
+goto fail;
+
+dst->width   = src->width;
+dst->height  = src->height;
+dst->data[3] = (uint8_t*)surfaces_internal;
+
+return 0;
+
+fail:
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+return ret;
+}
+
+static int qsv_map_to(AVHWFramesContext *dst_ctx,
+  AVFrame *dst, const AVFrame *src, int flags)
+{
+AVQSVFramesContext *hwctx = dst_ctx->hwctx;
+
+if (hwctx->nb_surfaces)
+return qsv_fixed_pool_map_to(dst_ctx, dst, src, flags);
+else
+return qsv_dynamic_pool_map_to(dst_ctx, dst, src, flags);
+}
+
 static int qsv_frames_get_constraints(AVHWDeviceContext *ctx,
   const void *hwconfig,
   AVHWFramesConstraints *constraints)
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 61 ++-
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 01bd273a08..1d3091e6f8 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1972,18 +1972,52 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 return 0;
 }
 
-static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
-AVHWFramesContext *src_ctx, int flags)
+static int qsv_dynamic_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
 {
 QSVFramesContext *s = dst_ctx->hwctx;
 AVQSVFramesContext *dst_hwctx = &s->p;
-int i;
+mfxFrameSurface1 mfx_surf1;
 
-if (src_ctx->initial_pool_size == 0) {
-av_log(dst_ctx, AV_LOG_ERROR, "Only fixed-size pools can be "
-"mapped to QSV frames.\n");
-return AVERROR(EINVAL);
+switch (src_ctx->device_ctx->type) {
+#if CONFIG_VAAPI
+case AV_HWDEVICE_TYPE_VAAPI:
+dst_hwctx->frame_type  = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+break;
+#endif
+
+#if CONFIG_D3D11VA
+case AV_HWDEVICE_TYPE_D3D11VA:
+{
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
+} else {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+}
 }
+break;
+#endif
+
+default:
+return AVERROR(ENOSYS);
+}
+
+memset(&mfx_surf1, 0, sizeof(mfx_surf1));
+qsv_init_surface(dst_ctx, &mfx_surf1);
+s->frame_info = mfx_surf1.Info;
+dst_hwctx->info = &s->frame_info;
+dst_hwctx->nb_surfaces = 0;
+return 0;
+}
+
+static int qsv_fixed_frames_derive_to(AVHWFramesContext *dst_ctx,
+  AVHWFramesContext *src_ctx, int flags)
+{
+QSVFramesContext *s = dst_ctx->hwctx;
+AVQSVFramesContext *dst_hwctx = &s->p;
+int i;
 
 switch (src_ctx->device_ctx->type) {
 #if CONFIG_VAAPI
@@ -2075,6 +2109,19 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 return 0;
 }
 
+static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
+{
+if (src_ctx->initial_pool_size < 0) {
+av_log(dst_ctx, AV_LOG_ERROR, "Invalid src frame pool. \n");
+return AVERROR(EINVAL);
+} else if (src_ctx->initial_pool_size == 0) {
+return qsv_dynamic_frames_derive_to(dst_ctx, src_ctx, flags);
+} else {
+return qsv_fixed_frames_derive_to(dst_ctx, src_ctx, flags);
+}
+}
+
 static int qsv_map_to(AVHWFramesContext *dst_ctx,
   AVFrame *dst, const AVFrame *src, int flags)
 {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

When AVHWFramesContext.initial_pool_size is 0, a dynamic frame pool is
required. We may support this under certain conditions, e.g. oneVPL 2.9+
support dynamic frame allocation, we needn't provide a fixed frame pool
in the mfxFrameAllocator.Alloc callback.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 157 +-
 1 file changed, 154 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index f552811346..01bd273a08 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -118,8 +118,15 @@ typedef struct QSVFramesContext {
 #endif
 AVFrame realigned_upload_frame;
 AVFrame realigned_download_frame;
+
+mfxFrameInfo frame_info;
 } QSVFramesContext;
 
+typedef struct QSVSurface {
+mfxFrameSurface1 mfx_surface;
+AVFrame *child_frame;
+} QSVSurface;
+
 static const struct {
 enum AVPixelFormat pix_fmt;
 uint32_t   fourcc;
@@ -165,6 +172,8 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 
*surf,
   enum AVHWDeviceType base_dev_type,
   void **base_handle);
 
+static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf);
+
 /**
  * Caller needs to allocate enough space for base_handle pointer.
  **/
@@ -373,7 +382,32 @@ static void qsv_pool_release_dummy(void *opaque, uint8_t 
*data)
 {
 }
 
-static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
+static void qsv_pool_release(void *opaque, uint8_t *data)
+{
+AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext *s = ctx->hwctx;
+QSVSurface *qsv_surface = (QSVSurface *)data;
+mfxHDLPair *hdl_pair = (mfxHDLPair *)qsv_surface->mfx_surface.Data.MemId;
+AVHWFramesContext *child_frames_ctx;
+
+if (!s->child_frames_ref)
+return;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+return;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI)
+av_freep(&hdl_pair->first);
+#endif
+
+av_freep(&hdl_pair);
+av_frame_free(&qsv_surface->child_frame);
+av_freep(&qsv_surface);
+}
+
+static AVBufferRef *qsv_fixed_pool_alloc(void *opaque, size_t size)
 {
 AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
 QSVFramesContext   *s = ctx->hwctx;
@@ -388,6 +422,104 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t 
size)
 return NULL;
 }
 
+static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size)
+{
+AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext   *s = ctx->hwctx;
+AVHWFramesContext *child_frames_ctx;
+QSVSurface *qsv_surface = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret;
+
+if (!s->child_frames_ref)
+goto fail;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+goto fail;
+
+#if CONFIG_DXVA2
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+av_log(ctx, AV_LOG_ERROR,
+   "QSV on dxva2 requires a fixed frame pool size\n");
+goto fail;
+}
+#endif
+
+qsv_surface = av_calloc(1, sizeof(*qsv_surface));
+if (!qsv_surface)
+goto fail;
+
+qsv_surface->child_frame = av_frame_alloc();
+if (!qsv_surface->child_frame)
+goto fail;
+
+ret = av_hwframe_get_buffer(s->child_frames_ref, qsv_surface->child_frame, 
0);
+if (ret < 0)
+goto fail;
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal)
+goto fail;
+
+ret = qsv_init_surface(ctx, &qsv_surface->mfx_surface);
+if (ret < 0)
+goto fail;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) {
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal)
+goto fail;
+
+*surface_id_internal = 
(VASurfaceID)(uintptr_t)qsv_surface->child_frame->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+}
+#endif
+
+#if CONFIG_D3D11VA
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx;
+handle_pairs_internal->first = 
(mfxMemId)qsv_surface->child_frame->data[0];
+
+if (child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET)
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+else
+handle_pairs_internal->second = 
(mfxMemId)qsv_surface->child_frame->data[1];
+
+}
+#endif
+
+qsv_surface->mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal

[FFmpeg-devel] [PATCH v2 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool

2024-05-07 Thread Xiang, Haihao
From: Haihao Xiang 

Add AVQSVFramesContext.info and update the description.

Signed-off-by: Haihao Xiang 
---
 doc/APIchanges|  3 +++
 libavutil/hwcontext_qsv.c |  4 ++--
 libavutil/hwcontext_qsv.h | 27 +--
 libavutil/version.h   |  2 +-
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 824beec9d3..fa281cec5c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-05-xx - xx - lavu 59.18.100 - hwcontext_qsv.h
+  Add AVQSVFramesContext.info
+
 2024-05-04 - xx - lavu 59.17.100 - opt.h
   Add AV_OPT_TYPE_UINT and av_opt_eval_uint().
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index c7c7878644..f552811346 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -627,7 +627,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 QSVFramesContext   *s = ctx->hwctx;
 AVQSVFramesContext *hwctx = &s->p;
 mfxFrameInfo *i  = &req->Info;
-mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
+mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : 
hwctx->info;
 
 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
@@ -1207,7 +1207,7 @@ static int qsv_init_internal_session(AVHWFramesContext 
*ctx,
   MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
 par.AsyncDepth = 1;
 
-par.vpp.In = frames_hwctx->surfaces[0].Info;
+par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : 
*frames_hwctx->info;
 
 /* Apparently VPP requires the frame rate to be set to some value, 
otherwise
  * init will fail (probably for the framerate conversion filter). Since we
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index e2dba8ad83..35530e4e93 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -25,8 +25,8 @@
  * @file
  * An API-specific header for AV_HWDEVICE_TYPE_QSV.
  *
- * This API does not support dynamic frame pools. AVHWFramesContext.pool must
- * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 
struct.
+ * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
+ * to a mfxFrameSurface1 struct.
  */
 
 /**
@@ -51,13 +51,36 @@ typedef struct AVQSVDeviceContext {
  * This struct is allocated as AVHWFramesContext.hwctx
  */
 typedef struct AVQSVFramesContext {
+/**
+ * A pointer to a mfxFrameSurface1 struct
+ *
+ * It is available when nb_surfaces is non-zero.
+ */
 mfxFrameSurface1 *surfaces;
+
+/**
+ * Number of frames in the pool
+ *
+ * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
+ * for fixed frame pools.
+ *
+ * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
+ * on d3d11va or vaapi
+ */
 intnb_surfaces;
 
 /**
  * A combination of MFX_MEMTYPE_* describing the frame pool.
  */
 int frame_type;
+
+/**
+ * A pointer to a mfxFrameInfo struct
+ *
+ * It is available when nb_surfaces is 0, all buffers allocated from the
+ * pool have the same mfxFrameInfo.
+ */
+mfxFrameInfo *info;
 } AVQSVFramesContext;
 
 #endif /* AVUTIL_HWCONTEXT_QSV_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 3b5a2e7aaa..b9b9baf98c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  17
+#define LIBAVUTIL_VERSION_MINOR  18
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers

2024-05-07 Thread Xiang, Haihao
On So, 2024-04-28 at 09:26 +0200, David Rosca wrote:
> ---
>  libavcodec/vaapi_av1.c    | 2 +-
>  libavcodec/vaapi_decode.c | 3 ++-
>  libavcodec/vaapi_decode.h | 1 +
>  libavcodec/vaapi_h264.c   | 2 +-
>  libavcodec/vaapi_hevc.c   | 4 ++--
>  libavcodec/vaapi_mjpeg.c  | 2 +-
>  libavcodec/vaapi_mpeg2.c  | 2 +-
>  libavcodec/vaapi_mpeg4.c  | 2 +-
>  libavcodec/vaapi_vc1.c    | 2 +-
>  libavcodec/vaapi_vp8.c    | 2 +-
>  libavcodec/vaapi_vp9.c    | 2 +-
>  11 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 1f563483b9..4a90db1e09 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  .tg_end    = s->tg_end,
>  };
>  
> -    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
> 
> sizeof(VASliceParameterBufferAV1),
>  buffer,
>  size);
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 21b273cd0f..8e9f647c20 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>    VAAPIDecodePicture *pic,
>    const void *params_data,
> +  int nb_params,
>    size_t params_size,
>    const void *slice_data,
>    size_t slice_size)
> @@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>  
>  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
>   VASliceParameterBufferType,
> - params_size, 1, (void*)params_data,
> + params_size, nb_params, (void*)params_data,
>   &pic->slice_buffers[index]);
>  if (vas != VA_STATUS_SUCCESS) {
>  av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
> diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
> index 6beda14e52..702171e108 100644
> --- a/libavcodec/vaapi_decode.h
> +++ b/libavcodec/vaapi_decode.h
> @@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
>  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
>    VAAPIDecodePicture *pic,
>    const void *params_data,
> +  int nb_params,
>    size_t params_size,
>    const void *slice_data,
>    size_t slice_size);
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index 55cf5a05ee..b47531ce1c 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
>     slice_param.chroma_offset_l1);
>  
>  err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
> -    &slice_param,
> sizeof(slice_param),
> +    &slice_param, 1,
> sizeof(slice_param),
>  buffer, size);
>  if (err) {
>  ff_vaapi_decode_cancel(avctx, pic);
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> index 3bdd2dd1b8..3937b7574a 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
>  if (pic->last_size) {
>  last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
>  ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -    &pic->last_slice_param,
> slice_param_size,
> +    &pic->last_slice_param, 1,
> slice_param_size,
>  pic->last_buffer, pic-
> >last_size);
>  if (ret < 0)
>  goto fail;
> @@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
>  
>  if (!sh->first_slice_in_pic_flag) {
>  err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
> -    &pic->last_slice_param,
> slice_param_size,
> +    &pic->last_slice_param, 1,
> slice_param_size,
>  pic->last_buffer, pic-
> >last_size);
>  pic->la

Re: [FFmpeg-devel] [PATCH v4 1/5] configure: Remove libva 1.x support

2024-05-06 Thread Xiang, Haihao
On So, 2024-05-05 at 20:01 +0100, Mark Thompson wrote:
> libva 2.0 was released in 2017 and the 2.x versions are included in all
> supported distributions nowadays.  Various features no longer need any
> configure check after this command, including all codecs except AV1.
> Note that the libva version is the API version plus one, so this is
> removing support for VAAPI 0.x and requiring VAAPI 1.x.
> ---
> Changes to the series since v3:
> * Reorder so that the series doesn't need to be squashed.
> * New patch to remove the driver quirk support (deprecated in the public
>   header, but will have no effect if set).
> 
>  configure | 25 ++---
>  1 file changed, 6 insertions(+), 19 deletions(-)
> 
> diff --git a/configure b/configure
> index ed74583a6f..69fde0bf35 100755
> --- a/configure
> +++ b/configure
> @@ -2625,7 +2625,6 @@ CONFIG_EXTRA="
>  texturedsp
>  texturedspenc
>  tpeldsp
> -    vaapi_1

CONFIG_VAAPI_1 is used in the code. Removing this only caused compiling errors.

libavfilter/vaapi_vpp.c: In function ‘ff_vaapi_vpp_config_output’:
libavfilter/vaapi_vpp.c:207:9: error: ‘CONFIG_VAAPI_1’ undeclared (first use in
this function); did you mean ‘CONFIG_VAAPI’?
  207 | if (CONFIG_VAAPI_1)
  | ^~
  | CONFIG_VAAPI


Thanks
Haihao


>  vaapi_encode
>  vc1dsp
>  videodsp
> @@ -3189,7 +3188,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
>  hevc_dxva2_hwaccel_select="hevc_decoder"
>  hevc_nvdec_hwaccel_deps="nvdec"
>  hevc_nvdec_hwaccel_select="hevc_decoder"
> -hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
> +hevc_vaapi_hwaccel_deps="vaapi"
>  hevc_vaapi_hwaccel_select="hevc_decoder"
>  hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
>  hevc_vdpau_hwaccel_select="hevc_decoder"
> @@ -3261,7 +3260,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
>  vp9_dxva2_hwaccel_select="vp9_decoder"
>  vp9_nvdec_hwaccel_deps="nvdec"
>  vp9_nvdec_hwaccel_select="vp9_decoder"
> -vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
> +vp9_vaapi_hwaccel_deps="vaapi"
>  vp9_vaapi_hwaccel_select="vp9_decoder"
>  vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
>  vp9_vdpau_hwaccel_select="vp9_decoder"
> @@ -3354,7 +3353,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
>  hevc_qsv_encoder_select="hevcparse qsvenc"
>  hevc_rkmpp_decoder_deps="rkmpp"
>  hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
> -hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
>  hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
>  hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
>  hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
> @@ -3363,7 +3361,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
>  mjpeg_qsv_decoder_select="qsvdec"
>  mjpeg_qsv_encoder_deps="libmfx"
>  mjpeg_qsv_encoder_select="qsvenc"
> -mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
>  mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
>  mp3_mf_encoder_deps="mediafoundation"
>  mpeg1_cuvid_decoder_deps="cuvid"
> @@ -3392,7 +3389,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
>  vp8_mediacodec_encoder_deps="mediacodec"
>  vp8_qsv_decoder_select="qsvdec"
>  vp8_rkmpp_decoder_deps="rkmpp"
> -vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
>  vp8_vaapi_encoder_select="vaapi_encode"
>  vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
>  vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
> @@ -3401,7 +3397,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
>  vp9_mediacodec_encoder_deps="mediacodec"
>  vp9_qsv_decoder_select="qsvdec"
>  vp9_rkmpp_decoder_deps="rkmpp"
> -vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
>  vp9_vaapi_encoder_select="vaapi_encode"
>  vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
>  vp9_qsv_encoder_select="qsvenc"
> @@ -3952,9 +3947,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
>  yadif_cuda_filter_deps="ffnvcodec"
>  yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
>  yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
> -hstack_vaapi_filter_deps="vaapi_1"
> -vstack_vaapi_filter_deps="vaapi_1"
> -xstack_vaapi_filter_deps="vaapi_1"
> +hstack_vaapi_filter_deps="vaapi"
> +vstack_vaapi_filter_deps="vaapi"
> +xstack_vaapi_filter_deps="vaapi"
>  hstack_qsv_filter_deps="libmfx"
>  hstack_qsv_filter_select="qsvvpp"
>  vstack_qsv_filter_deps="libmfx"
> @@ -7252,7 +7247,7 @@ enabled libdrm &&
>  check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2
>  
>  enabled vaapi &&
> -    check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
> +    check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize
>  
>  if enabled vaapi; then
>  case $target_os in
> @@ -7268,18 +7263,10 @@ if enabled vaapi; then
>  check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
>  fi
>  
> -    check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
> -
> -    check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"

Re: [FFmpeg-devel] [PATCH 2/2] lavc/qsvenc: add support for oneVPL string API

2024-05-03 Thread Xiang, Haihao
On Do, 2024-02-29 at 13:34 +0800, Xiang, Haihao wrote:
> From: "Mandava, Mounika" 
> 
> A new option -qsv_params  is added, where  is a :-separated
> list of key=value parameters.
> 
> Example:
> $ ffmpeg -y -f lavfi -i testsrc -vf "format=nv12" -c:v h264_qsv -qsv_params
> "TargetUsage=1:GopPicSize=30:GopRefDist=2:TargetKbps=5000" -f null -
> 
> Signed-off-by: Mounika Mandava 
> Signed-off-by: Haihao Xiang 
> ---
>  Changelog   |  1 +
>  configure   |  2 ++
>  doc/encoders.texi   | 14 ++
>  libavcodec/qsvenc.c | 62 +
>  libavcodec/qsvenc.h |  8 +-
>  5 files changed, 86 insertions(+), 1 deletion(-)
> 
> diff --git a/Changelog b/Changelog
> index 610ee61dd6..b137d089d8 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -27,6 +27,7 @@ version :
>  - a C11-compliant compiler is now required; note that this requirement
>    will be bumped to C17 in the near future, so consider updating your
>    build environment if it lacks C17 support
> +- qsv_params option added for QSV encoders
>  
>  version 6.1:
>  - libaribcaption decoder
> diff --git a/configure b/configure
> index bb5e630bad..046c481f63 100755
> --- a/configure
> +++ b/configure
> @@ -2431,6 +2431,7 @@ TYPES_LIST="
>  struct_sockaddr_storage
>  struct_stat_st_mtim_tv_nsec
>  struct_v4l2_frmivalenum_discrete
> +    struct_mfxConfigInterface
>  "
>  
>  HAVE_LIST="
> @@ -6828,6 +6829,7 @@ elif enabled libvpl; then
>  check_pkg_config libmfx "vpl >= 2.6" "mfxvideo.h mfxdispatcher.h" MFXLoad
> || \
>  die "ERROR: libvpl >= 2.6 not found"
>  add_cflags -DMFX_DEPRECATED_OFF
> +    check_type "vpl/mfxdefs.h vpl/mfxvideo.h" "struct mfxConfigInterface"
>  fi
>  
>  if enabled libmfx; then
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 9f477d7c53..cbd3b538cf 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3485,6 +3485,20 @@ Change these value to reset qsv codec's bitrate control
> configuration.
>  @item @var{pic_timing_sei}
>  Supported in h264_qsv and hevc_qsv.
>  Change this value to reset qsv codec's pic_timing_sei configuration.
> +
> +@item @var{qsv_params}
> +Set QSV encoder parameters as a colon-separated list of key-value pairs.
> +
> +The @option{qsv_params} should be formatted as
> @code{key1=value1:key2=value2:...}.
> +
> +These parameters are passed directly to the underlying Intel Quick Sync Video
> (QSV) encoder using the MFXSetParameter function.
> +
> +Example:
> +@example
> +ffmpeg -i input.mp4 -c:v h264_qsv -qsv_params
> "CodingOption1=1:CodingOption2=2" output.mp4
> +@end example
> +
> +This option allows fine-grained control over various encoder-specific
> settings provided by the QSV encoder.
>  @end table
>  
>  @subsection H264 options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 27e0e7ee71..0189c219d2 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -31,6 +31,7 @@
>  #include "libavutil/hwcontext_qsv.h"
>  #include "libavutil/mem.h"
>  #include "libavutil/log.h"
> +#include "libavutil/dict.h"
>  #include "libavutil/time.h"
>  #include "libavutil/imgutils.h"
>  
> @@ -1609,6 +1610,11 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> QSVEncContext *q)
>  int opaque_alloc = 0;
>  int ret;
>  void *tmp;
> +#if HAVE_STRUCT_MFXCONFIGINTERFACE
> +    mfxExtBuffer ext_buf;
> +    mfxConfigInterface *iface = NULL;
> +    const AVDictionaryEntry *param = NULL;
> +#endif
>  
>  q->param.AsyncDepth = q->async_depth;
>  
> @@ -1703,6 +1709,58 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->param.ExtParam    = q->extparam;
>  q->param.NumExtParam = q->nb_extparam;
>  
> +#if HAVE_STRUCT_MFXCONFIGINTERFACE
> +    ret = MFXVideoCORE_GetHandle(q->session, MFX_HANDLE_CONFIG_INTERFACE,
> (mfxHDL *)(&iface));
> +    if (ret < 0)
> +    return ff_qsv_print_error(avctx, ret,
> +  "Error getting mfx config interface
> handle");
> +
> +    while ((param = av_dict_get(q->qsv_params, "", param,
> AV_DICT_IGNORE_SUFFIX))) {
> +    const char *param_key = param->key;
> +    const char *param_value = param->value;
> +    mfxExtBuffer *new_ext_buf;
> +    void *tmp;
> +
> +    av_log(avctx, AV_LOG_VERBOSE, "Parameter key: %s, value: %s\n",
> param_key, param_value);
> +

Re: [FFmpeg-devel] [PATCH 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool

2024-05-03 Thread Xiang, Haihao
On Do, 2024-05-02 at 20:35 +0100, Mark Thompson wrote:
> On 28/04/2024 08:39, Xiang, Haihao wrote:
> > From: Haihao Xiang 
> > 
> > Add AVQSVFramesContext.info and update the description.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  doc/APIchanges    |  3 +++
> >  libavutil/hwcontext_qsv.c |  4 ++--
> >  libavutil/hwcontext_qsv.h | 28 +---
> >  libavutil/version.h   |  4 ++--
> >  4 files changed, 32 insertions(+), 7 deletions(-)
> > 
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 0566fcdcc5..4a434b2877 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-
> > 07
> >  
> >  API changes, most recent first:
> >  
> > +2024-04-xx - xx - lavu 59.17.100 - hwcontext_qsv.h
> > +  Add AVQSVFramesContext.info
> > +
> >  2024-04-24 - 8616cfe0890 - lavu 59.16.100 - opt.h
> >    Add AV_OPT_SERIALIZE_SEARCH_CHILDREN.
> >  
> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > index c7c7878644..f552811346 100644
> > --- a/libavutil/hwcontext_qsv.c
> > +++ b/libavutil/hwcontext_qsv.c
> > @@ -627,7 +627,7 @@ static mfxStatus frame_alloc(mfxHDL pthis,
> > mfxFrameAllocRequest *req,
> >  QSVFramesContext   *s = ctx->hwctx;
> >  AVQSVFramesContext *hwctx = &s->p;
> >  mfxFrameInfo *i  = &req->Info;
> > -    mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
> > +    mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info :
> > hwctx->info;
> >  
> >  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
> >  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT))
> > ||
> > @@ -1207,7 +1207,7 @@ static int qsv_init_internal_session(AVHWFramesContext
> > *ctx,
> >    MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
> >  par.AsyncDepth = 1;
> >  
> > -    par.vpp.In = frames_hwctx->surfaces[0].Info;
> > +    par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info
> > : *frames_hwctx->info;
> >  
> >  /* Apparently VPP requires the frame rate to be set to some value,
> > otherwise
> >   * init will fail (probably for the framerate conversion filter). Since
> > we
> > diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
> > index e2dba8ad83..9e43a237d4 100644
> > --- a/libavutil/hwcontext_qsv.h
> > +++ b/libavutil/hwcontext_qsv.h
> > @@ -25,8 +25,8 @@
> >   * @file
> >   * An API-specific header for AV_HWDEVICE_TYPE_QSV.
> >   *
> > - * This API does not support dynamic frame pools. AVHWFramesContext.pool
> > must
> > - * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1
> > struct.
> > + * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer
> > points
> > + * to a mfxFrameSurface1 struct.
> >   */
> >  
> >  /**
> > @@ -51,7 +51,29 @@ typedef struct AVQSVDeviceContext {
> >   * This struct is allocated as AVHWFramesContext.hwctx
> >   */
> >  typedef struct AVQSVFramesContext {
> > -    mfxFrameSurface1 *surfaces;
> > +    /**
> > + * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
> > + *
> > + * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
> > + * struct.
> > + *
> > + * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
> > + * buffers allocated from the pool have the same mfxFrameInfo.
> > + */
> > +    union {
> > +    mfxFrameSurface1 *surfaces;
> > +    mfxFrameInfo *info;
> > +    };
> 
> doc/developer.texi:
> 
> "FFmpeg is mainly programmed in the ISO C11 language, except for the public
> headers which must stay C99 compatible."
> 
> Anonymous unions are therefore not allowed in public headers.

Thanks for pointing it out, I missed this statement.

> 
> Can you explain what you need the info field for, though?  (What is needed but
> can't be inferred elsewhere?  VAAPI in particular is can be mapped here but
> doesn't contain any special information like this.)

The info is used in libavcodec and libavfilter. My thought is we may get the
info from surfaces directly for fixed frame pool in libavcodec and libavfilter,
It is better to have a field too for the info in dynamic frame pool so we
needn't infer the info in libavcodec and libavfilter.

Thanks
Haihao

>

Re: [FFmpeg-devel] [PATCH 5/6] vaapi_av1: Fix force_integer_mv value

2024-04-29 Thread Xiang, Haihao
On Sa, 2024-04-27 at 16:30 +0100, Mark Thompson wrote:
> ---
>  libavcodec/vaapi_av1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 1f563483b9..f61bf63098 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -220,7 +220,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
>  .error_resilient_mode = frame_header-
> >error_resilient_mode,
>  .disable_cdf_update   = frame_header->disable_cdf_update,
>  .allow_screen_content_tools   = frame_header-
> >allow_screen_content_tools,
> -    .force_integer_mv = frame_header->force_integer_mv,
> +    .force_integer_mv = s->cur_frame.force_integer_mv,
>  .allow_intrabc    = frame_header->allow_intrabc,
>  .use_superres = frame_header->use_superres,
>  .allow_high_precision_mv  = frame_header-
> >allow_high_precision_mv,

LGTM, vaapi av1 also requires this value instead of the syntax element value.

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_hevc: Don't require exact profiles

2024-04-29 Thread Xiang, Haihao
On So, 2024-04-28 at 15:14 +0100, Mark Thompson wrote:
> On 24/04/2024 14:45, Xiang, Haihao wrote:
> > On Ma, 2024-04-22 at 22:23 +0100, Mark Thompson wrote:
> > > Rather than turning the constraint flags into a single profile and then
> > > searching for that profile (and failing if it doesn't match any profile
> > > exactly), instead search all supported profiles and use the first one
> > > which supports the given set of constraint flags.
> > > ---
> > > This fixes decode of rext 8-bit 4:2:0; it will correctly pick Main 12 or
> > > Main
> > > 4:2:2 10 or Main 4:4:4 (first one available) to use as the decoding
> > > profile
> > > after this patch.
> > 
> > sw decoding and vaapi decoding might have different bits (There is the same
> > issue if applying Fei's patchset).  
> > 
> > For example:
> > $ ffmpeg -hwaccel vaapi -f lavfi -i testsrc -vf 'format=nv12,hwupload' -c:v
> > hevc_vaapi -profile:v rext -vframes 30 -y out.mp4
> > 
> > 8bit ouput if using sw decoding:
> > $ ffmpeg -i out.mp4 -f null - 
> > [...]
> > Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, progressive), 320x240
> > [SAR
> > 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
> > 
> > 12bit output if using vaapi decoding:
> > $ ffmpeg -hwaccel vaapi -i out.mp4 -f null -
> > [...]
> >  Stream #0:0(und): Video: wrapped_avframe, p012le(tv, progressive), 320x240
> > [SAR
> > 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
> 
> That comes from what the driver reports support for, though?
> 
> E.g. with the Intel iHD driver, I have
> 
>     {
>     "profile": 23,
>     "name": "HEVCMain12",
> ...
>     "surface_formats": [
>     {
>     "rt_format": "YUV420",
>     "max_width": 16384,
>     "max_height": 16384,
>     "memory_types": [
>     "VA",
>     "DRM_PRIME_2",
>     ],
>     "pixel_formats": [
>     "P012",
>     "P016",
>     ],
>     },
> 
> So to decode a 4:2:0 8-bit input it is asking for a P012 or P016 surface.
> 
> If the driver reported that a Main 12 profile 4:2:0 8-bit input could be
> decoded to an NV12 surface then it would be picked by the logic in
> vaapi_decode_find_best_format(), since it would be a better match than the
> higher-depth formats.

You are right, the iHD driver doesn't report the support for HEVCMain12 8bit. 

Thanks
Haihao

___
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 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8c92fec0c1..6814d8add8 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -308,7 +308,7 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, 
AVFilterLink *link)
 
 frames_ctx   = (AVHWFramesContext *)link->hw_frames_ctx->data;
 frames_hwctx = frames_ctx->hwctx;
-*frameinfo   = frames_hwctx->surfaces[0].Info;
+*frameinfo   = frames_hwctx->nb_surfaces ? 
frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
 } else {
 pix_fmt = link->format;
 desc = av_pix_fmt_desc_get(pix_fmt);
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 7/9] lavc/qsvdec: require a dynamic frame pool if possible

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

This allows a downstream element stores more frames from qsv decoders
and fixes error in get_buffer().

$ ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i input.mp4 -vf
reverse -f null -

[vist#0:0/h264 @ 0x562248f12c50] Decoding error: Cannot allocate memory
[h264_qsv @ 0x562248f66b10] get_buffer() failed

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 57 +++--
 1 file changed, 45 insertions(+), 12 deletions(-)

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

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

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


[FFmpeg-devel] [PATCH 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 52 
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 6814d8add8..f3897823db 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -604,6 +604,26 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 device_ctx   = (AVHWDeviceContext *)device_ref->data;
 device_hwctx = device_ctx->hwctx;
 
+/* extract the properties of the "master" session given to us */
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
+return AVERROR_UNKNOWN;
+}
+
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
+}
+
 if (outlink->format == AV_PIX_FMT_QSV) {
 AVHWFramesContext *out_frames_ctx;
 AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
@@ -625,9 +645,15 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 out_frames_ctx->width = FFALIGN(outlink->w, 32);
 out_frames_ctx->height= FFALIGN(outlink->h, 32);
 out_frames_ctx->sw_format = s->out_sw_format;
-out_frames_ctx->initial_pool_size = 64;
-if (avctx->extra_hw_frames > 0)
-out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9) && handle_type != 
MFX_HANDLE_D3D9_DEVICE_MANAGER)
+out_frames_ctx->initial_pool_size = 0;
+else {
+out_frames_ctx->initial_pool_size = 64;
+if (avctx->extra_hw_frames > 0)
+out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+}
+
 out_frames_hwctx->frame_type  = s->out_mem_mode;
 
 ret = av_hwframe_ctx_init(out_frames_ref);
@@ -653,26 +679,6 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 } else
 s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
 
-/* extract the properties of the "master" session given to us */
-ret = MFXQueryIMPL(device_hwctx->session, &impl);
-if (ret == MFX_ERR_NONE)
-ret = MFXQueryVersion(device_hwctx->session, &ver);
-if (ret != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
-return AVERROR_UNKNOWN;
-}
-
-if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_VA_DISPLAY;
-} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D11_DEVICE;
-} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
-} else {
-av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
-return AVERROR_UNKNOWN;
-}
-
 ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
 if (ret < 0)
 return ff_qsvvpp_print_error(avctx, ret, "Error getting the session 
handle");
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 6/9] lavc/qsvenc: use the right info for encoding

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

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

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 018d193495..ca1a88e49f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -744,8 +744,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx= (AVHWFramesContext 
*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
@@ -868,8 +869,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 5/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

When the external allocator is used for dynamic frame allocation, only
video memory is supported, the SDK doesn't lock/unlock the memory block
via Lock()/Unlock() calls.

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsv.c | 68 +++-
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b07302cdf6..6bbfe2a5a9 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -825,8 +825,16 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
-mfxFrameInfo  *i1 = &frames_hwctx->surfaces[0].Info;
+mfxFrameInfo  *i1;
 
+if (!frames_hwctx->nb_surfaces) {
+av_log(ctx->logctx, AV_LOG_DEBUG,
+   "Dynamic frame pools, no frame is pre-allocated\n");
+
+return MFX_ERR_NONE;
+}
+
+i1 = &frames_hwctx->surfaces[0].Info;
 if (i->Width  > i1->Width  || i->Height > i1->Height ||
 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
 av_log(ctx->logctx, AV_LOG_ERROR, "Mismatching surface properties 
in an "
@@ -845,6 +853,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 } else if (req->Type & MFX_MEMTYPE_INTERNAL_FRAME) {
 /* internal frames -- allocate a new hw frames context */
 AVHWFramesContext *ext_frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *ext_frames_hwctx = ext_frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
 
 AVBufferRef *frames_ref;
@@ -852,6 +861,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx;
 AVQSVFramesContext *frames_hwctx;
 
+if (!ext_frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
 frames_ref = av_hwframe_ctx_alloc(ext_frames_ctx->device_ref);
 if (!frames_ref)
 return MFX_ERR_MEMORY_ALLOC;
@@ -899,6 +911,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 
 static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
 {
+if (!resp->mids)
+return MFX_ERR_NONE;
+
 av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]);
 ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]);
 av_freep(&resp->mids);
@@ -907,11 +922,20 @@ static mfxStatus qsv_frame_free(mfxHDL pthis, 
mfxFrameAllocResponse *resp)
 
 static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
 {
-QSVMid *qsv_mid = mid;
-AVHWFramesContext *hw_frames_ctx = 
(AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
-AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+AVHWFramesContext *hw_frames_ctx;
+AVQSVFramesContext *hw_frames_hwctx;
 int ret;
 
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
+qsv_mid = mid;
+hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
+hw_frames_hwctx = hw_frames_ctx->hwctx;
 if (qsv_mid->locked_frame)
 return MFX_ERR_UNDEFINED_BEHAVIOR;
 
@@ -964,8 +988,15 @@ fail:
 
 static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData 
*ptr)
 {
-QSVMid *qsv_mid = mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
 
+qsv_mid = mid;
 av_frame_free(&qsv_mid->locked_frame);
 av_frame_free(&qsv_mid->hw_frame);
 
@@ -974,9 +1005,18 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId 
mid, mfxFrameData *ptr)
 
 static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-QSVMid *qsv_mid = (QSVMid*)mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
-mfxHDLPair *pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+mfxHDLPair *pair_src;
+
+if (frames_hwctx->nb_surfaces) {
+QSVMid *qsv_mid = (QSVMid*)mid;
+pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+} else {
+pair_src = (mfxHDLPair*)mid;
+}
 
 pair_dst->first = pair_src->first;
 
@@ -1090,13 +1130,17 @@ int ff_qsv_init_session_fr

[FFmpeg-devel] [PATCH 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 131 +-
 1 file changed, 129 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 1d3091e6f8..8b7b4dc501 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2122,8 +2122,8 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 }
 }
 
-static int qsv_map_to(AVHWFramesContext *dst_ctx,
-  AVFrame *dst, const AVFrame *src, int flags)
+static int qsv_fixed_pool_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
 {
 AVQSVFramesContext *hwctx = dst_ctx->hwctx;
 int i, err, index = -1;
@@ -2182,6 +2182,133 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx,
 return 0;
 }
 
+static void qsv_dynamic_pool_unmap(AVHWFramesContext *ctx, HWMapDescriptor 
*hwmap)
+{
+mfxFrameSurface1 *surfaces_internal = (mfxFrameSurface1 *)hwmap->priv;
+mfxHDLPair *handle_pairs_internal = (mfxHDLPair 
*)surfaces_internal->Data.MemId;
+AVHWFramesContext *src_ctx = (AVHWFramesContext 
*)ffhwframesctx(ctx)->source_frames->data;
+
+switch (src_ctx->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+av_freep(&handle_pairs_internal->first);
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+/* Do nothing */
+break;
+}
+#endif
+default:
+av_log(ctx, AV_LOG_ERROR, "Should not reach here. \n");
+break;
+}
+
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+}
+
+static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx,
+   AVFrame *dst, const AVFrame *src, int flags)
+{
+mfxFrameSurface1 *surfaces_internal = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret = 0;
+
+surfaces_internal = av_calloc(1, sizeof(*surfaces_internal));
+if (!surfaces_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+ret = qsv_init_surface(dst_ctx, surfaces_internal);
+if (ret < 0)
+goto fail;
+
+switch (src->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal) {
+ret =AVERROR(ENOMEM);
+goto fail;
+}
+
+*surface_id_internal = (VASurfaceID)(uintptr_t)src->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+AVHWFramesContext *src_ctx = 
(AVHWFramesContext*)src->hw_frames_ctx->data;
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+handle_pairs_internal->first = (mfxMemId)src->data[0];
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+} else {
+handle_pairs_internal->second = (mfxMemId)src->data[1];
+}
+
+break;
+}
+#endif
+default:
+ret = AVERROR(ENOSYS);
+goto fail;
+}
+
+surfaces_internal->Data.MemId = (mfxMemId)handle_pairs_internal;
+
+ret = ff_hwframe_map_create(dst->hw_frames_ctx,
+dst, src, qsv_dynamic_pool_unmap, 
surfaces_internal);
+if (ret)
+goto fail;
+
+dst->width   = src->width;
+dst->height  = src->height;
+dst->data[3] = (uint8_t*)surfaces_internal;
+
+return 0;
+
+fail:
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+return ret;
+}
+
+static int qsv_map_to(AVHWFramesContext *dst_ctx,
+  AVFrame *dst, const AVFrame *src, int flags)
+{
+AVQSVFramesContext *hwctx = dst_ctx->hwctx;
+
+if (hwctx->nb_surfaces)
+return qsv_fixed_pool_map_to(dst_ctx, dst, src, flags);
+else
+return qsv_dynamic_pool_map_to(dst_ctx, dst, src, flags);
+}
+
 static int qsv_frames_get_constraints(AVHWDeviceContext *ctx,
   const void *hwconfig,
   AVHWFramesConstraints *constraints)
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 3/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 61 ++-
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 01bd273a08..1d3091e6f8 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1972,18 +1972,52 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 return 0;
 }
 
-static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
-AVHWFramesContext *src_ctx, int flags)
+static int qsv_dynamic_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
 {
 QSVFramesContext *s = dst_ctx->hwctx;
 AVQSVFramesContext *dst_hwctx = &s->p;
-int i;
+mfxFrameSurface1 mfx_surf1;
 
-if (src_ctx->initial_pool_size == 0) {
-av_log(dst_ctx, AV_LOG_ERROR, "Only fixed-size pools can be "
-"mapped to QSV frames.\n");
-return AVERROR(EINVAL);
+switch (src_ctx->device_ctx->type) {
+#if CONFIG_VAAPI
+case AV_HWDEVICE_TYPE_VAAPI:
+dst_hwctx->frame_type  = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+break;
+#endif
+
+#if CONFIG_D3D11VA
+case AV_HWDEVICE_TYPE_D3D11VA:
+{
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
+} else {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+}
 }
+break;
+#endif
+
+default:
+return AVERROR(ENOSYS);
+}
+
+memset(&mfx_surf1, 0, sizeof(mfx_surf1));
+qsv_init_surface(dst_ctx, &mfx_surf1);
+s->frame_info = mfx_surf1.Info;
+dst_hwctx->info = &s->frame_info;
+dst_hwctx->nb_surfaces = 0;
+return 0;
+}
+
+static int qsv_fixed_frames_derive_to(AVHWFramesContext *dst_ctx,
+  AVHWFramesContext *src_ctx, int flags)
+{
+QSVFramesContext *s = dst_ctx->hwctx;
+AVQSVFramesContext *dst_hwctx = &s->p;
+int i;
 
 switch (src_ctx->device_ctx->type) {
 #if CONFIG_VAAPI
@@ -2075,6 +2109,19 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 return 0;
 }
 
+static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
+{
+if (src_ctx->initial_pool_size < 0) {
+av_log(dst_ctx, AV_LOG_ERROR, "Invalid src frame pool. \n");
+return AVERROR(EINVAL);
+} else if (src_ctx->initial_pool_size == 0) {
+return qsv_dynamic_frames_derive_to(dst_ctx, src_ctx, flags);
+} else {
+return qsv_fixed_frames_derive_to(dst_ctx, src_ctx, flags);
+}
+}
+
 static int qsv_map_to(AVHWFramesContext *dst_ctx,
   AVFrame *dst, const AVFrame *src, int flags)
 {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/9] lavu/hwcontext_qsv: create dynamic frame pool if required

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

When AVHWFramesContext.initial_pool_size is 0, a dynamic frame pool is
required. We may support this under certain conditions, e.g. oneVPL 2.9+
support dynamic frame allocation, we needn't provide a fixed frame pool
in the mfxFrameAllocator.Alloc callback.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 157 +-
 1 file changed, 154 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index f552811346..01bd273a08 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -118,8 +118,15 @@ typedef struct QSVFramesContext {
 #endif
 AVFrame realigned_upload_frame;
 AVFrame realigned_download_frame;
+
+mfxFrameInfo frame_info;
 } QSVFramesContext;
 
+typedef struct QSVSurface {
+mfxFrameSurface1 mfx_surface;
+AVFrame *child_frame;
+} QSVSurface;
+
 static const struct {
 enum AVPixelFormat pix_fmt;
 uint32_t   fourcc;
@@ -165,6 +172,8 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 
*surf,
   enum AVHWDeviceType base_dev_type,
   void **base_handle);
 
+static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf);
+
 /**
  * Caller needs to allocate enough space for base_handle pointer.
  **/
@@ -373,7 +382,32 @@ static void qsv_pool_release_dummy(void *opaque, uint8_t 
*data)
 {
 }
 
-static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
+static void qsv_pool_release(void *opaque, uint8_t *data)
+{
+AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext *s = ctx->hwctx;
+QSVSurface *qsv_surface = (QSVSurface *)data;
+mfxHDLPair *hdl_pair = (mfxHDLPair *)qsv_surface->mfx_surface.Data.MemId;
+AVHWFramesContext *child_frames_ctx;
+
+if (!s->child_frames_ref)
+return;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+return;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI)
+av_freep(&hdl_pair->first);
+#endif
+
+av_freep(&hdl_pair);
+av_frame_free(&qsv_surface->child_frame);
+av_freep(&qsv_surface);
+}
+
+static AVBufferRef *qsv_fixed_pool_alloc(void *opaque, size_t size)
 {
 AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
 QSVFramesContext   *s = ctx->hwctx;
@@ -388,6 +422,104 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t 
size)
 return NULL;
 }
 
+static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size)
+{
+AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext   *s = ctx->hwctx;
+AVHWFramesContext *child_frames_ctx;
+QSVSurface *qsv_surface = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret;
+
+if (!s->child_frames_ref)
+goto fail;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+goto fail;
+
+#if CONFIG_DXVA2
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+av_log(ctx, AV_LOG_ERROR,
+   "QSV on dxva2 requires a fixed frame pool size\n");
+goto fail;
+}
+#endif
+
+qsv_surface = av_calloc(1, sizeof(*qsv_surface));
+if (!qsv_surface)
+goto fail;
+
+qsv_surface->child_frame = av_frame_alloc();
+if (!qsv_surface->child_frame)
+goto fail;
+
+ret = av_hwframe_get_buffer(s->child_frames_ref, qsv_surface->child_frame, 
0);
+if (ret < 0)
+goto fail;
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal)
+goto fail;
+
+ret = qsv_init_surface(ctx, &qsv_surface->mfx_surface);
+if (ret < 0)
+goto fail;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) {
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal)
+goto fail;
+
+*surface_id_internal = 
(VASurfaceID)(uintptr_t)qsv_surface->child_frame->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+}
+#endif
+
+#if CONFIG_D3D11VA
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx;
+handle_pairs_internal->first = 
(mfxMemId)qsv_surface->child_frame->data[0];
+
+if (child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET)
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+else
+handle_pairs_internal->second = 
(mfxMemId)qsv_surface->child_frame->data[1];
+
+}
+#endif
+
+qsv_surface->mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal

[FFmpeg-devel] [PATCH 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Add AVQSVFramesContext.info and update the description.

Signed-off-by: Haihao Xiang 
---
 doc/APIchanges|  3 +++
 libavutil/hwcontext_qsv.c |  4 ++--
 libavutil/hwcontext_qsv.h | 28 +---
 libavutil/version.h   |  4 ++--
 4 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0566fcdcc5..4a434b2877 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-04-xx - xx - lavu 59.17.100 - hwcontext_qsv.h
+  Add AVQSVFramesContext.info
+
 2024-04-24 - 8616cfe0890 - lavu 59.16.100 - opt.h
   Add AV_OPT_SERIALIZE_SEARCH_CHILDREN.
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index c7c7878644..f552811346 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -627,7 +627,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 QSVFramesContext   *s = ctx->hwctx;
 AVQSVFramesContext *hwctx = &s->p;
 mfxFrameInfo *i  = &req->Info;
-mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
+mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : 
hwctx->info;
 
 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
@@ -1207,7 +1207,7 @@ static int qsv_init_internal_session(AVHWFramesContext 
*ctx,
   MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
 par.AsyncDepth = 1;
 
-par.vpp.In = frames_hwctx->surfaces[0].Info;
+par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : 
*frames_hwctx->info;
 
 /* Apparently VPP requires the frame rate to be set to some value, 
otherwise
  * init will fail (probably for the framerate conversion filter). Since we
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index e2dba8ad83..9e43a237d4 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -25,8 +25,8 @@
  * @file
  * An API-specific header for AV_HWDEVICE_TYPE_QSV.
  *
- * This API does not support dynamic frame pools. AVHWFramesContext.pool must
- * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 
struct.
+ * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
+ * to a mfxFrameSurface1 struct.
  */
 
 /**
@@ -51,7 +51,29 @@ typedef struct AVQSVDeviceContext {
  * This struct is allocated as AVHWFramesContext.hwctx
  */
 typedef struct AVQSVFramesContext {
-mfxFrameSurface1 *surfaces;
+/**
+ * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
+ *
+ * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
+ * struct.
+ *
+ * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
+ * buffers allocated from the pool have the same mfxFrameInfo.
+ */
+union {
+mfxFrameSurface1 *surfaces;
+mfxFrameInfo *info;
+};
+
+/**
+ * Number of frames in the pool
+ *
+ * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
+ * for fixed frame pools.
+ *
+ * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
+ * on d3d11va or vaapi
+ */
 intnb_surfaces;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index 735f6832e3..3b5a2e7aaa 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  16
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR  17
+#define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH] lavfi/qsv: Copy metadata fields from the given input

2024-04-27 Thread Xiang, Haihao
On Do, 2024-04-25 at 13:18 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Currently it always copies the metadata fields from the last input when
> there are multiple inputs for the filter. For example, the metadata
> fields from input1 are copied to the output for overlay_qsv filter,
> however for regular overlay filters, the metadata fields from input0 are
> copied to the output. With this fix, we may copy the metadata fields
> from input0 to the ouput as well.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavfilter/qsvvpp.c | 29 +++--
>  libavfilter/qsvvpp.h |  2 +-
>  libavfilter/vf_overlay_qsv.c |  9 ++---
>  libavfilter/vf_stack_qsv.c   |  9 ++---
>  libavfilter/vf_vpp_qsv.c |  2 +-
>  5 files changed, 25 insertions(+), 26 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 8c92fec0c1..10d970652e 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -441,11 +441,6 @@ static QSVFrame *submit_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *p
>  av_frame_free(&qsv_frame->frame);
>  return NULL;
>  }
> -
> -    if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
> -    av_frame_free(&qsv_frame->frame);
> -    return NULL;
> -    }
>  } else
>  qsv_frame->frame = av_frame_clone(picref);
>  
> @@ -494,12 +489,6 @@ static QSVFrame *query_frame(QSVVPPContext *s,
> AVFilterLink *outlink, const AVFr
>  if (!out_frame->frame)
>  return NULL;
>  
> -    ret = av_frame_copy_props(out_frame->frame, in);
> -    if (ret < 0) {
> -    av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from
> src to dst.\n");
> -    return NULL;
> -    }
> -
>  ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame,
> 0);
>  if (ret < 0) {
>  av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
> @@ -516,12 +505,6 @@ static QSVFrame *query_frame(QSVVPPContext *s,
> AVFilterLink *outlink, const AVFr
>  if (!out_frame->frame)
>  return NULL;
>  
> -    ret = av_frame_copy_props(out_frame->frame, in);
> -    if (ret < 0) {
> -    av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from
> src to dst.\n");
> -    return NULL;
> -    }
> -
>  ret = map_frame_to_surface(out_frame->frame,
>     &out_frame->surface);
>  if (ret < 0)
> @@ -958,7 +941,7 @@ int ff_qsvvpp_close(AVFilterContext *avctx)
>  return 0;
>  }
>  
> -int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame
> *picref)
> +int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame
> *picref, AVFrame *propref)
>  {
>  AVFilterContext  *ctx = inlink->dst;
>  AVFilterLink *outlink = ctx->outputs[0];
> @@ -1015,6 +998,16 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *picr
>  return AVERROR(EAGAIN);
>  break;
>  }
> +
> +    if (propref) {
> +    ret1 = av_frame_copy_props(out_frame->frame, propref);
> +    if (ret1 < 0) {
> +    av_frame_free(&out_frame->frame);
> +    av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields
> from src to dst.\n");
> +    return ret1;
> +    }
> +    }
> +
>  out_frame->frame->pts = av_rescale_q(out_frame-
> >surface.Data.TimeStamp,
>   default_tb, outlink->time_base);
>  
> diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
> index 4eea7a46c7..3b9192b62e 100644
> --- a/libavfilter/qsvvpp.h
> +++ b/libavfilter/qsvvpp.h
> @@ -131,7 +131,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam
> *param);
>  int ff_qsvvpp_close(AVFilterContext *avctx);
>  
>  /* vpp filter frame and call the cb if needed */
> -int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame
> *frame);
> +int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame
> *frame, AVFrame *propref);
>  
>  int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern,
>    const char *extra_string);
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index 0f52c93245..059602fe03 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilte

Re: [FFmpeg-devel] [PATCH v4] lavu/hwcontext_vaapi: Use vaMapBuffer2 for mapping image buffers

2024-04-27 Thread Xiang, Haihao
On Do, 2024-04-25 at 09:33 +0200, David Rosca wrote:
> On Fri, Nov 24, 2023 at 8:27 AM Xiang, Haihao  wrote:
> > 
> > On Vr, 2023-10-27 at 22:25 +0200, David Rosca wrote:
> > > This allows some optimizations in driver, such as not having to read
> > > back the data if write-only mapping is requested.
> > > ---
> > > v4: overwrite + note about vaMapBuffer libva fallback
> > > 
> > >  libavutil/hwcontext_vaapi.c | 12 
> > >  1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> > > index 558fed94c6..435f10a7f3 100644
> > > --- a/libavutil/hwcontext_vaapi.c
> > > +++ b/libavutil/hwcontext_vaapi.c
> > > @@ -799,6 +799,9 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc,
> > >  VAStatus vas;
> > >  void *address = NULL;
> > >  int err, i;
> > > +#if VA_CHECK_VERSION(1, 21, 0)
> > > +    uint32_t vaflags = 0;
> > > +#endif
> > > 
> > >  surface_id = (VASurfaceID)(uintptr_t)src->data[3];
> > >  av_log(hwfc, AV_LOG_DEBUG, "Map surface %#x.\n", surface_id);
> > > @@ -882,7 +885,16 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc,
> > >  }
> > >  }
> > > 
> > > +#if VA_CHECK_VERSION(1, 21, 0)
> > > +    if (flags & AV_HWFRAME_MAP_READ)
> > > +    vaflags |= VA_MAPBUFFER_FLAG_READ;
> > > +    if (flags & AV_HWFRAME_MAP_WRITE)
> > > +    vaflags |= VA_MAPBUFFER_FLAG_WRITE;
> > > +    // On drivers not implementing vaMapBuffer2 libva calls vaMapBuffer
> > > instead.
> > > +    vas = vaMapBuffer2(hwctx->display, map->image.buf, &address,
> > > vaflags);
> > > +#else
> > >  vas = vaMapBuffer(hwctx->display, map->image.buf, &address);
> > > +#endif
> > >  if (vas != VA_STATUS_SUCCESS) {
> > >  av_log(hwfc, AV_LOG_ERROR, "Failed to map image from surface "
> > >     "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas));
> > 
> > LGTM, and will apply it when the official libva 2.21 is released.
> 
> Ping, libva 2.21 has now been released.

Thanks for reminding me, will apply.

-Haihao

___
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] lavfi/qsv: Copy metadata fields from the given input

2024-04-24 Thread Xiang, Haihao
From: Haihao Xiang 

Currently it always copies the metadata fields from the last input when
there are multiple inputs for the filter. For example, the metadata
fields from input1 are copied to the output for overlay_qsv filter,
however for regular overlay filters, the metadata fields from input0 are
copied to the output. With this fix, we may copy the metadata fields
from input0 to the ouput as well.

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 29 +++--
 libavfilter/qsvvpp.h |  2 +-
 libavfilter/vf_overlay_qsv.c |  9 ++---
 libavfilter/vf_stack_qsv.c   |  9 ++---
 libavfilter/vf_vpp_qsv.c |  2 +-
 5 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8c92fec0c1..10d970652e 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -441,11 +441,6 @@ static QSVFrame *submit_frame(QSVVPPContext *s, 
AVFilterLink *inlink, AVFrame *p
 av_frame_free(&qsv_frame->frame);
 return NULL;
 }
-
-if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
-av_frame_free(&qsv_frame->frame);
-return NULL;
-}
 } else
 qsv_frame->frame = av_frame_clone(picref);
 
@@ -494,12 +489,6 @@ static QSVFrame *query_frame(QSVVPPContext *s, 
AVFilterLink *outlink, const AVFr
 if (!out_frame->frame)
 return NULL;
 
-ret = av_frame_copy_props(out_frame->frame, in);
-if (ret < 0) {
-av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from src 
to dst.\n");
-return NULL;
-}
-
 ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame, 
0);
 if (ret < 0) {
 av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
@@ -516,12 +505,6 @@ static QSVFrame *query_frame(QSVVPPContext *s, 
AVFilterLink *outlink, const AVFr
 if (!out_frame->frame)
 return NULL;
 
-ret = av_frame_copy_props(out_frame->frame, in);
-if (ret < 0) {
-av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from src 
to dst.\n");
-return NULL;
-}
-
 ret = map_frame_to_surface(out_frame->frame,
&out_frame->surface);
 if (ret < 0)
@@ -958,7 +941,7 @@ int ff_qsvvpp_close(AVFilterContext *avctx)
 return 0;
 }
 
-int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame 
*picref)
+int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame 
*picref, AVFrame *propref)
 {
 AVFilterContext  *ctx = inlink->dst;
 AVFilterLink *outlink = ctx->outputs[0];
@@ -1015,6 +998,16 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 return AVERROR(EAGAIN);
 break;
 }
+
+if (propref) {
+ret1 = av_frame_copy_props(out_frame->frame, propref);
+if (ret1 < 0) {
+av_frame_free(&out_frame->frame);
+av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from 
src to dst.\n");
+return ret1;
+}
+}
+
 out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
  default_tb, outlink->time_base);
 
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 4eea7a46c7..3b9192b62e 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -131,7 +131,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam 
*param);
 int ff_qsvvpp_close(AVFilterContext *avctx);
 
 /* vpp filter frame and call the cb if needed */
-int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame 
*frame);
+int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame 
*frame, AVFrame *propref);
 
 int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern,
   const char *extra_string);
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index 0f52c93245..059602fe03 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -228,13 +228,16 @@ static int process_frame(FFFrameSync *fs)
 {
 AVFilterContext  *ctx = fs->parent;
 QSVVPPContext*qsv = fs->opaque;
-AVFrame*frame = NULL;
+AVFrame*frame = NULL, *propref = NULL;
 int   ret = 0, i;
 
 for (i = 0; i < ctx->nb_inputs; i++) {
 ret = ff_framesync_get_frame(fs, i, &frame, 0);
-if (ret == 0)
-ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame);
+if (ret == 0) {
+if (i == 0)
+propref = frame;
+ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame, propref);
+}
 if (ret < 0 && ret != AVERROR(EAGAIN))
 break;
 }
diff --git a/libavfilter/vf_stac

Re: [FFmpeg-devel] [PATCH v3 1/4] lavu: Remove libva 1.x support

2024-04-24 Thread Xiang, Haihao
On Ma, 2024-04-22 at 22:41 +0100, Mark Thompson wrote:
> libva 2.0 was released in 2017 and the 2.x versions are included in all
> supported distributions nowadays.
> ---
> Rebased.
> 
> I think we can also drop the other quirks?  They are for the proprietary media
> SDK driver (which I think is dead?) and the VDPAU wrapper (which I don't think
> was ever updated for libva 2?).

Agree, please drop these quirks in a new patch. 

BTW I think we should require VA-API 1.x firstly, otherwise if someone has VA-
API 0.x, he/she will get errors when building this commit. 

Thanks
Haihao

> 
> 
>  libavutil/hwcontext_vaapi.c | 22 --
>  1 file changed, 22 deletions(-)
> 
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 56d03aa4cd..84bcb78087 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -372,14 +372,6 @@ static const struct {
>  const char *match_string;
>  unsigned int quirks;
>  } vaapi_driver_quirks_table[] = {
> -#if !VA_CHECK_VERSION(1, 0, 0)
> -    // The i965 driver did not conform before version 2.0.
> -    {
> -    "Intel i965 (Quick Sync)",
> -    "i965",
> -    AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
> -    },
> -#endif
>  {
>  "Intel iHD",
>  "ubit",
> @@ -1413,7 +1405,6 @@ fail:
>  }
>  #endif
> 
> -#if VA_CHECK_VERSION(0, 36, 0)
>  typedef struct VAAPIDRMImageBufferMapping {
>  VAImage  image;
>  VABufferInfo buffer_info;
> @@ -1573,7 +1564,6 @@ fail:
>  av_freep(&mapping);
>  return err;
>  }
> -#endif
> 
>  static int vaapi_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
>  const AVFrame *src, int flags)
> @@ -1584,10 +1574,7 @@ static int vaapi_map_to_drm(AVHWFramesContext *hwfc,
> AVFrame *dst,
>  if (err != AVERROR(ENOSYS))
>  return err;
>  #endif
> -#if VA_CHECK_VERSION(0, 36, 0)
>  return vaapi_map_to_drm_abh(hwfc, dst, src, flags);
> -#endif
> -    return AVERROR(ENOSYS);
>  }
> 
>  #endif /* CONFIG_LIBDRM */
> @@ -1637,7 +1624,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
>  av_freep(&priv);
>  }
> 
> -#if CONFIG_VAAPI_1
>  static void vaapi_device_log_error(void *context, const char *message)
>  {
>  AVHWDeviceContext *ctx = context;
> @@ -1651,7 +1637,6 @@ static void vaapi_device_log_info(void *context, const
> char *message)
> 
>  av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
>  }
> -#endif
> 
>  static int vaapi_device_connect(AVHWDeviceContext *ctx,
>  VADisplay display)
> @@ -1660,10 +1645,8 @@ static int vaapi_device_connect(AVHWDeviceContext *ctx,
>  int major, minor;
>  VAStatus vas;
> 
> -#if CONFIG_VAAPI_1
>  vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
>  vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
> -#endif
> 
>  hwctx->display = display;
> 
> @@ -1907,7 +1890,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
> 
>  ent = av_dict_get(opts, "driver", NULL, 0);
>  if (ent) {
> -#if VA_CHECK_VERSION(0, 38, 0)
>  VAStatus vas;
>  vas = vaSetDriverName(display, ent->value);
>  if (vas != VA_STATUS_SUCCESS) {
> @@ -1916,10 +1898,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx,
> const char *device,
>  vaTerminate(display);
>  return AVERROR_EXTERNAL;
>  }
> -#else
> -    av_log(ctx, AV_LOG_WARNING, "Driver name setting is not "
> -   "supported with this VAAPI version.\n");
> -#endif
>  }
> 
>  return vaapi_device_connect(ctx, display);

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

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


Re: [FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking

2024-04-24 Thread Xiang, Haihao
On Ma, 2024-04-22 at 22:22 +0100, Mark Thompson wrote:
> Replace existing get_profile() with find_profile(), which finds the
> lowest compatible profile rather than requiring an exact match.
> ---
>  libavcodec/h265_profile_level.c | 73 +
>  libavcodec/h265_profile_level.h | 70 ++-
>  libavcodec/vaapi_hevc.c |  2 +-
>  libavcodec/vdpau_hevc.c |  2 +-
>  4 files changed, 117 insertions(+), 30 deletions(-)
> 
> diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c
> index 7ff9681f65..4bc72414cb 100644
> --- a/libavcodec/h265_profile_level.c
> +++ b/libavcodec/h265_profile_level.c
> @@ -119,41 +119,60 @@ static const H265ProfileDescriptor h265_profiles[] = {
>    5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 },
>  };
> 
> +_Static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles),
> +   "Incorrect H.265 profiles table.");
> 
> -const H265ProfileDescriptor *ff_h265_get_profile(const
> H265RawProfileTierLevel *ptl)
> +
> +const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl,
> + int profile)
>  {
> -    int i;
> +    const H265ProfileDescriptor *desc;
> +
> +    av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT);
> 
>  if (ptl->general_profile_space)
> -    return NULL;
> +    return 0;
> 
> -    for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) {
> -    const H265ProfileDescriptor *profile = &h265_profiles[i];
> +    desc = &h265_profiles[profile];
> 
> -    if (ptl->general_profile_idc &&
> -    ptl->general_profile_idc != profile->profile_idc)
> -    continue;
> -    if (!ptl->general_profile_compatibility_flag[profile->profile_idc])
> -    continue;
> +    if (ptl->general_profile_idc &&
> +    ptl->general_profile_idc != desc->profile_idc)
> +    return 0;
> +    if (!ptl->general_profile_compatibility_flag[desc->profile_idc])
> +    return 0;
> 
> -#define check_flag(name) \
> -    if (profile->name < 2) { \
> -    if (profile->name != ptl->general_ ## name ## _constraint_flag) \
> -    continue; \
> -    }
> -    check_flag(max_14bit);
> -    check_flag(max_12bit);
> -    check_flag(max_10bit);
> -    check_flag(max_8bit);
> -    check_flag(max_422chroma);
> -    check_flag(max_420chroma);
> -    check_flag(max_monochrome);
> -    check_flag(intra);
> -    check_flag(one_picture_only);
> -    check_flag(lower_bit_rate);
> +#define check_flag(flag) \
> +    if (desc->flag < 2 && \
> +    desc->flag > ptl->general_ ## flag ## _constraint_flag) \
> +    return 0;
> +    check_flag(max_14bit);
> +    check_flag(max_12bit);
> +    check_flag(max_10bit);
> +    check_flag(max_8bit);
> +    check_flag(max_422chroma);
> +    check_flag(max_420chroma);
> +    check_flag(max_monochrome);
> +    check_flag(intra);
> +    check_flag(one_picture_only);
> +    check_flag(lower_bit_rate);
>  #undef check_flag
> 
> -    return profile;
> +    return 1;
> +}
> +
> +
> +const H265ProfileDescriptor *ff_h265_get_profile(int profile)
> +{
> +    av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT);
> +
> +    return &h265_profiles[profile];
> +}
> +
> +const H265ProfileDescriptor *ff_h265_find_profile(const
> H265RawProfileTierLevel *ptl)
> +{
> +    for (int p = 0; p < H265_PROFILE_COUNT; p++) {
> +    if (ff_h265_profile_compatible(ptl, p))
> +    return &h265_profiles[p];
>  }
> 
>  return NULL;
> @@ -171,7 +190,7 @@ const H265LevelDescriptor *ff_h265_guess_level(const
> H265RawProfileTierLevel *pt
>  int i;
> 
>  if (ptl)
> -    profile = ff_h265_get_profile(ptl);
> +    profile = ff_h265_find_profile(ptl);
>  else
>  profile = NULL;
>  if (!profile) {
> diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h
> index cd30ac5c50..f403f63211 100644
> --- a/libavcodec/h265_profile_level.h
> +++ b/libavcodec/h265_profile_level.h
> @@ -24,6 +24,49 @@
>  #include "cbs_h265.h"
> 
> 
> +// Enumeration of all H.265 profiles.
> +// The list is ordered to match table A.10; numeric values are an index
> +// into the latest version of this table and have no codec meaning.
> +enum {
> +    H265_PROFILE_MONOCHROME,
> +    H265_PROFILE_MONOCHROME_10,
> +    H265_PROFILE_MONOCHROME_12,
> +    H265_PROFILE_MONOCHROME_16,
> +    H265_PROFILE_MAIN,
> +    H265_PROFILE_SCREEN_EXTENDED_MAIN,
> +    H265_PROFILE_MAIN_10,
> +    H265_PROFILE_SCREEN_EXTENDED_MAIN_10,
> +    H265_PROFILE_MAIN_12,
> +    H265_PROFILE_MAIN_STILL_PICTURE,
> +    H265_PROFILE_MAIN_10_STILL_PICTURE,
> +    H265_PROFILE_MAIN_422_10,
> +    H265_PROFILE_MAIN_422_12,
> +    H265_PROFILE_MAIN_444,
> +    H265_PROFILE_HIGH_THROUGHPUT_444,
> +    H265_PROFILE_SCREEN_EXTENDED_MAIN_444,
> +    H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444,
> +    H265_PROFI

Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_hevc: Don't require exact profiles

2024-04-24 Thread Xiang, Haihao
On Ma, 2024-04-22 at 22:23 +0100, Mark Thompson wrote:
> Rather than turning the constraint flags into a single profile and then
> searching for that profile (and failing if it doesn't match any profile
> exactly), instead search all supported profiles and use the first one
> which supports the given set of constraint flags.
> ---
> This fixes decode of rext 8-bit 4:2:0; it will correctly pick Main 12 or Main
> 4:2:2 10 or Main 4:4:4 (first one available) to use as the decoding profile
> after this patch.

sw decoding and vaapi decoding might have different bits (There is the same
issue if applying Fei's patchset).  

For example:
$ ffmpeg -hwaccel vaapi -f lavfi -i testsrc -vf 'format=nv12,hwupload' -c:v
hevc_vaapi -profile:v rext -vframes 30 -y out.mp4

8bit ouput if using sw decoding:
$ ffmpeg -i out.mp4 -f null - 
[...]
Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, progressive), 320x240 [SAR
1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)

12bit output if using vaapi decoding:
$ ffmpeg -hwaccel vaapi -i out.mp4 -f null -
[...]
 Stream #0:0(und): Video: wrapped_avframe, p012le(tv, progressive), 320x240 [SAR
1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)

Thanks
Haihao

> 
>  libavcodec/vaapi_decode.c | 45 ---
>  libavcodec/vaapi_hevc.c   | 95 +--
>  libavcodec/vaapi_hevc.h   |  4 +-
>  3 files changed, 83 insertions(+), 61 deletions(-)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 21b273cd0f..f1327464f5 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -387,7 +387,9 @@ static const struct {
>  enum AVCodecID codec_id;
>  int codec_profile;
>  VAProfile va_profile;
> -    VAProfile (*profile_parser)(AVCodecContext *avctx);
> +    VAProfile (*match_profile)(AVCodecContext *avctx,
> +   const VAProfile *profile_list,
> +   int profile_count);
>  } vaapi_profile_map[] = {
>  #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ##
> v, __VA_ARGS__ }
>  MAP(MPEG2VIDEO,  MPEG2_SIMPLE,    MPEG2Simple ),
> @@ -414,9 +416,9 @@ static const struct {
>  #endif
>  #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
>  MAP(HEVC,    HEVC_REXT,   None,
> - ff_vaapi_parse_hevc_rext_scc_profile ),
> + ff_vaapi_hevc_match_rext_scc_profile ),
>  MAP(HEVC,    HEVC_SCC,    None,
> - ff_vaapi_parse_hevc_rext_scc_profile ),
> + ff_vaapi_hevc_match_rext_scc_profile ),
>  #endif
>  MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
>    JPEGBaseline),
> @@ -499,22 +501,33 @@ static int vaapi_decode_make_config(AVCodecContext
> *avctx,
>  vaapi_profile_map[i].codec_profile == AV_PROFILE_UNKNOWN)
>  profile_match = 1;
> 
> -    va_profile = vaapi_profile_map[i].profile_parser ?
> - vaapi_profile_map[i].profile_parser(avctx) :
> - vaapi_profile_map[i].va_profile;
>  codec_profile = vaapi_profile_map[i].codec_profile;
> -
> -    for (j = 0; j < profile_count; j++) {
> -    if (va_profile == profile_list[j]) {
> -    exact_match = profile_match;
> +    if (vaapi_profile_map[i].match_profile) {
> +    va_profile =
> +    vaapi_profile_map[i].match_profile(avctx, profile_list,
> +   profile_count);
> +    if (va_profile != VAProfileNone) {
> +    matched_va_profile = va_profile;
> +    matched_ff_profile = codec_profile;
> +    exact_match = 1;
>  break;
>  }
> -    }
> -    if (j < profile_count) {
> -    matched_va_profile = va_profile;
> -    matched_ff_profile = codec_profile;
> -    if (exact_match)
> -    break;
> +    } else {
> +    va_profile = vaapi_profile_map[i].va_profile;
> +
> +    for (j = 0; j < profile_count; j++) {
> +    if (va_profile == profile_list[j]) {
> +    exact_match = profile_match;
> +    break;
> +    }
> +    }
> +
> +    if (j < profile_count) {
> +    matched_va_profile = va_profile;
> +    matched_ff_profile = codec_profile;
> +    if (exact_match)
> +    break;
> +    }
>  }
>  }
>  av_freep(&profile_list);
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> index 77f55ff8b1..28f7c9280e 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -590,63 +590,70 @@ static int ptl_convert(const PTLCommon *general_ptl,
> H265RawProfileTierLevel *h2
>  }
> 
>  /*
> - * Find exact va_profile for HEVC Range Extension and Screen Content Coding
> Extension
> + * Find compatible 

Re: [FFmpeg-devel] [PATCH 2/5] doc/examples/qsv_transcode: Simplify loop

2024-04-23 Thread Xiang, Haihao
On Wo, 2024-04-24 at 03:45 +0200, Michael Niedermayer wrote:
> Fixes: CID1428858(2/2) Logically dead code
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/examples/qsv_transcode.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
> index 8e7d2899f12..a4440a3403f 100644
> --- a/doc/examples/qsv_transcode.c
> +++ b/doc/examples/qsv_transcode.c
> @@ -335,10 +335,8 @@ static int dec_enc(AVPacket *pkt, const AVCodec
> *enc_codec, char *optstr)
>  
>  fail:
>  av_frame_free(&frame);
> -    if (ret < 0)
> -    return ret;
>  }
> -    return 0;
> +    return ret;
>  }
>  
>  int main(int argc, char **argv)

LGTM

Thanks
Haihao





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

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


Re: [FFmpeg-devel] [PATCH 5/5] doc/examples/qsv_transcode: Initialize pointer before free

2024-04-23 Thread Xiang, Haihao
On Wo, 2024-04-24 at 03:45 +0200, Michael Niedermayer wrote:
> Fixees: CID1517023 Uninitialized pointer read
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/examples/qsv_transcode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
> index 8e843ddd84c..665a76af2ed 100644
> --- a/doc/examples/qsv_transcode.c
> +++ b/doc/examples/qsv_transcode.c
> @@ -342,7 +342,7 @@ int main(int argc, char **argv)
>  {
>  const AVCodec *enc_codec;
>  int ret = 0;
> -    AVPacket *dec_pkt;
> +    AVPacket *dec_pkt = NULL;
>  
>  if (argc < 5 || (argc - 5) % 2) {
>  av_log(NULL, AV_LOG_ERROR, "Usage: %sfile>"

LGTM,

- Haihao

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

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


Re: [FFmpeg-devel] [PATCH 4/5] doc/examples/qsv_transcode: Simplify str_to_dict() loop

2024-04-23 Thread Xiang, Haihao
On Wo, 2024-04-24 at 03:45 +0200, Michael Niedermayer wrote:
> Fixes: CID1517022 Logically dead code
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/examples/qsv_transcode.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
> index a4440a3403f..8e843ddd84c 100644
> --- a/doc/examples/qsv_transcode.c
> +++ b/doc/examples/qsv_transcode.c
> @@ -76,8 +76,7 @@ static int str_to_dict(char* optstr, AVDictionary **opt)
>  if (value == NULL)
>  return AVERROR(EINVAL);
>  av_dict_set(opt, key, value, 0);
> -    } while(key != NULL);
> -    return 0;
> +    } while(1);
>  }
>  
>  static int dynamic_set_parameter(AVCodecContext *avctx)

LGTM, thanks for catching & fixing this.

- Haihao


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

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


Re: [FFmpeg-devel] [PATCH v1] lavc/qsvdec: Use FFmpeg default 1/25 framerate if can't derive it from bitstream

2024-04-23 Thread Xiang, Haihao
On Do, 2024-04-18 at 16:15 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Fix error:
> $ ffmpeg -hwaccel qsv -i input.h265 -f null -
> ...
> [null @ 0x55da1a629200] Application provided invalid, non monotonically
> increasing dts to muxer in stream 0: 3 >= 3
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/qsvdec.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index fd9267c6f4..218ca59e08 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -440,6 +440,11 @@ static int qsv_decode_header(AVCodecContext *avctx,
> QSVContext *q,
>  param->ExtParam    = q->ext_buffers;
>  param->NumExtParam = q->nb_ext_buffers;
>  
> +    if (param->mfx.FrameInfo.FrameRateExtN == 0 || param-
> >mfx.FrameInfo.FrameRateExtD == 0) {
> +    param->mfx.FrameInfo.FrameRateExtN = 25;
> +    param->mfx.FrameInfo.FrameRateExtD = 1;
> +    }
> +
>  #if QSV_VERSION_ATLEAST(1, 34)
>  if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) && avctx->codec_id ==
> AV_CODEC_ID_AV1)
>  param->mfx.FilmGrain = (avctx->export_side_data &
> AV_CODEC_EXPORT_DATA_FILM_GRAIN) ? 0 : param->mfx.FilmGrain;

LGTM, will apply

Thanks
Haihao




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

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


Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: Make qsv hardware transfers thread safe

2024-04-23 Thread Xiang, Haihao
On Wo, 2024-04-17 at 09:46 -0500, Mark Samuelson wrote:
> The QSV hardware context currently uses pthreads to lock initilization,
> which is not available on windows builds.  Instead, use the AVMutex
> object.  Also lock uses of the realigned_upload_frame and
> realigned_download_frame objects, so multiple threads do not attempt
> to write to them at the same time.
> ---
>  
> Here is a new patch addressing your comments
> Fixed the nested calls to ff_mutex_lock
> Fixed the two accidental tabs
> Fixed the two violations of K&R style
> Fixed the two incidents of mixing declaration and code
> 
> 
>  libavutil/hwcontext_qsv.c | 93 +++
>  1 file changed, 56 insertions(+), 37 deletions(-)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index c7c7878644..ed462d440a 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -23,10 +23,7 @@
>  #include 
>  
>  #include "config.h"
> -
> -#if HAVE_PTHREADS
> -#include 
> -#endif
> +#include "thread.h"
>  
>  #define COBJMACROS
>  #if CONFIG_VAAPI
> @@ -98,9 +95,7 @@ typedef struct QSVFramesContext {
>  atomic_int session_download_init;
>  mfxSession session_upload;
>  atomic_int session_upload_init;
> -#if HAVE_PTHREADS
> -    pthread_mutex_t session_lock;
> -#endif
> +    AVMutex session_lock;
>  
>  AVBufferRef *child_frames_ref;
>  mfxFrameSurface1 *surfaces_internal;
> @@ -354,9 +349,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
>  s->session_upload = NULL;
>  s->session_upload_init = 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_destroy(&s->session_lock);
> -#endif
> +    ff_mutex_destroy(&s->session_lock);
>  
>  av_freep(&s->mem_ids);
>  #if QSV_HAVE_OPAQUE
> @@ -1302,9 +1295,7 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
>  s->session_download_init = 0;
>  s->session_upload_init   = 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_init(&s->session_lock, NULL);
> -#endif
> +    ff_mutex_init(&s->session_lock, NULL);
>  
>  return 0;
>  }
> @@ -1629,24 +1620,20 @@ static int
> qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload)
>  if (atomic_load(inited))
>  return 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_lock(&s->session_lock);
> -#endif
> +    ff_mutex_lock(&s->session_lock);
>  
>  if (!atomic_load(inited)) {
>  ret = qsv_init_internal_session(ctx, session, upload);
>  atomic_store(inited, 1);
>  }
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_unlock(&s->session_lock);
> -#endif
> +    ff_mutex_unlock(&s->session_lock);
>  
>  return ret;
>  }
>  
> -static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> -  const AVFrame *src)
> +static int qsv_transfer_data_from_internal(AVHWFramesContext *ctx, AVFrame
> *dst,
> +   const AVFrame *src, int realigned)
>  {
>  QSVFramesContext  *s = ctx->hwctx;
>  mfxFrameSurface1 out = {{ 0 }};
> @@ -1658,17 +1645,11 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  /* download to temp frame if the output is not padded as libmfx requires
> */
>  AVFrame *tmp_frame = &s->realigned_download_frame;
>  AVFrame *dst_frame;
> -    int realigned = 0;
> -
> -    ret = qsv_internal_session_check_init(ctx, 0);
> -    if (ret < 0)
> -    return ret;
>  
>  /* According to MSDK spec for mfxframeinfo, "Width must be a multiple of
> 16.
>   * Height must be a multiple of 16 for progressive frame sequence and a
>   * multiple of 32 otherwise.", so allign all frames to 16 before
> downloading. */
> -    if (dst->height & 15 || dst->linesize[0] & 15) {
> -    realigned = 1;
> +    if (realigned) {
>  if (tmp_frame->format != dst->format ||
>  tmp_frame->width  != FFALIGN(dst->linesize[0], 16) ||
>  tmp_frame->height != FFALIGN(dst->height, 16)) {
> @@ -1728,8 +1709,30 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  return 0;
>  }
>  
> -static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
> -    const AVFrame *src)
> +static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> +  const AVFrame *src)
> +{
> +    QSVFramesContext *s = ctx->hwctx;
> +    int realigned = 0;
> +    int ret = 0;
> +
> +    ret = qsv_internal_session_check_init(ctx, 0);
> +    if (ret < 0)
> +    return ret;
> +
> +    if (dst->height & 15 || dst->linesize[0] & 15) {
> +    realigned = 1;
> +    ff_mutex_lock(&s->session_lock);

Needn't lock the use if changing realigned_upload_frame and
realigned_download_frame to local variables.

Thanks
Haihao

> +    }
> +    ret = qsv_transfer_data_from_internal(ctx, dst, src, realigned);
> +    if (realigned)
> +    ff_mutex_unlock(&s->session_lock);
> +
> +    return ret;
> +}
> +
>

Re: [FFmpeg-devel] [PATCH] lavc/vp9: Fix regression introduced in 0ba05857

2024-04-23 Thread Xiang, Haihao
On Di, 2024-04-23 at 14:14 +0200, Andreas Rheinhardt wrote:
> Xiang, Haihao:
> > From: Haihao Xiang 
> > 
> > It is possible that ff_progress_frame_await() is called but
> > ff_progress_frame_report() isn't called when a hardware acceleration
> > method is used, so a thread for vp9 decoding might get stuck.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  libavcodec/vp9.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> > index 3adfb98f2d..6e2d18bf95 100644
> > --- a/libavcodec/vp9.c
> > +++ b/libavcodec/vp9.c
> > @@ -1735,9 +1735,9 @@ static int vp9_decode_frame(AVCodecContext *avctx,
> > AVFrame *frame,
> >  if (ret < 0)
> >  goto fail;
> >  }
> > -    ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
> >  
> >  finish:
> > +    ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
> >  // ref frame setup
> >  for (int i = 0; i < 8; i++)
> >  ff_progress_frame_replace(&s->s.refs[i], &s->next_refs[i]);
> 
> LGTM. Sorry for the breakage.
> 

Thanks for reviewing the patch, I pushed the patch.

BRs
Haihao

___
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/vp9: Fix regression introduced in 0ba05857

2024-04-22 Thread Xiang, Haihao
From: Haihao Xiang 

It is possible that ff_progress_frame_await() is called but
ff_progress_frame_report() isn't called when a hardware acceleration
method is used, so a thread for vp9 decoding might get stuck.

Signed-off-by: Haihao Xiang 
---
 libavcodec/vp9.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 3adfb98f2d..6e2d18bf95 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1735,9 +1735,9 @@ static int vp9_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 if (ret < 0)
 goto fail;
 }
-ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
 
 finish:
+ff_progress_frame_report(&s->s.frames[CUR_FRAME].tf, INT_MAX);
 // ref frame setup
 for (int i = 0; i < 8; i++)
 ff_progress_frame_replace(&s->s.refs[i], &s->next_refs[i]);
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH] configure: Fix typo

2024-04-22 Thread Xiang, Haihao
From: Haihao Xiang 

Otherwise there are link errors:
LD  ffprobe_g
/usr/bin/ld: libavcodec/libavcodec.so: undefined reference to
`ff_dovi_rpu_generate'
/usr/bin/ld: libavcodec/libavcodec.so: undefined reference to
`ff_dovi_configure'
collect2: error: ld returned 1 exit status

Signed-off-by: Haihao Xiang 
---
 configure | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index b101ed9256..02711bf930 100755
--- a/configure
+++ b/configure
@@ -3534,7 +3534,7 @@ libspeex_decoder_deps="libspeex"
 libspeex_encoder_deps="libspeex"
 libspeex_encoder_select="audio_frame_queue"
 libsvtav1_encoder_deps="libsvtav1"
-libsvtav1_encoder_select="dovi_rpueenc"
+libsvtav1_encoder_select="dovi_rpuenc"
 libtheora_encoder_deps="libtheora"
 libtwolame_encoder_deps="libtwolame"
 libuavs3d_decoder_deps="libuavs3d"
@@ -3554,7 +3554,7 @@ libx264_encoder_select="atsc_a53 golomb"
 libx264rgb_encoder_deps="libx264"
 libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
-libx265_encoder_select="atsc_a53 dovi_rpueenc"
+libx265_encoder_select="atsc_a53 dovi_rpuenc"
 libxavs_encoder_deps="libxavs"
 libxavs2_encoder_deps="libxavs2"
 libxevd_decoder_deps="libxevd"
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: Make qsv hardware transfers thread safe

2024-04-17 Thread Xiang, Haihao
On Sa, 2024-04-13 at 07:57 -0500, Mark Samuelson wrote:
> The QSV hardware context currently uses pthreads to lock initilization,
> which is not available on windows builds.  Instead, use the AVMutex
> object.  Also lock uses of the realigned_upload_frame and
> realigned_download_frame objects, so multiple threads do not attempt
> to write to them at the same time.
> ---
>  libavutil/hwcontext_qsv.c | 75 ---
>  1 file changed, 46 insertions(+), 29 deletions(-)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index c7c7878644..92bab134e4 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -23,10 +23,7 @@
>  #include 
>  
>  #include "config.h"
> -
> -#if HAVE_PTHREADS
> -#include 
> -#endif
> +#include "thread.h"
>  
>  #define COBJMACROS
>  #if CONFIG_VAAPI
> @@ -98,9 +95,7 @@ typedef struct QSVFramesContext {
>  atomic_int session_download_init;
>  mfxSession session_upload;
>  atomic_int session_upload_init;
> -#if HAVE_PTHREADS
> -    pthread_mutex_t session_lock;
> -#endif
> +    AVMutex session_lock;
>  
>  AVBufferRef *child_frames_ref;
>  mfxFrameSurface1 *surfaces_internal;
> @@ -354,9 +349,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
>  s->session_upload = NULL;
>  s->session_upload_init = 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_destroy(&s->session_lock);
> -#endif
> +    ff_mutex_destroy(&s->session_lock);
>  
>  av_freep(&s->mem_ids);
>  #if QSV_HAVE_OPAQUE
> @@ -1302,9 +1295,7 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
>  s->session_download_init = 0;
>  s->session_upload_init   = 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_init(&s->session_lock, NULL);
> -#endif
> +    ff_mutex_init(&s->session_lock, NULL);
>  
>  return 0;
>  }
> @@ -1629,24 +1620,20 @@ static int
> qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload)
>  if (atomic_load(inited))
>  return 0;
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_lock(&s->session_lock);
> -#endif
> +    ff_mutex_lock(&s->session_lock);

ff_mutex_lock is called twice in the same thread when realigned is 1, the
current thread is blocked. You may run the command below to reproduce this
issue:

./ffmpeg -init_hw_device qsv -f lavfi -i testsrc=size=352x280,format=nv12 -vf
"hwupload=extra_hw_frames=16" -f null -

>  
>  if (!atomic_load(inited)) {
>  ret = qsv_init_internal_session(ctx, session, upload);
>  atomic_store(inited, 1);
>  }
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_unlock(&s->session_lock);
> -#endif
> +    ff_mutex_unlock(&s->session_lock);
>  
>  return ret;
>  }
>  
> -static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> -  const AVFrame *src)
> +static int qsv_transfer_data_from_internal(AVHWFramesContext *ctx, AVFrame
> *dst,
> +   const AVFrame *src, int realigned)
>  {
>  QSVFramesContext  *s = ctx->hwctx;
>  mfxFrameSurface1 out = {{ 0 }};
> @@ -1658,7 +1645,6 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  /* download to temp frame if the output is not padded as libmfx requires
> */
>  AVFrame *tmp_frame = &s->realigned_download_frame;
>  AVFrame *dst_frame;
> -    int realigned = 0;
>  
>  ret = qsv_internal_session_check_init(ctx, 0);
>  if (ret < 0)
> @@ -1667,8 +1653,7 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  /* According to MSDK spec for mfxframeinfo, "Width must be a multiple of
> 16.
>   * Height must be a multiple of 16 for progressive frame sequence and a
>   * multiple of 32 otherwise.", so allign all frames to 16 before
> downloading. */
> -    if (dst->height & 15 || dst->linesize[0] & 15) {
> -    realigned = 1;
> +    if (realigned) {
>  if (tmp_frame->format != dst->format ||
>  tmp_frame->width  != FFALIGN(dst->linesize[0], 16) ||
>  tmp_frame->height != FFALIGN(dst->height, 16)) {
> @@ -1728,8 +1713,25 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  return 0;
>  }
>  
> -static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
> -    const AVFrame *src)
> +static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> +  const AVFrame *src)
> +{
> +   QSVFramesContext *s = ctx->hwctx;

Please do not use tab for indentation.

> +    int realigned = 0;
> +    if (dst->height & 15 || dst->linesize[0] & 15)
> +    {

{ and if statement should be on the same line to keep the consistent code style.

> +    realigned = 1;
> +    ff_mutex_lock(&s->session_lock);
> +    }
> +    int ret = qsv_transfer_data_from_internal(ctx, dst, src, realigned);

Please do not mix declaration and code.

> +    if (realigned)
> +    ff_mutex_unlock(&

[FFmpeg-devel] [PATCH 3/3] lavc/vaapi_encode_av1: insert HDR_CLL metadata if have

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

Only look for HDR_CLL on key frame on the output.

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

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 4077d21202..b868f5b66a 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -707,6 +707,21 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
mdm->min_luminance.den);
 }
 }
+
+sd = av_frame_get_side_data(pic->input_image,
+AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd) {
+AVContentLightMetadata *cllm = (AVContentLightMetadata *)sd->data;
+AV1RawOBU   *obu = &priv->mh[priv->nb_mh++];
+AV1RawMetadata   *md = &obu->obu.metadata;
+AV1RawMetadataHDRCLL*cll = &md->metadata.hdr_cll;
+
+memset(obu, 0, sizeof(*obu));
+obu->header.obu_type = AV1_OBU_METADATA;
+md->metadata_type= AV1_METADATA_TYPE_HDR_CLL;
+cll->max_cll = cllm->MaxCLL;
+cll->max_fall= cllm->MaxFALL;
+}
 }
 
 end:
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/3] lavc/vaapi_encode_av1: Insert HDR_MDCV metadata if have

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

Only look for HDR_MDVC on key frame on the output.

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

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 4b417b05e7..4077d21202 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
+#include "libavutil/mastering_display_metadata.h"
 
 #include "cbs_av1.h"
 #include "put_bits.h"
@@ -663,6 +664,51 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
 
 priv->nb_mh = 0;
 
+if (pic->type == PICTURE_TYPE_IDR) {
+AVFrameSideData *sd =
+av_frame_get_side_data(pic->input_image,
+   AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd) {
+AVMasteringDisplayMetadata *mdm =
+(AVMasteringDisplayMetadata *)sd->data;
+if (mdm->has_primaries && mdm->has_luminance) {
+AV1RawOBU  *obu = &priv->mh[priv->nb_mh++];
+AV1RawMetadata  *md = &obu->obu.metadata;
+AV1RawMetadataHDRMDCV *mdcv = &md->metadata.hdr_mdcv;
+const intchroma_den = 1 << 16;
+const int  max_luma_den = 1 << 8;
+const int  min_luma_den = 1 << 14;
+
+memset(obu, 0, sizeof(*obu));
+obu->header.obu_type = AV1_OBU_METADATA;
+md->metadata_type = AV1_METADATA_TYPE_HDR_MDCV;
+
+for (i = 0; i < 3; i++) {
+mdcv->primary_chromaticity_x[i] =
+av_rescale(mdm->display_primaries[i][0].num, 
chroma_den,
+   mdm->display_primaries[i][0].den);
+mdcv->primary_chromaticity_y[i] =
+av_rescale(mdm->display_primaries[i][1].num, 
chroma_den,
+   mdm->display_primaries[i][1].den);
+}
+
+mdcv->white_point_chromaticity_x =
+av_rescale(mdm->white_point[0].num, chroma_den,
+   mdm->white_point[0].den);
+mdcv->white_point_chromaticity_y =
+av_rescale(mdm->white_point[1].num, chroma_den,
+   mdm->white_point[1].den);
+
+mdcv->luminance_max =
+av_rescale(mdm->max_luminance.num, max_luma_den,
+   mdm->max_luminance.den);
+mdcv->luminance_min =
+av_rescale(mdm->min_luminance.num, min_luma_den,
+   mdm->min_luminance.den);
+}
+}
+}
+
 end:
 ff_cbs_fragment_reset(obu);
 return ret;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 1/3] lavc/vaapi_encode_av1: implement write_extra_header callback

2024-04-14 Thread Xiang, Haihao
From: Haihao Xiang 

This can be used to insert a metadata OBU to the stream later.

Signed-off-by: Haihao Xiang 
---
 libavcodec/vaapi_encode_av1.c | 42 ++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index 02a31b894d..4b417b05e7 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -41,6 +41,8 @@ typedef struct VAAPIEncodeAV1Context {
 VAAPIEncodeContext common;
 AV1RawOBU sh; /**< sequence header.*/
 AV1RawOBU fh; /**< frame header.*/
+AV1RawOBU mh[4]; /**< metadata header.*/
+int nb_mh;
 CodedBitstreamContext *cbc;
 CodedBitstreamFragment current_obu;
 VAConfigAttribValEncAV1 attr;
@@ -659,6 +661,8 @@ static int 
vaapi_encode_av1_init_picture_params(AVCodecContext *avctx,
2 : 1));
 }
 
+priv->nb_mh = 0;
+
 end:
 ff_cbs_fragment_reset(obu);
 return ret;
@@ -735,6 +739,39 @@ end:
 return ret;
 }
 
+static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx,
+   VAAPIEncodePicture *pic,
+   int index, int *type,
+   char *data, size_t *data_len)
+{
+VAAPIEncodeAV1Context  *priv = avctx->priv_data;
+CodedBitstreamFragment *obu  = &priv->current_obu;
+AV1RawOBU *mh_obu;
+char mh_data[MAX_PARAM_BUFFER_SIZE];
+size_t mh_data_len;
+int ret = 0;
+
+if (index >= priv->nb_mh)
+return AVERROR_EOF;
+
+mh_obu = &priv->mh[index];
+ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_METADATA, mh_obu);
+if (ret < 0)
+goto end;
+
+ret = vaapi_encode_av1_write_obu(avctx, mh_data, &mh_data_len, obu);
+if (ret < 0)
+goto end;
+
+memcpy(data, mh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
+*data_len = mh_data_len;
+*type = VAEncPackedHeaderRawData;
+
+end:
+ff_cbs_fragment_reset(obu);
+return ret;
+}
+
 static const VAAPIEncodeProfile vaapi_encode_av1_profiles[] = {
 { AV_PROFILE_AV1_MAIN,  8, 3, 1, 1, VAProfileAV1Profile0 },
 { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 },
@@ -762,6 +799,8 @@ static const VAAPIEncodeType vaapi_encode_type_av1 = {
 
 .slice_params_size = sizeof(VAEncTileGroupBufferAV1),
 .init_slice_params = &vaapi_encode_av1_init_slice_params,
+
+.write_extra_header = &vaapi_encode_av1_write_extra_header,
 };
 
 static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
@@ -776,7 +815,8 @@ static av_cold int vaapi_encode_av1_init(AVCodecContext 
*avctx)
 
 ctx->desired_packed_headers =
 VA_ENC_PACKED_HEADER_SEQUENCE |
-VA_ENC_PACKED_HEADER_PICTURE;
+VA_ENC_PACKED_HEADER_PICTURE |
+VA_ENC_PACKED_HEADER_MISC;  // Metadata
 
 if (avctx->profile == AV_PROFILE_UNKNOWN)
 avctx->profile = priv->profile;
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavfi/tonemap_vaapi: By default use bt709 for output frame

2024-04-14 Thread Xiang, Haihao
On Ma, 2024-03-18 at 16:12 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> By default don't use the color properties from input frame as output
> frame properties when performing HDR to SDR conversion
> 
> Signed-off-by: Haihao Xiang 
> ---
>  doc/filters.texi   | 4 ++--
>  libavfilter/vf_tonemap_vaapi.c | 7 +--
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 913365671d..2cb84c1476 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -27839,7 +27839,7 @@ Default is nv12.
>  @item primaries, p
>  Set the output color primaries.
>  
> -Default is same as input.
> +Default is bt709.
>  
>  @item transfer, t
>  Set the output transfer characteristics.
> @@ -27849,7 +27849,7 @@ Default is bt709.
>  @item matrix, m
>  Set the output colorspace matrix.
>  
> -Default is same as input.
> +Default is bt709.
>  
>  @end table
>  
> diff --git a/libavfilter/vf_tonemap_vaapi.c b/libavfilter/vf_tonemap_vaapi.c
> index 0b767202d2..a21f565e3a 100644
> --- a/libavfilter/vf_tonemap_vaapi.c
> +++ b/libavfilter/vf_tonemap_vaapi.c
> @@ -278,13 +278,16 @@ static int tonemap_vaapi_filter_frame(AVFilterLink
> *inlink, AVFrame *input_frame
>  if (err < 0)
>  goto fail;
>  
> +    /* Use BT709 by default for HDR to SDR output frame */
> +    output_frame->color_primaries = AVCOL_PRI_BT709;
> +    output_frame->color_trc = AVCOL_TRC_BT709;
> +    output_frame->colorspace = AVCOL_SPC_BT709;
> +
>  if (ctx->color_primaries != AVCOL_PRI_UNSPECIFIED)
>  output_frame->color_primaries = ctx->color_primaries;
>  
>  if (ctx->color_transfer != AVCOL_TRC_UNSPECIFIED)
>  output_frame->color_trc = ctx->color_transfer;
> -    else
> -    output_frame->color_trc = AVCOL_TRC_BT709;
>  
>  if (ctx->color_matrix != AVCOL_SPC_UNSPECIFIED)
>  output_frame->colorspace = ctx->color_matrix;

Will apply, 

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavfi: Add pad_vaapi filter

2024-04-14 Thread Xiang, Haihao
On Ma, 2024-03-18 at 14:06 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Signed-off-by: Haihao Xiang 
> ---
>  configure  |   1 +
>  doc/filters.texi   |  77 ++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_pad_vaapi.c | 283 +
>  5 files changed, 363 insertions(+)
>  create mode 100644 libavfilter/vf_pad_vaapi.c
> 
> diff --git a/configure b/configure
> index 2b4c4ec9a2..4f64f48b38 100755
> --- a/configure
> +++ b/configure
> @@ -3890,6 +3890,7 @@ vstack_qsv_filter_deps="libmfx"
>  vstack_qsv_filter_select="qsvvpp"
>  xstack_qsv_filter_deps="libmfx"
>  xstack_qsv_filter_select="qsvvpp"
> +pad_vaapi_filter_deps="vaapi_1"
>  
>  # examples
>  avio_http_serve_files_deps="avformat avutil fork"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 913365671d..2bd1a5b9e7 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -27941,6 +27941,83 @@ first input stream. For the syntax of this option,
> check the
>  See @ref{xstack}.
>  @end table
>  
> +@section pad_vaapi
> +
> +Add paddings to the input image, and place the original input at the
> +provided @var{x}, @var{y} coordinates.
> +
> +It accepts the following options:
> +
> +@table @option
> +@item width, w
> +@item height, h
> +Specify an expression for the size of the output image with the
> +paddings added. If the value for @var{width} or @var{height} is 0, the
> +corresponding input size is used for the output.
> +
> +The @var{width} expression can reference the value set by the
> +@var{height} expression, and vice versa.
> +
> +The default value of @var{width} and @var{height} is 0.
> +
> +@item x
> +@item y
> +Specify the offsets to place the input image at within the padded area,
> +with respect to the top/left border of the output image.
> +
> +The @var{x} expression can reference the value set by the @var{y}
> +expression, and vice versa.
> +
> +The default value of @var{x} and @var{y} is 0.
> +
> +If @var{x} or @var{y} evaluate to a negative number, they'll be changed
> +so the input image is centered on the padded area.
> +
> +@item color
> +Specify the color of the padded area. For the syntax of this option,
> +check the @ref{color syntax,,"Color" section in the ffmpeg-utils
> +manual,ffmpeg-utils}.
> +
> +@item aspect
> +Pad to an aspect instead to a resolution.
> +@end table
> +
> +The value for the @var{width}, @var{height}, @var{x}, and @var{y}
> +options are expressions containing the following constants:
> +
> +@table @option
> +@item in_w
> +@item in_h
> +The input video width and height.
> +
> +@item iw
> +@item ih
> +These are the same as @var{in_w} and @var{in_h}.
> +
> +@item out_w
> +@item out_h
> +The output width and height (the size of the padded area), as
> +specified by the @var{width} and @var{height} expressions.
> +
> +@item ow
> +@item oh
> +These are the same as @var{out_w} and @var{out_h}.
> +
> +@item x
> +@item y
> +The x and y offsets as specified by the @var{x} and @var{y}
> +expressions, or NAN if not yet specified.
> +
> +@item a
> +same as @var{iw} / @var{ih}
> +
> +@item sar
> +input sample aspect ratio
> +
> +@item dar
> +input display aspect ratio, it is the same as (@var{iw} / @var{ih}) *
> @var{sar}
> +@end table
> +
>  @c man end VAAPI VIDEO FILTERS
>  
>  @chapter Vulkan Video Filters
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 994d9773ba..babcc7b676 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -581,6 +581,7 @@ OBJS-$(CONFIG_XSTACK_VAAPI_FILTER)   +=
> vf_stack_vaapi.o framesync.o vaa
>  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_PAD_VAAPI_FILTER)  += vf_pad_vaapi.o vaapi_vpp.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 149bf50997..1e024b3376 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -546,6 +546,7 @@ extern const AVFilter ff_vf_xstack_vaapi;
>  extern const AVFilter ff_vf_hstack_qsv;
>  extern const AVFilter ff_vf_vstack_qsv;
>  extern const AVFilter ff_vf_xstack_qsv;
> +extern const AVFilter ff_vf_pad_vaapi;
>  
>  extern 

Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/vaapi_decode: Use dynamic frame pool if possible

2024-04-14 Thread Xiang, Haihao
On Wo, 2024-04-10 at 11:01 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> libva2 doesn't require a fixed surface-array any more, so we may use
> dynamic frame pool for decoding when libva2 is available, which allows a
> downstream element stores more frames from VAAPI decoders and fixes the
> error below:
> 
> $ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi \
> -i input.mp4 -c:v hevc_vaapi -f null -
> ...
> [h264 @ 0x557a075a1400] get_buffer() failed
> [h264 @ 0x557a075a1400] thread_get_buffer() failed
> [h264 @ 0x557a075a1400] decode_slice_header error
> [h264 @ 0x557a075a1400] no frame!
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_decode.c | 36 
>  1 file changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index 5665639dd7..21b273cd0f 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -599,22 +599,26 @@ static int vaapi_decode_make_config(AVCodecContext
> *avctx,
>  if (err < 0)
>  goto fail;
>  
> -    frames->initial_pool_size = 1;
> -    // Add per-codec number of surfaces used for storing reference
> frames.
> -    switch (avctx->codec_id) {
> -    case AV_CODEC_ID_H264:
> -    case AV_CODEC_ID_HEVC:
> -    case AV_CODEC_ID_AV1:
> -    frames->initial_pool_size += 16;
> -    break;
> -    case AV_CODEC_ID_VP9:
> -    frames->initial_pool_size += 8;
> -    break;
> -    case AV_CODEC_ID_VP8:
> -    frames->initial_pool_size += 3;
> -    break;
> -    default:
> -    frames->initial_pool_size += 2;
> +    if (CONFIG_VAAPI_1)
> +    frames->initial_pool_size = 0;
> +    else {
> +    frames->initial_pool_size = 1;
> +    // Add per-codec number of surfaces used for storing reference
> frames.
> +    switch (avctx->codec_id) {
> +    case AV_CODEC_ID_H264:
> +    case AV_CODEC_ID_HEVC:
> +    case AV_CODEC_ID_AV1:
> +    frames->initial_pool_size += 16;
> +    break;
> +    case AV_CODEC_ID_VP9:
> +    frames->initial_pool_size += 8;
> +    break;
> +    case AV_CODEC_ID_VP8:
> +    frames->initial_pool_size += 3;
> +    break;
> +    default:
> +    frames->initial_pool_size += 2;
> +    }
>  }
>  }
> 
> 

Hi,

I'll merge this patchset if there are no objections.

Thanks
Haihao

>  

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

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


Re: [FFmpeg-devel] [PATCH v3 1/2] avcodec/vaapi_encode_h264: use is_reference to fill reference_pic_flag

2024-04-14 Thread Xiang, Haihao
On Di, 2024-03-05 at 16:02 +0800, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> This codec supports FLAG_B_PICTURE_REFERENCES. We need to correctly fill
> the reference_pic_flag with is_reference variable instead of 0 for B
> frames.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/vaapi_encode_h264.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index 37df9103ae..4a738215c1 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -759,7 +759,7 @@ static int
> vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>  vpic->frame_num = hpic->frame_num;
>  
>  vpic->pic_fields.bits.idr_pic_flag   = (pic->type ==
> PICTURE_TYPE_IDR);
> -    vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
> +    vpic->pic_fields.bits.reference_pic_flag = pic->is_reference;
>  
>  return 0;
>  }

Patchset LGTM, will apply, 

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-04-14 Thread Xiang, Haihao
On Ma, 2024-03-18 at 12:21 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> There is no Main8/10 profile defined in HEVC REXT profiles. Use Main12
> which is compatible with 8/10bit.
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_encode_h265.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index c4aabbf5ed..43755e2188 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -1305,12 +1305,12 @@ static av_cold int
> vaapi_encode_h265_configure(AVCodecContext *avctx)
>  
>  static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
>  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain   },
> -    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain   },
>  #if VA_CHECK_VERSION(0, 37, 0)
>  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
> -    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain10 },
>  #endif
>  #if VA_CHECK_VERSION(1, 2, 0)
> +    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain12 },
> +    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain12 },
>  { AV_PROFILE_HEVC_REXT,    12, 3, 1, 1, VAProfileHEVCMain12 },
>  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
>  { AV_PROFILE_HEVC_REXT,    10, 3, 1, 0, VAProfileHEVCMain422_10 },

Patchset LGTM, I'll push it if there are no comments.

Thanks
Haihao


___
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 2/2] lavfi/vaapi_vpp: Use dynamic frame pool in outlink if possible

2024-04-09 Thread Xiang, Haihao
From: Haihao Xiang 

This can avoid to exhaust the buffers within outlink when libva2 is
available.

For example:
$ ffmpeg -hwaccel_output_format vaapi -hwaccel vaapi -i input.mp4 \
-vf 'scale_vaapi=w=720:h=480' -c:v hevc_vaapi -f null -
...
[vf#0:0 @ 0x55acad91f400] Error while filtering: Cannot allocate memory
[vf#0:0 @ 0x55acad91f400] Task finished with error code: -12 (Cannot
allocate memory)
[vf#0:0 @ 0x55acad91f400] Terminating thread with return code -12
(Cannot allocate memory)

Signed-off-by: Haihao Xiang 
---
 libavfilter/vaapi_vpp.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index ace1153a23..9ef7a289fb 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -204,7 +204,10 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 output_frames->width = ctx->output_width;
 output_frames->height= ctx->output_height;
 
-output_frames->initial_pool_size = 4;
+if (CONFIG_VAAPI_1)
+output_frames->initial_pool_size = 0;
+else
+output_frames->initial_pool_size = 4;
 
 err = ff_filter_init_hw_frames(avctx, outlink, 10);
 if (err < 0)
@@ -220,6 +223,8 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 va_frames = output_frames->hwctx;
 
 av_assert0(ctx->va_context == VA_INVALID_ID);
+av_assert0(output_frames->initial_pool_size ||
+   (va_frames->surface_ids == NULL && va_frames->nb_surfaces == 
0));
 vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
   ctx->output_width, ctx->output_height,
   VA_PROGRESSIVE,
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 1/2] lavc/vaapi_decode: Use dynamic frame pool if possible

2024-04-09 Thread Xiang, Haihao
From: Haihao Xiang 

libva2 doesn't require a fixed surface-array any more, so we may use
dynamic frame pool for decoding when libva2 is available, which allows a
downstream element stores more frames from VAAPI decoders and fixes the
error below:

$ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi \
-i input.mp4 -c:v hevc_vaapi -f null -
...
[h264 @ 0x557a075a1400] get_buffer() failed
[h264 @ 0x557a075a1400] thread_get_buffer() failed
[h264 @ 0x557a075a1400] decode_slice_header error
[h264 @ 0x557a075a1400] no frame!

Signed-off-by: Haihao Xiang 
---
 libavcodec/vaapi_decode.c | 36 
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 5665639dd7..21b273cd0f 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -599,22 +599,26 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 
-frames->initial_pool_size = 1;
-// Add per-codec number of surfaces used for storing reference frames.
-switch (avctx->codec_id) {
-case AV_CODEC_ID_H264:
-case AV_CODEC_ID_HEVC:
-case AV_CODEC_ID_AV1:
-frames->initial_pool_size += 16;
-break;
-case AV_CODEC_ID_VP9:
-frames->initial_pool_size += 8;
-break;
-case AV_CODEC_ID_VP8:
-frames->initial_pool_size += 3;
-break;
-default:
-frames->initial_pool_size += 2;
+if (CONFIG_VAAPI_1)
+frames->initial_pool_size = 0;
+else {
+frames->initial_pool_size = 1;
+// Add per-codec number of surfaces used for storing reference 
frames.
+switch (avctx->codec_id) {
+case AV_CODEC_ID_H264:
+case AV_CODEC_ID_HEVC:
+case AV_CODEC_ID_AV1:
+frames->initial_pool_size += 16;
+break;
+case AV_CODEC_ID_VP9:
+frames->initial_pool_size += 8;
+break;
+case AV_CODEC_ID_VP8:
+frames->initial_pool_size += 3;
+break;
+default:
+frames->initial_pool_size += 2;
+}
 }
 }
 
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add a new quirk

2024-04-06 Thread Xiang, Haihao
On Wo, 2024-04-03 at 20:21 +0100, Mark Thompson wrote:
> On 28/03/2024 02:17, Xiang, Haihao wrote:
> > From: Haihao Xiang 
> > 
> > libva2 doesn't require a fixed surface-array any more, but some
> > driver/hardware combinations which rely on this are still used. To
> > reduce the impact to users, add a quirk for the driver/hardware
> > combination which supports dynamic surface pool.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >   libavutil/hwcontext_vaapi.c | 7 +++
> >   libavutil/hwcontext_vaapi.h | 6 ++
> >   2 files changed, 13 insertions(+)
> > 
> > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> > index 56d03aa4cd..dae5dd4a11 100644
> > --- a/libavutil/hwcontext_vaapi.c
> > +++ b/libavutil/hwcontext_vaapi.c
> > @@ -390,6 +390,13 @@ static const struct {
> >   "Splitted-Desktop Systems VDPAU backend for VA-API",
> >   AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
> >   },
> > +#if CONFIG_VAAPI_1
> > +    {
> > +    "New Intel iHD",
> > +    "Intel iHD driver for Intel(R) Gen Graphics",
> > +    AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
> > +    },
> > +#endif
> >   };
> >   
> >   static int vaapi_device_init(AVHWDeviceContext *hwdev)
> > diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
> > index 0b2e071cb3..07014fd526 100644
> > --- a/libavutil/hwcontext_vaapi.h
> > +++ b/libavutil/hwcontext_vaapi.h
> > @@ -58,6 +58,12 @@ enum {
> >    * and the results of the vaQuerySurfaceAttributes() call will be
> > faked.
> >    */
> >   AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
> > +
> > +    /**
> > + * The driver (and the underlying HW) supports dynamic surface pool.
> > + * The vaCreateContext() call doesn't require a fixed surface-array.
> > + */
> > +    AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
> >   };
> >   
> >   /**
> 
> I do not think a vendor-specific quirk like this is a reasonable answer, but I
> can see that your company is invested in making sure that your current driver
> doesn't hit this problem.
> 
> Given that, I give up on arguing for trying to preserve compatibility here. 
> Let's just use dynamic pools unconditionally and see if anything breaks.

Thanks, I'll update the patchset to use dynamic pools for all drivers when libva
>= 2.0. 

> 
> Is there any reason not to drop support for libva < 2.0 at the same time? 
> (Making CONFIG_VAAPI_1 always true.)  It is of similar age to C17, which we
> are intending to require soon as well.

We are considering to drop the support for libva < 2.0, but we can't be sure
whether user is still using libva < 2.0.

If there isn't any objection about dropping the support for libva < 2.0, We will
use a separate patch to drop the support.

BRs
Haihao

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add a new quirk

2024-04-02 Thread Xiang, Haihao
On Do, 2024-03-28 at 10:17 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> libva2 doesn't require a fixed surface-array any more, but some
> driver/hardware combinations which rely on this are still used. To
> reduce the impact to users, add a quirk for the driver/hardware
> combination which supports dynamic surface pool.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavutil/hwcontext_vaapi.c | 7 +++
>  libavutil/hwcontext_vaapi.h | 6 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 56d03aa4cd..dae5dd4a11 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -390,6 +390,13 @@ static const struct {
>  "Splitted-Desktop Systems VDPAU backend for VA-API",
>  AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
>  },
> +#if CONFIG_VAAPI_1
> +    {
> +    "New Intel iHD",
> +    "Intel iHD driver for Intel(R) Gen Graphics",
> +    AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
> +    },
> +#endif
>  };
>  
>  static int vaapi_device_init(AVHWDeviceContext *hwdev)
> diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
> index 0b2e071cb3..07014fd526 100644
> --- a/libavutil/hwcontext_vaapi.h
> +++ b/libavutil/hwcontext_vaapi.h
> @@ -58,6 +58,12 @@ enum {
>   * and the results of the vaQuerySurfaceAttributes() call will be faked.
>   */
>  AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
> +
> +    /**
> + * The driver (and the underlying HW) supports dynamic surface pool.
> + * The vaCreateContext() call doesn't require a fixed surface-array.
> + */
> +    AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
>  };
>  
>  /**

I will merge this patchset if there are no objections.

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-04-02 Thread Xiang, Haihao
On Di, 2024-04-02 at 22:01 +0100, Mark Thompson wrote:
> On 02/04/2024 07:55, Xiang, Haihao wrote:
> > On Ma, 2024-04-01 at 21:11 +0100, Mark Thompson wrote:
> > > On 28/03/2024 02:07, Xiang, Haihao wrote:
> > > > From: Haihao Xiang 
> > > > 
> > > > Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
> > > > instead for decoding. This patch fixes the error below:
> > > > 
> > > > [hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
> > > > [hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
> > > > initialisation returned error.
> > > > 
> > > > Signed-off-by: Haihao Xiang 
> > > > ---
> > > >    libavcodec/vaapi_hevc.c | 7 +++
> > > >    1 file changed, 7 insertions(+)
> > > > 
> > > > diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> > > > index 3bdd2dd1b8..83b94d1a55 100644
> > > > --- a/libavcodec/vaapi_hevc.c
> > > > +++ b/libavcodec/vaapi_hevc.c
> > > > @@ -612,6 +612,13 @@ VAProfile
> > > > ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
> > > >    av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n",
> > > > profile->name);
> > > >    }
> > > >    
> > > > +#if VA_CHECK_VERSION(0, 37, 0)
> > > > +    if (!strcmp(profile->name, "Main Intra"))
> > > > +    return VAProfileHEVCMain;
> > > > +    else if (!strcmp(profile->name, "Main 10 Intra"))
> > > > +    return VAProfileHEVCMain10;
> > > > +#endif
> > > > +
> > > >    #if VA_CHECK_VERSION(1, 2, 0)
> > > >    if (!strcmp(profile->name, "Main 12") ||
> > > >    !strcmp(profile->name, "Main 12 Intra"))
> > > 
> > > What if high_precision_offsets_enabled_flag is set?
> > > 
> > > (That doesn't matter for the VAAPI encoder setting the profile because we
> > > always have it as zero.)
> > 
> > Here use VAProfileHEVCMain or VAProfileHEVCMain10 to create VAConfig for
> > decoding,  avctx->profile (4) is not changed.
> > high_precision_offsets_enabled_flag is set in
> > VAPictureParameterBufferHEVCRext
> > when avctx->profile is 4.
> 
> But Main and Main 10 profile have:
> 
> "Active SPSs for the base layer shall have ...
> high_precision_offsets_enabled_flag, ... when present, equal to 0 only."
> 
> so a decoder implementing those profiles need not support it.  (It may work as
> a compatible extension as the field is there, but if it doesn't also support
> general rext cases then this is unlikely to be implemented.)
> 

I get your point, the underlying driver mightn't support
VAPictureParameterBufferHEVCRext. Seems we should add new profiles in libva. 

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-04-01 Thread Xiang, Haihao
On Ma, 2024-04-01 at 21:11 +0100, Mark Thompson wrote:
> On 28/03/2024 02:07, Xiang, Haihao wrote:
> > From: Haihao Xiang 
> > 
> > Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
> > instead for decoding. This patch fixes the error below:
> > 
> > [hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
> > [hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
> > initialisation returned error.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >   libavcodec/vaapi_hevc.c | 7 +++
> >   1 file changed, 7 insertions(+)
> > 
> > diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> > index 3bdd2dd1b8..83b94d1a55 100644
> > --- a/libavcodec/vaapi_hevc.c
> > +++ b/libavcodec/vaapi_hevc.c
> > @@ -612,6 +612,13 @@ VAProfile
> > ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
> >   av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n",
> > profile->name);
> >   }
> >   
> > +#if VA_CHECK_VERSION(0, 37, 0)
> > +    if (!strcmp(profile->name, "Main Intra"))
> > +    return VAProfileHEVCMain;
> > +    else if (!strcmp(profile->name, "Main 10 Intra"))
> > +    return VAProfileHEVCMain10;
> > +#endif
> > +
> >   #if VA_CHECK_VERSION(1, 2, 0)
> >   if (!strcmp(profile->name, "Main 12") ||
> >   !strcmp(profile->name, "Main 12 Intra"))
> 
> What if high_precision_offsets_enabled_flag is set?
> 
> (That doesn't matter for the VAAPI encoder setting the profile because we
> always have it as zero.)

Here use VAProfileHEVCMain or VAProfileHEVCMain10 to create VAConfig for
decoding,  avctx->profile (4) is not changed.
high_precision_offsets_enabled_flag is set in VAPictureParameterBufferHEVCRext
when avctx->profile is 4.

BRs
Haihao

> 
> Thanks,
> 
> - Mark
> ___
> 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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-03-31 Thread Xiang, Haihao
On Do, 2024-03-28 at 10:07 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
> instead for decoding. This patch fixes the error below:
> 
> [hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
> [hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
> initialisation returned error.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_hevc.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
> index 3bdd2dd1b8..83b94d1a55 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -612,6 +612,13 @@ VAProfile
> ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
>  av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n", profile-
> >name);
>  }
>  
> +#if VA_CHECK_VERSION(0, 37, 0)
> +    if (!strcmp(profile->name, "Main Intra"))
> +    return VAProfileHEVCMain;
> +    else if (!strcmp(profile->name, "Main 10 Intra"))
> +    return VAProfileHEVCMain10;
> +#endif
> +
>  #if VA_CHECK_VERSION(1, 2, 0)
>  if (!strcmp(profile->name, "Main 12") ||
>  !strcmp(profile->name, "Main 12 Intra"))

Will apply,

- Haihao


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

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


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: convert from lambda to qp

2024-03-31 Thread Xiang, Haihao
On Do, 2024-03-28 at 14:55 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> When AV_CODEC_FLAG_QSCALE is set, the value of avctx->global_quality is
> lambda.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavcodec/vaapi_encode.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 940f0678a5..8b53095d61 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1961,7 +1961,10 @@ rc_mode_found:
>  if (ctx->explicit_qp) {
>  rc_quality = ctx->explicit_qp;
>  } else if (avctx->global_quality > 0) {
> -    rc_quality = avctx->global_quality;
> +    if (avctx->flags & AV_CODEC_FLAG_QSCALE)
> +    rc_quality = avctx->global_quality / FF_QP2LAMBDA;
> +    else
> +    rc_quality = avctx->global_quality;
>  } else {
>  rc_quality = ctx->codec->default_quality;
>  av_log(avctx, AV_LOG_WARNING, "No quality level set; "

Will apply,

- Haihao


___
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   4   5   6   7   8   9   10   >