[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, >mdcv,
> >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   = ##_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-23 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, >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, >mdcv, 
>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, >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, >mdcv, 
>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-13 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-13 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, );
> +    if (ret == MFX_ERR_NONE)
> +    ret = MFXQueryVersion(device_hwctx->session, );
> +    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, );
> -    if (ret == MFX_ERR_NONE)
> -    ret = MFXQueryVersion(device_hwctx->session, );
> -    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,
> );
>  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-08 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  = >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 = >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, _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 = _encode_av1_init_slice_params,
> +
> +    .write_extra_header = _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-08 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-08 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-08 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, );
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, );
+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, );
-if (ret == MFX_ERR_NONE)
-ret = MFXQueryVersion(device_hwctx->session, );
-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, );
 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-08 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, >ver) != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
-q->session = NULL;
+if (MFXQueryIMPL(q->session, ) == 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, >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-08 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 ? 
_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 ? 
_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-08 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  = >Info;
-mfxFrameInfo  *i1 = _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 = _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  = >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**)>mids[resp->NumFrameActual]);
 ff_refstruct_unref(>mids[resp->NumFrameActual + 1]);
 av_freep(>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(_mid->locked_frame);
 av_frame_free(_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_frames(AVCodecContext *avctx, 
mfxSession 

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

2024-05-08 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(_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(_pairs_internal);
+av_freep(_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(_pairs_internal);
+av_freep(_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-08 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 = >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(_surf1, 0, sizeof(mfx_surf1));
+qsv_init_surface(dst_ctx, _surf1);
+s->frame_info = mfx_surf1.Info;
+dst_hwctx->info = >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 = >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-08 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(_pair->first);
+#endif
+
+av_freep(_pair);
+av_frame_free(_surface->child_frame);
+av_freep(_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, _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;
+return 

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

2024-05-08 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 = >p;
 mfxFrameInfo *i  = >Info;
-mfxFrameInfo *i1 = >surfaces[0].Info;
+mfxFrameInfo *i1 = hwctx->nb_surfaces ? >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, _param,
> +    err = ff_vaapi_decode_make_slice_buffer(avctx, pic, _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,
>   >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,
> -    _param,
> sizeof(slice_param),
> +    _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,
> -    >last_slice_param,
> slice_param_size,
> +    >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,
> -    >last_slice_param,
> slice_param_size,
> +    >last_slice_param, 1,
> slice_param_size,
>  pic->last_buffer, pic-
> >last_size);
>  pic->last_buffer = NULL;
>  pic->last_size   = 0;
> diff 

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 *)());
> +    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 = >p;
> >  mfxFrameInfo *i  = >Info;
> > -    mfxFrameInfo *i1 = >surfaces[0].Info;
> > +    mfxFrameInfo *i1 = hwctx->nb_surfaces ? >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-30 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-30 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, >ver) != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
-q->session = NULL;
+if (MFXQueryIMPL(q->session, ) == 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, >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, );
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, );
+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, );
-if (ret == MFX_ERR_NONE)
-ret = MFXQueryVersion(device_hwctx->session, );
-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, );
 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 ? 
_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 ? 
_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  = >Info;
-mfxFrameInfo  *i1 = _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 = _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  = >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**)>mids[resp->NumFrameActual]);
 ff_refstruct_unref(>mids[resp->NumFrameActual + 1]);
 av_freep(>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(_mid->locked_frame);
 av_frame_free(_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_frames(AVCodecContext *avctx, 
mfxSession 

[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(_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(_pairs_internal);
+av_freep(_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(_pairs_internal);
+av_freep(_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 = >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(_surf1, 0, sizeof(mfx_surf1));
+qsv_init_surface(dst_ctx, _surf1);
+s->frame_info = mfx_surf1.Info;
+dst_hwctx->info = >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 = >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(_pair->first);
+#endif
+
+av_freep(_pair);
+av_frame_free(_surface->child_frame);
+av_freep(_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, _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;
+return 

[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 = >p;
 mfxFrameInfo *i  = >Info;
-mfxFrameInfo *i1 = >surfaces[0].Info;
+mfxFrameInfo *i1 = hwctx->nb_surfaces ? >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(_frame->frame);
>  return NULL;
>  }
> -
> -    if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
> -    av_frame_free(_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,
>     _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(_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,1

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, ,
> > > vaflags);
> > > +#else
> > >  vas = vaMapBuffer(hwctx->display, map->image.buf, );
> > > +#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(_frame->frame);
 return NULL;
 }
-
-if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
-av_frame_free(_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,
_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(_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, , 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_stack_qsv.c 

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();
>  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();
>  }
> 
> -#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, _device_log_error, ctx);
>  vaSetInfoCallback (display, _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 = _profiles[i];
> +    desc = _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 _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 _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_PROFILE_MAIN_444_10,
> + 

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(_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();
> -    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 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(>session_lock);
> -#endif
> +    ff_mutex_destroy(>session_lock);
>  
>  av_freep(>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(>session_lock, NULL);
> -#endif
> +    ff_mutex_init(>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(>session_lock);
> -#endif
> +    ff_mutex_lock(>session_lock);
>  
>  if (!atomic_load(inited)) {
>  ret = qsv_init_internal_session(ctx, session, upload);
>  atomic_store(inited, 1);
>  }
>  
> -#if HAVE_PTHREADS
> -    pthread_mutex_unlock(>session_lock);
> -#endif
> +    ff_mutex_unlock(>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 = >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(>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(>session_lock);
> +
> +    return ret;
> +}
> +
> +static int 

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.frames[CUR_FRAME].tf, INT_MAX);
> >  
> >  finish:
> > +    ff_progress_frame_report(>s.frames[CUR_FRAME].tf, INT_MAX);
> >  // ref frame setup
> >  for (int i = 0; i < 8; i++)
> >  ff_progress_frame_replace(>s.refs[i], >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.frames[CUR_FRAME].tf, INT_MAX);
 
 finish:
+ff_progress_frame_report(>s.frames[CUR_FRAME].tf, INT_MAX);
 // ref frame setup
 for (int i = 0; i < 8; i++)
 ff_progress_frame_replace(>s.refs[i], >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(>session_lock);
> -#endif
> +    ff_mutex_destroy(>session_lock);
>  
>  av_freep(>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(>session_lock, NULL);
> -#endif
> +    ff_mutex_init(>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(>session_lock);
> -#endif
> +    ff_mutex_lock(>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(>session_lock);
> -#endif
> +    ff_mutex_unlock(>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 = >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(>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(>session_lock);
> +
> +    return 

[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 = >mh[priv->nb_mh++];
+AV1RawMetadata   *md = >obu.metadata;
+AV1RawMetadataHDRCLL*cll = >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 = >mh[priv->nb_mh++];
+AV1RawMetadata  *md = >obu.metadata;
+AV1RawMetadataHDRMDCV *mdcv = >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  = >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 = >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, _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 = _encode_av1_init_slice_params,
+
+.write_extra_header = _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 const

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-02 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-04-01 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-04-01 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".


Re: [FFmpeg-devel] [PATCH v1] lavc/vaapi_encode: Add VAAPI version check for BLBRC

2024-04-01 Thread Xiang, Haihao
On Vr, 2024-03-29 at 09:10 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> From: Fei Wang 
> 
> Fix build fail when VAAPI version less than 0.39.2.
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_encode.c | 20 +---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 940f0678a5..c4b5411e68 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1805,9 +1805,17 @@ static av_cold int
> vaapi_encode_init_rate_control(AVCodecContext *avctx)
>  int i, first = 1, res;
>  
>  supported_va_rc_modes = rc_attr.value;
> -    if (ctx->blbrc && !(supported_va_rc_modes & VA_RC_MB)) {
> +    if (ctx->blbrc) {
> +#if VA_CHECK_VERSION(0, 39, 2)
> +    if (!(supported_va_rc_modes & VA_RC_MB)) {
> +    ctx->blbrc = 0;
> +    av_log(avctx, AV_LOG_WARNING, "Driver does not support
> BLBRC.\n");
> +    }
> +#else
>  ctx->blbrc = 0;
> -    av_log(avctx, AV_LOG_WARNING, "Driver does not support
> BLBRC.\n");
> +    av_log(avctx, AV_LOG_WARNING, "Please consider to update to VAAPI
> 0.39.2 "
> +   "or above, which can support BLBRC.\n");
> +#endif
>  }
>  
>  for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
> @@ -2032,7 +2040,11 @@ rc_mode_found:
>  ctx->config_attributes[ctx->nb_config_attributes++] =
>  (VAConfigAttrib) {
>  .type  = VAConfigAttribRateControl,
> +#if VA_CHECK_VERSION(0, 39, 2)
>  .value = ctx->blbrc ? ctx->va_rc_mode | VA_RC_MB : ctx-
> >va_rc_mode,
> +#else
> +    .value = ctx->va_rc_mode,
> +#endif
>  };
>  }
>  
> @@ -2061,10 +2073,12 @@ rc_mode_found:
>  #if VA_CHECK_VERSION(1, 1, 0)
>  .ICQ_quality_factor = av_clip(rc_quality, 1, 51),
>  .max_qp = (avctx->qmax > 0 ? avctx->qmax : 0),
> -    .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2,
>  #endif
>  #if VA_CHECK_VERSION(1, 3, 0)
>  .quality_factor = rc_quality,
> +#endif
> +#if VA_CHECK_VERSION(0, 39, 2)
> +    .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2,
>  #endif
>  };
>  vaapi_encode_add_global_param(avctx,

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".


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

2024-03-28 Thread Xiang, Haihao
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; "
-- 
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/3] lavfi/vaapi_vpp: Use dynamic frame pool in outlink if possible

2024-03-27 Thread Xiang, Haihao
From: Haihao Xiang 

This can fix the broken cases for the driver/hardware combination which
doesn't rely on fixed surface-array.

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 -

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 59961bfa4a..0755d674ac 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -203,7 +203,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 (ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL)
+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)
@@ -219,6 +222,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 2/3] lavc/vaapi_decode: Use dynamic frame pool if possible

2024-03-27 Thread Xiang, Haihao
From: Haihao Xiang 

This allows a downstream element stores more frames from VAAPI
decoders and fixes the broke cases for the driver/hardware
combination which doesn't rely on fixed surface-array.

For example:
$ 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 cca94b5336..c690e25342 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -598,22 +598,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 (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL)
+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".


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

2024-03-27 Thread Xiang, Haihao
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),
 };
 
 /**
-- 
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] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-03-27 Thread Xiang, Haihao
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"))
-- 
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] avcodec/d3d12va_decode: remove extra spaces for declaration

2024-03-25 Thread Xiang, Haihao
On Di, 2024-03-19 at 16:02 +0800, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/d3d12va_decode.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
> index af7cf11640..c61f8c685a 100644
> --- a/libavcodec/d3d12va_decode.c
> +++ b/libavcodec/d3d12va_decode.c
> @@ -269,7 +269,7 @@ fail:
>  
>  int ff_d3d12va_common_frame_params(AVCodecContext *avctx, AVBufferRef
> *hw_frames_ctx)
>  {
> -    AVHWFramesContext  *frames_ctx   = (AVHWFramesContext
> *)hw_frames_ctx->data;
> +    AVHWFramesContext *frames_ctx = (AVHWFramesContext *)hw_frames_ctx->data;
>  
>  frames_ctx->format    = AV_PIX_FMT_D3D12;
>  frames_ctx->sw_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ?
> AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
> @@ -410,7 +410,7 @@ int ff_d3d12va_decode_uninit(AVCodecContext *avctx)
>  static inline int d3d12va_update_reference_frames_state(AVCodecContext
> *avctx, D3D12_RESOURCE_BARRIER *barriers,
>  ID3D12Resource
> *current_resource, int state_before, int state_end)
>  {
> -    D3D12VADecodeContext   *ctx  = D3D12VA_DECODE_CONTEXT(avctx);
> +    D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
>  
>  int num_barrier = 0;
>  for (int i = 0; i < ctx->max_num_ref; i++) {

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 v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-25 Thread Xiang, Haihao
On Di, 2024-03-19 at 22:52 +, Mark Thompson wrote:
> On 19/03/2024 04:16, Xiang, Haihao wrote:
> > On Ma, 2024-03-18 at 21:33 +, Mark Thompson wrote:
> > > On 18/03/2024 05:53, Xiang, Haihao wrote:
> > > > On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:
> > > > > For hardware cases where we are forced to have a fixed pool of frames
> > > > > allocated up-front (such as array textures on decoder output), suggest
> > > > > a possible workaround to the user if an allocation fails because the
> > > > > pool is exhausted.
> > > > > ---
> > > > > Perhaps helpful; any thoughts?
> > > > > 
> > > > > The warning comes out before any errors, looking like:
> > > > > 
> > > > > [mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame
> > > > > from a
> > > > > fixed pool of hardware frames.
> > > > > [mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a
> > > > > larger
> > > > > value (currently set to 8, giving a pool size of 14).
> > > > > [mpeg2video @ 0x560ff51b4600] get_buffer() failed
> > > > > [vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @
> > > > > 0x560ff51b3b40]
> > > > > Error
> > > > > submitting packet to decoder: Operation not permitted
> > > > 
> > > > I'm OK to print such warning so user may know how to work around it. But
> > > > now
> > > > many cases are impacted by this error
> > > > (e.g. https://trac.ffmpeg.org/ticket/10856
> > > > ), I think it is a regression to user. I still prefer to use a dynamic
> > > > buffer
> > > > pool instead fixed frame pool to avoid such error when the dynamic
> > > > buffer
> > > > pool
> > > > can work.
> > > 
> > > How would we implement this on D3D11 or D3D12?
> > 
> > I understand not all can support dynamic frame pool, your patch is useful
> > for
> > decoders using fixed pool. But for driver which doesn't require array
> > textures,
> > I think we'd be better to use dynamic frame pool instead so user needn't
> > worry
> > about frame allocation. For example, we may use dynamic frame pool for vaapi
> > with iHD driver, what do you think about adding a quirk to enable dynamic
> > frame
> > pool for special drivers ?
> 
> I think we should come to a conclusion on what the generic code for this case
> should be and then consider whether any special cases are needed.
> 
> When compared to the state right now, I agree with you that just switching
> VAAPI to always be dynamic would probably be better just to avoid the nasty
> failures, but given that we need to improve the situation for cases (like
> D3D11) where we don't have an ad-hoc workaround we should be comparing to
> whatever that concludes rather than the broken state right now.

Hi Mark,

I agree with you. Will you push this patch ? We may switch to dynamic frame pool
for vaapi cases later after pushing your patch. 

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] avutil/hwcontext_qsv: Fix mixed declaration and code

2024-03-25 Thread Xiang, Haihao
On So, 2024-03-24 at 21:30 +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavutil/hwcontext_qsv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index e5e043d2d1..c7c7878644 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -1121,7 +1121,8 @@ fail:
>  static int qsv_init_internal_session(AVHWFramesContext *ctx,
>   mfxSession *session, int upload)
>  {
> -    AVQSVFramesContext *frames_hwctx = ctx->hwctx;
> +    QSVFramesContext  *s = ctx->hwctx;
> +    AVQSVFramesContext *frames_hwctx = >p;
>  QSVDeviceContext   *device_priv  = ctx->device_ctx->hwctx;
>  AVQSVDeviceContext *hwctx    = _priv->p;
>  int opaque = 0;
> @@ -1153,7 +1154,6 @@ static int qsv_init_internal_session(AVHWFramesContext
> *ctx,
>  }
>  
>  #if QSV_HAVE_OPAQUE
> -    QSVFramesContext  *s = ctx->hwctx;
>  opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
>  #endif
>  

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 v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-18 Thread Xiang, Haihao
On Ma, 2024-03-18 at 21:33 +, Mark Thompson wrote:
> On 18/03/2024 05:53, Xiang, Haihao wrote:
> > On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:
> > > For hardware cases where we are forced to have a fixed pool of frames
> > > allocated up-front (such as array textures on decoder output), suggest
> > > a possible workaround to the user if an allocation fails because the
> > > pool is exhausted.
> > > ---
> > > Perhaps helpful; any thoughts?
> > > 
> > > The warning comes out before any errors, looking like:
> > > 
> > > [mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame from a
> > > fixed pool of hardware frames.
> > > [mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a larger
> > > value (currently set to 8, giving a pool size of 14).
> > > [mpeg2video @ 0x560ff51b4600] get_buffer() failed
> > > [vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @ 0x560ff51b3b40]
> > > Error
> > > submitting packet to decoder: Operation not permitted
> > 
> > I'm OK to print such warning so user may know how to work around it. But now
> > many cases are impacted by this error
> > (e.g. https://trac.ffmpeg.org/ticket/10856
> > ), I think it is a regression to user. I still prefer to use a dynamic
> > buffer
> > pool instead fixed frame pool to avoid such error when the dynamic buffer
> > pool
> > can work.
> 
> How would we implement this on D3D11 or D3D12?

I understand not all can support dynamic frame pool, your patch is useful for
decoders using fixed pool. But for driver which doesn't require array textures,
I think we'd be better to use dynamic frame pool instead so user needn't worry
about frame allocation. For example, we may use dynamic frame pool for vaapi
with iHD driver, what do you think about adding a quirk to enable dynamic frame
pool for special drivers ? 

Thanks
Haihao

> 
> A way of doing the second in particular would be very useful, because the
> current decoder only works on a subset of drivers which don't require array
> textures.
> 
> 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] lavu/hwcontext_vulkan: check PCI ID if possible

2024-03-18 Thread Xiang, Haihao
On Ma, 2024-03-18 at 18:41 +0100, Lynne wrote:
> Mar 18, 2024, 08:27 by haihao.xiang-at-intel@ffmpeg.org:
> 
> > From: Haihao Xiang 
> > 
> > Otherwise the derived device and the source device might have different
> > PCI ID in a multiple-device system.
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  libavutil/hwcontext_vulkan.c | 30 +++---
> >  1 file changed, 23 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> > index 855f099e26..91b9f96ccf 100644
> > --- a/libavutil/hwcontext_vulkan.c
> > +++ b/libavutil/hwcontext_vulkan.c
> > @@ -1597,15 +1597,31 @@ static int vulkan_device_derive(AVHWDeviceContext
> > *ctx,
> >  #if CONFIG_VAAPI
> >  case AV_HWDEVICE_TYPE_VAAPI: {
> >  AVVAAPIDeviceContext *src_hwctx = src_ctx->hwctx;
> > +    VADisplay dpy = src_hwctx->display;
> > +#if VA_CHECK_VERSION(1, 15, 0)
> > +    VAStatus vas;
> > +    VADisplayAttribute attr = {
> > +    .type = VADisplayPCIID,
> > +    };
> > +#endif
> > +    const char *vendor;
> >  
> > -    const char *vendor = vaQueryVendorString(src_hwctx->display);
> > -    if (!vendor) {
> > -    av_log(ctx, AV_LOG_ERROR, "Unable to get device info from
> > VAAPI!\n");
> > -    return AVERROR_EXTERNAL;
> > -    }
> > +#if VA_CHECK_VERSION(1, 15, 0)
> > +    vas = vaGetDisplayAttributes(dpy, , 1);
> > +    if (vas == VA_STATUS_SUCCESS && attr.flags !=
> > VA_DISPLAY_ATTRIB_NOT_SUPPORTED)
> > +    dev_select.pci_device = (attr.value & 0x);
> > +#endif
> > +
> > +    if (!dev_select.pci_device) {
> > +    vendor = vaQueryVendorString(dpy);
> > +    if (!vendor) {
> > +    av_log(ctx, AV_LOG_ERROR, "Unable to get device info from
> > VAAPI!\n");
> > +    return AVERROR_EXTERNAL;
> > +    }
> >  
> > -    if (strstr(vendor, "AMD"))
> > -    dev_select.vendor_id = 0x1002;
> > +    if (strstr(vendor, "AMD"))
> > +    dev_select.vendor_id = 0x1002;
> > 
> 
> LGTM

Thanks for reviewing the patch, pushed.

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 3/3] lavfi/tonemap_vaapi: Add support for HDR to HDR tone mapping

2024-03-18 Thread Xiang, Haihao
From: Xinpeng Sun 

Usage example:
ffmpeg -y -hwaccel vaapi -hwaccel_output_format vaapi -i hdr.mp4 \
-vf "tonemap_vaapi=display=7500 3000|34000 16000|13250 34500|15635 16450|500 
1000:extra_hw_frames=64" \
-c:v hevc_vaapi output.mp4

Signed-off-by: Xinpeng Sun 
Signed-off-by: Haihao Xiang 
---
 doc/filters.texi   |  42 +---
 libavfilter/vf_tonemap_vaapi.c | 191 +
 2 files changed, 203 insertions(+), 30 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 2cb84c1476..fb18fecfa5 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -27818,8 +27818,7 @@ The inputs have same memory layout for color channels, 
the overlay has additiona
 
 @section tonemap_vaapi
 
-Perform HDR(High Dynamic Range) to SDR(Standard Dynamic Range) conversion with 
tone-mapping.
-It maps the dynamic range of HDR10 content to the SDR content.
+Perform HDR-to-SDR or HDR-to-HDR tone-mapping.
 It currently only accepts HDR10 as input.
 
 It accepts the following parameters:
@@ -27828,28 +27827,42 @@ It accepts the following parameters:
 @item format
 Specify the output pixel format.
 
-Currently supported formats are:
-@table @var
-@item p010
-@item nv12
-@end table
-
-Default is nv12.
+Default is nv12 for HDR-to-SDR tone-mapping and p010 for HDR-to-HDR
+tone-mapping.
 
 @item primaries, p
 Set the output color primaries.
 
-Default is bt709.
+Default is bt709 for HDR-to-SDR tone-mapping and same as input for HDR-to-HDR
+tone-mapping.
 
 @item transfer, t
 Set the output transfer characteristics.
 
-Default is bt709.
+Default is bt709 for HDR-to-SDR tone-mapping and same as input for HDR-to-HDR
+tone-mapping.
 
 @item matrix, m
 Set the output colorspace matrix.
 
-Default is bt709.
+Default is bt709 for HDR-to-SDR tone-mapping and same as input for HDR-to-HDR
+tone-mapping.
+
+@item display
+Set the output mastering display colour volume. It is given by a '|'-separated
+list of two values, two values are space separated. It set display primaries
+x & y in G, B, R order, then white point x & y, the the nominal minimum & 
maximum
+display luminances.
+
+HDR-to-HDR tone-mapping will be performed when this option is set.
+
+@item light
+Set the output content light level information. It accepts 2 space-separated
+values, the first input is the maximum light level and the second input is
+he maximum average light level.
+
+It is ignored for HDR-to-SDR tone-mapping, and optional for HDR-to-HDR
+tone-mapping.
 
 @end table
 
@@ -27861,6 +27874,11 @@ Convert HDR(HDR10) video to 
bt2020-transfer-characteristic p010 format
 @example
 tonemap_vaapi=format=p010:t=bt2020-10
 @end example
+@item
+Convert HDR video to HDR video
+@example
+tonemap_vaapi=display=7500\ 3000|34000\ 16000|13250\ 34500|15635\ 16450|500\ 
1000
+@end example
 @end itemize
 
 @section hstack_vaapi
diff --git a/libavfilter/vf_tonemap_vaapi.c b/libavfilter/vf_tonemap_vaapi.c
index 5d475e8ff2..7ebcb18f79 100644
--- a/libavfilter/vf_tonemap_vaapi.c
+++ b/libavfilter/vf_tonemap_vaapi.c
@@ -39,7 +39,11 @@ typedef struct HDRVAAPIContext {
 enum AVColorTransferCharacteristic color_transfer;
 enum AVColorSpace color_matrix;
 
+char *mastering_display;
+char *content_light;
+
 VAHdrMetaDataHDR10  in_metadata;
+VAHdrMetaDataHDR10  out_metadata;
 
 AVFrameSideData*src_display;
 AVFrameSideData*src_light;
@@ -146,6 +150,87 @@ static int tonemap_vaapi_save_metadata(AVFilterContext 
*avctx, AVFrame *input_fr
 return 0;
 }
 
+static int tonemap_vaapi_update_sidedata(AVFilterContext *avctx, AVFrame 
*output_frame)
+{
+HDRVAAPIContext *ctx = avctx->priv;
+AVFrameSideData *metadata;
+AVMasteringDisplayMetadata *hdr_meta;
+AVFrameSideData *metadata_lt;
+AVContentLightMetadata *hdr_meta_lt;
+int i;
+const int mapping[3] = {1, 2, 0};  //green, blue, red
+const int chroma_den = 5;
+const int luma_den   = 1;
+
+metadata = av_frame_new_side_data(output_frame,
+  AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
+  sizeof(AVMasteringDisplayMetadata));
+if (!metadata)
+return AVERROR(ENOMEM);
+
+hdr_meta = (AVMasteringDisplayMetadata *)metadata->data;
+
+for (i = 0; i < 3; i++) {
+const int j = mapping[i];
+hdr_meta->display_primaries[j][0].num = 
ctx->out_metadata.display_primaries_x[i];
+hdr_meta->display_primaries[j][0].den = chroma_den;
+
+hdr_meta->display_primaries[j][1].num = 
ctx->out_metadata.display_primaries_y[i];
+hdr_meta->display_primaries[j][1].den = chroma_den;
+}
+
+hdr_meta->white_point[0].num = ctx->out_metadata.white_point_x;
+hdr_meta->white_point[0].den = chroma_den;
+
+hdr_meta->white_point[1].num = ctx->out_metadata.white_point_y;
+hdr_meta->white_point[1].den = chroma_den;
+hdr_meta->has_primaries = 1;
+
+hdr_meta->max_luminance.num = 

[FFmpeg-devel] [PATCH 2/3] lavfi/tonemap_vaapi: Update the log

2024-03-18 Thread Xiang, Haihao
From: Haihao Xiang 

demote the message to AV_LOG_VERBOSE.

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

diff --git a/libavfilter/vf_tonemap_vaapi.c b/libavfilter/vf_tonemap_vaapi.c
index a21f565e3a..5d475e8ff2 100644
--- a/libavfilter/vf_tonemap_vaapi.c
+++ b/libavfilter/vf_tonemap_vaapi.c
@@ -336,7 +336,7 @@ static av_cold int tonemap_vaapi_init(AVFilterContext 
*avctx)
 vpp_ctx->output_format = av_get_pix_fmt(ctx->output_format_string);
 } else {
 vpp_ctx->output_format = AV_PIX_FMT_NV12;
-av_log(avctx, AV_LOG_WARNING, "Output format not set, use default 
format NV12\n");
+av_log(avctx, AV_LOG_VERBOSE, "Output format not set, use default 
format NV12 for HDR to SDR tone mapping.\n");
 }
 
 #define STRING_OPTION(var_name, func_name, default_value) do { \
-- 
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] lavfi/tonemap_vaapi: By default use bt709 for output frame

2024-03-18 Thread Xiang, Haihao
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;
-- 
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] lavu/hwcontext_vulkan: check both vendor and PCI IDs

2024-03-18 Thread Xiang, Haihao
On Ma, 2024-03-18 at 07:39 +0100, Lynne wrote:
> Mar 18, 2024, 07:33 by haihao.xiang-at-intel@ffmpeg.org:
> 
> > On Ma, 2024-03-18 at 07:18 +0100, Lynne wrote:
> > 
> > > Mar 18, 2024, 06:57 by haihao.xiang-at-intel@ffmpeg.org:
> > > 
> > > > On Vr, 2024-03-08 at 15:13 +0800, Xiang, Haihao wrote:
> > > > 
> > > > > From: Haihao Xiang 
> > > > > 
> > > > > Otherwise the derived device and the source device might have
> > > > > different
> > > > > PCI ID or vendor ID in a multiple-device system.
> > > > > 
> > > > > Signed-off-by: Haihao Xiang 
> > > > > ---
> > > > >  libavutil/hwcontext_vulkan.c | 31 +--
> > > > >  1 file changed, 29 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/libavutil/hwcontext_vulkan.c
> > > > > b/libavutil/hwcontext_vulkan.c
> > > > > index 855f099e26..9d94f74d78 100644
> > > > > --- a/libavutil/hwcontext_vulkan.c
> > > > > +++ b/libavutil/hwcontext_vulkan.c
> > > > > @@ -975,6 +975,20 @@ static int find_device(AVHWDeviceContext *ctx,
> > > > > VulkanDeviceSelection *select)
> > > > >     select->name);
> > > > >  err = AVERROR(ENODEV);
> > > > >  goto end;
> > > > > +    } else if (select->vendor_id && select->pci_device) {
> > > > > +    av_log(ctx, AV_LOG_VERBOSE, "Requested vendor:device
> > > > > %04x:%04x\n",
> > > > > +   select->vendor_id, select->pci_device);
> > > > > +    for (int i = 0; i < num; i++) {
> > > > > +    if (select->vendor_id == prop[i].properties.vendorID &&
> > > > > +    select->pci_device == prop[i].properties.deviceID) {
> > > > > +    choice = i;
> > > > > +    goto end;
> > > > > +    }
> > > > > +    }
> > > > > +    av_log(ctx, AV_LOG_ERROR, "Unable to find device with vendor
> > > > > ID
> > > > > 0x%x
> > > > > "
> > > > > +   "and PCI ID 0x%x!\n", select->vendor_id, select-
> > > > > > pci_device);
> > > > > +    err = AVERROR(EINVAL);
> > > > > +    goto end;
> > > > >  } else if (select->pci_device) {
> > > > >  av_log(ctx, AV_LOG_VERBOSE, "Requested device: 0x%x\n",
> > > > > select-
> > > > > > pci_device);
> > > > >  for (int i = 0; i < num; i++) {
> > > > > @@ -1597,8 +1611,14 @@ static int
> > > > > vulkan_device_derive(AVHWDeviceContext
> > > > > *ctx,
> > > > >  #if CONFIG_VAAPI
> > > > >  case AV_HWDEVICE_TYPE_VAAPI: {
> > > > >  AVVAAPIDeviceContext *src_hwctx = src_ctx->hwctx;
> > > > > -
> > > > > -    const char *vendor = vaQueryVendorString(src_hwctx->display);
> > > > > +    VADisplay dpy = src_hwctx->display;
> > > > > +#if VA_CHECK_VERSION(1, 15, 0)
> > > > > +    VAStatus vas;
> > > > > +    VADisplayAttribute attr = {
> > > > > +    .type = VADisplayPCIID,
> > > > > +    };
> > > > > +#endif
> > > > > +    const char *vendor = vaQueryVendorString(dpy);
> > > > >  if (!vendor) {
> > > > >  av_log(ctx, AV_LOG_ERROR, "Unable to get device info from
> > > > > VAAPI!\n");
> > > > >  return AVERROR_EXTERNAL;
> > > > > @@ -1607,6 +1627,13 @@ static int
> > > > > vulkan_device_derive(AVHWDeviceContext
> > > > > *ctx,
> > > > >  if (strstr(vendor, "AMD"))
> > > > >  dev_select.vendor_id = 0x1002;
> > > > >  
> > > > > +#if VA_CHECK_VERSION(1, 15, 0)
> > > > > +    vas = vaGetDisplayAttributes(dpy, , 1);
> > > > > +    if (vas == VA_STATUS_SUCCESS && attr.flags !=
> > > > > VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
> > > > > +    dev_select.vendor_id = ((attr.value >> 16) & 0x);
> > > > > +    dev_select.pci_device = (attr.value & 0x);
> > > > > +    }
> > > > > +#endif
> > > > >  return vulkan_device_create_internal(ctx, _select, 0,
> > > > > opts,
> > > > > flags);
> > > > >  }
> > > > >  #endif
> > > > > 
> > > > 
> > > > Hi,
> > > > 
> > > > Any comment for this patch ? 
> > > > 
> > > 
> > > Is this possible? For two devices from different vendors to have the same
> > > PCI
> > > ID?
> > > 
> > 
> > I'm not sure for different vendors. But when two devices come from the same
> > vendor (e.g. 8086:56a0 and 8086:4682), vulkan always picks up 8086:56a0 no
> > matter the source device is 8086:4682 if we don't set the device id here.
> > 
> 
> Do you need to check for both vendor and PCI ID?
> If not, could you resend without the custom vendor+pci check
> and just using the regular pci ID check?

I updated the patch to check PCI ID only, please see 
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-March/323661.html

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] lavu/hwcontext_vulkan: check PCI ID if possible

2024-03-18 Thread Xiang, Haihao
From: Haihao Xiang 

Otherwise the derived device and the source device might have different
PCI ID in a multiple-device system.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_vulkan.c | 30 +++---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 855f099e26..91b9f96ccf 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1597,15 +1597,31 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
 #if CONFIG_VAAPI
 case AV_HWDEVICE_TYPE_VAAPI: {
 AVVAAPIDeviceContext *src_hwctx = src_ctx->hwctx;
+VADisplay dpy = src_hwctx->display;
+#if VA_CHECK_VERSION(1, 15, 0)
+VAStatus vas;
+VADisplayAttribute attr = {
+.type = VADisplayPCIID,
+};
+#endif
+const char *vendor;
 
-const char *vendor = vaQueryVendorString(src_hwctx->display);
-if (!vendor) {
-av_log(ctx, AV_LOG_ERROR, "Unable to get device info from 
VAAPI!\n");
-return AVERROR_EXTERNAL;
-}
+#if VA_CHECK_VERSION(1, 15, 0)
+vas = vaGetDisplayAttributes(dpy, , 1);
+if (vas == VA_STATUS_SUCCESS && attr.flags != 
VA_DISPLAY_ATTRIB_NOT_SUPPORTED)
+dev_select.pci_device = (attr.value & 0x);
+#endif
+
+if (!dev_select.pci_device) {
+vendor = vaQueryVendorString(dpy);
+if (!vendor) {
+av_log(ctx, AV_LOG_ERROR, "Unable to get device info from 
VAAPI!\n");
+return AVERROR_EXTERNAL;
+}
 
-if (strstr(vendor, "AMD"))
-dev_select.vendor_id = 0x1002;
+if (strstr(vendor, "AMD"))
+dev_select.vendor_id = 0x1002;
+}
 
 return vulkan_device_create_internal(ctx, _select, 0, opts, 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".


Re: [FFmpeg-devel] [PATCH] lavu/hwcontext_vulkan: check both vendor and PCI IDs

2024-03-18 Thread Xiang, Haihao
On Ma, 2024-03-18 at 07:18 +0100, Lynne wrote:
> Mar 18, 2024, 06:57 by haihao.xiang-at-intel@ffmpeg.org:
> 
> > On Vr, 2024-03-08 at 15:13 +0800, Xiang, Haihao wrote:
> > 
> > > From: Haihao Xiang 
> > > 
> > > Otherwise the derived device and the source device might have different
> > > PCI ID or vendor ID in a multiple-device system.
> > > 
> > > Signed-off-by: Haihao Xiang 
> > > ---
> > >  libavutil/hwcontext_vulkan.c | 31 +--
> > >  1 file changed, 29 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> > > index 855f099e26..9d94f74d78 100644
> > > --- a/libavutil/hwcontext_vulkan.c
> > > +++ b/libavutil/hwcontext_vulkan.c
> > > @@ -975,6 +975,20 @@ static int find_device(AVHWDeviceContext *ctx,
> > > VulkanDeviceSelection *select)
> > >     select->name);
> > >  err = AVERROR(ENODEV);
> > >  goto end;
> > > +    } else if (select->vendor_id && select->pci_device) {
> > > +    av_log(ctx, AV_LOG_VERBOSE, "Requested vendor:device
> > > %04x:%04x\n",
> > > +   select->vendor_id, select->pci_device);
> > > +    for (int i = 0; i < num; i++) {
> > > +    if (select->vendor_id == prop[i].properties.vendorID &&
> > > +    select->pci_device == prop[i].properties.deviceID) {
> > > +    choice = i;
> > > +    goto end;
> > > +    }
> > > +    }
> > > +    av_log(ctx, AV_LOG_ERROR, "Unable to find device with vendor ID
> > > 0x%x
> > > "
> > > +   "and PCI ID 0x%x!\n", select->vendor_id, select-
> > > >pci_device);
> > > +    err = AVERROR(EINVAL);
> > > +    goto end;
> > >  } else if (select->pci_device) {
> > >  av_log(ctx, AV_LOG_VERBOSE, "Requested device: 0x%x\n", select-
> > > > pci_device);
> > >  for (int i = 0; i < num; i++) {
> > > @@ -1597,8 +1611,14 @@ static int vulkan_device_derive(AVHWDeviceContext
> > > *ctx,
> > >  #if CONFIG_VAAPI
> > >  case AV_HWDEVICE_TYPE_VAAPI: {
> > >  AVVAAPIDeviceContext *src_hwctx = src_ctx->hwctx;
> > > -
> > > -    const char *vendor = vaQueryVendorString(src_hwctx->display);
> > > +    VADisplay dpy = src_hwctx->display;
> > > +#if VA_CHECK_VERSION(1, 15, 0)
> > > +    VAStatus vas;
> > > +    VADisplayAttribute attr = {
> > > +    .type = VADisplayPCIID,
> > > +    };
> > > +#endif
> > > +    const char *vendor = vaQueryVendorString(dpy);
> > >  if (!vendor) {
> > >  av_log(ctx, AV_LOG_ERROR, "Unable to get device info from
> > > VAAPI!\n");
> > >  return AVERROR_EXTERNAL;
> > > @@ -1607,6 +1627,13 @@ static int vulkan_device_derive(AVHWDeviceContext
> > > *ctx,
> > >  if (strstr(vendor, "AMD"))
> > >  dev_select.vendor_id = 0x1002;
> > >  
> > > +#if VA_CHECK_VERSION(1, 15, 0)
> > > +    vas = vaGetDisplayAttributes(dpy, , 1);
> > > +    if (vas == VA_STATUS_SUCCESS && attr.flags !=
> > > VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
> > > +    dev_select.vendor_id = ((attr.value >> 16) & 0x);
> > > +    dev_select.pci_device = (attr.value & 0x);
> > > +    }
> > > +#endif
> > >  return vulkan_device_create_internal(ctx, _select, 0, opts,
> > > flags);
> > >  }
> > >  #endif
> > > 
> > 
> > Hi,
> > 
> > Any comment for this patch ? 
> > 
> 
> Is this possible? For two devices from different vendors to have the same PCI
> ID?

I'm not sure for different vendors. But when two devices come from the same
vendor (e.g. 8086:56a0 and 8086:4682), vulkan always picks up 8086:56a0 no
matter the source device is 8086:4682 if we don't set the device id here.

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".


[FFmpeg-devel] [PATCH 3/3] Changelog: Add pad_vaapi, drawbox_vaapi entry

2024-03-18 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index b7d7535a9e..27da4b77f0 100644
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@ version :
 - ffprobe (with -export_side_data film_grain) now prints film grain metadata
 - AEA muxer
 - ffmpeg CLI loopback decoders
+- pad_vaapi, drawbox_vaapi filters
 
 
 version 6.1:
-- 
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] lavfi: Add drawbox_vaapi filter

2024-03-18 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 configure  |   1 +
 doc/filters.texi   |  85 
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_drawbox_vaapi.c | 369 +
 5 files changed, 457 insertions(+)
 create mode 100644 libavfilter/vf_drawbox_vaapi.c

diff --git a/configure b/configure
index 4f64f48b38..3102689392 100755
--- a/configure
+++ b/configure
@@ -3891,6 +3891,7 @@ vstack_qsv_filter_select="qsvvpp"
 xstack_qsv_filter_deps="libmfx"
 xstack_qsv_filter_select="qsvvpp"
 pad_vaapi_filter_deps="vaapi_1"
+drawbox_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 2bd1a5b9e7..82bea77107 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28018,6 +28018,91 @@ input sample aspect ratio
 input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
 @end table
 
+@section drawbox_vaapi
+
+Draw a colored box on the input image.
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+The expressions which specify the top left corner coordinates of the box. It 
defaults to 0.
+
+@item width, w
+@item height, h
+The expressions which specify the width and height of the box; if 0 they are 
interpreted as
+the input width and height. It defaults to 0.
+
+@item color, c
+Specify the color of the box to write. For the general syntax of this option,
+check the @ref{color syntax,,"Color" section in the ffmpeg-utils 
manual,ffmpeg-utils}.
+
+@item thickness, t
+The expression which sets the thickness of the box edge.
+A value of @code{fill} will create a filled box. Default value is @code{3}.
+
+See below for the list of accepted constants.
+
+@item replace
+With value @code{1}, the pixels of the painted box will overwrite the video's 
color and alpha pixels.
+Default is @code{0}, which composites the box onto the input video.
+@end table
+
+The parameters for @var{x}, @var{y}, @var{w} and @var{h} and @var{t} are 
expressions containing the
+following constants:
+
+@table @option
+@item in_h, ih
+@item in_w, iw
+The input width and height.
+
+@item x
+@item y
+The x and y offset coordinates where the box is drawn.
+
+@item w
+@item h
+The width and height of the drawn box.
+
+@item t
+The thickness of the drawn box.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Draw a black box around the edge of the input image:
+@example
+drawbox
+@end example
+
+@item
+Draw a box with color red and an opacity of 50%:
+@example
+drawbox=10:20:200:60:red@@0.5
+@end example
+
+The previous example can be specified as:
+@example
+drawbox=x=10:y=20:w=200:h=60:color=red@@0.5
+@end example
+
+@item
+Fill the box with pink color:
+@example
+drawbox=x=10:y=10:w=100:h=100:color=pink@@0.5:t=fill
+@end example
+
+@item
+Draw a 2-pixel red 2.40:1 mask:
+@example
+drawbox=x=-t:y=0.5*(ih-iw/2.4)-t:w=iw+t*2:h=iw/2.4+t*2:t=2:c=red
+@end example
+@end itemize
+
 @c man end VAAPI VIDEO FILTERS
 
 @chapter Vulkan Video Filters
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index babcc7b676..8571e9e2af 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -582,6 +582,7 @@ 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_DRAWBOX_VAAPI_FILTER)  += vf_drawbox_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 1e024b3376..c532682fc2 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -547,6 +547,7 @@ 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 const AVFilter ff_vf_drawbox_vaapi;
 
 extern const AVFilter ff_vsrc_allrgb;
 extern const AVFilter ff_vsrc_allyuv;
diff --git a/libavfilter/vf_drawbox_vaapi.c b/libavfilter/vf_drawbox_vaapi.c
new file mode 100644
index 00..1081d463e9
--- /dev/null
+++ b/libavfilter/vf_drawbox_vaapi.c
@@ -0,0 +1,369 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License 

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

2024-03-18 Thread Xiang, Haihao
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 const AVFilter ff_vsrc_allrgb;
 extern const AVFilter ff_vsrc_allyuv;
diff --git a/libavfilter/vf_pad_vaapi.c b/libavfilter/vf_pad_vaapi.c
new file mode 100644
index 00..98f6285222
--- /dev/null
+++ b/libavfilter/vf_pad_vaapi.c
@@ -0,0 +1,283 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You 

Re: [FFmpeg-devel] [PATCH v3] lavc/vaapi_encode: Enable block level bitrate control

2024-03-18 Thread Xiang, Haihao
On Vr, 2024-03-15 at 02:46 +, Xiang, Haihao wrote:
> On Vr, 2024-03-08 at 16:45 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
> > From: Fei Wang 
> > 
> > Signed-off-by: Fei Wang 
> > ---
> >  doc/encoders.texi |  4 
> >  libavcodec/vaapi_encode.c | 13 -
> >  libavcodec/vaapi_encode.h |  9 -
> >  3 files changed, 24 insertions(+), 2 deletions(-)
> > 
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 5f7864770e..7c223ed74c 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -4089,6 +4089,10 @@ Quality-defined variable-bitrate.
> >  Average variable bitrate.
> >  @end table
> >  
> > +@item blbrc
> > +Enable block level rate control, which assigns different bitrate block by
> > block.
> > +Invalid for CQP mode.
> > +
> >  @end table
> >  
> >  Each encoder also has its own specific options:
> > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > index 808b79c0c7..940f0678a5 100644
> > --- a/libavcodec/vaapi_encode.c
> > +++ b/libavcodec/vaapi_encode.c
> > @@ -1805,6 +1805,11 @@ static av_cold int
> > vaapi_encode_init_rate_control(AVCodecContext *avctx)
> >  int i, first = 1, res;
> >  
> >  supported_va_rc_modes = rc_attr.value;
> > +    if (ctx->blbrc && !(supported_va_rc_modes & VA_RC_MB)) {
> > +    ctx->blbrc = 0;
> > +    av_log(avctx, AV_LOG_WARNING, "Driver does not support
> > BLBRC.\n");
> > +    }
> > +
> >  for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
> >  rc_mode = _encode_rc_modes[i];
> >  if (supported_va_rc_modes & rc_mode->va_mode) {
> > @@ -2016,13 +2021,18 @@ rc_mode_found:
> >  ctx->va_bit_rate = rc_bits_per_second;
> >  
> >  av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
> > +
> > +    if (ctx->blbrc && ctx->va_rc_mode == VA_RC_CQP)
> > +    ctx->blbrc = 0;
> > +    av_log(avctx, AV_LOG_VERBOSE, "Block Level bitrate control: %s.\n",
> > ctx-
> > > blbrc ? "ON" : "OFF");
> > +
> >  if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> >  // This driver does not want the RC mode attribute to be set.
> >  } else {
> >  ctx->config_attributes[ctx->nb_config_attributes++] =
> >  (VAConfigAttrib) {
> >  .type  = VAConfigAttribRateControl,
> > -    .value = ctx->va_rc_mode,
> > +    .value = ctx->blbrc ? ctx->va_rc_mode | VA_RC_MB : ctx-
> > > va_rc_mode,
> >  };
> >  }
> >  
> > @@ -2051,6 +2061,7 @@ rc_mode_found:
> >  #if VA_CHECK_VERSION(1, 1, 0)
> >  .ICQ_quality_factor = av_clip(rc_quality, 1, 51),
> >  .max_qp = (avctx->qmax > 0 ? avctx->qmax : 0),
> > +    .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2,
> >  #endif
> >  #if VA_CHECK_VERSION(1, 3, 0)
> >  .quality_factor = rc_quality,
> > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> > index 6964055b93..0eed9691ca 100644
> > --- a/libavcodec/vaapi_encode.h
> > +++ b/libavcodec/vaapi_encode.h
> > @@ -216,6 +216,9 @@ typedef struct VAAPIEncodeContext {
> >  // available modes).
> >  int explicit_rc_mode;
> >  
> > +    // Block Level based bitrate control.
> > +    int blbrc;
> > +
> >  // Explicitly-set QP, for use with the "qp" options.
> >  // (Forces CQP mode when set, overriding everything else.)
> >  int explicit_qp;
> > @@ -538,7 +541,11 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
> >  VAAPI_ENCODE_RC_MODE(VBR,  "Variable-bitrate"), \
> >  VAAPI_ENCODE_RC_MODE(ICQ,  "Intelligent constant-quality"), \
> >  VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
> > -    VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
> > +    VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate"), \
> > +    { "blbrc", \
> > +  "Block level based bitrate control",\
> > +  OFFSET(common.blbrc), AV_OPT_TYPE_BOOL, \
> > +  { .i64 = 0 }, 0, 1, FLAGS }
> >  
> >  
> >  #endif /* AVCODEC_VAAPI_ENCODE_H */
> 
> LGTM, I will push this patch if there is no objection.

Pushed.

- 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/hwcontext_vulkan: check both vendor and PCI IDs

2024-03-17 Thread Xiang, Haihao
On Vr, 2024-03-08 at 15:13 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Otherwise the derived device and the source device might have different
> PCI ID or vendor ID in a multiple-device system.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavutil/hwcontext_vulkan.c | 31 +--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 855f099e26..9d94f74d78 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -975,6 +975,20 @@ static int find_device(AVHWDeviceContext *ctx,
> VulkanDeviceSelection *select)
>     select->name);
>  err = AVERROR(ENODEV);
>  goto end;
> +    } else if (select->vendor_id && select->pci_device) {
> +    av_log(ctx, AV_LOG_VERBOSE, "Requested vendor:device %04x:%04x\n",
> +   select->vendor_id, select->pci_device);
> +    for (int i = 0; i < num; i++) {
> +    if (select->vendor_id == prop[i].properties.vendorID &&
> +    select->pci_device == prop[i].properties.deviceID) {
> +    choice = i;
> +    goto end;
> +    }
> +    }
> +    av_log(ctx, AV_LOG_ERROR, "Unable to find device with vendor ID 0x%x
> "
> +   "and PCI ID 0x%x!\n", select->vendor_id, select->pci_device);
> +    err = AVERROR(EINVAL);
> +    goto end;
>  } else if (select->pci_device) {
>  av_log(ctx, AV_LOG_VERBOSE, "Requested device: 0x%x\n", select-
> >pci_device);
>  for (int i = 0; i < num; i++) {
> @@ -1597,8 +1611,14 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
>  #if CONFIG_VAAPI
>  case AV_HWDEVICE_TYPE_VAAPI: {
>  AVVAAPIDeviceContext *src_hwctx = src_ctx->hwctx;
> -
> -    const char *vendor = vaQueryVendorString(src_hwctx->display);
> +    VADisplay dpy = src_hwctx->display;
> +#if VA_CHECK_VERSION(1, 15, 0)
> +    VAStatus vas;
> +    VADisplayAttribute attr = {
> +    .type = VADisplayPCIID,
> +    };
> +#endif
> +    const char *vendor = vaQueryVendorString(dpy);
>  if (!vendor) {
>  av_log(ctx, AV_LOG_ERROR, "Unable to get device info from
> VAAPI!\n");
>  return AVERROR_EXTERNAL;
> @@ -1607,6 +1627,13 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
>  if (strstr(vendor, "AMD"))
>  dev_select.vendor_id = 0x1002;
>  
> +#if VA_CHECK_VERSION(1, 15, 0)
> +    vas = vaGetDisplayAttributes(dpy, , 1);
> +    if (vas == VA_STATUS_SUCCESS && attr.flags !=
> VA_DISPLAY_ATTRIB_NOT_SUPPORTED) {
> +    dev_select.vendor_id = ((attr.value >> 16) & 0x);
> +    dev_select.pci_device = (attr.value & 0x);
> +    }
> +#endif
>  return vulkan_device_create_internal(ctx, _select, 0, opts,
> flags);
>  }
>  #endif

Hi,

Any comment for this patch ? 

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 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-17 Thread Xiang, Haihao
On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:
> For hardware cases where we are forced to have a fixed pool of frames
> allocated up-front (such as array textures on decoder output), suggest
> a possible workaround to the user if an allocation fails because the
> pool is exhausted.
> ---
> Perhaps helpful; any thoughts?
> 
> The warning comes out before any errors, looking like:
> 
> [mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame from a
> fixed pool of hardware frames.
> [mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a larger
> value (currently set to 8, giving a pool size of 14).
> [mpeg2video @ 0x560ff51b4600] get_buffer() failed
> [vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @ 0x560ff51b3b40] Error
> submitting packet to decoder: Operation not permitted

I'm OK to print such warning so user may know how to work around it. But now
many cases are impacted by this error (e.g. https://trac.ffmpeg.org/ticket/10856
), I think it is a regression to user. I still prefer to use a dynamic buffer
pool instead fixed frame pool to avoid such error when the dynamic buffer pool
can work.

Thanks
Haihao

> 
>   libavcodec/get_buffer.c | 16 
>   libavcodec/internal.h   |  6 ++
>   2 files changed, 22 insertions(+)
> 
> diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
> index 46c20781af..9b35fde7c6 100644
> --- a/libavcodec/get_buffer.c
> +++ b/libavcodec/get_buffer.c
> @@ -257,6 +257,22 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx,
> AVFrame *frame, int flags
> 
>   if (avctx->hw_frames_ctx) {
>   ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
> +    if (ret == AVERROR(ENOMEM)) {
> +    AVHWFramesContext *frames_ctx =
> +    (AVHWFramesContext*)avctx->hw_frames_ctx->data;
> +    if (frames_ctx->initial_pool_size > 0 &&
> +    !avctx->internal-
> >warned_on_failed_allocation_from_fixed_pool) {
> +    av_log(avctx, AV_LOG_WARNING, "Failed to allocate a %s/%s "
> +   "frame from a fixed pool of hardware frames.\n",
> +   av_get_pix_fmt_name(frames_ctx->format),
> +   av_get_pix_fmt_name(frames_ctx->sw_format));
> +    av_log(avctx, AV_LOG_WARNING, "Consider setting "
> +   "extra_hw_frames to a larger value "
> +   "(currently set to %d, giving a pool size of %d).\n",
> +   avctx->extra_hw_frames, frames_ctx-
> >initial_pool_size);
> +    avctx->internal->warned_on_failed_allocation_from_fixed_pool
> = 1;
> +    }
> +    }
>   frame->width  = avctx->coded_width;
>   frame->height = avctx->coded_height;
>   return ret;
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index 04f7cebdcb..64fe0122c8 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -144,6 +144,12 @@ typedef struct AVCodecInternal {
>   #if CONFIG_LCMS2
>   FFIccContext icc; /* used to read and write embedded ICC profiles */
>   #endif
> +
> +    /**
> + * Set when the user has been warned about a failed allocation from
> + * a fixed frame pool.
> + */
> +    int warned_on_failed_allocation_from_fixed_pool;
>   } AVCodecInternal;
> 
>   /**

___
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] ffmpeg: set extra_hw_frames to account for frames held in queues

2024-03-17 Thread Xiang, Haihao
On So, 2024-03-17 at 20:49 +, Mark Thompson wrote:
> Since e0da916b8f5b079a4865eef7f64863f50785463d the ffmpeg utility has
> held multiple frames output by the decoder in internal queues without
> telling the decoder that it is going to do so.  When the decoder has a
> fixed-size pool of frames (common in some hardware APIs where the output
> frames must be stored as an array texture) this could lead to the pool
> being exhausted and the decoder getting stuck.  Fix this by telling the
> decoder to allocate additional frames according to the queue size.
> ---
> Rebased but otherwise unchanged since previous version.
> 
>   fftools/ffmpeg_dec.c   | 13 +
>   fftools/ffmpeg_sched.c | 16 +++-
>   fftools/ffmpeg_sched.h | 12 
>   3 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
> index c41c5748e5..ed411b6bf8 100644
> --- a/fftools/ffmpeg_dec.c
> +++ b/fftools/ffmpeg_dec.c
> @@ -1207,6 +1207,19 @@ static int dec_open(DecoderPriv *dp, AVDictionary
> **dec_opts,
>   return ret;
>   }
> 
> +    if (dp->dec_ctx->hw_device_ctx) {
> +    // Update decoder extra_hw_frames option to account for the
> +    // frames held in queues inside the ffmpeg utility.  This is
> +    // called after avcodec_open2() because the user-set value of
> +    // extra_hw_frames becomes valid in there, and we need to add
> +    // this on top of it.
> +    int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
> +    if (dp->dec_ctx->extra_hw_frames >= 0)
> +    dp->dec_ctx->extra_hw_frames += extra_frames;
> +    else
> +    dp->dec_ctx->extra_hw_frames = extra_frames;
> +    }
> +
>   ret = check_avoptions(*dec_opts);
>   if (ret < 0)
>   return ret;
> diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
> index f739066921..ec88017e21 100644
> --- a/fftools/ffmpeg_sched.c
> +++ b/fftools/ffmpeg_sched.c
> @@ -365,7 +365,21 @@ static int queue_alloc(ThreadQueue **ptq, unsigned
> nb_streams, unsigned queue_si
>   ThreadQueue *tq;
>   ObjPool *op;
> 
> -    queue_size = queue_size > 0 ? queue_size : 8;
> +    if (queue_size <= 0) {
> +    if (type == QUEUE_FRAMES)
> +    queue_size = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
> +    else
> +    queue_size = DEFAULT_PACKET_THREAD_QUEUE_SIZE;
> +    }
> +
> +    if (type == QUEUE_FRAMES) {
> +    // This queue length is used in the decoder code to ensure that
> +    // there are enough entries in fixed-size frame pools to account
> +    // for frames held in queues inside the ffmpeg utility.  If this
> +    // can ever dynamically change then the corresponding decode
> +    // code needs to be updated as well.
> +    av_assert0(queue_size == DEFAULT_FRAME_THREAD_QUEUE_SIZE);
> +    }
> 
>   op = (type == QUEUE_PACKETS) ? objpool_alloc_packets() :
>  objpool_alloc_frames();
> diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h
> index a9190bd3d1..e51c26cec9 100644
> --- a/fftools/ffmpeg_sched.h
> +++ b/fftools/ffmpeg_sched.h
> @@ -233,6 +233,18 @@ int sch_add_filtergraph(Scheduler *sch, unsigned
> nb_inputs, unsigned nb_outputs,
>    */
>   int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *),
>   void *ctx, int sdp_auto, unsigned thread_queue_size);
> +
> +/**
> + * Default size of a packet thread queue.  For muxing this can be overridden
> by
> + * the thread_queue_size option as passed to a call to sch_add_mux().
> + */
> +#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8
> +
> +/**
> + * Default size of a frame thread queue.
> + */
> +#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8
> +
>   /**
>    * Add a muxed stream for a previously added muxer.

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] lavu/hwcontext_qsv: Join the download/upload session to the main session

2024-03-14 Thread Xiang, Haihao
On Ma, 2024-03-11 at 12:56 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> This may reduce the number of internal threads when using hwupload or
> hwdownload filter.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  libavutil/hwcontext_qsv.c | 24 
>  1 file changed, 24 insertions(+)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 378cd5e826..e5e043d2d1 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -55,6 +55,10 @@
>  (MFX_VERSION_MAJOR > (MAJOR) || \
>   MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
>  
> +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)  \
> +    ((MFX_VERSION.Major > (MAJOR)) ||   \
> + (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
> +
>  #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
>  #define QSV_ONEVPL   QSV_VERSION_ATLEAST(2, 0)
>  #define QSV_HAVE_OPAQUE  !QSV_ONEVPL
> @@ -1136,6 +1140,17 @@ static int qsv_init_internal_session(AVHWFramesContext
> *ctx,
>  int   ret = AVERROR_UNKNOWN;
>  /* hwctx->loader is non-NULL for oneVPL user and NULL for non-oneVPL user
> */
>  void **loader = >loader;
> +    mfxSession parent_session = hwctx->session;
> +    mfxIMPL impl;
> +    mfxVersion ver;
> +
> +    err = MFXQueryIMPL(parent_session, );
> +    if (err == MFX_ERR_NONE)
> +    err = MFXQueryVersion(parent_session, );
> +    if (err != MFX_ERR_NONE) {
> +    av_log(ctx, AV_LOG_ERROR, "Error querying the session
> attributes.\n");
> +    return AVERROR_UNKNOWN;
> +    }
>  
>  #if QSV_HAVE_OPAQUE
>  QSVFramesContext  *s = ctx->hwctx;
> @@ -1156,6 +1171,15 @@ static int qsv_init_internal_session(AVHWFramesContext
> *ctx,
>  }
>  }
>  
> +    if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> +    err = MFXJoinSession(parent_session, *session);
> +    if (err != MFX_ERR_NONE) {
> +    av_log(ctx, AV_LOG_ERROR, "Error joining session.\n");
> +    ret = AVERROR_UNKNOWN;
> +    goto fail;
> +    }
> +    }
> +
>  if (!opaque) {
>  err = MFXVideoCORE_SetFrameAllocator(*session, _allocator);
>  if (err != MFX_ERR_NONE) {

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   >