[FFmpeg-devel] [PATCH 2/2] lavc/qsvenc: respect user's setting for keyframes

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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


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

How about changing the unit to qsv_skip_frame too ? 

Thanks
Haihao


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

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

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


Re: [FFmpeg-devel] [PATCH v2] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-23 Thread Zhao Zhili


> On May 24, 2024, at 02:41, epira...@gmail.com wrote:
> 
> 
> On 23 May 2024, at 18:05, Zhao Zhili wrote:
> 
>>> On May 21, 2024, at 09:56, Gnattu OC via ffmpeg-devel 
>>>  wrote:
>>> 
 
 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,
 + 
 ,
 + 
 );
 +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, 
 );
 -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.
>> 
>> I will just remove the log message and apply the patch this week if no 
>> objection.
>> 
> 
> I will do some more tests, if you want apply with the log message removed and 
> I will do a follow up patch
> if I find another solution.

OK, then I can wait. Please notify when it’s ready.

> 
>>> 
 +
 +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 1/2] lavc/qsvdec: update HDR side data on output AVFrame for AV1 decoding

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

Will apply,

-Haihao


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

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


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

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

patchset LGTM, will apply

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH v5 0/4] Explain what "context" means

2024-05-23 Thread Michael Niedermayer
On Thu, May 23, 2024 at 09:00:39PM +0100, Andrew Sayers wrote:
> NOTE: this patchset depends on [1], and should not be applied before that.
> 
> I think it's important to guide readers between parts of FFmpeg, because
> learning how the pieces of the puzzle fit together is a big part of the
> newbie experience.  So this patchset replaces the "@ref Context for foo"
> statements in public structs with "@see" blocks, giving us a hook we can
> hang more links on in future.
> 
> That said, there's a rule against internal links from private structs,
> so I've removed the @ref's from them.  By the way, is this rule written
> somewhere?  If not, where would be a good place to write it?
> And either way, it would be good to link to this as part of [2].
> 
> Previous patches had to change the language for many structs, but "@see" 
> blocks
> avoid the need to include those changes in this patchset.  Rather than waste
> that work, I've temporarily moved those changes to the final patch in this 
> set.
> My feelings about that last patch aren't strong, but I guess I'll propose them
> in a separate thread unless anyone wants them here or chucked altogether.
> 
> 
> I've rewritten AVOptions and AVClass based on feedback.  The new version
> reflects a hypothetical that's been going round my head all week...
> 
> Imagine you wanted to write a system that nudged people to try new codecs.
> It might say e.g. "you seem to be using H.264, would you like to try H.265?"
> Implementing that would probably involve a struct like:
> 
> struct AVOldNew {
>   AVClass* old;
>   AVClass* new;
> };

AVClass would describe the internal decoder structures. This would not be
correct at all in this example.
Thats like handing a man 2 CAD documents about 2 engines of 2 cars

If you wanted to suggest to get a tesla instead of a ford. One would have to
describe the 2 cars and their differences
thats 2 AVCodecDescriptor maybe

thx

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

It is a danger to trust the dream we wish for rather than
the science we have, -- Dr. Kenneth Brown


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 7/7] avcodec/tests/bitstream_template: Make it clear that the return is intentionally not checked

2024-05-23 Thread Michael Niedermayer
On Thu, May 23, 2024 at 10:22:56AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Helps: CID1518967 Unchecked return value
> > Helps: CID1518968 Unchecked return value
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/tests/bitstream_template.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/tests/bitstream_template.c 
> > b/libavcodec/tests/bitstream_template.c
> > index ef59845154d..d8cf980bee1 100644
> > --- a/libavcodec/tests/bitstream_template.c
> > +++ b/libavcodec/tests/bitstream_template.c
> > @@ -74,7 +74,7 @@ int main(int argc, char **argv)
> >  for (unsigned i = 0; i < SIZE; i++)
> >  buf[i] = av_lfg_get();
> >  
> > -bits_init8   (, buf, SIZE);
> > +(void)bits_init8   (, buf, SIZE);
> >  init_put_bits(, dst, SIZE);
> >  
> >  /* use a random sequence of bitreading operations to transfer data
> 
> Test tools should actually test.

will replace with a assert0() then

thx

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

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


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


[FFmpeg-devel] [PATCH] avformat/demux: Remove dead stores

2024-05-23 Thread Michael Niedermayer
Fixes: CID1473512 Unused value
Fixes: CID1529228 Unused value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavformat/demux.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index ecefe7e0a74..d0a5a39d052 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2998,9 +2998,6 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 
 av_opt_set_int(ic, "skip_clear", 0, AV_OPT_SEARCH_CHILDREN);
 
-if (ret >= 0 && ic->nb_streams)
-/* We could not have all the codec parameters before EOF. */
-ret = -1;
 for (unsigned i = 0; i < ic->nb_streams; i++) {
 AVStream *const st  = ic->streams[i];
 FFStream *const sti = ffstream(st);
@@ -3022,8 +3019,6 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
"Could not find codec parameters for stream %d (%s): %s\n"
"Consider increasing the value for the 'analyzeduration' 
(%"PRId64") and 'probesize' (%"PRId64") options\n",
i, buf, errmsg, ic->max_analyze_duration, ic->probesize);
-} else {
-ret = 0;
 }
 }
 
-- 
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".


Re: [FFmpeg-devel] [PATCH v3 1/2] lavu/dovi_meta - add fields for ext_mapping_idc

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


> On May 23, 2024, at 4:03 AM, Niklas Haas  wrote:
> 
> On Wed, 22 May 2024 15:50:43 + Cosmin Stejerean via ffmpeg-devel 
>  wrote:
>> From: Cosmin Stejerean 
>> 
>> ---
>> libavutil/dovi_meta.h | 2 ++
>> libavutil/version.h   | 2 +-
>> 2 files changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
>> index e10332f8d7..e168075a24 100644
>> --- a/libavutil/dovi_meta.h
>> +++ b/libavutil/dovi_meta.h
>> @@ -91,6 +91,8 @@ typedef struct AVDOVIRpuDataHeader {
>> uint8_t spatial_resampling_filter_flag;
>> uint8_t el_spatial_resampling_filter_flag;
>> uint8_t disable_residual_flag;
>> +uint8_t ext_mapping_idc_0_4; /* extended base layer inverse mapping 
>> indicator */
>> +uint8_t ext_mapping_idc_5_7; /* reserved */
>> } AVDOVIRpuDataHeader;
> 
> What value ranges have you seen for this indicator? Is it possible that
> some values would extend the RPU in other ways, adding more bits that we
> need to parse?

So far I've only seen two sets of values. 

The samples from the iPhone:

ext_mapping_idc[4:0] = 0
ext_mapping_idc[7:5] = 0

The samples from Xiaomi and Oppo:

ext_mapping_idc[4:0] = 1
ext_mapping_idc[7:5] = 4

I don't have any additional information on what the possible range of values 
could be so far.
As far as I can tell it has no impact on the size of the subsequent fields, at 
least for what I've encountered so far.


> 
> Maybe we should enforce this to be a well-known value just to be on the
> safe side, until we receive public documentation on its purpose.
> 

I think to avoid being brittle we should allow the entire range of values for 
now until we know better, and just ensure it roundtrips correctly (which I've 
verified by running the validator on the 10.4 output transcoded from 8.4 input).

Once we track down more info we can try to add more validation on top of it.

- 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 v5 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-05-23 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 119 
 1 file changed, 32 insertions(+), 87 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 8229438373..8962be25a1 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -39,72 +39,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*), 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = [wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*), 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = [wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)>key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -121,10 +58,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -161,25 +96,30 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 void *value;
 uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, );
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, );
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_get(ctx->color_ht, , _pos))
+color_idx = pos - prev_pos;
+av_hashtable_set(ctx->color_ht, , );
+
 if (pos >= LOOKBACK_WORDS) {
 uint32_t old_pos = pos - LOOKBACK_WORDS;
-uint32_t old_color = AV_RL32(ctx->tex_data + old_pos * 4);
-ht_delete(ctx->color_lookback_ht, ctx->crc_ctx, old_color, 
old_pos);
+if (av_hashtable_get(ctx->color_ht, 

[FFmpeg-devel] [PATCH v5 1/2] lavu/hashtable: create generic robin hood hash table

2024-05-23 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  91 +
 libavutil/tests/hashtable.c | 108 
 4 files changed, 393 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6e6fa8d800..8c7b4452b4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -252,6 +253,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * 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 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep();
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep();
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep();
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 0, key, ctx->key_size) % ctx->max_entries;
+}
+
+int av_hashtable_get(const struct AVHashtableContext *ctx, const void *key, 
void 

[FFmpeg-devel] [PATCH v5 4/4] all: Rewrite documentation for contexts

2024-05-23 Thread Andrew Sayers
Make their documentation more readable and similar to each other,
(hopefully) without changing the meaning.
---
 libavcodec/aac/aacdec.h  |  2 +-
 libavcodec/aacenc.h  |  2 +-
 libavcodec/ac3enc.h  |  2 +-
 libavcodec/amfenc.h  |  2 +-
 libavcodec/atrac.h   |  2 +-
 libavcodec/avcodec.h |  3 ++-
 libavcodec/bsf.h |  2 +-
 libavcodec/cbs.h |  2 +-
 libavcodec/d3d11va.h |  3 +--
 libavcodec/mediacodec.h  |  4 ++--
 libavcodec/pthread_frame.c   |  4 ++--
 libavcodec/qsv.h |  6 --
 libavcodec/sbr.h |  2 +-
 libavcodec/vdpau.h   |  5 +++--
 libavcodec/videotoolbox.h|  5 +++--
 libavfilter/avfilter.h   |  2 +-
 libavformat/avformat.h   |  3 ++-
 libavformat/avio.h   |  3 ++-
 libavutil/audio_fifo.h   |  2 +-
 libavutil/hwcontext.h| 21 -
 libavutil/hwcontext_cuda.h   |  2 +-
 libavutil/hwcontext_d3d11va.h|  4 ++--
 libavutil/hwcontext_d3d12va.h|  6 +++---
 libavutil/hwcontext_drm.h|  2 +-
 libavutil/hwcontext_dxva2.h  |  4 ++--
 libavutil/hwcontext_mediacodec.h |  2 +-
 libavutil/hwcontext_opencl.h |  4 ++--
 libavutil/hwcontext_qsv.h|  4 ++--
 libavutil/hwcontext_vaapi.h  |  4 ++--
 libavutil/hwcontext_vdpau.h  |  2 +-
 libavutil/hwcontext_vulkan.h |  5 +++--
 libavutil/lfg.h  |  3 ++-
 32 files changed, 65 insertions(+), 54 deletions(-)

diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h
index eed53c6c96..87a834797d 100644
--- a/libavcodec/aac/aacdec.h
+++ b/libavcodec/aac/aacdec.h
@@ -253,7 +253,7 @@ typedef struct AACDecDSP {
 } AACDecDSP;
 
 /**
- * main AAC decoding context
+ * Context for decoding AAC
  */
 struct AACDecContext {
 const struct AVClass  *class;
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index d07960620e..3e710c7fac 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -207,7 +207,7 @@ typedef struct AACPCEInfo {
 } AACPCEInfo;
 
 /**
- * AAC encoder context
+ * Context for encoding AAC
  */
 typedef struct AACEncContext {
 AVClass *av_class;
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 5e98ad188b..e5abe0a856 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -153,7 +153,7 @@ typedef struct AC3Block {
 struct PutBitContext;
 
 /**
- * AC-3 encoder private context.
+ * Private context for encoding AC-3
  */
 typedef struct AC3EncodeContext {
 AVClass *av_class;  ///< AVClass used for AVOption
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..184897beeb 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -43,7 +43,7 @@ typedef struct AmfTraceWriter {
 } AmfTraceWriter;
 
 /**
-* AMF encoder context
+* Context for encoding AMF
 */
 
 typedef struct AmfContext {
diff --git a/libavcodec/atrac.h b/libavcodec/atrac.h
index 05208bbee6..e760f0384d 100644
--- a/libavcodec/atrac.h
+++ b/libavcodec/atrac.h
@@ -39,7 +39,7 @@ typedef struct AtracGainInfo {
 } AtracGainInfo;
 
 /**
- *  Gain compensation context structure.
+ *  Context for gain compensation
  */
 typedef struct AtracGCContext {
 float   gain_tab1[16];  ///< gain compensation level table
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index abc00ab394..2fed4757ed 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -430,7 +430,8 @@ typedef struct RcOverride{
 #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
 
 /**
- * main external API structure.
+ * Context for an encode or decode session
+ *
  * New fields can be added to the end with minor version bumps.
  * Removal, reordering and changes to existing fields require a major
  * version bump.
diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h
index ee5fdd48d2..fadcfc5d47 100644
--- a/libavcodec/bsf.h
+++ b/libavcodec/bsf.h
@@ -56,7 +56,7 @@
  */
 
 /**
- * The bitstream filter state.
+ * Context for bitstream filtering
  *
  * This struct must be allocated with av_bsf_alloc() and freed with
  * av_bsf_free().
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index d479b1ac2d..c074dd11ec 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -214,7 +214,7 @@ typedef void (*CBSTraceWriteCallback)(void *trace_context,
   int64_t value);
 
 /**
- * Context structure for coded bitstream operations.
+ * Context for coded bitstream operations
  */
 typedef struct CodedBitstreamContext {
 /**
diff --git a/libavcodec/d3d11va.h b/libavcodec/d3d11va.h
index 686974b083..5ffee2b3be 100644
--- a/libavcodec/d3d11va.h
+++ b/libavcodec/d3d11va.h
@@ -46,8 +46,7 @@
  */
 
 /**
- * This structure is used to provides the necessary configurations and data
- * to the Direct3D11 FFmpeg HWAccel implementation.
+ * Context for the Direct3D11 FFmpeg HWAccel implementation
  *
  * The application must make it available as 

[FFmpeg-devel] [PATCH v5 3/4] all: Link to "context" from all public contexts with documentation

2024-05-23 Thread Andrew Sayers
The goal of putting these links in "@see" blocks is to provide hooks
for future developers to add links to other useful parts of the codebase.
---
 libavcodec/avcodec.h | 3 +++
 libavcodec/bsf.h | 3 +++
 libavcodec/d3d11va.h | 3 +++
 libavcodec/mediacodec.h  | 2 ++
 libavcodec/qsv.h | 3 +++
 libavcodec/vdpau.h   | 3 +++
 libavcodec/videotoolbox.h| 3 +++
 libavfilter/avfilter.h   | 7 ++-
 libavformat/avformat.h   | 3 +++
 libavformat/avio.h   | 3 +++
 libavutil/audio_fifo.h   | 3 +++
 libavutil/hwcontext.h| 6 ++
 libavutil/hwcontext_cuda.h   | 3 +++
 libavutil/hwcontext_d3d11va.h| 6 ++
 libavutil/hwcontext_d3d12va.h| 6 ++
 libavutil/hwcontext_drm.h| 3 +++
 libavutil/hwcontext_dxva2.h  | 6 ++
 libavutil/hwcontext_mediacodec.h | 3 +++
 libavutil/hwcontext_opencl.h | 6 ++
 libavutil/hwcontext_qsv.h| 6 ++
 libavutil/hwcontext_vaapi.h  | 6 ++
 libavutil/hwcontext_vdpau.h  | 3 +++
 libavutil/hwcontext_vulkan.h | 6 ++
 libavutil/lfg.h  | 3 +++
 24 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2da63c87ea..abc00ab394 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -441,6 +441,9 @@ typedef struct RcOverride{
  * The AVOption/command line parameter names differ in some cases from the C
  * structure field names for historic reasons or brevity.
  * sizeof(AVCodecContext) must not be used outside libav*.
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVCodecContext {
 /**
diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h
index a09c69f242..ee5fdd48d2 100644
--- a/libavcodec/bsf.h
+++ b/libavcodec/bsf.h
@@ -64,6 +64,9 @@
  * The fields in the struct will only be changed (by the caller or by the
  * filter) as described in their documentation, and are to be considered
  * immutable otherwise.
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVBSFContext {
 /**
diff --git a/libavcodec/d3d11va.h b/libavcodec/d3d11va.h
index 27f40e5519..686974b083 100644
--- a/libavcodec/d3d11va.h
+++ b/libavcodec/d3d11va.h
@@ -52,6 +52,9 @@
  * The application must make it available as AVCodecContext.hwaccel_context.
  *
  * Use av_d3d11va_alloc_context() exclusively to allocate an AVD3D11VAContext.
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVD3D11VAContext {
 /**
diff --git a/libavcodec/mediacodec.h b/libavcodec/mediacodec.h
index 4e9b56a618..43f049a609 100644
--- a/libavcodec/mediacodec.h
+++ b/libavcodec/mediacodec.h
@@ -29,6 +29,8 @@
  * This structure holds a reference to a android/view/Surface object that will
  * be used as output by the decoder.
  *
+ * @see
+ * - @ref Context
  */
 typedef struct AVMediaCodecContext {
 
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index c156b08d07..8ab93af6b6 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -32,6 +32,9 @@
  * - decoding: hwaccel_context must be set on return from the get_format()
  * callback
  * - encoding: hwaccel_context must be set before avcodec_open2()
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVQSVContext {
 /**
diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h
index 8021c25761..934c96b88c 100644
--- a/libavcodec/vdpau.h
+++ b/libavcodec/vdpau.h
@@ -74,6 +74,9 @@ typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, 
struct AVFrame *,
  *
  * The size of this structure is not a part of the public ABI and must not
  * be used outside of libavcodec.
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVVDPAUContext {
 /**
diff --git a/libavcodec/videotoolbox.h b/libavcodec/videotoolbox.h
index d68d76e400..81d90d63b6 100644
--- a/libavcodec/videotoolbox.h
+++ b/libavcodec/videotoolbox.h
@@ -53,6 +53,9 @@
  * between the caller and libavcodec for initializing Videotoolbox decoding.
  * Its size is not a part of the public ABI, it must be allocated with
  * av_videotoolbox_alloc_context() and freed with av_free().
+ *
+ * @see
+ * - @ref Context
  */
 typedef struct AVVideotoolboxContext {
 /**
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index a34e61f23c..25ccd80433 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -403,7 +403,12 @@ unsigned avfilter_filter_pad_count(const AVFilter *filter, 
int is_output);
  */
 #define AVFILTER_THREAD_SLICE (1 << 0)
 
-/** An instance of a filter */
+/**
+ * An instance of a filter
+ *
+ * @see
+ * - @ref Context
+ */
 struct AVFilterContext {
 const AVClass *av_class;///< needed for av_log() and filters 
common options
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 8afdcd9fd0..18f20f0bb0 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1253,6 +1253,9 @@ enum AVDurationEstimationMethod {
  * can be found in libavformat/options_table.h.
  * The AVOption/command line 

[FFmpeg-devel] [PATCH v5 2/4] lavu: Clarify relationship between AVClass, AVOption and context

2024-05-23 Thread Andrew Sayers
---
 libavutil/log.h | 16 +---
 libavutil/opt.h | 17 ++---
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/libavutil/log.h b/libavutil/log.h
index ab7ceabe22..d599ab506e 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -59,9 +59,19 @@ typedef enum {
 struct AVOptionRanges;
 
 /**
- * Describe the class of an AVClass context structure. That is an
- * arbitrary struct of which the first field is a pointer to an
- * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
+ * Generic Logging and introspection facilities
+ *
+ * Logging and introspection functions expect to be passed structs
+ * whose first member is a pointer-to-@ref AVClass.
+ *
+ * Structs that only use the logging facilities are often referred to as
+ * "AVClass context structures", while those that use introspection facilities
+ * are called "AVOptions-enabled structs".
+ *
+ * @see
+ * * @ref lavu_log
+ * * @ref avoptions
+ * * @ref Context
  */
 typedef struct AVClass {
 /**
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 07e27a9208..b14c120e36 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -39,9 +39,16 @@
  * @defgroup avoptions AVOptions
  * @ingroup lavu_data
  * @{
- * AVOptions provide a generic system to declare options on arbitrary structs
- * ("objects"). An option can have a help text, a type and a range of possible
- * values. Options may then be enumerated, read and written to.
+ *
+ * Generic introspection facilities for AVClass context structures
+ *
+ * Provides a generic system to declare and manage options on any struct
+ * whose first member is a pointer-to-@ref AVClass.  Structs with private
+ * contexts can use that AVClass to return further @ref AVClass "AVClass"es
+ * that enable introspection of the private structs.
+ *
+ * Each option can have a help text, a type and a range of possible values.
+ * Options may be enumerated, read and written to.
  *
  * There are two modes of access to members of AVOption and its child structs.
  * One is called 'native access', and refers to access from the code that
@@ -53,6 +60,10 @@
  * question is allowed to access the field. This allows us to extend the
  * semantics of those fields without breaking API compatibility.
  *
+ * @see
+ * * @ref lavu_log
+ * * @ref Context
+ *
  * @section avoptions_scope Scope of AVOptions
  *
  * AVOptions is designed to support any set of multimedia configuration options
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH v5 1/4] doc: Explain what "context" means

2024-05-23 Thread Andrew Sayers
Derived from explanations kindly provided by Stefano Sabatini and others:
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-April/325903.html
---
 doc/context.md | 439 +
 1 file changed, 439 insertions(+)
 create mode 100644 doc/context.md

diff --git a/doc/context.md b/doc/context.md
new file mode 100644
index 00..21469a6e58
--- /dev/null
+++ b/doc/context.md
@@ -0,0 +1,439 @@
+@page Context Introduction to contexts
+
+@tableofcontents
+
+“Context” is a name for a widely-used programming idiom.
+This document explains the general idiom and some conventions used by FFmpeg.
+
+This document uses object-oriented analogies for readers familiar with
+[object-oriented 
programming](https://en.wikipedia.org/wiki/Object-oriented_programming).
+But contexts can also be used outside of OOP, and even in situations where OOP
+isn't helpful.  So these analogies should only be used as a rough guide.
+
+@section Context_general “Context” as a general concept
+
+Many projects use some kind of “context” idiom.  You can safely skip this
+section if you have used contexts in another project.  You might also prefer to
+read @ref Context_comparison before continuing with the rest of the document.
+
+@subsection Context_think “Context” as a way to think about code
+
+A context is any data structure that is passed to several functions
+(or several instances of the same function) that all operate on the same 
entity.
+For example, [object-oriented 
programming](https://en.wikipedia.org/wiki/Object-oriented_programming)
+languages usually provide member functions with a `this` or `self` value:
+
+```python
+# Python methods (functions within classes) must start with an object argument,
+# which does a similar job to a context:
+class MyClass:
+def my_func(self):
+...
+```
+
+Contexts can also be used in C-style procedural code.  If you have ever written
+a callback function, you have probably used a context:
+
+```c
+struct FileReader {
+FILE* file;
+};
+
+int my_callback(void *my_var_, uint8_t* buf, int buf_size) {
+
+// my_var provides context for the callback function:
+struct FileReader *my_var = (struct FileReader *)my_var_;
+
+return read(my_var->file, sizeof(*buf), buf_size);
+}
+
+void init() {
+
+struct FileReader my_var;
+my_var->file = fopen("my-file", "rb");
+
+register_callback(my_callback, _var);
+
+...
+
+fclose( my_var->file );
+
+}
+```
+
+In the broadest sense, a context is just a way to think about some code.
+You can even use it to think about code written by people who have never
+heard the term, or who would disagree with you about what it means.
+But when FFmpeg developers say “context”, they're usually talking about
+a more specific set of conventions.
+
+@subsection Context_communication “Context” as a tool of communication
+
+“Context“ can just be a word to understand code in your own head,
+but it can also be a term you use to explain your interfaces.
+Here is a version of the callback example that makes the context explicit:
+
+```c
+struct FileReaderContext {
+FILE *file;
+};
+
+int my_callback(void *ctx_, uint8_t *buf, int buf_size) {
+
+// ctx provides context for the callback function:
+struct FileReaderContext *ctx = (struct FileReaderContext *)ctx_;
+
+return read(ctx->file, sizeof(*buf), buf_size);
+}
+
+void init() {
+
+struct FileReader ctx;
+ctx->file = fopen("my-file", "rb");
+
+register_callback(my_callback, );
+
+...
+
+fclose( ctx->file );
+
+}
+```
+
+The difference here is subtle, but important.  If a piece of code
+*appears compatible with contexts*, then you are *allowed to think
+that way*, but if a piece of code *explicitly states it uses
+contexts*, then you are *required to follow that approach*.
+
+For example, take a look at avio_alloc_context().
+The function name and return value both state it uses contexts,
+so failing to follow that approach is a bug you can report.
+But its arguments are a set of callbacks that merely appear compatible with
+contexts, so it's fine to write a `read_packet` function that just reads
+from standard input.
+
+When a programmer says their code is "a context", they're guaranteeing
+to follow a set of conventions enforced by their community - for example,
+the FFmpeg community enforces that contexts have separate allocation,
+configuration, and initialization steps.  That's different from saying
+their code is "an object", which normally guarantees to follow conventions
+enforced by their programming language (e.g. using a constructor function).
+
+@section Context_ffmpeg FFmpeg contexts
+
+This section discusses specific context-related conventions used in FFmpeg.
+Some of these are used in other projects, others are unique to this project.
+
+@subsection Context_naming Naming: “Context” and “ctx”
+
+```c
+// Context struct names usually end with `Context`:
+struct AVSomeContext {
+  ...
+};
+
+// Functions are 

[FFmpeg-devel] [PATCH v5 0/4] Explain what "context" means

2024-05-23 Thread Andrew Sayers
NOTE: this patchset depends on [1], and should not be applied before that.

I think it's important to guide readers between parts of FFmpeg, because
learning how the pieces of the puzzle fit together is a big part of the
newbie experience.  So this patchset replaces the "@ref Context for foo"
statements in public structs with "@see" blocks, giving us a hook we can
hang more links on in future.

That said, there's a rule against internal links from private structs,
so I've removed the @ref's from them.  By the way, is this rule written
somewhere?  If not, where would be a good place to write it?
And either way, it would be good to link to this as part of [2].

Previous patches had to change the language for many structs, but "@see" blocks
avoid the need to include those changes in this patchset.  Rather than waste
that work, I've temporarily moved those changes to the final patch in this set.
My feelings about that last patch aren't strong, but I guess I'll propose them
in a separate thread unless anyone wants them here or chucked altogether.


I've rewritten AVOptions and AVClass based on feedback.  The new version
reflects a hypothetical that's been going round my head all week...

Imagine you wanted to write a system that nudged people to try new codecs.
It might say e.g. "you seem to be using H.264, would you like to try H.265?"
Implementing that would probably involve a struct like:

struct AVOldNew {
  AVClass* old;
  AVClass* new;
};

That's a struct that begins with an AVClass*, but is clearly not an AVClass
context structure.  So the new version defines "AVClass context structure" and
"AVOptions-enabled struct" in terms of the way the structs are used instead of
their layout, which should be more useful and accurate to current practice,
while remaining compatible(ish) with the way the words are used in conversation.


I mentioned hwaccels in a previous message.  From another look around the code,
I think these are supposed to be completely invisible to an external API dev.
If not, please point me in the direction of any documentation I missed.

[1] https://ffmpeg.org/pipermail/ffmpeg-devel/2024-May/327958.html
[2] https://ffmpeg.org/pipermail/ffmpeg-devel/2024-May/327624.html


___
ffmpeg-devel mailing list
ffmpeg-devel@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 4/5] avcodec/libsvtav1 - switch to DOVI_ENCODING_OPTS

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

---
 libavcodec/libsvtav1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 2fef8c8971..4a8cab4eb9 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -731,8 +731,7 @@ static const AVOption options[] = {
   AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
 { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list 
of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, 
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" },
+DOVI_ENCODING_OPTS(dovi)
 
 {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".


[FFmpeg-devel] [PATCH v3 5/5] avcodec/libx265 - switch to DOVI_ENCODING_OPTS

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

---
 libavcodec/libx265.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index ac1dbc4f97..70e447fc0e 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -951,8 +951,7 @@ static const AVOption options[] = {
 { "a53cc",   "Use A53 Closed Captions (if available)", 
 OFFSET(a53_cc),AV_OPT_TYPE_BOOL,   { .i64 = 1 }, 0, 1, 
VE },
 { "x265-params", "set the x265 configuration using a :-separated list of 
key=value parameters", OFFSET(x265_opts), AV_OPT_TYPE_DICT,   { 0 }, 0, 0, VE },
 #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" },
+DOVI_ENCODING_OPTS(dovi)
 #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".


[FFmpeg-devel] [PATCH v3 3/5] avcodec/libaomenc - switch to DOVI_ENCODING_OPTS

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

---
 libavcodec/libaomenc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index dec74ebecd..22429717e8 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1487,8 +1487,7 @@ static const AVOption options[] = {
 { "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_SSIM}, 0, 0, VE, .unit = "tune"},
 FF_AV1_PROFILE_OPTS
 { "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" },
+DOVI_ENCODING_OPTS(dovi)
 { "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},
-- 
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 v3 2/5] avcodec/dovi_rpuenc - guard metadata compression

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

Guard use_prev_vdr_rpu by the new enable_compression field since not all
clients support this.

Separately output when vdr_dm_metadata_changed == 0 fails the DV verifier so
turn that off unconditionally for now.


---
 libavcodec/dovi_rpuenc.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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(>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(>vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping));
 
 buffer_size = 12 /* vdr seq info */ + 5 /* CRC32 + terminator */;
 buffer_size += num_ext_blocks_v1 * 13;
-- 
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 v3 1/5] avcodec/dovi_rpu - field and macro for metadata compression

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


Add a field to enable or disable metadata compression since not all clients 
support this.

Introduce DOVI_ENCODING_OPTS macro to faciliate exposing this as an option to 
encoders.

---
 libavcodec/dovi_rpu.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 8ce0c88e9d..5406425c0d 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -28,6 +28,11 @@
 #include "libavutil/frame.h"
 #include "avcodec.h"
 
+#define DOVI_ENCODING_OPTS(dovi) \
+{ "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 },
+
 #define DOVI_MAX_DM_ID 15
 typedef struct DOVIContext {
 void *logctx;
@@ -71,6 +76,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
  */
-- 
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 v3 0/5] avcodec/dovi - disable metadata compression by default

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

not all clients support metadata compression, output when 
vdr_dm_metadata_changed fails the DV verifier.

Compared to v2 this makes the dovi field name a parameter of the
DOVI_ENCODING_OPTS macro as requested.  It also splits up the commits into
introducing the macro, guarding compression by it, and then leveraging it in
the encoder.

I split up each encoder into a separate patch since the original support was
added in separate patches but this could also be squashed when applying if
that's better.

Cosmin Stejerean (5):
  avcodec/dovi_rpu - add field to disable metadata compression
  avcodec/dovi_rpuenc - guard metadata compression by enable_compression
  avcodec/libaomenc - switch DolbyVision options to DOVI_ENCODING_OPTS
  avcodec/libsvtav1 - switch DolbyVision options to DOVI_ENCODING_OPTS
  avcodec/libx265 - switch DolbyVision options to DOVI_ENCODING_OPTS

 libavcodec/dovi_rpu.h| 10 ++
 libavcodec/dovi_rpuenc.c |  8 ++--
 libavcodec/libaomenc.c   |  3 +--
 libavcodec/libsvtav1.c   |  3 +--
 libavcodec/libx265.c |  3 +--
 5 files changed, 19 insertions(+), 8 deletions(-)

-- 
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] lavc/vp8dsp: remove unused macro parameter

2024-05-23 Thread Rémi Denis-Courmont
---
 libavcodec/riscv/vp8dsp_rvv.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/riscv/vp8dsp_rvv.S b/libavcodec/riscv/vp8dsp_rvv.S
index 0ba9fa443d..9c84b1503e 100644
--- a/libavcodec/riscv/vp8dsp_rvv.S
+++ b/libavcodec/riscv/vp8dsp_rvv.S
@@ -94,7 +94,7 @@ func ff_vp8_idct_dc_add4uv_rvv, zve32x
 ret
 endfunc
 
-.macro bilin_load dst len type mn
+.macro bilin_load dst type mn
 .ifc \type,v
 add t5, a2, a3
 .else
@@ -116,7 +116,7 @@ func ff_put_vp8_bilin\len\()_\type\()_rvv, zve32x
 sub t1, t1, \mn
 1:
 addia4, a4, -1
-bilin_load  v0, \len, \type, \mn
+bilin_load  v0, \type, \mn
 vse8.v  v0, (a0)
 add a2, a2, a3
 add a0, a0, a1
@@ -133,12 +133,12 @@ func ff_put_vp8_bilin\len\()_hv_rvv, zve32x
 sub t1, t3, a5
 sub t2, t3, a6
 li  t4, 4
-bilin_load  v4, \len, h, a5
+bilin_load  v4, h, a5
 add a2, a2, a3
 1:
 addia4, a4, -1
 vwmulu.vx   v20, v4, t2
-bilin_load  v4, \len, h, a5
+bilin_load  v4, h, a5
 vwmaccu.vx  v20, a6, v4
 vwaddu.wx   v24, v20, t4
 vnsra.wiv0, v24, 3
-- 
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] lavc/rv32dsp: remove stray load immediate

2024-05-23 Thread Rémi Denis-Courmont
---
 libavcodec/riscv/rv34dsp_rvv.S | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/riscv/rv34dsp_rvv.S b/libavcodec/riscv/rv34dsp_rvv.S
index f1f6345012..8eda01665d 100644
--- a/libavcodec/riscv/rv34dsp_rvv.S
+++ b/libavcodec/riscv/rv34dsp_rvv.S
@@ -37,7 +37,6 @@ func ff_rv34_idct_dc_add_rvv, zve32x
 vlse32.v  v0, (a0), a1
 lit1, 169
 mul   t1, t1, a2
-lia2, 255
 addi  t1, t1, 512
 srai  t1, t1, 10
 vsetivli  zero, 4*4, e16, m2, ta, ma
-- 
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".


Re: [FFmpeg-devel] [PATCH v2] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-23 Thread epirat07



On 23 May 2024, at 18:05, Zhao Zhili wrote:

>> On May 21, 2024, at 09:56, Gnattu OC via ffmpeg-devel 
>>  wrote:
>>
>>>
>>> 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,
>>> + 
>>> ,
>>> + 
>>> );
>>> +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, 
>>> );
>>> -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.
>
> I will just remove the log message and apply the patch this week if no 
> objection.
>

I will do some more tests, if you want apply with the log message removed and I 
will do a follow up patch
if I find another solution.

>>
>>> +
>>> +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 mailing list
> ffmpeg-devel@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

Re: [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg: rewrite checking whether codec AVOptions have been used

2024-05-23 Thread Marton Balint




On Thu, 23 May 2024, Anton Khirnov wrote:


Share the code between encoding and decoding. Instead of checking every
stream's options dictionary (which is also used for other purposes),
track all used options in a dedicated dictionary.
---
fftools/cmdutils.c| 17 
fftools/cmdutils.h|  4 ++-
fftools/ffmpeg.c  | 49 ++
fftools/ffmpeg.h  |  3 ++-
fftools/ffmpeg_demux.c| 50 ---
fftools/ffmpeg_mux.c  |  1 +
fftools/ffmpeg_mux.h  |  3 +++
fftools/ffmpeg_mux_init.c | 55 +--
fftools/ffmpeg_opt.c  | 18 -
fftools/ffplay.c  |  2 +-
fftools/ffprobe.c |  2 +-
11 files changed, 89 insertions(+), 115 deletions(-)



[...]


--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -493,6 +493,55 @@ int check_avoptions(AVDictionary *m)
return 0;
}

+int check_avoptions_used(const AVDictionary *opts, const AVDictionary 
*opts_used,
+ void *logctx, int decode)
+{
+const AVClass  *class = avcodec_get_class();
+const AVClass *fclass = avformat_get_class();
+
+const int flag = decode ? AV_OPT_FLAG_DECODING_PARAM :
+  AV_OPT_FLAG_ENCODING_PARAM;
+const AVDictionaryEntry *e = NULL;
+
+while ((e = av_dict_iterate(opts, e))) {
+const AVOption *option, *foption;
+char *optname, *p;
+
+optname = av_strdup(e->key);
+if (!optname)
+return AVERROR(ENOMEM);
+
+p = strchr(optname, ':');
+if (p)
+*p = 0;
+
+option = av_opt_find(, optname, NULL, 0,
+ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
+foption = av_opt_find(, optname, NULL, 0,
+  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
+av_freep();
+if (!option || foption)
+continue;
+
+if (!(option->flags & flag)) {
+av_log(logctx, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a %s "
+   "option.\n", option->name, option->help ? option->help : "",


Why the change of e->key to option->name? The full user specified option 
should be printed with specifier, so the user will know exactly which 
specifier matched the wrong stream type.



+   decode ? "decoding" : "encoding");
+return AVERROR(EINVAL);
+}
+
+if (!av_dict_get(opts_used, e->key, NULL, 0)) {
+av_log(logctx, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been 
used "
+   "for any stream. The most likely reason is either wrong type 
"
+   "(e.g. a video option with no video streams) or that it is a 
"
+   "private option of some decoder which was not actually used 
"
+   "for any stream.\n", option->name, option->help ? option->help : 
"");


Same here. The non-matching specifer should also be printed, not only the 
option name, so please keep using e->key in the warning message.


Thanks,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@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 v9 01/13] avcodec/vaapi_encode: introduce a base layer for vaapi encode

2024-05-23 Thread Lynne via ffmpeg-devel

On 20/05/2024 16:52, tong1.wu-at-intel@ffmpeg.org wrote:

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

Re: [FFmpeg-devel] [PATCH v2] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-23 Thread Zhao Zhili



> On May 21, 2024, at 09:56, Gnattu OC via ffmpeg-devel 
>  wrote:
> 
>> 
>> 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,
>> + 
>> ,
>> + 
>> );
>> +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, 
>> );
>> -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.

I will just remove the log message and apply the patch this week if no 
objection.

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: workaround the alignment requirement for H.265

2024-05-23 Thread Zhao Zhili

> On May 23, 2024, at 15:08, Zhao Zhili  wrote:
> 
> From: Zhao Zhili 
> 
> Signed-off-by: Zhao Zhili 
> ---
> libavcodec/mediacodecenc.c | 11 ---
> 1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
> index bfff149039..a42270551b 100644
> --- a/libavcodec/mediacodecenc.c
> +++ b/libavcodec/mediacodecenc.c
> @@ -154,8 +154,12 @@ static int mediacodec_init_bsf(AVCodecContext *avctx)
> ret = snprintf(str, sizeof(str), 
> "h264_metadata=crop_right=%d:crop_bottom=%d",
>crop_right, crop_bottom);
> else if (avctx->codec_id == AV_CODEC_ID_HEVC)
> -ret = snprintf(str, sizeof(str), 
> "hevc_metadata=crop_right=%d:crop_bottom=%d",
> -   crop_right, crop_bottom);
> +/* Encoder can use CTU size larger than 16x16, so the real crop
> + * margin can be larger than crop_right/crop_bottom. Let bsf 
> figure
> + * out the real crop margin.
> + */
> +ret = snprintf(str, sizeof(str), 
> "hevc_metadata=width=%d:height=%d",
> +   avctx->width, avctx->height);
> if (ret >= sizeof(str))
> return AVERROR_BUFFER_TOO_SMALL;
> }
> @@ -235,7 +239,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
> // Workaround the alignment requirement of mediacodec. We can't do it
> // silently for AV_PIX_FMT_MEDIACODEC.
> if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
> -avctx->codec_id == AV_CODEC_ID_H264) {
> +(avctx->codec_id == AV_CODEC_ID_H264 ||
> + avctx->codec_id == AV_CODEC_ID_HEVC)) {
> s->width = FFALIGN(avctx->width, 16);
> s->height = FFALIGN(avctx->height, 16);
> } else {
> -- 
> 2.42.0
> 

For anyone who is interested on why the workaround is important, here is an 
example.

This mediacodec xml comes from a pretty new mobile made by Vivo, with CPU from 
MTK.
Both H.264 and H.265 encoder require alignment of 16x16. MediaCodec will fail 
during
configure with resolution like 1080x1920. When use surface as input, it will 
output a video
stream with resolution 1072x1920. It’s weird, but it’s not rare.

  










  













___
ffmpeg-devel mailing list
ffmpeg-devel@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] [7.0 PATCH 2/2] avcodec/mediacodecenc: workaround the alignment requirement for H.265

2024-05-23 Thread Zhao Zhili
From: Zhao Zhili 

---
The patchset for master branch isn't suitable for release branch, since it
implement a new feature in bsf.
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11882

 libavcodec/mediacodecenc.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index a898e335b5..d3bf27cb7f 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -201,9 +201,18 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 // Workaround the alignment requirement of mediacodec. We can't do it
 // silently for AV_PIX_FMT_MEDIACODEC.
 if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
-avctx->codec_id == AV_CODEC_ID_H264) {
+(avctx->codec_id == AV_CODEC_ID_H264 ||
+ avctx->codec_id == AV_CODEC_ID_HEVC)) {
 s->width = FFALIGN(avctx->width, 16);
 s->height = FFALIGN(avctx->height, 16);
+// If avctx video size is aligned to 16 already, we don't need to do
+// anything. If align is needed for HEVC, we should use the maximum CTU
+// size.
+if (avctx->codec_id == AV_CODEC_ID_HEVC &&
+(s->width != avctx->width || s->height != avctx->height)) {
+s->width = FFALIGN(avctx->width, 64);
+s->height = FFALIGN(avctx->height, 64);
+}
 } else {
 s->width = avctx->width;
 s->height = avctx->height;
-- 
2.42.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] [7.0 PATCH 1/2] avcodec/mediacodecenc: workaround the alignment requirement only for H.264

2024-05-23 Thread Zhao Zhili
From: Zhao Zhili 

There is no bsf for other codecs to modify crop info except H.265.
For H.265, the assumption that FFALIGN(width, 16)xFFALIGN(height, 16)
is the video resolution can be wrong, since the encoder can use CTU
larger than 16x16. In that case, use FFALIGN(width, 16) - width
as crop_right is incorrect. So disable the workaround for H.265 now.
---
 libavcodec/mediacodecenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index fcb84ef0ac..a898e335b5 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -200,7 +200,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 ff_AMediaFormat_setString(format, "mime", codec_mime);
 // Workaround the alignment requirement of mediacodec. We can't do it
 // silently for AV_PIX_FMT_MEDIACODEC.
-if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) {
+if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
+avctx->codec_id == AV_CODEC_ID_H264) {
 s->width = FFALIGN(avctx->width, 16);
 s->height = FFALIGN(avctx->height, 16);
 } else {
-- 
2.42.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 2/2] avformat/movenc: add support for writing SA3D boxes

2024-05-23 Thread James Almer

On 5/14/2024 10:08 PM, James Almer wrote:

Signed-off-by: James Almer 
---
  libavformat/movenc.c | 61 
  1 file changed, 61 insertions(+)


Will apply the set.
___
ffmpeg-devel mailing list
ffmpeg-devel@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] avfilter/framesync: fix forward EOF pts

2024-05-23 Thread Nicolas Gaullier
>Envoyé : mardi 21 mai 2024 21:39
>
>Note1: when the EOF pts is not accurate enough, the last frame can be dropped 
>by vf_fps with default rounding.
>
>Note2: vf_scale use framesync since e82a3997cdd6c0894869b33ba42430ac3,
>so this is a very commonplace scenario.
>
>For example:
>./ffprobe -f lavfi testsrc=d=1,scale,fps -of flat \
>  -count_frames -show_entries stream=nb_read_frames
>
>Before:
>streams.stream.0.nb_read_frames="24"
>
>After:
>streams.stream.0.nb_read_frames="25"
>---
> libavfilter/framesync.c | 23 +++
> 1 file changed, 11 insertions(+), 12 deletions(-)

Ping ?

Here is another straight way to highlight the issue with a format filter 
auto-inserting a scale filter thus implying framesync:
>ffprobe -v debug -f lavfi testsrc=d=1,format=yuv420p,fps -count_frames
shows:
Before:
[auto_scale_0 @ X] [framesync @ X] Sync level 0
[Parsed_fps_2 @ X] EOF is at pts 24
[Parsed_fps_2 @ X] Dropping frame with pts 24
[Parsed_fps_2 @ X] 25 frames in, 24 frames out; 1 frames dropped, 0 frames 
duplicated.

After:
[auto_scale_0 @ X] [framesync @ X] Sync level 0
[Parsed_fps_2 @ X] EOF is at pts 25
[Parsed_fps_2 @ X] Writing frame with pts 24 to pts 24
[Parsed_fps_2 @ X] 25 frames in, 25 frames out; 0 frames dropped, 0 frames 
duplicated.

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

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


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

2024-05-23 Thread Stone Chen
On Thu, May 23, 2024 at 9:18 AM Nuo Mi  wrote:

> On Thu, May 23, 2024 at 7:38 AM James Almer  wrote:
>
> > On 5/21/2024 10:01 PM, Ronald S. Bultje wrote:
> > > Hi,
> > >
> > > On Tue, May 21, 2024 at 8:01 PM Stone Chen 
> > wrote:
> > >
> > >> Implements AVX2 DMVR (decoder-side motion vector refinement) SAD
> > >> functions. DMVR SAD is only calculated if w >= 8, h >= 8, and w * h >
> > 128.
> > >> To reduce complexity, SAD is only calculated on even rows. This is
> > >> calculated for all video bitdepths, but the values passed to the
> > function
> > >> are always 16bit (even if the original video bitdepth is 8). The AVX2
> > >> implementation uses min/max/sub.
> > >>
> > >> Additionally this changes parameters dx and dy from int to intptr_t.
> > This
> > >> allows dx & dy to be used as pointer offsets without needing to use
> > movsxd.
> > >>
> > >> Benchmarks ( AMD 7940HS )
> > >> Before:
> > >> BQTerrace_1920x1080_60_10_420_22_RA.vvc | 106.0 |
> > >> Chimera_8bit_1080P_1000_frames.vvc | 204.3 |
> > >> NovosobornayaSquare_1920x1080.bin | 197.3 |
> > >> RitualDance_1920x1080_60_10_420_37_RA.266 | 174.0 |
> > >>
> > >> After:
> > >> BQTerrace_1920x1080_60_10_420_22_RA.vvc | 109.3 |
> > >> Chimera_8bit_1080P_1000_frames.vvc | 216.0 |
> > >> NovosobornayaSquare_1920x1080.bin | 204.0|
> > >> RitualDance_1920x1080_60_10_420_37_RA.266 | 181.7 |
> > >> ---
> > >>   libavcodec/vvc/dsp.c |   2 +-
> > >>   libavcodec/vvc/dsp.h |   2 +-
> > >>   libavcodec/x86/vvc/Makefile  |   3 +-
> > >>   libavcodec/x86/vvc/vvc_sad.asm   | 130
> +++
> > >>   libavcodec/x86/vvc/vvcdsp_init.c |   6 ++
> > >>   5 files changed, 140 insertions(+), 3 deletions(-)
> > >>   create mode 100644 libavcodec/x86/vvc/vvc_sad.asm
> > >>
> > >
> > > LGTM.
> > >
> > > Ronald
> >
> > Implemented my changes and applied.
> >
>

Hi all,


> Thank you, Ronald, Andreas, and James.
>
> Hi Stone,
> Congratulations on surviving your first crossfire!
>


Yes thank you Ronald, Andreas and James for the feedback! Also Nuo Mi and
Jian Hua as well.

-Stone


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

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


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

2024-05-23 Thread Nuo Mi
On Thu, May 23, 2024 at 7:38 AM James Almer  wrote:

> On 5/21/2024 10:01 PM, Ronald S. Bultje wrote:
> > Hi,
> >
> > On Tue, May 21, 2024 at 8:01 PM Stone Chen 
> wrote:
> >
> >> Implements AVX2 DMVR (decoder-side motion vector refinement) SAD
> >> functions. DMVR SAD is only calculated if w >= 8, h >= 8, and w * h >
> 128.
> >> To reduce complexity, SAD is only calculated on even rows. This is
> >> calculated for all video bitdepths, but the values passed to the
> function
> >> are always 16bit (even if the original video bitdepth is 8). The AVX2
> >> implementation uses min/max/sub.
> >>
> >> Additionally this changes parameters dx and dy from int to intptr_t.
> This
> >> allows dx & dy to be used as pointer offsets without needing to use
> movsxd.
> >>
> >> Benchmarks ( AMD 7940HS )
> >> Before:
> >> BQTerrace_1920x1080_60_10_420_22_RA.vvc | 106.0 |
> >> Chimera_8bit_1080P_1000_frames.vvc | 204.3 |
> >> NovosobornayaSquare_1920x1080.bin | 197.3 |
> >> RitualDance_1920x1080_60_10_420_37_RA.266 | 174.0 |
> >>
> >> After:
> >> BQTerrace_1920x1080_60_10_420_22_RA.vvc | 109.3 |
> >> Chimera_8bit_1080P_1000_frames.vvc | 216.0 |
> >> NovosobornayaSquare_1920x1080.bin | 204.0|
> >> RitualDance_1920x1080_60_10_420_37_RA.266 | 181.7 |
> >> ---
> >>   libavcodec/vvc/dsp.c |   2 +-
> >>   libavcodec/vvc/dsp.h |   2 +-
> >>   libavcodec/x86/vvc/Makefile  |   3 +-
> >>   libavcodec/x86/vvc/vvc_sad.asm   | 130 +++
> >>   libavcodec/x86/vvc/vvcdsp_init.c |   6 ++
> >>   5 files changed, 140 insertions(+), 3 deletions(-)
> >>   create mode 100644 libavcodec/x86/vvc/vvc_sad.asm
> >>
> >
> > LGTM.
> >
> > Ronald
>
> Implemented my changes and applied.
>
Thank you, Ronald, Andreas, and James.

Hi Stone,
Congratulations on surviving your first crossfire!

___
> ffmpeg-devel mailing list
> ffmpeg-devel@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 v3 2/2] avcodec/dovi - correctly read el_bit_depth_minus8 and ext_mapping_idc

2024-05-23 Thread James Almer

On 5/22/2024 12:50 PM, Cosmin Stejerean via ffmpeg-devel wrote:

From: Cosmin Stejerean 

These two fields are coded together into a single 16 bit integer with upper 8
bits for ext_mapping_idc and lower 8 bits for el_bit_depth_minus8.

Furthermore ext_mapping_idc has two components, upper 3 bits and lower 5 bits.
---
  libavcodec/dovi_rpudec.c | 7 ++-
  libavcodec/dovi_rpuenc.c | 4 +++-
  2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
index 7c7eda9d09..af41ab5827 100644
--- a/libavcodec/dovi_rpudec.c
+++ b/libavcodec/dovi_rpudec.c
@@ -411,13 +411,18 @@ 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);
+int el_bit_depth_minus8_and_ext_mapping_idc = 
get_ue_golomb_long(gb);
+int el_bit_depth_minus8 = el_bit_depth_minus8_and_ext_mapping_idc 
& 0xFF; // lowest 8 bits
+int ext_mapping_idc = (el_bit_depth_minus8_and_ext_mapping_idc & 0xFF00) 
>> 8; // upper 8 bits


nit: we usually do (foo >> 8) & 0xFF.

Also, coding two (maybe three) values in a single golomb code is evil.


+
  int vdr_bit_depth_minus8 = get_ue_golomb_31(gb);
  VALIDATE(bl_bit_depth_minus8, 0, 8);
  VALIDATE(el_bit_depth_minus8, 0, 8);
  VALIDATE(vdr_bit_depth_minus8, 0, 8);
  hdr->bl_bit_depth = bl_bit_depth_minus8 + 8;
  hdr->el_bit_depth = el_bit_depth_minus8 + 8;
+hdr->ext_mapping_idc_0_4 = ext_mapping_idc & 0x1F; // lowest 5 
bits of ext_mapping_idc
+hdr->ext_mapping_idc_5_7 = (ext_mapping_idc & 0xE0) >> 5; // upper 
3 bits of ext_mapping_idc


Ditto.


  hdr->vdr_bit_depth = vdr_bit_depth_minus8 + 8;
  hdr->spatial_resampling_filter_flag = get_bits1(gb);
  skip_bits(gb, 3); /* reserved_zero_3bits */
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index 3c3e0f84c0..91c0a85050 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -444,6 +444,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const 
AVDOVIMetadata *metadata,
  int vdr_dm_metadata_changed, vdr_rpu_id, use_prev_vdr_rpu, profile,
  buffer_size, rpu_size, pad, zero_run;
  int num_ext_blocks_v1, num_ext_blocks_v2;
+uint8_t ext_mapping_idc;
  uint32_t crc;
  uint8_t *dst;
  if (!metadata) {
@@ -551,7 +552,8 @@ int ff_dovi_rpu_generate(DOVIContext *s, const 
AVDOVIMetadata *metadata,
  put_bits(pb, 1, hdr->bl_video_full_range_flag);
  if ((hdr->rpu_format & 0x700) == 0) {
  set_ue_golomb(pb, hdr->bl_bit_depth - 8);
-set_ue_golomb(pb, hdr->el_bit_depth - 8);
+ext_mapping_idc = (hdr->ext_mapping_idc_5_7 << 5) | 
hdr->ext_mapping_idc_0_4;
+set_ue_golomb(pb, (ext_mapping_idc << 8) | hdr->el_bit_depth - 8);
  set_ue_golomb(pb, hdr->vdr_bit_depth - 8);
  put_bits(pb, 1, hdr->spatial_resampling_filter_flag);
  put_bits(pb, 3, 0); /* reserved_zero_3bits */

___
ffmpeg-devel mailing list
ffmpeg-devel@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/5] avcodec/vvc_mc: split the SAD dsp prototype into one function per blocksize width

2024-05-23 Thread Andreas Rheinhardt
James Almer:
> Signed-off-by: James Almer 
> ---

The commit message should explain what the advantage of this is.
Particularly, what is the advantage of this over jumping in the function
to based upon blocksize vs. selecting an appropriate function in the
generic code (even when these functions turn out all the same as is for
the C version).

>  libavcodec/vvc/dsp.h |  2 +-
>  libavcodec/vvc/inter.c   |  6 --
>  libavcodec/vvc/inter_template.c  |  6 +-
>  libavcodec/x86/vvc/vvc_sad.asm   | 32 ++--
>  libavcodec/x86/vvc/vvcdsp_init.c | 22 +-
>  tests/checkasm/vvc_mc.c  |  3 ++-
>  6 files changed, 55 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
> index 1f14096c41..55c4c81f53 100644
> --- a/libavcodec/vvc/dsp.h
> +++ b/libavcodec/vvc/dsp.h
> @@ -99,7 +99,7 @@ typedef struct VVCInterDSPContext {
>  
>  void (*apply_bdof)(uint8_t *dst, ptrdiff_t dst_stride, int16_t *src0, 
> int16_t *src1, int block_w, int block_h);
>  
> -int (*sad)(const int16_t *src0, const int16_t *src1, int dx, int dy, int 
> block_w, int block_h);
> +int (*sad[5])(const int16_t *src0, const int16_t *src1, int dx, int dy, 
> int block_w, int block_h);
>  void (*dmvr[2][2])(int16_t *dst, const uint8_t *src, ptrdiff_t 
> src_stride, int height,
>  intptr_t mx, intptr_t my, int width);
>  } VVCInterDSPContext;
> diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
> index e1011b4fa1..0214e46634 100644
> --- a/libavcodec/vvc/inter.c
> +++ b/libavcodec/vvc/inter.c
> @@ -740,6 +740,8 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
> *mvf, MvField *orig_mv,
>  const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int 
> y_off, const int block_w, const int block_h)
>  {
>  const VVCFrameContext *fc   = lc->fc;
> +static const uint8_t sad_tab[16] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 
> 4, 4, 4, 4 };
> +const int tab   = sad_tab[(FFALIGN(block_w, 8) >> 3) - 1];
>  const int sr_range  = 2;
>  const AVFrame *ref[]= { ref0, ref1 };
>  int16_t *tmp[]  = { lc->tmp, lc->tmp1 };
> @@ -763,7 +765,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
> *mvf, MvField *orig_mv,
>  fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, 
> mx, my, pred_w);
>  }
>  
> -min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, 
> block_h);
> +min_sad = fc->vvcdsp.inter.sad[tab](tmp[L0], tmp[L1], dx, dy, block_w, 
> block_h);
>  min_sad -= min_sad >> 2;
>  sad[dy][dx] = min_sad;
>  
> @@ -773,7 +775,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
> *mvf, MvField *orig_mv,
>  for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
>  for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
>  if (dx != sr_range || dy != sr_range) {
> -sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, 
> dx, dy, block_w, block_h);
> +sad[dy][dx] = fc->vvcdsp.inter.sad[tab](lc->tmp, 
> lc->tmp1, dx, dy, block_w, block_h);
>  if (sad[dy][dx] < min_sad) {
>  min_sad = sad[dy][dx];
>  min_dx = dx;
> diff --git a/libavcodec/vvc/inter_template.c b/libavcodec/vvc/inter_template.c
> index a8068f4ba8..34485321d3 100644
> --- a/libavcodec/vvc/inter_template.c
> +++ b/libavcodec/vvc/inter_template.c
> @@ -626,7 +626,11 @@ static void 
> FUNC(ff_vvc_inter_dsp_init)(VVCInterDSPContext *const inter)
>  inter->apply_prof_uni_w = FUNC(apply_prof_uni_w);
>  inter->apply_bdof   = FUNC(apply_bdof);
>  inter->prof_grad_filter = FUNC(prof_grad_filter);
> -inter->sad  = vvc_sad;
> +inter->sad[0]   =
> +inter->sad[1]   =
> +inter->sad[2]   =
> +inter->sad[3]   =
> +inter->sad[4]   = vvc_sad;
>  }
>  
>  #undef FUNCS
> diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
> index b468d89ac2..a20818530f 100644
> --- a/libavcodec/x86/vvc/vvc_sad.asm
> +++ b/libavcodec/x86/vvc/vvc_sad.asm
> @@ -51,7 +51,7 @@ SECTION .text
>  
>  INIT_YMM avx2
>  
> -cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
> row_idx
> +cglobal vvc_sad_8, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, 
> off2, row_idx
>  movsxdifnidndxq, dxd
>  movsxdifnidndyq, dyd
>  
> @@ -76,10 +76,6 @@ cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, 
> block_h, off1, off2, row_
>  pxor   m3, m3
>  vpbroadcastd   m4, [pw_1]
>  
> -cmp  block_wd, 16
> -jgevvc_sad_16_128
> -
> -vvc_sad_8:
>  .loop_height:
>  movu  xm0, [src1q]
>  vinserti128m0, m0, [src1q + MAX_PB_SIZE * ROWS * 2], 1
> @@ -100,7 +96,31 @@ cglobal 

[FFmpeg-devel] [PATCH 5/5] x86/vvc_sad: reindent after the previous changes

2024-05-23 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/x86/vvc/vvc_sad.asm | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index 9881b1180d..14f7ce230e 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -81,7 +81,7 @@ DEFINE_ARGS src1, src2, dx, off1, off2, block_h
 mova   m4, [pw_1]
 %endif
 
-.loop_height:
+.loop_height:
 movu   m0, [src1q]
 movu   m1, [src2q]
 MIN_MAX_SADm1, m0, m2
@@ -94,8 +94,8 @@ DEFINE_ARGS src1, src2, dx, off1, off2, block_h
 sub  block_hd, 2
 jg   .loop_height
 
-HORIZ_ADD xm0, xm3, m3
-movd  eax, xm0
+HORIZ_ADD xm0, xm3, m3
+movd  eax, xm0
 RET
 %endmacro
 
@@ -129,13 +129,13 @@ DEFINE_ARGS src1, src2, dx, off1, block_w, block_h, off2
 mova   m4, [pw_1]
 %endif
 
-shl  block_wd, 1
-add src1q, block_wq
-add src2q, block_wq
-neg  block_wq
+shl  block_wd, 1
+add src1q, block_wq
+add src2q, block_wq
+neg  block_wq
 
 DEFINE_ARGS src1, src2, dx, dy, block_w, block_h, row_idx
-.loop_height:
+.loop_height:
 mov  row_idxq, block_wq
 
 .loop_width:
@@ -154,8 +154,8 @@ DEFINE_ARGS src1, src2, dx, dy, block_w, block_h, row_idx
 sub  block_hd, 2
 jg   .loop_height
 
-HORIZ_ADD xm0, xm3, m3
-movd  eax, xm0
+HORIZ_ADD xm0, xm3, m3
+movd  eax, xm0
 RET
 %endmacro
 
-- 
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/5] x86/vvc_sad: reduce gpr usage in all loop functions

2024-05-23 Thread James Almer
This way they can be assembled on x86_32 targets.

Signed-off-by: James Almer 
---
 libavcodec/x86/vvc/vvc_sad.asm   | 22 ++
 libavcodec/x86/vvc/vvcdsp_init.c | 16 +---
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index 26df25ec66..9881b1180d 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -49,7 +49,7 @@ SECTION .text
 %endmacro
 
 %macro VVC_SAD 1
-cglobal vvc_sad_%1, 4, 7, 5, src1, src2, dx, dy, off1, block_h, off2
+cglobal vvc_sad_%1, 4, 6, 5, src1, src2, dx, dy, off, block_h
 %if UNIX64 == 0
 mov block_hd, dword r5m
 %endif
@@ -59,12 +59,12 @@ cglobal vvc_sad_%1, 4, 7, 5, src1, src2, dx, dy, off1, 
block_h, off2
 sub dxq, 2
 sub dyq, 2
 
-mov off1q, 2
-mov off2q, 2
+mov offq, 2
 
-add off1q, dyq
-sub off2q, dyq
+sub offq, dyq
+add dyq, 2
 
+DEFINE_ARGS src1, src2, dx, off1, off2, block_h
 shl off1q, 7
 shl off2q, 7
 
@@ -100,19 +100,19 @@ cglobal vvc_sad_%1, 4, 7, 5, src1, src2, dx, dy, off1, 
block_h, off2
 %endmacro
 
 %macro VVC_SAD_LOOP 1
-cglobal vvc_sad_%1, 6, 8, 5, src1, src2, dx, dy, block_w, block_h, off1, off2
+cglobal vvc_sad_%1, 6, 7, 5, src1, src2, dx, dy, block_w, block_h, off
 movsxdifnidndxq, dxd
 movsxdifnidndyq, dyd
 
 sub dxq, 2
 sub dyq, 2
 
-mov off1q, 2
-mov off2q, 2
+mov offq, 2
 
-add off1q, dyq
-sub off2q, dyq
+sub offq, dyq
+add dyq, 2
 
+DEFINE_ARGS src1, src2, dx, off1, block_w, block_h, off2
 shl off1q, 7
 shl off2q, 7
 
@@ -159,7 +159,6 @@ DEFINE_ARGS src1, src2, dx, dy, block_w, block_h, row_idx
 RET
 %endmacro
 
-%if ARCH_X86_64
 INIT_XMM sse4
 VVC_SAD 8
 VVC_SAD_LOOP 16
@@ -168,4 +167,3 @@ INIT_YMM avx2
 VVC_SAD 16
 VVC_SAD_LOOP 32
 %endif
-%endif
diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index cdf0e36b62..c0bd145191 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -311,6 +311,7 @@ ALF_FUNCS(16, 12, avx2)
 c->alf.filter[CHROMA] = ff_vvc_alf_filter_chroma_##bd##_avx2;\
 c->alf.classify   = ff_vvc_alf_classify_##bd##_avx2; \
 } while (0)
+#endif
 
 #define SAD_PROTOTYPE(w, opt)\
 int bf(ff_vvc_sad, w, opt)(const int16_t *src0, const int16_t *src1, \
@@ -320,17 +321,17 @@ SAD_PROTOTYPE(8,   sse4);
 SAD_PROTOTYPE(16,  sse4);
 SAD_PROTOTYPE(16,  avx2);
 SAD_PROTOTYPE(32,  avx2);
-#endif
 
 void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int bd)
 {
-#if ARCH_X86_64
 const int cpu_flags = av_get_cpu_flags();
 
 switch (bd) {
 case 8:
 if (EXTERNAL_SSE4(cpu_flags)) {
+#if ARCH_X86_64
 MC_LINK_SSE4(8);
+#endif
 c->inter.sad[0] = ff_vvc_sad_8_sse4;
 c->inter.sad[1] =
 c->inter.sad[2] =
@@ -338,9 +339,11 @@ void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int 
bd)
 c->inter.sad[4] = ff_vvc_sad_16_sse4;
 }
 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
+#if ARCH_X86_64
 ALF_INIT(8);
 AVG_INIT(8, avx2);
 MC_LINKS_AVX2(8);
+#endif
 c->inter.sad[1] = ff_vvc_sad_16_avx2;
 c->inter.sad[2] =
 c->inter.sad[3] =
@@ -349,7 +352,9 @@ void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int 
bd)
 break;
 case 10:
 if (EXTERNAL_SSE4(cpu_flags)) {
+#if ARCH_X86_64
 MC_LINK_SSE4(10);
+#endif
 c->inter.sad[0] = ff_vvc_sad_8_sse4;
 c->inter.sad[1] =
 c->inter.sad[2] =
@@ -357,10 +362,12 @@ void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const 
int bd)
 c->inter.sad[4] = ff_vvc_sad_16_sse4;
 }
 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
+#if ARCH_X86_64
 ALF_INIT(10);
 AVG_INIT(10, avx2);
 MC_LINKS_AVX2(10);
 MC_LINKS_16BPC_AVX2(10);
+#endif
 c->inter.sad[1] = ff_vvc_sad_16_avx2;
 c->inter.sad[2] =
 c->inter.sad[3] =
@@ -369,7 +376,9 @@ void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int 
bd)
 break;
 case 12:
 if (EXTERNAL_SSE4(cpu_flags)) {
+#if ARCH_X86_64
 MC_LINK_SSE4(12);
+#endif
 c->inter.sad[0] = ff_vvc_sad_8_sse4;
 c->inter.sad[1] =
 c->inter.sad[2] =
@@ -377,10 +386,12 @@ void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const 
int bd)
 c->inter.sad[4] = ff_vvc_sad_16_sse4;
 }
 if (EXTERNAL_AVX2_FAST(cpu_flags)) {
+#if ARCH_X86_64
 ALF_INIT(12);
 

[FFmpeg-devel] [PATCH 3/5] x86/vvc_sad: add sse4 versions of all functions

2024-05-23 Thread James Almer
And remove sad_8x8_avx2, as it's not faster than sad_8x8_sse4.

sad_8x8_c: 54.8
sad_8x8_sse4: 14.3
sad_16x16_c: 200.8
sad_16x16_sse4: 34.8
sad_16x16_avx2: 29.8
sad_32x32_c: 826.3
sad_32x32_sse4: 113.8
sad_32x32_avx2: 69.3
sad_64x64_c: 3679.8
sad_64x64_sse4: 392.8
sad_64x64_avx2: 257.3
sad_128x128_c: 12581.3
sad_128x128_sse4: 1560.8
sad_128x128_avx2: 1151.8

Signed-off-by: James Almer 
---
 libavcodec/x86/vvc/vvc_sad.asm   | 53 +---
 libavcodec/x86/vvc/vvcdsp_init.c | 42 +
 2 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index 829dbce489..26df25ec66 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -26,7 +26,7 @@
 
 SECTION_RODATA
 
-pw_1: times 2 dw 1
+cextern pw_1
 
 ; DMVR SAD is only calculated on even rows to reduce complexity
 SECTION .text
@@ -38,20 +38,21 @@ SECTION .text
 %endmacro
 
 %macro HORIZ_ADD 3  ; xm0, xm1, m1
+%if mmsize == 32
 vextracti128 %1, %3, q0001  ;32  1  0
-paddd%1, %2 ; xm0 (7 + 3) (6 + 2) (5 + 1)   (4 + 0)
-pshufd   %2, %1, q0032  ; xm1-  - (7 + 3)   (6 + 2)
+paddd%2, %1 ; xm1 (7 + 3) (6 + 2) (5 + 1)   (4 + 0)
+%endif
+pshufd   %1, %2, q0032  ; xm0-  - (7 + 3)   (6 + 2)
 paddd%1, %1, %2 ; xm0_  _ (5 1 7 3) (4 0 6 2)
 pshufd   %2, %1, q0001  ; xm1_  _ (5 1 7 3) (5 1 7 3)
 paddd%1, %1, %2 ;   (01234567)
 %endmacro
 
-%if ARCH_X86_64
-%if HAVE_AVX2_EXTERNAL
-
-INIT_YMM avx2
-
-cglobal vvc_sad_8, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
row_idx
+%macro VVC_SAD 1
+cglobal vvc_sad_%1, 4, 7, 5, src1, src2, dx, dy, off1, block_h, off2
+%if UNIX64 == 0
+mov block_hd, dword r5m
+%endif
 movsxdifnidndxq, dxd
 movsxdifnidndyq, dyd
 
@@ -74,29 +75,32 @@ cglobal vvc_sad_8, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, ro
 lea src2q, [src2q + off2q * 2 + 2 * 2]
 
 pxor   m3, m3
+%if mmsize == 32
 vpbroadcastd   m4, [pw_1]
+%else
+mova   m4, [pw_1]
+%endif
 
 .loop_height:
-movu  xm0, [src1q]
-vinserti128m0, m0, [src1q + MAX_PB_SIZE * ROWS * 2], 1
-movu  xm1, [src2q]
-vinserti128m1, m1, [src2q + MAX_PB_SIZE * ROWS * 2], 1
-
+movu   m0, [src1q]
+movu   m1, [src2q]
 MIN_MAX_SADm1, m0, m2
 pmaddwdm1, m4
 paddd  m3, m1
 
-add src1q, 2 * MAX_PB_SIZE * ROWS * 2
-add src2q, 2 * MAX_PB_SIZE * ROWS * 2
+add src1q, ROWS * MAX_PB_SIZE * 2
+add src2q, ROWS * MAX_PB_SIZE * 2
 
-sub  block_hd, 4
+sub  block_hd, 2
 jg   .loop_height
 
 HORIZ_ADD xm0, xm3, m3
 movd  eax, xm0
 RET
+%endmacro
 
-cglobal vvc_sad_16, 6, 8, 5, src1, src2, dx, dy, block_w, block_h, off1, off2
+%macro VVC_SAD_LOOP 1
+cglobal vvc_sad_%1, 6, 8, 5, src1, src2, dx, dy, block_w, block_h, off1, off2
 movsxdifnidndxq, dxd
 movsxdifnidndyq, dyd
 
@@ -119,7 +123,11 @@ cglobal vvc_sad_16, 6, 8, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2
 lea src2q, [src2q + off2q * 2 + 2 * 2]
 
 pxor   m3, m3
+%if mmsize == 32
 vpbroadcastd   m4, [pw_1]
+%else
+mova   m4, [pw_1]
+%endif
 
 shl  block_wd, 1
 add src1q, block_wq
@@ -149,6 +157,15 @@ DEFINE_ARGS src1, src2, dx, dy, block_w, block_h, row_idx
 HORIZ_ADD xm0, xm3, m3
 movd  eax, xm0
 RET
+%endmacro
 
+%if ARCH_X86_64
+INIT_XMM sse4
+VVC_SAD 8
+VVC_SAD_LOOP 16
+%if HAVE_AVX2_EXTERNAL
+INIT_YMM avx2
+VVC_SAD 16
+VVC_SAD_LOOP 32
 %endif
 %endif
diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index bd60963432..cdf0e36b62 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -316,16 +316,10 @@ ALF_FUNCS(16, 12, avx2)
 int bf(ff_vvc_sad, w, opt)(const int16_t *src0, const int16_t *src1, \
int dx, int dy, int block_w, int block_h) \
 
-SAD_PROTOTYPE(8,   avx2);
+SAD_PROTOTYPE(8,   sse4);
+SAD_PROTOTYPE(16,  sse4);
 SAD_PROTOTYPE(16,  avx2);
-
-#define SAD_INIT(opt) do {   \
-c->inter.sad[0] = ff_vvc_sad_8_##opt;\
-c->inter.sad[1] =\
-c->inter.sad[2] =\
-c->inter.sad[3] =\
-c->inter.sad[4] = ff_vvc_sad_16_##opt;   \
-} while (0)
+SAD_PROTOTYPE(32,  avx2);
 #endif
 
 void ff_vvc_dsp_init_x86(VVCDSPContext *const c, const int bd)
@@ -337,36 +331,60 @@ 

[FFmpeg-devel] [PATCH 2/5] x86/vvc_sad: optimize vvc_sad_16

2024-05-23 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/x86/vvc/vvc_sad.asm | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index a20818530f..829dbce489 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -96,7 +96,7 @@ cglobal vvc_sad_8, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, ro
 movd  eax, xm0
 RET
 
-cglobal vvc_sad_16, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
row_idx
+cglobal vvc_sad_16, 6, 8, 5, src1, src2, dx, dy, block_w, block_h, off1, off2
 movsxdifnidndxq, dxd
 movsxdifnidndyq, dyd
 
@@ -121,26 +121,27 @@ cglobal vvc_sad_16, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, r
 pxor   m3, m3
 vpbroadcastd   m4, [pw_1]
 
-sar  block_wd, 4
+shl  block_wd, 1
+add src1q, block_wq
+add src2q, block_wq
+neg  block_wq
+
+DEFINE_ARGS src1, src2, dx, dy, block_w, block_h, row_idx
 .loop_height:
-mov off1q, src1q
-mov off2q, src2q
-mov  row_idxd, block_wd
+mov  row_idxq, block_wq
 
 .loop_width:
-movu   m0, [src1q]
-movu   m1, [src2q]
+movu   m0, [src1q+row_idxq]
+movu   m1, [src2q+row_idxq]
 MIN_MAX_SADm1, m0, m2
 pmaddwdm1, m4
 paddd  m3, m1
 
-add src1q, 32
-add src2q, 32
-dec  row_idxd
-jg.loop_width
+add  row_idxq, mmsize
+jl.loop_width
 
-lea src1q, [off1q + ROWS * MAX_PB_SIZE * 2]
-lea src2q, [off2q + ROWS * MAX_PB_SIZE * 2]
+add src1q, ROWS * MAX_PB_SIZE * 2
+add src2q, ROWS * MAX_PB_SIZE * 2
 
 sub  block_hd, 2
 jg   .loop_height
-- 
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/5] avcodec/vvc_mc: split the SAD dsp prototype into one function per blocksize width

2024-05-23 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/vvc/dsp.h |  2 +-
 libavcodec/vvc/inter.c   |  6 --
 libavcodec/vvc/inter_template.c  |  6 +-
 libavcodec/x86/vvc/vvc_sad.asm   | 32 ++--
 libavcodec/x86/vvc/vvcdsp_init.c | 22 +-
 tests/checkasm/vvc_mc.c  |  3 ++-
 6 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/libavcodec/vvc/dsp.h b/libavcodec/vvc/dsp.h
index 1f14096c41..55c4c81f53 100644
--- a/libavcodec/vvc/dsp.h
+++ b/libavcodec/vvc/dsp.h
@@ -99,7 +99,7 @@ typedef struct VVCInterDSPContext {
 
 void (*apply_bdof)(uint8_t *dst, ptrdiff_t dst_stride, int16_t *src0, 
int16_t *src1, int block_w, int block_h);
 
-int (*sad)(const int16_t *src0, const int16_t *src1, int dx, int dy, int 
block_w, int block_h);
+int (*sad[5])(const int16_t *src0, const int16_t *src1, int dx, int dy, 
int block_w, int block_h);
 void (*dmvr[2][2])(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, 
int height,
 intptr_t mx, intptr_t my, int width);
 } VVCInterDSPContext;
diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
index e1011b4fa1..0214e46634 100644
--- a/libavcodec/vvc/inter.c
+++ b/libavcodec/vvc/inter.c
@@ -740,6 +740,8 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
*mvf, MvField *orig_mv,
 const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int 
y_off, const int block_w, const int block_h)
 {
 const VVCFrameContext *fc   = lc->fc;
+static const uint8_t sad_tab[16] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 
4, 4, 4, 4 };
+const int tab   = sad_tab[(FFALIGN(block_w, 8) >> 3) - 1];
 const int sr_range  = 2;
 const AVFrame *ref[]= { ref0, ref1 };
 int16_t *tmp[]  = { lc->tmp, lc->tmp1 };
@@ -763,7 +765,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
*mvf, MvField *orig_mv,
 fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, 
my, pred_w);
 }
 
-min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h);
+min_sad = fc->vvcdsp.inter.sad[tab](tmp[L0], tmp[L1], dx, dy, block_w, 
block_h);
 min_sad -= min_sad >> 2;
 sad[dy][dx] = min_sad;
 
@@ -773,7 +775,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField 
*mvf, MvField *orig_mv,
 for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
 for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
 if (dx != sr_range || dy != sr_range) {
-sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, 
dy, block_w, block_h);
+sad[dy][dx] = fc->vvcdsp.inter.sad[tab](lc->tmp, lc->tmp1, 
dx, dy, block_w, block_h);
 if (sad[dy][dx] < min_sad) {
 min_sad = sad[dy][dx];
 min_dx = dx;
diff --git a/libavcodec/vvc/inter_template.c b/libavcodec/vvc/inter_template.c
index a8068f4ba8..34485321d3 100644
--- a/libavcodec/vvc/inter_template.c
+++ b/libavcodec/vvc/inter_template.c
@@ -626,7 +626,11 @@ static void FUNC(ff_vvc_inter_dsp_init)(VVCInterDSPContext 
*const inter)
 inter->apply_prof_uni_w = FUNC(apply_prof_uni_w);
 inter->apply_bdof   = FUNC(apply_bdof);
 inter->prof_grad_filter = FUNC(prof_grad_filter);
-inter->sad  = vvc_sad;
+inter->sad[0]   =
+inter->sad[1]   =
+inter->sad[2]   =
+inter->sad[3]   =
+inter->sad[4]   = vvc_sad;
 }
 
 #undef FUNCS
diff --git a/libavcodec/x86/vvc/vvc_sad.asm b/libavcodec/x86/vvc/vvc_sad.asm
index b468d89ac2..a20818530f 100644
--- a/libavcodec/x86/vvc/vvc_sad.asm
+++ b/libavcodec/x86/vvc/vvc_sad.asm
@@ -51,7 +51,7 @@ SECTION .text
 
 INIT_YMM avx2
 
-cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
row_idx
+cglobal vvc_sad_8, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
row_idx
 movsxdifnidndxq, dxd
 movsxdifnidndyq, dyd
 
@@ -76,10 +76,6 @@ cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, row_
 pxor   m3, m3
 vpbroadcastd   m4, [pw_1]
 
-cmp  block_wd, 16
-jgevvc_sad_16_128
-
-vvc_sad_8:
 .loop_height:
 movu  xm0, [src1q]
 vinserti128m0, m0, [src1q + MAX_PB_SIZE * ROWS * 2], 1
@@ -100,7 +96,31 @@ cglobal vvc_sad, 6, 9, 5, src1, src2, dx, dy, block_w, 
block_h, off1, off2, row_
 movd  eax, xm0
 RET
 
-vvc_sad_16_128:
+cglobal vvc_sad_16, 6, 9, 5, src1, src2, dx, dy, block_w, block_h, off1, off2, 
row_idx
+movsxdifnidndxq, dxd
+movsxdifnidndyq, dyd
+
+sub dxq, 2
+sub dyq, 2
+
+mov off1q, 2
+mov off2q, 2
+
+add off1q, dyq
+sub off2q, dyq
+
+shl off1q, 7
+shl off2q, 7
+
+

Re: [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout

2024-05-23 Thread James Almer

On 5/23/2024 4:11 AM, Anton Khirnov wrote:

Quoting James Almer (2024-05-15 03:08:28)

Signed-off-by: James Almer 
---
  libavutil/channel_layout.c | 17 -
  libavutil/channel_layout.h | 10 ++
  2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index fd6718e0e7..e213f68666 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout 
*channel_layout)
  return 0;
  }
  
-/**

- * If the layout is n-th order standard-order ambisonic, with optional
- * extra non-diegetic channels at the end, return the order.
- * Return a negative error code otherwise.
- */
-static int ambisonic_order(const AVChannelLayout *channel_layout)
+int av_channel_layout_get_ambisonic_order(const AVChannelLayout 
*channel_layout)


IMO the _get_ in the name is just making it unnecessarily longer.


Ok, will remove it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v3 1/2] lavu/dovi_meta - add fields for ext_mapping_idc

2024-05-23 Thread Niklas Haas
On Wed, 22 May 2024 15:50:43 + Cosmin Stejerean via ffmpeg-devel 
 wrote:
> From: Cosmin Stejerean 
> 
> ---
>  libavutil/dovi_meta.h | 2 ++
>  libavutil/version.h   | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
> index e10332f8d7..e168075a24 100644
> --- a/libavutil/dovi_meta.h
> +++ b/libavutil/dovi_meta.h
> @@ -91,6 +91,8 @@ typedef struct AVDOVIRpuDataHeader {
>  uint8_t spatial_resampling_filter_flag;
>  uint8_t el_spatial_resampling_filter_flag;
>  uint8_t disable_residual_flag;
> +uint8_t ext_mapping_idc_0_4; /* extended base layer inverse mapping 
> indicator */
> +uint8_t ext_mapping_idc_5_7; /* reserved */
>  } AVDOVIRpuDataHeader;

What value ranges have you seen for this indicator? Is it possible that
some values would extend the RPU in other ways, adding more bits that we
need to parse?

Maybe we should enforce this to be a well-known value just to be on the
safe side, until we receive public documentation on its purpose.

>  
>  enum AVDOVIMappingMethod {
> 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.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 mailing list
ffmpeg-devel@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] avcodec/dovi - disable metadata compression by default

2024-05-23 Thread Niklas Haas
On Thu, 23 May 2024 03:45:44 + Cosmin Stejerean via ffmpeg-devel 
 wrote:
> From: Cosmin Stejerean 
> 
> not all clients support metadata compression, output when 
> vdr_dm_metadata_changed fails the DV verifier.
> ---
>  libavcodec/dovi_rpu.h| 10 ++
>  libavcodec/dovi_rpuenc.c |  8 ++--
>  libavcodec/libaomenc.c   |  3 +--
>  libavcodec/libsvtav1.c   |  3 +--
>  libavcodec/libx265.c |  3 +--
>  5 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
> index 8ce0c88e9d..dee34165c9 100644
> --- a/libavcodec/dovi_rpu.h
> +++ b/libavcodec/dovi_rpu.h
> @@ -28,6 +28,11 @@
>  #include "libavutil/frame.h"
>  #include "avcodec.h"
>  
> +#define DOVI_ENCODING_OPTS \
> +{ "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 },
> +

Nit: I would probably parametrize the base struct location (what you
hard-coded as `dovi`), just to avoid leaking per-encoder implementation
specifics. (Maybe somebody will decide to rename or move this struct
down the line)

Introducing this macro could probably be a separate commit also.

>  #define DOVI_MAX_DM_ID 15
>  typedef struct DOVIContext {
>  void *logctx;
> @@ -71,6 +76,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(>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(>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..3837eaaec2 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -1487,8 +1487,7 @@ static const AVOption options[] = {
>  { "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
> AOM_TUNE_SSIM}, 0, 0, VE, .unit = "tune"},
>  FF_AV1_PROFILE_OPTS
>  { "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" },
> +DOVI_ENCODING_OPTS
>  { "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..d747c31824 100644
> --- a/libavcodec/libsvtav1.c
> +++ b/libavcodec/libsvtav1.c
> @@ -731,8 +731,7 @@ static const AVOption options[] = {
>AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
>  { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated 
> list of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 
> 0, 0, 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" },
> +DOVI_ENCODING_OPTS
>  
>  {NULL},
>  };
> diff --git 

[FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg: rewrite checking whether codec AVOptions have been used

2024-05-23 Thread Anton Khirnov
Share the code between encoding and decoding. Instead of checking every
stream's options dictionary (which is also used for other purposes),
track all used options in a dedicated dictionary.
---
 fftools/cmdutils.c| 17 
 fftools/cmdutils.h|  4 ++-
 fftools/ffmpeg.c  | 49 ++
 fftools/ffmpeg.h  |  3 ++-
 fftools/ffmpeg_demux.c| 50 ---
 fftools/ffmpeg_mux.c  |  1 +
 fftools/ffmpeg_mux.h  |  3 +++
 fftools/ffmpeg_mux_init.c | 55 +--
 fftools/ffmpeg_opt.c  | 18 -
 fftools/ffplay.c  |  2 +-
 fftools/ffprobe.c |  2 +-
 11 files changed, 89 insertions(+), 115 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index a8f5c6d89b..265ce5c04c 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -986,7 +986,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream 
*st, const char *spec)
 
 int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
   AVFormatContext *s, AVStream *st, const AVCodec *codec,
-  AVDictionary **dst)
+  AVDictionary **dst, AVDictionary **opts_used)
 {
 AVDictionary*ret = NULL;
 const AVDictionaryEntry *t = NULL;
@@ -1013,6 +1013,7 @@ int filter_codec_opts(const AVDictionary *opts, enum 
AVCodecID codec_id,
 while (t = av_dict_iterate(opts, t)) {
 const AVClass *priv_class;
 char *p = strchr(t->key, ':');
+int used = 0;
 
 /* check stream specification in opt name */
 if (p) {
@@ -1030,15 +1031,21 @@ int filter_codec_opts(const AVDictionary *opts, enum 
AVCodecID codec_id,
 !codec ||
 ((priv_class = codec->priv_class) &&
  av_opt_find(_class, t->key, NULL, flags,
- AV_OPT_SEARCH_FAKE_OBJ)))
+ AV_OPT_SEARCH_FAKE_OBJ))) {
 av_dict_set(, t->key, t->value, 0);
-else if (t->key[0] == prefix &&
+used = 1;
+} else if (t->key[0] == prefix &&
  av_opt_find(, t->key + 1, NULL, flags,
- AV_OPT_SEARCH_FAKE_OBJ))
+ AV_OPT_SEARCH_FAKE_OBJ)) {
 av_dict_set(, t->key + 1, t->value, 0);
+used = 1;
+}
 
 if (p)
 *p = ':';
+
+if (used && opts_used)
+av_dict_set(opts_used, t->key, "", 0);
 }
 
 *dst = ret;
@@ -1063,7 +1070,7 @@ int setup_find_stream_info_opts(AVFormatContext *s,
 
 for (int i = 0; i < s->nb_streams; i++) {
 ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
-s, s->streams[i], NULL, [i]);
+s, s->streams[i], NULL, [i], NULL);
 if (ret < 0)
 goto fail;
 }
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index d0c773663b..5966501d84 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -371,11 +371,13 @@ int check_stream_specifier(AVFormatContext *s, AVStream 
*st, const char *spec);
  * @param codec The particular codec for which the options should be filtered.
  *  If null, the default one is looked up according to the codec 
id.
  * @param dst a pointer to the created dictionary
+ * @param opts_used if non-NULL, every option stored in dst is also stored 
here,
+ *  with specifiers preserved
  * @return a non-negative number on success, a negative error code on failure
  */
 int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
   AVFormatContext *s, AVStream *st, const AVCodec *codec,
-  AVDictionary **dst);
+  AVDictionary **dst, AVDictionary **opts_used);
 
 /**
  * Setup AVCodecContext options for avformat_find_stream_info().
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c86fd5065e..5e27f073aa 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -493,6 +493,55 @@ int check_avoptions(AVDictionary *m)
 return 0;
 }
 
+int check_avoptions_used(const AVDictionary *opts, const AVDictionary 
*opts_used,
+ void *logctx, int decode)
+{
+const AVClass  *class = avcodec_get_class();
+const AVClass *fclass = avformat_get_class();
+
+const int flag = decode ? AV_OPT_FLAG_DECODING_PARAM :
+  AV_OPT_FLAG_ENCODING_PARAM;
+const AVDictionaryEntry *e = NULL;
+
+while ((e = av_dict_iterate(opts, e))) {
+const AVOption *option, *foption;
+char *optname, *p;
+
+optname = av_strdup(e->key);
+if (!optname)
+return AVERROR(ENOMEM);
+
+p = strchr(optname, ':');
+if (p)
+*p = 0;
+
+option = av_opt_find(, optname, NULL, 0,
+ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
+

[FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg_mux_init: make encoder_opts local to ost_add()

2024-05-23 Thread Anton Khirnov
It is no longer needed after this function returns.
---
 fftools/ffmpeg.h  |  2 --
 fftools/ffmpeg_mux.c  |  1 -
 fftools/ffmpeg_mux_init.c | 71 ++-
 3 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9cab8148ca..51aee0679a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -586,8 +586,6 @@ typedef struct OutputStream {
 FilterGraph  *fg_simple;
 OutputFilter *filter;
 
-AVDictionary *encoder_opts;
-
 char *attachment_filename;
 
 /* stats */
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 055e2f3678..de3e052152 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -813,7 +813,6 @@ static void ost_free(OutputStream **post)
 av_packet_free(>bsf_pkt);
 
 av_packet_free(>pkt);
-av_dict_free(>encoder_opts);
 
 av_freep(>kf.pts);
 av_expr_free(ost->kf.pexpr);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 61a0d8658f..b8dc6017a9 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -905,7 +905,7 @@ static int new_stream_subtitle(Muxer *mux, const 
OptionsContext *o,
 return 0;
 }
 
-static int streamcopy_init(const Muxer *mux, OutputStream *ost)
+static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary 
**encoder_opts)
 {
 MuxStream   *ms = ms_from_ost(ost);
 
@@ -928,7 +928,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 
 ret = avcodec_parameters_to_context(codec_ctx, ist->par);
 if (ret >= 0)
-ret = av_opt_set_dict(codec_ctx, >encoder_opts);
+ret = av_opt_set_dict(codec_ctx, encoder_opts);
 if (ret < 0) {
 av_log(ost, AV_LOG_FATAL,
"Error setting up codec context options.\n");
@@ -1039,6 +1039,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 OutputStream *ost;
 const AVCodec *enc;
 AVStream *st;
+AVDictionary *encoder_opts = NULL;
 int ret = 0, keep_pix_fmt = 0, autoscale = 1;
 int threads_manual = 0;
 AVRational enc_tb = { 0, 0 };
@@ -1160,10 +1161,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 const char *enc_time_base = NULL;
 
 ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
-oc, st, enc->codec, >encoder_opts,
+oc, st, enc->codec, _opts,
 >enc_opts_used);
 if (ret < 0)
-return ret;
+goto fail;
 
 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
 
@@ -1187,7 +1188,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 break;
 }
 *arg++ = 0;
-av_dict_set(>encoder_opts, buf, arg, 
AV_DICT_DONT_OVERWRITE);
+av_dict_set(_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
 } while (!s->eof_reached);
 av_bprint_finalize(, NULL);
 avio_closep();
@@ -1195,7 +1196,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 if (ret) {
 av_log(ost, AV_LOG_FATAL,
"Preset %s specified, but could not be opened.\n", preset);
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
@@ -1207,7 +1208,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >enc_stats_pre, 1, enc_stats_pre, 
format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
@@ -1219,7 +1220,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >enc_stats_post, 0, enc_stats_post, 
format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
@@ -1231,7 +1232,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >stats, 0, mux_stats, format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
@@ -1253,7 +1254,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 #endif
 ) {
 av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", 
enc_time_base);
-return ret < 0 ? ret : AVERROR(EINVAL);
+ret = ret < 0 ? ret : AVERROR(EINVAL);
+goto fail;
 }
 #if FFMPEG_OPT_ENC_TIME_BASE_NUM
 

[FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg_mux_init: apply encoder options manually

2024-05-23 Thread Anton Khirnov
Do not pass an options dictionary to the avcodec_open2() in enc_open().

This is cleaner and more robust, as previously various bits of code
would try to interpret the contents of the options dictionary, with
varying degrees of correctness. Now they can just access the encoder
AVCodecContext directly.

Cf. 372c78dd42f2b1ca743473b9c32fad71c65919e0 - analogous change for
decoding.

A non-progressive field order is now written on the container level in
interlaced ProRes encoding tests.
---
 fftools/ffmpeg_enc.c| 18 ++
 fftools/ffmpeg_mux_init.c   | 66 +++--
 tests/ref/vsynth/vsynth1-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth1-prores_int |  2 +-
 tests/ref/vsynth/vsynth2-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth2-prores_int |  2 +-
 tests/ref/vsynth/vsynth3-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth3-prores_int |  2 +-
 tests/ref/vsynth/vsynth_lena-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth_lena-prores_int |  2 +-
 10 files changed, 47 insertions(+), 53 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 618ba193ff..029980063d 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -307,16 +307,10 @@ int enc_open(void *opaque, const AVFrame *frame)
 if (ost->bitexact)
 enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
 
-if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
-av_dict_set(>encoder_opts, "threads", "auto", 0);
+if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE)
+enc_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
 
-if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) {
-ret = av_dict_set(>encoder_opts, "flags", "+copy_opaque", 
AV_DICT_MULTIKEY);
-if (ret < 0)
-return ret;
-}
-
-av_dict_set(>encoder_opts, "flags", "+frame_duration", 
AV_DICT_MULTIKEY);
+enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION;
 
 ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL);
 if (ret < 0) {
@@ -325,7 +319,7 @@ int enc_open(void *opaque, const AVFrame *frame)
 return ret;
 }
 
-if ((ret = avcodec_open2(ost->enc_ctx, enc, >encoder_opts)) < 0) {
+if ((ret = avcodec_open2(ost->enc_ctx, enc, NULL)) < 0) {
 if (ret != AVERROR_EXPERIMENTAL)
 av_log(ost, AV_LOG_ERROR, "Error while opening encoder - maybe "
"incorrect parameters such as bit_rate, rate, width or 
height.\n");
@@ -337,10 +331,6 @@ int enc_open(void *opaque, const AVFrame *frame)
 if (ost->enc_ctx->frame_size)
 frame_samples = ost->enc_ctx->frame_size;
 
-ret = check_avoptions(ost->encoder_opts);
-if (ret < 0)
-return ret;
-
 if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 &&
 ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 
700 bit/s modes */)
 av_log(ost, AV_LOG_WARNING, "The bitrate parameter is set too low."
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 41afe8259d..61a0d8658f 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -711,14 +711,10 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 /* two pass mode */
 MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
 if (do_pass) {
-if (do_pass & 1) {
+if (do_pass & 1)
 video_enc->flags |= AV_CODEC_FLAG_PASS1;
-av_dict_set(>encoder_opts, "flags", "+pass1", 
AV_DICT_APPEND);
-}
-if (do_pass & 2) {
+if (do_pass & 2)
 video_enc->flags |= AV_CODEC_FLAG_PASS2;
-av_dict_set(>encoder_opts, "flags", "+pass2", 
AV_DICT_APPEND);
-}
 }
 
 MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
@@ -740,7 +736,10 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
DEFAULT_PASS_LOGFILENAME_PREFIX,
  ost_idx);
 if (!strcmp(ost->enc_ctx->codec->name, "libx264")) {
-av_dict_set(>encoder_opts, "stats", logfilename, 
AV_DICT_DONT_OVERWRITE);
+if (av_opt_is_set_to_default_by_name(ost->enc_ctx, "stats",
+ AV_OPT_SEARCH_CHILDREN) > 
0)
+av_opt_set(ost->enc_ctx, "stats", logfilename,
+   AV_OPT_SEARCH_CHILDREN);
 } else {
 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
 char  *logbuffer = file_read(logfilename);
@@ -1041,6 +1040,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 const AVCodec *enc;
 AVStream *st;
 int ret = 0, keep_pix_fmt = 0, autoscale = 1;
+int threads_manual = 0;
 AVRational enc_tb = { 0, 0 };
 enum VideoSyncMethod vsync_method 

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

2024-05-23 Thread Anton Khirnov
It conflicts with the AVCodecContext option of the same name.
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index e3eb083746..d69dd19049 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -139,7 +139,7 @@
 { "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100 
frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 
UINT16_MAX, VE },
 
 #define QSV_OPTION_SKIP_FRAME \
-{ "skip_frame", "Allow frame skipping", OFFSET(qsv.skip_frame),  
AV_OPT_TYPE_INT, { .i64 = MFX_SKIPFRAME_NO_SKIP }, \
+{ "qsv_skip_frame", "Allow frame skipping", OFFSET(qsv.skip_frame),  
AV_OPT_TYPE_INT, { .i64 = MFX_SKIPFRAME_NO_SKIP }, \
MFX_SKIPFRAME_NO_SKIP, MFX_SKIPFRAME_BRC_ONLY, VE, .unit = "skip_frame" }, \
 { "no_skip","Frame skipping is disabled", \
 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SKIPFRAME_NO_SKIP },   .flags = 
VE, .unit = "skip_frame" },\
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr

On 5/23/24 2:13 PM, Andreas Rheinhardt wrote:

llyyr.pub...@gmail.com:

From: llyyr 

Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811


You should probably not link to HEAD here, because the line number will
be wrong in the future.



Should I resent the patch with a v3 or could whoever applies the patch 
fix it when applying it? The correct url is 
https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/2e877090f958131accb8c7e5ac10e5b9865d1735:/libavcodec/vp8.c#l797


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

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


Re: [FFmpeg-devel] [PATCH v2] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread Andreas Rheinhardt
llyyr.pub...@gmail.com:
> From: llyyr 
> 
> Fields under the segmentation switch are never reset on a new frame, and
> retain the value from the previous frame. This bugs out a bunch of
> hwaccel drivers when segmentation is disabled but update_map isn't
> reset because they don't ignore values behind switches. This commit also
> resets the temporal field, though it may not be required.
> 
> We also do this for vp8 [1] so this commit is just mirroring the vp8
> logic.
> 
> This fixes an issue with certain samples [2] that causes blocky
> artifacts with vaapi, d3d11va and cuda (and possibly others).
> Mesa worked around [3] this by ignoring these fields if
> segmentation.enabled is 0, but d3d11va still displays blocky artifacts.
> 
> [1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811

You should probably not link to HEAD here, because the line number will
be wrong in the future.

> [2] https://github.com/mpv-player/mpv/issues/13533
> [3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816
> 
> Signed-off-by: llyyr 
> ---
>  libavcodec/vp9.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> index 6e2d18bf9595..8ede2e2eb358 100644
> --- a/libavcodec/vp9.c
> +++ b/libavcodec/vp9.c
> @@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
>  s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
>  }
>  }
> +} else {
> +// Reset fields under segmentation switch if segmentation is 
> disabled.
> +// This is necessary because some hwaccels don't ignore these fields
> +// if segmentation is disabled.
> +s->s.h.segmentation.temporal = 0;
> +s->s.h.segmentation.update_map = 0;
>  }
>  
>  // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas

___
ffmpeg-devel mailing list
ffmpeg-devel@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/5] avfilter/af_atempo: Simplify resetting

2024-05-23 Thread Andreas Rheinhardt
Pavel Koshevoy:
> On Wed, May 22, 2024, 02:59 Andreas Rheinhardt <
> andreas.rheinha...@outlook.com> wrote:
> 
>> The earlier code distinguished between a partial reset
>> (yae_clear()) and a complete reset (yae_release_buffers()
>> which also releases the buffers); this separation existed
>> to avoid allocations, as buffers were reallocated on reconfigs.
>>
>> Yet it is pointless since a5704659e3e41b7698812b89f67d9a7467a74d20,
>> so simply use yae_release_buffers() everywhere.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavfilter/af_atempo.c | 69 +
>>  1 file changed, 35 insertions(+), 34 deletions(-)
>>
>> diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
>> index 1aedb82060..110f792eec 100644
>> --- a/libavfilter/af_atempo.c
>> +++ b/libavfilter/af_atempo.c
>> @@ -244,18 +244,6 @@ static void yae_release_buffers(ATempoContext *atempo)
>>  av_tx_uninit(>complex_to_real);
>>  }
>>
>> -/* av_realloc is not aligned enough; fortunately, the data does not need
>> to
>> - * be preserved */
>> -#define RE_MALLOC_OR_FAIL(field, field_size, element_size)  \
>> -do {\
>> -av_freep();   \
>> -field = av_calloc(field_size, element_size);\
>> -if (!field) {   \
>> -yae_release_buffers(atempo);\
>> -return AVERROR(ENOMEM); \
>> -}   \
>> -} while (0)
>> -
>>  /**
>>   * Prepare filter for processing audio data of given format,
>>   * sample rate and number of channels.
>> @@ -289,40 +277,51 @@ static int yae_reset(ATempoContext *atempo,
>>  nlevels++;
>>  }
>>
>> +/* av_realloc is not aligned enough, so simply discard all the old
>> buffers
>> + * (fortunately, their data does not need to be preserved) */
>> +yae_release_buffers(atempo);
>> +
>>  // initialize audio fragment buffers:
>> -RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window,
>> atempo->stride);
>> -RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window,
>> atempo->stride);
>> -RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1),
>> sizeof(AVComplexFloat));
>> -RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1),
>> sizeof(AVComplexFloat));
>> -RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, (atempo->window + 1),
>> sizeof(AVComplexFloat));
>> -RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, (atempo->window + 1),
>> sizeof(AVComplexFloat));
>> +if (!(atempo->frag[0].data= av_calloc(atempo->window,
>> atempo->stride)) ||
>> +!(atempo->frag[1].data= av_calloc(atempo->window,
>> atempo->stride)) ||
>> +!(atempo->frag[0].xdat_in = av_calloc(atempo->window + 1,
>> sizeof(AVComplexFloat))) ||
>> +!(atempo->frag[1].xdat_in = av_calloc(atempo->window + 1,
>> sizeof(AVComplexFloat))) ||
>> +!(atempo->frag[0].xdat= av_calloc(atempo->window + 1,
>> sizeof(AVComplexFloat))) ||
>> +!(atempo->frag[1].xdat= av_calloc(atempo->window + 1,
>> sizeof(AVComplexFloat {
>> +ret = AVERROR(ENOMEM);
>> +goto fail;
>> +}
>>
>>  // initialize rDFT contexts:
>> -av_tx_uninit(>real_to_complex);
>> -av_tx_uninit(>complex_to_real);
>> -
>>  ret = av_tx_init(>real_to_complex, >r2c_fn,
>>   AV_TX_FLOAT_RDFT, 0, 1 << (nlevels + 1), , 0);
>> -if (ret < 0) {
>> -yae_release_buffers(atempo);
>> -return ret;
>> -}
>> +if (ret < 0)
>> +goto fail;
>>
>>  ret = av_tx_init(>complex_to_real, >c2r_fn,
>>   AV_TX_FLOAT_RDFT, 1, 1 << (nlevels + 1), , 0);
>> -if (ret < 0) {
>> -yae_release_buffers(atempo);
>> -return ret;
>> -}
>> +if (ret < 0)
>> +goto fail;
>>
>> -RE_MALLOC_OR_FAIL(atempo->correlation_in, (atempo->window + 1),
>> sizeof(AVComplexFloat));
>> -RE_MALLOC_OR_FAIL(atempo->correlation, atempo->window,
>> sizeof(AVComplexFloat));
>> +if (!(atempo->correlation_in = av_calloc(atempo->window + 1,
>> sizeof(AVComplexFloat))) ||
>> +!(atempo->correlation= av_calloc(atempo->window,
>>  sizeof(AVComplexFloat {
>> +ret = AVERROR(ENOMEM);
>> +goto fail;
>> +}
>>
>>  atempo->ring = atempo->window * 3;
>> -RE_MALLOC_OR_FAIL(atempo->buffer, atempo->ring, atempo->stride);
>> +atempo->buffer = av_calloc(atempo->ring, atempo->stride);
>> +if (!atempo->buffer) {
>> +ret = AVERROR(ENOMEM);
>> +goto fail;
>> +}
>>
>>  // initialize the Hann window function:
>> -RE_MALLOC_OR_FAIL(atempo->hann, atempo->window, sizeof(float));
>> +atempo->hann = av_malloc_array(atempo->window, sizeof(float));
>> +if (!atempo->hann) {
>> +ret = AVERROR(ENOMEM);
>> +  

[FFmpeg-devel] [PATCH v2] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr . public
From: llyyr 

Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811
[2] https://github.com/mpv-player/mpv/issues/13533
[3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816

Signed-off-by: llyyr 
---
 libavcodec/vp9.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6e2d18bf9595..8ede2e2eb358 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
 }
 }
+} else {
+// Reset fields under segmentation switch if segmentation is disabled.
+// This is necessary because some hwaccels don't ignore these fields
+// if segmentation is disabled.
+s->s.h.segmentation.temporal = 0;
+s->s.h.segmentation.update_map = 0;
 }
 
 // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas
-- 
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".


Re: [FFmpeg-devel] [PATCH] lavc/rv34dsp: optimise R-V V idct_dc_add

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


Le 23 mai 2024 06:31:52 GMT+03:00, flow gg  a écrit :
>Unfortunately I only test to obtain benchmarks and basic correctness. I
>always feel the need for a professional to write the tests.

Everybody agrees that tests should be written alongside the corresponding DSP C 
reference functions, but we can't go back in time and make it happen for 
existing code.

In my experience, nobody funds audio and old video codec optimisations, so the 
chances that checkasm tests would be written professionally are unfortunately 
slim. Likewise getting rid of MMX legacy optimisations.

For RVV, I am aware of funding for H.264 only. I hope that H.265 could get 
funded afterwards but that's just my hope. H.266 and VP9 won't be funded since 
you're already working on them, and everything else is probably too old to get 
attention. So colour me pessimistic for getting funding there :-(



FWIW, beware that people will tend to assume that you are a professional if you 
assign copyright to a legal entity, even if there is another nonobvious reason 
why you do that.

>Rémi Denis-Courmont  于2024年5月23日周四 04:35写道:
>
>>
>>
>> Le 22 mai 2024 23:28:54 GMT+03:00, "Rémi Denis-Courmont" 
>> a écrit :
>> >This removes one stray LI and reworks the vector arithmetic to avoid
>> >changing the vector configuration. On K230, this takes the 46.5 cycle
>> >count down from 46.5 to 43.5.
>> >---
>> > libavcodec/riscv/rv34dsp_rvv.S | 13 ++---
>> > 1 file changed, 6 insertions(+), 7 deletions(-)
>> >
>> >diff --git a/libavcodec/riscv/rv34dsp_rvv.S
>> b/libavcodec/riscv/rv34dsp_rvv.S
>> >index f1f6345012..e8aff7e570 100644
>> >--- a/libavcodec/riscv/rv34dsp_rvv.S
>> >+++ b/libavcodec/riscv/rv34dsp_rvv.S
>> >@@ -36,16 +36,15 @@ func ff_rv34_idct_dc_add_rvv, zve32x
>> > vsetivli  zero, 4, e8, mf4, ta, ma
>> > vlse32.v  v0, (a0), a1
>> > lit1, 169
>> >+lit2, 128
>> > mul   t1, t1, a2
>> >-lia2, 255
>> >+vsetivli  zero, 4*4, e8, m1, ta, ma
>> >+vwsubu.vx v2, v0, t2
>> > addi  t1, t1, 512
>> > srai  t1, t1, 10
>> >-vsetivli  zero, 4*4, e16, m2, ta, ma
>> >-vzext.vf2 v2, v0
>> >-vadd.vx   v2, v2, t1
>> >-vmax.vx   v2, v2, zero
>> >-vsetvli   zero, zero, e8, m1, ta, ma
>> >-vnclipu.wiv0, v2, 0
>> >+vwadd.wx  v2, v2, t1
>>
>> Hmm, this should not work, as t1 has more than 8 bits. Maybe checkasm is
>> sloppy here.
>>
>> >+vnclip.wi v0, v2, 0
>> >+vxor.vx   v0, v0, t2
>> > vsetivli  zero, 4, e8, mf4, ta, ma
>> > vsse32.v  v0, (a0), a1
>> >
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@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 mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr . public
From: llyyr 

Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811
[2] https://github.com/mpv-player/mpv/issues/13533
[3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816

Signed-off-by: llyyr 
---
 libavcodec/vp9.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6e2d18bf9595..8ede2e2eb358 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
 }
 }
+} else {
+// Reset fields under segmentation switch if segmentation is disabled.
+// This is necessary because some hwaccels don't ignore these fields
+// if segmentation is disabled.
+s->s.h.segmentation.temporal = 0;
+s->s.h.segmentation.update_map = 0;
 }
 
 // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas
-- 
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] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr . public
From: llyyr 

Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811
[2] https://github.com/mpv-player/mpv/issues/13533
[3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816

Signed-off-by: llyyr 
---
 libavcodec/vp9.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6e2d18bf9595..8ede2e2eb358 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
 }
 }
+} else {
+// Reset fields under segmentation switch if segmentation is disabled.
+// This is necessary because some hwaccels don't ignore these fields
+// if segmentation is disabled.
+s->s.h.segmentation.temporal = 0;
+s->s.h.segmentation.update_map = 0;
 }
 
 // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas
-- 
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 v2] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr
Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811
[2] https://github.com/mpv-player/mpv/issues/13533
[3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816

Signed-off-by: llyyr 
---
 libavcodec/vp9.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6e2d18bf9595..8ede2e2eb358 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
 }
 }
+} else {
+// Reset fields under segmentation switch if segmentation is disabled.
+// This is necessary because some hwaccels don't ignore these fields
+// if segmentation is disabled.
+s->s.h.segmentation.temporal = 0;
+s->s.h.segmentation.update_map = 0;
 }
 
 // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas

base-commit: 2e877090f958131accb8c7e5ac10e5b9865d1735
-- 
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 v2] lavc/vp9: reset segmentation fields when segmentation isn't enabled

2024-05-23 Thread llyyr
Fields under the segmentation switch are never reset on a new frame, and
retain the value from the previous frame. This bugs out a bunch of
hwaccel drivers when segmentation is disabled but update_map isn't
reset because they don't ignore values behind switches. This commit also
resets the temporal field, though it may not be required.

We also do this for vp8 [1] so this commit is just mirroring the vp8
logic.

This fixes an issue with certain samples [2] that causes blocky
artifacts with vaapi, d3d11va and cuda (and possibly others).
Mesa worked around [3] this by ignoring these fields if
segmentation.enabled is 0, but d3d11va still displays blocky artifacts.

[1] https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/vp8.c#l811
[2] https://github.com/mpv-player/mpv/issues/13533
[3] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27816

Signed-off-by: llyyr 
---
 libavcodec/vp9.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 6e2d18bf9595..8ede2e2eb358 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -709,6 +709,12 @@ static int decode_frame_header(AVCodecContext *avctx,
 s->s.h.segmentation.feat[i].skip_enabled = get_bits1(>gb);
 }
 }
+} else {
+// Reset fields under segmentation switch if segmentation is disabled.
+// This is necessary because some hwaccels don't ignore these fields
+// if segmentation is disabled.
+s->s.h.segmentation.temporal = 0;
+s->s.h.segmentation.update_map = 0;
 }
 
 // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas

base-commit: 2e877090f958131accb8c7e5ac10e5b9865d1735
-- 
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".


Re: [FFmpeg-devel] [PATCH 7/7] avcodec/tests/bitstream_template: Make it clear that the return is intentionally not checked

2024-05-23 Thread Andreas Rheinhardt
Michael Niedermayer:
> Helps: CID1518967 Unchecked return value
> Helps: CID1518968 Unchecked return value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/tests/bitstream_template.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/tests/bitstream_template.c 
> b/libavcodec/tests/bitstream_template.c
> index ef59845154d..d8cf980bee1 100644
> --- a/libavcodec/tests/bitstream_template.c
> +++ b/libavcodec/tests/bitstream_template.c
> @@ -74,7 +74,7 @@ int main(int argc, char **argv)
>  for (unsigned i = 0; i < SIZE; i++)
>  buf[i] = av_lfg_get();
>  
> -bits_init8   (, buf, SIZE);
> +(void)bits_init8   (, buf, SIZE);
>  init_put_bits(, dst, SIZE);
>  
>  /* use a random sequence of bitreading operations to transfer data

Test tools should actually test.

- 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] fftools/ffprobe: Avoid overflow when calculating DAR

2024-05-23 Thread Anton Khirnov
Quoting Derek Buitenhuis (2024-05-03 18:36:23)
> Both the codecpar's width and height, and the SAR num and den are
> ints, which can overflow. Cast to int64_t, which is what av_reduce
> takes.
> 
> Without this, occasionally, display_aspect_ratio can be negative in
> ffprobe's -show_stream output.
> 
> Signed-off-by: Derek Buitenhuis 
> ---
>  fftools/ffprobe.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 0d4cd0b048..5b40dad527 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -3324,8 +3324,8 @@ static int show_stream(WriterContext *w, 
> AVFormatContext *fmt_ctx, int stream_id
>  if (sar.num) {
>  print_q("sample_aspect_ratio", sar, ':');
>  av_reduce(, ,
> -  par->width  * sar.num,
> -  par->height * sar.den,
> +  (int64_t) par->width  * sar.num,
> +  (int64_t) par->height * sar.den,

Aren't we supposed to avoid assumptions that int is always strictly
smaller than 64bit?

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

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


Re: [FFmpeg-devel] [PATCH] avfilter/src_movie: Remove align dimension to fix crash

2024-05-23 Thread Anton Khirnov
Quoting Paul B Mahol (2024-05-11 15:48:08)
> Any next filter after (a)movie filter that calls ff_null_get_video_buffer()
> will not? work and using
> ff_default_get_video_buffer() will allocate new frame.
> 
> Original idea was/is to improve performance by using DR support provided by
> decoders.

As I remember, the original intent behind lavfi get_buffer functions
was:

1) Allow a downstream filter like pad to allocate a larger frame in
order to avoid copying.

2) Allow direct rendering into caller-provided buffers (currently not
supported).

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

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


Re: [FFmpeg-devel] [RFC PATCH] avfilter/video: Protect frame_pool from multi-threads access

2024-05-23 Thread Anton Khirnov
Quoting Zhao Zhili (2024-05-11 06:45:12)
> 
> > On May 10, 2024, at 16:57, Zhao Zhili  wrote:
> > 
> > From: Zhao Zhili 
> > 
> > Fix crash with
> > ./ffplay -f lavfi -i movie=foo.mp4,drawtext=text=bar
> 
> This is an RFC because I’m not sure whether it’s a valid use case or not to 
> call
>  ff_default_get_video_buffer2 from multiple threads. On one hand, it’s rare 
> used
> with multithreads. On the other hand, it can be hidden deep and dangerous.

Naively it sounds like something that should not happen, since lavfi
only has slice threading and slice threads should not allocate frames.

In your example it seems to happen because of frame threading in the
movie source, but that should ideally be handled inside that filter.

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout

2024-05-23 Thread Anton Khirnov
Quoting James Almer (2024-05-15 03:08:28)
> Signed-off-by: James Almer 
> ---
>  libavutil/channel_layout.c | 17 -
>  libavutil/channel_layout.h | 10 ++
>  2 files changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
> index fd6718e0e7..e213f68666 100644
> --- a/libavutil/channel_layout.c
> +++ b/libavutil/channel_layout.c
> @@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout 
> *channel_layout)
>  return 0;
>  }
>  
> -/**
> - * If the layout is n-th order standard-order ambisonic, with optional
> - * extra non-diegetic channels at the end, return the order.
> - * Return a negative error code otherwise.
> - */
> -static int ambisonic_order(const AVChannelLayout *channel_layout)
> +int av_channel_layout_get_ambisonic_order(const AVChannelLayout 
> *channel_layout)

IMO the _get_ in the name is just making it unnecessarily longer.

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

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


[FFmpeg-devel] [PATCH 2/3] avcodec/mediacodecenc: workaround the alignment requirement only for H.264

2024-05-23 Thread Zhao Zhili
From: Zhao Zhili 

There is no bsf for other codecs to modify crop info except H.265.
For H.265, the assumption that FFALIGN(width, 16)xFFALIGN(height, 16)
is the video resolution can be wrong, since the encoder can use CTU
larger than 16x16. In that case, use FFALIGN(width, 16) - width
as crop_right is incorrect. So disable the workaround for H.265 now.
---
 libavcodec/mediacodecenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index bbf570e7be..bfff149039 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -234,7 +234,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 ff_AMediaFormat_setString(format, "mime", codec_mime);
 // Workaround the alignment requirement of mediacodec. We can't do it
 // silently for AV_PIX_FMT_MEDIACODEC.
-if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) {
+if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
+avctx->codec_id == AV_CODEC_ID_H264) {
 s->width = FFALIGN(avctx->width, 16);
 s->height = FFALIGN(avctx->height, 16);
 } else {
-- 
2.42.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 1/3] avcodec/h265_metadata: Add options to set width/height after crop

2024-05-23 Thread Zhao Zhili
From: Zhao Zhili 

It's a common usecase to request a video size after crop. Before
this patch, user must know the video size before crop, then set
crop_right/crop_bottom accordingly. Since HEVC can have different
CTU size, it's not easy to get/deduce the video size before crop.
With the new width/height options, there is no such requirement.

Signed-off-by: Zhao Zhili 
---
 doc/bitstream_filters.texi |   4 ++
 libavcodec/bsf/h265_metadata.c | 101 -
 libavcodec/version.h   |   2 +-
 3 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 3d4dda04fc..c03f04f858 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -456,6 +456,10 @@ will replace the current ones if the stream is already 
cropped.
 These fields are set in pixels.  Note that some sizes may not be
 representable if the chroma is subsampled (H.265 section 7.4.3.2.1).
 
+@item width
+@item height
+Set width and height after crop.
+
 @item level
 Set the level in the VPS and SPS.  See H.265 section A.4 and tables
 A.6 and A.7.
diff --git a/libavcodec/bsf/h265_metadata.c b/libavcodec/bsf/h265_metadata.c
index c9e1cc3eed..eba00c20d5 100644
--- a/libavcodec/bsf/h265_metadata.c
+++ b/libavcodec/bsf/h265_metadata.c
@@ -58,6 +58,8 @@ typedef struct H265MetadataContext {
 int crop_right;
 int crop_top;
 int crop_bottom;
+int width;
+int height;
 
 int level;
 int level_guess;
@@ -187,12 +189,94 @@ static int h265_metadata_update_vps(AVBSFContext *bsf,
 return 0;
 }
 
+static int h265_metadata_deduce_crop(AVBSFContext *bsf, const H265RawSPS *sps,
+ int *crop_left, int *crop_right,
+ int *crop_top, int *crop_bottom)
+{
+const H265MetadataContext *ctx = bsf->priv_data;
+int left = ctx->crop_left;
+int right = ctx->crop_right;
+int top = ctx->crop_top;
+int bottom = ctx->crop_bottom;
+
+if (ctx->width > 0) {
+if (ctx->width > sps->pic_width_in_luma_samples) {
+av_log(bsf, AV_LOG_ERROR,
+   "The width option value %d is larger than picture width 
%d\n",
+   ctx->width, sps->pic_width_in_luma_samples);
+return AVERROR(EINVAL);
+}
+
+if (left < 0) {
+if (right > 0)
+left = sps->pic_width_in_luma_samples - ctx->width - right;
+else
+left = 0;
+}
+
+if (right < 0)
+right = sps->pic_width_in_luma_samples - ctx->width - left;
+
+if (left < 0 || right < 0 || (left + right + ctx->width) !=
+sps->pic_width_in_luma_samples) {
+av_log(bsf, AV_LOG_ERROR,
+   "Invalid value for crop_left %d, crop_right %d, width after 
"
+   "crop %d, with picture width %d\n",
+   ctx->crop_left, ctx->crop_right, ctx->width,
+   sps->pic_width_in_luma_samples);
+return AVERROR(EINVAL);
+}
+}
+
+if (ctx->height > 0) {
+if (ctx->height > sps->pic_height_in_luma_samples) {
+av_log(bsf, AV_LOG_ERROR,
+   "The height option value %d is larger than picture height 
%d\n",
+   ctx->height, sps->pic_height_in_luma_samples);
+return AVERROR(EINVAL);
+}
+
+if (top < 0) {
+if (bottom > 0)
+top = sps->pic_height_in_luma_samples - ctx->height - bottom;
+else
+top = 0;
+}
+
+if (bottom < 0)
+bottom = sps->pic_height_in_luma_samples - ctx->height - top;
+
+if (top < 0 || bottom < 0 || (top + bottom + ctx->height) !=
+sps->pic_height_in_luma_samples) {
+av_log(bsf, AV_LOG_ERROR,
+   "Invalid value for crop_top %d, crop_bottom %d, height 
after "
+   "crop %d, with picture height %d\n",
+   ctx->crop_top, ctx->crop_bottom, ctx->height,
+   sps->pic_height_in_luma_samples);
+return AVERROR(EINVAL);
+}
+}
+
+*crop_left = left;
+*crop_right = right;
+*crop_top = top;
+*crop_bottom = bottom;
+
+return 0;
+}
+
 static int h265_metadata_update_sps(AVBSFContext *bsf,
 H265RawSPS *sps)
 {
 H265MetadataContext *ctx = bsf->priv_data;
 int need_vui = 0;
 int crop_unit_x, crop_unit_y;
+/* Use local variables to avoid modifying context fields in case of video
+ * resolution changed. Crop doesn't work well with resolution change, this
+ * is the best we can do.
+ */
+int crop_left, crop_right, crop_top, crop_bottom;
+int ret;
 
 if (ctx->sample_aspect_ratio.num && ctx->sample_aspect_ratio.den) {
 int num, den, i;
@@ -289,6 +373,11 @@ static int h265_metadata_update_sps(AVBSFContext *bsf,
 

[FFmpeg-devel] [PATCH 3/3] avcodec/mediacodecenc: workaround the alignment requirement for H.265

2024-05-23 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 libavcodec/mediacodecenc.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index bfff149039..a42270551b 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -154,8 +154,12 @@ static int mediacodec_init_bsf(AVCodecContext *avctx)
 ret = snprintf(str, sizeof(str), 
"h264_metadata=crop_right=%d:crop_bottom=%d",
crop_right, crop_bottom);
 else if (avctx->codec_id == AV_CODEC_ID_HEVC)
-ret = snprintf(str, sizeof(str), 
"hevc_metadata=crop_right=%d:crop_bottom=%d",
-   crop_right, crop_bottom);
+/* Encoder can use CTU size larger than 16x16, so the real crop
+ * margin can be larger than crop_right/crop_bottom. Let bsf figure
+ * out the real crop margin.
+ */
+ret = snprintf(str, sizeof(str), 
"hevc_metadata=width=%d:height=%d",
+   avctx->width, avctx->height);
 if (ret >= sizeof(str))
 return AVERROR_BUFFER_TOO_SMALL;
 }
@@ -235,7 +239,8 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
 // Workaround the alignment requirement of mediacodec. We can't do it
 // silently for AV_PIX_FMT_MEDIACODEC.
 if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
-avctx->codec_id == AV_CODEC_ID_H264) {
+(avctx->codec_id == AV_CODEC_ID_H264 ||
+ avctx->codec_id == AV_CODEC_ID_HEVC)) {
 s->width = FFALIGN(avctx->width, 16);
 s->height = FFALIGN(avctx->height, 16);
 } else {
-- 
2.42.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] libavcodec/x86/vvc/vvc_sad: fix assembler error

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

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

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

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

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

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


Re: [FFmpeg-devel] [PATCH 0/5] replace scale2ref by scale=rw:rh

2024-05-23 Thread Anton Khirnov
Quoting Niklas Haas (2024-04-24 12:51:55)
> Incidentally, I think it would be nice if lavfi could *automatically*
> split filter links referenced multiple times, so we could just write
> e.g. [i][ri]scale=rw:rh[o]; [ri][o]overlay[out] and have it work. Maybe
> I'll try getting that to work, next.

While I agree that it would be nice, using duplicate link labels
currently does not break, and I've seen multiple people using those. So
we'll probably need to deprecate this behaviour first.

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

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