Re: [FFmpeg-devel] [PATCH v8 14/15] avcodec: add D3D12VA hardware HEVC encoder

2024-05-08 Thread Wu, Tong1
>From: Wu, Tong1 
>Sent: Thursday, April 18, 2024 4:59 PM
>To: ffmpeg-devel@ffmpeg.org
>Cc: Wu, Tong1 
>Subject: [FFmpeg-devel][PATCH v8 14/15] avcodec: add D3D12VA hardware
>HEVC encoder
>
>From: Tong Wu 
>
>This implementation is based on D3D12 Video Encoding Spec:
>https://microsoft.github.io/DirectX-Specs/d3d/D3D12VideoEncoding.html
>
>Sample command line for transcoding:
>ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4
>-c:v hevc_d3d12va output.mp4
>
>Signed-off-by: Tong Wu 

Kindly ping again. Since this patch set has been in the mail list for quite a 
while, can we push it if there's no more objections?

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

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


Re: [FFmpeg-devel] [PATCH] avformat/riffdec: add ch_layout used av_channel_layout_default.

2024-05-08 Thread James Almer

On 5/8/2024 11:28 PM, shiqizhu wrote:

Signed-off-by: shiqizhu 
---
  libavformat/riffdec.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index b7a85a6ab2..89267e879d 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -197,8 +197,7 @@ int ff_get_wav_header(void *logctx, AVIOContext *pb,
  /* ignore WAVEFORMATEXTENSIBLE layout if different from channel count */
  if (channels != par->ch_layout.nb_channels) {
  av_channel_layout_uninit(>ch_layout);
-par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-par->ch_layout.nb_channels = channels;
+av_channel_layout_default(>ch_layout, channels);


No, guessing is left to the caller. lavf should export what's signaled 
in the file.

___
ffmpeg-devel mailing list
ffmpeg-devel@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/riffdec: add ch_layout used av_channel_layout_default.

2024-05-08 Thread shiqizhu
Signed-off-by: shiqizhu 
---
 libavformat/riffdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index b7a85a6ab2..89267e879d 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -197,8 +197,7 @@ int ff_get_wav_header(void *logctx, AVIOContext *pb,
 /* ignore WAVEFORMATEXTENSIBLE layout if different from channel count */
 if (channels != par->ch_layout.nb_channels) {
 av_channel_layout_uninit(>ch_layout);
-par->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-par->ch_layout.nb_channels = channels;
+av_channel_layout_default(>ch_layout, channels);
 }
 
 return 0;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 4/4] avcodec: Remove redundant setting of AV_FRAME_FLAG_KEY, AV_PICTURE_TYPE_I

2024-05-08 Thread Andreas Rheinhardt
This is done generically now.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/012v.c  | 3 ---
 libavcodec/aic.c   | 2 --
 libavcodec/aliaspixdec.c   | 3 ---
 libavcodec/asvdec.c| 2 --
 libavcodec/avuidec.c   | 3 ---
 libavcodec/bitpacked_dec.c | 3 ---
 libavcodec/bmp.c   | 2 --
 libavcodec/brenderpix.c| 2 --
 libavcodec/cdxl.c  | 2 --
 libavcodec/cljrdec.c   | 2 --
 libavcodec/cllc.c  | 3 ---
 libavcodec/cri.c   | 3 ---
 libavcodec/dds.c   | 2 --
 libavcodec/dnxhddec.c  | 2 --
 libavcodec/dvdec.c | 2 --
 libavcodec/dxtory.c| 2 --
 libavcodec/dxv.c   | 2 --
 libavcodec/fitsdec.c   | 3 ---
 libavcodec/fraps.c | 3 ---
 libavcodec/frwu.c  | 3 ---
 libavcodec/hapdec.c| 2 --
 libavcodec/hdrdec.c| 3 ---
 libavcodec/hq_hqa.c| 3 ---
 libavcodec/hqx.c   | 3 ---
 libavcodec/jpeg2000dec.c   | 2 --
 libavcodec/lagarith.c  | 3 ---
 libavcodec/lcldec.c| 3 ---
 libavcodec/leaddec.c   | 3 ---
 libavcodec/loco.c  | 1 -
 libavcodec/m101.c  | 2 --
 libavcodec/magicyuv.c  | 3 ---
 libavcodec/mdec.c  | 2 --
 libavcodec/mpeg12dec.c | 2 --
 libavcodec/mscc.c  | 3 ---
 libavcodec/msp2dec.c   | 3 ---
 libavcodec/mvcdec.c| 3 ---
 libavcodec/mvha.c  | 2 --
 libavcodec/notchlc.c   | 3 ---
 libavcodec/pgxdec.c| 2 --
 libavcodec/pixlet.c| 2 --
 libavcodec/pnmdec.c| 2 --
 libavcodec/proresdec.c | 2 --
 libavcodec/prosumer.c  | 2 --
 libavcodec/qdrw.c  | 3 ---
 libavcodec/qoidec.c| 3 ---
 libavcodec/r210dec.c   | 2 --
 libavcodec/rawdec.c| 3 ---
 libavcodec/rtv1.c  | 3 ---
 libavcodec/sgidec.c| 2 --
 libavcodec/sgirledec.c | 3 ---
 libavcodec/sheervideo.c| 3 ---
 libavcodec/speedhqdec.c| 1 -
 libavcodec/targa_y216dec.c | 3 ---
 libavcodec/tiff.c  | 1 -
 libavcodec/tmv.c   | 2 --
 libavcodec/truemotion2rt.c | 2 --
 libavcodec/utvideodec.c| 2 --
 libavcodec/v210dec.c   | 3 ---
 libavcodec/v210x.c | 2 --
 libavcodec/v308dec.c   | 3 ---
 libavcodec/v408dec.c   | 3 ---
 libavcodec/v410dec.c   | 3 ---
 libavcodec/vble.c  | 4 
 libavcodec/vcr1.c  | 2 --
 libavcodec/vmixdec.c   | 3 ---
 libavcodec/wbmpdec.c   | 3 ---
 libavcodec/wnv1.c  | 1 -
 libavcodec/xbmdec.c| 3 ---
 libavcodec/xl.c| 2 --
 libavcodec/xpmdec.c| 3 ---
 libavcodec/xwddec.c| 3 ---
 libavcodec/y41pdec.c   | 3 ---
 libavcodec/ylc.c   | 2 --
 libavcodec/yuv4dec.c   | 3 ---
 74 files changed, 184 deletions(-)

diff --git a/libavcodec/012v.c b/libavcodec/012v.c
index fa5eb0f95e..7bb60219cc 100644
--- a/libavcodec/012v.c
+++ b/libavcodec/012v.c
@@ -64,9 +64,6 @@ static int zero12v_decode_frame(AVCodecContext *avctx, 
AVFrame *pic,
 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
 return ret;
 
-pic->pict_type = AV_PICTURE_TYPE_I;
-pic->flags |= AV_FRAME_FLAG_KEY;
-
 line_end = avpkt->data + stride;
 for (line = 0; line < avctx->height; line++) {
 uint16_t y_temp[6] = {0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000};
diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index 440c399049..3ff170b414 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -393,8 +393,6 @@ static int aic_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 int slice_size;
 
 ctx->frame= frame;
-ctx->frame->pict_type = AV_PICTURE_TYPE_I;
-ctx->frame->flags |= AV_FRAME_FLAG_KEY;
 
 off = FFALIGN(AIC_HDR_SIZE + ctx->num_x_slices * ctx->mb_height * 2, 4);
 
diff --git a/libavcodec/aliaspixdec.c b/libavcodec/aliaspixdec.c
index 72f810d408..50a6b72a0a 100644
--- a/libavcodec/aliaspixdec.c
+++ b/libavcodec/aliaspixdec.c
@@ -69,9 +69,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
 if (ret < 0)
 return ret;
 
-f->pict_type = AV_PICTURE_TYPE_I;
-f->flags |= AV_FRAME_FLAG_KEY;
-
 x = 0;
 y = 1;
 out_buf = f->data[0];
diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 568881ccd2..5abe279f35 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -244,8 +244,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 
 if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
 return ret;
-p->pict_type = AV_PICTURE_TYPE_I;
-p->flags |= AV_FRAME_FLAG_KEY;
 
 if (avctx->codec_id == AV_CODEC_ID_ASV1) {
 av_fast_padded_malloc(>bitstream_buffer, >bitstream_buffer_size,
diff --git a/libavcodec/avuidec.c b/libavcodec/avuidec.c
index 48b23d4875..64a1d019d3 100644
--- a/libavcodec/avuidec.c
+++ b/libavcodec/avuidec.c
@@ -71,9 +71,6 @@ static int avui_decode_frame(AVCodecContext *avctx, AVFrame 
*pic,
 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
 return ret;
 
-pic->flags |= AV_FRAME_FLAG_KEY;
-

[FFmpeg-devel] [PATCH 3/4] avcodec/decode: Set KEY flag+pict_type generically for intra-only codecs

2024-05-08 Thread Andreas Rheinhardt
This commit is the analog of 3f11eac75741888c7b2b6f93c458766f2613bab5
for decoding: It sets the AV_FRAME_FLAG_KEY and (for video decoders)
also pict_type to AV_PICTURE_TYPE_I. It furthermore stops setting
audio frames as always being key frames -- it is wrong for e.g.
TrueHD/MLP. The latter also affects TAK and DFPWM.

The change already improves output for several decoders where
it has been forgotten to set e.g. pict_type like speedhq, wnv1
or tiff. The latter is the reason for the change to the exif-image-tiff
FATE test reference file.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/decode.c| 29 +++--
 libavcodec/pthread_frame.c | 17 ++---
 tests/ref/fate/exif-image-tiff |  2 +-
 3 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index d031b1ca17..0ca5344ef5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -57,6 +57,20 @@
 typedef struct DecodeContext {
 AVCodecInternal avci;
 
+/**
+ * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
+ * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
+ * to set the flag generically.
+ */
+int intra_only_flag;
+
+/**
+ * This is set to AV_PICTURE_TYPE_I for intra only video decoders
+ * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
+ * the AVFrame's pict_type before the decoder receives it.
+ */
+enum AVPictureType initial_pict_type;
+
 /* to prevent infinite loop on errors when draining */
 int nb_draining_errors;
 
@@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame 
*frame, int64_t *disca
 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame 
*frame, int64_t *discarded_samples)
 {
 AVCodecInternal   *avci = avctx->internal;
+DecodeContext *dc = decode_ctx(avci);
 AVPacket *const pkt = avci->in_pkt;
 const FFCodec *const codec = ffcodec(avctx->codec);
 int got_frame, consumed;
@@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext 
*avctx, AVFrame *frame,
 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
 consumed = ff_thread_decode_frame(avctx, frame, _frame, pkt);
 } else {
+frame->pict_type = dc->initial_pict_type;
+frame->flags|= dc->intra_only_flag;
 consumed = codec->cb.decode(avctx, frame, _frame, pkt);
 
 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
@@ -597,6 +614,8 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 av_assert0(!frame->buf[0]);
 
 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
+frame->pict_type = dc->initial_pict_type;
+frame->flags|= dc->intra_only_flag;
 ret = codec->cb.receive_frame(avctx, frame);
 emms_c();
 if (!ret) {
@@ -626,8 +645,7 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 frame->width = avctx->width;
 if (!frame->height)
 frame->height = avctx->height;
-} else
-frame->flags |= AV_FRAME_FLAG_KEY;
+}
 
 ret = fill_frame_props(avctx, frame);
 if (ret < 0) {
@@ -1793,6 +1811,13 @@ int ff_decode_preinit(AVCodecContext *avctx)
 DecodeContext *dc = decode_ctx(avci);
 int ret = 0;
 
+dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
+if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
+dc->intra_only_flag = AV_FRAME_FLAG_KEY;
+if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
+dc->initial_pict_type = AV_PICTURE_TYPE_I;
+}
+
 /* if the decoder init function was already called previously,
  * free the already allocated subtitle_header before overwriting it */
 av_freep(>subtitle_header);
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 67f09c1f48..982e4a64c5 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -22,13 +22,11 @@
  * @see doc/multithreading.txt
  */
 
-#include "config.h"
-
 #include 
-#include 
 
 #include "avcodec.h"
 #include "avcodec_internal.h"
+#include "codec_desc.h"
 #include "codec_internal.h"
 #include "decode.h"
 #include "hwaccel_internal.h"
@@ -108,6 +106,10 @@ typedef struct PerThreadContext {
 int hwaccel_threadsafe;
 
 atomic_int debug_threads;   ///< Set if the FF_DEBUG_THREADS option is 
set.
+
+/// The following two fields have the same semantics as the DecodeContext 
field
+int intra_only_flag;
+enum AVPictureType initial_pict_type;
 } PerThreadContext;
 
 /**
@@ -220,6 +222,8 @@ static attribute_align_arg void *frame_worker_thread(void 
*arg)
 
 av_frame_unref(p->frame);
 p->got_frame = 0;
+p->frame->pict_type = p->initial_pict_type;
+p->frame->flags|= p->intra_only_flag;
 p->result = 

[FFmpeg-devel] [PATCH 2/4] avcodec/codec_desc, jvdec: JV is not intra-only

2024-05-08 Thread Andreas Rheinhardt
It reuses the previous frame and does not code unchanged blocks.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/codec_desc.c |  2 +-
 libavcodec/jvdec.c  |  2 --
 tests/ref/fate/jv-demux | 14 +++---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 7dba61dc8b..5ae26f5d2b 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1095,7 +1095,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "jv",
 .long_name = NULL_IF_CONFIG_SMALL("Bitmap Brothers JV video"),
-.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+.props = AV_CODEC_PROP_LOSSY,
 },
 {
 .id= AV_CODEC_ID_DFA,
diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index 13ede9068a..2b7c9f0d29 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -215,8 +215,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 }
 
 if (video_size) {
-s->frame->flags |= AV_FRAME_FLAG_KEY;
-s->frame->pict_type   = AV_PICTURE_TYPE_I;
 #if FF_API_PALETTE_HAS_CHANGED
 FF_DISABLE_DEPRECATION_WARNINGS
 s->frame->palette_has_changed = s->palette_has_changed;
diff --git a/tests/ref/fate/jv-demux b/tests/ref/fate/jv-demux
index b5d3196cf5..22a9217e23 100644
--- a/tests/ref/fate/jv-demux
+++ b/tests/ref/fate/jv-demux
@@ -11,13 +11,13 @@
 0,  0,  0,1,6, 0x000a0003
 1,  0,  0,   131072,   131072, 0x14c664d6
 0,  1,  1,1,  773, 0x11802a51
-0,  2,  2,1,12974, 0xc2e466b7
-0,  3,  3,1,12200, 0x3c0eeb31
-0,  4,  4,1,13339, 0x91d82488
-0,  5,  5,1,13940, 0x064c350a
-0,  6,  6,1,14418, 0x078d2dd2
-0,  7,  7,1,14539, 0x145167ed
-0,  8,  8,1, 2552, 0xcf2b1db7, F=0x3
+0,  2,  2,1,12974, 0xc2e466b7, F=0x0
+0,  3,  3,1,12200, 0x3c0eeb31, F=0x0
+0,  4,  4,1,13339, 0x91d82488, F=0x0
+0,  5,  5,1,13940, 0x064c350a, F=0x0
+0,  6,  6,1,14418, 0x078d2dd2, F=0x0
+0,  7,  7,1,14539, 0x145167ed, F=0x0
+0,  8,  8,1, 2552, 0xcf2b1db7, F=0x2
 1, 131072, 131072, 1764, 1764, 0x30be734d
 1, 132836, 132836, 1764, 1764, 0xa4c873a7
 1, 134600, 134600, 1764, 1764, 0xd5f17443
-- 
2.40.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/mlpdec: Set AV_FRAME_FLAG_KEY explicitly

2024-05-08 Thread Andreas Rheinhardt
It is currently always set for all audio frames, but this is
wrong (namely for MLP/TrueHD) and will be changed.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mlpdec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 305c5d2b36..e85dac36a7 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -1212,6 +1212,7 @@ static int read_access_unit(AVCodecContext *avctx, 
AVFrame *frame,
 goto error;
 m->is_major_sync_unit = 1;
 header_size += m->major_sync_header_size;
+frame->flags |= AV_FRAME_FLAG_KEY;
 }
 
 if (!m->params_valid) {
-- 
2.40.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 6/7] avcodec/cbs_av1: Avoid shift overflow

2024-05-08 Thread Michael Niedermayer
On Thu, May 02, 2024 at 02:41:49AM +0200, Michael Niedermayer wrote:
> Fixes: CID1465488 Unintentional integer overflow
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cbs_av1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

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

What does censorship reveal? It reveals fear. -- Julian Assange


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 09/10] fftools/ffplay: Check return of swr_alloc_set_opts2()

2024-05-08 Thread Michael Niedermayer
On Sun, Apr 28, 2024 at 01:54:23AM +0200, Michael Niedermayer wrote:
> This probably makes no difference but its more correct
> 
> Fixes: CID1503080 Unchecked return value
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  fftools/ffplay.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply

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

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


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 1/5] doc/examples/demux_decode: Simplify loop

2024-05-08 Thread Michael Niedermayer
On Wed, Apr 24, 2024 at 03:45:18AM +0200, Michael Niedermayer wrote:
> Fixes: CID1463550 Logically dead code
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  doc/examples/demux_decode.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

will apply

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

No great genius has ever existed without some touch of madness. -- Aristotle


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 2/3] avformat/concatdec: Check file

2024-05-08 Thread Michael Niedermayer
On Tue, Apr 30, 2024 at 02:48:53AM +0200, Michael Niedermayer wrote:
> Fixes: null pointer dereference
> Fixes: -stream_loop 1 -ss 00:00:05 -i zgclab/ffmpeg_crash/poc2 -codec:v copy 
> -codec:a aac -y output.mp4
> 
> Found-by: Wang Dawei and Zhou Geng, from Zhongguancun Laboratory
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/concatdec.c | 5 +
>  1 file changed, 5 insertions(+)

will apply

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

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.


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 1/2] tools/target_enc_fuzzer: replace assert by clean exit

2024-05-08 Thread Michael Niedermayer
On Sun, May 05, 2024 at 03:18:57AM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_enc_fuzzer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

will apply

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

Does the universe only have a finite lifespan? No, its going to go on
forever, its just that you wont like living in it. -- Hiranya Peiri


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 v2 1/2] libavcodec/mpegvideo_enc: fix multi-threaded motion estimation rounding for mpeg4

2024-05-08 Thread Michael Niedermayer
On Wed, May 08, 2024 at 05:19:49PM +0200, Ramiro Polla wrote:
> ff_init_me() was being called after ff_update_duplicate_context(),
> which caused the propagation of the initialization to other thread
> contexts to be delayed by one frame.
> 
> In the case of mpeg4 (or flipflop_rounding), this would make the
> hpel_put functions differ between the first thread (which would be
> correctly initialized) and the other threads (which would be stale
> from the previous frame).
> ---
>  libavcodec/mpegvideo_enc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

have you confirmed the actual used rounding matches after this
encoder & decoder side ?

if yes then this should be ok

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.



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 v2 2/2] libavcodec/motion_est: fix penalty_factor for b frames

2024-05-08 Thread Michael Niedermayer
On Wed, May 08, 2024 at 05:19:50PM +0200, Ramiro Polla wrote:
> In direct_search() and ff_estimate_b_frame_motion(), penalty_factor
> would be used before being initialized in estimate_motion_b(). Also,
> the initialization would happen more than once unnecessarily.
> ---
>  libavcodec/motion_est.c  | 15 ---
>  tests/ref/vsynth/vsynth1-mpeg4-thread|  6 +++---
>  tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd |  6 +++---
>  tests/ref/vsynth/vsynth2-mpeg4-adap  |  8 
>  tests/ref/vsynth/vsynth2-mpeg4-qprd  |  6 +++---
>  tests/ref/vsynth/vsynth2-mpeg4-thread|  6 +++---
>  tests/ref/vsynth/vsynth_lena-mpeg4-rc|  4 ++--
>  7 files changed, 26 insertions(+), 25 deletions(-)

probably ok

thx

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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato


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 3/3] lavc/speedhqdec: Set AV_PICTURE_TYPE_I

2024-05-08 Thread James Almer

On 5/8/2024 5:01 PM, Marton Balint wrote:



On Wed, 8 May 2024, Tomas Härdin wrote:






What suprises me is that pict_type and the keyframe flag is not set 
already for decoding codecs with AV_CODEC_PROP_INTRA_ONLY flag. Is this 
intentional or just nobody had the time to set it up to work automatically?


For audio it's not always the case (See MLP/TrueHD). For video it might 
with intra-only codecs, but at least with non intra-only codecs, an I 
frame is not necessarily a keyframe (See AV1).




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

___
ffmpeg-devel mailing list
ffmpeg-devel@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] avformat/img2dec: assert no pipe on ts_from_file

2024-05-08 Thread Michael Niedermayer
On Wed, May 08, 2024 at 12:16:44PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Help coverity with CID500302 Uninitialized scalar variable
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/img2dec.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> > index a40675d4341..6220003fb4d 100644
> > --- a/libavformat/img2dec.c
> > +++ b/libavformat/img2dec.c
> > @@ -25,6 +25,7 @@
> >  #define _DEFAULT_SOURCE
> >  #define _BSD_SOURCE
> >  #include 
> > +#include "libavutil/avassert.h"
> >  #include "libavutil/avstring.h"
> >  #include "libavutil/log.h"
> >  #include "libavutil/mem.h"
> > @@ -504,6 +505,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket 
> > *pkt)
> >  pkt->flags   |= AV_PKT_FLAG_KEY;
> >  if (s->ts_from_file) {
> >  struct stat img_stat;
> > +av_assert0(!s->is_pipe);
> >  if (stat(filename, _stat)) {
> >  res = AVERROR(EIO);
> >  goto fail;
> 
> 1. You seem to refer to 1500302

yes, fixed locally


> which I can't even select any more
> because it has been dismissed.

no, it can be selected, it works here on the 3rd try
coverity sometimes ignores selecting issues
sometimes it displayes a long list of unrelated issues
sometimes it works


> 2. Why are you using av_assert0 to help coverity?

I dont understand the question


> 3. In cases like these it would be important to actually note why this
> assert can't be triggered. With a comment like "The ts_from_file option
> is not supported by piped input demuxers".

its kind of clear from the assert but i added the comment,


> 4. I just sent an alternative for this:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2024-May/327035.html. I don't
> know which one should be preferred or whether the code should be left as-is.

I think if somehow ts_from_file and is_pipe are set. Thats a bug in the code
its only the combination of flags and AVOptions that prevents this.
I think an assert like in my patch makes the code more robust compared to
simply not crashing on an inconsistant state

thx

[...]

--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


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 3/3] lavc/speedhqdec: Set AV_PICTURE_TYPE_I

2024-05-08 Thread Marton Balint



On Wed, 8 May 2024, Tomas Härdin wrote:






What suprises me is that pict_type and the keyframe flag is not set 
already for decoding codecs with AV_CODEC_PROP_INTRA_ONLY flag. Is this 
intentional or just nobody had the time to set it up to work 
automatically?


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 1/3] avcodec/cbs_jpeg: Assert that cbs_jpeg_assemble_fragment() stays within the array

2024-05-08 Thread Michael Niedermayer
On Wed, May 08, 2024 at 11:46:45AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Inspired by: CID1473561 Untrusted pointer write
> > 
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/cbs_jpeg.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> > index b1b58dcd65e..628841c5f37 100644
> > --- a/libavcodec/cbs_jpeg.c
> > +++ b/libavcodec/cbs_jpeg.c
> > @@ -401,6 +401,7 @@ static int 
> > cbs_jpeg_assemble_fragment(CodedBitstreamContext *ctx,
> >  } else {
> >  data[dp++] = unit->data[sp];
> >  }
> > +av_assert0(dp <= size - 2);
> >  }
> >  }
> >  }
> 
> You want to add an av_assert0 to a hot loop (or rather: to what would be
> a hot loop in case this code were executed) just because Coverity thinks
> that reading data with a different endianness taints this data? (That
> the supposedly tainted variable has actually already been checked via an
> assert makes this even more crazy.)

patch droped

But the code is fragile, there are 2 loops that must match exactly
if what the second writes doesnt match what the first counts it writes
out of array
This just needs someone finding a bug in the loop and fix it without
updating the 2nd loop

thx

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

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


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] avformat/wavdec: change ch_layout used av_channel_layout_default.

2024-05-08 Thread Marton Balint




On Wed, 8 May 2024, shiqizhu wrote:


Signed-off-by: shiqizhu 
---
libavformat/wavdec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 00856a5eca..9060796c81 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -233,8 +233,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t 
size, AVStream *st)
avio_skip(pb, 3);
}
av_channel_layout_uninit(>codecpar->ch_layout);
-st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-st->codecpar->ch_layout.nb_channels = channels;
+av_channel_layout_default(>codecpar->ch_layout, channels);


Why do you assume that the default layout is suitable here? A demuxer 
should not guess the channel layout, if the format does not provide any 
information about it.


Regards,
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] avfilter/af_volume: Don't free options manually

2024-05-08 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/af_volume.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
> index 5a3c9220f4..b3dd57c5e5 100644
> --- a/libavfilter/af_volume.c
> +++ b/libavfilter/af_volume.c
> @@ -127,7 +127,6 @@ static av_cold void uninit(AVFilterContext *ctx)
>  {
>  VolumeContext *vol = ctx->priv;
>  av_expr_free(vol->volume_pexpr);
> -av_opt_free(vol);
>  av_freep(>fdsp);
>  }
>  

Will apply tomorrow unless there are objections.

- 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] tests/checkasm/svq1enc: Use proper range for input

2024-05-08 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> ssd_int8_vs_int16 is only called from encode_block()
> in svq1enc.c; it calls it in stages: At stage 0,
> the int16_t array contains the difference of two
> uint16_t. At each of the following stages, the
> int16_t array is filled by subtracting an int8_t from
> the current stage's int16_t array. The maximum stage
> is five, so the int16_t are in the range
> (-255 + 5 * 127)..(255 + 5 * 128).
> 
> This commit modifies the checkasm test to only use
> values from this range, fixing (undefined) integer overflow
> in the test.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  tests/checkasm/svq1enc.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/checkasm/svq1enc.c b/tests/checkasm/svq1enc.c
> index 1a6f531141..f9abdcbff8 100644
> --- a/tests/checkasm/svq1enc.c
> +++ b/tests/checkasm/svq1enc.c
> @@ -18,7 +18,6 @@
>   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>   */
>  
> -#include "libavutil/mem.h"
>  #include "libavutil/mem_internal.h"
>  
>  #include "libavcodec/svq1encdsp.h"
> @@ -26,11 +25,13 @@
>  #include "checkasm.h"
>  
>  #define BUF_SIZE 1024
> +#define MIN_VAL (-255 - 5 * 127)
> +#define MAX_VAL ( 255 + 5 * 128)
>  
>  #define randomize(buf, len) \
>  do { \
>  for (int i = 0; i < len; i++) \
> -buf[i] = ((rnd() % 65281) - 32641); \
> +buf[i] = ((rnd() % (MAX_VAL - MIN_VAL + 1)) + MIN_VAL); \
>  } while (0)
>  
>  static void test_ssd_int8_vs_int16(SVQ1EncDSPContext *s) {

Will apply tomorrow unless there are objections.

- Andreas

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

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


[FFmpeg-devel] [PATCH 3/3] lavc/ac3dsp: add R-V Zvbb extract_exponents

2024-05-08 Thread Rémi Denis-Courmont
---
 libavcodec/riscv/Makefile  |  1 +
 libavcodec/riscv/ac3dsp_init.c |  5 
 libavcodec/riscv/ac3dsp_rvvb.S | 43 ++
 3 files changed, 49 insertions(+)
 create mode 100644 libavcodec/riscv/ac3dsp_rvvb.S

diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index 11d47f9a57..bd24f18cb9 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -5,6 +5,7 @@ RVV-OBJS-$(CONFIG_AAC_ENCODER) += riscv/aacencdsp_rvv.o
 OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_init.o
 RV-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_rvb.o
 RVV-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_rvv.o
+RVVB-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_rvvb.o
 OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_init.o
 RVV-OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_rvv.o
 OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o
diff --git a/libavcodec/riscv/ac3dsp_init.c b/libavcodec/riscv/ac3dsp_init.c
index 8cfa69055a..f66b6cac57 100644
--- a/libavcodec/riscv/ac3dsp_init.c
+++ b/libavcodec/riscv/ac3dsp_init.c
@@ -29,6 +29,7 @@
 void ff_ac3_exponent_min_rvb(uint8_t *exp, int, int);
 void ff_ac3_exponent_min_rvv(uint8_t *exp, int, int);
 void ff_extract_exponents_rvb(uint8_t *exp, int32_t *coef, int nb_coefs);
+void ff_extract_exponents_rvvb(uint8_t *exp, int32_t *coef, int nb_coefs);
 void ff_float_to_fixed24_rvv(int32_t *dst, const float *src, size_t len);
 void ff_sum_square_butterfly_int32_rvv(int64_t *, const int32_t *,
const int32_t *, int);
@@ -48,6 +49,10 @@ av_cold void ff_ac3dsp_init_riscv(AC3DSPContext *c)
 if (flags & AV_CPU_FLAG_RVB_ADDR) {
 if (flags & AV_CPU_FLAG_RVB_BASIC)
 c->extract_exponents = ff_extract_exponents_rvb;
+# if HAVE_RV_ZVBB
+if (flags & AV_CPU_FLAG_RV_ZVBB)
+c->extract_exponents = ff_extract_exponents_rvvb;
+# endif
 if (flags & AV_CPU_FLAG_RVV_F32) {
 c->float_to_fixed24 = ff_float_to_fixed24_rvv;
 c->sum_square_butterfly_float = ff_sum_square_butterfly_float_rvv;
diff --git a/libavcodec/riscv/ac3dsp_rvvb.S b/libavcodec/riscv/ac3dsp_rvvb.S
new file mode 100644
index 00..64766b56be
--- /dev/null
+++ b/libavcodec/riscv/ac3dsp_rvvb.S
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2023 Rémi Denis-Courmont.
+ *
+ * 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 "config.h"
+#include "libavutil/riscv/asm.S"
+
+func ff_extract_exponents_rvvb, zve32x, zvbb
+1:
+vsetvli t0, a2, e32, m8, ta, ma
+vle32.v v8, (a1)
+sub a2, a2, t0
+vneg.v  v16, v8
+sh2add  a1, t0, a1
+vmax.vv v8, v8, v16
+vclz.v  v8, v8
+vsetvli zero, zero, e16, m4, ta, ma
+vncvt.x.x.w v4, v8
+vsetvli zero, zero, e8, m2, ta, ma
+vncvt.x.x.w v2, v4
+vadd.vi v2, v2, 24 - 32
+vse8.v  v2, (a0)
+add a0, a0, t0
+bneza2, 1b
+
+ret
+endfunc
-- 
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 2/3] lavu/riscv: add Zvbb CPU capability detection

2024-05-08 Thread Rémi Denis-Courmont
This requires Linux kernel version 6.8 or later.
---
 libavutil/riscv/cpu.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavutil/riscv/cpu.c b/libavutil/riscv/cpu.c
index 69d1afe853..3cf4e25bc9 100644
--- a/libavutil/riscv/cpu.c
+++ b/libavutil/riscv/cpu.c
@@ -54,6 +54,10 @@ int ff_get_cpu_flags_riscv(void)
 ret |= AV_CPU_FLAG_RVB_ADDR;
 if (pairs[1].value & RISCV_HWPROBE_EXT_ZBB)
 ret |= AV_CPU_FLAG_RVB_BASIC;
+#ifdef RISCV_HWPROBE_EXT_ZVBB
+if (pairs[1].value & RISCV_HWPROBE_EXT_ZVBB)
+ret |= AV_CPU_FLAG_RV_ZVBB;
+#endif
 } else
 #endif
 #if HAVE_GETAUXVAL
@@ -105,6 +109,9 @@ int ff_get_cpu_flags_riscv(void)
 ret |= AV_CPU_FLAG_RVV_F64;
 #endif
 #endif
+#endif
+#ifdef __riscv_zvbb
+ret |= AV_CPU_FLAG_RV_ZVBB;
 #endif
 
 return ret;
-- 
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] [PATCHv2 1/3] riscv: add Zvbb vector bit manipulation extension

2024-05-08 Thread Rémi Denis-Courmont
---
 Makefile  | 2 +-
 configure | 3 +++
 doc/APIchanges| 3 +++
 ffbuild/arch.mak  | 1 +
 libavutil/cpu.c   | 1 +
 libavutil/cpu.h   | 1 +
 libavutil/tests/cpu.c | 1 +
 tests/checkasm/checkasm.c | 1 +
 8 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index de727cbe00..4c3af09fec 100644
--- a/Makefile
+++ b/Makefile
@@ -101,7 +101,7 @@ SUBDIR_VARS := CLEANFILES FFLIBS HOSTPROGS TESTPROGS TOOLS  
 \
ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS \
ALTIVEC-OBJS VSX-OBJS MMX-OBJS X86ASM-OBJS\
MIPSFPU-OBJS MIPSDSPR2-OBJS MIPSDSP-OBJS MSA-OBJS \
-   MMI-OBJS LSX-OBJS LASX-OBJS RV-OBJS RVV-OBJS  \
+   MMI-OBJS LSX-OBJS LASX-OBJS RV-OBJS RVV-OBJS RVVB-OBJS\
OBJS SLIBOBJS SHLIBOBJS STLIBOBJS HOSTOBJS TESTOBJS
 
 define RESET
diff --git a/configure b/configure
index beb1fa6d3c..2193905a54 100755
--- a/configure
+++ b/configure
@@ -,6 +,7 @@ ARCH_EXT_LIST_PPC="
 ARCH_EXT_LIST_RISCV="
 rv
 rvv
+rv_zvbb
 "
 
 ARCH_EXT_LIST_X86="
@@ -2760,6 +2761,7 @@ power8_deps="vsx"
 
 rv_deps="riscv"
 rvv_deps="rv"
+rv_zvbb_deps="rvv"
 
 loongson2_deps="mips"
 loongson3_deps="mips"
@@ -6384,6 +6386,7 @@ elif enabled riscv; then
 
 enabled rv && check_inline_asm rv '".option arch, +zbb\nrev8 t0, t1"'
 enabled rvv && check_inline_asm rvv '".option arch, +v\nvsetivli zero, 0, 
e8, m1, ta, ma"'
+enabled rv_zvbb && check_inline_asm rv_zvbb '".option arch, +zvbb\nvclz.v 
v0, v8"'
 
 elif enabled x86; then
 
diff --git a/doc/APIchanges b/doc/APIchanges
index 824beec9d3..238d22c135 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-05-10 - x - lavu 59.18.100 - cpu.h
+  Add AV_CPU_FLAG_RV_ZVBB.
+
 2024-05-04 - xx - lavu 59.17.100 - opt.h
   Add AV_OPT_TYPE_UINT and av_opt_eval_uint().
 
diff --git a/ffbuild/arch.mak b/ffbuild/arch.mak
index 23a3feb090..3fc40e5e5d 100644
--- a/ffbuild/arch.mak
+++ b/ffbuild/arch.mak
@@ -17,6 +17,7 @@ OBJS-$(HAVE_VSX) += $(VSX-OBJS) $(VSX-OBJS-yes)
 
 OBJS-$(HAVE_RV)  += $(RV-OBJS)  $(RV-OBJS-yes)
 OBJS-$(HAVE_RVV) += $(RVV-OBJS) $(RVV-OBJS-yes)
+OBJS-$(HAVE_RV_ZVBB) += $(RVVB-OBJS)$(RVVB-OBJS-yes)
 
 OBJS-$(HAVE_MMX) += $(MMX-OBJS) $(MMX-OBJS-yes)
 OBJS-$(HAVE_X86ASM)  += $(X86ASM-OBJS)  $(X86ASM-OBJS-yes)
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index d4f947360a..396eeb38d6 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -192,6 +192,7 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
 { "zve64d",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RVV_F64 
 },.unit = "flags" },
 { "zba",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_CPU_FLAG_RVB_ADDR },.unit = "flags" },
 { "zbb",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
AV_CPU_FLAG_RVB_BASIC },   .unit = "flags" },
+{ "zvbb", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RV_ZVBB 
},   .unit = "flags" },
 #endif
 { NULL },
 };
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index 8dff341886..cc19828d4b 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -90,6 +90,7 @@
 #define AV_CPU_FLAG_RVV_F64  (1 << 6) ///< Vectors of double's
 #define AV_CPU_FLAG_RVB_BASIC(1 << 7) ///< Basic bit-manipulations
 #define AV_CPU_FLAG_RVB_ADDR (1 << 8) ///< Address bit-manipulations
+#define AV_CPU_FLAG_RV_ZVBB  (1 << 9) ///< Vector basic bit-manipulations
 
 /**
  * Return the flags which specify extensions supported by the CPU.
diff --git a/libavutil/tests/cpu.c b/libavutil/tests/cpu.c
index d91bfeab5c..10e620963b 100644
--- a/libavutil/tests/cpu.c
+++ b/libavutil/tests/cpu.c
@@ -94,6 +94,7 @@ static const struct {
 { AV_CPU_FLAG_RVV_F32,   "zve32f" },
 { AV_CPU_FLAG_RVV_I64,   "zve64x" },
 { AV_CPU_FLAG_RVV_F64,   "zve64d" },
+{ AV_CPU_FLAG_RV_ZVBB,   "zvbb"  },
 #endif
 { 0 }
 };
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 9be32fc16e..9a05c1f95e 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -282,6 +282,7 @@ static const struct {
 { "RVVf32",   "rvv_f32",  AV_CPU_FLAG_RVV_F32 },
 { "RVVi64",   "rvv_i64",  AV_CPU_FLAG_RVV_I64 },
 { "RVVf64",   "rvv_f64",  AV_CPU_FLAG_RVV_F64 },
+{ "RV_Zvbb",  "rv_zvbb",  AV_CPU_FLAG_RV_ZVBB },
 #elif ARCH_MIPS
 { "MMI",  "mmi",  AV_CPU_FLAG_MMI },
 { "MSA",  "msa",  AV_CPU_FLAG_MSA },
-- 
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] lavc/vaapi_h264: Fix merging fields in DPB with missing references

2024-05-08 Thread David Rosca
On Tue, May 7, 2024 at 10:22 PM Mark Thompson  wrote:
>
> On 07/05/2024 07:00, David Rosca wrote:
> > If there are missing references, h264 decode does error concealment
> > by copying previous refs which means there will be duplicated surfaces
> > and this code would try to merge them instead of correctly appending
> > to DPB. Make sure the fields were actually merged before early return.
> > ---
> >  libavcodec/vaapi_h264.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> > index b47531ce1c..c62a320e97 100644
> > --- a/libavcodec/vaapi_h264.c
> > +++ b/libavcodec/vaapi_h264.c
> > @@ -112,8 +112,9 @@ static int dpb_add(DPB *dpb, const H264Picture *pic)
> >  } else {
> >  va_pic->BottomFieldOrderCnt = 
> > temp_va_pic.BottomFieldOrderCnt;
> >  }
> > +return 0;
> >  }
> > -return 0;
> > +break;
> >  }
> >  }
> >
>
> I agree that the old code did nasty things, but can you explain a bit more 
> about the reasoning for what you've got now?
>
> I'm thinking that given duplication a top field could appear twice, so you'd 
> want to merge twice if you have the matching bottom field.

Right, that may be possible.

Also I've looked at vdpau code and there it checks frame_num (in
addition to surface) when searching for the other field, which seems
better to avoid trying to merge when it should not. Posted v2 with
this change + multiple merge.

Thanks,
David

>
> Thanks,
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


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

2024-05-08 Thread David Rosca
If there are missing references, h264 decode does error concealment
by copying previous refs which means there will be duplicated surfaces.
Check long_ref and frame_idx in addition to surface when looking for
the other field to avoid trying to merge with wrong picture.
Also allow to merge with multiple pictures in case there are duplicates
of the other field.
---
v2: Check long_ref/frame_idx + multiple merge

 libavcodec/vaapi_h264.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index b47531ce1c..398e92568c 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -93,14 +93,19 @@ typedef struct DPB {
  */
 static int dpb_add(DPB *dpb, const H264Picture *pic)
 {
-int i;
+int i, pic_frame_idx, merged = 0;
 
 if (dpb->size >= dpb->max_size)
 return -1;
 
+pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
+
 for (i = 0; i < dpb->size; i++) {
 VAPictureH264 * const va_pic = >va_pics[i];
-if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
+int va_pic_long_ref = !!(va_pic->flags & 
VA_PICTURE_H264_LONG_TERM_REFERENCE);
+if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f) &&
+va_pic_long_ref == pic->long_ref &&
+va_pic->frame_idx == pic_frame_idx) {
 VAPictureH264 temp_va_pic;
 fill_vaapi_pic(_va_pic, pic, 0);
 
@@ -112,11 +117,14 @@ static int dpb_add(DPB *dpb, const H264Picture *pic)
 } else {
 va_pic->BottomFieldOrderCnt = 
temp_va_pic.BottomFieldOrderCnt;
 }
+merged = 1;
 }
-return 0;
 }
 }
 
+if (merged)
+return 0;
+
 fill_vaapi_pic(>va_pics[dpb->size++], pic, 0);
 return 0;
 }
-- 
2.45.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 v2 2/2] libavcodec/motion_est: fix penalty_factor for b frames

2024-05-08 Thread Ramiro Polla
In direct_search() and ff_estimate_b_frame_motion(), penalty_factor
would be used before being initialized in estimate_motion_b(). Also,
the initialization would happen more than once unnecessarily.
---
 libavcodec/motion_est.c  | 15 ---
 tests/ref/vsynth/vsynth1-mpeg4-thread|  6 +++---
 tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd |  6 +++---
 tests/ref/vsynth/vsynth2-mpeg4-adap  |  8 
 tests/ref/vsynth/vsynth2-mpeg4-qprd  |  6 +++---
 tests/ref/vsynth/vsynth2-mpeg4-thread|  6 +++---
 tests/ref/vsynth/vsynth_lena-mpeg4-rc|  4 ++--
 7 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index df9d1befa8..fb569ede8a 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -1127,9 +1127,6 @@ static int estimate_motion_b(MpegEncContext *s, int mb_x, 
int mb_y,
 const uint8_t * const mv_penalty = c->mv_penalty[f_code] + MAX_DMV;
 int mv_scale;
 
-c->penalty_factor= get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->me_cmp);
-c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->me_sub_cmp);
-c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->mb_cmp);
 c->current_mv_penalty= mv_penalty;
 
 get_limits(s, 16*mb_x, 16*mb_y);
@@ -1495,7 +1492,6 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
  int mb_x, int mb_y)
 {
 MotionEstContext * const c= >me;
-const int penalty_factor= c->mb_penalty_factor;
 int fmin, bmin, dmin, fbmin, bimin, fimin;
 int type=0;
 const int xy = mb_y*s->mb_stride + mb_x;
@@ -1517,22 +1513,27 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
 return;
 }
 
+c->penalty_factor= get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->me_cmp);
+c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->me_sub_cmp);
+c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, 
c->avctx->mb_cmp);
+
 if (s->codec_id == AV_CODEC_ID_MPEG4)
 dmin= direct_search(s, mb_x, mb_y);
 else
 dmin= INT_MAX;
+
 // FIXME penalty stuff for non-MPEG-4
 c->skip=0;
 fmin = estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) +
-   3 * penalty_factor;
+   3 * c->mb_penalty_factor;
 
 c->skip=0;
 bmin = estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) +
-   2 * penalty_factor;
+   2 * c->mb_penalty_factor;
 ff_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], 
s->b_forw_mv_table[xy][1]);
 
 c->skip=0;
-fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
+fbmin= bidir_refine(s, mb_x, mb_y) + c->mb_penalty_factor;
 ff_dlog(s, "%d %d %d %d\n", dmin, fmin, bmin, fbmin);
 
 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
diff --git a/tests/ref/vsynth/vsynth1-mpeg4-thread 
b/tests/ref/vsynth/vsynth1-mpeg4-thread
index 6b69fb4c12..6b110c49fb 100644
--- a/tests/ref/vsynth/vsynth1-mpeg4-thread
+++ b/tests/ref/vsynth/vsynth1-mpeg4-thread
@@ -1,4 +1,4 @@
-369ace2f9613261af869efd9fbb3c149 *tests/data/fate/vsynth1-mpeg4-thread.avi
-774754 tests/data/fate/vsynth1-mpeg4-thread.avi
-9aa327a244d5179acf7fe64dc1459bff 
*tests/data/fate/vsynth1-mpeg4-thread.out.rawvideo
+7761391e354266976a9e0155eff983dd *tests/data/fate/vsynth1-mpeg4-thread.avi
+774752 tests/data/fate/vsynth1-mpeg4-thread.avi
+bbdbe9af4f5b106b847595bf3040699f 
*tests/data/fate/vsynth1-mpeg4-thread.out.rawvideo
 stddev:   10.13 PSNR: 28.02 MAXDIFF:  183 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd 
b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
index 16de39edfc..f5bbecfcb2 100644
--- a/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
+++ b/tests/ref/vsynth/vsynth2-mpeg2-ivlc-qprd
@@ -1,4 +1,4 @@
-907a30295ed8323780eee08e606af0ab 
*tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
-269722 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
-d2d9793bf8f3427b5cc17a1be78ddd64 
*tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo
+f612ea89aa79a7f7b93a8acf332705c4 
*tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
+269723 tests/data/fate/vsynth2-mpeg2-ivlc-qprd.mpeg2video
+88e17886e6383755829d7da519fd5e79 
*tests/data/fate/vsynth2-mpeg2-ivlc-qprd.out.rawvideo
 stddev:5.54 PSNR: 33.25 MAXDIFF:   94 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mpeg4-adap 
b/tests/ref/vsynth/vsynth2-mpeg4-adap
index 35b2b6aac9..e058cd1ce3 100644
--- a/tests/ref/vsynth/vsynth2-mpeg4-adap
+++ b/tests/ref/vsynth/vsynth2-mpeg4-adap
@@ -1,4 +1,4 @@
-06a397fe43dab7b6cf56870410fbbbaf *tests/data/fate/vsynth2-mpeg4-adap.avi
-203000 tests/data/fate/vsynth2-mpeg4-adap.avi
-686565d42d8ba5aea790824b04fa0a18 
*tests/data/fate/vsynth2-mpeg4-adap.out.rawvideo
-stddev:4.55 PSNR: 34.95 MAXDIFF:   84 bytes:  7603200/  7603200
+9465ef120d560537d8fcfb5564782e01 *tests/data/fate/vsynth2-mpeg4-adap.avi
+203004 

[FFmpeg-devel] [PATCH v2 1/2] libavcodec/mpegvideo_enc: fix multi-threaded motion estimation rounding for mpeg4

2024-05-08 Thread Ramiro Polla
ff_init_me() was being called after ff_update_duplicate_context(),
which caused the propagation of the initialization to other thread
contexts to be delayed by one frame.

In the case of mpeg4 (or flipflop_rounding), this would make the
hpel_put functions differ between the first thread (which would be
correctly initialized) and the other threads (which would be stale
from the previous frame).
---
 libavcodec/mpegvideo_enc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 2a75973ac4..b601a1a9e4 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3623,6 +3623,9 @@ static int encode_picture(MpegEncContext *s)
 s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
 }
 
+if(ff_init_me(s)<0)
+return -1;
+
 s->mb_intra=0; //for the rate distortion & bit compare functions
 for(i=1; ithread_context[i], s);
@@ -3630,9 +3633,6 @@ static int encode_picture(MpegEncContext *s)
 return ret;
 }
 
-if(ff_init_me(s)<0)
-return -1;
-
 /* Estimate motion for every MB */
 if(s->pict_type != AV_PICTURE_TYPE_I){
 s->lambda  = (s->lambda  * s->me_penalty_compensation + 128) >> 8;
-- 
2.30.2

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavc/speedhqdec: Add AV_CODEC_CAP_FRAME_THREADS

2024-05-08 Thread Tomas Härdin
ons 2024-05-08 klockan 09:46 -0300 skrev James Almer:
> On 5/8/2024 9:42 AM, Tomas Härdin wrote:
> > Hi
> > 
> > On a 36-core machine (Intel(R) Xeon(R) Platinum 8124M CPU @
> > 3.00GHz)
> > with a 7 minute 125 Mbit/s 1080p sample and -thread_type frame -
> > threads
> > 36 this brings CPU utilization from 117% to 3174%, 58x realtime
> > 
> > Without -threads 36 the utilization is only 1601% due to it being
> > 16 by
> > default..
> 
> Does this default make sense anymore? I think it was added for h264,
> but 
> maybe it should be decoder dependent.

It is only relevant for slice threading in h264, right? It certainly
doesn't make sense for any intra-only codec in frame threading mode

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

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


Re: [FFmpeg-devel] [PATCH 1/3] lavc/speedhqdec: Add AV_CODEC_CAP_FRAME_THREADS

2024-05-08 Thread James Almer

On 5/8/2024 9:42 AM, Tomas Härdin wrote:

Hi

On a 36-core machine (Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz)
with a 7 minute 125 Mbit/s 1080p sample and -thread_type frame -threads
36 this brings CPU utilization from 117% to 3174%, 58x realtime

Without -threads 36 the utilization is only 1601% due to it being 16 by
default..


Does this default make sense anymore? I think it was added for h264, but 
maybe it should be decoder dependent.




/Tomas


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

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

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

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


[FFmpeg-devel] [PATCH 3/3] lavc/speedhqdec: Set AV_PICTURE_TYPE_I

2024-05-08 Thread Tomas Härdin

From 894a0ff35e892f84b079bef62efa56250bb33e41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Wed, 8 May 2024 14:18:10 +0200
Subject: [PATCH 3/3] lavc/speedhqdec: Set AV_PICTURE_TYPE_I

---
 libavcodec/speedhqdec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index d6b1fff7a5..2244d73c15 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -441,6 +441,7 @@ static int speedhq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 return ret;
 }
 frame->flags |= AV_FRAME_FLAG_KEY;
+frame->pict_type = AV_PICTURE_TYPE_I;
 
 if (second_field_offset == 4 || second_field_offset == (buf_size-4)) {
 /*
-- 
2.39.2

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

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


[FFmpeg-devel] [PATCH 2/3] lavc/speedhqdec: Obey AVDISCARD_ALL

2024-05-08 Thread Tomas Härdin
Inspired by qoidec

/Tomas
From ed49d383d40a9a4fad04b76bc7d86107c6350d9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Wed, 8 May 2024 14:17:57 +0200
Subject: [PATCH 2/3] lavc/speedhqdec: Obey AVDISCARD_ALL

---
 libavcodec/speedhqdec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index e54e25cb25..d6b1fff7a5 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -424,6 +424,9 @@ static int speedhq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 return AVERROR_INVALIDDATA;
 }
 
+if (avctx->skip_frame >= AVDISCARD_ALL)
+return avpkt->size;
+
 compute_quant_matrix(s->quant_matrix, 100 - quality);
 
 second_field_offset = AV_RL24(buf + 1);
-- 
2.39.2

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

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


[FFmpeg-devel] [PATCH 1/3] lavc/speedhqdec: Add AV_CODEC_CAP_FRAME_THREADS

2024-05-08 Thread Tomas Härdin
Hi

On a 36-core machine (Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz)
with a 7 minute 125 Mbit/s 1080p sample and -thread_type frame -threads
36 this brings CPU utilization from 117% to 3174%, 58x realtime

Without -threads 36 the utilization is only 1601% due to it being 16 by
default..

/Tomas
From d1a7f33a1c394142b6dc14d4e8392ad786f8ba52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Wed, 8 May 2024 14:17:18 +0200
Subject: [PATCH 1/3] lavc/speedhqdec: Add AV_CODEC_CAP_FRAME_THREADS

---
 libavcodec/speedhqdec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index d3605b0649..e54e25cb25 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -40,6 +40,7 @@
 #include "mpeg12data.h"
 #include "mpeg12vlc.h"
 #include "speedhq.h"
+#include "thread.h"
 
 #define MAX_INDEX (64 - 1)
 
@@ -433,7 +434,7 @@ static int speedhq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 avctx->coded_width = FFALIGN(avctx->width, 16);
 avctx->coded_height = FFALIGN(avctx->height, 16);
 
-if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
+if ((ret = ff_thread_get_buffer(avctx, frame, 0)) < 0) {
 return ret;
 }
 frame->flags |= AV_FRAME_FLAG_KEY;
@@ -649,5 +650,5 @@ const FFCodec ff_speedhq_decoder = {
 .priv_data_size = sizeof(SHQContext),
 .init   = speedhq_decode_init,
 FF_CODEC_DECODE_CB(speedhq_decode_frame),
-.p.capabilities = AV_CODEC_CAP_DR1,
+.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
 };
-- 
2.39.2

___
ffmpeg-devel mailing list
ffmpeg-devel@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] avformat/img2dec: assert no pipe on ts_from_file

2024-05-08 Thread Andreas Rheinhardt
Michael Niedermayer:
> Help coverity with CID500302 Uninitialized scalar variable
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/img2dec.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> index a40675d4341..6220003fb4d 100644
> --- a/libavformat/img2dec.c
> +++ b/libavformat/img2dec.c
> @@ -25,6 +25,7 @@
>  #define _DEFAULT_SOURCE
>  #define _BSD_SOURCE
>  #include 
> +#include "libavutil/avassert.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/log.h"
>  #include "libavutil/mem.h"
> @@ -504,6 +505,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
>  pkt->flags   |= AV_PKT_FLAG_KEY;
>  if (s->ts_from_file) {
>  struct stat img_stat;
> +av_assert0(!s->is_pipe);
>  if (stat(filename, _stat)) {
>  res = AVERROR(EIO);
>  goto fail;

1. You seem to refer to 1500302 which I can't even select any more
because it has been dismissed.
2. Why are you using av_assert0 to help coverity?
3. In cases like these it would be important to actually note why this
assert can't be triggered. With a comment like "The ts_from_file option
is not supported by piped input demuxers".
4. I just sent an alternative for this:
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-May/327035.html. I don't
know which one should be preferred or whether the code should be left as-is.

- Andreas

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

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


[FFmpeg-devel] [PATCH] avformat/img2dec: Join branches

2024-05-08 Thread Andreas Rheinhardt
Piped inputs don't support the ts_from_file option,
which allows to avoid a branch. Should also help
Coverity with issue #1500302.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/img2dec.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index a40675d434..5c2ff58f2e 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -502,7 +502,9 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
 }
 pkt->stream_index = 0;
 pkt->flags   |= AV_PKT_FLAG_KEY;
-if (s->ts_from_file) {
+if (s->is_pipe) {
+pkt->pos = avio_tell(f[0]);
+} else if (s->ts_from_file) {
 struct stat img_stat;
 if (stat(filename, _stat)) {
 res = AVERROR(EIO);
@@ -514,13 +516,10 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
 pkt->pts = 10*pkt->pts + img_stat.st_mtim.tv_nsec;
 #endif
 av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, 
AVINDEX_KEYFRAME);
-} else if (!s->is_pipe) {
+} else {
 pkt->pts  = s->pts;
 }
 
-if (s->is_pipe)
-pkt->pos = avio_tell(f[0]);
-
 /*
  * export_path_metadata must be explicitly enabled via
  * command line options for path metadata to be exported
-- 
2.40.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] swscale: [loongarch] Fix undeclared functions prob.

2024-05-08 Thread Shiyou Yin
Compile with '--disable-lasx', ‘lumRangeFromJpeg_lasx’ undeclared.
---
 libswscale/loongarch/swscale_init_loongarch.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libswscale/loongarch/swscale_init_loongarch.c 
b/libswscale/loongarch/swscale_init_loongarch.c
index 3a5a7ee856..4af62ad9f8 100644
--- a/libswscale/loongarch/swscale_init_loongarch.c
+++ b/libswscale/loongarch/swscale_init_loongarch.c
@@ -41,6 +41,7 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsContext 
*c)
 }
 }
 }
+#if HAVE_LASX
 if (have_lasx(cpu_flags)) {
 if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
 if (c->dstBpc <= 14) {
@@ -54,6 +55,7 @@ av_cold void ff_sws_init_range_convert_loongarch(SwsContext 
*c)
 }
 }
 }
+#endif // #if HAVE_LASX
 }
 
 av_cold void ff_sws_init_swscale_loongarch(SwsContext *c)
-- 
2.20.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] avcodec/cbs_jpeg: Assert that cbs_jpeg_assemble_fragment() stays within the array

2024-05-08 Thread Andreas Rheinhardt
Michael Niedermayer:
> Inspired by: CID1473561 Untrusted pointer write
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cbs_jpeg.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> index b1b58dcd65e..628841c5f37 100644
> --- a/libavcodec/cbs_jpeg.c
> +++ b/libavcodec/cbs_jpeg.c
> @@ -401,6 +401,7 @@ static int 
> cbs_jpeg_assemble_fragment(CodedBitstreamContext *ctx,
>  } else {
>  data[dp++] = unit->data[sp];
>  }
> +av_assert0(dp <= size - 2);
>  }
>  }
>  }

You want to add an av_assert0 to a hot loop (or rather: to what would be
a hot loop in case this code were executed) just because Coverity thinks
that reading data with a different endianness taints this data? (That
the supposedly tainted variable has actually already been checked via an
assert makes this even more crazy.)

- Andreas

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

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


[FFmpeg-devel] [PATCH] avformat/wavdec: change ch_layout used av_channel_layout_default.

2024-05-08 Thread shiqizhu
Signed-off-by: shiqizhu 
---
 libavformat/wavdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 00856a5eca..9060796c81 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -233,8 +233,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t 
size, AVStream *st)
 avio_skip(pb, 3);
 }
 av_channel_layout_uninit(>codecpar->ch_layout);
-st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-st->codecpar->ch_layout.nb_channels = channels;
+av_channel_layout_default(>codecpar->ch_layout, channels);
 
 if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate 
<= 0)
 return AVERROR_INVALIDDATA;
-- 
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 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times

2024-05-08 Thread David Rosca
On Tue, May 7, 2024 at 10:01 PM Mark Thompson  wrote:
>
> On 28/04/2024 08:26, David Rosca wrote:
> > When there are multiple tiles in one slice buffer, use multiple slice
> > params to avoid sending the same slice buffer multiple times and thus
> > increasing the bitstream size the driver will need to upload to hw.
> > ---
> >  libavcodec/vaapi_av1.c | 37 +++--
> >  1 file changed, 23 insertions(+), 14 deletions(-)
>
> Can you confirm that this works on at least iHD (Intel) and Mesa (AMD)?  (I 
> don't expect any issue, but it's good to check in case of something strange 
> going on matching up to what this was previously doing.)

I've tested with Mesa and it works correctly. Gstreamer also does the same.

https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/da35ed69164ba8c8599d337b00ba54074215f7e7/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c#L891-L912

>
> > diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> > index 4a90db1e09..567f505fbd 100644
> > --- a/libavcodec/vaapi_av1.c
> > +++ b/libavcodec/vaapi_av1.c
> > @@ -19,6 +19,7 @@
> >   */
> >
> >  #include "libavutil/frame.h"
> > +#include "libavutil/mem.h"
> >  #include "hwaccel_internal.h"
> >  #include "vaapi_decode.h"
> >  #include "internal.h"
> > @@ -393,13 +394,17 @@ static int vaapi_av1_decode_slice(AVCodecContext 
> > *avctx,
> >  {
> >  const AV1DecContext *s = avctx->priv_data;
> >  VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
> > -VASliceParameterBufferAV1 slice_param;
> > -int err = 0;
> > +VASliceParameterBufferAV1 *slice_params;
> > +int err = 0, nb_params = 0;
>
> Remove the spurious initialisation on err?

Done in v2.

>
> >
> > -for (int i = s->tg_start; i <= s->tg_end; i++) {
> > -memset(_param, 0, sizeof(VASliceParameterBufferAV1));
> > +slice_params = av_calloc(s->tg_end - s->tg_start + 1, 
> > sizeof(*slice_params));
>
> I suggest allocating this into VAAPIAV1DecContext to avoid the alloc/free on 
> every call.  (Only reallocate if it needs to be bigger than the previous 
> maximum.)

Done in v2.

Thanks,
David

>
> > +if (!slice_params) {
> > +err = AVERROR(ENOMEM);
> > +goto fail;
> > +}
> >
> > -slice_param = (VASliceParameterBufferAV1) {
> > +for (int i = s->tg_start; i <= s->tg_end; i++) {
> > +slice_params[nb_params++] = (VASliceParameterBufferAV1) {
> >  .slice_data_size   = s->tile_group_info[i].tile_size,
> >  .slice_data_offset = s->tile_group_info[i].tile_offset,
> >  .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
> > @@ -408,18 +413,22 @@ static int vaapi_av1_decode_slice(AVCodecContext 
> > *avctx,
> >  .tg_start  = s->tg_start,
> >  .tg_end= s->tg_end,
> >  };
> > -
> > -err = ff_vaapi_decode_make_slice_buffer(avctx, pic, _param, 
> > 1,
> > -
> > sizeof(VASliceParameterBufferAV1),
> > -buffer,
> > -size);
> > -if (err) {
> > -ff_vaapi_decode_cancel(avctx, pic);
> > -return err;
> > -}
> >  }
> >
> > +err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, 
> > nb_params,
> > +
> > sizeof(VASliceParameterBufferAV1),
> > +buffer,
> > +size);
> > +av_free(slice_params);
> > +
> > +if (err)
> > +goto fail;
> > +
> >  return 0;
> > +
> > +fail:
> > +ff_vaapi_decode_cancel(avctx, pic);
> > +return err;
> >  }
> >
> >  const FFHWAccel ff_av1_vaapi_hwaccel = {
>
> It's amusing that this quadratic behaviour was around for so long!  (I guess 
> people don't use many tiles.)
>
> Thanks,
>
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times

2024-05-08 Thread David Rosca
When there are multiple tiles in one slice buffer, use multiple slice
params to avoid sending the same slice buffer multiple times and thus
increasing the bitstream size the driver will need to upload to hw.
---
v2: Avoid allocations every slice.

 libavcodec/vaapi_av1.c | 47 +-
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 4a90db1e09..4ee33a3ae3 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -19,6 +19,7 @@
  */
 
 #include "libavutil/frame.h"
+#include "libavutil/mem.h"
 #include "hwaccel_internal.h"
 #include "vaapi_decode.h"
 #include "internal.h"
@@ -42,6 +43,9 @@ typedef struct VAAPIAV1DecContext {
 */
 VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES];
 AVFrame *tmp_frame;
+
+int nb_slice_params;
+VASliceParameterBufferAV1 *slice_params;
 } VAAPIAV1DecContext;
 
 static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf)
@@ -97,6 +101,8 @@ static int vaapi_av1_decode_uninit(AVCodecContext *avctx)
 for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++)
 av_frame_free(>ref_tab[i].frame);
 
+av_freep(>slice_params);
+
 return ff_vaapi_decode_uninit(avctx);
 }
 
@@ -393,13 +399,24 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
 {
 const AV1DecContext *s = avctx->priv_data;
 VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
-VASliceParameterBufferAV1 slice_param;
-int err = 0;
+VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
+int err, nb_params;
+
+nb_params = s->tg_end - s->tg_start + 1;
+if (ctx->nb_slice_params < nb_params) {
+ctx->slice_params = av_realloc_array(ctx->slice_params,
+ nb_params,
+ sizeof(*ctx->slice_params));
+if (!ctx->slice_params) {
+ctx->nb_slice_params = 0;
+err = AVERROR(ENOMEM);
+goto fail;
+}
+ctx->nb_slice_params = nb_params;
+}
 
 for (int i = s->tg_start; i <= s->tg_end; i++) {
-memset(_param, 0, sizeof(VASliceParameterBufferAV1));
-
-slice_param = (VASliceParameterBufferAV1) {
+ctx->slice_params[i - s->tg_start] = (VASliceParameterBufferAV1) {
 .slice_data_size   = s->tile_group_info[i].tile_size,
 .slice_data_offset = s->tile_group_info[i].tile_offset,
 .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
@@ -408,18 +425,20 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
 .tg_start  = s->tg_start,
 .tg_end= s->tg_end,
 };
-
-err = ff_vaapi_decode_make_slice_buffer(avctx, pic, _param, 1,
-
sizeof(VASliceParameterBufferAV1),
-buffer,
-size);
-if (err) {
-ff_vaapi_decode_cancel(avctx, pic);
-return err;
-}
 }
 
+err = ff_vaapi_decode_make_slice_buffer(avctx, pic, ctx->slice_params, 
nb_params,
+sizeof(VASliceParameterBufferAV1),
+buffer,
+size);
+if (err)
+goto fail;
+
 return 0;
+
+fail:
+ff_vaapi_decode_cancel(avctx, pic);
+return err;
 }
 
 const FFHWAccel ff_av1_vaapi_hwaccel = {
-- 
2.45.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 v2 1/2] lavc/vaapi_decode: Make it possible to send multiple slice params buffers

2024-05-08 Thread David Rosca
---
v2: No changes

 libavcodec/vaapi_av1.c| 2 +-
 libavcodec/vaapi_decode.c | 3 ++-
 libavcodec/vaapi_decode.h | 1 +
 libavcodec/vaapi_h264.c   | 2 +-
 libavcodec/vaapi_hevc.c   | 4 ++--
 libavcodec/vaapi_mjpeg.c  | 2 +-
 libavcodec/vaapi_mpeg2.c  | 2 +-
 libavcodec/vaapi_mpeg4.c  | 2 +-
 libavcodec/vaapi_vc1.c| 2 +-
 libavcodec/vaapi_vp8.c| 2 +-
 libavcodec/vaapi_vp9.c| 2 +-
 11 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 1f563483b9..4a90db1e09 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
 .tg_end= s->tg_end,
 };
 
-err = ff_vaapi_decode_make_slice_buffer(avctx, pic, _param,
+err = ff_vaapi_decode_make_slice_buffer(avctx, pic, _param, 1,
 
sizeof(VASliceParameterBufferAV1),
 buffer,
 size);
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..8e9f647c20 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
   VAAPIDecodePicture *pic,
   const void *params_data,
+  int nb_params,
   size_t params_size,
   const void *slice_data,
   size_t slice_size)
@@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
 
 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
  VASliceParameterBufferType,
- params_size, 1, (void*)params_data,
+ params_size, nb_params, (void*)params_data,
  >slice_buffers[index]);
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..702171e108 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
   VAAPIDecodePicture *pic,
   const void *params_data,
+  int nb_params,
   size_t params_size,
   const void *slice_data,
   size_t slice_size);
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 55cf5a05ee..b47531ce1c 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
slice_param.chroma_offset_l1);
 
 err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-_param, sizeof(slice_param),
+_param, 1, 
sizeof(slice_param),
 buffer, size);
 if (err) {
 ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..3937b7574a 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
 if (pic->last_size) {
 last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
 ret = ff_vaapi_decode_make_slice_buffer(avctx, >pic,
->last_slice_param, 
slice_param_size,
+>last_slice_param, 1, 
slice_param_size,
 pic->last_buffer, 
pic->last_size);
 if (ret < 0)
 goto fail;
@@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 
 if (!sh->first_slice_in_pic_flag) {
 err = ff_vaapi_decode_make_slice_buffer(avctx, >pic,
->last_slice_param, 
slice_param_size,
+>last_slice_param, 1, 
slice_param_size,
 pic->last_buffer, 
pic->last_size);
 pic->last_buffer = NULL;
 pic->last_size   = 0;
diff --git a/libavcodec/vaapi_mjpeg.c b/libavcodec/vaapi_mjpeg.c
index 5b8d47bb2a..9557cf5f9b 100644
--- a/libavcodec/vaapi_mjpeg.c
+++ b/libavcodec/vaapi_mjpeg.c
@@ -131,7 +131,7 @@ static int vaapi_mjpeg_decode_slice(AVCodecContext *avctx,
 

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

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

Will apply,

Thanks
Haihao


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

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


Re: [FFmpeg-devel] [PATCH 1/3] riscv: add Zvbb vector bit manipulation extension

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


Le 7 mai 2024 23:34:14 GMT+03:00, "Martin Storsjö"  a écrit :
>On Tue, 7 May 2024, Rémi Denis-Courmont wrote:
>
>> ---
>> Makefile  | 2 +-
>> configure | 3 +++
>> doc/APIchanges| 3 +++
>> ffbuild/arch.mak  | 1 +
>> libavutil/cpu.h   | 1 +
>> libavutil/tests/cpu.c | 1 +
>> tests/checkasm/checkasm.c | 1 +
>> 7 files changed, 11 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavutil/tests/cpu.c b/libavutil/tests/cpu.c
>> index d91bfeab5c..10e620963b 100644
>> --- a/libavutil/tests/cpu.c
>> +++ b/libavutil/tests/cpu.c
>> @@ -94,6 +94,7 @@ static const struct {
>> { AV_CPU_FLAG_RVV_F32,   "zve32f" },
>> { AV_CPU_FLAG_RVV_I64,   "zve64x" },
>> { AV_CPU_FLAG_RVV_F64,   "zve64d" },
>> +{ AV_CPU_FLAG_RV_ZVBB,   "zvbb"  },
>> #endif
>> { 0 }
>> };
>
>Doesn't this test require you to add this extension to the list in 
>libavutil/cpu.c as well?

TBH, I don't see the point of this stuff. These options look like cargo cult to 
me.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


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

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

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

BRs
Haihao

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

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


[FFmpeg-devel] [PATCH v2 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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

Add AVQSVFramesContext.info and update the description.

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

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

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

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