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

2024-05-20 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> 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
>>
>>>  
>>>  #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
>>
>>> +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.
>>
> 
> I know see that this would necessitate more changes because the ExtParam
> pointers are currently ownership pointers. So ignore this suggestion.
> 

s/know/now/

- Andreas

___
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-20 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> 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
> 
>>  
>>  #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
> 
>> +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.
> 

I know see that this would necessitate more changes because the ExtParam
pointers are currently ownership pointers. So ignore this suggestion.

- Andreas

___
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-20 Thread Andreas Rheinhardt
Xiang, Haihao:
> +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;

Iterators with loop scope should be preferred if possible (like here).

> +
> +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;
> +}
> +

___
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 2/2][GSoC 2024] tests/checkasm: Add check_vvc_sad to vvc_mc.c

2024-05-20 Thread Martin Storsjö

On Tue, 21 May 2024, Rémi Denis-Courmont wrote:


Hi,

Le 20 mai 2024 03:42:03 GMT+03:00, Stone Chen  a 
écrit :

Adds checkasm for DMVR SAD AVX2 implementation.

Benchmarks ( AMD 7940HS )
vvc_sad_8x8_c: 70.0
vvc_sad_8x8_avx2: 10.0
vvc_sad_16x16_c: 280.0
vvc_sad_16x16_avx2: 20.0
vvc_sad_32x32_c: 1020.0
vvc_sad_32x32_avx2: 70.0
vvc_sad_64x64_c: 3560.0
vvc_sad_64x64_avx2: 270.0
vvc_sad_128x128_c: 13760.0
vvc_sad_128x128_avx2: 1070.0
---
tests/checkasm/vvc_mc.c | 38 ++
1 file changed, 38 insertions(+)


VVC benchmarks have increased checksam runtime by at least an order of 
magnitude. It's become so prohibitively slow that I could not even get 
to the end.


This is not an acceptable situation and impedes non-VVC assembler work


I don't quite understand; whenever benchmarking anything in checkasm, I 
would always run e.g. "checkasm --test=ac3dsp 
--bench=ac3_sum_square_bufferfly_float", limiting the total running of 
tests to a specific module, and only benchmarking a subset of the run 
functions. (The --bench parameter specifies a prefix; only functions 
matching that prefix gets benchmarked.)


Without limiting the scope with a --test parameter, checkasm benchmarking 
has always been prohibitively slow for me - so I don't think there's 
anything new here? If you were lucky enough to be able to do a full run of 
checkasm with benchmarks of all functions before, that sounds like an 
exception to me, not a reason to limit adding new tests?


That said I'm not familiar with the VVC tests in checkasm, perhaps they 
benchmark things excessively. But I don't see how that would impede work 
on other DSP functions in any way?


// Martin
___
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-20 Thread Andreas Rheinhardt
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

>  
>  #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

> +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_ATLEAST(1,
35)", yet this patch does not use any such #if. Why?)

> +if (!clli)
> +return AVERROR(ENOMEM);
> +
> +clli->Header.BufferId = MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO;
> +clli->Header.BufferSz = sizeof(*clli);
> +
> +clli->MaxContentLightLevel  = clm->MaxCLL;
> +clli->MaxPicAverageLightLevel   = clm->MaxFALL;
> +
> +enc_ctrl->ExtParam[enc_ctrl->NumExtParam++] = (mfxExtBuffer *)clli;
> +}
> +
> +return 0;
> +}
> +
>  static av_cold int qsv_enc_init(AVCodecContext *avctx)
>  {
>  QSVAV1EncContext *q = avctx->priv_data;
> @@ -61,6 +134,8 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx)
> return ret;
>  }
>  
> +q->qsv.set_encode_ctrl_cb = qsv_av1_set_encode_ctrl;
> +
>  return ff_qsv_enc_init(avctx, &q->qsv);
>  }
>  

___
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/dovi_rpudec - correctly read el_bit_depth_minus8 when ext_mapping_idc is non-zero

2024-05-20 Thread Andreas Rheinhardt
Cosmin Stejerean via ffmpeg-devel:
> From: Cosmin Stejerean 
> 
> It looks like the el_bitdepth_minus8 value in the header can also encode
> ext_mapping_idc in the upper 8 bits.
> 
> Samples having a non-zero ext_mapping_idc fail validation currently because 
> the
> value returned is out of range. This bypasses this by currently ignoring the
> ext_mapping_idc and using only the lower 8 bits for el_bitdepth_minus8.
> 
> ---
>  libavcodec/dovi_rpudec.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
> index 7c7eda9d09..1b11ad3640 100644
> --- a/libavcodec/dovi_rpudec.c
> +++ b/libavcodec/dovi_rpudec.c
> @@ -411,7 +411,9 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
> size_t rpu_size,
>  
>  if ((hdr->rpu_format & 0x700) == 0) {
>  int bl_bit_depth_minus8 = get_ue_golomb_31(gb);
> -int el_bit_depth_minus8 = get_ue_golomb_31(gb);
> +// this can encode a two byte value, with higher byte being 
> ext_mapping_idc
> +// use only the lower byte for el_bit_depth_minus8
> +uint8_t el_bit_depth_minus8 = get_ue_golomb_long(gb) & 0xFF;
>  int vdr_bit_depth_minus8 = get_ue_golomb_31(gb);
>  VALIDATE(bl_bit_depth_minus8, 0, 8);
>  VALIDATE(el_bit_depth_minus8, 0, 8);

So there is a field (ext_mapping_idc) in RPU that neither rpudec nor
rpuenc (nor dovi_meta.h) know about? In this case, we should disable the
encoding parts.

- Andreas

___
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-20 Thread Xiang, Haihao
From: Haihao Xiang 

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

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

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

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

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


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

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

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

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

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

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

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


Re: [FFmpeg-devel] [PATCH v4 2/2][GSoC 2024] tests/checkasm: Add check_vvc_sad to vvc_mc.c

2024-05-20 Thread Rémi Denis-Courmont
Hi,

Le 20 mai 2024 03:42:03 GMT+03:00, Stone Chen  a 
écrit :
>Adds checkasm for DMVR SAD AVX2 implementation.
>
>Benchmarks ( AMD 7940HS )
>vvc_sad_8x8_c: 70.0
>vvc_sad_8x8_avx2: 10.0
>vvc_sad_16x16_c: 280.0
>vvc_sad_16x16_avx2: 20.0
>vvc_sad_32x32_c: 1020.0
>vvc_sad_32x32_avx2: 70.0
>vvc_sad_64x64_c: 3560.0
>vvc_sad_64x64_avx2: 270.0
>vvc_sad_128x128_c: 13760.0
>vvc_sad_128x128_avx2: 1070.0
>---
> tests/checkasm/vvc_mc.c | 38 ++
> 1 file changed, 38 insertions(+)

VVC benchmarks have increased checksam runtime by at least an order of 
magnitude. It's become so prohibitively slow that I could not even get to the 
end.

This is not an acceptable situation and impedes non-VVC assembler work 

Please fix this before you add any new VVC tests. In the mean time:

-1 / Nack all VVC checksam from my behalf.


>diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
>index 97f57cb401..e251400bfc 100644
>--- a/tests/checkasm/vvc_mc.c
>+++ b/tests/checkasm/vvc_mc.c
>@@ -322,8 +322,46 @@ static void check_avg(void)
> report("avg");
> }
> 
>+static void check_vvc_sad(void)
>+{
>+const int bit_depth = 10;
>+VVCDSPContext c;
>+LOCAL_ALIGNED_32(uint16_t, src0, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
>+LOCAL_ALIGNED_32(uint16_t, src1, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
>+declare_func(int, const int16_t *src0, const int16_t *src1, int dx, int 
>dy, int block_w, int block_h);
>+
>+ff_vvc_dsp_init(&c, bit_depth);
>+memset(src0, 0, MAX_CTU_SIZE * MAX_CTU_SIZE * 4);
>+memset(src1, 0, MAX_CTU_SIZE * MAX_CTU_SIZE * 4);
>+
>+randomize_pixels(src0, src1, MAX_CTU_SIZE * MAX_CTU_SIZE * 2);
>+ for (int h = 8; h <= MAX_CTU_SIZE; h *= 2) {
>+for (int w = 8; w <= MAX_CTU_SIZE; w *= 2) {
>+for(int offy = 0; offy <= 4; offy++) {
>+for(int offx = 0; offx <= 4; offx++) {
>+if(check_func(c.inter.sad, "vvc_sad_%dx%d", w, h)) {
>+int result0;
>+int result1;
>+
>+result0 =  call_ref(src0 + PIXEL_STRIDE * 2 + 2, src1 
>+ PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
>+result1 =  call_new(src0 + PIXEL_STRIDE * 2 + 2, src1 
>+ PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
>+
>+if (result1 != result0)
>+fail();
>+if(w == h && offx == 0 && offy == 0)
>+bench_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + 
>PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
>+}
>+}
>+}
>+}
>+ }
>+
>+report("check_vvc_sad");
>+}
>+
> void checkasm_check_vvc_mc(void)
> {
>+check_vvc_sad();
> check_put_vvc_luma();
> check_put_vvc_luma_uni();
> check_put_vvc_chroma();
___
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] avcodec/dovi - disable metadata compression by default

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel
From: Cosmin Stejerean 

not all clients support metadata compression, make this an option and off by
default until we can verify output.

vdr_dm_metadata_changed = 0 case fails the DV verifier so force this to true
for now until we can determine the correct output format for this case.


---
 libavcodec/dovi_rpu.h| 5 +
 libavcodec/dovi_rpuenc.c | 8 ++--
 libavcodec/libaomenc.c   | 1 +
 libavcodec/libsvtav1.c   | 1 +
 libavcodec/libx265.c | 1 +
 5 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 8ce0c88e9d..fca30804ae 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -71,6 +71,11 @@ typedef struct DOVIContext {
 AVDOVIDmData *ext_blocks;
 int num_ext_blocks;
 
+/**
+ * Enable metadata compression in the output. Currently this is 
experimental.
+ */
+int enable_compression;
+
 /**
  * Private fields internal to dovi_rpu.c
  */
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index 3c3e0f84c0..26ed25733a 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -512,8 +512,12 @@ int ff_dovi_rpu_generate(DOVIContext *s, const 
AVDOVIMetadata *metadata,
 }
 }
 
-vdr_dm_metadata_changed = !s->color || memcmp(s->color, color, 
sizeof(*color));
-use_prev_vdr_rpu = !memcmp(&s->vdr[vdr_rpu_id]->mapping, mapping, 
sizeof(*mapping));
+// the output when vdr_dm_metadata_changed is 0 fails the DV verifier
+// force it to 1 until we can get some samples or documentation on correct 
syntax
+vdr_dm_metadata_changed = 1; // !s->color || memcmp(s->color, color, 
sizeof(*color));
+
+// not all clients support metadata compression
+use_prev_vdr_rpu = s->enable_compression && 
!memcmp(&s->vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping));
 
 buffer_size = 12 /* vdr seq info */ + 5 /* CRC32 + terminator */;
 buffer_size += num_ext_blocks_v1 * 13;
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index dec74ebecd..c6104f5522 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1489,6 +1489,7 @@ static const AVOption options[] = {
 { "still-picture", "Encode in single frame mode (typically used for still 
AVIF images).", OFFSET(still_picture), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, VE 
},
 { "dolbyvision", "Enable Dolby Vision RPU coding", 
OFFSET(dovi.enable), AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, 
.unit = "dovi" },
 {   "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags 
= VE, .unit = "dovi" },
+{ "dv_enable_compression", "Enable Dolby Vision metadata compression", 
OFFSET(dovi.enable_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, VE },
 { "enable-rect-partitions", "Enable rectangular partitions", 
OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", 
OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-ab-partitions",   "Enable ab shape partitions",
OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 2fef8c8971..86bb6686dd 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -733,6 +733,7 @@ static const AVOption options[] = {
 
 { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), 
AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" },
 {   "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags 
= VE, .unit = "dovi" },
+{ "dv_enable_compression", "Enable Dolby Vision metadata compression", 
OFFSET(dovi.enable_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, VE },
 
 {NULL},
 };
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index ac1dbc4f97..2a79a5e6da 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -953,6 +953,7 @@ static const AVOption options[] = {
 #if X265_BUILD >= 167
 { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), 
AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" },
 {   "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags 
= VE, .unit = "dovi" },
+{ "dv_enable_compression", "Enable Dolby Vision metadata compression", 
OFFSET(dovi.enable_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, VE },
 #endif
 { NULL }
 };
-- 
2.42.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/libsvtav1: send the EOS signal without a one frame delay to allow for the library to operate in a low-delay mode

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel


> On May 20, 2024, at 6:17 PM, Cosmin Stejerean via ffmpeg-devel 
>  wrote:
> 
> From: Cosmin Stejerean 
> 
> Co-authored-by: Amir Naghdinezhad 
> Signed-off-by: Cosmin Stejerean 
> ---
> libavcodec/libsvtav1.c | 10 ++
> 1 file changed, 10 insertions(+)
> 

Disregard this one, it was previously applied. It was left over in my patches 
folder by mistake and git send-email picked it up again.

- Cosmin


___
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/7] tools/enc_recon_frame_test: Assert that av_image_get_linesize() succeeds

2024-05-20 Thread Michael Niedermayer
Helps: CID1524598 Improper use of negative value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 tools/enc_recon_frame_test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/enc_recon_frame_test.c b/tools/enc_recon_frame_test.c
index c099beb3f4b..d39d6303c2e 100644
--- a/tools/enc_recon_frame_test.c
+++ b/tools/enc_recon_frame_test.c
@@ -28,6 +28,7 @@
 #include "decode_simple.h"
 
 #include "libavutil/adler32.h"
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/error.h"
 #include "libavutil/frame.h"
@@ -89,6 +90,8 @@ static int frame_hash(FrameChecksum **pc, size_t *nb_c, 
int64_t ts,
 int linesize = av_image_get_linesize(frame->format, frame->width, p);
 uint32_t checksum = 0;
 
+av_assert1(linesize >= 0);
+
 for (int j = 0; j < frame->height >> shift_v[p]; j++) {
 checksum = av_adler32_update(checksum, data, linesize);
 data += frame->linesize[p];
-- 
2.45.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/7] tools/decode_simple: Check avcodec_send_packet() for errors on flushing

2024-05-20 Thread Michael Niedermayer
This will not error but the API allows errors so we should check it
Fixes: CID148 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 tools/decode_simple.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/decode_simple.c b/tools/decode_simple.c
index 6532e368d46..e8c1d6a407e 100644
--- a/tools/decode_simple.c
+++ b/tools/decode_simple.c
@@ -94,8 +94,9 @@ int ds_run(DecodeContext *dc)
 goto finish;
 }
 
-avcodec_send_packet(dc->decoder, NULL);
-ret = decode_read(dc, 1);
+ret = avcodec_send_packet(dc->decoder, NULL);
+if (ret >= 0)
+ret = decode_read(dc, 1);
 if (ret < 0) {
 fprintf(stderr, "Error flushing: %d\n", ret);
 return ret;
-- 
2.45.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/7] swscale/yuv2rgb: Use 64bit for brightness computation

2024-05-20 Thread Michael Niedermayer
This will not overflow for normal values
Fixes: CID1500280 Unintentional integer overflow

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libswscale/yuv2rgb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index 2b2358d2cc1..c1d6236f37f 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -830,7 +830,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const 
int inv_table[4],
 cbu  = (cbu * contrast * saturation) >> 32;
 cgu  = (cgu * contrast * saturation) >> 32;
 cgv  = (cgv * contrast * saturation) >> 32;
-oy  -= 256 * brightness;
+oy  -= 256LL * brightness;
 
 c->uOffset = 0x0400040004000400LL;
 c->vOffset = 0x0400040004000400LL;
-- 
2.45.1

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

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


[FFmpeg-devel] [PATCH 4/7] swscale/x86/swscale: use a clearer name for INPUT_PLANER_RGB_A_FUNC_CASE

2024-05-20 Thread Michael Niedermayer
related: CID1497114 Missing break in switch

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libswscale/x86/swscale.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index ff16398988a..bc18f9dd08a 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -649,7 +649,7 @@ switch(c->dstBpc){ \
 }
 
 
-#define INPUT_PLANER_RGB_A_FUNC_CASE(fmt, name, opt)  \
+#define INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(fmt, name, opt)  \
 case fmt: \
 c->readAlpPlanar = ff_planar_##name##_to_a_##opt;
 
@@ -672,15 +672,15 @@ switch(c->dstBpc){ \
 break;
 
 #define INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
-INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE,  name##le, opt)   \
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE,  name##le, opt) 
  \
 INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##LE, name##le, opt)   \
-INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE,  name##be, opt)   \
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE,  name##be, opt) 
  \
 INPUT_PLANER_RGB_YUV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
 
 #define INPUT_PLANER_RGBAXX_UVA_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt) \
-INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##LE, name##le, opt)   \
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##LE, name##le, opt)  
 \
 INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##LE, name##le, opt)   \
-INPUT_PLANER_RGB_A_FUNC_CASE(rgba_fmt##BE, name##be, opt)   \
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(rgba_fmt##BE, name##be, opt)  
 \
 INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
 
 #define INPUT_PLANER_RGBAXX_YUV_FUNC_CASE(rgb_fmt, rgba_fmt, name, opt)
   \
@@ -696,7 +696,7 @@ switch(c->dstBpc){ \
 INPUT_PLANER_RGB_UV_FUNC_CASE(rgb_fmt##BE, name##be, opt)
 
 #define INPUT_PLANER_RGB_YUVA_ALL_CASES(opt)   
  \
-INPUT_PLANER_RGB_A_FUNC_CASE(  AV_PIX_FMT_GBRAP,   
rgb, opt) \
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(  AV_PIX_FMT_GBRAP,   
rgb, opt) \
 INPUT_PLANER_RGB_YUV_FUNC_CASE(AV_PIX_FMT_GBRP,
rgb, opt) \
 INPUT_PLANER_RGBXX_YUV_FUNC_CASE(  AV_PIX_FMT_GBRP9,   
   rgb9, opt) \
 INPUT_PLANER_RGBAXX_YUVA_FUNC_CASE(AV_PIX_FMT_GBRP10,  
AV_PIX_FMT_GBRAP10,   rgb10, opt) \
@@ -708,7 +708,7 @@ switch(c->dstBpc){ \
 
 if (EXTERNAL_SSE2(cpu_flags)) {
 switch (c->srcFormat) {
-INPUT_PLANER_RGB_A_FUNC_CASE(  AV_PIX_FMT_GBRAP,   
rgb, sse2);
+INPUT_PLANER_RGB_A_FUNC_CASE_NOBREAK(  AV_PIX_FMT_GBRAP,   
rgb, sse2);
 INPUT_PLANER_RGB_UV_FUNC_CASE( AV_PIX_FMT_GBRP,
rgb, sse2);
 INPUT_PLANER_RGBXX_UV_FUNC_CASE(   AV_PIX_FMT_GBRP9,   
   rgb9, sse2);
 INPUT_PLANER_RGBAXX_UVA_FUNC_CASE( AV_PIX_FMT_GBRP10,  
AV_PIX_FMT_GBRAP10,   rgb10, sse2);
-- 
2.45.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/7] avutil/tests/opt: Check av_set_options_string() for failure

2024-05-20 Thread Michael Niedermayer
This is test code after all so it should test things

Fixes: CID1518990 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavutil/tests/opt.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index d189938d9ba..02b3ed6e90e 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -304,6 +304,7 @@ int main(void)
 {
 TestContext test_ctx = { 0 };
 char *buf;
+int ret;
 test_ctx.class = &test_class;
 
 av_log_set_level(AV_LOG_QUIET);
@@ -314,8 +315,10 @@ int main(void)
 av_opt_free(&test_ctx);
 memset(&test_ctx, 0, sizeof(test_ctx));
 test_ctx.class = &test_class;
-av_set_options_string(&test_ctx, buf, "=", ",");
+ret = av_set_options_string(&test_ctx, buf, "=", ",");
 av_free(buf);
+if (ret < 0)
+printf("Error ret '%d'\n", ret);
 if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
 ChildContext child_ctx = { 0 };
 printf("%s\n", buf);
-- 
2.45.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/7] avutil/tests/dict: Check av_dict_set() before get for failure

2024-05-20 Thread Michael Niedermayer
Failure is possible due to strdup()

Fixes: CID1516764 Dereference null return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavutil/tests/dict.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavutil/tests/dict.c b/libavutil/tests/dict.c
index e45bc220cb3..21368203ce2 100644
--- a/libavutil/tests/dict.c
+++ b/libavutil/tests/dict.c
@@ -150,12 +150,15 @@ int main(void)
 
 //valgrind sensible test
 printf("\nTesting av_dict_set() with existing AVDictionaryEntry.key as 
key\n");
-av_dict_set(&dict, "key", "old", 0);
+if (av_dict_set(&dict, "key", "old", 0) < 0)
+return 1;
 e = av_dict_get(dict, "key", NULL, 0);
-av_dict_set(&dict, e->key, "new val OK", 0);
+if (av_dict_set(&dict, e->key, "new val OK", 0) < 0)
+return 1;
 e = av_dict_get(dict, "key", NULL, 0);
 printf("%s\n", e->value);
-av_dict_set(&dict, e->key, e->value, 0);
+if (av_dict_set(&dict, e->key, e->value, 0) < 0)
+return 1;
 e = av_dict_get(dict, "key", NULL, 0);
 printf("%s\n", e->value);
 av_dict_free(&dict);
-- 
2.45.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/7] avutil/random_seed: Avoid dead returns

2024-05-20 Thread Michael Niedermayer
Fixes: CID1538296 Structurally dead code

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavutil/random_seed.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 6d399cee49c..8a4e4f1fc0b 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -158,10 +158,10 @@ int av_random_bytes(uint8_t* buf, size_t len)
 #elif CONFIG_OPENSSL
 if (RAND_bytes(buf, len) == 1)
 return 0;
-err = AVERROR_EXTERNAL;
-#endif
-
+return AVERROR_EXTERNAL;
+#else
 return err;
+#endif
 }
 
 uint32_t av_get_random_seed(void)
-- 
2.45.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] fate: add tests for xHE-AAC

2024-05-20 Thread Lynne via ffmpeg-devel
Starting off small with a few features.
Samples and reference decoded files copied from the official ISO
reference suite.
---
Samples and references: https://files.lynne.ee/xhe_refs/

 tests/fate/aac.mak | 8 
 1 file changed, 8 insertions(+)

diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak
index 817944773d..ff58392ad9 100644
--- a/tests/fate/aac.mak
+++ b/tests/fate/aac.mak
@@ -62,6 +62,14 @@ FATE_AAC += fate-aac-ap05_48
 fate-aac-ap05_48: CMD = pcm -i $(TARGET_SAMPLES)/aac/ap05_48.mp4
 fate-aac-ap05_48: REF = $(SAMPLES)/aac/ap05_48.s16
 
+FATE_AAC += fate-aac-fd_2_c1_ms_0x01
+fate-aac-fd_2_c1_ms_0x01: CMD = pcm -i 
$(TARGET_SAMPLES)/aac/Fd_2_c1_Ms_0x01.mp4
+fate-aac-fd_2_c1_ms_0x01: REF = $(SAMPLES)/aac/Fd_2_c1_Ms_0x01.s16
+
+FATE_AAC += fate-aac-fd_2_c1_ms_0x04
+fate-aac-fd_2_c1_ms_0x04: CMD = pcm -i 
$(TARGET_SAMPLES)/aac/Fd_2_c1_Ms_0x04.mp4
+fate-aac-fd_2_c1_ms_0x04: REF = $(SAMPLES)/aac/Fd_2_c1_Ms_0x04.s16
+
 FATE_AAC += fate-aac-er_ad6000np_44_ep0
 fate-aac-er_ad6000np_44_ep0: CMD = pcm -i 
$(TARGET_SAMPLES)/aac/er_ad6000np_44_ep0.mp4
 fate-aac-er_ad6000np_44_ep0: REF = $(SAMPLES)/aac/er_ad6000np_44.s16
-- 
2.43.0.381.gb435a96ce8
___
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] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-20 Thread Gnattu OC via ffmpeg-devel



> On May 20, 2024, at 09:12, Marvin Scholz  wrote:
> 
> Fix #10884
> ---
> libavutil/hwcontext_videotoolbox.c | 54 +-
> 1 file changed, 38 insertions(+), 16 deletions(-)
> 
> diff --git a/libavutil/hwcontext_videotoolbox.c 
> b/libavutil/hwcontext_videotoolbox.c
> index 9f82b104c3..4a35bfc7ff 100644
> --- a/libavutil/hwcontext_videotoolbox.c
> +++ b/libavutil/hwcontext_videotoolbox.c
> @@ -530,6 +530,8 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum 
> AVColorTransferCharacteri
> static int vt_pixbuf_set_colorspace(void *log_ctx,
> CVPixelBufferRef pixbuf, const AVFrame 
> *src)
> {
> +CGColorSpaceRef colorspace = NULL;
> +CFMutableDictionaryRef attachments = NULL;
> CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
> Float32 gamma = 0;
> 
> @@ -550,37 +552,57 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
> else if (src->color_trc == AVCOL_TRC_GAMMA28)
> gamma = 2.8;
> 
> +attachments = CFDictionaryCreateMutable(NULL, 0,
> + 
> &kCFTypeDictionaryKeyCallBacks,
> + 
> &kCFTypeDictionaryValueCallBacks);
> +if (!attachments)
> +return AVERROR(ENOMEM);
> +
> if (colormatrix) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferYCbCrMatrixKey,
> -colormatrix,
> -kCVAttachmentMode_ShouldPropagate);
> +colormatrix);
> }
> if (colorpri) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferColorPrimariesKey,
> -colorpri,
> -kCVAttachmentMode_ShouldPropagate);
> +colorpri);
> }
> if (colortrc) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferTransferFunctionKey,
> -colortrc,
> -kCVAttachmentMode_ShouldPropagate);
> +colortrc);
> }
> if (gamma != 0) {
> CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, 
> &gamma);
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferGammaLevelKey,
> -gamma_level,
> -kCVAttachmentMode_ShouldPropagate);
> +gamma_level);
> CFRelease(gamma_level);
> }
> 
> +if (__builtin_available(macOS 10.8, iOS 10, *))
> +colorspace = 
> CVImageBufferCreateColorSpaceFromAttachments(attachments);
> +
> +if (colorspace) {
> +CFDictionarySetValue(
> +attachments,
> +kCVImageBufferCGColorSpaceKey,
> +colorspace);
> +CFRelease(colorspace);
> +} else
> +av_log(log_ctx, AV_LOG_WARNING, "Unable to set proper colorspace for 
> the CVImageBuffer.\n");

This will spam the console on SDR video inputs because they have nothing to be 
set as the attachment and the colorspace creation will always fail and return 
nil.

> +
> +CVBufferSetAttachments(
> +pixbuf,
> +attachments,
> +kCVAttachmentMode_ShouldPropagate);
> +CFRelease(attachments);
> +
> return 0;
> }
> 
> 
> base-commit: 463c573e6b6489c588bee90124d5cf92db8ccaaa
> -- 
> 2.39.3 (Apple Git-145)
> ___
> 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] avcodec/libsvtav1: send the EOS signal without a one frame delay to allow for the library to operate in a low-delay mode

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel
From: Cosmin Stejerean 

Co-authored-by: Amir Naghdinezhad 
Signed-off-by: Cosmin Stejerean 
---
 libavcodec/libsvtav1.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 3b41f5a39e..1eda63200c 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -539,6 +539,14 @@ static int eb_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 if (svt_ret == EB_NoErrorEmptyQueue)
 return AVERROR(EAGAIN);
 
+#if SVT_AV1_CHECK_VERSION(2, 0, 0)
+if (headerPtr->flags & EB_BUFFERFLAG_EOS) {
+ svt_enc->eos_flag = EOS_RECEIVED;
+ svt_av1_enc_release_out_buffer(&headerPtr);
+ return AVERROR_EOF;
+}
+#endif
+
 ref = get_output_ref(avctx, svt_enc, headerPtr->n_filled_len);
 if (!ref) {
 av_log(avctx, AV_LOG_ERROR, "Failed to allocate output packet.\n");
@@ -573,8 +581,10 @@ static int eb_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 if (headerPtr->pic_type == EB_AV1_NON_REF_PICTURE)
 pkt->flags |= AV_PKT_FLAG_DISPOSABLE;
 
+#if !(SVT_AV1_CHECK_VERSION(2, 0, 0))
 if (headerPtr->flags & EB_BUFFERFLAG_EOS)
 svt_enc->eos_flag = EOS_RECEIVED;
+#endif
 
 ff_side_data_set_encoder_stats(pkt, headerPtr->qp * FF_QP2LAMBDA, NULL, 0, 
pict_type);
 
-- 
2.42.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] avcodec/dovi_rpudec - correctly read el_bit_depth_minus8 when ext_mapping_idc is non-zero

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel
From: Cosmin Stejerean 

It looks like the el_bitdepth_minus8 value in the header can also encode
ext_mapping_idc in the upper 8 bits.

Samples having a non-zero ext_mapping_idc fail validation currently because the
value returned is out of range. This bypasses this by currently ignoring the
ext_mapping_idc and using only the lower 8 bits for el_bitdepth_minus8.

---
 libavcodec/dovi_rpudec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
index 7c7eda9d09..1b11ad3640 100644
--- a/libavcodec/dovi_rpudec.c
+++ b/libavcodec/dovi_rpudec.c
@@ -411,7 +411,9 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size,
 
 if ((hdr->rpu_format & 0x700) == 0) {
 int bl_bit_depth_minus8 = get_ue_golomb_31(gb);
-int el_bit_depth_minus8 = get_ue_golomb_31(gb);
+// this can encode a two byte value, with higher byte being 
ext_mapping_idc
+// use only the lower byte for el_bit_depth_minus8
+uint8_t el_bit_depth_minus8 = get_ue_golomb_long(gb) & 0xFF;
 int vdr_bit_depth_minus8 = get_ue_golomb_31(gb);
 VALIDATE(bl_bit_depth_minus8, 0, 8);
 VALIDATE(el_bit_depth_minus8, 0, 8);
-- 
2.42.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] lavf/dash: Forward strict flag to component demuxers

2024-05-20 Thread Andreas Rheinhardt
Frank Plowman:
> Before the patch, opening a DASH file containing streams which require
> experimental decoders was problematic.  No matter where the -strict -2
> was put on the command line, the option was not passed to the demuxer
> for that component.  This resulted in an error, prompting the user to
> add the -strict -2 flag, which is already present.  Decoding appeared to
> continue correctly however.
> 
> Patch removes the error message by creating an options object for the
> demuxer created for the component, which inherits from the parent
> demuxer.
> 
> Signed-off-by: Frank Plowman 
> ---
> PS: Can anyone think of other options which should be propagated to the
> component demuxers?
> 
>  libavformat/dashdec.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 555e21bf69..40abb5ebba 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -1911,13 +1911,18 @@ static int reopen_demux_for_component(AVFormatContext 
> *s, struct representation
>  if (ret < 0)
>  goto fail;
>  if (pls->n_fragments) {
> +AVDictionary *stream_info_opts = NULL;
> +
>  #if FF_API_R_FRAME_RATE
>  if (pls->framerate.den) {
>  for (i = 0; i < pls->ctx->nb_streams; i++)
>  pls->ctx->streams[i]->r_frame_rate = pls->framerate;
>  }
>  #endif
> -ret = avformat_find_stream_info(pls->ctx, NULL);
> +
> +av_dict_set_int(&stream_info_opts, "strict", 
> s->strict_std_compliance, 0);
> +
> +ret = avformat_find_stream_info(pls->ctx, &stream_info_opts);
>  if (ret < 0)
>  goto fail;
>  }

The loop over pls->ctx indicates that pls->ctx->nb_streams can be > 1
before avformat_find_stream_info(). But then using a single AVDictionary
is wrong, as avformat_find_stream_info() expects an array of
pls->ctx->nb_streams AVDictionary*.

Furthermore, the mixing between AVFormatContext and AVCodecContext
options here does not seem good (e.g. for ordinary demuxers setting
strict_std_compliance does not affect the AVCodecContext's values at all).

- Andreas

___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel


> On May 20, 2024, at 1:05 PM, Rémi Denis-Courmont  wrote:
> 
> Le maanantaina 20. toukokuuta 2024, 22.33.45 EEST Cosmin Stejerean via ffmpeg-
> devel a écrit :
>>> And again, you can't expect users to select decoders manually. If vvdec is
>>> the 
>>> default, hwaccel won't work. If vvdec is not the default, then it's
>>> dead code.
>> 
>> Not sure why you keep returning to this false dichotomy. 
> 
> It is the default or it is not the default. This is a true dichotomy and it 
> is 
> very disingenous to claim otherwise, so I will leave it at that.

You stated it's either the default or dead code. This is the false dichotomy I 
was referring to. Seems disingenuous to claim otherwise.

- Cosmin



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

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


[FFmpeg-devel] [PATCH v3 3/3] avfilter/af_volumedetect.c: reindent after last commit

2024-05-20 Thread Yigithan Yigit
---
 libavfilter/af_volumedetect.c | 68 +--
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index dbbcd037a5..b78b073c09 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -134,40 +134,40 @@ static void print_stats(AVFilterContext *ctx)
 sum += vd->histogram[i];
 }
 } else {
-for (i = 0; i < 0x1; i++)
-nb_samples += vd->histogram[i];
-av_log(ctx, AV_LOG_INFO, "n_samples: %"PRId64"\n", nb_samples);
-if (!nb_samples)
-return;
-
-/* If nb_samples > 1<<34, there is a risk of overflow in the
-   multiplication or the sum: shift all histogram values to avoid that.
-   The total number of samples must be recomputed to avoid rounding
-   errors. */
-shift = av_log2(nb_samples >> 33);
-for (i = 0; i < 0x1; i++) {
-nb_samples_shift += vd->histogram[i] >> shift;
-power += (i - 0x8000) * (i - 0x8000) * (vd->histogram[i] >> shift);
-}
-if (!nb_samples_shift)
-return;
-power = (power + nb_samples_shift / 2) / nb_samples_shift;
-av_assert0(power <= 0x8000 * 0x8000);
-av_log(ctx, AV_LOG_INFO, "mean_volume: %.1f dB\n", -logdb((double)power, 
AV_SAMPLE_FMT_S16));
-
-max_volume = 0x8000;
-while (max_volume > 0 && !vd->histogram[0x8000 + max_volume] &&
- !vd->histogram[0x8000 - max_volume])
-max_volume--;
-av_log(ctx, AV_LOG_INFO, "max_volume: %.1f dB\n", 
-logdb((double)(max_volume * max_volume), AV_SAMPLE_FMT_S16));
-
-for (i = 0; i < 0x1; i++)
-histdb[(int)logdb((double)(i - 0x8000) * (i - 0x8000), 
AV_SAMPLE_FMT_S16)] += vd->histogram[i];
-for (i = 0; i <= MAX_DB && !histdb[i]; i++);
-for (; i <= MAX_DB && sum < nb_samples / 1000; i++) {
-av_log(ctx, AV_LOG_INFO, "histogram_%ddb: %"PRId64"\n", -i, histdb[i]);
-sum += histdb[i];
-}
+for (i = 0; i < 0x1; i++)
+nb_samples += vd->histogram[i];
+av_log(ctx, AV_LOG_INFO, "n_samples: %"PRId64"\n", nb_samples);
+if (!nb_samples)
+return;
+
+/* If nb_samples > 1<<34, there is a risk of overflow in the
+multiplication or the sum: shift all histogram values to avoid that.
+The total number of samples must be recomputed to avoid rounding
+errors. */
+shift = av_log2(nb_samples >> 33);
+for (i = 0; i < 0x1; i++) {
+nb_samples_shift += vd->histogram[i] >> shift;
+power += (i - 0x8000) * (i - 0x8000) * (vd->histogram[i] >> shift);
+}
+if (!nb_samples_shift)
+return;
+power = (power + nb_samples_shift / 2) / nb_samples_shift;
+av_assert0(power <= 0x8000 * 0x8000);
+av_log(ctx, AV_LOG_INFO, "mean_volume: %.1f dB\n", 
-logdb((double)power, AV_SAMPLE_FMT_S16));
+
+max_volume = 0x8000;
+while (max_volume > 0 && !vd->histogram[0x8000 + max_volume] &&
+!vd->histogram[0x8000 - max_volume])
+max_volume--;
+av_log(ctx, AV_LOG_INFO, "max_volume: %.1f dB\n", 
-logdb((double)(max_volume * max_volume), AV_SAMPLE_FMT_S16));
+
+for (i = 0; i < 0x1; i++)
+histdb[(int)logdb((double)(i - 0x8000) * (i - 0x8000), 
AV_SAMPLE_FMT_S16)] += vd->histogram[i];
+for (i = 0; i <= MAX_DB && !histdb[i]; i++);
+for (; i <= MAX_DB && sum < nb_samples / 1000; i++) {
+av_log(ctx, AV_LOG_INFO, "histogram_%ddb: %"PRId64"\n", -i, 
histdb[i]);
+sum += histdb[i];
+}
 }
 }
 
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH v3 2/3] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-05-20 Thread Yigithan Yigit
---
 libavfilter/af_volumedetect.c | 159 --
 1 file changed, 133 insertions(+), 26 deletions(-)

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index 327801a7f9..dbbcd037a5 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -20,27 +20,51 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/avassert.h"
+#include "libavutil/mem.h"
 #include "audio.h"
 #include "avfilter.h"
 #include "internal.h"
 
+#define MAX_DB_FLT 1024
 #define MAX_DB 91
+#define HISTOGRAM_SIZE 0x1
+#define HISTOGRAM_SIZE_FLT (MAX_DB_FLT*2)
 
 typedef struct VolDetectContext {
-/**
- * Number of samples at each PCM value.
- * histogram[0x8000 + i] is the number of samples at value i.
- * The extra element is there for symmetry.
- */
-uint64_t histogram[0x10001];
+uint64_t* histogram; ///< for integer number of samples at each PCM value, 
for float number of samples at each dB
+uint64_t nb_samples; ///< number of samples
+double sum2; ///< sum of the squares of the samples
+double max;  ///< maximum sample value
+int is_float;///< true if the input is in floating point
 } VolDetectContext;
 
-static inline double logdb(uint64_t v)
+static inline double logdb(double v, enum AVSampleFormat sample_fmt)
 {
-double d = v / (double)(0x8000 * 0x8000);
-if (!v)
-return MAX_DB;
-return -log10(d) * 10;
+if (sample_fmt == AV_SAMPLE_FMT_FLT) {
+if (!v)
+return MAX_DB_FLT;
+return -log10(v) * 10;
+} else {
+double d = v / (double)(0x8000 * 0x8000);
+if (!v)
+return MAX_DB;
+return -log10(d) * 10;
+}
+}
+
+static void update_float_stats(VolDetectContext *vd, float *audio_data)
+{
+double sample;
+int idx;
+if(!isnormal(*audio_data))
+return;
+sample = fabsf(*audio_data);
+if (sample > vd->max)
+vd->max = sample;
+vd->sum2 += sample * sample;
+idx = lrintf(floorf(logdb(sample * sample, AV_SAMPLE_FMT_FLT))) + 
MAX_DB_FLT;
+vd->histogram[idx]++;
+vd->nb_samples++;
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
@@ -51,18 +75,41 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*samples)
 int nb_channels = samples->ch_layout.nb_channels;
 int nb_planes   = nb_channels;
 int plane, i;
-int16_t *pcm;
+int planar = 0;
 
-if (!av_sample_fmt_is_planar(samples->format)) {
-nb_samples *= nb_channels;
+planar = av_sample_fmt_is_planar(samples->format);
+if (!planar)
 nb_planes = 1;
+if (vd->is_float) {
+float *audio_data;
+for (plane = 0; plane < nb_planes; plane++) {
+audio_data = (float *)samples->extended_data[plane];
+for (i = 0; i < nb_samples; i++) {
+if (planar) {
+update_float_stats(vd, &audio_data[i]);
+} else {
+for (int j = 0; j < nb_channels; j++)
+update_float_stats(vd, &audio_data[i * nb_channels + 
j]);
+}
+}
+}
+} else {
+int16_t *pcm;
+for (plane = 0; plane < nb_planes; plane++) {
+pcm = (int16_t *)samples->extended_data[plane];
+for (i = 0; i < nb_samples; i++) {
+if (planar) {
+vd->histogram[pcm[i] + 0x8000]++;
+vd->nb_samples++;
+} else {
+for (int j = 0; j < nb_channels; j++) {
+vd->histogram[pcm[i * nb_channels + j] + 0x8000]++;
+vd->nb_samples++;
+}
+}
+}
+}
 }
-for (plane = 0; plane < nb_planes; plane++) {
-pcm = (int16_t *)samples->extended_data[plane];
-for (i = 0; i < nb_samples; i++)
-vd->histogram[pcm[i] + 0x8000]++;
-}
-
 return ff_filter_frame(inlink->dst->outputs[0], samples);
 }
 
@@ -73,6 +120,20 @@ static void print_stats(AVFilterContext *ctx)
 uint64_t nb_samples = 0, power = 0, nb_samples_shift = 0, sum = 0;
 uint64_t histdb[MAX_DB + 1] = { 0 };
 
+if (!vd->nb_samples)
+return;
+if (vd->is_float) {
+av_log(ctx, AV_LOG_INFO, "n_samples: %" PRId64 "\n", vd->nb_samples);
+av_log(ctx, AV_LOG_INFO, "mean_volume: %.1f dB\n", -logdb(vd->sum2 / 
vd->nb_samples, AV_SAMPLE_FMT_FLT));
+av_log(ctx, AV_LOG_INFO, "max_volume: %.1f dB\n", -2.0*logdb(vd->max, 
AV_SAMPLE_FMT_FLT));
+for (i = 0; i < HISTOGRAM_SIZE_FLT && !vd->histogram[i]; i++);
+for (; i >= 0 && sum < vd->nb_samples / 1000; i++) {
+if (!vd->histogram[i])
+continue;
+av_log(ctx, AV_LOG_INFO, "histogram_%ddb: %" PRId64 "\n", 
MAX_DB_FLT - i, vd->histogram[i]);
+sum += vd->histogram[i];
+}
+} else {
 for (i 

[FFmpeg-devel] [PATCH v3 1/3] avfilter/af_volumedetect.c: Move logdb function

2024-05-20 Thread Yigithan Yigit
---
 libavfilter/af_volumedetect.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index 8b001d1cf2..327801a7f9 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -24,6 +24,8 @@
 #include "avfilter.h"
 #include "internal.h"
 
+#define MAX_DB 91
+
 typedef struct VolDetectContext {
 /**
  * Number of samples at each PCM value.
@@ -33,6 +35,14 @@ typedef struct VolDetectContext {
 uint64_t histogram[0x10001];
 } VolDetectContext;
 
+static inline double logdb(uint64_t v)
+{
+double d = v / (double)(0x8000 * 0x8000);
+if (!v)
+return MAX_DB;
+return -log10(d) * 10;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -56,16 +66,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*samples)
 return ff_filter_frame(inlink->dst->outputs[0], samples);
 }
 
-#define MAX_DB 91
-
-static inline double logdb(uint64_t v)
-{
-double d = v / (double)(0x8000 * 0x8000);
-if (!v)
-return MAX_DB;
-return -log10(d) * 10;
-}
-
 static void print_stats(AVFilterContext *ctx)
 {
 VolDetectContext *vd = ctx->priv;
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH v3 0/3] avfilter/af_volumedetect.c: Move logdb function

2024-05-20 Thread Yigithan Yigit
v2 was mangled by my client.

Yigithan Yigit (3):
  avfilter/af_volumedetect.c: Move logdb function
  avfilter/af_volumedetect.c: Add 32bit float audio support
  avfilter/af_volumedetect.c: reindent after last commit

 libavfilter/af_volumedetect.c | 221 +-
 1 file changed, 164 insertions(+), 57 deletions(-)

--
2.44.0

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

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


[FFmpeg-devel] [PATCH] lavf/dash: Forward strict flag to component demuxers

2024-05-20 Thread Frank Plowman
Before the patch, opening a DASH file containing streams which require
experimental decoders was problematic.  No matter where the -strict -2
was put on the command line, the option was not passed to the demuxer
for that component.  This resulted in an error, prompting the user to
add the -strict -2 flag, which is already present.  Decoding appeared to
continue correctly however.

Patch removes the error message by creating an options object for the
demuxer created for the component, which inherits from the parent
demuxer.

Signed-off-by: Frank Plowman 
---
PS: Can anyone think of other options which should be propagated to the
component demuxers?

 libavformat/dashdec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 555e21bf69..40abb5ebba 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1911,13 +1911,18 @@ static int reopen_demux_for_component(AVFormatContext 
*s, struct representation
 if (ret < 0)
 goto fail;
 if (pls->n_fragments) {
+AVDictionary *stream_info_opts = NULL;
+
 #if FF_API_R_FRAME_RATE
 if (pls->framerate.den) {
 for (i = 0; i < pls->ctx->nb_streams; i++)
 pls->ctx->streams[i]->r_frame_rate = pls->framerate;
 }
 #endif
-ret = avformat_find_stream_info(pls->ctx, NULL);
+
+av_dict_set_int(&stream_info_opts, "strict", s->strict_std_compliance, 
0);
+
+ret = avformat_find_stream_info(pls->ctx, &stream_info_opts);
 if (ret < 0)
 goto fail;
 }
-- 
2.44.0

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

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


Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Rémi Denis-Courmont
Le maanantaina 20. toukokuuta 2024, 22.33.45 EEST Cosmin Stejerean via ffmpeg-
devel a écrit :
> > And again, you can't expect users to select decoders manually. If vvdec is
> > the 
> > default, hwaccel won't work. If vvdec is not the default, then it's
> > dead code.
> 
> Not sure why you keep returning to this false dichotomy. 

It is the default or it is not the default. This is a true dichotomy and it is 
very disingenous to claim otherwise, so I will leave it at that.

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel


> On May 20, 2024, at 12:01 PM, Rémi Denis-Courmont  wrote:
> 
> Le maanantaina 20. toukokuuta 2024, 21.39.18 EEST Cosmin Stejerean via ffmpeg-
> devel a écrit :
>> The same way using FDK-AAC as a decoder works, if you want to use it as the
>> *AAC decoder you have to specify the decoder with -c:a libfdk_aac before
>> the input.-
> 
> AFAIK, we don't have hwaccel for audio codecs. That sentence makes zero sense.

This is unrelated to hwaccel, I'm illustrating how a non-default decoder is 
selected in practice. It just so happens I always need to do this for audio 
currently.

> 
> And again, you can't expect users to select decoders manually. If vvdec is 
> the 
> default, hwaccel won't work. If vvdec is not the default, then it's dead code.

Not sure why you keep returning to this false dichotomy. 

You absolutely can have a decoder that's not the default, there is a facility 
for selecting it, and I use this to select the non-default decoder despite you 
claiming that non-default decoders are dead code, or that manually selecting 
them isn't a thing that users do.

>> Where is the "requiring" part coming in? I'm saying that manual decoder
>> selection is an option in the ffmpeg CLI, and can be used to select an
>> alternate decoder if the default one is not sufficient for some reason. 
> 
> So most people use libavcodec through higher-level frameworks or 
> applications, 
> not the CLI tool, and that is especially true for playback. If that's the 
> super-niche use-case for vvdec, then I agree with Kieran that it's just bloat.

Yes, the use case would be to be an alternate decoder that's available to users 
that want to use it. If that's not your use case that's ok, don't build with 
--enable-libvvdec.



- Cosmin


___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Rémi Denis-Courmont
Le maanantaina 20. toukokuuta 2024, 21.39.18 EEST Cosmin Stejerean via ffmpeg-
devel a écrit :
> The same way using FDK-AAC as a decoder works, if you want to use it as the
> *AAC decoder you have to specify the decoder with -c:a libfdk_aac before
> the input.-

AFAIK, we don't have hwaccel for audio codecs. That sentence makes zero sense.

And again, you can't expect users to select decoders manually. If vvdec is the 
default, hwaccel won't work. If vvdec is not the default, then it's dead code.

> Where is the "requiring" part coming in? I'm saying that manual decoder
> selection is an option in the ffmpeg CLI, and can be used to select an
> alternate decoder if the default one is not sufficient for some reason. 

So most people use libavcodec through higher-level frameworks or applications, 
not the CLI tool, and that is especially true for playback. If that's the 
super-niche use-case for vvdec, then I agree with Kieran that it's just bloat.

> > To the contrary, gstreamer, mpv, VLC et al. are better equipped to handle
> > this, starting with a proper plugin architecture.
> 
> 
> Better equipped to handle what?

To handle multiple implementations of decoding for a given codec, and not 
force them as installation and load-time dependencies.

-- 
レミ・デニ-クールモン
http://www.remlab.net/



___
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] [RFC] STF 2025

2024-05-20 Thread Rémi Denis-Courmont
Le sunnuntaina 19. toukokuuta 2024, 14.29.43 EEST Thilo Borgmann via ffmpeg-
devel a écrit :
> [...]
> 
> >> * Fund administrative / maintainance work (one example is the mailman
> >> upgrade that is needed>> 
> >>   with the next OS upgrade on one of our servers (this is not as trivial
> >>   as one might expect). Another example here may be some git related
> >>   tools if we find something that theres a broad consensus about.
> > 
> > I agree that this should be paid but I would expect that STF would not be
> > too keen on it, not that I'd know really.
> We should absolutely pay for such activity and STF is very well willing
> to fund such things.

Again, I don't know but that seems to stray from their stated goals. Also this 
is most certainly not a full-time job, and it requires a very high level of 
trust. In practice, what this really means is paying Michael.

It is more of a question whether STF is willing to pay for this, and whether a 
reasonable task description with a reasonable average prorated workload and a 
pay can be defined.

> > And again, it is completely reasonable to be paid for that, and also for
> > code reviews and writing test cases (if we want to complete the menial
> > task list), but I am perplexed as to STF's stance on that.

> Same as above about that we should and STF would.
> Especially since no corporate interest usually pays anyone for these tasks

Sadly true, but...

> (in case of reviews it might of course be considered a good thing).

I think some review is better than none. There may be conflict of interests, 
but they are weighed by the risk of being caught abusing the review process.

> The one problem to solve here AFAICT is we don't know exactly what
> quantity of bugs, reviewable code submissions and other maintenance work
> will come up in the next 12 months.

People would normally do this as interruption task whilst developing code (or 
writing documentation or whatever else) when there are no bugs and no review 
pending. Just like server admin, this is not a full-time job and we can't 
really pretend that it is.

> So it renders impossible to define in prior the workload, milestones and
> compensation per contributor interested as we did this year for
> well-defined tasks.

If you can't define workload, deliverables and cost, you wouldn't normally get 
funding. So I don't see much point in arguing about this. We can all agree 
that it is a conundrum, and that won't make the requirement go away.

> What we should consider IMO is defining the tasks (patch review, bug
> review & fix, FATE extensions, checkasm extensions, etc. as well such
> things for the administrative tasks from above) and defining a budget
> for these tasks.

In principles, all work deserves compensation. In practice, giving money in 
such small units sounds extremely impractical.

Also...

> Then, allow 'everyone interested' (aka git push access?) to claim a part
> of that budget every N-months, depending what the corresponding
> contributor actually did and can somehow be determined.

... with the current relatively small budget (even including STF funding), 
that would be a pittance for most people. I think we are better off paying a 
few people correctly than paying a lot of people peanuts - even leaving aside 
the administrative gas factory that this would add up to.

> > This is not something that STF should pay for, AFAIU. This is something
> > that professionals should pay out of their budget (or their employer's)
> > for the business events, and SPI for cheap/community events, IMO.
> I think we should fund all non-b2b appearances.

Of course we should reimburse reasonable transporation and accomodation costs, 
and of course goodies, as as been done already. Whether it's B2B, B2C or 
community is not really the criterion: we should simply *not* pay for booth 
space, booth installation or exhibitor tickets. It just so happens that in 
practice mostly only community conferences would allow us to hold a booth for 
free.

> About b2b, I wouldn't like our donation based money to be spent. We had
> corporate sponsorship in the past not having to think about it and
> possibly will have that as well in the future. The companies are
> interested in seeing us there and some are willing to pay for that
> happening.

If the conference/tradeshow organisers want to use FFmpeg as a marketing 
argument to attract attendees, they should provide a free booth. There is 
simply no way that FFmpeg would recoup its expenditure on a booth. It is not 
selling anything, additional donations are very unlikely to end us in the 
black, and the chance of finding a new contributor at B2B or B2C shows is also 
pretty much zilch.

If the booth is paid for by a business, then well that's a case of 
"professionals paying for it out of their budget", assuming that there are no 
hidden costs such as setup costs.

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
ffmpeg-devel mailing 

Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel


> On May 20, 2024, at 11:03 AM, Rémi Denis-Courmont  wrote:
> 
> Le maanantaina 20. toukokuuta 2024, 19.33.43 EEST Cosmin Stejerean via ffmpeg-
> devel a écrit :
> 
>> hwaccel decoding seems somewhat orthogonal
> 
> How exactly will that work then? Either vvdec is the default, and hwaccel 
> won't work, or vvdec is not the default and it's essentially dead code.

The same way using FDK-AAC as a decoder works, if you want to use it as the 
*AAC decoder you have to specify the decoder with -c:a libfdk_aac before the 
input.-

> 
>>> Providing a non-default choice is a poor excuse for a bug. Most users
>>> won't know how to do that, and many FFmpeg reverse dependencies don't
>>> even allow it.
>> 
>> Need better documentation then?
> 
> Well, good luck with that. Documentation for working around as yet unknown 
> bugs sounds a bit difficult to write, and even then, requiring manual decoder 
> selection seems very user-hostile to me.

Where is the "requiring" part coming in? I'm saying that manual decoder 
selection is an option in the ffmpeg CLI, and can be used to select an 
alternate decoder if the default one is not sufficient for some reason. 

This is a thing I've had to do repeatedly over the past few years for FDK-AAC.

> 
>> Not sure that designing for the lowest common denominator of reverse
>> dependencies is the best way to do things, but at a minimum one can rebuild
>> ffmpeg with only one decoder enabled to get around this.
> 
> To the contrary, gstreamer, mpv, VLC et al. are better equipped to handle 
> this, starting with a proper plugin architecture.

Better equipped to handle what? For the usecase of transcoding it doesn't 
matter whether or not downstream player dependencies do or don't expose 
alternate decoders in libavcodec, to the extent they even use libavcodec for 
decoding.

So it seems weird to reject a patch to add a decoder option because it may or 
may not be useful to the downstream players.
 
- Cosmin
___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Rémi Denis-Courmont
Le maanantaina 20. toukokuuta 2024, 19.33.43 EEST Cosmin Stejerean via ffmpeg-
devel a écrit :
> > Adding a disabled-by-default decoder is adding bloat, if there is not a
> > specific known reason why that is needed.
 
> > This is especially true for video decoders, where the external decoders
> > typically will have no or worse optimisations for DSP functions, no
> > thread support (or not accessible via libavcodec), and no integration
> > with hwaccel.
> 
> Is this an actual problem with vvdec?

Yes?

> To me it seems like a reasonably optimized decoder with support for
> threading, etc.

It seems to be vendoring SIMDe, which is 1) a bad thing according to most 
distro policies, 2) not as good as FFmpeg optimisations generally speaking and 
3) lacking several ISAs featured by FFmpeg.

> hwaccel decoding seems somewhat orthogonal

How exactly will that work then? Either vvdec is the default, and hwaccel 
won't work, or vvdec is not the default and it's essentially dead code.

> > Providing a non-default choice is a poor excuse for a bug. Most users
> > won't know how to do that, and many FFmpeg reverse dependencies don't
> > even allow it.
> 
> Need better documentation then?

Well, good luck with that. Documentation for working around as yet unknown 
bugs sounds a bit difficult to write, and even then, requiring manual decoder 
selection seems very user-hostile to me.

> Not sure that designing for the lowest common denominator of reverse
> dependencies is the best way to do things, but at a minimum one can rebuild
> ffmpeg with only one decoder enabled to get around this.

To the contrary, gstreamer, mpv, VLC et al. are better equipped to handle 
this, starting with a proper plugin architecture.

-- 
レミ・デニ-クールモン
http://www.remlab.net/



___
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] libavcodec/amfenc: Update AMF encoder options

2024-05-20 Thread Araz
Please review the attached patch and provide your feedback.
___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel
Trying again with better formatting, hopefully

> On May 18, 2024, at 10:48 PM, Rémi Denis-Courmont  wrote:
> 
> Hi,
> 
> Le 18 mai 2024 21:55:04 GMT+03:00, Cosmin Stejerean via ffmpeg-devel 
>  a écrit :
>> 
>> 
>>> On May 18, 2024, at 7:04 AM, Nuo Mi  wrote:
>>> 
>>> This happened many years ago. See the discussion here:
>>> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20201221060710.12230-6-nuomi2...@gmail.com/#60589
>>> Now that we have an internal vvc decoder, we can focus on improving it.
>>> As for the encoder, it is far more complex than the decoder. Reasonable to
>>> wrapper other libraries just like libx264 and libx265...
>> 
>> I'm all for improving the internal decoder, and I agree that the internal 
>> decoder should be preferred and be used by default, but it's not clear why 
>> that should preclude adding an external decoder as an option.
> 
> Adding a disabled-by-default decoder is adding bloat, if there is not a 
> specific known reason why that is needed.
> 
> This is especially true for video decoders, where the external decoders 
> typically will have no or worse optimisations for DSP functions, no thread 
> support (or not accessible via libavcodec), and no integration with hwaccel.

Is this an actual problem with vvdec? To me it seems like a reasonably 
optimized decoder with support for threading, etc. hwaccel decoding seems 
somewhat orthogonal

> 
> The later point has become a problem even with dav1d...
> 
>> Sometimes bugs are found in the internal decoders
> 
> Providing a non-default choice is a poor excuse for a bug. Most users won't 
> know how to do that, and many FFmpeg reverse dependencies don't even allow it.

Need better documentation then? Not sure that designing for the lowest common 
denominator of reverse dependencies is the best way to do things, but at a 
minimum one can rebuild ffmpeg with only one decoder enabled to get around this.

> 
>> or some functionality may be missing, and having the option to fallback to 
>> an external decoder as a workaround is very useful in practice.
> 
> That I can agree, but what do you find missing in the VVC decoder compared to 
> libvvcdec?

This I'm not sure, perhaps there is no feature gap? Does the internal VVC 
decoder supports all features of the Main10 profile?

- Cosmin
___
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] avcodec: add external dec libvvdec for H266/VVC

2024-05-20 Thread Cosmin Stejerean via ffmpeg-devel
On May 18, 2024, at 10:48 PM, Rémi Denis-Courmont  wrote:

Le 18 mai 2024 21:55:04 GMT+03:00, Cosmin Stejerean via ffmpeg-devel 
mailto:ffmpeg-devel@ffmpeg.org> > a écrit :


On May 18, 2024, at 7:04 AM, Nuo Mi mailto:nuomi2...@gmail.com> > wrote:

This happened many years ago. See the discussion here:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20201221060710.12230-6-nuomi2...@gmail.com/#60589
 

 
Now that we have an internal vvc decoder, we can focus on improving it.
As for the encoder, it is far more complex than the decoder. Reasonable to
wrapper other libraries just like libx264 and libx265...

I'm all for improving the internal decoder, and I agree that the internal 
decoder should be preferred and be used by default, but it's not clear why that 
should preclude adding an external decoder as an option.

Adding a disabled-by-default decoder is adding bloat, if there is not a 
specific known reason why that is needed.

This is especially true for video decoders, where the external decoders 
typically will have no or worse optimisations for DSP functions, no thread 
support (or not accessible via libavcodec), 

Is this an actual problem with vvdec? To me it seems like a reasonably 
optimized decoder with support for threading, etc.

and no integration with hwaccel.

The later point has become a problem even with dav1d...

hwaccel decoding seems somewhat orthogonal


Sometimes bugs are found in the internal decoders

Providing a non-default choice is a poor excuse for a bug. Most users won't 
know how to do that, 

need better documentation?

and many FFmpeg reverse dependencies don't even allow it.

not sure that designing for the lowest common denominator of reverse 
dependencies is the best way to do things, but at a minimum one can rebuild 
ffmpeg with only one decoder enabled to get around this


or some functionality may be missing, and having the option to fallback to an 
external decoder as a workaround is very useful in practice.

That I can agree, but what do you find missing in the VVC decoder compared to 
libvvcdec?
___

This I'm not sure, perhaps there is no feature gap? Does the internal VVC 
decoder supports all features of the Main10 profile?

- Cosmin
___
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/2][GSoC 2024] libavcodec/x86/vvc: Add AVX2 DMVR SAD functions for VVC

2024-05-20 Thread Ronald S. Bultje
Hi,

one more, I forgot.

On Sun, May 19, 2024 at 8:46 PM Stone Chen  wrote:

> +pw_1: dw 1
>
[..]

> +vpbroadcastw   m4, [pw_1]
>

We typically suggest to use vpbroadcastd, not w (and then pw_1: times 2 dw
1). agner shows that on e.g. Haswell, the former (d) is 1 uops with 5
cycles latency, whereas the latter (w) is 3 uops with 7 cycles latency, or
more generally d is faster then w.

Ronald
___
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] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-20 Thread Marvin Scholz
Fix #10884
---
 libavutil/hwcontext_videotoolbox.c | 54 +-
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index 9f82b104c3..4a35bfc7ff 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -530,6 +530,8 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum 
AVColorTransferCharacteri
 static int vt_pixbuf_set_colorspace(void *log_ctx,
 CVPixelBufferRef pixbuf, const AVFrame 
*src)
 {
+CGColorSpaceRef colorspace = NULL;
+CFMutableDictionaryRef attachments = NULL;
 CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
 Float32 gamma = 0;
 
@@ -550,37 +552,57 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 else if (src->color_trc == AVCOL_TRC_GAMMA28)
 gamma = 2.8;
 
+attachments = CFDictionaryCreateMutable(NULL, 0,
+ 
&kCFTypeDictionaryKeyCallBacks,
+ 
&kCFTypeDictionaryValueCallBacks);
+if (!attachments)
+return AVERROR(ENOMEM);
+
 if (colormatrix) {
-CVBufferSetAttachment(
-pixbuf,
+CFDictionarySetValue(
+attachments,
 kCVImageBufferYCbCrMatrixKey,
-colormatrix,
-kCVAttachmentMode_ShouldPropagate);
+colormatrix);
 }
 if (colorpri) {
-CVBufferSetAttachment(
-pixbuf,
+CFDictionarySetValue(
+attachments,
 kCVImageBufferColorPrimariesKey,
-colorpri,
-kCVAttachmentMode_ShouldPropagate);
+colorpri);
 }
 if (colortrc) {
-CVBufferSetAttachment(
-pixbuf,
+CFDictionarySetValue(
+attachments,
 kCVImageBufferTransferFunctionKey,
-colortrc,
-kCVAttachmentMode_ShouldPropagate);
+colortrc);
 }
 if (gamma != 0) {
 CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, 
&gamma);
-CVBufferSetAttachment(
-pixbuf,
+CFDictionarySetValue(
+attachments,
 kCVImageBufferGammaLevelKey,
-gamma_level,
-kCVAttachmentMode_ShouldPropagate);
+gamma_level);
 CFRelease(gamma_level);
 }
 
+if (__builtin_available(macOS 10.8, iOS 10, *))
+colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments);
+
+if (colorspace) {
+CFDictionarySetValue(
+attachments,
+kCVImageBufferCGColorSpaceKey,
+colorspace);
+CFRelease(colorspace);
+} else
+av_log(log_ctx, AV_LOG_WARNING, "Unable to set proper colorspace for 
the CVImageBuffer.\n");
+
+CVBufferSetAttachments(
+pixbuf,
+attachments,
+kCVAttachmentMode_ShouldPropagate);
+CFRelease(attachments);
+
 return 0;
 }
 

base-commit: 463c573e6b6489c588bee90124d5cf92db8ccaaa
-- 
2.39.3 (Apple Git-145)
___
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: Set proper CVBuffer colorspace

2024-05-20 Thread Zhao Zhili



> On May 20, 2024, at 09:12, Marvin Scholz  wrote:
> 
> Fix #10884

LGTM except the commit subject should mention videotoolbox or vt in short.

> ---
> libavutil/hwcontext_videotoolbox.c | 54 +-
> 1 file changed, 38 insertions(+), 16 deletions(-)
> 
> diff --git a/libavutil/hwcontext_videotoolbox.c 
> b/libavutil/hwcontext_videotoolbox.c
> index 9f82b104c3..4a35bfc7ff 100644
> --- a/libavutil/hwcontext_videotoolbox.c
> +++ b/libavutil/hwcontext_videotoolbox.c
> @@ -530,6 +530,8 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum 
> AVColorTransferCharacteri
> static int vt_pixbuf_set_colorspace(void *log_ctx,
> CVPixelBufferRef pixbuf, const AVFrame 
> *src)
> {
> +CGColorSpaceRef colorspace = NULL;
> +CFMutableDictionaryRef attachments = NULL;
> CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
> Float32 gamma = 0;
> 
> @@ -550,37 +552,57 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
> else if (src->color_trc == AVCOL_TRC_GAMMA28)
> gamma = 2.8;
> 
> +attachments = CFDictionaryCreateMutable(NULL, 0,
> + 
> &kCFTypeDictionaryKeyCallBacks,
> + 
> &kCFTypeDictionaryValueCallBacks);
> +if (!attachments)
> +return AVERROR(ENOMEM);
> +
> if (colormatrix) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferYCbCrMatrixKey,
> -colormatrix,
> -kCVAttachmentMode_ShouldPropagate);
> +colormatrix);
> }
> if (colorpri) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferColorPrimariesKey,
> -colorpri,
> -kCVAttachmentMode_ShouldPropagate);
> +colorpri);
> }
> if (colortrc) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferTransferFunctionKey,
> -colortrc,
> -kCVAttachmentMode_ShouldPropagate);
> +colortrc);
> }
> if (gamma != 0) {
> CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, 
> &gamma);
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferGammaLevelKey,
> -gamma_level,
> -kCVAttachmentMode_ShouldPropagate);
> +gamma_level);
> CFRelease(gamma_level);
> }
> 
> +if (__builtin_available(macOS 10.8, iOS 10, *))
> +colorspace = 
> CVImageBufferCreateColorSpaceFromAttachments(attachments);
> +
> +if (colorspace) {
> +CFDictionarySetValue(
> +attachments,
> +kCVImageBufferCGColorSpaceKey,
> +colorspace);
> +CFRelease(colorspace);
> +} else
> +av_log(log_ctx, AV_LOG_WARNING, "Unable to set proper colorspace for 
> the CVImageBuffer.\n");
> +
> +CVBufferSetAttachments(
> +pixbuf,
> +attachments,
> +kCVAttachmentMode_ShouldPropagate);
> +CFRelease(attachments);
> +
> return 0;
> }
> 
> 
> base-commit: 463c573e6b6489c588bee90124d5cf92db8ccaaa
> -- 
> 2.39.3 (Apple Git-145)
> ___
> 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 v8 12/15] avcodec/vaapi_encode: extract a free funtion to base layer

2024-05-20 Thread Wu, Tong1
>Subject: Re: [FFmpeg-devel] [PATCH v8 12/15] avcodec/vaapi_encode: extract a
>free funtion to base layer
>
>On 18/04/2024 09:59, tong1.wu-at-intel@ffmpeg.org wrote:
>> From: Tong Wu 
>>
>> Signed-off-by: Tong Wu 
>> ---
>>  libavcodec/hw_base_encode.c | 11 +++
>>  libavcodec/hw_base_encode.h |  2 ++
>>  libavcodec/vaapi_encode.c   |  6 +-
>>  3 files changed, 14 insertions(+), 5 deletions(-)
>
>"... free funtion to ..."
>
>While I do approve of fun, maybe this should be a function.
>

Hi Mark,

I've sent patch v9 which addressed multiple concerns of yours.
1. AVClass definition is put in the first patch.
2. Used "base_foo = &foo->base_field"
3. Used vaapi_pic and pic instead of pic and base_pic in vaapi_encode_*.c to 
simplify code lines.
4. Squashed init and close into one patch.

However, I did not change the way for .alloc and .free since I feel like the 
malloc(sizeof(VAAPIEncodePicture)) and ctx->codec are both part of vaapi 
context and should not be moved to base. 
As for the .free function I have this patch to extract a base layer free 
function which avoid the mix of two layer parameters. 

Feel free to comment on V9. Thanks.

-Tong



___
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 v9 13/13] Changelog: add D3D12VA HEVC encoder changelog

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Signed-off-by: Tong Wu 
---
 Changelog | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index dd25715d6b..c3f802617f 100644
--- a/Changelog
+++ b/Changelog
@@ -10,7 +10,7 @@ version :
 - vf_scale supports secondary ref input and framesync options
 - vf_scale2ref deprecated
 - qsv_params option added for QSV encoders
-
+- D3D12VA HEVC encoder
 
 version 7.0:
 - DXV DXT1 encoder
-- 
2.41.0.windows.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 v9 07/13] avcodec/vaapi_encode: extract gop configuration and two options to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

idr_interval and desired_b_depth are moved to HW_BASE_ENCODE_COMMON_OPTIONS.

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 54 +
 libavcodec/hw_base_encode.h | 19 +
 libavcodec/vaapi_encode.c   | 52 +++
 libavcodec/vaapi_encode.h   | 16 ---
 4 files changed, 77 insertions(+), 64 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index f2b6ef4a3a..dfe20c4e67 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -596,6 +596,60 @@ end:
 return 0;
 }
 
+int ff_hw_base_init_gop_structure(AVCodecContext *avctx, uint32_t ref_l0, 
uint32_t ref_l1,
+  int flags, int prediction_pre_only)
+{
+HWBaseEncodeContext *ctx = avctx->priv_data;
+
+if (flags & FLAG_INTRA_ONLY || avctx->gop_size <= 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n");
+ctx->gop_size = 1;
+} else if (ref_l0 < 1) {
+av_log(avctx, AV_LOG_ERROR, "Driver does not support any "
+   "reference frames.\n");
+return AVERROR(EINVAL);
+} else if (!(flags & FLAG_B_PICTURES) || ref_l1 < 1 ||
+   avctx->max_b_frames < 1 || prediction_pre_only) {
+if (ctx->p_to_gpb)
+   av_log(avctx, AV_LOG_VERBOSE, "Using intra and B-frames "
+  "(supported references: %d / %d).\n",
+  ref_l0, ref_l1);
+else
+av_log(avctx, AV_LOG_VERBOSE, "Using intra and P-frames "
+   "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = 0;
+} else {
+   if (ctx->p_to_gpb)
+   av_log(avctx, AV_LOG_VERBOSE, "Using intra and B-frames "
+  "(supported references: %d / %d).\n",
+  ref_l0, ref_l1);
+   else
+   av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames "
+  "(supported references: %d / %d).\n", ref_l0, ref_l1);
+ctx->gop_size = avctx->gop_size;
+ctx->p_per_i  = INT_MAX;
+ctx->b_per_p  = avctx->max_b_frames;
+if (flags & FLAG_B_PICTURE_REFERENCES) {
+ctx->max_b_depth = FFMIN(ctx->desired_b_depth,
+ av_log2(ctx->b_per_p) + 1);
+} else {
+ctx->max_b_depth = 1;
+}
+}
+
+if (flags & FLAG_NON_IDR_KEY_PICTURES) {
+ctx->closed_gop  = !!(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP);
+ctx->gop_per_idr = ctx->idr_interval + 1;
+} else {
+ctx->closed_gop  = 1;
+ctx->gop_per_idr = 1;
+}
+
+return 0;
+}
+
 int ff_hw_base_encode_init(AVCodecContext *avctx)
 {
 HWBaseEncodeContext *ctx = avctx->priv_data;
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 7e20f57b9c..07936bf9bb 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -119,6 +119,14 @@ typedef struct HWBaseEncodeContext {
 // Hardware-specific hooks.
 const struct HWEncodePictureOperation *op;
 
+// Global options.
+
+// Number of I frames between IDR frames.
+int idr_interval;
+
+// Desired B frame reference depth.
+int desired_b_depth;
+
 // The hardware device context.
 AVBufferRef*device_ref;
 AVHWDeviceContext *device;
@@ -197,11 +205,22 @@ typedef struct HWBaseEncodeContext {
 
 int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
 
+int ff_hw_base_init_gop_structure(AVCodecContext *avctx, uint32_t ref_l0, 
uint32_t ref_l1,
+  int flags, int prediction_pre_only);
+
 int ff_hw_base_encode_init(AVCodecContext *avctx);
 
 int ff_hw_base_encode_close(AVCodecContext *avctx);
 
 #define HW_BASE_ENCODE_COMMON_OPTIONS \
+{ "idr_interval", \
+  "Distance (in I-frames) between key frames", \
+  OFFSET(common.base.idr_interval), AV_OPT_TYPE_INT, \
+  { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
+{ "b_depth", \
+  "Maximum B-frame reference depth", \
+  OFFSET(common.base.desired_b_depth), AV_OPT_TYPE_INT, \
+  { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
 { "async_depth", "Maximum processing parallelism. " \
   "Increase this to improve single channel performance.", \
   OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c3ab0fc192..4db64b686b 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1638,7 +1638,7 @@ static av_cold int 
vaapi_encode_init_gop_structure(AVCodecContext *avctx)
 VAStatus vas;
 VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames };
 uint32_t ref_l0, ref_l1;
-int prediction_pre_only;
+int prediction_pre_only, err;
 
 vas = vaGetConfigAttributes(ctx->hwctx->display,

[FFmpeg-devel] [PATCH v9 12/13] avcodec: add D3D12VA hardware HEVC encoder

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

This implementation is based on D3D12 Video Encoding Spec:
https://microsoft.github.io/DirectX-Specs/d3d/D3D12VideoEncoding.html

Sample command line for transcoding:
ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4
-c:v hevc_d3d12va output.mp4

Signed-off-by: Tong Wu 
---
 configure|6 +
 libavcodec/Makefile  |5 +-
 libavcodec/allcodecs.c   |1 +
 libavcodec/d3d12va_encode.c  | 1558 ++
 libavcodec/d3d12va_encode.h  |  334 +++
 libavcodec/d3d12va_encode_hevc.c | 1007 +++
 6 files changed, 2910 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/d3d12va_encode.c
 create mode 100644 libavcodec/d3d12va_encode.h
 create mode 100644 libavcodec/d3d12va_encode_hevc.c

diff --git a/configure b/configure
index b16722d83d..127d68e60c 100755
--- a/configure
+++ b/configure
@@ -2551,6 +2551,7 @@ CONFIG_EXTRA="
 cbs_mpeg2
 cbs_vp8
 cbs_vp9
+d3d12va_encode
 deflate_wrapper
 dirac_parse
 dnn
@@ -3287,6 +3288,7 @@ wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
 wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
 
 # hardware-accelerated codecs
+d3d12va_encode_deps="d3d12va ID3D12VideoEncoder d3d12_encoder_feature"
 mediafoundation_deps="mftransform_h MFCreateAlignedMemoryBuffer"
 omx_deps="libdl pthreads"
 omx_rpi_select="omx"
@@ -3354,6 +3356,7 @@ h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
 hevc_amf_encoder_deps="amf"
 hevc_cuvid_decoder_deps="cuvid"
 hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
+hevc_d3d12va_encoder_select="cbs_h265 d3d12va_encode"
 hevc_mediacodec_decoder_deps="mediacodec"
 hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
 hevc_mediacodec_encoder_deps="mediacodec"
@@ -6725,6 +6728,9 @@ check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "windows.h d3d11.h" "ID3D11VideoContext"
 check_type "windows.h d3d12.h" "ID3D12Device"
 check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
+check_type "windows.h d3d12video.h" "ID3D12VideoEncoder"
+test_code cc "windows.h d3d12video.h" "D3D12_FEATURE_VIDEO feature = 
D3D12_FEATURE_VIDEO_ENCODER_CODEC" && \
+test_code cc "windows.h d3d12video.h" 
"D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS req" && enable 
d3d12_encoder_feature
 check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 998f6b7e12..6c4500ce6d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -86,6 +86,7 @@ OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CBS_VP8) += cbs_vp8.o vp8data.o
 OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
+OBJS-$(CONFIG_D3D12VA_ENCODE)  += d3d12va_encode.o hw_base_encode.o
 OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o
 OBJS-$(CONFIG_DOVI_RPUDEC) += dovi_rpu.o dovi_rpudec.o
 OBJS-$(CONFIG_DOVI_RPUENC) += dovi_rpu.o dovi_rpuenc.o
@@ -436,6 +437,8 @@ OBJS-$(CONFIG_HEVC_DECODER)+= hevcdec.o 
hevc_mvs.o \
   h274.o aom_film_grain.o
 OBJS-$(CONFIG_HEVC_AMF_ENCODER)+= amfenc_hevc.o
 OBJS-$(CONFIG_HEVC_CUVID_DECODER)  += cuviddec.o
+OBJS-$(CONFIG_HEVC_D3D12VA_ENCODER)+= d3d12va_encode_hevc.o 
h265_profile_level.o \
+  h2645data.o
 OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_HEVC_MEDIACODEC_ENCODER) += mediacodecenc.o
 OBJS-$(CONFIG_HEVC_MF_ENCODER) += mfenc.o mf_utils.o
@@ -1265,7 +1268,7 @@ SKIPHEADERS+= %_tablegen.h
  \
 
 SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
 SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
-SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
+SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h d3d12va_encode.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
 SKIPHEADERS-$(CONFIG_JNI)  += ffjni.h
 SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b102a8069e..463ffbbd08 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -848,6 +848,7 @@ extern const FFCodec ff_h264_vaapi_encoder;
 extern const FFCodec ff_h264_videotoolbox_encoder;
 extern const FFCodec ff_hevc_amf_encoder;
 extern const FFCodec ff_hevc_cuvid_decoder;
+extern const FFCodec ff_hevc_d3d12va_encoder;
 extern const FFCodec ff_hevc_mediacodec_decoder;
 extern const FFCodec ff_hevc_mediacodec_encoder;
 extern const FFCodec ff_hevc_mf_encoder;
diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
new file mode 100644
index 00..a20e6cc961
--- /

[FFmpeg-devel] [PATCH v9 11/13] avutil/hwcontext_d3d12va: add Flags for resource creation

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Flags field is added to support diffferent resource creation.

Signed-off-by: Tong Wu 
---
 doc/APIchanges| 3 +++
 libavutil/hwcontext_d3d12va.c | 2 +-
 libavutil/hwcontext_d3d12va.h | 8 
 libavutil/version.h   | 2 +-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 269fd36559..808ba02f2d 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-01-xx - xx - lavu 59.20.100 - hwcontext_d3d12va.h
+ Add AVD3D12VAFramesContext.flags
+
 2024-05-xx - xx - lavu 59.19.100 - hwcontext_qsv.h
   Add AVQSVFramesContext.info
 
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index cfc016315d..6507cf69c1 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -247,7 +247,7 @@ static AVBufferRef *d3d12va_pool_alloc(void *opaque, size_t 
size)
 .Format   = hwctx->format,
 .SampleDesc   = {.Count = 1, .Quality = 0 },
 .Layout   = D3D12_TEXTURE_LAYOUT_UNKNOWN,
-.Flags= D3D12_RESOURCE_FLAG_NONE,
+.Flags= hwctx->flags,
 };
 
 frame = av_mallocz(sizeof(AVD3D12VAFrame));
diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
index ff06e6f2ef..608dbac97f 100644
--- a/libavutil/hwcontext_d3d12va.h
+++ b/libavutil/hwcontext_d3d12va.h
@@ -129,6 +129,14 @@ typedef struct AVD3D12VAFramesContext {
  * If unset, will be automatically set.
  */
 DXGI_FORMAT format;
+
+/**
+ * This field is used to specify options for working with resources.
+ * If unset, this will be D3D12_RESOURCE_FLAG_NONE.
+ *
+ * @see: 
https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_flags.
+ */
+D3D12_RESOURCE_FLAGS flags;
 } AVD3D12VAFramesContext;
 
 #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 3221c4c592..9c7146c228 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  19
+#define LIBAVUTIL_VERSION_MINOR  20
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.41.0.windows.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 v9 10/13] avcodec/vaapi_encode: extract a free funtion to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 11 +++
 libavcodec/hw_base_encode.h |  2 ++
 libavcodec/vaapi_encode.c   |  6 +-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index 42c40cb48f..f743d119cd 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -748,6 +748,17 @@ fail:
 return err;
 }
 
+int ff_hw_base_encode_free(AVCodecContext *avctx, HWBaseEncodePicture *pic)
+{
+av_frame_free(&pic->input_image);
+av_frame_free(&pic->recon_image);
+
+av_buffer_unref(&pic->opaque_ref);
+av_freep(&pic->priv_data);
+
+return 0;
+}
+
 int ff_hw_base_encode_init(AVCodecContext *avctx)
 {
 HWBaseEncodeContext *ctx = avctx->priv_data;
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 7d40da039c..76a39e2d97 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -223,6 +223,8 @@ int ff_hw_base_init_gop_structure(AVCodecContext *avctx, 
uint32_t ref_l0, uint32
 
 int ff_hw_base_get_recon_format(AVCodecContext *avctx, const void *hwconfig, 
enum AVPixelFormat *fmt);
 
+int ff_hw_base_encode_free(AVCodecContext *avctx, HWBaseEncodePicture *pic);
+
 int ff_hw_base_encode_init(AVCodecContext *avctx);
 
 int ff_hw_base_encode_close(AVCodecContext *avctx);
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 98b8c82da3..e89d6e01af 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -878,17 +878,13 @@ static int vaapi_encode_free(AVCodecContext *avctx,
 av_freep(&pic->slices[i].codec_slice_params);
 }
 
-av_frame_free(&base_pic->input_image);
-av_frame_free(&base_pic->recon_image);
-
-av_buffer_unref(&base_pic->opaque_ref);
+ff_hw_base_encode_free(avctx, base_pic);
 
 av_freep(&pic->param_buffers);
 av_freep(&pic->slices);
 // Output buffer should already be destroyed.
 av_assert0(pic->output_buffer == VA_INVALID_ID);
 
-av_freep(&base_pic->priv_data);
 av_freep(&pic->codec_picture_params);
 av_freep(&pic->roi);
 
-- 
2.41.0.windows.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 v9 09/13] avcodec/vaapi_encode: extract a get_recon_format function to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Surface size and block size parameters are also moved to base layer.

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 58 +++
 libavcodec/hw_base_encode.h | 12 +
 libavcodec/vaapi_encode.c   | 81 -
 libavcodec/vaapi_encode.h   | 10 
 libavcodec/vaapi_encode_av1.c   | 10 ++--
 libavcodec/vaapi_encode_h264.c  | 11 +++--
 libavcodec/vaapi_encode_h265.c  | 25 +-
 libavcodec/vaapi_encode_mjpeg.c |  5 +-
 libavcodec/vaapi_encode_vp9.c   |  6 +--
 9 files changed, 118 insertions(+), 100 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index df820c2f83..42c40cb48f 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -690,6 +690,64 @@ int ff_hw_base_init_gop_structure(AVCodecContext *avctx, 
uint32_t ref_l0, uint32
 return 0;
 }
 
+int ff_hw_base_get_recon_format(AVCodecContext *avctx, const void *hwconfig, 
enum AVPixelFormat *fmt)
+{
+HWBaseEncodeContext *ctx = avctx->priv_data;
+AVHWFramesConstraints *constraints = NULL;
+enum AVPixelFormat recon_format;
+int err, i;
+
+constraints = av_hwdevice_get_hwframe_constraints(ctx->device_ref,
+  hwconfig);
+if (!constraints) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+
+// Probably we can use the input surface format as the surface format
+// of the reconstructed frames.  If not, we just pick the first (only?)
+// format in the valid list and hope that it all works.
+recon_format = AV_PIX_FMT_NONE;
+if (constraints->valid_sw_formats) {
+for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
+if (ctx->input_frames->sw_format ==
+constraints->valid_sw_formats[i]) {
+recon_format = ctx->input_frames->sw_format;
+break;
+}
+}
+if (recon_format == AV_PIX_FMT_NONE) {
+// No match.  Just use the first in the supported list and
+// hope for the best.
+recon_format = constraints->valid_sw_formats[0];
+}
+} else {
+// No idea what to use; copy input format.
+recon_format = ctx->input_frames->sw_format;
+}
+av_log(avctx, AV_LOG_DEBUG, "Using %s as format of "
+   "reconstructed frames.\n", av_get_pix_fmt_name(recon_format));
+
+if (ctx->surface_width  < constraints->min_width  ||
+ctx->surface_height < constraints->min_height ||
+ctx->surface_width  > constraints->max_width ||
+ctx->surface_height > constraints->max_height) {
+av_log(avctx, AV_LOG_ERROR, "Hardware does not support encoding at "
+   "size %dx%d (constraints: width %d-%d height %d-%d).\n",
+   ctx->surface_width, ctx->surface_height,
+   constraints->min_width,  constraints->max_width,
+   constraints->min_height, constraints->max_height);
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+*fmt = recon_format;
+err = 0;
+fail:
+av_hwframe_constraints_free(&constraints);
+return err;
+}
+
 int ff_hw_base_encode_init(AVCodecContext *avctx)
 {
 HWBaseEncodeContext *ctx = avctx->priv_data;
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index d363819329..7d40da039c 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -127,6 +127,16 @@ typedef struct HWBaseEncodeContext {
 // Desired B frame reference depth.
 int desired_b_depth;
 
+// The required size of surfaces.  This is probably the input
+// size (AVCodecContext.width|height) aligned up to whatever
+// block size is required by the codec.
+int surface_width;
+int surface_height;
+
+// The block size for slice calculations.
+int slice_block_width;
+int slice_block_height;
+
 // The hardware device context.
 AVBufferRef*device_ref;
 AVHWDeviceContext *device;
@@ -211,6 +221,8 @@ int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt);
 int ff_hw_base_init_gop_structure(AVCodecContext *avctx, uint32_t ref_l0, 
uint32_t ref_l1,
   int flags, int prediction_pre_only);
 
+int ff_hw_base_get_recon_format(AVCodecContext *avctx, const void *hwconfig, 
enum AVPixelFormat *fmt);
+
 int ff_hw_base_encode_init(AVCodecContext *avctx);
 
 int ff_hw_base_encode_close(AVCodecContext *avctx);
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6ab1b633ed..98b8c82da3 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1777,6 +1777,7 @@ static av_cold int 
vaapi_encode_init_tile_slice_structure(AVCodecContext *avctx,
 
 static av_cold int vaapi_encode_init_slice_structure(AVCodecContext *avctx)
 {
+HWBaseEncodeContext *base_ctx = avctx->pr

[FFmpeg-devel] [PATCH v9 08/13] avcodec/vaapi_encode: extract set_output_property to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 40 +
 libavcodec/hw_base_encode.h |  3 +++
 libavcodec/vaapi_encode.c   | 44 ++---
 3 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index dfe20c4e67..df820c2f83 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -491,6 +491,46 @@ fail:
 return err;
 }
 
+int ff_hw_base_encode_set_output_property(AVCodecContext *avctx,
+  HWBaseEncodePicture *pic,
+  AVPacket *pkt, int flag_no_delay)
+{
+HWBaseEncodeContext *ctx = avctx->priv_data;
+
+if (pic->type == PICTURE_TYPE_IDR)
+pkt->flags |= AV_PKT_FLAG_KEY;
+
+pkt->pts = pic->pts;
+pkt->duration = pic->duration;
+
+// for no-delay encoders this is handled in generic codec
+if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY &&
+avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
+pkt->opaque  = pic->opaque;
+pkt->opaque_ref  = pic->opaque_ref;
+pic->opaque_ref = NULL;
+}
+
+if (flag_no_delay) {
+pkt->dts = pkt->pts;
+return 0;
+}
+
+if (ctx->output_delay == 0) {
+pkt->dts = pkt->pts;
+} else if (pic->encode_order < ctx->decode_delay) {
+if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
+pkt->dts = INT64_MIN;
+else
+pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
+} else {
+pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
+(3 * ctx->output_delay + ctx->async_depth)];
+}
+
+return 0;
+}
+
 int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 HWBaseEncodeContext *ctx = avctx->priv_data;
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 07936bf9bb..d363819329 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -203,6 +203,9 @@ typedef struct HWBaseEncodeContext {
 AVPacket*tail_pkt;
 } HWBaseEncodeContext;
 
+int ff_hw_base_encode_set_output_property(AVCodecContext *avctx, 
HWBaseEncodePicture *pic,
+  AVPacket *pkt, int flag_no_delay);
+
 int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
 
 int ff_hw_base_init_gop_structure(AVCodecContext *avctx, uint32_t ref_l0, 
uint32_t ref_l1,
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 4db64b686b..6ab1b633ed 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -660,47 +660,6 @@ fail_at_end:
 return err;
 }
 
-static int vaapi_encode_set_output_property(AVCodecContext *avctx,
-HWBaseEncodePicture *pic,
-AVPacket *pkt)
-{
-HWBaseEncodeContext *base_ctx = avctx->priv_data;
-VAAPIEncodeContext   *ctx = avctx->priv_data;
-
-if (pic->type == PICTURE_TYPE_IDR)
-pkt->flags |= AV_PKT_FLAG_KEY;
-
-pkt->pts = pic->pts;
-pkt->duration = pic->duration;
-
-// for no-delay encoders this is handled in generic codec
-if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY &&
-avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
-pkt->opaque = pic->opaque;
-pkt->opaque_ref = pic->opaque_ref;
-pic->opaque_ref = NULL;
-}
-
-if (ctx->codec->flags & FLAG_TIMESTAMP_NO_DELAY) {
-pkt->dts = pkt->pts;
-return 0;
-}
-
-if (base_ctx->output_delay == 0) {
-pkt->dts = pkt->pts;
-} else if (pic->encode_order < base_ctx->decode_delay) {
-if (base_ctx->ts_ring[pic->encode_order] < INT64_MIN + 
base_ctx->dts_pts_diff)
-pkt->dts = INT64_MIN;
-else
-pkt->dts = base_ctx->ts_ring[pic->encode_order] - 
base_ctx->dts_pts_diff;
-} else {
-pkt->dts = base_ctx->ts_ring[(pic->encode_order - 
base_ctx->decode_delay) %
- (3 * base_ctx->output_delay + 
base_ctx->async_depth)];
-}
-
-return 0;
-}
-
 static int vaapi_encode_get_coded_buffer_size(AVCodecContext *avctx, 
VABufferID buf_id)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -852,7 +811,8 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Output read for pic %"PRId64"/%"PRId64".\n",
base_pic->display_order, base_pic->encode_order);
 
-vaapi_encode_set_output_property(avctx, (HWBaseEncodePicture*)pic, 
pkt_ptr);
+ff_hw_base_encode_set_output_property(avctx, 
(HWBaseEncodePicture*)base_pic, pkt_ptr,
+  ctx->codec->flags & 
FLAG_TIMESTAMP_NO_DELAY);
 
 end:
 ff_refstruct_unref(&pic->output_buffer_ref);
-- 
2.41.0.windows.1

_

[FFmpeg-devel] [PATCH v9 06/13] avcodec/vaapi_encode: extract the init and close function to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Related parameters such as device context, frame context are also moved
to base layer.

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.c | 49 ++
 libavcodec/hw_base_encode.h | 17 +++
 libavcodec/vaapi_encode.c   | 90 +++--
 libavcodec/vaapi_encode.h   | 10 
 libavcodec/vaapi_encode_av1.c   |  2 +-
 libavcodec/vaapi_encode_h264.c  |  2 +-
 libavcodec/vaapi_encode_h265.c  |  2 +-
 libavcodec/vaapi_encode_mjpeg.c |  6 ++-
 8 files changed, 102 insertions(+), 76 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index ec7178d2dc..f2b6ef4a3a 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -595,3 +595,52 @@ end:
 
 return 0;
 }
+
+int ff_hw_base_encode_init(AVCodecContext *avctx)
+{
+HWBaseEncodeContext *ctx = avctx->priv_data;
+
+ctx->frame = av_frame_alloc();
+if (!ctx->frame)
+return AVERROR(ENOMEM);
+
+if (!avctx->hw_frames_ctx) {
+av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is "
+   "required to associate the encoding device.\n");
+return AVERROR(EINVAL);
+}
+
+ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
+if (!ctx->input_frames_ref)
+return AVERROR(ENOMEM);
+
+ctx->input_frames = (AVHWFramesContext *)ctx->input_frames_ref->data;
+
+ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
+if (!ctx->device_ref)
+return AVERROR(ENOMEM);
+
+ctx->device = (AVHWDeviceContext *)ctx->device_ref->data;
+
+ctx->tail_pkt = av_packet_alloc();
+if (!ctx->tail_pkt)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+int ff_hw_base_encode_close(AVCodecContext *avctx)
+{
+HWBaseEncodeContext *ctx = avctx->priv_data;
+
+av_fifo_freep2(&ctx->encode_fifo);
+
+av_frame_free(&ctx->frame);
+av_packet_free(&ctx->tail_pkt);
+
+av_buffer_unref(&ctx->device_ref);
+av_buffer_unref(&ctx->input_frames_ref);
+av_buffer_unref(&ctx->recon_frames_ref);
+
+return 0;
+}
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 2667ae61cd..7e20f57b9c 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -19,6 +19,7 @@
 #ifndef AVCODEC_HW_BASE_ENCODE_H
 #define AVCODEC_HW_BASE_ENCODE_H
 
+#include "libavutil/hwcontext.h"
 #include "libavutil/fifo.h"
 
 #define MAX_DPB_SIZE 16
@@ -118,6 +119,18 @@ typedef struct HWBaseEncodeContext {
 // Hardware-specific hooks.
 const struct HWEncodePictureOperation *op;
 
+// The hardware device context.
+AVBufferRef*device_ref;
+AVHWDeviceContext *device;
+
+// The hardware frame context containing the input frames.
+AVBufferRef*input_frames_ref;
+AVHWFramesContext *input_frames;
+
+// The hardware frame context containing the reconstructed frames.
+AVBufferRef*recon_frames_ref;
+AVHWFramesContext *recon_frames;
+
 // Current encoding window, in display (input) order.
 HWBaseEncodePicture *pic_start, *pic_end;
 // The next picture to use as the previous reference picture in
@@ -184,6 +197,10 @@ typedef struct HWBaseEncodeContext {
 
 int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
 
+int ff_hw_base_encode_init(AVCodecContext *avctx);
+
+int ff_hw_base_encode_close(AVCodecContext *avctx);
+
 #define HW_BASE_ENCODE_COMMON_OPTIONS \
 { "async_depth", "Maximum processing parallelism. " \
   "Increase this to improve single channel performance.", \
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c4bb93c520..c3ab0fc192 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -314,7 +314,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface);
 
-err = av_hwframe_get_buffer(ctx->recon_frames_ref, base_pic->recon_image, 
0);
+err = av_hwframe_get_buffer(base_ctx->recon_frames_ref, 
base_pic->recon_image, 0);
 if (err < 0) {
 err = AVERROR(ENOMEM);
 goto fail;
@@ -996,9 +996,10 @@ static const VAEntrypoint 
vaapi_encode_entrypoints_low_power[] = {
 
 static av_cold int vaapi_encode_profile_entrypoint(AVCodecContext *avctx)
 {
-VAAPIEncodeContext  *ctx = avctx->priv_data;
-VAProfile*va_profiles= NULL;
-VAEntrypoint *va_entrypoints = NULL;
+HWBaseEncodeContext *base_ctx = avctx->priv_data;
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAProfile *va_profiles= NULL;
+VAEntrypoint  *va_entrypoints = NULL;
 VAStatus vas;
 const VAEntrypoint *usable_entrypoints;
 const VAAPIEncodeProfile *profile;
@@ -1021,10 +1022,10 @@ static av_cold int 
vaapi_encode_profile_entrypoint(AVCodecContext *avctx)
 usable_entrypoints = vaapi_encode_entrypoints_normal;
 }
 
-desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format);
+

[FFmpeg-devel] [PATCH v9 05/13] avcodec/vaapi_encode: move the dpb logic from VAAPI to base layer

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Move receive_packet function to base. This requires adding *alloc,
*issue, *output, *free as hardware callbacks. HWBaseEncodePicture is
introduced as the base layer structure. The related parameters in
VAAPIEncodeContext are also extracted to HWBaseEncodeContext. Then DPB
management logic can be fully extracted to base layer as-is.

Signed-off-by: Tong Wu 
---
 libavcodec/Makefile |   2 +-
 libavcodec/hw_base_encode.c | 597 
 libavcodec/hw_base_encode.h | 124 +
 libavcodec/vaapi_encode.c   | 793 +---
 libavcodec/vaapi_encode.h   | 102 +---
 libavcodec/vaapi_encode_av1.c   |  35 +-
 libavcodec/vaapi_encode_h264.c  |  84 ++--
 libavcodec/vaapi_encode_h265.c  |  53 ++-
 libavcodec/vaapi_encode_mjpeg.c |  13 +-
 libavcodec/vaapi_encode_mpeg2.c |  33 +-
 libavcodec/vaapi_encode_vp8.c   |  18 +-
 libavcodec/vaapi_encode_vp9.c   |  24 +-
 12 files changed, 988 insertions(+), 890 deletions(-)
 create mode 100644 libavcodec/hw_base_encode.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2443d2c6fd..998f6b7e12 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -165,7 +165,7 @@ OBJS-$(CONFIG_STARTCODE)   += startcode.o
 OBJS-$(CONFIG_TEXTUREDSP)  += texturedsp.o
 OBJS-$(CONFIG_TEXTUREDSPENC)   += texturedspenc.o
 OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
-OBJS-$(CONFIG_VAAPI_ENCODE)+= vaapi_encode.o
+OBJS-$(CONFIG_VAAPI_ENCODE)+= vaapi_encode.o hw_base_encode.o
 OBJS-$(CONFIG_AV1_AMF_ENCODER) += amfenc_av1.o
 OBJS-$(CONFIG_VC1DSP)  += vc1dsp.o
 OBJS-$(CONFIG_VIDEODSP)+= videodsp.o
diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
new file mode 100644
index 00..ec7178d2dc
--- /dev/null
+++ b/libavcodec/hw_base_encode.c
@@ -0,0 +1,597 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+
+#include "encode.h"
+#include "avcodec.h"
+#include "hw_base_encode.h"
+
+static void hw_base_encode_add_ref(AVCodecContext *avctx,
+   HWBaseEncodePicture *pic,
+   HWBaseEncodePicture *target,
+   int is_ref, int in_dpb, int prev)
+{
+int refs = 0;
+
+if (is_ref) {
+av_assert0(pic != target);
+av_assert0(pic->nb_refs[0] < MAX_PICTURE_REFERENCES &&
+   pic->nb_refs[1] < MAX_PICTURE_REFERENCES);
+if (target->display_order < pic->display_order)
+pic->refs[0][pic->nb_refs[0]++] = target;
+else
+pic->refs[1][pic->nb_refs[1]++] = target;
+++refs;
+}
+
+if (in_dpb) {
+av_assert0(pic->nb_dpb_pics < MAX_DPB_SIZE);
+pic->dpb[pic->nb_dpb_pics++] = target;
+++refs;
+}
+
+if (prev) {
+av_assert0(!pic->prev);
+pic->prev = target;
+++refs;
+}
+
+target->ref_count[0] += refs;
+target->ref_count[1] += refs;
+}
+
+static void hw_base_encode_remove_refs(AVCodecContext *avctx,
+   HWBaseEncodePicture *pic,
+   int level)
+{
+int i;
+
+if (pic->ref_removed[level])
+return;
+
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+--pic->refs[0][i]->ref_count[level];
+av_assert0(pic->refs[0][i]->ref_count[level] >= 0);
+}
+
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+--pic->refs[1][i]->ref_count[level];
+av_assert0(pic->refs[1][i]->ref_count[level] >= 0);
+}
+
+for (i = 0; i < pic->nb_dpb_pics; i++) {
+av_assert0(pic->dpb[i]);
+--pic->dpb[i]->ref_count[level];
+av_assert0(pic->dpb[i]->ref_count[level] >= 0);
+}
+
+av_assert0(pic->prev || pic->type == PICTURE_TYPE_IDR);
+if (pic->prev) {
+--pic->prev->ref_count[level];
+av_assert0(pic->prev->ref_count[level] >= 0);
+}
+
+pic->ref_removed[l

[FFmpeg-devel] [PATCH v9 04/13] avcodec/vaapi_encode: move pic->input_surface initialization to encode_alloc

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

When allocating the VAAPIEncodePicture, pic->input_surface can be
initialized right in the place. This movement simplifies the send_frame
logic and is the preparation for moving vaapi_encode_send_frame to the base 
layer.

Signed-off-by: Tong Wu 
---
 libavcodec/vaapi_encode.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2d22e4bd85..227cccae64 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -878,7 +878,8 @@ static int vaapi_encode_discard(AVCodecContext *avctx,
 return 0;
 }
 
-static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
+static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx,
+  const AVFrame *frame)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodePicture *pic;
@@ -895,7 +896,7 @@ static VAAPIEncodePicture 
*vaapi_encode_alloc(AVCodecContext *avctx)
 }
 }
 
-pic->input_surface = VA_INVALID_ID;
+pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
 pic->recon_surface = VA_INVALID_ID;
 pic->output_buffer = VA_INVALID_ID;
 
@@ -1332,7 +1333,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (err < 0)
 return err;
 
-pic = vaapi_encode_alloc(avctx);
+pic = vaapi_encode_alloc(avctx, frame);
 if (!pic)
 return AVERROR(ENOMEM);
 
@@ -1345,7 +1346,6 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
 pic->force_idr = 1;
 
-pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
 pic->pts = frame->pts;
 pic->duration = frame->duration;
 
-- 
2.41.0.windows.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 v9 03/13] avcodec/vaapi_encode: add picture type name to base

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.h | 5 +
 libavcodec/vaapi_encode.c   | 4 +---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 5272f2836d..a578db8c06 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -25,6 +25,11 @@
 #define MAX_ASYNC_DEPTH 64
 #define MAX_REFERENCE_LIST_NUM 2
 
+static inline const char *ff_hw_base_encode_get_pictype_name(const int type) {
+const char * const picture_type_name[] = { "IDR", "I", "P", "B" };
+return picture_type_name[type];
+}
+
 enum {
 PICTURE_TYPE_IDR = 0,
 PICTURE_TYPE_I   = 1,
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 9373512417..2d22e4bd85 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -38,8 +38,6 @@ const AVCodecHWConfigInternal *const 
ff_vaapi_encode_hw_configs[] = {
 NULL,
 };
 
-static const char * const picture_type_name[] = { "IDR", "I", "P", "B" };
-
 static int vaapi_encode_make_packed_header(AVCodecContext *avctx,
VAAPIEncodePicture *pic,
int type, char *data, size_t 
bit_len)
@@ -277,7 +275,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 
 av_log(avctx, AV_LOG_DEBUG, "Issuing encode for pic %"PRId64"/%"PRId64" "
"as type %s.\n", pic->display_order, pic->encode_order,
-   picture_type_name[pic->type]);
+   ff_hw_base_encode_get_pictype_name(pic->type));
 if (pic->nb_refs[0] == 0 && pic->nb_refs[1] == 0) {
 av_log(avctx, AV_LOG_DEBUG, "No reference pictures.\n");
 } else {
-- 
2.41.0.windows.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 v9 02/13] avcodec/vaapi_encode: add async_depth to common options

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.h | 10 +-
 libavcodec/vaapi_encode.c   | 13 -
 libavcodec/vaapi_encode.h   |  7 ---
 libavcodec/vaapi_encode_av1.c   |  1 +
 libavcodec/vaapi_encode_h264.c  |  1 +
 libavcodec/vaapi_encode_h265.c  |  1 +
 libavcodec/vaapi_encode_mjpeg.c |  1 +
 libavcodec/vaapi_encode_mpeg2.c |  1 +
 libavcodec/vaapi_encode_vp8.c   |  1 +
 libavcodec/vaapi_encode_vp9.c   |  1 +
 10 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index 1996179456..5272f2836d 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -50,7 +50,15 @@ enum {
 
 typedef struct HWBaseEncodeContext {
 const AVClass *class;
+
+// Max number of frame buffered in encoder.
+int async_depth;
 } HWBaseEncodeContext;
 
-#endif /* AVCODEC_HW_BASE_ENCODE_H */
+#define HW_BASE_ENCODE_COMMON_OPTIONS \
+{ "async_depth", "Maximum processing parallelism. " \
+  "Increase this to improve single channel performance.", \
+  OFFSET(common.base.async_depth), AV_OPT_TYPE_INT, \
+  { .i64 = 2 }, 1, MAX_ASYNC_DEPTH, FLAGS }
 
+#endif /* AVCODEC_HW_BASE_ENCODE_H */
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..9373512417 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -669,7 +669,8 @@ static int vaapi_encode_set_output_property(AVCodecContext 
*avctx,
 VAAPIEncodePicture *pic,
 AVPacket *pkt)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+HWBaseEncodeContext *base_ctx = avctx->priv_data;
+VAAPIEncodeContext   *ctx = avctx->priv_data;
 
 if (pic->type == PICTURE_TYPE_IDR)
 pkt->flags |= AV_PKT_FLAG_KEY;
@@ -699,7 +700,7 @@ static int vaapi_encode_set_output_property(AVCodecContext 
*avctx,
 pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
 } else {
 pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
-(3 * ctx->output_delay + ctx->async_depth)];
+(3 * ctx->output_delay + 
base_ctx->async_depth)];
 }
 
 return 0;
@@ -1320,6 +1321,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx,
 
 static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
 {
+HWBaseEncodeContext *base_ctx = avctx->priv_data;
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VAAPIEncodePicture *pic;
 int err;
@@ -1365,7 +1367,7 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, 
AVFrame *frame)
 ctx->dts_pts_diff = pic->pts - ctx->first_pts;
 if (ctx->output_delay > 0)
 ctx->ts_ring[ctx->input_order %
-(3 * ctx->output_delay + ctx->async_depth)] = pic->pts;
+(3 * ctx->output_delay + base_ctx->async_depth)] = 
pic->pts;
 
 pic->display_order = ctx->input_order;
 ++ctx->input_order;
@@ -2773,7 +2775,8 @@ static av_cold int 
vaapi_encode_create_recon_frames(AVCodecContext *avctx)
 
 av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 {
-VAAPIEncodeContext *ctx = avctx->priv_data;
+HWBaseEncodeContext *base_ctx = avctx->priv_data;
+VAAPIEncodeContext   *ctx = avctx->priv_data;
 AVVAAPIFramesContext *recon_hwctx = NULL;
 VAStatus vas;
 int err;
@@ -2966,7 +2969,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
 vas = vaSyncBuffer(ctx->hwctx->display, VA_INVALID_ID, 0);
 if (vas != VA_STATUS_ERROR_UNIMPLEMENTED) {
 ctx->has_sync_buffer_func = 1;
-ctx->encode_fifo = av_fifo_alloc2(ctx->async_depth,
+ctx->encode_fifo = av_fifo_alloc2(base_ctx->async_depth,
   sizeof(VAAPIEncodePicture *),
   0);
 if (!ctx->encode_fifo)
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index f5c9be8973..02410c72ec 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -374,8 +374,6 @@ typedef struct VAAPIEncodeContext {
 int has_sync_buffer_func;
 // Store buffered pic
 AVFifo  *encode_fifo;
-// Max number of frame buffered in encoder.
-int async_depth;
 
 /** Head data for current output pkt, used only for AV1. */
 //void  *header_data;
@@ -491,11 +489,6 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
   "Maximum B-frame reference depth", \
   OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \
   { .i64 = 1 }, 1, INT_MAX, FLAGS }, \
-{ "async_depth", "Maximum processing parallelism. " \
-  "Increase this to improve single channel performance. This option " \
-  "doesn't work if driver doesn't implement vaSyncBuffer function.", \
-  OFFSET(common.async_depth), A

[FFmpeg-devel] [PATCH v9 01/13] avcodec/vaapi_encode: introduce a base layer for vaapi encode

2024-05-20 Thread tong1 . wu-at-intel . com
From: Tong Wu 

Since VAAPI and future D3D12VA implementation may share some common parameters,
a base layer encode context is introduced as vaapi context's base.

Signed-off-by: Tong Wu 
---
 libavcodec/hw_base_encode.h | 56 +
 libavcodec/vaapi_encode.h   | 39 +-
 2 files changed, 63 insertions(+), 32 deletions(-)
 create mode 100644 libavcodec/hw_base_encode.h

diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
new file mode 100644
index 00..1996179456
--- /dev/null
+++ b/libavcodec/hw_base_encode.h
@@ -0,0 +1,56 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_HW_BASE_ENCODE_H
+#define AVCODEC_HW_BASE_ENCODE_H
+
+#define MAX_DPB_SIZE 16
+#define MAX_PICTURE_REFERENCES 2
+#define MAX_REORDER_DELAY 16
+#define MAX_ASYNC_DEPTH 64
+#define MAX_REFERENCE_LIST_NUM 2
+
+enum {
+PICTURE_TYPE_IDR = 0,
+PICTURE_TYPE_I   = 1,
+PICTURE_TYPE_P   = 2,
+PICTURE_TYPE_B   = 3,
+};
+
+enum {
+// Codec supports controlling the subdivision of pictures into slices.
+FLAG_SLICE_CONTROL = 1 << 0,
+// Codec only supports constant quality (no rate control).
+FLAG_CONSTANT_QUALITY_ONLY = 1 << 1,
+// Codec is intra-only.
+FLAG_INTRA_ONLY= 1 << 2,
+// Codec supports B-pictures.
+FLAG_B_PICTURES= 1 << 3,
+// Codec supports referencing B-pictures.
+FLAG_B_PICTURE_REFERENCES  = 1 << 4,
+// Codec supports non-IDR key pictures (that is, key pictures do
+// not necessarily empty the DPB).
+FLAG_NON_IDR_KEY_PICTURES  = 1 << 5,
+};
+
+typedef struct HWBaseEncodeContext {
+const AVClass *class;
+} HWBaseEncodeContext;
+
+#endif /* AVCODEC_HW_BASE_ENCODE_H */
+
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 0eed9691ca..f5c9be8973 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -33,34 +33,27 @@
 
 #include "avcodec.h"
 #include "hwconfig.h"
+#include "hw_base_encode.h"
 
 struct VAAPIEncodeType;
 struct VAAPIEncodePicture;
 
+// Codec output packet without timestamp delay, which means the
+// output packet has same PTS and DTS.
+#define FLAG_TIMESTAMP_NO_DELAY 1 << 6
+
 enum {
 MAX_CONFIG_ATTRIBUTES  = 4,
 MAX_GLOBAL_PARAMS  = 4,
-MAX_DPB_SIZE   = 16,
-MAX_PICTURE_REFERENCES = 2,
-MAX_REORDER_DELAY  = 16,
 MAX_PARAM_BUFFER_SIZE  = 1024,
 // A.4.1: table A.6 allows at most 22 tile rows for any level.
 MAX_TILE_ROWS  = 22,
 // A.4.1: table A.6 allows at most 20 tile columns for any level.
 MAX_TILE_COLS  = 20,
-MAX_ASYNC_DEPTH= 64,
-MAX_REFERENCE_LIST_NUM = 2,
 };
 
 extern const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[];
 
-enum {
-PICTURE_TYPE_IDR = 0,
-PICTURE_TYPE_I   = 1,
-PICTURE_TYPE_P   = 2,
-PICTURE_TYPE_B   = 3,
-};
-
 typedef struct VAAPIEncodeSlice {
 int index;
 int row_start;
@@ -193,7 +186,8 @@ typedef struct VAAPIEncodeRCMode {
 } VAAPIEncodeRCMode;
 
 typedef struct VAAPIEncodeContext {
-const AVClass *class;
+// Base context.
+HWBaseEncodeContext base;
 
 // Codec-specific hooks.
 const struct VAAPIEncodeType *codec;
@@ -397,25 +391,6 @@ typedef struct VAAPIEncodeContext {
 AVPacket*tail_pkt;
 } VAAPIEncodeContext;
 
-enum {
-// Codec supports controlling the subdivision of pictures into slices.
-FLAG_SLICE_CONTROL = 1 << 0,
-// Codec only supports constant quality (no rate control).
-FLAG_CONSTANT_QUALITY_ONLY = 1 << 1,
-// Codec is intra-only.
-FLAG_INTRA_ONLY= 1 << 2,
-// Codec supports B-pictures.
-FLAG_B_PICTURES= 1 << 3,
-// Codec supports referencing B-pictures.
-FLAG_B_PICTURE_REFERENCES  = 1 << 4,
-// Codec supports non-IDR key pictures (that is, key pictures do
-// not necessarily empty the DPB).
-FLAG_NON_IDR_KEY_PICTURES  = 1 << 5,
-// Codec output packet without timestamp delay, which means the
-// output packet has same PTS and DTS.
-FLAG_TIMESTAMP_NO_DELAY= 1 << 6,
-};
-
 typedef struct VAAPIEncodeType {
 // List of supported profiles and correspond

Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_drm: Check ioctl in drm_map_frame() for failure

2024-05-20 Thread Rémi Denis-Courmont


Le 20 mai 2024 12:33:41 GMT+03:00, Andreas Rheinhardt 
 a écrit :
>Michael Niedermayer:
>> Fixes: CID1583742 Unchecked return value
>> 
>> Sponsored-by: Sovereign Tech Fund
>> Signed-off-by: Michael Niedermayer 
>> ---
>>  libavutil/hwcontext_drm.c | 5 -
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c
>> index 0847db09a08..e080c0597b8 100644
>> --- a/libavutil/hwcontext_drm.c
>> +++ b/libavutil/hwcontext_drm.c
>> @@ -166,7 +166,10 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
>>  #if HAVE_LINUX_DMA_BUF_H
>>  /* We're not checking for errors here because the kernel may not
>>   * support the ioctl, in which case its okay to carry on */
>> -ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
>> +if (ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start) == 
>> -1) {
>> +err = AVERROR(errno);
>> +goto fail;
>> +}
>>  #endif
>>  }
>>  map->nb_regions = i;
>
>Did you read the comment above the code?

It looks like this should check the errno value rather than flatly ignoring or 
not ignoring the error, not that I'd know.
___
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_drm: Check ioctl in drm_map_frame() for failure

2024-05-20 Thread Michael Niedermayer
On Mon, May 20, 2024 at 11:33:41AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: CID1583742 Unchecked return value
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavutil/hwcontext_drm.c | 5 -
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c
> > index 0847db09a08..e080c0597b8 100644
> > --- a/libavutil/hwcontext_drm.c
> > +++ b/libavutil/hwcontext_drm.c
> > @@ -166,7 +166,10 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
> >  #if HAVE_LINUX_DMA_BUF_H
> >  /* We're not checking for errors here because the kernel may not
> >   * support the ioctl, in which case its okay to carry on */
> > -ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
> > +if (ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start) == 
> > -1) {
> > +err = AVERROR(errno);
> > +goto fail;
> > +}
> >  #endif
> >  }
> >  map->nb_regions = i;
> 
> Did you read the comment above the code?

Apparently not

patch droped, will mark this as intentional

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety -- Benjamin Franklin


signature.asc
Description: PGP signature
___
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 12/18] avcodec/vvcdec: inter, wait reference with a diffrent resolution

2024-05-20 Thread Nuo Mi
On Sun, May 19, 2024 at 11:21 PM Jean-Baptiste Kempf 
wrote:

> Careful about the typo on "different" on the title of the patch.
>
Changed locally.
Thank you, jb

>
> On Sun, 19 May 2024, at 13:27, Nuo Mi wrote:
> > For RPR, the current frame may reference a frame with a different
> resolution.
> > Therefore, we need to consider frame scaling when we wait for reference
> pixels.
> > ---
> >  libavcodec/vvc/dec.c|  5 +
> >  libavcodec/vvc/dec.h| 17 +
> >  libavcodec/vvc/refs.c   | 39 +++
> >  libavcodec/vvc/thread.c | 10 +++---
> >  4 files changed, 68 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
> > index 3325133efb..584c7b219f 100644
> > --- a/libavcodec/vvc/dec.c
> > +++ b/libavcodec/vvc/dec.c
> > @@ -573,6 +573,11 @@ static int ref_frame(VVCFrame *dst, const VVCFrame
> *src)
> >
> >  dst->poc = src->poc;
> >  dst->ctb_count = src->ctb_count;
> > +
> > +dst->scaling_win = src->scaling_win;
> > +dst->ref_width   = src->ref_width;
> > +dst->ref_height  = src->ref_height;
> > +
> >  dst->flags = src->flags;
> >  dst->sequence = src->sequence;
> >
> > diff --git a/libavcodec/vvc/dec.h b/libavcodec/vvc/dec.h
> > index 6f14cc1860..1e0b76f283 100644
> > --- a/libavcodec/vvc/dec.h
> > +++ b/libavcodec/vvc/dec.h
> > @@ -46,6 +46,10 @@ typedef struct VVCRefPic {
> >  struct VVCFrame *ref;
> >  int poc;
> >  int is_lt;  // is long term reference
> > +
> > +// for RPR
> > +int is_scaled;  ///< RprConstraintsActiveFlag
> > +int scale[2];   ///< RefPicScale[]
> >  } VVCRefPic;
> >
> >  typedef struct RefPicList {
> > @@ -57,6 +61,13 @@ typedef struct RefPicListTab {
> >  RefPicList refPicList[2];
> >  } RefPicListTab;
> >
> > +typedef struct VVCWindow {
> > +int16_t left_offset;
> > +int16_t right_offset;
> > +int16_t top_offset;
> > +int16_t bottom_offset;
> > +} VVCWindow;
> > +
> >  typedef struct VVCFrame {
> >  struct AVFrame *frame;
> >
> > @@ -71,6 +82,12 @@ typedef struct VVCFrame {
> >
> >  int poc;
> >
> > +//for RPR
> > +VVCWindow scaling_win;  ///<
> > pps_scaling_win_left_offset * SubWithC,  pps_scaling_win_right_offset
> > * SubWithC,
> > +///<
> > pps_scaling_win_top_offset  * SubHeigtC, pps_scaling_win_bottom_offset
> > * SubHiehgtC
> > +int ref_width;  ///<
> > CurrPicScalWinWidthL
> > +int ref_height; ///<
> > CurrPicScalWinHeightL
> > +
> >  struct VVCFrame *collocated_ref;
> >
> >  struct FrameProgress *progress; ///< RefStruct reference
> > diff --git a/libavcodec/vvc/refs.c b/libavcodec/vvc/refs.c
> > index 954db4a8c8..fb42963034 100644
> > --- a/libavcodec/vvc/refs.c
> > +++ b/libavcodec/vvc/refs.c
> > @@ -114,10 +114,12 @@ static FrameProgress *alloc_progress(void)
> >
> >  static VVCFrame *alloc_frame(VVCContext *s, VVCFrameContext *fc)
> >  {
> > +const VVCSPS *sps = fc->ps.sps;
> >  const VVCPPS *pps = fc->ps.pps;
> >  for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
> >  int ret;
> >  VVCFrame *frame = &fc->DPB[i];
> > +VVCWindow *win = &frame->scaling_win;
> >  if (frame->frame->buf[0])
> >  continue;
> >
> > @@ -144,6 +146,13 @@ static VVCFrame *alloc_frame(VVCContext *s,
> > VVCFrameContext *fc)
> >  for (int j = 0; j < frame->ctb_count; j++)
> >  frame->rpl_tab[j] = frame->rpl;
> >
> > +win->left_offset   = pps->r->pps_scaling_win_left_offset   <<
> > sps->hshift[CHROMA];
> > +win->right_offset  = pps->r->pps_scaling_win_right_offset  <<
> > sps->hshift[CHROMA];
> > +win->top_offset= pps->r->pps_scaling_win_top_offset<<
> > sps->vshift[CHROMA];
> > +win->bottom_offset = pps->r->pps_scaling_win_bottom_offset <<
> > sps->vshift[CHROMA];
> > +frame->ref_width   = pps->r->pps_pic_width_in_luma_samples  -
> > win->left_offset   - win->right_offset;
> > +frame->ref_height  = pps->r->pps_pic_height_in_luma_samples -
> > win->bottom_offset - win->top_offset;
> > +
> >  frame->progress = alloc_progress();
> >  if (!frame->progress)
> >  goto fail;
> > @@ -353,6 +362,24 @@ static VVCFrame *generate_missing_ref(VVCContext
> > *s, VVCFrameContext *fc, int po
> >  return frame;
> >  }
> >
> > +#define CHECK_MAX(d) (frame->ref_##d *
> > frame->sps->r->sps_pic_##d##_max_in_luma_samples >= ref->ref_##d *
> > (frame->pps->r->pps_pic_##d##_in_luma_samples - max))
> > +#define CHECK_SAMPLES(d) (frame->pps->r->pps_pic_##d##_in_luma_samples
> > == ref->pps->r->pps_pic_##d##_in_luma_samples)
> > +static int check_candidate_ref(const VVCFrame *frame, const VVCRefPic
> > *refp)
> > +{
> > +const VVCFrame *ref = refp->ref;
> > +
> > +if (refp->is_sc

Re: [FFmpeg-devel] [PATCH v4 1/2][GSoC 2024] libavcodec/x86/vvc: Add AVX2 DMVR SAD functions for VVC

2024-05-20 Thread Ronald S. Bultje
Hi,

This is mostly good, the following is tiny nitpicks.

On Sun, May 19, 2024 at 8:46 PM Stone Chen  wrote:

> +%macro INIT_OFFSET 6 ; src1, src2, dxq, dyq, off1, off2
>

The macro is only used once, so you could inline it in the calling function.

>
> +imul%5, 128
> +imul%6, 128
>

I believe shl is typically preferred over imul for powers of two.


> +add %5, 2
> +add %6, 2
>

And these can be integrated as a constant offset in the lea below (lea %1,
[%1 + %5 * 2 + 2 * 2], same for %2).


> +add %5, %3
> +sub %6, %3
> +
> +lea %1, [%1 + %5 * 2]
> +lea %2, [%2 + %6 * 2]

[..]

> +cglobal vvc_sad, 6, 11, 5, src1, src2, dx, dy, block_w, block_h, off1,
> off2, row_idx, dx2, dy2
> +movsxd   dx2q, dxd
> +movsxd   dy2q, dyd
>

If you change the argument type from int to intptr_t, this is not necessary
anymore.


> +vvc_sad_16_128:
> +.loop_height:
> +mov off1q, src1q
> +mov off2q, src2q
> +mov  row_idxd, block_wd
> +sar  row_idxd, 4
>

You could right-shift block_wd by 4 outside the loop (before .loop_height).

Ronald
___
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] Samples with invalid permissions

2024-05-20 Thread Thilo Borgmann via ffmpeg-devel




Hi,

There are a couple of files in samples.ffmpeg.org with invalid 
permissions, rsync is not able to read those:



/V-codecs/UCOD/noextradata/CLV1_tony.mov
/V-codecs/UCOD/noextradata/freddie2.mov
/V-codecs/UCOD/noextradata/pittc.mov
/V-codecs/UCOD/noextradata/smilla_cv.mov
/ffmpeg-bugs/trac/ticket4729/hap2_fuzz.mov
/ffmpeg-bugs/trac/ticket5406/crushed_1.snm
/ffmpeg-bugs/trac/ticket5407/512kbps.wv
/ffmpeg-bugs/trac/ticket5407/512kbps.wvc
/ffmpeg-bugs/trac/ticket5410/ela2.m4b
/ffmpeg-bugs/trac/ticket5410/intro_a.m4b
/ffmpeg-bugs/trac/ticket6102/error_reading_header_ticket_6102_first100.mp4 > 
/ffmpeg-bugs/trac/ticket6102/error_reading_header_ticket_6102_last100.mp4


the above are now free to read.



/ffmpeg-bugs/trac/ticket5925/non-work-spanned.zip
/ffmpeg-bugs/trac/ticket6400/tooshort.avi
/ffmpeg-bugs/trac/ticket6675/Cineform_Bottom_8_Pixel_Distort_1080_YUV.mov
/ffmpeg-bugs/trac/ticket6765/Canon-C200-Raw.CRM


These are in the size of GB's.
If someone really needs them, send us a mail according to
http://samples.ffmpeg.org/00-README

-Thilo
___
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] avfilter/vf_signalstats: Use av_dict_set_int() where appropriate

2024-05-20 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/vf_signalstats.c | 80 ++--
>  1 file changed, 40 insertions(+), 40 deletions(-)
> 
> diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c
> index c2358c66cb..960899596f 100644
> --- a/libavfilter/vf_signalstats.c
> +++ b/libavfilter/vf_signalstats.c
> @@ -720,40 +720,40 @@ static int filter_frame8(AVFilterLink *link, AVFrame 
> *in)
>  av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0);   \
>  } while (0)
>  
> -SET_META("YMIN","%d", miny);
> -SET_META("YLOW","%d", lowy);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YMIN", miny, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YLOW", lowy, 0);
>  SET_META("YAVG","%g", 1.0 * toty / s->fs);
> -SET_META("YHIGH",   "%d", highy);
> -SET_META("YMAX","%d", maxy);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YHIGH", highy, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YMAX", maxy, 0);
>  
> -SET_META("UMIN","%d", minu);
> -SET_META("ULOW","%d", lowu);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UMIN", minu, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.ULOW", lowu, 0);
>  SET_META("UAVG","%g", 1.0 * totu / s->cfs);
> -SET_META("UHIGH",   "%d", highu);
> -SET_META("UMAX","%d", maxu);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UHIGH", highu, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UMAX", maxu, 0);
>  
> -SET_META("VMIN","%d", minv);
> -SET_META("VLOW","%d", lowv);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VMIN", minv, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VLOW", lowv, 0);
>  SET_META("VAVG","%g", 1.0 * totv / s->cfs);
> -SET_META("VHIGH",   "%d", highv);
> -SET_META("VMAX","%d", maxv);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VHIGH", highv, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VMAX", maxv, 0);
>  
> -SET_META("SATMIN",  "%d", minsat);
> -SET_META("SATLOW",  "%d", lowsat);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.SATMIN", minsat, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.SATLOW", lowsat, 0);
>  SET_META("SATAVG",  "%g", 1.0 * totsat / s->cfs);
> -SET_META("SATHIGH", "%d", highsat);
> -SET_META("SATMAX",  "%d", maxsat);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.SATHIGH", highsat, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.SATMAX", maxsat, 0);
>  
> -SET_META("HUEMED",  "%d", medhue);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.HUEMED", medhue, 0);
>  SET_META("HUEAVG",  "%g", 1.0 * tothue / s->cfs);
>  
>  SET_META("YDIF","%g", 1.0 * dify / s->fs);
>  SET_META("UDIF","%g", 1.0 * difu / s->cfs);
>  SET_META("VDIF","%g", 1.0 * difv / s->cfs);
>  
> -SET_META("YBITDEPTH", "%d", compute_bit_depth(masky));
> -SET_META("UBITDEPTH", "%d", compute_bit_depth(masku));
> -SET_META("VBITDEPTH", "%d", compute_bit_depth(maskv));
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YBITDEPTH", 
> compute_bit_depth(masky), 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UBITDEPTH", 
> compute_bit_depth(masku), 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VBITDEPTH", 
> compute_bit_depth(maskv), 0);
>  
>  for (fil = 0; fil < FILT_NUMB; fil ++) {
>  if (s->filters & 1< @@ -946,40 +946,40 @@ static int filter_frame16(AVFilterLink *link, AVFrame 
> *in)
>  av_frame_free(&s->frame_prev);
>  s->frame_prev = av_frame_clone(in);
>  
> -SET_META("YMIN","%d", miny);
> -SET_META("YLOW","%d", lowy);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YMIN", miny, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YLOW", lowy, 0);
>  SET_META("YAVG","%g", 1.0 * toty / s->fs);
> -SET_META("YHIGH",   "%d", highy);
> -SET_META("YMAX","%d", maxy);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YHIGH", highy, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.YMAX", maxy, 0);
>  
> -SET_META("UMIN","%d", minu);
> -SET_META("ULOW","%d", lowu);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UMIN", minu, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.ULOW", lowu, 0);
>  SET_META("UAVG","%g", 1.0 * totu / s->cfs);
> -SET_META("UHIGH",   "%d", highu);
> -SET_META("UMAX","%d", maxu);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UHIGH", highu, 0);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.UMAX", maxu, 0);
>  
> -SET_META("VMIN","%d", minv);
> -SET_META("VLOW","%d", lowv);
> +av_dict_set_int(&out->metadata, "lavfi.signalstats.VMIN", minv, 0);
> +av_dict_set_int(&out->

Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_drm: Check ioctl in drm_map_frame() for failure

2024-05-20 Thread Andreas Rheinhardt
Michael Niedermayer:
> Fixes: CID1583742 Unchecked return value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavutil/hwcontext_drm.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c
> index 0847db09a08..e080c0597b8 100644
> --- a/libavutil/hwcontext_drm.c
> +++ b/libavutil/hwcontext_drm.c
> @@ -166,7 +166,10 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
>  #if HAVE_LINUX_DMA_BUF_H
>  /* We're not checking for errors here because the kernel may not
>   * support the ioctl, in which case its okay to carry on */
> -ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
> +if (ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start) == 
> -1) {
> +err = AVERROR(errno);
> +goto fail;
> +}
>  #endif
>  }
>  map->nb_regions = i;

Did you read the comment above the code?

- Andreas

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