Re: [FFmpeg-devel] [PATCH 1/6 v3] avutil/frame: add a flag to allow overwritting existing entries

2024-03-27 Thread James Almer

On 3/28/2024 12:25 AM, Michael Niedermayer wrote:

On Wed, Mar 27, 2024 at 04:10:43PM -0300, James Almer wrote:

Signed-off-by: James Almer 
---
  libavutil/frame.c | 59 +++
  libavutil/frame.h | 27 +++---
  2 files changed, 74 insertions(+), 12 deletions(-)


broke fate, but i see you already posted a new patch (which i didnt test yet)


I sent a new patchset as a new thread just now, yes. Sorry for the noise.
___
ffmpeg-devel mailing list
ffmpeg-devel@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/6 v3] avutil/frame: add a flag to allow overwritting existing entries

2024-03-27 Thread Michael Niedermayer
On Wed, Mar 27, 2024 at 04:10:43PM -0300, James Almer wrote:
> Signed-off-by: James Almer 
> ---
>  libavutil/frame.c | 59 +++
>  libavutil/frame.h | 27 +++---
>  2 files changed, 74 insertions(+), 12 deletions(-)

broke fate, but i see you already posted a new patch (which i didnt test yet)

@@ -1,14 +0,0 @@
-Initial addition results with duplicates:
-sd 0, Ambient viewing environment
-sd 1, Content light level metadata: MaxCLL: 1
-sd 2, Content light level metadata: MaxCLL: 2
-sd 3, Content light level metadata: MaxCLL: 3
-sd 4, Spherical Mapping
-sd 5, Content light level metadata: MaxCLL: 4
-sd 6, Content light level metadata: MaxCLL: 5
-sd 7, Content light level metadata: MaxCLL: 6
-
-Final state after a single 'no-duplicates' addition:
-sd 0, Ambient viewing environment
-sd 1, Spherical Mapping
-sd 2, Content light level metadata: MaxCLL: 1337
Test side_data_array failed. Look at tests/data/fate/side_data_array.err for 
details.
Assertion sd failed at libavutil/tests/side_data_array.c:63
Aborted (core dumped)
threads=1
tests/Makefile:309: recipe for target 'fate-side_data_array' failed
make: *** [fate-side_data_array] Error 134


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

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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 7/7 v4] avcodec/hevcdec: export global side data in AVCodecContext

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/avcodec.h   |   2 +-
 libavcodec/h2645_sei.c | 215 +
 libavcodec/h2645_sei.h |   2 +
 libavcodec/hevcdec.c   |   4 +
 libavcodec/pthread_frame.c |  11 ++
 5 files changed, 141 insertions(+), 93 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 83dc487251..968009a192 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2071,7 +2071,7 @@ typedef struct AVCodecContext {
  * - encoding: may be set by user before calling avcodec_open2() for
  * encoder configuration. Afterwards owned and freed by the
  * encoder.
- * - decoding: unused
+ * - decoding: may be set by libavcodec in avcodec_open2().
  */
 AVFrameSideData  **decoded_side_data;
 int nb_decoded_side_data;
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index a9f4e01de8..4b7ce78a38 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -529,6 +529,120 @@ static int is_frame_packing_type_valid(SEIFpaType type, 
enum AVCodecID codec_id)
type >= SEI_FPA_TYPE_SIDE_BY_SIDE;
 }
 
+static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei,
+  AVFrameSideData ***sd, int *nb_sd)
+{
+int ret;
+
+for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) {
+H2645SEIUnregistered *unreg = >unregistered;
+
+if (unreg->buf_ref[i]) {
+AVFrameSideData *entry = av_frame_side_data_add(sd, nb_sd,
+AV_FRAME_DATA_SEI_UNREGISTERED,
+>buf_ref[i], 0);
+if (!entry)
+av_buffer_unref(>buf_ref[i]);
+}
+}
+sei->unregistered.nb_buf_ref = 0;
+
+if (sei->ambient_viewing_environment.present) {
+H2645SEIAmbientViewingEnvironment *env =
+>ambient_viewing_environment;
+AVBufferRef *buf;
+size_t size;
+
+AVAmbientViewingEnvironment *dst_env =
+av_ambient_viewing_environment_alloc();
+if (!dst_env)
+return AVERROR(ENOMEM);
+
+buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0);
+if (!buf) {
+av_free(dst_env);
+return AVERROR(ENOMEM);
+}
+
+ret = ff_frame_new_side_data_from_buf(avctx, sd, nb_sd,
+  
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, );
+
+if (ret < 0)
+return ret;
+
+dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 
1);
+dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 
5);
+dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 
5);
+}
+
+if (sei->mastering_display.present) {
+// HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
+const int mapping[3] = {2, 0, 1};
+const int chroma_den = 5;
+const int luma_den = 1;
+int i;
+AVMasteringDisplayMetadata *metadata;
+
+ret = ff_decode_mastering_display_new(avctx, sd, nb_sd, );
+if (ret < 0)
+return ret;
+
+if (metadata) {
+for (i = 0; i < 3; i++) {
+const int j = mapping[i];
+metadata->display_primaries[i][0].num = 
sei->mastering_display.display_primaries[j][0];
+metadata->display_primaries[i][0].den = chroma_den;
+metadata->display_primaries[i][1].num = 
sei->mastering_display.display_primaries[j][1];
+metadata->display_primaries[i][1].den = chroma_den;
+}
+metadata->white_point[0].num = 
sei->mastering_display.white_point[0];
+metadata->white_point[0].den = chroma_den;
+metadata->white_point[1].num = 
sei->mastering_display.white_point[1];
+metadata->white_point[1].den = chroma_den;
+
+metadata->max_luminance.num = sei->mastering_display.max_luminance;
+metadata->max_luminance.den = luma_den;
+metadata->min_luminance.num = sei->mastering_display.min_luminance;
+metadata->min_luminance.den = luma_den;
+metadata->has_luminance = 1;
+metadata->has_primaries = 1;
+
+av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
+av_log(avctx, AV_LOG_DEBUG,
+   "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, 
%5.4f)\n",
+   av_q2d(metadata->display_primaries[0][0]),
+   av_q2d(metadata->display_primaries[0][1]),
+   av_q2d(metadata->display_primaries[1][0]),
+   av_q2d(metadata->display_primaries[1][1]),
+   av_q2d(metadata->display_primaries[2][0]),
+   av_q2d(metadata->display_primaries[2][1]),
+   av_q2d(metadata->white_point[0]), 

[FFmpeg-devel] [PATCH 6/7 v4] avcodec/decode: make the AVFrameSideData helper wrappers not depend on frames

2024-03-27 Thread James Almer
They will be useful to fill arrays stored in other structs.

Signed-off-by: James Almer 
---
 libavcodec/av1dec.c |  7 +--
 libavcodec/cri.c|  3 +-
 libavcodec/decode.c | 99 +++--
 libavcodec/decode.h | 28 ++--
 libavcodec/dpx.c|  3 +-
 libavcodec/h2645_sei.c  |  4 +-
 libavcodec/h264_slice.c |  3 +-
 libavcodec/hevcdec.c|  6 ++-
 libavcodec/libdav1d.c   |  7 +--
 libavcodec/libjxldec.c  |  3 +-
 libavcodec/mjpegdec.c   |  3 +-
 libavcodec/mpeg12dec.c  | 11 +++--
 libavcodec/pngdec.c |  8 ++--
 libavcodec/qsvdec.c |  4 +-
 libavcodec/tiff.c   |  3 +-
 libavcodec/webp.c   |  3 +-
 16 files changed, 120 insertions(+), 75 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 32a795e758..54bedc27e1 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -964,7 +964,8 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame 
*frame,
 if (!ret)
 break;
 
-ret = ff_frame_new_side_data_from_buf(avctx, frame, 
AV_FRAME_DATA_A53_CC, , NULL);
+ret = ff_frame_new_side_data_from_buf(avctx, >side_data, 
>nb_side_data,
+  AV_FRAME_DATA_A53_CC, );
 if (ret < 0)
 return ret;
 
@@ -1028,7 +1029,7 @@ static int export_metadata(AVCodecContext *avctx, AVFrame 
*frame)
 if (s->mdcv) {
 AVMasteringDisplayMetadata *mastering;
 
-ret = ff_decode_mastering_display_new(avctx, frame, );
+ret = ff_decode_mastering_display_new(avctx, >side_data, 
>nb_side_data, );
 if (ret < 0)
 return ret;
 
@@ -1051,7 +1052,7 @@ static int export_metadata(AVCodecContext *avctx, AVFrame 
*frame)
 if (s->cll) {
 AVContentLightMetadata *light;
 
-ret = ff_decode_content_light_new(avctx, frame, );
+ret = ff_decode_content_light_new(avctx, >side_data, 
>nb_side_data, );
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index 990e52ac99..94468e7515 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -398,7 +398,8 @@ skip:
 }
 
 if (hflip || vflip) {
-ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_DISPLAYMATRIX,
+ff_frame_new_side_data(avctx, >side_data, >nb_side_data,
+   AV_FRAME_DATA_DISPLAYMATRIX,
sizeof(int32_t) * 9, );
 if (rotation) {
 av_display_rotation_set((int32_t *)rotation->data, 0.f);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 34bcb7cc64..48048cd599 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1793,93 +1793,124 @@ int ff_decode_preinit(AVCodecContext *avctx)
 }
 
 /**
- * Check side data preference and clear existing side data from frame
+ * Check side data preference and clear existing side data from sd/nb_sd
  * if needed.
  *
  * @retval 0 side data of this type can be added to frame
  * @retval 1 side data of this type should not be added to frame
  */
-static int side_data_pref(const AVCodecContext *avctx, AVFrame *frame,
-  enum AVFrameSideDataType type)
+static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
+  int *nb_sd, enum AVFrameSideDataType type)
 {
 DecodeContext *dc = decode_ctx(avctx->internal);
 
 // Note: could be skipped for `type` without corresponding packet sd
-if (av_frame_get_side_data(frame, type)) {
+if (av_frame_side_data_get(*sd, *nb_sd, type)) {
 if (dc->side_data_pref_mask & (1ULL << type))
 return 1;
-av_frame_remove_side_data(frame, type);
+av_frame_side_data_remove(sd, nb_sd, type);
 }
 
 return 0;
 }
 
-
-int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
-   enum AVFrameSideDataType type, size_t size,
+int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrameSideData ***sd,
+   int *nb_sd, enum AVFrameSideDataType type, size_t 
size,
AVFrameSideData **psd)
 {
-AVFrameSideData *sd;
+AVFrameSideData *entry;
 
-if (side_data_pref(avctx, frame, type)) {
+if (side_data_pref(avctx, sd, nb_sd, type)) {
 if (psd)
 *psd = NULL;
 return 0;
 }
 
-sd = av_frame_new_side_data(frame, type, size);
+entry = av_frame_side_data_new(sd, nb_sd, type, size, 0);
 if (psd)
-*psd = sd;
+*psd = entry;
 
-return sd ? 0 : AVERROR(ENOMEM);
+return entry ? 0 : AVERROR(ENOMEM);
 }
 
-int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
-AVFrame *frame, enum AVFrameSideDataType 
type,
-AVBufferRef **buf, AVFrameSideData **psd)
+int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, 
AVFrameSideData ***sd,
+   

[FFmpeg-devel] [PATCH 5/7 v4] avutil/mastering_display_metadata: add a new allocator function that returns a size

2024-03-27 Thread James Almer
av_mastering_display_metadata_alloc() is not useful in scenarios where you need 
to
know the runtime size of AVMasteringDisplayMetadata.

Signed-off-by: James Almer 
---
 libavutil/mastering_display_metadata.c | 13 +
 libavutil/mastering_display_metadata.h |  9 +
 2 files changed, 22 insertions(+)

diff --git a/libavutil/mastering_display_metadata.c 
b/libavutil/mastering_display_metadata.c
index 6069347617..ea41f13f9d 100644
--- a/libavutil/mastering_display_metadata.c
+++ b/libavutil/mastering_display_metadata.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
 #include 
 #include 
 
@@ -29,6 +30,18 @@ AVMasteringDisplayMetadata 
*av_mastering_display_metadata_alloc(void)
 return av_mallocz(sizeof(AVMasteringDisplayMetadata));
 }
 
+AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t 
*size)
+{
+AVMasteringDisplayMetadata *mastering = 
av_mallocz(sizeof(AVMasteringDisplayMetadata));
+if (!mastering)
+return NULL;
+
+if (size)
+*size = sizeof(*mastering);
+
+return mastering;
+}
+
 AVMasteringDisplayMetadata 
*av_mastering_display_metadata_create_side_data(AVFrame *frame)
 {
 AVFrameSideData *side_data = av_frame_new_side_data(frame,
diff --git a/libavutil/mastering_display_metadata.h 
b/libavutil/mastering_display_metadata.h
index c23b07c3cd..52fcef9e37 100644
--- a/libavutil/mastering_display_metadata.h
+++ b/libavutil/mastering_display_metadata.h
@@ -77,6 +77,15 @@ typedef struct AVMasteringDisplayMetadata {
  */
 AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void);
 
+/**
+ * Allocate an AVMasteringDisplayMetadata structure and set its fields to
+ * default values. The resulting struct can be freed using av_freep().
+ *
+ * @return An AVMasteringDisplayMetadata filled with default values or NULL
+ * on failure.
+ */
+AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t 
*size);
+
 /**
  * Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
  *
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 4/7 v4] avutil/frame: add helper to remove side data of a given type from an array

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/frame.c | 6 ++
 libavutil/frame.h | 5 +
 2 files changed, 11 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d27998d1f4..f54c1fa472 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -965,6 +965,12 @@ const AVFrameSideData *av_frame_side_data_get_c(const 
AVFrameSideData * const *s
 return NULL;
 }
 
+void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
+   enum AVFrameSideDataType type)
+{
+remove_side_data(sd, nb_sd, type);
+}
+
 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
 enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 3e5d170a5b..da78aeea7f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1156,6 +1156,11 @@ const AVFrameSideData 
*av_frame_side_data_get(AVFrameSideData * const *sd,
 nb_sd, type);
 }
 
+/**
+ * Remove and free all side data instances of the given type from an array.
+ */
+void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
+   enum AVFrameSideDataType type);
 /**
  * @}
  */
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 3/7 v4] avutil/frame: use the same data pointer as the source entry when cloning side data

2024-03-27 Thread James Almer
src->data does not need to match src->buf->data

Signed-off-by: James Almer 
---
 libavutil/frame.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index a165e56a64..d27998d1f4 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -744,13 +744,11 @@ AVBufferRef *av_frame_get_plane_buffer(const AVFrame 
*frame, int plane)
 static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd,
int *nb_sd,
enum AVFrameSideDataType type,
-   AVBufferRef *buf)
+   AVBufferRef *buf, uint8_t *data,
+   size_t size)
 {
 AVFrameSideData *ret, **tmp;
 
-if (!buf)
-return NULL;
-
 // *nb_sd + 1 needs to fit into an int and a size_t.
 if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX))
 return NULL;
@@ -765,8 +763,8 @@ static AVFrameSideData 
*add_side_data_from_buf(AVFrameSideData ***sd,
 return NULL;
 
 ret->buf = buf;
-ret->data = ret->buf->data;
-ret->size = buf->size;
+ret->data = data;
+ret->size = size;
 ret->type = type;
 
 (*sd)[(*nb_sd)++] = ret;
@@ -778,9 +776,13 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame 
*frame,
  enum AVFrameSideDataType type,
  AVBufferRef *buf)
 {
+if (!buf)
+return NULL;
+
 return
 add_side_data_from_buf(
->side_data, >nb_side_data, type, buf);
+>side_data, >nb_side_data, type, buf,
+buf->data, buf->size);
 }
 
 AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
@@ -827,7 +829,9 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 }
 
 buf = av_buffer_alloc(size);
-ret = add_side_data_from_buf(sd, nb_sd, type, buf);
+if (!buf)
+return NULL;
+ret = add_side_data_from_buf(sd, nb_sd, type, buf, buf->data, size);
 if (!ret)
 av_buffer_unref();
 
@@ -873,8 +877,10 @@ AVFrameSideData *av_frame_side_data_add(AVFrameSideData 
***sd, int *nb_sd,
 
 buf = (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) ?
av_buffer_ref(*pbuf) : *pbuf;
+if (!buf)
+return NULL;
 
-sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf);
+sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf, buf->data, 
buf->size);
 if (!sd_dst) {
 if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)
 av_buffer_unref();
@@ -933,7 +939,7 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
 if (!buf)
 return AVERROR(ENOMEM);
 
-sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf);
+sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf, src->data, 
src->size);
 if (!sd_dst) {
 av_buffer_unref();
 return AVERROR(ENOMEM);
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 2/7 v4] avutil/frame: add helper for adding side data w/ AVBufferRef to array

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/frame.c | 53 +++
 libavutil/frame.h | 34 ++
 2 files changed, 87 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d9bd19b2aa..a165e56a64 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -834,6 +834,59 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 return ret;
 }
 
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **pbuf, unsigned int flags)
+{
+const AVSideDataDescriptor *desc = av_frame_side_data_desc(type);
+AVFrameSideData *sd_dst  = NULL;
+AVBufferRef *buf;
+
+if (!sd || !pbuf || !*pbuf || !nb_sd || (*nb_sd && !*sd))
+return NULL;
+
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+
+if (entry->type != type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return NULL;
+
+buf = *pbuf;
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) {
+int ret = av_buffer_replace(>buf, buf);
+if (ret < 0)
+return NULL;
+} else
+*pbuf = NULL;
+
+av_dict_free(>metadata);
+entry->data = buf->data;
+entry->size = buf->size;
+return entry;
+}
+}
+
+buf = (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) ?
+   av_buffer_ref(*pbuf) : *pbuf;
+
+sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf);
+if (!sd_dst) {
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)
+av_buffer_unref();
+return NULL;
+}
+
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
+*pbuf = NULL;
+
+return sd_dst;
+}
+
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 2ea129888e..3e5d170a5b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1048,6 +1048,10 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  * Don't add a new entry if another of the same type exists.
  */
 #define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)
+/**
+ * Create a new reference instead of taking ownership of the passed in one.
+ */
+#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2)
 
 /**
  * Add new side data entry to an array.
@@ -1066,11 +1070,40 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  *   is attempted.
  * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
  *   entry of the same type already exists, it will be replaced instead.
+ * @note AV_FRAME_SIDE_DATA_FLAG_NEW_REF has no effect in this function.
  */
 AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags);
 
+/**
+ * Add a new side data entry to an array from an existing AVBufferRef.
+ *
+ * @param sdpointer to array of side data to which to add another entry,
+ *  or to NULL in order to start a new array.
+ * @param nb_sd pointer to an integer containing the number of entries in
+ *  the array.
+ * @param type  type of the added side data
+ * @param buf   Pointer to AVBufferRef to add to the array. On success,
+ *  the function takes ownership of the AVBufferRef and *buf is
+ *  set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set
+ *  in which case the ownership will remain with the caller.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
+ *
+ * @return newly added side data on success, NULL on error.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of
+ *   matching AVFrameSideDataType will be removed before the addition
+ *   is attempted.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
+ *   entry of the same type already exists, it will be replaced instead.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_NEW_REF being set, the ownership
+ *   of *buf will remain with the caller.
+ *
+ */
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **buf, unsigned int flags);
+
 /**
  * Add a new side data entry to an array based on existing side data, taking
  * a reference towards the contained AVBufferRef.
@@ 

[FFmpeg-devel] [PATCH 1/7 v4] avutil/frame: add a flag to allow overwritting existing entries

2024-03-27 Thread James Almer
Enable it only for side data types that don't allow more than one entry.

Signed-off-by: James Almer 
---
 libavutil/frame.c | 59 ---
 libavutil/frame.h | 27 +-
 libavutil/tests/side_data_array.c | 52 +++
 tests/ref/fate/side_data_array| 22 ++--
 4 files changed, 115 insertions(+), 45 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index ef1613c344..d9bd19b2aa 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -799,12 +799,34 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags)
 {
-AVBufferRef *buf = av_buffer_alloc(size);
+const AVSideDataDescriptor *desc = av_frame_side_data_desc(type);
+AVBufferRef *buf;
 AVFrameSideData *ret = NULL;
 
 if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
 remove_side_data(sd, nb_sd, type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+if (entry->type != type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return NULL;
+
+buf = av_buffer_alloc(size);
+if (!buf)
+return NULL;
+
+av_buffer_unref(>buf);
+av_dict_free(>metadata);
+entry->buf  = buf;
+entry->data = buf->data;
+entry->size = buf->size;
+return entry;
+}
+}
 
+buf = av_buffer_alloc(size);
 ret = add_side_data_from_buf(sd, nb_sd, type, buf);
 if (!ret)
 av_buffer_unref();
@@ -815,6 +837,7 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
+const AVSideDataDescriptor *desc;
 AVBufferRef *buf= NULL;
 AVFrameSideData *sd_dst = NULL;
 int  ret= AVERROR_BUG;
@@ -822,13 +845,41 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
 if (!sd || !src || !nb_sd || (*nb_sd && !*sd))
 return AVERROR(EINVAL);
 
+desc = av_frame_side_data_desc(src->type);
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, src->type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+AVDictionary *dict = NULL;
+
+if (entry->type != src->type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return AVERROR(EEXIST);
+
+ret = av_dict_copy(, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = av_buffer_replace(>buf, src->buf);
+if (ret < 0) {
+av_dict_free();
+return ret;
+}
+
+av_dict_free(>metadata);
+entry->metadata = dict;
+entry->data = src->data;
+entry->size = src->size;
+return 0;
+}
+}
+
 buf = av_buffer_ref(src->buf);
 if (!buf)
 return AVERROR(ENOMEM);
 
-if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
-remove_side_data(sd, nb_sd, src->type);
-
 sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf);
 if (!sd_dst) {
 av_buffer_unref();
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 3b6d746a16..2ea129888e 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1040,7 +1040,14 @@ const AVSideDataDescriptor *av_frame_side_data_desc(enum 
AVFrameSideDataType typ
  */
 void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);
 
+/**
+ * Remove existing entries before adding new ones.
+ */
 #define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0)
+/**
+ * Don't add a new entry if another of the same type exists.
+ */
+#define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)
 
 /**
  * Add new side data entry to an array.
@@ -1053,10 +1060,12 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  * @param size  size of the side data
  * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
  *
- * @return newly added side data on success, NULL on error. In case of
- * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
- * AVFrameSideDataType will be removed before the addition is
- * attempted.
+ * @return newly added side data on success, NULL on error.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of
+ *   matching AVFrameSideDataType will be removed before the addition
+ *   is attempted.
+ * @note In 

Re: [FFmpeg-devel] [PATCH 1/4] avcodec/jpeg2000htdec: Check M_b / magp before using it in a shift

2024-03-27 Thread Michael Niedermayer
On Wed, Mar 27, 2024 at 11:13:48AM +0100, Tomas Härdin wrote:
> mån 2024-03-25 klockan 21:04 +0100 skrev Michael Niedermayer:
> > On Mon, Mar 25, 2024 at 08:13:13PM +0100, Michael Niedermayer wrote:
> > > On Thu, Mar 21, 2024 at 04:07:14PM +0100, Tomas Härdin wrote:
> > > > ons 2024-03-20 klockan 21:35 +0100 skrev Tomas Härdin:
> > > > > ons 2024-03-20 klockan 14:12 +0100 skrev Michael Niedermayer:
> > > > > > On Wed, Mar 20, 2024 at 12:20:11PM +0100, Tomas Härdin wrote:
> > > > > > > ons 2024-03-20 klockan 03:59 +0100 skrev Michael
> > > > > > > Niedermayer:
> > > > > > > > Fixes: shift exponent -1 is negative
> > > > > > > > Fixes: 65378/clusterfuzz-testcase-minimized-
> > > > > > > > ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5457678193197056
> > > > > > > > 
> > > > > > > > Found-by: continuous fuzzing process
> > > > > > > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > > > > > Signed-off-by: Michael Niedermayer
> > > > > > > > 
> > > > > > > > ---
> > > > > > > >  libavcodec/jpeg2000htdec.c | 3 +++
> > > > > > > >  1 file changed, 3 insertions(+)
> > > > > > > > 
> > > > > > > > diff --git a/libavcodec/jpeg2000htdec.c
> > > > > > > > b/libavcodec/jpeg2000htdec.c
> > > > > > > > index 6b9898d3ff..0b94bb5da2 100644
> > > > > > > > --- a/libavcodec/jpeg2000htdec.c
> > > > > > > > +++ b/libavcodec/jpeg2000htdec.c
> > > > > > > > @@ -1193,6 +1193,9 @@ ff_jpeg2000_decode_htj2k(const
> > > > > > > > Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c
> > > > > > > >  
> > > > > > > >  int32_t M_b = magp;
> > > > > > > >  
> > > > > > > > +    if (magp >= 31)
> > > > > > > > +    return AVERROR_INVALIDDATA;
> > > > > > > 
> > > > > > > This isn't where the error is, assuming it even is an
> > > > > > > error. It's
> > > > > > > either expn or nguardbits that are wrong, and they should
> > > > > > > be
> > > > > > > detected
> > > > > > > and reported as such in jpeg2000dec.c. Checking this in
> > > > > > > every
> > > > > > > call
> > > > > > > to
> > > > > > > ff_jpeg2000_decode_htj2k() is wasteful.
> > > > > > > 
> > > > > > > nguardbits can be 0..7 and expn can be 0..31. Table A.11
> > > > > > > indicates
> > > > > > > that
> > > > > > > Ssize can be up to 38 bits, so M_b >= 31 is in fact
> > > > > > > perfectly
> > > > > > > valid.
> > > > > > 
> > > > > > > A
> > > > > > > more appropriate error might be AVERROR_PATCHWELCOME.
> > > > > > 
> > > > > > indeed, i will change it to AVERROR_PATCHWELCOME
> > > > > 
> > > > > Please also move it further up so as to not waste cycles
> > > > > checking it
> > > > > every time
> > > > 
> > > > To be more precise, get_qcx() looks like the proper place for it
> > > 
> > > will apply with teh check moved there
> > 
> > the values that are causing undefined behavior for htj2k are used in
> > normal
> > j2k knowing which type of j2k we have seems decided by COC/COD/COX
> > 
> > so i dont think we can check in QCX, because a later COX could
> > make it both invalid or valid
> > and we cannot check in COX as a later QCX can similarly change it
> 
> That all calls get_qcx().

yes


> If you git grep for nguardbits you'll see
> it's only ever set there when decoding, and similarly with expn.

yes


> Coding
> style and quantization style are not the same thing.

yes


but still, you can try to add a check the values for both nguardbits
and expn which lead to undefined shifts in ff_jpeg2000_decode_htj2k()
are used in normal jpeg2000 and break these samples

because the same get_qcx() is used both for "normal" jpeg2000 and htj2k
so the check needs to know if its htj2k

inside ff_jpeg2000_decode_htj2k() thats obvious, in get_qcx() its not
one can use the coding style to tell them apart but thats not trivial
with the various ways to slice and dice things
and it might not be set when get_qcx() is run

if iam missing something please tell me how to know in get_qcx() that
teh data is only used for ht2jk
(Its very possible iam missing something given i did not read the hundreads
 of pages of spec, and mostly assume that its as insane as possible)

thx

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

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


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/4] lavc/vp9dsp: R-V V ipred dc

2024-03-27 Thread flow gg
I don't quite understand, I think here 8x8 because zve64x is not suitable
for sharing, it shares between dc16x16 and dc32x32, there isn't much common
code, it would require adding 3 if-else statements and function parameters,
it feels okay not to extract too.

Rémi Denis-Courmont  于2024年3月27日周三 23:41写道:

> Le perjantaina 22. maaliskuuta 2024, 8.02.08 EET flow gg a écrit :
> > Using macros to shorten function definitions, updated in this response
>
> Did you try to share the common code after getdc and see how slower it is?
> If
> an extra static branch has negligible overhead, it would reduce binary
> size
> quite a bit here, AFAICT.
>
> --
> レミ・デニ-クールモン
> http://www.remlab.net/
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@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 v7 11/12] avcodec: add D3D12VA hardware HEVC encoder

2024-03-27 Thread Wu, Tong1
Kindly ping. Is there any more comment on v7?

>-Original Message-
>From: Wu, Tong1 
>Sent: Thursday, March 14, 2024 4:15 PM
>To: ffmpeg-devel@ffmpeg.org
>Cc: Wu, Tong1 
>Subject: [FFmpeg-devel][PATCH v7 11/12] 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 
>---
> configure|6 +
> libavcodec/Makefile  |4 +-
> libavcodec/allcodecs.c   |1 +
> libavcodec/d3d12va_encode.c  | 1550 ++
> libavcodec/d3d12va_encode.h  |  321 +++
> libavcodec/d3d12va_encode_hevc.c |  957 ++
> 6 files changed, 2838 insertions(+), 1 deletion(-)
> create mode 100644 libavcodec/d3d12va_encode.c
> create mode 100644 libavcodec/d3d12va_encode.h
> create mode 100644 libavcodec/d3d12va_encode_hevc.c
>
>diff --git a/configure b/configure
>index c34bdd13f5..53076fbf22 100755
>--- a/configure
>+++ b/configure
>@@ -2570,6 +2570,7 @@ CONFIG_EXTRA="
> tpeldsp
> vaapi_1
> vaapi_encode
>+d3d12va_encode
> vc1dsp
> videodsp
> vp3dsp
>@@ -3214,6 +3215,7 @@ wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
> wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
>
> # hardware-accelerated codecs
>+d3d12va_encode_deps="d3d12va ID3D12VideoEncoder
>d3d12_encoder_feature"
> mediafoundation_deps="mftransform_h MFCreateAlignedMemoryBuffer"
> omx_deps="libdl pthreads"
> omx_rpi_select="omx"
>@@ -3280,6 +3282,7 @@ h264_v4l2m2m_encoder_deps="v4l2_m2m
>h264_v4l2_m2m"
> hevc_amf_encoder_deps="amf"
> hevc_cuvid_decoder_deps="cuvid"
> hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
>+hevc_d3d12va_encoder_select="cbs_h265 d3d12va_encode"
> hevc_mediacodec_decoder_deps="mediacodec"
> hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
> hevc_mediacodec_encoder_deps="mediacodec"
>@@ -6620,6 +6623,9 @@ check_type "windows.h d3d11.h"
>"ID3D11VideoDecoder"
> check_type "windows.h d3d11.h" "ID3D11VideoContext"
> check_type "windows.h d3d12.h" "ID3D12Device"
> check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
>+check_type "windows.h d3d12video.h" "ID3D12VideoEncoder"
>+test_code cc "windows.h d3d12video.h" "D3D12_FEATURE_VIDEO feature =
>D3D12_FEATURE_VIDEO_ENCODER_CODEC" && \
>+test_code cc "windows.h d3d12video.h"
>"D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS req"
>&& enable d3d12_encoder_feature
> check_type "windows.h" "DPI_AWARENESS_CONTEXT" -
>D_WIN32_WINNT=0x0A00
> check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -
>D_WIN32_WINNT=0x0602
> check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
>diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>index cbfae5f182..cdda3f0d0a 100644
>--- a/libavcodec/Makefile
>+++ b/libavcodec/Makefile
>@@ -84,6 +84,7 @@ OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
> OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
> OBJS-$(CONFIG_CBS_VP8) += cbs_vp8.o vp8data.o
> OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
>+OBJS-$(CONFIG_D3D12VA_ENCODE)  += d3d12va_encode.o
>hw_base_encode.o
> OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o
> OBJS-$(CONFIG_DOVI_RPU)+= dovi_rpu.o
> OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o
>@@ -435,6 +436,7 @@ OBJS-$(CONFIG_HEVC_DECODER)+= hevcdec.o
>hevc_mvs.o \
>   h274.o
> OBJS-$(CONFIG_HEVC_AMF_ENCODER)+= amfenc_hevc.o
> OBJS-$(CONFIG_HEVC_CUVID_DECODER)  += cuviddec.o
>+OBJS-$(CONFIG_HEVC_D3D12VA_ENCODER)+= d3d12va_encode_hevc.o
> OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
> OBJS-$(CONFIG_HEVC_MEDIACODEC_ENCODER) += mediacodecenc.o
> OBJS-$(CONFIG_HEVC_MF_ENCODER) += mfenc.o mf_utils.o
>@@ -1263,7 +1265,7 @@ SKIPHEADERS+= %_tablegen.h
>\
>
> SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
> SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
>-SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
>+SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
>d3d12va_encode.h
> SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
> SKIPHEADERS-$(CONFIG_JNI)  += ffjni.h
> SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h
>diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>index 2386b450a6..7b5093233c 100644
>--- a/libavcodec/allcodecs.c
>+++ b/libavcodec/allcodecs.c
>@@ -855,6 +855,7 @@ extern const FFCodec ff_h264_vaapi_encoder;
> extern const FFCodec ff_h264_videotoolbox_encoder;
> extern const FFCodec ff_hevc_amf_encoder;
> extern const FFCodec ff_hevc_cuvid_decoder;
>+extern const FFCodec ff_hevc_d3d12va_encoder;
> extern const FFCodec 

[FFmpeg-devel] [PATCH 3/3] lavfi/vaapi_vpp: Use dynamic frame pool in outlink if possible

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

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

For example:
$ ffmpeg -hwaccel_output_format vaapi -hwaccel vaapi -i input.mp4 \
-vf 'scale_vaapi=w=720:h=480' -c:v hevc_vaapi -f null -

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

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 59961bfa4a..0755d674ac 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -203,7 +203,10 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 output_frames->width = ctx->output_width;
 output_frames->height= ctx->output_height;
 
-output_frames->initial_pool_size = 4;
+if (ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL)
+output_frames->initial_pool_size = 0;
+else
+output_frames->initial_pool_size = 4;
 
 err = ff_filter_init_hw_frames(avctx, outlink, 10);
 if (err < 0)
@@ -219,6 +222,8 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 va_frames = output_frames->hwctx;
 
 av_assert0(ctx->va_context == VA_INVALID_ID);
+av_assert0(output_frames->initial_pool_size ||
+   (va_frames->surface_ids == NULL && va_frames->nb_surfaces == 
0));
 vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
   ctx->output_width, ctx->output_height,
   VA_PROGRESSIVE,
-- 
2.34.1

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

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


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

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

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

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

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

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

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

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


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

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

libva2 doesn't require a fixed surface-array any more, but some
driver/hardware combinations which rely on this are still used. To
reduce the impact to users, add a quirk for the driver/hardware
combination which supports dynamic surface pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_vaapi.c | 7 +++
 libavutil/hwcontext_vaapi.h | 6 ++
 2 files changed, 13 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..dae5dd4a11 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -390,6 +390,13 @@ static const struct {
 "Splitted-Desktop Systems VDPAU backend for VA-API",
 AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
 },
+#if CONFIG_VAAPI_1
+{
+"New Intel iHD",
+"Intel iHD driver for Intel(R) Gen Graphics",
+AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
+},
+#endif
 };
 
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..07014fd526 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,12 @@ enum {
  * and the results of the vaQuerySurfaceAttributes() call will be faked.
  */
 AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+/**
+ * The driver (and the underlying HW) supports dynamic surface pool.
+ * The vaCreateContext() call doesn't require a fixed surface-array.
+ */
+AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
 };
 
 /**
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 2/3] lavc/vp8dsp: R-V V put_epel v

2024-03-27 Thread flow gg
Okay, changed in the reply and github (another reason for not doing so
initially was the thought that there weren't enough registers available,
and that other changes would need to be made that could cause side effects,
but now it's found that the vp8 registers are sufficient.. it's just that
vp9 doesn't have enough)

Rémi Denis-Courmont  于2024年3月27日周三 23:36写道:

> Le perjantaina 22. maaliskuuta 2024, 8.01.21 EET flow gg a écrit :
> >
>
> IMO, you could just as well share the code and avoid most if's. Not like
> one
> additional `li a3, 1` per function call is going to matter in the grand
> scheme
> of things. It might even help by reducing I-cache pressure.
>
> --
> 雷米‧德尼-库尔蒙
> http://www.remlab.net/
>
>
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
From 920e5274b9fb98fc1ac97d0644a9bb7c890e8f39 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 17:49:54 +0800
Subject: [PATCH 2/3] lavc/vp8dsp: R-V V put_epel v

C908:
vp8_put_epel4_v4_c: 11.0
vp8_put_epel4_v4_rvv_i32: 5.0
vp8_put_epel4_v6_c: 16.5
vp8_put_epel4_v6_rvv_i32: 6.2
vp8_put_epel8_v4_c: 43.7
vp8_put_epel8_v4_rvv_i32: 11.2
vp8_put_epel8_v6_c: 68.7
vp8_put_epel8_v6_rvv_i32: 13.2
vp8_put_epel16_v4_c: 92.5
vp8_put_epel16_v4_rvv_i32: 13.7
vp8_put_epel16_v6_c: 135.7
vp8_put_epel16_v6_rvv_i32: 16.5
---
 libavcodec/riscv/vp8dsp_init.c |  7 ++
 libavcodec/riscv/vp8dsp_rvv.S  | 46 +++---
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/libavcodec/riscv/vp8dsp_init.c b/libavcodec/riscv/vp8dsp_init.c
index 6614d661f7..2f123b67fe 100644
--- a/libavcodec/riscv/vp8dsp_init.c
+++ b/libavcodec/riscv/vp8dsp_init.c
@@ -85,6 +85,13 @@ av_cold void ff_vp78dsp_init_riscv(VP8DSPContext *c)
 c->put_vp8_epel_pixels_tab[0][0][1] = ff_put_vp8_epel16_h4_rvv;
 c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_rvv;
 c->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_rvv;
+
+c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_rvv;
+c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_rvv;
+c->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_rvv;
+c->put_vp8_epel_pixels_tab[0][1][0] = ff_put_vp8_epel16_v4_rvv;
+c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_rvv;
+c->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_rvv;
 }
 #endif
 }
diff --git a/libavcodec/riscv/vp8dsp_rvv.S b/libavcodec/riscv/vp8dsp_rvv.S
index 84e8ec61de..440a965ddd 100644
--- a/libavcodec/riscv/vp8dsp_rvv.S
+++ b/libavcodec/riscv/vp8dsp_rvv.S
@@ -234,9 +234,13 @@ const subpel_filters
 .byte 0,  -1,  12, 123,  -6, 0
 endconst
 
-.macro epel_filter size
+.macro epel_filter size type
 lla t2, subpel_filters
+.ifc \type,v
+addit0, a6, -1
+.elseif \type == h
 addit0, a5, -1
+.endif
 li  t1, 6
 mul t0, t0, t1
 add t0, t0, t2
@@ -249,19 +253,25 @@ endconst
 .endif
 .endm
 
-.macro epel_load dst len size
-addit6, a2, -1
-addia7, a2, 1
+.macro epel_load dst len size type
+.ifc \type,v
+mv  a5, a3
+.else
+li  a5, 1
+.endif
+sub t6, a2, a5
+add a7, a2, a5
+.if \from_mem
 vle8.v  v24, (a2)
 vle8.v  v22, (t6)
 vle8.v  v26, (a7)
-addia7, a7, 1
+add a7, a7, a5
 vle8.v  v28, (a7)
 vwmulu.vx   v16, v24, t2
 vwmulu.vx   v20, v26, t3
 .ifc \size,6
-addit6, t6, -1
-addia7, a7, 1
+sub t6, t6, a5
+add a7, a7, a5
 vle8.v  v24, (t6)
 vle8.v  v26, (a7)
 vwmaccu.vx  v16, t0, v24
@@ -293,13 +303,13 @@ endconst
 vnclipu.wi  \dst, v24, 0
 .endm
 
-.macro epel_load_inc dst len size
-epel_load   \dst \len \size
+.macro epel_load_inc dst len size type
+epel_load   \dst \len \size \type
 add a2, a2, a3
 .endm
 
-.macro epel len size
-epel_filter \size
+.macro epel len size type
+epel_filter \size \type
 
 .ifc \len,4
 vsetivlizero, 4, e8, mf4, ta, ma
@@ -311,7 +321,7 @@ endconst
 
 1:
 addia4, a4, -1
-epel_load_inc   v30 \len \size
+epel_load_inc   v30 \len \size \type
 vse8.v  v30, (a0)
 add a0, a0, a1
 bneza4, 1b
@@ -321,10 +331,18 @@ endconst
 
 .irp len 16,8,4
 func ff_put_vp8_epel\len\()_h6_rvv, zve32x
-epel \len 6
+epel \len 6 h
 endfunc
 
 

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

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

Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
instead for decoding. This patch fixes the error below:

[hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
[hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
initialisation returned error.

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

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..83b94d1a55 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -612,6 +612,13 @@ VAProfile 
ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n", 
profile->name);
 }
 
+#if VA_CHECK_VERSION(0, 37, 0)
+if (!strcmp(profile->name, "Main Intra"))
+return VAProfileHEVCMain;
+else if (!strcmp(profile->name, "Main 10 Intra"))
+return VAProfileHEVCMain10;
+#endif
+
 #if VA_CHECK_VERSION(1, 2, 0)
 if (!strcmp(profile->name, "Main 12") ||
 !strcmp(profile->name, "Main 12 Intra"))
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH v1 6/7] lavc/vvc_dec: Add hardware decode API

2024-03-27 Thread Andreas Rheinhardt
fei.w.wang-at-intel@ffmpeg.org:
> From: Fei Wang 
> 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vvc/vvc_refs.c |  6 
>  libavcodec/vvc/vvcdec.c   | 67 +++
>  libavcodec/vvc/vvcdec.h   |  5 +++
>  3 files changed, 72 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c
> index bf70777550..c9f89a5a0a 100644
> --- a/libavcodec/vvc/vvc_refs.c
> +++ b/libavcodec/vvc/vvc_refs.c
> @@ -25,6 +25,7 @@
>  #include "libavutil/thread.h"
>  #include "libavcodec/refstruct.h"
>  #include "libavcodec/thread.h"
> +#include "libavcodec/decode.h"
>  
>  #include "vvc_refs.h"
>  
> @@ -56,6 +57,7 @@ void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame 
> *frame, int flags)
>  ff_refstruct_unref(>rpl_tab);
>  
>  frame->collocated_ref = NULL;
> +ff_refstruct_unref(>hwaccel_picture_private);
>  }
>  }
>  
> @@ -138,6 +140,10 @@ static VVCFrame *alloc_frame(VVCContext *s, 
> VVCFrameContext *fc)
>  if (!frame->progress)
>  goto fail;
>  
> +ret = ff_hwaccel_frame_priv_alloc(s->avctx, 
> >hwaccel_picture_private);
> +if (ret < 0)
> +goto fail;
> +
>  return frame;
>  fail:
>  ff_vvc_unref_frame(fc, frame, ~0);
> diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
> index d5704aca25..f2e269ce76 100644
> --- a/libavcodec/vvc/vvcdec.c
> +++ b/libavcodec/vvc/vvcdec.c
> @@ -24,6 +24,8 @@
>  #include "libavcodec/decode.h"
>  #include "libavcodec/profiles.h"
>  #include "libavcodec/refstruct.h"
> +#include "libavcodec/hwconfig.h"
> +#include "libavcodec/hwaccel_internal.h"
>  #include "libavutil/cpu.h"
>  #include "libavutil/thread.h"
>  
> @@ -563,6 +565,8 @@ static int ref_frame(VVCFrame *dst, const VVCFrame *src)
>  
>  ff_refstruct_replace(>rpl_tab, src->rpl_tab);
>  ff_refstruct_replace(>rpl, src->rpl);
> +ff_refstruct_replace(>hwaccel_picture_private,
> +  src->hwaccel_picture_private);
>  dst->nb_rpl_elems = src->nb_rpl_elems;
>  
>  dst->poc = src->poc;
> @@ -718,17 +722,41 @@ static int slice_start(SliceContext *sc, VVCContext *s, 
> VVCFrameContext *fc,
>  return 0;
>  }
>  
> +static enum AVPixelFormat get_format(AVCodecContext *avctx, const VVCSPS 
> *sps)
> +{
> +#define HWACCEL_MAX 0
> +
> +enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
> +
> +switch (sps->pix_fmt) {
> +case AV_PIX_FMT_YUV420P:
> +break;
> +case AV_PIX_FMT_YUV420P10:
> +break;
> +}
> +
> +*fmt++ = sps->pix_fmt;
> +*fmt = AV_PIX_FMT_NONE;
> +
> +return ff_get_format(avctx, pix_fmts);
> +}
> +
>  static void export_frame_params(VVCContext *s, const VVCFrameContext *fc)
>  {
>  AVCodecContext *c = s->avctx;
>  const VVCSPS *sps = fc->ps.sps;
>  const VVCPPS *pps = fc->ps.pps;
>  
> -c->pix_fmt  = sps->pix_fmt;
> -c->coded_width  = pps->width;
> -c->coded_height = pps->height;
> -c->width= pps->width  - ((pps->r->pps_conf_win_left_offset + 
> pps->r->pps_conf_win_right_offset) << sps->hshift[CHROMA]);
> -c->height   = pps->height - ((pps->r->pps_conf_win_top_offset + 
> pps->r->pps_conf_win_bottom_offset) << sps->vshift[CHROMA]);
> +// Reset HW config if pix_fmt/w/h change.
> +if (s->pix_fmt != sps->pix_fmt || c->coded_width != pps->width || 
> c->coded_height != pps->height) {
> +c->coded_width  = pps->width;
> +c->coded_height = pps->height;
> +c->pix_fmt  = get_format(c, sps);
> +s->pix_fmt  = sps->pix_fmt;
> +}
> +
> +c->width  = pps->width  - ((pps->r->pps_conf_win_left_offset + 
> pps->r->pps_conf_win_right_offset) << sps->hshift[CHROMA]);
> +c->height = pps->height - ((pps->r->pps_conf_win_top_offset + 
> pps->r->pps_conf_win_bottom_offset) << sps->vshift[CHROMA]);
>  }
>  
>  static int frame_setup(VVCFrameContext *fc, VVCContext *s)
> @@ -771,6 +799,20 @@ static int decode_slice(VVCContext *s, VVCFrameContext 
> *fc, const H2645NAL *nal,
>  ret = slice_init_entry_points(sc, fc, nal, unit);
>  if (ret < 0)
>  return ret;
> +
> +if (s->avctx->hwaccel) {
> +if (is_first_slice) {
> +ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
> +if (ret < 0)
> +return ret;
> +}
> +
> +ret = FF_HW_CALL(s->avctx, decode_slice,
> + nal->raw_data, nal->raw_size);
> +if (ret < 0)
> +return ret;
> +}
> +
>  fc->nb_slices++;
>  
>  return 0;
> @@ -885,9 +927,20 @@ static int wait_delayed_frame(VVCContext *s, AVFrame 
> *output, int *got_output)
>  static int submit_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *output, 
> int *got_output)
>  {
>  int ret;
> +
> +if (s->avctx->hwaccel) {
> +if (ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame) < 0) {
> +av_log(s->avctx, AV_LOG_ERROR,
> +   

[FFmpeg-devel] [PATCH v1 7/7] lavc/vaapi_dec: Add VVC decoder

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 Changelog |   4 +
 configure |   3 +
 libavcodec/Makefile   |   1 +
 libavcodec/hwaccels.h |   1 +
 libavcodec/vaapi_decode.c |   7 +
 libavcodec/vaapi_vvc.c| 657 ++
 libavcodec/version.h  |   2 +-
 libavcodec/vvc/vvcdec.c   |  15 +-
 8 files changed, 688 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/vaapi_vvc.c

diff --git a/Changelog b/Changelog
index e83a00e35c..3108e65558 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,10 @@
 Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
+version :
+- VVC VAAPI decoder
+
+
 version 7.0:
 - DXV DXT1 encoder
 - LEAD MCMP decoder
diff --git a/configure b/configure
index 2a1d22310b..d902c9adc8 100755
--- a/configure
+++ b/configure
@@ -3258,6 +3258,8 @@ vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
 vp9_videotoolbox_hwaccel_deps="videotoolbox"
 vp9_videotoolbox_hwaccel_select="vp9_decoder"
+vvc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferVVC"
+vvc_vaapi_hwaccel_select="vvc_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
 wmv3_d3d12va_hwaccel_select="vc1_d3d12va_hwaccel"
@@ -7250,6 +7252,7 @@ if enabled vaapi; then
 check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
 
 check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
+check_type "va/va.h va/va_dec_vvc.h" "VAPictureParameterBufferVVC"
 check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ce6d445c1..343b037636 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1054,6 +1054,7 @@ OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)  += vaapi_vp9.o
 OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)  += vdpau_vp9.o
 OBJS-$(CONFIG_VP9_VIDEOTOOLBOX_HWACCEL)   += videotoolbox_vp9.o
 OBJS-$(CONFIG_VP8_QSV_HWACCEL)+= qsvdec.o
+OBJS-$(CONFIG_VVC_VAAPI_HWACCEL)  += vaapi_vvc.o
 
 # Objects duplicated from other libraries for shared builds
 SHLIBOBJS  += log2_tab.o reverse.o
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 5171e4c7d7..88d6b9a9b5 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -82,6 +82,7 @@ extern const struct FFHWAccel ff_vp9_nvdec_hwaccel;
 extern const struct FFHWAccel ff_vp9_vaapi_hwaccel;
 extern const struct FFHWAccel ff_vp9_vdpau_hwaccel;
 extern const struct FFHWAccel ff_vp9_videotoolbox_hwaccel;
+extern const struct FFHWAccel ff_vvc_vaapi_hwaccel;
 extern const struct FFHWAccel ff_wmv3_d3d11va_hwaccel;
 extern const struct FFHWAccel ff_wmv3_d3d11va2_hwaccel;
 extern const struct FFHWAccel ff_wmv3_d3d12va_hwaccel;
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 1b1972a2a9..ceeb1f1a12 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -455,6 +455,9 @@ static const struct {
 MAP(AV1, AV1_MAIN,AV1Profile0),
 MAP(AV1, AV1_HIGH,AV1Profile1),
 #endif
+#if VA_CHECK_VERSION(1, 22, 0)
+MAP(H266,VVC_MAIN_10, VVCMain10),
+#endif
 
 #undef MAP
 };
@@ -627,6 +630,10 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 case AV_CODEC_ID_VP8:
 frames->initial_pool_size += 3;
 break;
+case AV_CODEC_ID_H266:
+// Add additional 16 for maximum 16 frames delay in vvc native 
decode.
+frames->initial_pool_size += 32;
+break;
 default:
 frames->initial_pool_size += 2;
 }
diff --git a/libavcodec/vaapi_vvc.c b/libavcodec/vaapi_vvc.c
new file mode 100644
index 00..6141005688
--- /dev/null
+++ b/libavcodec/vaapi_vvc.c
@@ -0,0 +1,657 @@
+/*
+ * VVC HW decode acceleration through VA API
+ *
+ * Copyright (c) 2024 Intel Corporation
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+

[FFmpeg-devel] [PATCH v1 6/7] lavc/vvc_dec: Add hardware decode API

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/vvc/vvc_refs.c |  6 
 libavcodec/vvc/vvcdec.c   | 67 +++
 libavcodec/vvc/vvcdec.h   |  5 +++
 3 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c
index bf70777550..c9f89a5a0a 100644
--- a/libavcodec/vvc/vvc_refs.c
+++ b/libavcodec/vvc/vvc_refs.c
@@ -25,6 +25,7 @@
 #include "libavutil/thread.h"
 #include "libavcodec/refstruct.h"
 #include "libavcodec/thread.h"
+#include "libavcodec/decode.h"
 
 #include "vvc_refs.h"
 
@@ -56,6 +57,7 @@ void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, 
int flags)
 ff_refstruct_unref(>rpl_tab);
 
 frame->collocated_ref = NULL;
+ff_refstruct_unref(>hwaccel_picture_private);
 }
 }
 
@@ -138,6 +140,10 @@ static VVCFrame *alloc_frame(VVCContext *s, 
VVCFrameContext *fc)
 if (!frame->progress)
 goto fail;
 
+ret = ff_hwaccel_frame_priv_alloc(s->avctx, 
>hwaccel_picture_private);
+if (ret < 0)
+goto fail;
+
 return frame;
 fail:
 ff_vvc_unref_frame(fc, frame, ~0);
diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
index d5704aca25..f2e269ce76 100644
--- a/libavcodec/vvc/vvcdec.c
+++ b/libavcodec/vvc/vvcdec.c
@@ -24,6 +24,8 @@
 #include "libavcodec/decode.h"
 #include "libavcodec/profiles.h"
 #include "libavcodec/refstruct.h"
+#include "libavcodec/hwconfig.h"
+#include "libavcodec/hwaccel_internal.h"
 #include "libavutil/cpu.h"
 #include "libavutil/thread.h"
 
@@ -563,6 +565,8 @@ static int ref_frame(VVCFrame *dst, const VVCFrame *src)
 
 ff_refstruct_replace(>rpl_tab, src->rpl_tab);
 ff_refstruct_replace(>rpl, src->rpl);
+ff_refstruct_replace(>hwaccel_picture_private,
+  src->hwaccel_picture_private);
 dst->nb_rpl_elems = src->nb_rpl_elems;
 
 dst->poc = src->poc;
@@ -718,17 +722,41 @@ static int slice_start(SliceContext *sc, VVCContext *s, 
VVCFrameContext *fc,
 return 0;
 }
 
+static enum AVPixelFormat get_format(AVCodecContext *avctx, const VVCSPS *sps)
+{
+#define HWACCEL_MAX 0
+
+enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
+
+switch (sps->pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+break;
+case AV_PIX_FMT_YUV420P10:
+break;
+}
+
+*fmt++ = sps->pix_fmt;
+*fmt = AV_PIX_FMT_NONE;
+
+return ff_get_format(avctx, pix_fmts);
+}
+
 static void export_frame_params(VVCContext *s, const VVCFrameContext *fc)
 {
 AVCodecContext *c = s->avctx;
 const VVCSPS *sps = fc->ps.sps;
 const VVCPPS *pps = fc->ps.pps;
 
-c->pix_fmt  = sps->pix_fmt;
-c->coded_width  = pps->width;
-c->coded_height = pps->height;
-c->width= pps->width  - ((pps->r->pps_conf_win_left_offset + 
pps->r->pps_conf_win_right_offset) << sps->hshift[CHROMA]);
-c->height   = pps->height - ((pps->r->pps_conf_win_top_offset + 
pps->r->pps_conf_win_bottom_offset) << sps->vshift[CHROMA]);
+// Reset HW config if pix_fmt/w/h change.
+if (s->pix_fmt != sps->pix_fmt || c->coded_width != pps->width || 
c->coded_height != pps->height) {
+c->coded_width  = pps->width;
+c->coded_height = pps->height;
+c->pix_fmt  = get_format(c, sps);
+s->pix_fmt  = sps->pix_fmt;
+}
+
+c->width  = pps->width  - ((pps->r->pps_conf_win_left_offset + 
pps->r->pps_conf_win_right_offset) << sps->hshift[CHROMA]);
+c->height = pps->height - ((pps->r->pps_conf_win_top_offset + 
pps->r->pps_conf_win_bottom_offset) << sps->vshift[CHROMA]);
 }
 
 static int frame_setup(VVCFrameContext *fc, VVCContext *s)
@@ -771,6 +799,20 @@ static int decode_slice(VVCContext *s, VVCFrameContext 
*fc, const H2645NAL *nal,
 ret = slice_init_entry_points(sc, fc, nal, unit);
 if (ret < 0)
 return ret;
+
+if (s->avctx->hwaccel) {
+if (is_first_slice) {
+ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
+if (ret < 0)
+return ret;
+}
+
+ret = FF_HW_CALL(s->avctx, decode_slice,
+ nal->raw_data, nal->raw_size);
+if (ret < 0)
+return ret;
+}
+
 fc->nb_slices++;
 
 return 0;
@@ -885,9 +927,20 @@ static int wait_delayed_frame(VVCContext *s, AVFrame 
*output, int *got_output)
 static int submit_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *output, 
int *got_output)
 {
 int ret;
+
+if (s->avctx->hwaccel) {
+if (ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame) < 0) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Hardware accelerator failed to decode picture\n");
+ff_vvc_unref_frame(fc, fc->ref, ~0);
+return ret;
+}
+} else
+ff_vvc_frame_submit(s, fc);
+
 s->nb_frames++;
 s->nb_delayed++;
-ff_vvc_frame_submit(s, fc);
+
 if (s->nb_delayed >= s->nb_fcs) {
 if ((ret = 

[FFmpeg-devel] [PATCH v1 5/7] lavc/vvc_ps: Add alf raw syntax into VVCALF

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/vvc/vvc_ps.c | 10 +-
 libavcodec/vvc/vvc_ps.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 7972803da6..97eef85be9 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -873,13 +873,21 @@ static void alf_derive(VVCALF *alf, const H266RawAPS *aps)
 alf_cc(alf, aps);
 }
 
+static void alf_free(FFRefStructOpaque unused, void *obj)
+{
+VVCALF *alf = obj;
+
+ff_refstruct_unref(>r);
+}
+
 static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps)
 {
-VVCALF *a = ff_refstruct_allocz(sizeof(*a));
+VVCALF *a = ff_refstruct_alloc_ext(sizeof(*a), 0, NULL, alf_free);
 if (!a)
 return AVERROR(ENOMEM);
 
 alf_derive(a, aps);
+ff_refstruct_replace(>r, aps);
 ff_refstruct_replace(alf, a);
 ff_refstruct_unref();
 
diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h
index 1164d0eab6..d306e0354a 100644
--- a/libavcodec/vvc/vvc_ps.h
+++ b/libavcodec/vvc/vvc_ps.h
@@ -159,6 +159,7 @@ typedef struct VVCPH {
 #define ALF_NUM_COEFF_CC 7
 
 typedef struct VVCALF {
+const H266RawAPS *r;
 int16_t luma_coeff [ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA];
 uint8_t luma_clip_idx  [ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA];
 
-- 
2.25.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 v1 4/7] lavc/cbs_h266: Add NumSlicesInTile to H266RawPPS

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/cbs_h266.h |  1 +
 libavcodec/cbs_h266_syntax_template.c | 16 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 19f83aeb49..87bd39c6f5 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -594,6 +594,7 @@ typedef struct H266RawPPS {
 uint16_t col_width_val[VVC_MAX_TILE_COLUMNS];
 uint16_t row_height_val[VVC_MAX_TILE_ROWS];
 uint16_t slice_top_left_tile_idx[VVC_MAX_SLICES];
+uint16_t num_slices_in_tile[VVC_MAX_SLICES];
 } H266RawPPS;
 
 typedef struct H266RawAPS {
diff --git a/libavcodec/cbs_h266_syntax_template.c 
b/libavcodec/cbs_h266_syntax_template.c
index 12f821b3fd..3f378d199e 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -1976,14 +1976,13 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
 current->pps_slice_height_in_tiles_minus1[i] == 0 &&
 current->row_height_val[tile_y] > 1) {
-int num_slices_in_tile,
-uniform_slice_height, remaining_height_in_ctbs_y;
+int uniform_slice_height, remaining_height_in_ctbs_y;
 remaining_height_in_ctbs_y =
 current->row_height_val[tile_y];
 ues(pps_num_exp_slices_in_tile[i],
 0, current->row_height_val[tile_y] - 1, 1, i);
 if (current->pps_num_exp_slices_in_tile[i] == 0) {
-num_slices_in_tile = 1;
+current->num_slices_in_tile[i] = 1;
 current->slice_height_in_ctus[i] = 
current->row_height_val[tile_y];
 slice_top_left_ctu_x[i] = ctu_x;
 slice_top_left_ctu_y[i] = ctu_y;
@@ -2026,14 +2025,18 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 slice_top_left_ctu_y[i + j] = ctu_y;
 j++;
 }
-num_slices_in_tile = j;
+current->num_slices_in_tile[i] = j;
 }
-for (int k = 0; k < num_slices_in_tile; k++)
+for (int k = 0; k < current->num_slices_in_tile[i]; k++)
 current->slice_top_left_tile_idx[i + k] = tile_idx;
-i += num_slices_in_tile - 1;
+i += current->num_slices_in_tile[i] - 1;
 } else {
 uint16_t height = 0;
 infer(pps_num_exp_slices_in_tile[i], 0);
+if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
+current->pps_slice_height_in_tiles_minus1[i] == 0)
+current->num_slices_in_tile[i] = 1;
+
 for (j = 0;
  j <= current->pps_slice_height_in_tiles_minus1[i];
  j++) {
@@ -2074,6 +2077,7 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 uint16_t height = 0;
 
 current->slice_top_left_tile_idx[i] = tile_idx;
+current->num_slices_in_tile[i] = 1;
 tile_x = tile_idx % current->num_tile_columns;
 tile_y = tile_idx / current->num_tile_columns;
 if (tile_y >= current->num_tile_rows)
-- 
2.25.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 v1 3/7] lavc/cbs_h266: Add SliceTopLeftTileIdx to H266RawPPS

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/cbs_h266.h | 1 +
 libavcodec/cbs_h266_syntax_template.c | 4 
 2 files changed, 5 insertions(+)

diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 73d94157d4..19f83aeb49 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -593,6 +593,7 @@ typedef struct H266RawPPS {
 uint16_t sub_pic_id_val[VVC_MAX_SLICES];
 uint16_t col_width_val[VVC_MAX_TILE_COLUMNS];
 uint16_t row_height_val[VVC_MAX_TILE_ROWS];
+uint16_t slice_top_left_tile_idx[VVC_MAX_SLICES];
 } H266RawPPS;
 
 typedef struct H266RawAPS {
diff --git a/libavcodec/cbs_h266_syntax_template.c 
b/libavcodec/cbs_h266_syntax_template.c
index 0aae9fdfd5..12f821b3fd 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -1945,6 +1945,7 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 else
 infer(pps_tile_idx_delta_present_flag, 0);
 for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
+current->slice_top_left_tile_idx[i] = tile_idx;
 tile_x = tile_idx % current->num_tile_columns;
 tile_y = tile_idx / current->num_tile_columns;
 if (tile_x != current->num_tile_columns - 1) {
@@ -2027,6 +2028,8 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 }
 num_slices_in_tile = j;
 }
+for (int k = 0; k < num_slices_in_tile; k++)
+current->slice_top_left_tile_idx[i + k] = tile_idx;
 i += num_slices_in_tile - 1;
 } else {
 uint16_t height = 0;
@@ -2070,6 +2073,7 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 if (i == current->pps_num_slices_in_pic_minus1) {
 uint16_t height = 0;
 
+current->slice_top_left_tile_idx[i] = tile_idx;
 tile_x = tile_idx % current->num_tile_columns;
 tile_y = tile_idx / current->num_tile_columns;
 if (tile_y >= current->num_tile_rows)
-- 
2.25.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 v1 2/7] lavc/vvc_refs: Move definition of VVC_FRAME_FLAG* to h header

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

So that hardware decoder can use the flags too.

Signed-off-by: Fei Wang 
---
 libavcodec/vvc/vvc_refs.c | 4 
 libavcodec/vvc/vvc_refs.h | 5 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c
index afcfc09da7..bf70777550 100644
--- a/libavcodec/vvc/vvc_refs.c
+++ b/libavcodec/vvc/vvc_refs.c
@@ -28,10 +28,6 @@
 
 #include "vvc_refs.h"
 
-#define VVC_FRAME_FLAG_OUTPUT(1 << 0)
-#define VVC_FRAME_FLAG_SHORT_REF (1 << 1)
-#define VVC_FRAME_FLAG_LONG_REF  (1 << 2)
-#define VVC_FRAME_FLAG_BUMPING   (1 << 3)
 
 typedef struct FrameProgress {
 atomic_int progress[VVC_PROGRESS_LAST];
diff --git a/libavcodec/vvc/vvc_refs.h b/libavcodec/vvc/vvc_refs.h
index eba4422fb4..509fc6af22 100644
--- a/libavcodec/vvc/vvc_refs.h
+++ b/libavcodec/vvc/vvc_refs.h
@@ -25,6 +25,11 @@
 
 #include "vvcdec.h"
 
+#define VVC_FRAME_FLAG_OUTPUT(1 << 0)
+#define VVC_FRAME_FLAG_SHORT_REF (1 << 1)
+#define VVC_FRAME_FLAG_LONG_REF  (1 << 2)
+#define VVC_FRAME_FLAG_BUMPING   (1 << 3)
+
 int ff_vvc_output_frame(VVCContext *s, VVCFrameContext *fc, struct AVFrame 
*out, int no_output_of_prior_pics_flag, int flush);
 void ff_vvc_bump_frame(VVCContext *s, VVCFrameContext *fc);
 int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, struct AVFrame 
**frame);
-- 
2.25.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 v1 1/7] lavc/vaapi_dec: Create VA parameters dynamically

2024-03-27 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_decode.c | 29 ++---
 libavcodec/vaapi_decode.h |  7 ++-
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index cca94b5336..1b1972a2a9 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -38,12 +38,23 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 {
 VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
 VAStatus vas;
-VABufferID buffer;
 
-av_assert0(pic->nb_param_buffers + 1 <= MAX_PARAM_BUFFERS);
+av_assert0(pic->nb_param_buffers <= pic->param_allocated);
+if (pic->nb_param_buffers == pic->param_allocated) {
+pic->param_buffers =
+av_realloc_array(pic->param_buffers,
+ pic->param_allocated + 16,
+ sizeof(*pic->param_buffers));
+if (!pic->param_buffers)
+return AVERROR(ENOMEM);
+
+pic->param_allocated += 16;
+}
+av_assert0(pic->nb_param_buffers + 1 <= pic->param_allocated);
 
 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
- type, size, 1, (void*)data, );
+ type, size, 1, (void*)data,
+ >param_buffers[pic->nb_param_buffers]);
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to create parameter "
"buffer (type %d): %d (%s).\n",
@@ -51,14 +62,14 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 return AVERROR(EIO);
 }
 
-pic->param_buffers[pic->nb_param_buffers++] = buffer;
-
 av_log(avctx, AV_LOG_DEBUG, "Param buffer (type %d, %zu bytes) "
-   "is %#x.\n", type, size, buffer);
+   "is %#x.\n", type, size, pic->param_buffers[pic->nb_param_buffers]);
+
+++pic->nb_param_buffers;
+
 return 0;
 }
 
-
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
   VAAPIDecodePicture *pic,
   const void *params_data,
@@ -215,6 +226,8 @@ fail:
 fail_at_end:
 exit:
 pic->nb_param_buffers = 0;
+pic->param_allocated  = 0;
+av_freep(>param_buffers);
 pic->nb_slices= 0;
 pic->slices_allocated = 0;
 av_freep(>slice_buffers);
@@ -228,6 +241,8 @@ int ff_vaapi_decode_cancel(AVCodecContext *avctx,
 ff_vaapi_decode_destroy_buffers(avctx, pic);
 
 pic->nb_param_buffers = 0;
+pic->param_allocated  = 0;
+av_freep(>param_buffers);
 pic->nb_slices= 0;
 pic->slices_allocated = 0;
 av_freep(>slice_buffers);
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..a41d7ff2ff 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -32,15 +32,12 @@ static inline VASurfaceID ff_vaapi_get_surface_id(AVFrame 
*pic)
 return (uintptr_t)pic->data[3];
 }
 
-enum {
-MAX_PARAM_BUFFERS = 16,
-};
-
 typedef struct VAAPIDecodePicture {
 VASurfaceID   output_surface;
 
 intnb_param_buffers;
-VABufferIDparam_buffers[MAX_PARAM_BUFFERS];
+VABufferID   *param_buffers;
+int   param_allocated;
 
 intnb_slices;
 VABufferID   *slice_buffers;
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 3/3] avcodec/h264dec: Reindent after the previous commit

2024-03-27 Thread arch1t3cht
Signed-off-by: arch1t3cht 
---
 libavcodec/h264dec.c | 46 ++--
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 68f47912e2..6f62fadb11 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -999,32 +999,32 @@ static int send_next_delayed_frame(H264Context *h, 
AVFrame *dst_frame,
 h->first_field = 0;
 
 while (h->delayed_pic[0]) {
-out = h->delayed_pic[0];
-out_idx = 0;
-for (i = 1;
- h->delayed_pic[i] &&
- !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) &&
- !h->delayed_pic[i]->mmco_reset;
- i++)
-if (h->delayed_pic[i]->poc < out->poc) {
-out = h->delayed_pic[i];
-out_idx = i;
-}
+out = h->delayed_pic[0];
+out_idx = 0;
+for (i = 1;
+ h->delayed_pic[i] &&
+ !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) &&
+ !h->delayed_pic[i]->mmco_reset;
+ i++)
+if (h->delayed_pic[i]->poc < out->poc) {
+out = h->delayed_pic[i];
+out_idx = i;
+}
 
-for (i = out_idx; h->delayed_pic[i]; i++)
-h->delayed_pic[i] = h->delayed_pic[i + 1];
+for (i = out_idx; h->delayed_pic[i]; i++)
+h->delayed_pic[i] = h->delayed_pic[i + 1];
 
-if (out) {
-h->frame_recovered |= out->recovered;
-out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI;
+if (out) {
+h->frame_recovered |= out->recovered;
+out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI;
 
-out->reference &= ~DELAYED_PIC_REF;
-ret = finalize_frame(h, dst_frame, out, got_frame);
-if (ret < 0)
-return ret;
-if (*got_frame)
-break;
-}
+out->reference &= ~DELAYED_PIC_REF;
+ret = finalize_frame(h, dst_frame, out, got_frame);
+if (ret < 0)
+return ret;
+if (*got_frame)
+break;
+}
 }
 
 return buf_index;
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 2/3] avcodec/h264dec: Handle non-recovered frames when draining

2024-03-27 Thread arch1t3cht
When starting on a SEI recovery point close enough to the end of
the stream that draining starts before the recovery point's frame
is output, there can be non-recovered frames in the delayed picture
buffer that would currently cause the decoder to fail to output a
frame. This commit skips such frames and outputs the first recovered
frame, if there exists one.

Signed-off-by: arch1t3cht 
---
 libavcodec/h264dec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8503ea018a..68f47912e2 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -993,11 +993,13 @@ static int send_next_delayed_frame(H264Context *h, 
AVFrame *dst_frame,
int *got_frame, int buf_index)
 {
 int ret, i, out_idx;
-H264Picture *out = h->delayed_pic[0];
+H264Picture *out;
 
 h->cur_pic_ptr = NULL;
 h->first_field = 0;
 
+while (h->delayed_pic[0]) {
+out = h->delayed_pic[0];
 out_idx = 0;
 for (i = 1;
  h->delayed_pic[i] &&
@@ -1020,6 +1022,9 @@ static int send_next_delayed_frame(H264Context *h, 
AVFrame *dst_frame,
 ret = finalize_frame(h, dst_frame, out, got_frame);
 if (ret < 0)
 return ret;
+if (*got_frame)
+break;
+}
 }
 
 return buf_index;
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 1/3] avcodec/h264dec: Properly mark frames as recovered when draining

2024-03-27 Thread arch1t3cht
When decoding starts at a SEI recovery point very shortly before the
end of the video stream, there can be frames which are decoded before
the recovery point's frame is output and which will only be output once
the draining has started. Previously, these frames would never be set
as recovered. This commit copies the logic from h264_select_output_frame
to send_next_delayed_frame to properly mark such frames as recovered.

Fixes ticket #10936.

Signed-off-by: arch1t3cht 
---
 libavcodec/h264dec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index b4973fce29..8503ea018a 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1013,6 +1013,9 @@ static int send_next_delayed_frame(H264Context *h, 
AVFrame *dst_frame,
 h->delayed_pic[i] = h->delayed_pic[i + 1];
 
 if (out) {
+h->frame_recovered |= out->recovered;
+out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI;
+
 out->reference &= ~DELAYED_PIC_REF;
 ret = finalize_frame(h, dst_frame, out, got_frame);
 if (ret < 0)
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 0/3] avcodec/h264dec: Fix dropped frames when draining

2024-03-27 Thread arch1t3cht
Fix one or more frames being dropped when starting decoding at a SEI
recovery point that is very close to the end of the stream
(specifically, which is less than 2 * has_b_frames frames before the
end of the stream in decoding order). One case of this was reported
in ticket #10936.

Tested for regressions using FATE. If necessary I can also try to add
a test for the previously broken behavior.

There's now a bit of code duplication between
h264_select_output_frame and send_next_delayed_frame (or, rather,
there was already some code duplication and this patch
adds a bit more). But this probably cannot be avoided without a larger
refactor to, say, also call h264_select_output_frame in
send_next_delayed_frame instead of manually selecting a frame, which
I don't feel confident enough to do myself.

arch1t3cht (3):
  avcodec/h264dec: Properly mark frames as recovered when draining
  avcodec/h264dec: Handle non-recovered frames when draining
  avcodec/h264dec: Reindent after the previous commit

 libavcodec/h264dec.c | 44 ++--
 1 file changed, 26 insertions(+), 18 deletions(-)

-- 
2.44.0

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

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


Re: [FFmpeg-devel] [PATCH] Make Immersive Audio Model optional for MOV demuxing

2024-03-27 Thread Eugene Zemtsov via ffmpeg-devel
> Can you elaborate why you need this? In configure the mov demuxer
> selects iamfdec, so it will always be present and compiled.

Chromium doesn't use Immersive Audio, but the code for handling it
bloats Android binaries,
that's why we disabled it.

I have a second patch that disables iamfdec by default for mov demuxer,
but I had a feeling that maintainers will be less inclined to accept
it and that's why I split it from this one.
I will still try to send it if this patch is accepted.


On Wed, Mar 27, 2024 at 4:59 PM James Almer  wrote:
>
> On 3/27/2024 8:55 PM, Eugene Zemtsov via ffmpeg-devel wrote:
> > From: Eugene Zemtsov 
> >
> > Signed-off-by: Eugene Zemtsov 
> > ---
> >   libavformat/mov.c | 15 ++-
> >   1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index c55778f3ef..662301bf67 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -839,6 +839,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext 
> > *pb, MOVAtom atom)
> >   return 0;
> >   }
> >
> > +#if CONFIG_IAMFDEC
> >   static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >   {
> >   AVStream *st;
> > @@ -1015,6 +1016,7 @@ fail:
> >
> >   return ret;
> >   }
> > +#endif
> >
> >   static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >   {
> > @@ -4797,6 +4799,7 @@ static void fix_timescale(MOVContext *c, 
> > MOVStreamContext *sc)
> >   }
> >   }
> >
> > +#if CONFIG_IAMFDEC
> >   static int mov_update_iamf_streams(MOVContext *c, const AVStream *st)
> >   {
> >   const MOVStreamContext *sc = st->priv_data;
> > @@ -4840,6 +4843,7 @@ static int mov_update_iamf_streams(MOVContext *c, 
> > const AVStream *st)
> >
> >   return 0;
> >   }
> > +#endif
> >
> >   static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >   {
> > @@ -4921,11 +4925,13 @@ static int mov_read_trak(MOVContext *c, AVIOContext 
> > *pb, MOVAtom atom)
> >
> >   mov_build_index(c, st);
> >
> > +#if CONFIG_IAMFDEC
> >   if (sc->iamf) {
> >   ret = mov_update_iamf_streams(c, st);
> >   if (ret < 0)
> >   return ret;
> >   }
> > +#endif
> >
> >   if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) 
> > {
> >   MOVDref *dref = >drefs[sc->dref_id - 1];
> > @@ -8457,7 +8463,9 @@ static const MOVParseTableEntry 
> > mov_default_parse_table[] = {
> >   { MKTAG('i','p','r','p'), mov_read_iprp },
> >   { MKTAG('i','i','n','f'), mov_read_iinf },
> >   { MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment 
> > box */
> > +#if CONFIG_IAMFDEC
> >   { MKTAG('i','a','c','b'), mov_read_iacb },
> > +#endif
> >   { 0, NULL }
> >   };
> >
> > @@ -8929,8 +8937,10 @@ static void mov_free_stream_context(AVFormatContext 
> > *s, AVStream *st)
> >   av_freep(>coll);
> >   av_freep(>ambient);
> >
> > +#if CONFIG_IAMFDEC
> >   if (sc->iamf)
> >   ff_iamf_read_deinit(sc->iamf);
> > +#endif
> >   av_freep(>iamf);
> >   }
> >
> > @@ -9570,6 +9580,7 @@ static int mov_read_packet(AVFormatContext *s, 
> > AVPacket *pkt)
> >
> >   if (st->codecpar->codec_id == AV_CODEC_ID_EIA_608 && sample->size 
> > > 8)
> >   ret = get_eia608_packet(sc->pb, pkt, sample->size);
> > +#if CONFIG_IAMFDEC
> >   else if (sc->iamf) {
> >   int64_t pts, dts, pos, duration;
> >   int flags, size = sample->size;
> > @@ -9592,7 +9603,9 @@ static int mov_read_packet(AVFormatContext *s, 
> > AVPacket *pkt)
> >   }
> >   if (!ret)
> >   return FFERROR_REDO;
> > -} else
> > +}
> > +#endif
> > +else
> >   ret = av_get_packet(sc->pb, pkt, sample->size);
> >   if (ret < 0) {
> >   if (should_retry(sc->pb, ret)) {
>
> Can you elaborate why you need this? In configure the mov demuxer
> selects iamfdec, so it will always be present and compiled.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



-- 
Thanks,
Eugene Zemtsov.
___
ffmpeg-devel mailing list
ffmpeg-devel@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] Make Immersive Audio Model optional for MOV demuxing

2024-03-27 Thread James Almer

On 3/27/2024 8:55 PM, Eugene Zemtsov via ffmpeg-devel wrote:

From: Eugene Zemtsov 

Signed-off-by: Eugene Zemtsov 
---
  libavformat/mov.c | 15 ++-
  1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index c55778f3ef..662301bf67 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -839,6 +839,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
  return 0;
  }
  
+#if CONFIG_IAMFDEC

  static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom)
  {
  AVStream *st;
@@ -1015,6 +1016,7 @@ fail:
  
  return ret;

  }
+#endif
  
  static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)

  {
@@ -4797,6 +4799,7 @@ static void fix_timescale(MOVContext *c, MOVStreamContext 
*sc)
  }
  }
  
+#if CONFIG_IAMFDEC

  static int mov_update_iamf_streams(MOVContext *c, const AVStream *st)
  {
  const MOVStreamContext *sc = st->priv_data;
@@ -4840,6 +4843,7 @@ static int mov_update_iamf_streams(MOVContext *c, const 
AVStream *st)
  
  return 0;

  }
+#endif
  
  static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)

  {
@@ -4921,11 +4925,13 @@ static int mov_read_trak(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
  
  mov_build_index(c, st);
  
+#if CONFIG_IAMFDEC

  if (sc->iamf) {
  ret = mov_update_iamf_streams(c, st);
  if (ret < 0)
  return ret;
  }
+#endif
  
  if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {

  MOVDref *dref = >drefs[sc->dref_id - 1];
@@ -8457,7 +8463,9 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
  { MKTAG('i','p','r','p'), mov_read_iprp },
  { MKTAG('i','i','n','f'), mov_read_iinf },
  { MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box 
*/
+#if CONFIG_IAMFDEC
  { MKTAG('i','a','c','b'), mov_read_iacb },
+#endif
  { 0, NULL }
  };
  
@@ -8929,8 +8937,10 @@ static void mov_free_stream_context(AVFormatContext *s, AVStream *st)

  av_freep(>coll);
  av_freep(>ambient);
  
+#if CONFIG_IAMFDEC

  if (sc->iamf)
  ff_iamf_read_deinit(sc->iamf);
+#endif
  av_freep(>iamf);
  }
  
@@ -9570,6 +9580,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
  
  if (st->codecpar->codec_id == AV_CODEC_ID_EIA_608 && sample->size > 8)

  ret = get_eia608_packet(sc->pb, pkt, sample->size);
+#if CONFIG_IAMFDEC
  else if (sc->iamf) {
  int64_t pts, dts, pos, duration;
  int flags, size = sample->size;
@@ -9592,7 +9603,9 @@ static int mov_read_packet(AVFormatContext *s, AVPacket 
*pkt)
  }
  if (!ret)
  return FFERROR_REDO;
-} else
+}
+#endif
+else
  ret = av_get_packet(sc->pb, pkt, sample->size);
  if (ret < 0) {
  if (should_retry(sc->pb, ret)) {


Can you elaborate why you need this? In configure the mov demuxer 
selects iamfdec, so it will always be present and compiled.

___
ffmpeg-devel mailing list
ffmpeg-devel@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] Make Immersive Audio Model optional for MOV demuxing

2024-03-27 Thread Eugene Zemtsov via ffmpeg-devel
From: Eugene Zemtsov 

Signed-off-by: Eugene Zemtsov 
---
 libavformat/mov.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index c55778f3ef..662301bf67 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -839,6 +839,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+#if CONFIG_IAMFDEC
 static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -1015,6 +1016,7 @@ fail:
 
 return ret;
 }
+#endif
 
 static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
@@ -4797,6 +4799,7 @@ static void fix_timescale(MOVContext *c, MOVStreamContext 
*sc)
 }
 }
 
+#if CONFIG_IAMFDEC
 static int mov_update_iamf_streams(MOVContext *c, const AVStream *st)
 {
 const MOVStreamContext *sc = st->priv_data;
@@ -4840,6 +4843,7 @@ static int mov_update_iamf_streams(MOVContext *c, const 
AVStream *st)
 
 return 0;
 }
+#endif
 
 static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
@@ -4921,11 +4925,13 @@ static int mov_read_trak(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 
 mov_build_index(c, st);
 
+#if CONFIG_IAMFDEC
 if (sc->iamf) {
 ret = mov_update_iamf_streams(c, st);
 if (ret < 0)
 return ret;
 }
+#endif
 
 if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
 MOVDref *dref = >drefs[sc->dref_id - 1];
@@ -8457,7 +8463,9 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('i','p','r','p'), mov_read_iprp },
 { MKTAG('i','i','n','f'), mov_read_iinf },
 { MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box 
*/
+#if CONFIG_IAMFDEC
 { MKTAG('i','a','c','b'), mov_read_iacb },
+#endif
 { 0, NULL }
 };
 
@@ -8929,8 +8937,10 @@ static void mov_free_stream_context(AVFormatContext *s, 
AVStream *st)
 av_freep(>coll);
 av_freep(>ambient);
 
+#if CONFIG_IAMFDEC
 if (sc->iamf)
 ff_iamf_read_deinit(sc->iamf);
+#endif
 av_freep(>iamf);
 }
 
@@ -9570,6 +9580,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 if (st->codecpar->codec_id == AV_CODEC_ID_EIA_608 && sample->size > 8)
 ret = get_eia608_packet(sc->pb, pkt, sample->size);
+#if CONFIG_IAMFDEC
 else if (sc->iamf) {
 int64_t pts, dts, pos, duration;
 int flags, size = sample->size;
@@ -9592,7 +9603,9 @@ static int mov_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 }
 if (!ret)
 return FFERROR_REDO;
-} else
+}
+#endif
+else
 ret = av_get_packet(sc->pb, pkt, sample->size);
 if (ret < 0) {
 if (should_retry(sc->pb, ret)) {
-- 
2.44.0.396.g6e790dbe36-goog

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

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


Re: [FFmpeg-devel] [PATCH] avutil/tests/.gitignore: Add side_data_array

2024-03-27 Thread James Almer

On 3/27/2024 1:37 PM, Andreas Rheinhardt wrote:

Signed-off-by: Andreas Rheinhardt 
---
  libavutil/tests/.gitignore | 1 +
  1 file changed, 1 insertion(+)

diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 87895912f5..951cafb2d7 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -44,6 +44,7 @@
  /ripemd
  /sha
  /sha512
+/side_data_array
  /softfloat
  /tea
  /tree


LGTM.
___
ffmpeg-devel mailing list
ffmpeg-devel@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] avformat/cafdec: sanity check channels and bps

2024-03-27 Thread Michael Niedermayer
On Wed, Mar 27, 2024 at 08:39:17AM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2024-03-23 00:08:16)
> > Fixes: Timeout
> > Fixes: 
> > 67044/clusterfuzz-testcase-minimized-ffmpeg_dem_CAF_fuzzer-5791144363491328
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/cafdec.c | 5 +
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
> > index 426c56b9bd..334077efb5 100644
> > --- a/libavformat/cafdec.c
> > +++ b/libavformat/cafdec.c
> > @@ -33,6 +33,7 @@
> >  #include "isom.h"
> >  #include "mov_chan.h"
> >  #include "libavcodec/flac.h"
> > +#include "libavcodec/internal.h"
> >  #include "libavutil/intreadwrite.h"
> >  #include "libavutil/intfloat.h"
> >  #include "libavutil/dict.h"
> > @@ -87,6 +88,10 @@ static int read_desc_chunk(AVFormatContext *s)
> >  st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
> >  st->codecpar->bits_per_coded_sample = avio_rb32(pb);
> >  
> > +if (st->codecpar->ch_layout.nb_channels > FF_SANE_NB_CHANNELS ||
> 
> I dislike this.

I dislike it too

thx

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

Republics decline into democracies and democracies degenerate into
despotisms. -- 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] [FFmpeg-cvslog] fftools/ffplay: use correct buffersink channel layout parameters

2024-03-27 Thread Michael Niedermayer
On Wed, Mar 27, 2024 at 09:52:54PM +0100, Marton Balint wrote:
> 
> 
> On Wed, 27 Mar 2024, Michael Niedermayer wrote:
> 
> > On Tue, Mar 19, 2024 at 07:54:20PM +, Marton Balint wrote:
> > > ffmpeg | branch: master | Marton Balint  | Mon Mar 18 
> > > 21:07:20 2024 +0100| [7251f909721a570726775acf61b2b9c28a950c76] | 
> > > committer: Marton Balint
> > > 
> > > fftools/ffplay: use correct buffersink channel layout parameters
> > > 
> > > Regression since 0995e1f1b31f6e937a1b527407ed3e850f138098.
> > > 
> > > Signed-off-by: Marton Balint 
> > > 
> > > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7251f909721a570726775acf61b2b9c28a950c76
> > > ---
> > > 
> > >  fftools/ffplay.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > 
> > This breaks_
> > ./ffplay fate-suite/wav/200828-005.wav
> > 
> > [ffplay_abuffersink @ 0x7feef8008700] Channel layout change is not supported
> > 
> > should i open a ticket ?
> 
> No, there is already a patch for this under review:
> 
> https://lists.ffmpeg.org//pipermail/ffmpeg-devel/2024-March/324092.html

ok, please make sure this makes it into release/7.0 too

thx

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

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- 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] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-03-27 Thread Yiğithan Yiğit
According to Paul's private remarks I made this last patch. I would greatly
appreciate it if anyone could take the time to review these changes.
From 9d9ebcde761ce83c82c40f7537e7644f0c8d753b Mon Sep 17 00:00:00 2001
From: yigithanyigit 
Date: Tue, 12 Mar 2024 01:27:59 +0300
Subject: [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support

Fixes #9613
---
 libavfilter/af_volumedetect.c | 228 +-
 1 file changed, 166 insertions(+), 62 deletions(-)

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index 8b001d1cf2..272ba287ec 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -24,94 +24,187 @@
 #include "avfilter.h"
 #include "internal.h"
 
+#define NOISE_FLOOR_DB_FLT -758
+#define MAX_DB_FLT 770
+#define MAX_DB 91
+#define HISTOGRAM_SIZE 0x1
+
 typedef struct VolDetectContext {
-/**
- * Number of samples at each PCM value.
- * histogram[0x8000 + i] is the number of samples at value i.
- * The extra element is there for symmetry.
- */
-uint64_t histogram[0x10001];
+uint64_t* histogram; ///< for integer number of samples at each PCM value, for float number of samples at each dB
+uint64_t nb_samples; ///< number of samples
+double sum2; ///< sum of the squares of the samples
+double max;  ///< maximum sample value
+int is_float;///< true if the input is in floating point
 } VolDetectContext;
 
+static inline double logdb(double v, enum AVSampleFormat sample_fmt)
+{
+if (sample_fmt == AV_SAMPLE_FMT_FLT) {
+if (!v)
+return MAX_DB_FLT;
+return 10.0 * log10(v * v);
+} else {
+double d = v / (double)(0x8000 * 0x8000);
+if (!v)
+return MAX_DB;
+return -log10(d) * 10;
+}
+}
+
+static void update_float_stats(VolDetectContext *vd, float *audio_data)
+{
+double max_sample;
+if(!isnormal(*audio_data))
+return;
+max_sample = fabsf(*audio_data);
+if (max_sample > vd->max)
+vd->max = max_sample;
+vd->sum2 += *audio_data * *audio_data;
+vd->histogram[(int)logdb(*audio_data, AV_SAMPLE_FMT_FLT) + MAX_DB_FLT]++;
+vd->nb_samples++;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
 {
 AVFilterContext *ctx = inlink->dst;
 VolDetectContext *vd = ctx->priv;
-int nb_samples  = samples->nb_samples;
 int nb_channels = samples->ch_layout.nb_channels;
 int nb_planes   = nb_channels;
+int nb_samples  = samples->nb_samples;
 int plane, i;
-int16_t *pcm;
+int planar = 0;
 
-if (!av_sample_fmt_is_planar(samples->format)) {
-nb_samples *= nb_channels;
+planar = av_sample_fmt_is_planar(samples->format);
+if (!planar)
 nb_planes = 1;
+if (vd->is_float) {
+float *audio_data;
+for (plane = 0; plane < nb_planes; plane++) {
+audio_data = (float *)samples->extended_data[plane];
+for (i = 0; i < nb_samples; i++) {
+if (planar)
+update_float_stats(vd, _data[i]);
+else
+for (int j = 0; j < nb_channels; j++)
+update_float_stats(vd, _data[i * nb_channels + j]);
+}
+}
+} else {
+int16_t *pcm;
+for (plane = 0; plane < nb_planes; plane++) {
+pcm = (int16_t *)samples->extended_data[plane];
+for (i = 0; i < nb_samples; i++) {
+if (planar) {
+vd->histogram[pcm[i] + 0x8000]++;
+vd->nb_samples++;
+} else {
+for (int j = 0; j < nb_channels; j++) {
+vd->histogram[pcm[i * nb_channels + j] + 0x8000]++;
+vd->nb_samples++;
+}
+}
+}
+}
 }
-for (plane = 0; plane < nb_planes; plane++) {
-pcm = (int16_t *)samples->extended_data[plane];
-for (i = 0; i < nb_samples; i++)
-vd->histogram[pcm[i] + 0x8000]++;
-}
-
 return ff_filter_frame(inlink->dst->outputs[0], samples);
 }
 
-#define MAX_DB 91
-
-static inline double logdb(uint64_t v)
+static void print_stats(AVFilterContext *ctx)
 {
-double d = v / (double)(0x8000 * 0x8000);
-if (!v)
-return MAX_DB;
-return -log10(d) * 10;
+VolDetectContext *vd = ctx->priv;
+
+if (!vd->nb_samples)
+return;
+if (vd->is_float) {
+int i, sum = 0;
+double rms;
+av_log(ctx, AV_LOG_INFO, "n_samples: %" PRId64 "\n", vd->nb_samples);
+rms = sqrt(vd->sum2 / vd->nb_samples);
+av_log(ctx, AV_LOG_INFO, "mean_volume: %.1f dB\n", logdb(rms, AV_SAMPLE_FMT_FLT));
+av_log(ctx, AV_LOG_INFO, "max_volume: %.1f dB\n", logdb(vd->max, AV_SAMPLE_FMT_FLT));
+for (i = MAX_DB_FLT - NOISE_FLOOR_DB_FLT; i >= 0 && !vd->histogram[i]; i--);
+for (; i >= 0 && sum < 

[FFmpeg-devel] [PATCH 4/4] Changelog: Add LC3/LC3plus decoding/encoding support

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index 934241a965..2282f8ca76 100644
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,7 @@ version :
 - Support PacketTypeMetadata of PacketType in enhanced flv format
 - ffplay with hwaccel decoding support (depends on vulkan renderer via 
libplacebo)
 - dnn filter libtorch backend
+- LC3/LC3plus decoding/encoding using external library liblc3
 
 
 version 6.1:
-- 
2.44.0.478.gd926399ef9-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@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/4] avformat/lc3: Add file format for LC3/LC3plus transport

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
A file format is described in Bluetooth SIG LC3 and ETSI TS 103 634, for
test purpose. This is the format implemented here.

Signed-off-by: Antoine Soulier 
---
 doc/muxers.texi  |   6 ++
 libavformat/Makefile |   2 +
 libavformat/allformats.c |   2 +
 libavformat/lc3dec.c | 135 +++
 libavformat/lc3enc.c | 102 +
 5 files changed, 247 insertions(+)
 create mode 100644 libavformat/lc3dec.c
 create mode 100644 libavformat/lc3enc.c

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a10a8e216f..9687746c30 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2612,6 +2612,12 @@ WebDAV server every second:
 ffmpeg -f x11grab -framerate 1 -i :0.0 -q:v 6 -update 1 -protocol_opts 
method=PUT http://example.com/desktop.jpg
 @end example
 
+@section lc3
+Bluetooth SIG Low Complexity Communication Codec audio (LC3), or
+ETSI TS 103 634 Low Complexity Communication Codec plus (LC3plus).
+
+This muxer accepts a single @code{lc3} audio stream.
+
 @section matroska
 
 Matroska container muxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 44aa485029..4961c42852 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -332,6 +332,8 @@ OBJS-$(CONFIG_KVAG_DEMUXER)  += kvag.o
 OBJS-$(CONFIG_KVAG_MUXER)+= kvag.o rawenc.o
 OBJS-$(CONFIG_LAF_DEMUXER)   += lafdec.o
 OBJS-$(CONFIG_LATM_MUXER)+= latmenc.o rawenc.o
+OBJS-$(CONFIG_LC3_DEMUXER)   += lc3dec.o
+OBJS-$(CONFIG_LC3_MUXER) += lc3enc.o
 OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o
 OBJS-$(CONFIG_LOAS_DEMUXER)  += loasdec.o rawdec.o
 OBJS-$(CONFIG_LUODAT_DEMUXER)+= luodatdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e15d0fa6d7..e225354faf 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -252,6 +252,8 @@ extern const FFInputFormat  ff_kvag_demuxer;
 extern const FFOutputFormat ff_kvag_muxer;
 extern const FFInputFormat  ff_laf_demuxer;
 extern const FFOutputFormat ff_latm_muxer;
+extern const FFInputFormat  ff_lc3_demuxer;
+extern const FFOutputFormat ff_lc3_muxer;
 extern const FFInputFormat  ff_lmlm4_demuxer;
 extern const FFInputFormat  ff_loas_demuxer;
 extern const FFInputFormat  ff_luodat_demuxer;
diff --git a/libavformat/lc3dec.c b/libavformat/lc3dec.c
new file mode 100644
index 00..9ca9825f1b
--- /dev/null
+++ b/libavformat/lc3dec.c
@@ -0,0 +1,135 @@
+/*
+ * LC3 demuxer
+ * Copyright (C) 2024  Antoine Soulier 
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Based on the file format specified by :
+ *
+ * - Bluetooth SIG - Low Complexity Communication Codec Test Suite
+ *   https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=502301
+ *   3.2.8.2 Reference LC3 Codec Bitstream Format
+ *
+ * - ETSI TI 103 634 V1.4.1 - Low Complexity Communication Codec plus
+ *   
https://www.etsi.org/deliver/etsi_ts/103600_103699/103634/01.04.01_60/ts_103634v010401p.pdf
+ *   LC3plus conformance script package
+ */
+
+#include "libavcodec/packet.h"
+#include "libavutil/intreadwrite.h"
+
+#include "avformat.h"
+#include "avio.h"
+#include "demux.h"
+#include "internal.h"
+
+typedef struct LC3DemuxContext {
+int frame_samples;
+int64_t position;
+int64_t length;
+} LC3DemuxContext;
+
+static int lc3_read_header(AVFormatContext *s)
+{
+LC3DemuxContext *lc3 = s->priv_data;
+AVStream *st = NULL;
+uint16_t tag, hdr_size;
+uint16_t frame_us;
+uint32_t length;
+int ep_mode, hr_mode;
+int srate_hz, channels, bit_rate;
+int num_extra_params, ret;
+
+tag = avio_rb16(s->pb);
+hdr_size = avio_rl16(s->pb);
+
+if (tag != 0x1ccc || hdr_size < 9 * sizeof(uint16_t))
+return AVERROR_INVALIDDATA;
+
+num_extra_params = hdr_size / sizeof(uint16_t) - 9;
+
+srate_hz = avio_rl16(s->pb) * 100;
+bit_rate = avio_rl16(s->pb) * 100;
+channels = avio_rl16(s->pb);
+frame_us = avio_rl16(s->pb) * 10;
+ep_mode  = avio_rl16(s->pb) != 0;
+length   = avio_rl32(s->pb);
+hr_mode  = num_extra_params >= 1 && avio_rl16(s->pb);
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return 

[FFmpeg-devel] [PATCH 2/4] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
The LC3 audio codec is the default codec of Bluetooth LE audio.
This is a wrapper over the liblc3 library (https://github.com/google/liblc3).

Signed-off-by: Antoine Soulier 
---
 doc/encoders.texi |  57 
 doc/general_contents.texi |  11 ++-
 libavcodec/Makefile   |   2 +
 libavcodec/allcodecs.c|   2 +
 libavcodec/codec_desc.c   |   7 ++
 libavcodec/codec_id.h |   1 +
 libavcodec/liblc3dec.c| 135 +++
 libavcodec/liblc3enc.c| 190 ++
 8 files changed, 404 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/liblc3dec.c
 create mode 100644 libavcodec/liblc3enc.c

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7c223ed74c..66847191e1 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -814,6 +814,63 @@ ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 
64k output.m4a
 @end example
 @end itemize
 
+@anchor{liblc3-enc}
+@section liblc3
+
+liblc3 LC3 (Low Complexity Communication Codec) encoder wrapper.
+
+Requires the presence of the liblc3 headers and library during configuration.
+You need to explicitly configure the build with @code{--enable-liblc3}.
+
+This encoder has support for the Bluetooth SIG LC3 codec for the LE Audio
+protocol, and the following features of LC3plus:
+@itemize
+@item
+Frame duration of 2.5 and 5ms.
+@item
+High-Resolution mode, 48 KHz, and 96 kHz sampling rates.
+@end itemize
+
+For more information see the liblc3 project at
+@url{https://github.com/google/liblc3}.
+
+@subsection Options
+
+The following options are mapped on the shared FFmpeg codec options.
+
+@table @option
+@item b @var{bitrate}
+Set the bit rate in bits/s. This will determine the fixed size of the encoded
+frames, for a selected frame duration.
+
+@item ar @var{frequency}
+Set the audio sampling rate (in Hz).
+
+@item channels
+Set the number of audio channels.
+
+@item frame_duration
+Set the audio frame duration in milliseconds. Default value is 10ms.
+Allowed frame durations are 2.5ms, 5ms, 7.5ms and 10ms.
+LC3 (Bluetooth LE Audio), allows 7.5ms and 10ms; and LC3plus 2.5ms, 5ms
+and 10ms.
+
+The 10ms frame duration is available in LC3 and LC3 plus standard.
+In this mode, the produced bitstream can be referenced either as LC3 or 
LC3plus.
+
+@item high_resolution @var{boolean}
+Enable the high-resolution mode if set to 1. The high-resolution mode is
+available with all LC3plus frame durations and for a sampling rate of 48 KHz,
+and 96 KHz.
+
+The encoder automatically turns off this mode at lower sampling rates and
+activates it at 96 KHz.
+
+This mode should be preferred at high bitrates. In this mode, the audio
+bandwidth is always up to the Nyquist frequency, compared to LC3 at 48 KHz,
+which limits the bandwidth to 20 KHz.
+@end table
+
 @anchor{libmp3lame}
 @section libmp3lame
 
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index f269cbd1a9..e7cf4f8239 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -237,6 +237,14 @@ Go to @url{http://sourceforge.net/projects/opencore-amr/} 
and follow the
 instructions for installing the library.
 Then pass @code{--enable-libfdk-aac} to configure to enable it.
 
+@subsection LC3 library
+
+FFmpeg can make use of the Google LC3 library for LC3 decoding & encoding.
+
+Go to @url{https://github.com/google/liblc3/} and follow the instructions for
+installing the library.
+Then pass @code{--enable-liblc3} to configure to enable it.
+
 @section OpenH264
 
 FFmpeg can make use of the OpenH264 library for H.264 decoding and encoding.
@@ -1300,7 +1308,8 @@ following image formats are supported:
 @tab encoding and decoding supported through external library libilbc
 @item IMC (Intel Music Coder)  @tab @tab  X
 @item Interplay ACM@tab @tab  X
-@item MACE (Macintosh Audio Compression/Expansion) 3:1  @tab @tab  X
+@item LC3@tab E  @tab  E
+@tab supported through external library liblc3
 @item MACE (Macintosh Audio Compression/Expansion) 6:1  @tab @tab  X
 @item Marian's A-pac audio @tab @tab  X
 @item MI-SC4 (Micronas SC-4 Audio)  @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ce6d445c1..e70811dbd6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1123,6 +1123,8 @@ OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
 OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
 OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
+OBJS-$(CONFIG_LIBLC3_ENCODER) += liblc3enc.o
+OBJS-$(CONFIG_LIBLC3_DECODER) += liblc3dec.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2386b450a6..f4705651fb 100644

[FFmpeg-devel] [PATCH 1/4] configure: Add option for enabling LC3/LC3plus wrapper

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
---
 configure | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/configure b/configure
index 2a1d22310b..4262b96117 100755
--- a/configure
+++ b/configure
@@ -244,6 +244,7 @@ External library support:
   --enable-libjxl  enable JPEG XL de/encoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
+  --enable-liblc3  enable LC3 de/encoding via liblc3 [no]
   --enable-liblensfun  enable lensfun lens correction [no]
   --enable-libmodplug  enable ModPlug via libmodplug [no]
   --enable-libmp3lame  enable MP3 encoding via libmp3lame [no]
@@ -1926,6 +1927,7 @@ EXTERNAL_LIBRARY_LIST="
 libjxl
 libklvanc
 libkvazaar
+liblc3
 libmodplug
 libmp3lame
 libmysofa
@@ -3499,6 +3501,9 @@ libilbc_encoder_deps="libilbc"
 libjxl_decoder_deps="libjxl libjxl_threads"
 libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
+liblc3_decoder_deps="liblc3"
+liblc3_encoder_deps="liblc3"
+liblc3_encoder_select="audio_frame_queue"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
 libmp3lame_encoder_select="audio_frame_queue mpegaudioheader"
@@ -6869,6 +6874,7 @@ enabled libjxl&& require_pkg_config libjxl 
"libjxl >= 0.7.0" jxl/dec
  require_pkg_config libjxl_threads "libjxl_threads 
>= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 2.0.0" 
kvazaar.h kvz_api_get
+enabled liblc3&& require_pkg_config liblc3 "lc3 >= 1.1.0" lc3.h 
lc3_hr_setup_encoder
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_create
 
 if enabled libmfx && enabled libvpl; then
-- 
2.44.0.478.gd926399ef9-goog

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

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


Re: [FFmpeg-devel] [RFC] Channels

2024-03-27 Thread Michael Niedermayer
On Fri, Mar 22, 2024 at 11:29:31AM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2024-03-22 03:25:25)
[...]
> > alternative is "wont fix" for all such cases,
> 
> IMO it's not, in general, a bug, so EWONTFIX is the appropriate
> response. If the user does not want us to do arbitrarily large
> allocation, they have the appropriate OS-level mechanisms (e.g. ulimit,
> cgroups on Linux) or av_max_alloc().

You misunderstand the issue.

the issue is coverage in the fuzzer

if your 32bit channel number is all allowed then in some decoders
and demuxers you will in 99.9% of the cases never go beyond the
channel processing code
because it will timeout or hit OOM

your suggestion of ulimits, cgroups and other limits dont help
We already have both time and space limits in the fuzzers

Below is simplifying things a bit

if 99.9% of the random 32bit channel numbers die in the channel
processing because of the current limit. Then making the limit
tighter will increase that percentage further.

If you want better coverage you need a channel limit that stops
us before a resource intensive channel processing loop

you can also write down a model of this problem in a more formal way
Ht as in time spend reading the header
Ct time spend processing each channel after the header
Cmax maximum number of channels that will continue execution after the header

you will see that a Cmax = 2^32 will never be able to do what s Cmax=512
can do no matter what external limits you apply

because if you set really high external limits than 99.9% of time will be
spend in the channel processing code because most of the time the channel
number will be very large and nothing will stop it so little time will be
spend for coverage afterwards

and OTOH if you set a medium outside memory/time limut then most channel
cases will hit that limit but run the full length of the time limut
here 99.9% of the cases will timeout and take ALOT of time leaving no
resources for coverage after the channel code

and if you set a realls small outside memory/time limit then maybe you
will quickly stop the channel code but now 99.999% of cases will timeout
in the channel loop and what remains will not have enough time left to
even execute all the code after the loop

So again if you want fuzzer coverage theres need for a channel limit of
some sort.

The alternative is to tell everyone that we will not fix this and then
have bad fuzzer coverage for some cases.

(what iam skiping here is that fuzzers and AI might be able to direct
 the fuzzing towards lower channel numbers. But ill leave that to you
 if you want to trust that)

thx

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

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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 07/10] avformat/wavdec: sanity check channels and bps before using them for block_align

2024-03-27 Thread Michael Niedermayer
On Wed, Mar 27, 2024 at 10:42:31AM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2024-03-26 01:11:48)
> > Fixes: 
> > 62276/clusterfuzz-testcase-minimized-ffmpeg_dem_W64_fuzzer-4704044498944000
> > Fixes: signed integer overflow: 520464 * 8224 cannot be represented in type 
> > 'int'
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/wavdec.c | 5 -
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
> > index 668c8adc36b..89855670d9c 100644
> > --- a/libavformat/wavdec.c
> > +++ b/libavformat/wavdec.c
> > @@ -34,6 +34,7 @@
> >  #include "libavutil/log.h"
> >  #include "libavutil/mathematics.h"
> >  #include "libavutil/opt.h"
> > +#include "libavcodec/internal.h"
> >  #include "avformat.h"
> >  #include "avio.h"
> >  #include "avio_internal.h"
> > @@ -908,7 +909,9 @@ static int w64_read_header(AVFormatContext *s)
> >  if (ret < 0)
> >  return ret;
> >  avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
> > -if (st->codecpar->block_align) {
> > +if (st->codecpar->block_align &&
> > +st->codecpar->ch_layout.nb_channels < FF_SANE_NB_CHANNELS 
> > &&
> 
> I objected to this approach.

Maybe that was your intend but what you actually wrote and what i understood
was that you objected to adding a field to AVFormatContext
For reference:

> is anyone against adding a max_channels field to AVFormatContext  or 
something
> like that ?

I am.

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] fftools/ffplay: use correct buffersink channel layout parameters

2024-03-27 Thread Marton Balint




On Wed, 27 Mar 2024, Michael Niedermayer wrote:


On Tue, Mar 19, 2024 at 07:54:20PM +, Marton Balint wrote:

ffmpeg | branch: master | Marton Balint  | Mon Mar 18 21:07:20 
2024 +0100| [7251f909721a570726775acf61b2b9c28a950c76] | committer: Marton Balint

fftools/ffplay: use correct buffersink channel layout parameters

Regression since 0995e1f1b31f6e937a1b527407ed3e850f138098.

Signed-off-by: Marton Balint 


http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7251f909721a570726775acf61b2b9c28a950c76

---

 fftools/ffplay.c | 2 ++
 1 file changed, 2 insertions(+)


This breaks_
./ffplay fate-suite/wav/200828-005.wav

[ffplay_abuffersink @ 0x7feef8008700] Channel layout change is not supported

should i open a ticket ?


No, there is already a patch for this under review:

https://lists.ffmpeg.org//pipermail/ffmpeg-devel/2024-March/324092.html

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] [FFmpeg-cvslog] fftools/ffplay: use correct buffersink channel layout parameters

2024-03-27 Thread Michael Niedermayer
On Tue, Mar 19, 2024 at 07:54:20PM +, Marton Balint wrote:
> ffmpeg | branch: master | Marton Balint  | Mon Mar 18 
> 21:07:20 2024 +0100| [7251f909721a570726775acf61b2b9c28a950c76] | committer: 
> Marton Balint
> 
> fftools/ffplay: use correct buffersink channel layout parameters
> 
> Regression since 0995e1f1b31f6e937a1b527407ed3e850f138098.
> 
> Signed-off-by: Marton Balint 
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7251f909721a570726775acf61b2b9c28a950c76
> ---
> 
>  fftools/ffplay.c | 2 ++
>  1 file changed, 2 insertions(+)

This breaks_
./ffplay fate-suite/wav/200828-005.wav

[ffplay_abuffersink @ 0x7feef8008700] Channel layout change is not supported

should i open a ticket ?

thx

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

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


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] [FFmpeg-cvslog] avcodec/aacdec: fix parsing of dual mono files

2024-03-27 Thread Michael Niedermayer
On Fri, Jul 08, 2022 at 01:06:34PM +, James Almer wrote:
> ffmpeg | branch: master | James Almer  | Tue Jul  5 
> 12:49:29 2022 -0300| [f9785a78da117be0c66f6d5d58ce7277c7029ae7] | committer: 
> James Almer
> 
> avcodec/aacdec: fix parsing of dual mono files
> 
> Dual mono files report a channel count of 2 with each individual channel in 
> its
> own SCE, instead of both in a single CPE as is the case with standard stereo.
> This commit handles this non default channel configuration scenario.
> 
> Fixes ticket #1614
> 
> Signed-off-by: James Almer 
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f9785a78da117be0c66f6d5d58ce7277c7029ae7
> ---
> 
>  libavcodec/aacdec_template.c | 15 +--
>  1 file changed, 9 insertions(+), 6 deletions(-)

This breaks:

./ffplay ~/tickets/513/Nero%20032%20kbps%20CBR-HE.mp4

should i reopen the ticket ?

thx

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

Homeopathy is like voting while filling the ballot out with transparent ink.
Sometimes the outcome one wanted occurs. Rarely its worse than filling out
a ballot properly.


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] libavformat/flac_picture: Don't return AVERROR_INVALIDDATA for errors with flac picture mimetype

2024-03-27 Thread Dale Curtis
Bump on this patch -- it still applies cleanly. We're still seeing files in
the wild like this.

- dale

On Mon, Apr 10, 2023 at 10:54 AM Dale Curtis 
wrote:

> Will left Google, but I've updated the patch to only skip errors when the
> type is unrecognized.
>
> On Wed, Sep 28, 2022 at 7:17 AM Anton Khirnov  wrote:
>
>> IMO failing to recognize the MIME type is a lavf error rather than a
>> file error and so should not fail, much less with AVERROR_INVALIDDATA
>> (should be ENOSYS if anything).
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@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/6 v3] avutil/frame: add helper for adding side data w/ AVBufferRef to array

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
Same as the wrongly named 02/10 i sent earlier.

 libavutil/frame.c | 53 +++
 libavutil/frame.h | 34 ++
 2 files changed, 87 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 2e40018b83..08b6475cc2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -834,6 +834,59 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 return ret;
 }
 
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **pbuf, unsigned int flags)
+{
+const AVSideDataDescriptor *desc = av_frame_side_data_desc(type);
+AVFrameSideData *sd_dst  = NULL;
+AVBufferRef *buf;
+
+if (!sd || !pbuf || *pbuf || !nb_sd || (*nb_sd && !*sd))
+return NULL;
+
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+
+if (entry->type != type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return NULL;
+
+buf = *pbuf;
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) {
+int ret = av_buffer_replace(>buf, buf);
+if (ret < 0)
+return NULL;
+} else
+*pbuf = NULL;
+
+av_dict_free(>metadata);
+entry->data = buf->data;
+entry->size = buf->size;
+return 0;
+}
+}
+
+buf = (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) ?
+   av_buffer_ref(*pbuf) : *pbuf;
+
+sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf);
+if (!sd_dst) {
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)
+av_buffer_unref();
+return NULL;
+}
+
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
+*pbuf = NULL;
+
+return sd_dst;
+}
+
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 2ea129888e..3e5d170a5b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1048,6 +1048,10 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  * Don't add a new entry if another of the same type exists.
  */
 #define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)
+/**
+ * Create a new reference instead of taking ownership of the passed in one.
+ */
+#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2)
 
 /**
  * Add new side data entry to an array.
@@ -1066,11 +1070,40 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  *   is attempted.
  * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
  *   entry of the same type already exists, it will be replaced instead.
+ * @note AV_FRAME_SIDE_DATA_FLAG_NEW_REF has no effect in this function.
  */
 AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags);
 
+/**
+ * Add a new side data entry to an array from an existing AVBufferRef.
+ *
+ * @param sdpointer to array of side data to which to add another entry,
+ *  or to NULL in order to start a new array.
+ * @param nb_sd pointer to an integer containing the number of entries in
+ *  the array.
+ * @param type  type of the added side data
+ * @param buf   Pointer to AVBufferRef to add to the array. On success,
+ *  the function takes ownership of the AVBufferRef and *buf is
+ *  set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set
+ *  in which case the ownership will remain with the caller.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
+ *
+ * @return newly added side data on success, NULL on error.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of
+ *   matching AVFrameSideDataType will be removed before the addition
+ *   is attempted.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
+ *   entry of the same type already exists, it will be replaced instead.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_NEW_REF being set, the ownership
+ *   of *buf will remain with the caller.
+ *
+ */
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **buf, unsigned int flags);
+
 /**
  * Add a new side data entry to an array based on existing side data, taking
  * a 

[FFmpeg-devel] [PATCH 02/10] avutil/frame: add helper for adding side data w/ AVBufferRef to array

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/frame.c | 53 +++
 libavutil/frame.h | 34 ++
 2 files changed, 87 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 2e40018b83..08b6475cc2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -834,6 +834,59 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 return ret;
 }
 
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **pbuf, unsigned int flags)
+{
+const AVSideDataDescriptor *desc = av_frame_side_data_desc(type);
+AVFrameSideData *sd_dst  = NULL;
+AVBufferRef *buf;
+
+if (!sd || !pbuf || *pbuf || !nb_sd || (*nb_sd && !*sd))
+return NULL;
+
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+
+if (entry->type != type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return NULL;
+
+buf = *pbuf;
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) {
+int ret = av_buffer_replace(>buf, buf);
+if (ret < 0)
+return NULL;
+} else
+*pbuf = NULL;
+
+av_dict_free(>metadata);
+entry->data = buf->data;
+entry->size = buf->size;
+return 0;
+}
+}
+
+buf = (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) ?
+   av_buffer_ref(*pbuf) : *pbuf;
+
+sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf);
+if (!sd_dst) {
+if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)
+av_buffer_unref();
+return NULL;
+}
+
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF))
+*pbuf = NULL;
+
+return sd_dst;
+}
+
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 2ea129888e..3e5d170a5b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1048,6 +1048,10 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  * Don't add a new entry if another of the same type exists.
  */
 #define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)
+/**
+ * Create a new reference instead of taking ownership of the passed in one.
+ */
+#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2)
 
 /**
  * Add new side data entry to an array.
@@ -1066,11 +1070,40 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  *   is attempted.
  * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
  *   entry of the same type already exists, it will be replaced instead.
+ * @note AV_FRAME_SIDE_DATA_FLAG_NEW_REF has no effect in this function.
  */
 AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags);
 
+/**
+ * Add a new side data entry to an array from an existing AVBufferRef.
+ *
+ * @param sdpointer to array of side data to which to add another entry,
+ *  or to NULL in order to start a new array.
+ * @param nb_sd pointer to an integer containing the number of entries in
+ *  the array.
+ * @param type  type of the added side data
+ * @param buf   Pointer to AVBufferRef to add to the array. On success,
+ *  the function takes ownership of the AVBufferRef and *buf is
+ *  set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set
+ *  in which case the ownership will remain with the caller.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
+ *
+ * @return newly added side data on success, NULL on error.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of
+ *   matching AVFrameSideDataType will be removed before the addition
+ *   is attempted.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
+ *   entry of the same type already exists, it will be replaced instead.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_NEW_REF being set, the ownership
+ *   of *buf will remain with the caller.
+ *
+ */
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **buf, unsigned int flags);
+
 /**
  * Add a new side data entry to an array based on existing side data, taking
  * a reference towards the contained AVBufferRef.
@@ 

[FFmpeg-devel] [PATCH 1/6 v3] avutil/frame: add a flag to allow overwritting existing entries

2024-03-27 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/frame.c | 59 +++
 libavutil/frame.h | 27 +++---
 2 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index ef1613c344..2e40018b83 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -799,12 +799,34 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags)
 {
-AVBufferRef *buf = av_buffer_alloc(size);
+const AVSideDataDescriptor *desc = av_frame_side_data_desc(type);
+AVBufferRef *buf;
 AVFrameSideData *ret = NULL;
 
 if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
 remove_side_data(sd, nb_sd, type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+if (entry->type != type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return NULL;
+
+buf = av_buffer_alloc(size);
+if (!buf)
+return NULL;
+
+av_buffer_unref(>buf);
+av_dict_free(>metadata);
+entry->buf  = buf;
+entry->data = buf->data;
+entry->size = buf->size;
+return 0;
+}
+}
 
+buf = av_buffer_alloc(size);
 ret = add_side_data_from_buf(sd, nb_sd, type, buf);
 if (!ret)
 av_buffer_unref();
@@ -815,6 +837,7 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
+const AVSideDataDescriptor *desc;
 AVBufferRef *buf= NULL;
 AVFrameSideData *sd_dst = NULL;
 int  ret= AVERROR_BUG;
@@ -822,13 +845,41 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
 if (!sd || !src || !nb_sd || (*nb_sd && !*sd))
 return AVERROR(EINVAL);
 
+desc = av_frame_side_data_desc(src->type);
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, src->type);
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) {
+for (int i = 0; i < *nb_sd; i++) {
+AVFrameSideData *entry = ((*sd)[i]);
+AVDictionary *dict = NULL;
+
+if (entry->type != src->type)
+continue;
+if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE))
+return AVERROR(EEXIST);
+
+ret = av_dict_copy(, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = av_buffer_replace(>buf, src->buf);
+if (ret < 0) {
+av_dict_free();
+return ret;
+}
+
+av_dict_free(>metadata);
+entry->metadata = dict;
+entry->data = src->data;
+entry->size = src->size;
+return 0;
+}
+}
+
 buf = av_buffer_ref(src->buf);
 if (!buf)
 return AVERROR(ENOMEM);
 
-if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
-remove_side_data(sd, nb_sd, src->type);
-
 sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf);
 if (!sd_dst) {
 av_buffer_unref();
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 3b6d746a16..2ea129888e 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1040,7 +1040,14 @@ const AVSideDataDescriptor *av_frame_side_data_desc(enum 
AVFrameSideDataType typ
  */
 void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);
 
+/**
+ * Remove existing entries before adding new ones.
+ */
 #define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0)
+/**
+ * Don't add a new entry if another of the same type exists.
+ */
+#define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1)
 
 /**
  * Add new side data entry to an array.
@@ -1053,10 +1060,12 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int 
*nb_sd);
  * @param size  size of the side data
  * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
  *
- * @return newly added side data on success, NULL on error. In case of
- * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
- * AVFrameSideDataType will be removed before the addition is
- * attempted.
+ * @return newly added side data on success, NULL on error.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of
+ *   matching AVFrameSideDataType will be removed before the addition
+ *   is attempted.
+ * @note In case of AV_FRAME_SIDE_DATA_FLAG_REPLACE being set, if an
+ *   entry of the same type already exists, it will be replaced instead.
  */
 AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int 

Re: [FFmpeg-devel] [PATCH] avformat/rtmpproto: Fix segfault

2024-03-27 Thread Armin Hasitzka via ffmpeg-devel
Ooooh interesting, I see (makes a lot of sense)! I can confirm, btw; your
updated fix (from 324509) works for me (no segfault + clean shutdown)! ...
I will comment on the other thread as soon as the email comes through!

Thanks a lot!
Armin

On Wed, 27 Mar 2024 at 18:21, Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Armin Hasitzka via ffmpeg-devel:
> > Hi,
> >
> > we found this when testing with rejected RTMP streams.
> >
> > Best
> > Armin
>
> Thanks for the report and the patch; yet actually freeing them manually
> is not only harmful, but also unnecessary, as these strings can be set
> via AVOptions; therefore they will be freed generically (which is also
> the reason why rtmp_close() does not have code to free them). I sent a
> patch for this here:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2024-March/324509.html Would
> be nice if you could test it.
>
> - 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 mailing list
ffmpeg-devel@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/rtmpproto: Fix segfault

2024-03-27 Thread Andreas Rheinhardt
Armin Hasitzka via ffmpeg-devel:
> Hi,
> 
> we found this when testing with rejected RTMP streams.
> 
> Best
> Armin

Thanks for the report and the patch; yet actually freeing them manually
is not only harmful, but also unnecessary, as these strings can be set
via AVOptions; therefore they will be freed generically (which is also
the reason why rtmp_close() does not have code to free them). I sent a
patch for this here:
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-March/324509.html Would
be nice if you could test it.

- 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/rtmpproto: Don't free AVOpt-strings manually, fix crash

2024-03-27 Thread Andreas Rheinhardt
Besides being redundant, freeing manually is actually harmful here,
as rtmp_close() may call gen_fcunpublish_stream() which dereferences
rt->playpath.

Reported-by: Armin Hasitzka 
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/rtmpproto.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4b01b67d28..b1d73b3d75 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -2917,9 +2917,6 @@ reconnect:
 return 0;
 
 fail:
-av_freep(>playpath);
-av_freep(>tcurl);
-av_freep(>flashver);
 av_dict_free(opts);
 rtmp_close(s);
 return ret;
-- 
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] [FFmpeg-cvslog] fftools/ffmpeg: convert to a threaded architecture

2024-03-27 Thread Michael Niedermayer
On Tue, Dec 12, 2023 at 07:41:18AM +, Anton Khirnov wrote:
> ffmpeg | branch: master | Anton Khirnov  | Tue Jul 18 
> 16:37:52 2023 +0200| [d119ae2fd82a494d9430ff4d4fc262961a68c598] | committer: 
> Anton Khirnov
> 
> fftools/ffmpeg: convert to a threaded architecture
> 
> Change the main loop and every component (demuxers, decoders, filters,
> encoders, muxers) to use the previously added transcode scheduler. Every
> instance of every such component was already running in a separate
> thread, but now they can actually run in parallel.
> 
> Changes the results of ffmpeg-fix_sub_duration_heartbeat - tested by
> JEEB to be more correct and deterministic.
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d119ae2fd82a494d9430ff4d4fc262961a68c598
> ---
> 
>  Changelog|   2 +
>  fftools/ffmpeg.c | 374 +---
>  fftools/ffmpeg.h |  97 +--
>  fftools/ffmpeg_dec.c | 313 +++---
>  fftools/ffmpeg_demux.c   | 268 -
>  fftools/ffmpeg_enc.c | 377 ++--
>  fftools/ffmpeg_filter.c  | 714 
> ++-
>  fftools/ffmpeg_mux.c | 324 ++
>  fftools/ffmpeg_mux.h |  24 +-
>  fftools/ffmpeg_mux_init.c|  88 +--
>  fftools/ffmpeg_opt.c |   6 +-
>  tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat |  34 +-
>  12 files changed, 600 insertions(+), 2021 deletions(-)

breaks: (races, violates bitexact)

for i in `seq 50` ; do ./ffmpeg -v 0 -i ~/tickets/4003/mp3_demuxer_EOI.mp3 
-bitexact -vframes 1 -y /tmp/file-4003.avi ; md5sum /tmp/file-4003.avi

before:
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi


aftre:
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
1508e16c1877abe172173cd1e11f1155  /tmp/file-4003.avi
1508e16c1877abe172173cd1e11f1155  /tmp/file-4003.avi
933c2cc12cda1deac7245ec768f5b35f  /tmp/file-4003.avi
933c2cc12cda1deac7245ec768f5b35f  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
933c2cc12cda1deac7245ec768f5b35f  /tmp/file-4003.avi
db7ad90e0e02af90e98e09c9b0158124  /tmp/file-4003.avi
1508e16c1877abe172173cd1e11f1155  /tmp/file-4003.avi
1508e16c1877abe172173cd1e11f1155 

Re: [FFmpeg-devel] [PATCH 2/6] avcodec/libvpxenc: Remove obsolete av_unused

2024-03-27 Thread James Zern via ffmpeg-devel
On Tue, Mar 26, 2024 at 6:38 PM Andreas Rheinhardt
 wrote:
>
> Forgotten in 753074721bd414874d18c372c491bdc6323fa3bf.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/libvpxenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

lgtm.
___
ffmpeg-devel mailing list
ffmpeg-devel@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/6] avcodec/libvpxenc: Only search for side data when intending to use it

2024-03-27 Thread James Zern via ffmpeg-devel
On Tue, Mar 26, 2024 at 6:36 PM Andreas Rheinhardt
 wrote:
>
> Also rewrite the code so that a variable that is only used
> depending upon CONFIG_LIBVPX_VP9_ENCODER is not declared
> outside of the #if block.
> (The variable was declared with av_uninit, but it should have been
> av_unused, as the former does not work for all compilers.)
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/libvpxenc.c | 19 ++-
>  1 file changed, 10 insertions(+), 9 deletions(-)
>

lgtm.

> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 4b89e47e83..ee903a4e5c 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -357,19 +357,20 @@ static int frame_data_submit(AVCodecContext *avctx, 
> AVFifo *fifo,
>  const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
>
>  FrameData fd = { .pts = frame->pts };
> -
> -AVFrameSideData *av_uninit(sd);
>  int ret;
>
>  #if CONFIG_LIBVPX_VP9_ENCODER
> -// Keep HDR10+ if it has bit depth higher than 8 and
> -// it has PQ trc (SMPTE2084).
> -sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> -if (avctx->codec_id == AV_CODEC_ID_VP9 && sd &&
> +if (avctx->codec_id == AV_CODEC_ID_VP9 &&
> +// Keep HDR10+ if it has bit depth higher than 8 and
> +// it has PQ trc (SMPTE2084).
>  enccfg->g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) {
> -fd.hdr10_plus = av_buffer_ref(sd->buf);
> -if (!fd.hdr10_plus)
> -return AVERROR(ENOMEM);
> +const AVFrameSideData *sd = av_frame_get_side_data(frame, 
> AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> +
> +if (sd) {
> +fd.hdr10_plus = av_buffer_ref(sd->buf);
> +if (!fd.hdr10_plus)
> +return AVERROR(ENOMEM);
> +}
>  }
>  #endif
>
> --
> 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 mailing list
ffmpeg-devel@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/vf_signature: Dont crash on no frames

2024-03-27 Thread Michael Niedermayer
On Tue, Feb 13, 2024 at 03:07:59AM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer 
> ---
>  libavfilter/vf_signature.c | 3 +++
>  1 file changed, 3 insertions(+)

will apply

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

The real ebay dictionary, page 1
"Used only once"- "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH] avformat/rtmpproto: Fix segfault

2024-03-27 Thread Armin Hasitzka via ffmpeg-devel
Hi,

we found this when testing with rejected RTMP streams.

Best
Armin


0001-avformat-rtmpproto-Fix-segfault.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/5] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
>
> Does this function do anything else than frame_us * srate_hz / 1000?

 Also check the already validated parameters.
Yes, I can safely replace it with "av_scale()".

It seems that lc3 has a fixed blocksize. If so, you should use
> ff_get_encode_buffer().

Technically the codec allows you to freely change the size on frame basis.
But it's not used in this way, ack.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/5] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec

2024-03-27 Thread Antoine Soulier via ffmpeg-devel
do you need to reset/free the encoder in case of failure? If this is
> the case you need to unset/free here or in the close function


Nothing to do with the encoder in case of failure. It just initializes the
given buffer, and returns it.
BTW, the only failure condition is bad parameters, already checked by
`lc3_hr_encoder_size()`.
Perhaps I can just remove the check of the returned value.

can this fail?

Can just fail on bad parameters, the size of frames `frame_bytes` has been
checked by `lc3_hr_frame_block_bytes()`.
Looks safe 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".


[FFmpeg-devel] [PATCH] avutil/tests/.gitignore: Add side_data_array

2024-03-27 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavutil/tests/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 87895912f5..951cafb2d7 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -44,6 +44,7 @@
 /ripemd
 /sha
 /sha512
+/side_data_array
 /softfloat
 /tea
 /tree
-- 
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 04/10] fftools/ffmpeg_sched: Explicitly return 0 on sch_enc_send() success

2024-03-27 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Do not return the return value of the last enc_send_to_dst()
> call, as this would treat the last call differently from the
> earlier calls; furthermore, sch_enc_send() explicitly documents
> to always return 0 on success.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  fftools/ffmpeg_sched.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
> index ec88017e21..30b2355eb6 100644
> --- a/fftools/ffmpeg_sched.c
> +++ b/fftools/ffmpeg_sched.c
> @@ -2344,15 +2344,13 @@ int sch_enc_send(Scheduler *sch, unsigned enc_idx, 
> AVPacket *pkt)
>  ret = enc_send_to_dst(sch, enc->dst[i], finished, to_send);
>  if (ret < 0) {
>  av_packet_unref(to_send);
> -if (ret == AVERROR_EOF) {
> -ret = 0;
> +if (ret == AVERROR_EOF)
>  continue;
> -}
>  return ret;
>  }
>  }
>  
> -return ret;
> +return 0;
>  }
>  
>  static int enc_done(Scheduler *sch, unsigned enc_idx)

Will apply patches 4-12 of this patchset 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 1/4] lavc/vp9dsp: R-V V ipred dc

2024-03-27 Thread Rémi Denis-Courmont
Le perjantaina 22. maaliskuuta 2024, 8.02.08 EET flow gg a écrit :
> Using macros to shorten function definitions, updated in this response

Did you try to share the common code after getdc and see how slower it is? If 
an extra static branch has negligible overhead, it would reduce binary size 
quite a bit here, AFAICT.

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



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

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


[FFmpeg-devel] [PATCH v2] avformat: enable UDP IPv6 multicast interface selection using zone index

2024-03-27 Thread RS
avformat: enable UDP IPv6 multicast interface selection using zone index

Enabled IPv6 interface selection using zone index. Properly resolved
interface index in places where default 0 interface index is used
(marked with TODO: within udp.c). Adjusted binding for multicast sockets
that are used for reading from the network.

For mcast addresses, bind to mcast address is attempted as before.
In case that this fails, which will happen on Windows, socket is bound
to INADDR_ANY/IN6ADDR_ANY_INIT depending on address family. Actual
interface selection is performed using udp_set_multicast_interface to
point to the desired interface for sending.

Closes: #368

Signed-off-by: Lazar Ignjatovic 
---
V1 -> V2 reverted iface resolution for IPv4 MCAST_JOIN_SOURCE_GROUP
NOTE: Due to comments, this patch is proposed as one of two alternatives
The other alternative uses `localaddr` for defining interfaces.


 configure |  3 ++
 doc/protocols.texi|  2 +-
 libavformat/network.h |  6 +++
 libavformat/udp.c | 85 +++
 4 files changed, 88 insertions(+), 8 deletions(-)

diff --git a/configure b/configure
index 2a1d22310b..35d6a0b78c 100755
--- a/configure
+++ b/configure
@@ -2307,6 +2307,7 @@ HEADERS_LIST="
 valgrind_valgrind_h
 windows_h
 winsock2_h
+iphlpapi_h
 "

 INTRINSICS_LIST="
@@ -6475,6 +6476,8 @@ if ! disabled network; then
 check_struct winsock2.h "struct sockaddr" sa_len
 check_type ws2tcpip.h "struct sockaddr_in6"
 check_type ws2tcpip.h "struct sockaddr_storage"
+check_headers iphlpapi.h -liphlpapi && 
network_extralibs="$network_extralibs -liphlpapi" || disable iphlpapi_h
+check_func_headers iphlpapi.h GetBestInterfaceEx $network_extralibs
 else
 disable network
 fi
diff --git a/doc/protocols.texi b/doc/protocols.texi
index f54600b846..a8892845d3 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -2027,7 +2027,7 @@ packet bursts.
 Override the local UDP port to bind with.

 @item localaddr=@var{addr}
-Local IP address of a network interface used for sending packets or joining
+Local IPv4 address of a network interface used for sending packets or joining
 multicast groups.

 @item pkt_size=@var{size}
diff --git a/libavformat/network.h b/libavformat/network.h
index ca214087fc..2461b651d4 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -38,6 +38,10 @@
 #include 
 #include 

+#if HAVE_IPHLPAPI_H
+#include 
+#endif
+
 #ifndef EPROTONOSUPPORT
 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
 #endif
@@ -64,6 +68,8 @@ int ff_neterrno(void);
 #include 
 #include 
 #include 
+#include 
+#include 

 #define ff_neterrno() AVERROR(errno)
 #endif /* HAVE_WINSOCK2_H */
diff --git a/libavformat/udp.c b/libavformat/udp.c
index d9514f5026..00c73f9ec9 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -35,6 +35,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
 #include "libavutil/time.h"
+#include "libavutil/avstring.h"
 #include "internal.h"
 #include "network.h"
 #include "os_support.h"
@@ -220,8 +221,7 @@ static int udp_join_multicast_group(int sockfd, struct 
sockaddr *addr,
 struct ipv6_mreq mreq6;

 memcpy(_multiaddr, &(((struct sockaddr_in6 
*)addr)->sin6_addr), sizeof(struct in6_addr));
-//TODO: Interface index should be looked up from local_addr
-mreq6.ipv6mr_interface = 0;
+mreq6.ipv6mr_interface = ((struct sockaddr_in6 *)addr)->sin6_scope_id;
 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, , 
sizeof(mreq6)) < 0) {
 ff_log_net_error(logctx, AV_LOG_ERROR, 
"setsockopt(IPV6_ADD_MEMBERSHIP)");
 return ff_neterrno();
@@ -231,6 +231,39 @@ static int udp_join_multicast_group(int sockfd, struct 
sockaddr *addr,
 return 0;
 }

+static int udp_set_multicast_interface(int sockfd, struct sockaddr *addr,
+struct sockaddr *local_addr, void *logctx)
+{
+#ifdef IP_MULTICAST_IF
+if (addr->sa_family == AF_INET) {
+struct ip_mreq mreq;
+
+mreq.imr_multiaddr.s_addr = ((struct sockaddr_in 
*)addr)->sin_addr.s_addr;
+if (local_addr)
+mreq.imr_interface = ((struct sockaddr_in *)local_addr)->sin_addr;
+else
+mreq.imr_interface.s_addr = INADDR_ANY;
+
+if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_IF, (const void 
*), sizeof(mreq)) < 0) {
+ff_log_net_error(logctx, AV_LOG_ERROR, 
"setsockopt(IP_MULTICAST_IF)");
+return ff_neterrno();
+}
+}
+#endif
+#if defined(IPV6_MULTICAST_IF) && defined(IPPROTO_IPV6)
+if (addr->sa_family == AF_INET6) {
+unsigned int iface;
+iface = ((struct sockaddr_in6 *)addr)->sin6_scope_id;
+
+if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF, , 
sizeof(unsigned int)) < 0) {
+ff_log_net_error(logctx, AV_LOG_ERROR, 
"setsockopt(IPV6_MULTICAST_IF)");
+return ff_neterrno();
+ 

Re: [FFmpeg-devel] [PATCH 2/3] lavc/vp8dsp: R-V V put_epel v

2024-03-27 Thread Rémi Denis-Courmont
Le perjantaina 22. maaliskuuta 2024, 8.01.21 EET flow gg a écrit :
> 

IMO, you could just as well share the code and avoid most if's. Not like one 
additional `li a3, 1` per function call is going to matter in the grand scheme 
of things. It might even help by reducing I-cache pressure.

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



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

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


Re: [FFmpeg-devel] [PATCH v3] avformat: enable UDP IPv6 multicast interface selection using localaddr

2024-03-27 Thread Rémi Denis-Courmont
Le keskiviikkona 27. maaliskuuta 2024, 10.53.25 EET Ignjatović, Lazar (RS) a 
écrit :
> This message has been marked as Public on 03/27/2024 08:53Z.
> 
> On Tuesday, March 26, 2024 7:26 PM Rémi Denis-Courmont wrote:
> > Both patches -1 for same reasons as before and that's unnecessary,
> > functionally incorrect and potentially racy, enumeration of local
> > interfaces.
> Enumeration of interfaces is done only for IPv4
> MCAST_JOIN_SOURCE_GROUP/MCAST_BLOCK_SOURCE within zone index patch. Adding
> a separate parameter just for this seems pointless to me. Would removal of
> this, and reverting back to how it was ( = 0; // default interface in every
> case), address your concerns?

I have mixed feelings about changing how IPv4 works. Sure, it provides better 
consistency, and it is easier to remember an interface name than an IP address 
(especially if it is dynamically assigned). But it will also break backward 
compatibility. Not that I care about this specific hypothetical breakage, but 
somebody else very well might.

Either way, if you change how IPv4 works, you need to do it as a separate 
patch to adding IPv6 support. Avoiding reviewer confusion is just one of 
several reasons.

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



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

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


[FFmpeg-devel] [PATCH 1/2] lavf/vf_setpts: unset output framerate

2024-03-27 Thread Anton Khirnov
This filter produces VFR output in general.

Avoids dropping frames in the setpts test.
---
 libavfilter/setpts.c | 17 ++-
 tests/ref/fate/filter-setpts | 89 +---
 2 files changed, 67 insertions(+), 39 deletions(-)

diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 88a8d6af86..4f02a9a617 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -150,6 +150,13 @@ static int config_input(AVFilterLink *inlink)
 return 0;
 }
 
+static int config_output_video(AVFilterLink *outlink)
+{
+outlink->frame_rate = (AVRational){ 1, 0 };
+
+return 0;
+}
+
 #define BUF_SIZE 64
 
 static inline char *double2int64str(char *buf, double v)
@@ -322,6 +329,14 @@ static const AVFilterPad avfilter_vf_setpts_inputs[] = {
 },
 };
 
+static const AVFilterPad outputs_video[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_VIDEO,
+.config_props = config_output_video,
+},
+};
+
 const AVFilter ff_vf_setpts = {
 .name= "setpts",
 .description = NULL_IF_CONFIG_SMALL("Set PTS for the output video 
frame."),
@@ -335,7 +350,7 @@ const AVFilter ff_vf_setpts = {
 .priv_class = _class,
 
 FILTER_INPUTS(avfilter_vf_setpts_inputs),
-FILTER_OUTPUTS(ff_video_default_filterpad),
+FILTER_OUTPUTS(outputs_video),
 };
 #endif /* CONFIG_SETPTS_FILTER */
 
diff --git a/tests/ref/fate/filter-setpts b/tests/ref/fate/filter-setpts
index efdcf6a16e..8aa7a1e6a0 100644
--- a/tests/ref/fate/filter-setpts
+++ b/tests/ref/fate/filter-setpts
@@ -1,42 +1,55 @@
-#tb 0: 1/25
+#tb 0: 1/1000
 #media_type 0: video
 #codec_id 0: rawvideo
 #dimensions 0: 352x288
 #sar 0: 0/1
-0,  0,  0,1,   152064, 0x05b789ef
-0,  1,  1,1,   152064, 0x4bb46551
-0,  2,  2,1,   152064, 0x9dddf64a
-0,  3,  3,1,   152064, 0x2a8380b0
-0,  4,  4,1,   152064, 0x4de3b652
-0,  5,  5,1,   152064, 0xedb5a8e6
-0,  6,  6,1,   152064, 0x5ab58bac
-0,  7,  7,1,   152064, 0x1f1b8026
-0,  8,  8,1,   152064, 0x91373915
-0,  9,  9,1,   152064, 0x30f5fcd5
-0, 10, 10,1,   152064, 0xc711ad61
-0, 11, 11,1,   152064, 0x52a48ddd
-0, 12, 12,1,   152064, 0xa91c0f05
-0, 13, 13,1,   152064, 0x8e364e18
-0, 14, 14,1,   152064, 0xf25f6acc
-0, 15, 15,1,   152064, 0xf34ddbff
-0, 16, 16,1,   152064, 0x9dc72412
-0, 17, 17,1,   152064, 0x445d1d59
-0, 18, 18,1,   152064, 0x2f2768ef
-0, 19, 19,1,   152064, 0x95579936
-0, 20, 20,1,   152064, 0x43d796b5
-0, 21, 21,1,   152064, 0x76d2a455
-0, 22, 22,1,   152064, 0x6dc3650e
-0, 23, 23,1,   152064, 0x0f9d6aca
-0, 24, 24,1,   152064, 0xd766fc8d
-0, 25, 25,1,   152064, 0xe22f7a30
-0, 26, 26,1,   152064, 0xfa8d94fb
-0, 27, 27,1,   152064, 0x4c9737ab
-0, 28, 28,1,   152064, 0xa50d01f8
-0, 29, 29,1,   152064, 0x88734edd
-0, 30, 30,1,   152064, 0xd2735925
-0, 31, 31,1,   152064, 0x20cebfa9
-0, 32, 32,1,   152064, 0x575c20ec
-0, 33, 33,1,   152064, 0x61b47e73
-0, 34, 34,1,   152064, 0x09ef53ff
-0, 35, 35,1,   152064, 0x6e88c5c2
-0, 36, 36,1,   152064, 0x4bbad8ea
+0,  0,  0,   40,   152064, 0x05b789ef
+0, 28, 28,   40,   152064, 0x4bb46551
+0, 57, 57,   40,   152064, 0x9dddf64a
+0, 86, 86,   40,   152064, 0x2a8380b0
+0,115,115,   40,   152064, 0x4de3b652
+0,144,144,   40,   152064, 0xedb5a8e6
+0,172,172,   40,   152064, 0xe20f7c23
+0,201,201,   40,   152064, 0x5ab58bac
+0,229,229,   40,   152064, 0x1f1b8026
+0,258,258,   40,   152064, 0x91373915
+0,286,286,   40,   152064, 0x02344760
+0,314,314,   40,   152064, 0x30f5fcd5
+0,343,343,   40,   152064, 0xc711ad61
+0,371,371,   40,   152064, 0x24eca223
+0,399,399,   40,   152064, 0x52a48ddd
+0,427,427,   40,   152064, 0xa91c0f05
+0,456,456,   40,   152064, 0x8e364e18
+0,484,484,   40,   152064, 0xb15d38c8
+0,512,512,   40,   152064, 

[FFmpeg-devel] [PATCH 2/2] lavfi/setpts: unset frame durations

2024-03-27 Thread Anton Khirnov
Actual frame durations are, in general, not computable without buffering
a frame.
---
 libavfilter/setpts.c |   1 +
 tests/ref/fate/filter-setpts | 100 +--
 2 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 4f02a9a617..60cf2b642e 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -205,6 +205,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 
 d = eval_pts(setpts, inlink, frame, frame->pts);
 frame->pts = D2TS(d);
+frame->duration = 0;
 
 av_log(inlink->dst, AV_LOG_TRACE,
 "N:%"PRId64" PTS:%s T:%f",
diff --git a/tests/ref/fate/filter-setpts b/tests/ref/fate/filter-setpts
index 8aa7a1e6a0..08e0203831 100644
--- a/tests/ref/fate/filter-setpts
+++ b/tests/ref/fate/filter-setpts
@@ -3,53 +3,53 @@
 #codec_id 0: rawvideo
 #dimensions 0: 352x288
 #sar 0: 0/1
-0,  0,  0,   40,   152064, 0x05b789ef
-0, 28, 28,   40,   152064, 0x4bb46551
-0, 57, 57,   40,   152064, 0x9dddf64a
-0, 86, 86,   40,   152064, 0x2a8380b0
-0,115,115,   40,   152064, 0x4de3b652
-0,144,144,   40,   152064, 0xedb5a8e6
-0,172,172,   40,   152064, 0xe20f7c23
-0,201,201,   40,   152064, 0x5ab58bac
-0,229,229,   40,   152064, 0x1f1b8026
-0,258,258,   40,   152064, 0x91373915
-0,286,286,   40,   152064, 0x02344760
-0,314,314,   40,   152064, 0x30f5fcd5
-0,343,343,   40,   152064, 0xc711ad61
-0,371,371,   40,   152064, 0x24eca223
-0,399,399,   40,   152064, 0x52a48ddd
-0,427,427,   40,   152064, 0xa91c0f05
-0,456,456,   40,   152064, 0x8e364e18
-0,484,484,   40,   152064, 0xb15d38c8
-0,512,512,   40,   152064, 0xf25f6acc
-0,541,541,   40,   152064, 0xf34ddbff
-0,570,570,   40,   152064, 0xfc7bf570
-0,598,598,   40,   152064, 0x9dc72412
-0,627,627,   40,   152064, 0x445d1d59
-0,656,656,   40,   152064, 0x2f2768ef
-0,685,685,   40,   152064, 0xce09f9d6
-0,714,714,   40,   152064, 0x95579936
-0,743,743,   40,   152064, 0x43d796b5
-0,772,772,   40,   152064, 0xd780d887
-0,800,800,   40,   152064, 0x76d2a455
-0,829,829,   40,   152064, 0x6dc3650e
-0,858,858,   40,   152064, 0x0f9d6aca
-0,887,887,   40,   152064, 0xe295c51e
-0,915,915,   40,   152064, 0xd766fc8d
-0,944,944,   40,   152064, 0xe22f7a30
-0,972,972,   40,   152064, 0x7fea4378
-0,   1000,   1000,   40,   152064, 0xfa8d94fb
-0,   1029,   1029,   40,   152064, 0x4c9737ab
-0,   1057,   1057,   40,   152064, 0xa50d01f8
-0,   1085,   1085,   40,   152064, 0x0b07594c
-0,   1113,   1113,   40,   152064, 0x88734edd
-0,   1142,   1142,   40,   152064, 0xd2735925
-0,   1170,   1170,   40,   152064, 0xd4e49e08
-0,   1198,   1198,   40,   152064, 0x20cebfa9
-0,   1227,   1227,   40,   152064, 0x575c20ec
-0,   1255,   1255,   40,   152064, 0xfd500471
-0,   1284,   1284,   40,   152064, 0x61b47e73
-0,   1313,   1313,   40,   152064, 0x09ef53ff
-0,   1341,   1341,   40,   152064, 0x6e88c5c2
-0,   1370,   1370,   40,   152064, 0xbb87b483
-0,   1399,   1399,   40,   152064, 0x4bbad8ea
+0,  0,  0,0,   152064, 0x05b789ef
+0, 28, 28,0,   152064, 0x4bb46551
+0, 57, 57,0,   152064, 0x9dddf64a
+0, 86, 86,0,   152064, 0x2a8380b0
+0,115,115,0,   152064, 0x4de3b652
+0,144,144,0,   152064, 0xedb5a8e6
+0,172,172,0,   152064, 0xe20f7c23
+0,201,201,0,   152064, 0x5ab58bac
+0,229,229,0,   152064, 0x1f1b8026
+0,258,258,0,   152064, 0x91373915
+0,286,286,0,   152064, 0x02344760
+0,314,314,0,   152064, 0x30f5fcd5
+0,343,343,0,   152064, 0xc711ad61
+0,371,371,0,   152064, 0x24eca223
+0,399,399,0,   152064, 0x52a48ddd
+0,427,427,0,   152064, 0xa91c0f05
+0,456,456,0,   152064, 0x8e364e18
+0,484,484,0,   152064, 0xb15d38c8
+0,512,512,0,   152064, 0xf25f6acc

Re: [FFmpeg-devel] [FFmpeg-cvslog] fftools/ffmpeg: convert to a threaded architecture

2024-03-27 Thread Michael Niedermayer
On Tue, Dec 12, 2023 at 07:41:18AM +, Anton Khirnov wrote:
> ffmpeg | branch: master | Anton Khirnov  | Tue Jul 18 
> 16:37:52 2023 +0200| [d119ae2fd82a494d9430ff4d4fc262961a68c598] | committer: 
> Anton Khirnov
> 
> fftools/ffmpeg: convert to a threaded architecture
> 
> Change the main loop and every component (demuxers, decoders, filters,
> encoders, muxers) to use the previously added transcode scheduler. Every
> instance of every such component was already running in a separate
> thread, but now they can actually run in parallel.
> 
> Changes the results of ffmpeg-fix_sub_duration_heartbeat - tested by
> JEEB to be more correct and deterministic.
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d119ae2fd82a494d9430ff4d4fc262961a68c598
> ---
> 
>  Changelog|   2 +
>  fftools/ffmpeg.c | 374 +---
>  fftools/ffmpeg.h |  97 +--
>  fftools/ffmpeg_dec.c | 313 +++---
>  fftools/ffmpeg_demux.c   | 268 -
>  fftools/ffmpeg_enc.c | 377 ++--
>  fftools/ffmpeg_filter.c  | 714 
> ++-
>  fftools/ffmpeg_mux.c | 324 ++
>  fftools/ffmpeg_mux.h |  24 +-
>  fftools/ffmpeg_mux_init.c|  88 +--
>  fftools/ffmpeg_opt.c |   6 +-
>  tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat |  34 +-
>  12 files changed, 600 insertions(+), 2021 deletions(-)

breaks (vissible artifacts)
./ffmpeg -bitexact -t 1 -i '/home/michael/videos/bink/bikb/CGOOD3.BIK'  -y 
test.avi && ./ffplay test.avi

should be in game-formats/bink/bikb/

should i open a ticket ?

thx

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

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


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] [FFmpeg-cvslog] lavf/demux: stop calling avcodec_close()

2024-03-27 Thread James Almer

On 3/27/2024 11:13 AM, Kieran Kunhya wrote:

On Wed, 27 Mar 2024 at 14:03, Michael Niedermayer 
wrote:


On Fri, Feb 09, 2024 at 03:19:58PM +, Anton Khirnov wrote:

ffmpeg | branch: master | Anton Khirnov  | Thu Feb

1 08:57:24 2024 +0100| [ca18bb597223b3df5bbf8a1836d157ba58b62570] |
committer: Anton Khirnov


lavf/demux: stop calling avcodec_close()

Replace it with recreating the codec context.

This is the last remaining blocker for deprecating avcodec_close().




http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ca18bb597223b3df5bbf8a1836d157ba58b62570

---

  libavformat/demux.c | 61

-

  1 file changed, 56 insertions(+), 5 deletions(-)


This breaks ffprobe "Closed Caption" output
before:
Stream #0:2[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive),
1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 59.94 tbr, 90k tbn



Closed Captions are sparse side data, we shouldn't be exposing it like this
to begin with.


This avcodec_string() output is based on which 
AVCodecContext->properties flags are set (For CC, it happens when a 
caption is found). Which yes, it's not exactly ideal.

___
ffmpeg-devel mailing list
ffmpeg-devel@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: properly reduce YUV colorspace format lists

2024-03-27 Thread Damiano Galassi
On Mon, Mar 25, 2024 at 4:10 PM Niklas Haas  wrote:

> From: Niklas Haas 
>
> Doing this with REDUCE_FORMATS() instead of swap_color_*() is not only
> shorter, but more importantly comes with the benefit of being done
> inside a loop, allowing us to correctly propagate complex graphs
> involving multiple conversion filters (e.g. -vf scale,zscale).
>
> The latter family of swapping functions is only used to settle the
> best *remaining* entry if no exact match was found, and as such was
> never the correct solution to YUV colorspaces, which only care about
> exact matches.
>

I can confirm this fixes the issue I was seeing.
___
ffmpeg-devel mailing list
ffmpeg-devel@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] [FFmpeg-cvslog] lavf/demux: stop calling avcodec_close()

2024-03-27 Thread Kieran Kunhya
On Wed, 27 Mar 2024 at 14:03, Michael Niedermayer 
wrote:

> On Fri, Feb 09, 2024 at 03:19:58PM +, Anton Khirnov wrote:
> > ffmpeg | branch: master | Anton Khirnov  | Thu Feb
> 1 08:57:24 2024 +0100| [ca18bb597223b3df5bbf8a1836d157ba58b62570] |
> committer: Anton Khirnov
> >
> > lavf/demux: stop calling avcodec_close()
> >
> > Replace it with recreating the codec context.
> >
> > This is the last remaining blocker for deprecating avcodec_close().
> >
> > >
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ca18bb597223b3df5bbf8a1836d157ba58b62570
> > ---
> >
> >  libavformat/demux.c | 61
> -
> >  1 file changed, 56 insertions(+), 5 deletions(-)
>
> This breaks ffprobe "Closed Caption" output
> before:
> Stream #0:2[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive),
> 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 59.94 tbr, 90k tbn
>

Closed Captions are sparse side data, we shouldn't be exposing it like this
to begin with.

Kieran
___
ffmpeg-devel mailing list
ffmpeg-devel@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] [FFmpeg-cvslog] lavf/demux: stop calling avcodec_close()

2024-03-27 Thread Michael Niedermayer
On Fri, Feb 09, 2024 at 03:19:58PM +, Anton Khirnov wrote:
> ffmpeg | branch: master | Anton Khirnov  | Thu Feb  1 
> 08:57:24 2024 +0100| [ca18bb597223b3df5bbf8a1836d157ba58b62570] | committer: 
> Anton Khirnov
> 
> lavf/demux: stop calling avcodec_close()
> 
> Replace it with recreating the codec context.
> 
> This is the last remaining blocker for deprecating avcodec_close().
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ca18bb597223b3df5bbf8a1836d157ba58b62570
> ---
> 
>  libavformat/demux.c | 61 
> -
>  1 file changed, 56 insertions(+), 5 deletions(-)

This breaks ffprobe "Closed Caption" output
before:
Stream #0:2[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 
1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 59.94 tbr, 90k tbn

after:
Stream #0:2[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 
1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 59.94 tbr, 90k tbn

testcase:
./ffprobe ~/tickets/2147/sample.mpg 2>&1 | grep Stream

thx

should i open a ticket for this ?

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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] Undocuemnted options

2024-03-27 Thread Michael Niedermayer
Hi

some options not documented in doc/*
(this list is not complete)

libavcodec/options_table.h:{"copy_opaque", "propagate opaque values", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_COPY_OPAQUE}, .unit = "flags"},
libavcodec/options_table.h:{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), 
AV_OPT_TYPE_INT, {.i64 = 1 }, 1, INT_MAX, A|V|E|D},

libavcodec/options_table.h:{"side_data_prefer_packet", "Comma-separated list of 
side data types for which user-supplied (container) data is preferred over 
coded bytestream",
libavcodec/options_table.h:OFFSET(side_data_prefer_packet), AV_OPT_TYPE_INT 
| AR, .min = -1, .max = INT_MAX, .flags = V|A|S|D, .unit = "side_data_pkt" },

libavcodec/options_table.h:{"mastering_display_metadata",  .default_val.i64 
= AV_PKT_DATA_MASTERING_DISPLAY_METADATA,  .type = AV_OPT_TYPE_CONST, .flags = 
A|D, .unit = "side_data_pkt" },

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v2 1/1] avcodec, avformat/ffjni: fix duplicate JNI symbols

2024-03-27 Thread Leo Izen
Use SHLIBOBJS and STLIBOBJS in the Makefiles for avcodec and avformat,
and add a stub ffjni.c to libavformat, which allows the symbols to be
duplicated for shared builds but not static builds.

Signed-off-by: Leo Izen 
---
 libavcodec/Makefile  |  1 +
 libavformat/Makefile |  1 +
 libavformat/ffjni.c  | 23 +++
 libavformat/file.c   |  2 +-
 4 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/ffjni.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ce6d445c1..113adb22d5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1068,6 +1068,7 @@ STLIBOBJS-$(CONFIG_ISO_MEDIA)  += mpegaudiotabs.o
 STLIBOBJS-$(CONFIG_FLV_MUXER)  += mpeg4audio_sample_rates.o
 STLIBOBJS-$(CONFIG_HLS_DEMUXER)+= ac3_channel_layout_tab.o
 STLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += jpegxl_parse.o
+STLIBOBJS-$(CONFIG_JNI)+= ffjni.o
 STLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)   += jpegxl_parse.o
 STLIBOBJS-$(CONFIG_MATROSKA_DEMUXER)   += mpeg4audio_sample_rates.o
 STLIBOBJS-$(CONFIG_MOV_DEMUXER)+= ac3_channel_layout_tab.o
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 44aa485029..a89df7e9a3 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -728,6 +728,7 @@ SHLIBOBJS-$(CONFIG_ISO_MEDIA)+= mpegaudiotabs.o
 SHLIBOBJS-$(CONFIG_FLV_MUXER)+= mpeg4audio_sample_rates.o
 SHLIBOBJS-$(CONFIG_HLS_DEMUXER)  += ac3_channel_layout_tab.o
 SHLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER)+= jpegxl_parse.o
+SHLIBOBJS-$(CONFIG_JNI)  += ffjni.o
 SHLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)  += jpegxl_parse.o
 SHLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o
 SHLIBOBJS-$(CONFIG_MOV_DEMUXER)  += ac3_channel_layout_tab.o
diff --git a/libavformat/ffjni.c b/libavformat/ffjni.c
new file mode 100644
index 00..2b1483cf42
--- /dev/null
+++ b/libavformat/ffjni.c
@@ -0,0 +1,23 @@
+/*
+ * JNI utility functions - included stub
+ *
+ * Copyright (c) 2024 Leo Izen 
+ *
+ * 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 "libavcodec/ffjni.c"
diff --git a/libavformat/file.c b/libavformat/file.c
index 182995717a..1f853e0e17 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -527,8 +527,8 @@ const URLProtocol ff_fd_protocol = {
 
 #if CONFIG_ANDROID_CONTENT_PROTOCOL
 #include 
+#include "libavcodec/ffjni.h"
 #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
 
 typedef struct JFields {
 jclass uri_class;
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH v2 0/1] avcodec, avformat/ffjni: fix duplicate JNI symbols

2024-03-27 Thread Leo Izen
Changes since v1:
- Rebased onto master

I was unable to credit the original reporter with a Reported-by because
the name used Chinese characters (and it translated to 'admin').

Leo Izen (1):
  avcodec,avformat/ffjni: fix duplicate JNI symbols

 libavcodec/Makefile  |  1 +
 libavformat/Makefile |  1 +
 libavformat/ffjni.c  | 23 +++
 libavformat/file.c   |  2 +-
 4 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/ffjni.c

-- 
2.44.0

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

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


Re: [FFmpeg-devel] [PATCH 2/2] examples/decode_filter_video: Add loop for draining the filtergraph

2024-03-27 Thread Tobias Rapp

On 27/03/2024 13:53, Anton Khirnov wrote:


Quoting Tobias Rapp (2024-03-27 13:46:40)

On 27/03/2024 13:06, Stefano Sabatini wrote:


On date Wednesday 2024-03-27 11:51:31 +0100, Tobias Rapp wrote:

Depending on the filters used the filtergraph can produce trailing data
after feeding it the last input frame. Update the example to include the
necessary loop for draining the filtergrap.

Signed-off-by: Tobias Rapp 
---
   doc/examples/decode_filter_video.c | 19 +++
   1 file changed, 19 insertions(+)

diff --git a/doc/examples/decode_filter_video.c 
b/doc/examples/decode_filter_video.c
index 454c192..a57e6df 100644
--- a/doc/examples/decode_filter_video.c
+++ b/doc/examples/decode_filter_video.c
@@ -276,6 +276,25 @@ int main(int argc, char **argv)
   }
   av_packet_unref(packet);
   }
+if (ret == AVERROR_EOF) {
+/* signal EOF to the filtergraph */
+if (av_buffersrc_add_frame_flags(buffersrc_ctx, NULL, 0) < 0) {
+av_log(NULL, AV_LOG_ERROR, "Error while closing the 
filtergraph\n");
+goto end;
+}
+
+/* pull remaining frames from the filtergraph */
+while (1) {
+ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
+if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+break;

how are we supposed to handle the EAGAIN case? Shouldn't this be a
sleep and retry?

Good suggestion. I could add something like usleep(100) upon EAGAIN.

No, EAGAIN from a filter after EOF on all inputs is a bug.


Ok. Also from a second look at the example all the other locations where 
EAGAIN is handled do not perform a retry. So adding that would be 
orthogonal to this patch, IMHO.


Regards, Tobias

___
ffmpeg-devel mailing list
ffmpeg-devel@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 12/16] avcodec/vvcdec: sao, refact out tile_edge arrays

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_filter.c | 36 ++--
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index ecb004d245..1a3cd02a9f 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -157,56 +157,48 @@ void ff_vvc_sao_filter(VVCLocalContext *lc, int x, int y)
 const int ctb_size_y = fc->ps.sps->ctb_size_y;
 static const uint8_t sao_tab[16] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 
7, 7, 8, 8 };
 int c_idx;
-int edges[4];  // 0 left 1 top 2 right 3 bottom
 const int rx = x >> fc->ps.sps->ctb_log2_size_y;
 const int ry = y >> fc->ps.sps->ctb_log2_size_y;
+int edges[4] = { !rx, !ry, rx == fc->ps.pps->ctb_width - 1, ry == 
fc->ps.pps->ctb_height - 1 };
 const SAOParams *sao = (fc->tab.sao, rx, ry);
 // flags indicating unfilterable edges
 uint8_t vert_edge[]  = { 0, 0 };
 uint8_t horiz_edge[] = { 0, 0 };
 uint8_t diag_edge[]  = { 0, 0, 0, 0 };
+uint8_t tile_edge[]  = { 0, 0, 0, 0 };
 const uint8_t lfase  = 
fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
 const uint8_t no_tile_filter = fc->ps.pps->r->num_tiles_in_pic > 1 &&

!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag;
 const uint8_t restore= no_tile_filter || !lfase;
-uint8_t left_tile_edge   = 0;
-uint8_t right_tile_edge  = 0;
-uint8_t up_tile_edge = 0;
-uint8_t bottom_tile_edge = 0;
-
-edges[LEFT]   = rx == 0;
-edges[TOP]= ry == 0;
-edges[RIGHT]  = rx == fc->ps.pps->ctb_width  - 1;
-edges[BOTTOM] = ry == fc->ps.pps->ctb_height - 1;
 
 if (restore) {
 if (!edges[LEFT]) {
-left_tile_edge  = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
== rx;
-vert_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry)) || left_tile_edge;
+tile_edge[LEFT]  = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
== rx;
+vert_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry)) || tile_edge[LEFT];
 }
 if (!edges[RIGHT]) {
-right_tile_edge = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
!= fc->ps.pps->ctb_to_col_bd[rx + 1];
-vert_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry)) || right_tile_edge;
+tile_edge[RIGHT] = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
!= fc->ps.pps->ctb_to_col_bd[rx + 1];
+vert_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry)) || tile_edge[RIGHT];
 }
 if (!edges[TOP]) {
-up_tile_edge = no_tile_filter && fc->ps.pps->ctb_to_row_bd[ry] 
== ry;
-horiz_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry - 1)) || up_tile_edge;
+tile_edge[TOP] = no_tile_filter && 
fc->ps.pps->ctb_to_row_bd[ry] == ry;
+horiz_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry - 1)) || tile_edge[TOP];
 }
 if (!edges[BOTTOM]) {
-bottom_tile_edge = no_tile_filter && fc->ps.pps->ctb_to_row_bd[ry] 
!= fc->ps.pps->ctb_to_row_bd[ry + 1];
-horiz_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry + 1)) || bottom_tile_edge;
+tile_edge[BOTTOM] = no_tile_filter && 
fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1];
+horiz_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry + 1)) || tile_edge[BOTTOM];
 }
 if (!edges[LEFT] && !edges[TOP]) {
-diag_edge[0] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry - 1)) || left_tile_edge || up_tile_edge;
+diag_edge[0] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry - 1)) || tile_edge[LEFT] || tile_edge[TOP];
 }
 if (!edges[TOP] && !edges[RIGHT]) {
-diag_edge[1] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry - 1)) || right_tile_edge || up_tile_edge;
+diag_edge[1] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry - 1)) || tile_edge[RIGHT] || tile_edge[TOP];
 }
 if (!edges[RIGHT] && !edges[BOTTOM]) {
-diag_edge[2] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry + 1)) || right_tile_edge || bottom_tile_edge;
+diag_edge[2] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry + 1)) || tile_edge[RIGHT] || 
tile_edge[BOTTOM];
 }
 if (!edges[LEFT] && !edges[BOTTOM]) {
-diag_edge[3] = 

[FFmpeg-devel] [PATCH v2 11/16] avcodec/vvcdec: refact, movie the lc->sc assignment to task_run_stage to simplify the code

2024-03-27 Thread Nuo Mi
This change also make the lc->sc assigned for run_sao
---
 libavcodec/vvc/vvc_thread.c | 66 ++---
 1 file changed, 17 insertions(+), 49 deletions(-)

diff --git a/libavcodec/vvc/vvc_thread.c b/libavcodec/vvc/vvc_thread.c
index 5d2e8c67b9..8f23b8138b 100644
--- a/libavcodec/vvc/vvc_thread.c
+++ b/libavcodec/vvc/vvc_thread.c
@@ -416,7 +416,6 @@ static int run_parse(VVCContext *s, VVCLocalContext *lc, 
VVCTask *t)
 const int rs= t->rs;
 const CTU *ctu  = fc->tab.ctus + rs;
 
-lc->sc = t->sc;
 lc->ep = t->ep;
 
 ret = ff_vvc_coding_tree_unit(lc, t->ctu_idx, rs, t->rx, t->ry);
@@ -432,15 +431,9 @@ static int run_parse(VVCContext *s, VVCLocalContext *lc, 
VVCTask *t)
 static int run_inter(VVCContext *s, VVCLocalContext *lc, VVCTask *t)
 {
 VVCFrameContext *fc = lc->fc;
-VVCFrameThread *ft  = fc->ft;
-const int rs= t->ry * ft->ctu_width + t->rx;
-const CTU *ctu  = fc->tab.ctus + rs;
-const int slice_idx = fc->tab.slice_idx[rs];
+const CTU *ctu  = fc->tab.ctus + t->rs;
 
-if (slice_idx != -1) {
-lc->sc = fc->slices[slice_idx];
-ff_vvc_predict_inter(lc, rs);
-}
+ff_vvc_predict_inter(lc, t->rs);
 
 if (ctu->has_dmvr)
 report_frame_progress(fc, t->ry, VVC_PROGRESS_MV);
@@ -450,14 +443,7 @@ static int run_inter(VVCContext *s, VVCLocalContext *lc, 
VVCTask *t)
 
 static int run_recon(VVCContext *s, VVCLocalContext *lc, VVCTask *t)
 {
-VVCFrameContext *fc = lc->fc;
-const int rs= t->rs;
-const int slice_idx = fc->tab.slice_idx[rs];
-
-if (slice_idx != -1) {
-lc->sc = fc->slices[slice_idx];
-ff_vvc_reconstruct(lc, rs, t->rx, t->ry);
-}
+ff_vvc_reconstruct(lc, t->rs, t->rx, t->ry);
 
 return 0;
 }
@@ -469,13 +455,8 @@ static int run_lmcs(VVCContext *s, VVCLocalContext *lc, 
VVCTask *t)
 const int ctu_size  = ft->ctu_size;
 const int x0= t->rx * ctu_size;
 const int y0= t->ry * ctu_size;
-const int rs= t->ry * ft->ctu_width + t->rx;
-const int slice_idx = fc->tab.slice_idx[rs];
 
-if (slice_idx != -1) {
-lc->sc = fc->slices[slice_idx];
-ff_vvc_lmcs_filter(lc, x0, y0);
-}
+ff_vvc_lmcs_filter(lc, x0, y0);
 
 return 0;
 }
@@ -484,18 +465,13 @@ static int run_deblock_v(VVCContext *s, VVCLocalContext 
*lc, VVCTask *t)
 {
 VVCFrameContext *fc = lc->fc;
 VVCFrameThread *ft  = fc->ft;
-const int rs= t->ry * ft->ctu_width + t->rx;
 const int ctb_size  = ft->ctu_size;
 const int x0= t->rx * ctb_size;
 const int y0= t->ry * ctb_size;
-const int slice_idx = fc->tab.slice_idx[rs];
 
-if (slice_idx != -1) {
-lc->sc = fc->slices[slice_idx];
-if (!lc->sc->sh.r->sh_deblocking_filter_disabled_flag) {
-ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, rs);
-ff_vvc_deblock_vertical(lc, x0, y0, rs);
-}
+if (!lc->sc->sh.r->sh_deblocking_filter_disabled_flag) {
+ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, t->rs);
+ff_vvc_deblock_vertical(lc, x0, y0, t->rs);
 }
 
 return 0;
@@ -506,20 +482,15 @@ static int run_deblock_h(VVCContext *s, VVCLocalContext 
*lc, VVCTask *t)
 VVCFrameContext *fc = lc->fc;
 VVCFrameThread *ft  = fc->ft;
 const int ctb_size  = ft->ctu_size;
-const int rs= t->ry * ft->ctu_width + t->rx;
 const int x0= t->rx * ctb_size;
 const int y0= t->ry * ctb_size;
-const int slice_idx = fc->tab.slice_idx[rs];
 
-if (slice_idx != -1) {
-lc->sc = fc->slices[slice_idx];
-if (!lc->sc->sh.r->sh_deblocking_filter_disabled_flag) {
-ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, rs);
-ff_vvc_deblock_horizontal(lc, x0, y0, rs);
-}
-if (fc->ps.sps->r->sps_sao_enabled_flag)
-ff_vvc_sao_copy_ctb_to_hv(lc, t->rx, t->ry, t->ry == 
ft->ctu_height - 1);
+if (!lc->sc->sh.r->sh_deblocking_filter_disabled_flag) {
+ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, t->rs);
+ff_vvc_deblock_horizontal(lc, x0, y0, t->rs);
 }
+if (fc->ps.sps->r->sps_sao_enabled_flag)
+ff_vvc_sao_copy_ctb_to_hv(lc, t->rx, t->ry, t->ry == ft->ctu_height - 
1);
 
 return 0;
 }
@@ -528,13 +499,12 @@ static int run_sao(VVCContext *s, VVCLocalContext *lc, 
VVCTask *t)
 {
 VVCFrameContext *fc = lc->fc;
 VVCFrameThread *ft  = fc->ft;
-const int rs= t->ry * fc->ps.pps->ctb_width + t->rx;
 const int ctb_size  = ft->ctu_size;
 const int x0= t->rx * ctb_size;
 const int y0= t->ry * ctb_size;
 
 if (fc->ps.sps->r->sps_sao_enabled_flag) {
-ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, rs);
+ff_vvc_decode_neighbour(lc, x0, y0, t->rx, t->ry, t->rs);
 ff_vvc_sao_filter(lc, x0, y0);
 }
 
@@ -553,12 +523,8 @@ static int run_alf(VVCContext *s, 

[FFmpeg-devel] [PATCH v2 16/16] avcodec/vvcdec: inter prediction, support subpicture

2024-03-27 Thread Nuo Mi
passed files:
LMCS_B_Dolby_2.bit
CodingToolsSets_E_Tencent_1.bit
SUBPIC_A_HUAWEI_3.bit
SUBPIC_B_HUAWEI_3.bit
SUBPIC_C_ERICSSON_1.bit
SUBPIC_D_ERICSSON_1.bit
SUBPIC_E_MediaTek_1.bit

passed dvb conformance files 
(https://dvb.org/specifications/verification-validation/vvc-test-content):
VVC_HDR_UHDTV1_OpenGOP_3840x2160_50fps_HLG10_mosaic.bit
VVC_HDR_UHDTV1_OpenGOP_3840x2160_50fps_HLG10_PiP.bit
---
 libavcodec/vvc/vvc_inter.c | 79 +++---
 1 file changed, 56 insertions(+), 23 deletions(-)

diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
index c5629f7f6f..1a87cb71cf 100644
--- a/libavcodec/vvc/vvc_inter.c
+++ b/libavcodec/vvc/vvc_inter.c
@@ -30,14 +30,34 @@
 #define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32)
 static const int bcw_w_lut[] = {4, 5, 3, 10, -2};
 
-static int emulated_edge(const VVCFrameContext *fc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
-const int x_off, const int y_off, const int block_w, const int block_h, 
const int is_luma)
+static void subpic_offset(int *x_off, int *y_off,
+const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int 
is_luma)
 {
-const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
-const int extra_after  = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
-const int extra= is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
-const int pic_width= is_luma ? fc->ps.pps->width  : (fc->ps.pps->width 
>> fc->ps.sps->hshift[1]);
-const int pic_height   = is_luma ? fc->ps.pps->height : 
(fc->ps.pps->height >> fc->ps.sps->vshift[1]);
+*x_off -= pps->subpic_x[subpic_idx] >> sps->hshift[!is_luma];
+*y_off -= pps->subpic_y[subpic_idx] >> sps->vshift[!is_luma];
+}
+
+static void subpic_width_height(int *pic_width, int *pic_height,
+const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int 
is_luma)
+{
+*pic_width  = pps->subpic_width[subpic_idx]  >> sps->hshift[!is_luma];
+*pic_height = pps->subpic_height[subpic_idx] >> sps->vshift[!is_luma];
+}
+
+static int emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
+int x_off, int y_off, const int block_w, const int block_h, const int 
is_luma)
+{
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps = fc->ps.sps;
+const VVCPPS *pps = fc->ps.pps;
+const int subpic_idx  = lc->sc->sh.r->curr_subpic_idx;
+const int extra_before= is_luma ? LUMA_EXTRA_BEFORE : 
CHROMA_EXTRA_BEFORE;
+const int extra_after = is_luma ? LUMA_EXTRA_AFTER : 
CHROMA_EXTRA_AFTER;
+const int extra   = is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
+int pic_width, pic_height;
+
+subpic_offset(_off, _off, sps, pps, subpic_idx, is_luma);
+subpic_width_height(_width, _height, sps, pps, subpic_idx, 
is_luma);
 
 if (x_off < extra_before || y_off < extra_before ||
 x_off >= pic_width - block_w - extra_after ||
@@ -57,14 +77,21 @@ static int emulated_edge(const VVCFrameContext *fc, uint8_t 
*dst, const uint8_t
 return 0;
 }
 
-static void emulated_edge_dmvr(const VVCFrameContext *fc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
-const int x_sb, const int y_sb, const int x_off, const int y_off, const 
int block_w, const int block_h, const int is_luma)
+static void emulated_edge_dmvr(const VVCLocalContext *lc, uint8_t *dst, const 
uint8_t **src, ptrdiff_t *src_stride,
+int x_sb, int y_sb, int x_off,  int y_off, const int block_w, const int 
block_h, const int is_luma)
 {
-const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
-const int extra_after  = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
-const int extra= is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
-const int pic_width= is_luma ? fc->ps.pps->width  : (fc->ps.pps->width 
>> fc->ps.sps->hshift[1]);
-const int pic_height   = is_luma ? fc->ps.pps->height : 
(fc->ps.pps->height >> fc->ps.sps->vshift[1]);
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps = fc->ps.sps;
+const VVCPPS *pps = fc->ps.pps;
+const int subpic_idx  = lc->sc->sh.r->curr_subpic_idx;
+const int extra_before= is_luma ? LUMA_EXTRA_BEFORE : 
CHROMA_EXTRA_BEFORE;
+const int extra_after = is_luma ? LUMA_EXTRA_AFTER : 
CHROMA_EXTRA_AFTER;
+const int extra   = is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
+int pic_width, pic_height;
+
+subpic_offset(_off, _off, sps, pps, subpic_idx, is_luma);
+subpic_offset(_sb, _sb, sps, pps, subpic_idx, is_luma);
+subpic_width_height(_width, _height, sps, pps, subpic_idx, 
is_luma);
 
 if (x_off < extra_before || y_off < extra_before ||
 x_off >= pic_width - block_w - extra_after ||
@@ -88,11 +115,17 @@ static void emulated_edge_dmvr(const VVCFrameContext *fc, 
uint8_t *dst, const ui
}
 }
 
-static void emulated_edge_bilinear(const 

[FFmpeg-devel] [PATCH v2 15/16] avcodec/vvcdec: mvs, support subpicture

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_mvs.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vvc/vvc_mvs.c b/libavcodec/vvc/vvc_mvs.c
index cf92202b5b..37a2d0a228 100644
--- a/libavcodec/vvc/vvc_mvs.c
+++ b/libavcodec/vvc/vvc_mvs.c
@@ -200,10 +200,12 @@ static int derive_temporal_colocated_mvs(const 
VVCLocalContext *lc, MvField temp
 static int temporal_luma_motion_vector(const VVCLocalContext *lc,
 const int refIdxLx, Mv *mvLXCol, const int X, int check_center, int 
sb_flag)
 {
-const VVCFrameContext *fc   = lc->fc;
-const VVCSPS *sps   = fc->ps.sps;
-const CodingUnit *cu= lc->cu;
-int x, y, colPic, availableFlagLXCol = 0;
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps = fc->ps.sps;
+const VVCPPS *pps = fc->ps.pps;
+const CodingUnit *cu  = lc->cu;
+const int subpic_idx  = lc->sc->sh.r->curr_subpic_idx;
+int x, y, x_end, y_end, colPic, availableFlagLXCol = 0;
 int min_pu_width = fc->ps.pps->min_pu_width;
 VVCFrame *ref = fc->ref->collocated_ref;
 MvField *tab_mvf;
@@ -224,10 +226,12 @@ static int temporal_luma_motion_vector(const 
VVCLocalContext *lc,
 x = cu->x0 + cu->cb_width;
 y = cu->y0 + cu->cb_height;
 
+x_end = pps->subpic_x[subpic_idx] + pps->subpic_width[subpic_idx];
+y_end = pps->subpic_y[subpic_idx] + pps->subpic_height[subpic_idx];
+
 if (tab_mvf &&
 (cu->y0 >> sps->ctb_log2_size_y) == (y >> sps->ctb_log2_size_y) &&
-y < fc->ps.pps->height &&
-x < fc->ps.pps->width) {
+x < x_end && y < y_end) {
 x &= ~7;
 y &= ~7;
 temp_col   = TAB_MVF(x, y);
@@ -991,13 +995,18 @@ static av_always_inline int compare_pf_ref_idx(const 
MvField *A, const struct Mv
 return 1;
 }
 
-static av_always_inline void sb_clip_location(const VVCFrameContext *fc,
+static av_always_inline void sb_clip_location(const VVCLocalContext *lc,
 const int x_ctb, const int y_ctb, const Mv* temp_mv, int *x, int *y)
 {
-const VVCPPS *pps   = fc->ps.pps;
-const int ctb_log2_size = fc->ps.sps->ctb_log2_size_y;
-*y = av_clip(*y + temp_mv->y, y_ctb, FFMIN(pps->height - 1, y_ctb + (1 << 
ctb_log2_size) - 1)) & ~7;
-*x = av_clip(*x + temp_mv->x, x_ctb, FFMIN(pps->width - 1,  x_ctb + (1 << 
ctb_log2_size) + 3)) & ~7;
+const VVCFrameContext *fc = lc->fc;
+const VVCPPS *pps = fc->ps.pps;
+const int ctb_log2_size   = fc->ps.sps->ctb_log2_size_y;
+const int subpic_idx  = lc->sc->sh.r->curr_subpic_idx;
+const int x_end   = pps->subpic_x[subpic_idx] + 
pps->subpic_width[subpic_idx];
+const int y_end   = pps->subpic_y[subpic_idx] + 
pps->subpic_height[subpic_idx];
+
+*x = av_clip(*x + temp_mv->x, x_ctb, FFMIN(x_end - 1, x_ctb + (1 << 
ctb_log2_size) + 3)) & ~7;
+*y = av_clip(*y + temp_mv->y, y_ctb, FFMIN(y_end - 1, y_ctb + (1 << 
ctb_log2_size) - 1)) & ~7;
 }
 
 static void sb_temproal_luma_motion(const VVCLocalContext *lc,
@@ -1015,7 +1024,7 @@ static void sb_temproal_luma_motion(const VVCLocalContext 
*lc,
 int colPic  = ref->poc;
 int X   = 0;
 
-sb_clip_location(fc, x_ctb, y_ctb, temp_mv, , );
+sb_clip_location(lc, x_ctb, y_ctb, temp_mv, , );
 
 temp_col= TAB_MVF(x, y);
 mvLXCol = mv + 0;
-- 
2.25.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 14/16] avcodec/vvcdec: alf, support subpicture

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_filter.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index 6b4c2050c7..de0816619b 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -1199,6 +1199,7 @@ void ff_vvc_alf_copy_ctu_to_hv(VVCLocalContext* lc, const 
int x0, const int y0)
 void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, const int y0)
 {
 VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps   = fc->ps.sps;
 const VVCPPS *pps   = fc->ps.pps;
 const int rx= x0 >> fc->ps.sps->ctb_log2_size_y;
 const int ry= y0 >> fc->ps.sps->ctb_log2_size_y;
@@ -1207,6 +1208,7 @@ void ff_vvc_alf_filter(VVCLocalContext *lc, const int x0, 
const int y0)
 const int padded_stride = EDGE_EMU_BUFFER_STRIDE << ps;
 const int padded_offset = padded_stride * ALF_PADDING_SIZE + 
(ALF_PADDING_SIZE << ps);
 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 
VVC_MAX_SAMPLE_ARRAYS : 1;
+const int subpic_idx= lc->sc->sh.r->curr_subpic_idx;
 ALFParams *alf  = (fc->tab.alf, rx, ry);
 int edges[MAX_EDGES]= { rx == 0, ry == 0, rx == pps->ctb_width - 1, ry 
== pps->ctb_height - 1 };
 
@@ -1224,6 +1226,13 @@ void ff_vvc_alf_filter(VVCLocalContext *lc, const int 
x0, const int y0)
 edges[BOTTOM] = edges[BOTTOM] || CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry + 1);
 }
 
+if (!sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx]) {
+edges[LEFT]   = edges[LEFT] || (lc->boundary_flags & 
BOUNDARY_LEFT_SUBPIC);
+edges[TOP]= edges[TOP] || (lc->boundary_flags & 
BOUNDARY_UPPER_SUBPIC);
+edges[RIGHT]  = edges[RIGHT] || 
fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + 
fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx;
+edges[BOTTOM] = edges[BOTTOM] || 
fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + 
fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry;
+}
+
 for (int c_idx = 0; c_idx < c_end; c_idx++) {
 const int hs = fc->ps.sps->hshift[c_idx];
 const int vs = fc->ps.sps->vshift[c_idx];
-- 
2.25.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 13/16] avcodec/vvcdec: sao, support subpicture

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_filter.c | 40 +
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index 1a3cd02a9f..6b4c2050c7 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -166,39 +166,53 @@ void ff_vvc_sao_filter(VVCLocalContext *lc, int x, int y)
 uint8_t horiz_edge[] = { 0, 0 };
 uint8_t diag_edge[]  = { 0, 0, 0, 0 };
 uint8_t tile_edge[]  = { 0, 0, 0, 0 };
+uint8_t subpic_edge[]= { 0, 0, 0, 0 };
+const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
 const uint8_t lfase  = 
fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag;
 const uint8_t no_tile_filter = fc->ps.pps->r->num_tiles_in_pic > 1 &&

!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag;
-const uint8_t restore= no_tile_filter || !lfase;
+const uint8_t no_subpic_filter = fc->ps.sps->r->sps_num_subpics_minus1 &&
+!fc->ps.sps->r->sps_loop_filter_across_subpic_enabled_flag[subpic_idx];
+const uint8_t restore= no_subpic_filter || no_tile_filter || 
!lfase;
 
 if (restore) {
 if (!edges[LEFT]) {
-tile_edge[LEFT]  = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
== rx;
-vert_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry)) || tile_edge[LEFT];
+tile_edge[LEFT]   = no_tile_filter && 
fc->ps.pps->ctb_to_col_bd[rx] == rx;
+subpic_edge[LEFT] = no_subpic_filter && 
fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] == rx;
+vert_edge[0]  = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry)) || tile_edge[LEFT] || subpic_edge[LEFT];
 }
 if (!edges[RIGHT]) {
-tile_edge[RIGHT] = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
!= fc->ps.pps->ctb_to_col_bd[rx + 1];
-vert_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry)) || tile_edge[RIGHT];
+tile_edge[RIGHT]   = no_tile_filter && 
fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1];
+subpic_edge[RIGHT] = no_subpic_filter &&
+fc->ps.sps->r->sps_subpic_ctu_top_left_x[subpic_idx] + 
fc->ps.sps->r->sps_subpic_width_minus1[subpic_idx] == rx;
+vert_edge[1]   = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry)) || tile_edge[RIGHT] || subpic_edge[RIGHT];
 }
 if (!edges[TOP]) {
-tile_edge[TOP] = no_tile_filter && 
fc->ps.pps->ctb_to_row_bd[ry] == ry;
-horiz_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry - 1)) || tile_edge[TOP];
+tile_edge[TOP]   = no_tile_filter && fc->ps.pps->ctb_to_row_bd[ry] 
== ry;
+subpic_edge[TOP] = no_subpic_filter && 
fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] == ry;
+horiz_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry - 1)) || tile_edge[TOP] || subpic_edge[TOP];
 }
 if (!edges[BOTTOM]) {
-tile_edge[BOTTOM] = no_tile_filter && 
fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1];
-horiz_edge[1]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry + 1)) || tile_edge[BOTTOM];
+tile_edge[BOTTOM]   = no_tile_filter && 
fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1];
+subpic_edge[BOTTOM] = no_subpic_filter &&
+fc->ps.sps->r->sps_subpic_ctu_top_left_y[subpic_idx] + 
fc->ps.sps->r->sps_subpic_height_minus1[subpic_idx] == ry;
+horiz_edge[1]   = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx, ry + 1)) || tile_edge[BOTTOM] || subpic_edge[BOTTOM];
 }
 if (!edges[LEFT] && !edges[TOP]) {
-diag_edge[0] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry - 1)) || tile_edge[LEFT] || tile_edge[TOP];
+diag_edge[0] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry - 1)) ||
+tile_edge[LEFT] || tile_edge[TOP] || subpic_edge[LEFT] || 
subpic_edge[TOP];
 }
 if (!edges[TOP] && !edges[RIGHT]) {
-diag_edge[1] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry - 1)) || tile_edge[RIGHT] || tile_edge[TOP];
+diag_edge[1] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, ry - 1)) ||
+tile_edge[RIGHT] || tile_edge[TOP] || subpic_edge[TOP] || 
subpic_edge[RIGHT];
 }
 if (!edges[RIGHT] && !edges[BOTTOM]) {
-diag_edge[2] = (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx + 1, 

[FFmpeg-devel] [PATCH v2 10/16] avcodec/vvcdec: deblock, support subpicture

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_filter.c | 52 +
 libavcodec/vvc/vvc_filter.h |  6 +++--
 libavcodec/vvc/vvc_thread.c |  4 +--
 3 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index 11972bde41..ecb004d245 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -529,9 +529,10 @@ static av_always_inline int deblock_bs(const 
VVCLocalContext *lc,
 }
 
 static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary,
-const int pos, const int vertical)
+const int pos, const int rs, const int vertical)
 {
 const VVCFrameContext *fc = lc->fc;
+const H266RawSPS *rsps= fc->ps.sps->r;
 const H266RawPPS *rpps= fc->ps.pps->r;
 int flag;
 if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) {
@@ -544,12 +545,22 @@ static int deblock_is_boundary(const VVCLocalContext *lc, 
const int boundary,
 if (lc->boundary_flags & flag &&
 !rpps->pps_loop_filter_across_tiles_enabled_flag)
 return 0;
+
+flag = vertical ? BOUNDARY_LEFT_SUBPIC : BOUNDARY_UPPER_SUBPIC;
+if (lc->boundary_flags & flag) {
+const int q_rs  = rs - (vertical ? 1 : 
fc->ps.pps->ctb_width);
+const SliceContext *q_slice = 
lc->fc->slices[lc->fc->tab.slice_idx[q_rs]];
+
+if 
(!rsps->sps_loop_filter_across_subpic_enabled_flag[q_slice->sh.r->curr_subpic_idx]
 ||
+
!rsps->sps_loop_filter_across_subpic_enabled_flag[lc->sc->sh.r->curr_subpic_idx])
+return 0;
+}
 }
 return boundary;
 }
 
 static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
-const int x0, const int y0, const int width, const int height)
+const int x0, const int y0, const int width, const int height, const int 
rs)
 {
 const VVCFrameContext *fc  = lc->fc;
 const MvField *tab_mvf = fc->tab.mvf;
@@ -574,7 +585,7 @@ static void vvc_deblock_bs_luma_vertical(const 
VVCLocalContext *lc,
 }
 
 // bs for vertical TU boundaries
-boundary_left = deblock_is_boundary(lc, x0 > 0 && !(x0 & 3), x0, 1);
+boundary_left = deblock_is_boundary(lc, x0 > 0 && !(x0 & 3), x0, rs, 1);
 
 if (boundary_left) {
 const RefPicList *rpl_left =
@@ -598,7 +609,7 @@ static void vvc_deblock_bs_luma_vertical(const 
VVCLocalContext *lc,
 }
 
 static void vvc_deblock_bs_luma_horizontal(const VVCLocalContext *lc,
-const int x0, const int y0, const int width, const int height)
+const int x0, const int y0, const int width, const int height, const int 
rs)
 {
 const VVCFrameContext *fc  = lc->fc;
 const MvField *tab_mvf = fc->tab.mvf;
@@ -622,7 +633,7 @@ static void vvc_deblock_bs_luma_horizontal(const 
VVCLocalContext *lc,
 has_horizontal_sb = cb_height > 8;
 }
 
-boundary_upper = deblock_is_boundary(lc, y0 > 0 && !(y0 & 3), y0, 0);
+boundary_upper = deblock_is_boundary(lc, y0 > 0 && !(y0 & 3), y0, rs, 0);
 
 if (boundary_upper) {
 const RefPicList *rpl_top =
@@ -647,12 +658,11 @@ static void vvc_deblock_bs_luma_horizontal(const 
VVCLocalContext *lc,
 }
 
 static void vvc_deblock_bs_chroma_vertical(const VVCLocalContext *lc,
-const int x0, const int y0, const int width, const int height)
+const int x0, const int y0, const int width, const int height, const int 
rs)
 {
 const VVCFrameContext *fc = lc->fc;
-// bs for vertical TU boundaries
 const int boundary_left = deblock_is_boundary(lc,
- x0 > 0 && !(x0 & ((CHROMA_GRID << fc->ps.sps->hshift[CHROMA]) - 1)), 
x0, 1);
+ x0 > 0 && !(x0 & ((CHROMA_GRID << fc->ps.sps->hshift[CHROMA]) - 1)), 
x0, rs, 1);
 
 if (boundary_left) {
 for (int i = 0; i < height; i += 2) {
@@ -666,11 +676,11 @@ static void vvc_deblock_bs_chroma_vertical(const 
VVCLocalContext *lc,
 }
 
 static void vvc_deblock_bs_chroma_horizontal(const VVCLocalContext *lc,
-const int x0, const int y0, const int width, const int height)
+const int x0, const int y0, const int width, const int height, const int 
rs)
 {
 const VVCFrameContext *fc = lc->fc;
 const int boundary_upper  = deblock_is_boundary(lc,
-y0 > 0 && !(y0 & ((CHROMA_GRID << fc->ps.sps->vshift[CHROMA]) - 1)), 
y0, 0);
+y0 > 0 && !(y0 & ((CHROMA_GRID << fc->ps.sps->vshift[CHROMA]) - 1)), 
y0, rs, 0);
 
 if (boundary_upper) {
 for (int i = 0; i < width; i += 2) {
@@ -684,9 +694,9 @@ static void vvc_deblock_bs_chroma_horizontal(const 
VVCLocalContext *lc,
 }
 
 typedef void (*deblock_bs_fn)(const VVCLocalContext *lc, const int x0, const 
int y0,
-const int width, const int height);
+const int width, const int height, const int rs);
 
-static void vvc_deblock_bs(const VVCLocalContext *lc, const int x0, const int 
y0, const int vertical)
+static void vvc_deblock_bs(const VVCLocalContext *lc, const int x0, const int 
y0, const int rs, const int 

[FFmpeg-devel] [PATCH v2 09/16] avcodec/vvcdec: refact out deblock_is_boundary

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_filter.c | 66 +++--
 1 file changed, 26 insertions(+), 40 deletions(-)

diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index 10bd57e078..11972bde41 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -528,6 +528,26 @@ static av_always_inline int deblock_bs(const 
VVCLocalContext *lc,
 return boundary_strength(lc, mvf_q, mvf_p, rpl_p);
 }
 
+static int deblock_is_boundary(const VVCLocalContext *lc, const int boundary,
+const int pos, const int vertical)
+{
+const VVCFrameContext *fc = lc->fc;
+const H266RawPPS *rpps= fc->ps.pps->r;
+int flag;
+if (boundary && (pos % fc->ps.sps->ctb_size_y) == 0) {
+flag = vertical ? BOUNDARY_LEFT_SLICE : BOUNDARY_UPPER_SLICE;
+if (lc->boundary_flags & flag &&
+!rpps->pps_loop_filter_across_slices_enabled_flag)
+return 0;
+
+flag = vertical ? BOUNDARY_LEFT_TILE : BOUNDARY_UPPER_TILE;
+if (lc->boundary_flags & flag &&
+!rpps->pps_loop_filter_across_tiles_enabled_flag)
+return 0;
+}
+return boundary;
+}
+
 static void vvc_deblock_bs_luma_vertical(const VVCLocalContext *lc,
 const int x0, const int y0, const int width, const int height)
 {
@@ -554,15 +574,7 @@ static void vvc_deblock_bs_luma_vertical(const 
VVCLocalContext *lc,
 }
 
 // bs for vertical TU boundaries
-boundary_left = x0 > 0 && !(x0 & 3);
-if (boundary_left &&
-((!fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag &&
-lc->boundary_flags & BOUNDARY_LEFT_SLICE &&
-(x0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0) ||
-(!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag &&
-lc->boundary_flags & BOUNDARY_LEFT_TILE &&
-(x0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0)))
-boundary_left = 0;
+boundary_left = deblock_is_boundary(lc, x0 > 0 && !(x0 & 3), x0, 1);
 
 if (boundary_left) {
 const RefPicList *rpl_left =
@@ -610,15 +622,7 @@ static void vvc_deblock_bs_luma_horizontal(const 
VVCLocalContext *lc,
 has_horizontal_sb = cb_height > 8;
 }
 
-boundary_upper = y0 > 0 && !(y0 & 3);
-if (boundary_upper &&
-((!fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag &&
-lc->boundary_flags & BOUNDARY_UPPER_SLICE &&
-(y0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0) ||
-(!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag &&
-lc->boundary_flags & BOUNDARY_UPPER_TILE &&
-(y0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0)))
-boundary_upper = 0;
+boundary_upper = deblock_is_boundary(lc, y0 > 0 && !(y0 & 3), y0, 0);
 
 if (boundary_upper) {
 const RefPicList *rpl_top =
@@ -646,18 +650,9 @@ static void vvc_deblock_bs_chroma_vertical(const 
VVCLocalContext *lc,
 const int x0, const int y0, const int width, const int height)
 {
 const VVCFrameContext *fc = lc->fc;
-int boundary_left;
-
 // bs for vertical TU boundaries
-boundary_left = x0 > 0 && !(x0 & ((CHROMA_GRID << fc->ps.sps->hshift[1]) - 
1));
-if (boundary_left &&
-((!fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag &&
-  lc->boundary_flags & BOUNDARY_LEFT_SLICE &&
-  (x0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0) ||
- (!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag &&
-  lc->boundary_flags & BOUNDARY_LEFT_TILE &&
-  (x0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0)))
-boundary_left = 0;
+const int boundary_left = deblock_is_boundary(lc,
+ x0 > 0 && !(x0 & ((CHROMA_GRID << fc->ps.sps->hshift[CHROMA]) - 1)), 
x0, 1);
 
 if (boundary_left) {
 for (int i = 0; i < height; i += 2) {
@@ -674,17 +669,8 @@ static void vvc_deblock_bs_chroma_horizontal(const 
VVCLocalContext *lc,
 const int x0, const int y0, const int width, const int height)
 {
 const VVCFrameContext *fc = lc->fc;
-int boundary_upper;
-
-boundary_upper = y0 > 0 && !(y0 & ((CHROMA_GRID << fc->ps.sps->vshift[1]) 
- 1));
-if (boundary_upper &&
-((!fc->ps.pps->r->pps_loop_filter_across_slices_enabled_flag &&
-lc->boundary_flags & BOUNDARY_UPPER_SLICE &&
-(y0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0) ||
-(!fc->ps.pps->r->pps_loop_filter_across_tiles_enabled_flag &&
-lc->boundary_flags & BOUNDARY_UPPER_TILE &&
-(y0 % (1 << fc->ps.sps->ctb_log2_size_y)) == 0)))
-boundary_upper = 0;
+const int boundary_upper  = deblock_is_boundary(lc,
+y0 > 0 && !(y0 & ((CHROMA_GRID << fc->ps.sps->vshift[CHROMA]) - 1)), 
y0, 0);
 
 if (boundary_upper) {
 for (int i = 0; i < width; i += 2) {
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org

[FFmpeg-devel] [PATCH v2 08/16] avcodec/vvcdec: misc, rename x_ctb, y_ctb, ctu_x, ctu_y to rx, ry to avoid misleading

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_ctu.c|  8 ++--
 libavcodec/vvc/vvc_filter.c | 96 ++---
 libavcodec/vvc/vvc_ps.c | 38 +++
 3 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index 05c3e04b83..8ba12c8d9f 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -87,10 +87,10 @@ static int get_qp_y_pred(const VVCLocalContext *lc)
 const int min_cb_width  = fc->ps.pps->min_cb_width;
 const int x_cb  = cu->x0 >> sps->min_cb_log2_size_y;
 const int y_cb  = cu->y0 >> sps->min_cb_log2_size_y;
-const int x_ctb = cu->x0 >> ctb_log2_size;
-const int y_ctb = cu->y0 >> ctb_log2_size;
-const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == x_ctb && (yQg >> 
ctb_log2_size) == y_ctb;
-const int in_same_ctb_b = (xQg >> ctb_log2_size) == x_ctb && ((yQg - 1) >> 
ctb_log2_size) == y_ctb;
+const int rx= cu->x0 >> ctb_log2_size;
+const int ry= cu->y0 >> ctb_log2_size;
+const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> 
ctb_log2_size) == ry;
+const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> 
ctb_log2_size) == ry;
 int qPy_pred, qPy_a, qPy_b;
 
 if (lc->na.cand_up) {
diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index dded447bfa..10bd57e078 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -99,7 +99,7 @@ static void copy_vert(uint8_t *dst, const uint8_t *src, const 
int pixel_shift, c
 
 static void copy_ctb_to_hv(VVCFrameContext *fc, const uint8_t *src,
 const ptrdiff_t src_stride, const int x, const int y, const int width, 
const int height,
-const int c_idx, const int x_ctb, const int y_ctb, const int top)
+const int c_idx, const int rx, const int ry, const int top)
 {
 const int ps = fc->ps.sps->pixel_shift;
 const int w  = fc->ps.pps->width >> fc->ps.sps->hshift[c_idx];
@@ -107,16 +107,16 @@ static void copy_ctb_to_hv(VVCFrameContext *fc, const 
uint8_t *src,
 
 if (top) {
 /* top */
-memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * y_ctb) * w + x) << 
ps),
+memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry) * w + x) << ps),
 src, width << ps);
 } else {
 /* bottom */
-memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 1) * w + x) 
<< ps),
+memcpy(fc->tab.sao_pixel_buffer_h[c_idx] + (((2 * ry + 1) * w + x) << 
ps),
 src + src_stride * (height - 1), width << ps);
 
 /* copy vertical edges */
-copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * x_ctb) * h + y) 
<< ps), src, ps, height, 1 << ps, src_stride);
-copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 1) * h + 
y) << ps), src + ((width - 1) << ps), ps, height, 1 << ps, src_stride);
+copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx) * h + y) << 
ps), src, ps, height, 1 << ps, src_stride);
+copy_vert(fc->tab.sao_pixel_buffer_v[c_idx] + (((2 * rx + 1) * h + y) 
<< ps), src + ((width - 1) << ps), ps, height, 1 << ps, src_stride);
 }
 }
 
@@ -158,9 +158,9 @@ void ff_vvc_sao_filter(VVCLocalContext *lc, int x, int y)
 static const uint8_t sao_tab[16] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 
7, 7, 8, 8 };
 int c_idx;
 int edges[4];  // 0 left 1 top 2 right 3 bottom
-const int x_ctb  = x >> fc->ps.sps->ctb_log2_size_y;
-const int y_ctb  = y >> fc->ps.sps->ctb_log2_size_y;
-const SAOParams *sao = (fc->tab.sao, x_ctb, y_ctb);
+const int rx = x >> fc->ps.sps->ctb_log2_size_y;
+const int ry = y >> fc->ps.sps->ctb_log2_size_y;
+const SAOParams *sao = (fc->tab.sao, rx, ry);
 // flags indicating unfilterable edges
 uint8_t vert_edge[]  = { 0, 0 };
 uint8_t horiz_edge[] = { 0, 0 };
@@ -174,39 +174,39 @@ void ff_vvc_sao_filter(VVCLocalContext *lc, int x, int y)
 uint8_t up_tile_edge = 0;
 uint8_t bottom_tile_edge = 0;
 
-edges[LEFT]   = x_ctb == 0;
-edges[TOP]= y_ctb == 0;
-edges[RIGHT]  = x_ctb == fc->ps.pps->ctb_width  - 1;
-edges[BOTTOM] = y_ctb == fc->ps.pps->ctb_height - 1;
+edges[LEFT]   = rx == 0;
+edges[TOP]= ry == 0;
+edges[RIGHT]  = rx == fc->ps.pps->ctb_width  - 1;
+edges[BOTTOM] = ry == fc->ps.pps->ctb_height - 1;
 
 if (restore) {
 if (!edges[LEFT]) {
-left_tile_edge  = no_tile_filter && 
fc->ps.pps->ctb_to_col_bd[x_ctb] == x_ctb;
-vert_edge[0]= (!lfase && CTB(fc->tab.slice_idx, x_ctb, y_ctb) 
!= CTB(fc->tab.slice_idx, x_ctb - 1, y_ctb)) || left_tile_edge;
+left_tile_edge  = no_tile_filter && fc->ps.pps->ctb_to_col_bd[rx] 
== rx;
+vert_edge[0]= (!lfase && CTB(fc->tab.slice_idx, rx, ry) != 
CTB(fc->tab.slice_idx, rx - 1, ry)) || left_tile_edge;
 }
 if 

[FFmpeg-devel] [PATCH v2 06/16] avcodec/vvcdec: derive subpic postion for PPS

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_ps.c | 19 +++
 libavcodec/vvc/vvc_ps.h |  4 
 2 files changed, 23 insertions(+)

diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 6b5aa31ccd..556135fee2 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -514,6 +514,24 @@ static void pps_ref_wraparound_offset(VVCPPS *pps, const 
VVCSPS *sps)
 pps->ref_wraparound_offset = (pps->width / sps->min_cb_size_y) - 
r->pps_pic_width_minus_wraparound_offset;
 }
 
+static void pps_subpic(VVCPPS *pps, const VVCSPS *sps)
+{
+const H266RawSPS *rsps = sps->r;
+for (int i = 0; i < rsps->sps_num_subpics_minus1 + 1; i++) {
+if (rsps->sps_subpic_treated_as_pic_flag[i]) {
+pps->subpic_x[i]  = rsps->sps_subpic_ctu_top_left_x[i] << 
sps->ctb_log2_size_y;
+pps->subpic_y[i]  = rsps->sps_subpic_ctu_top_left_y[i] << 
sps->ctb_log2_size_y;
+pps->subpic_width[i]  = FFMIN(pps->width  - pps->subpic_x[i], 
(rsps->sps_subpic_width_minus1[i]  + 1) << sps->ctb_log2_size_y);
+pps->subpic_height[i] = FFMIN(pps->height - pps->subpic_y[i], 
(rsps->sps_subpic_height_minus1[i] + 1) << sps->ctb_log2_size_y);
+} else {
+pps->subpic_x[i]  = 0;
+pps->subpic_y[i]  = 0;
+pps->subpic_width[i]  = pps->width;
+pps->subpic_height[i] = pps->height;
+}
+}
+}
+
 static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
 {
 int ret;
@@ -530,6 +548,7 @@ static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
 return ret;
 
 pps_ref_wraparound_offset(pps, sps);
+pps_subpic(pps, sps);
 
 return 0;
 }
diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h
index d962cdf524..f60d8b81c6 100644
--- a/libavcodec/vvc/vvc_ps.h
+++ b/libavcodec/vvc/vvc_ps.h
@@ -127,6 +127,10 @@ typedef struct VVCPPS {
 
 uint16_t ref_wraparound_offset; ///< PpsRefWraparoundOffset
 
+uint16_t subpic_x[VVC_MAX_SLICES];  ///< SubpicLeftBoundaryPos
+uint16_t subpic_y[VVC_MAX_SLICES];  ///< SubpicTopBoundaryPos
+uint16_t subpic_width[VVC_MAX_SLICES];
+uint16_t subpic_height[VVC_MAX_SLICES];
 } VVCPPS;
 
 #define MAX_WEIGHTS 15
-- 
2.25.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 07/16] avcodec/vvcdec: ff_vvc_decode_neighbour, support subpicture

2024-03-27 Thread Nuo Mi
---
 libavcodec/vvc/vvc_ctu.c | 4 
 libavcodec/vvc/vvc_ctu.h | 6 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index e48ffda938..05c3e04b83 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -2493,6 +2493,10 @@ void ff_vvc_decode_neighbour(VVCLocalContext *lc, const 
int x_ctb, const int y_c
 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
 if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 
fc->ps.pps->ctb_width])
 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
+if 
(fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
+lc->boundary_flags |= BOUNDARY_LEFT_SUBPIC;
+if 
(fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
+lc->boundary_flags |= BOUNDARY_UPPER_SUBPIC;
 lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
 lc->ctb_up_flag   = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) 
&& !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
 lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] 
== fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
diff --git a/libavcodec/vvc/vvc_ctu.h b/libavcodec/vvc/vvc_ctu.h
index 8020e184c5..460dbdba59 100644
--- a/libavcodec/vvc/vvc_ctu.h
+++ b/libavcodec/vvc/vvc_ctu.h
@@ -421,8 +421,10 @@ typedef struct VVCLocalContext {
 
 #define BOUNDARY_LEFT_SLICE (1 << 0)
 #define BOUNDARY_LEFT_TILE  (1 << 1)
-#define BOUNDARY_UPPER_SLICE(1 << 2)
-#define BOUNDARY_UPPER_TILE (1 << 3)
+#define BOUNDARY_LEFT_SUBPIC(1 << 2)
+#define BOUNDARY_UPPER_SLICE(1 << 3)
+#define BOUNDARY_UPPER_TILE (1 << 4)
+#define BOUNDARY_UPPER_SUBPIC   (1 << 5)
 /* properties of the boundary of the current CTB for the purposes
  * of the deblocking filter */
 int boundary_flags;
-- 
2.25.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 03/16] avcodec/vvcdec: misc, add specification name for pps members

2024-03-27 Thread Nuo Mi
---
 libavcodec/cbs_h266.h   | 10 +-
 libavcodec/vvc/vvc_ps.h |  8 
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 73d94157d4..21b9a4196c 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -588,11 +588,11 @@ typedef struct H266RawPPS {
 uint16_t num_tile_columns;
 uint16_t num_tile_rows;
 uint16_t num_tiles_in_pic;
-uint16_t slice_height_in_ctus[VVC_MAX_SLICES];
-uint16_t num_slices_in_subpic[VVC_MAX_SLICES];
-uint16_t sub_pic_id_val[VVC_MAX_SLICES];
-uint16_t col_width_val[VVC_MAX_TILE_COLUMNS];
-uint16_t row_height_val[VVC_MAX_TILE_ROWS];
+uint16_t slice_height_in_ctus[VVC_MAX_SLICES];  ///< 
sliceHeightInCtus
+uint16_t num_slices_in_subpic[VVC_MAX_SLICES];  ///< 
NumSlicesInSubpic
+uint16_t sub_pic_id_val[VVC_MAX_SLICES];///< SubpicIdVal
+uint16_t col_width_val[VVC_MAX_TILE_COLUMNS];   ///< ColWidthVal
+uint16_t row_height_val[VVC_MAX_TILE_ROWS]; ///< RowHeightVal
 } H266RawPPS;
 
 typedef struct H266RawAPS {
diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h
index 1164d0eab6..d962cdf524 100644
--- a/libavcodec/vvc/vvc_ps.h
+++ b/libavcodec/vvc/vvc_ps.h
@@ -115,10 +115,10 @@ typedef struct VVCPPS {
 uint16_t min_tu_height;
 
 uint32_t *ctb_addr_in_slice;///< CtbAddrInCurrSlice for entire 
picture
-uint16_t *col_bd;
-uint16_t *row_bd;
-uint16_t *ctb_to_col_bd;
-uint16_t *ctb_to_row_bd;
+uint16_t *col_bd;   ///< TileColBdVal
+uint16_t *row_bd;   ///< TileRowBdVal
+uint16_t *ctb_to_col_bd;///< CtbToTileColBd
+uint16_t *ctb_to_row_bd;///< CtbToTileRowBd
 
 uint16_t width32;   ///< width  in 32 pixels
 uint16_t height32;  ///< height in 32 pixels
-- 
2.25.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 05/16] avcodec/vvcdec: support rectangular single-slice subpics

2024-03-27 Thread Nuo Mi
From: Frank Plowman 

Co-authored-by: Nuo Mi 
---
 libavcodec/cbs_h266_syntax_template.c |  5 +-
 libavcodec/vvc/vvc_ps.c   | 93 +--
 2 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/libavcodec/cbs_h266_syntax_template.c 
b/libavcodec/cbs_h266_syntax_template.c
index f56066d470..725cee5b03 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2120,9 +2120,12 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 } else {
 if (current->pps_no_pic_partition_flag)
 infer(pps_num_slices_in_pic_minus1, 0);
-else if (current->pps_single_slice_per_subpic_flag)
+else if (current->pps_single_slice_per_subpic_flag) {
+for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
+current->num_slices_in_subpic[i] = 1;
 infer(pps_num_slices_in_pic_minus1,
   sps->sps_num_subpics_minus1);
+}
 // else?
 }
 if (!current->pps_rect_slice_flag ||
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 3e7c0b4f5b..6b5aa31ccd 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -346,6 +346,83 @@ static int pps_add_ctus(VVCPPS *pps, int *off, const int 
ctu_x, const int ctu_y,
 return *off - start;
 }
 
+static void pps_single_slice_picture(VVCPPS *pps, int *off)
+{
+for (int j = 0; j < pps->r->num_tile_rows; j++) {
+for (int i = 0; i < pps->r->num_tile_columns; i++) {
+pps->num_ctus_in_slice[0] = pps_add_ctus(pps, off,
+pps->col_bd[i], pps->row_bd[j],
+pps->r->col_width_val[i], pps->r->row_height_val[j]);
+}
+}
+}
+
+static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int 
*tile_y_end,
+const VVCSPS *sps, const VVCPPS *pps,  const int i)
+{
+const int rx = sps->r->sps_subpic_ctu_top_left_x[i];
+const int ry = sps->r->sps_subpic_ctu_top_left_y[i];
+
+*tile_x = *tile_y = 0;
+
+while (pps->col_bd[*tile_x] != rx)
+(*tile_x)++;
+
+while (pps->row_bd[*tile_y] != ry)
+(*tile_y)++;
+
+*tile_x_end = (*tile_x);
+*tile_y_end = (*tile_y);
+
+while (pps->col_bd[*tile_x_end] < rx + sps->r->sps_subpic_width_minus1[i] 
+ 1)
+(*tile_x_end)++;
+
+while (pps->row_bd[*tile_y_end] < ry + sps->r->sps_subpic_height_minus1[i] 
+ 1)
+(*tile_y_end)++;
+}
+
+static void pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS 
*sps, const int i, const int tx, const int ty, int *off)
+{
+pps->num_ctus_in_slice[i] = pps_add_ctus(pps, off,
+pps->col_bd[tx], pps->row_bd[ty],
+pps->r->col_width_val[tx], sps->r->sps_subpic_height_minus1[i] + 1);
+}
+
+static void pps_subpic_one_or_more_tiles_slice(VVCPPS *pps, const int tile_x, 
const int tile_y, const int x_end, const int y_end, const int i, int *off)
+{
+for (int ty = tile_y; ty < y_end; ty++) {
+for (int tx = tile_x; tx < x_end; tx++) {
+pps->num_ctus_in_slice[i] += pps_add_ctus(pps, off,
+pps->col_bd[tx], pps->row_bd[ty],
+pps->r->col_width_val[tx], pps->r->row_height_val[ty]);
+}
+}
+}
+
+static void pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int 
*off)
+{
+int tx, ty, x_end, y_end;
+
+pps->slice_start_offset[i] = *off;
+pps->num_ctus_in_slice[i] = 0;
+
+subpic_tiles(, , _end, _end, sps, pps, i);
+if (ty + 1 == y_end && sps->r->sps_subpic_height_minus1[i] + 1 < 
pps->r->row_height_val[ty])
+pps_subpic_less_than_one_tile_slice(pps, sps, i, tx, ty, off);
+else
+pps_subpic_one_or_more_tiles_slice(pps, tx, ty, x_end, y_end, i, off);
+}
+
+static void pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int 
*off)
+{
+if (!sps->r->sps_subpic_info_present_flag) {
+pps_single_slice_picture(pps, off);
+} else {
+for (int i = 0; i < pps->r->pps_num_slices_in_pic_minus1 + 1; i++)
+pps_subpic_slice(pps, sps, i, off);
+}
+}
+
 static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int 
*off)
 {
 const H266RawPPS *r = pps->r;
@@ -381,18 +458,22 @@ static void pps_multi_tiles_slice(VVCPPS *pps, const int 
tile_idx, const int i,
 }
 }
 
-static void pps_rect_slice(VVCPPS* pps)
+static void pps_rect_slice(VVCPPS *pps, const VVCSPS *sps)
 {
-const H266RawPPS* r = pps->r;
+const H266RawPPS *r = pps->r;
 int tile_idx = 0, off = 0;
 
+if (r->pps_single_slice_per_subpic_flag) {
+pps_single_slice_per_subpic(pps, sps, );
+return;
+}
+
 for (int i = 0; i < r->pps_num_slices_in_pic_minus1 + 1; i++) {
 if (!r->pps_slice_width_in_tiles_minus1[i] &&
 !r->pps_slice_height_in_tiles_minus1[i]) {
 i = pps_one_tile_slices(pps, tile_idx, i, );
 } else {
 

[FFmpeg-devel] [PATCH v2 04/16] avcodec/vvcdec: fix uninitialized last element of xxx_bd and ctb_to_xxx_bd arrays

2024-03-27 Thread Nuo Mi
From: Frank Plowman 

see "6.5.1 CTB raster scanning, tile scanning, and subpicture scanning 
processes"

Co-authored-by: Nuo Mi 
---
 libavcodec/vvc/vvc_ps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 7972803da6..3e7c0b4f5b 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -290,6 +290,7 @@ static int pps_bd(VVCPPS *pps)
 for (int k = pps->col_bd[i]; k < j; k++)
 pps->ctb_to_col_bd[k] = pps->col_bd[i];
 }
+pps->col_bd[r->num_tile_columns] = pps->ctb_to_col_bd[pps->ctb_width] = 
pps->ctb_width;
 
 for (int i = 0, j = 0; i < r->num_tile_rows; i++) {
 pps->row_bd[i] = j;
@@ -297,6 +298,8 @@ static int pps_bd(VVCPPS *pps)
 for (int k = pps->row_bd[i]; k < j; k++)
 pps->ctb_to_row_bd[k] = pps->row_bd[i];
 }
+pps->row_bd[r->num_tile_rows] = pps->ctb_to_row_bd[pps->ctb_height] = 
pps->ctb_height;
+
 return 0;
 }
 
-- 
2.25.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 01/16] avcodec/vvcdec: NoBackwardPredFlag, only check active pictures

2024-03-27 Thread Nuo Mi
see "8.3.6 Decoding process for collocated picture and no backward prediction"
---
 libavcodec/vvc/vvc_mvs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vvc/vvc_mvs.c b/libavcodec/vvc/vvc_mvs.c
index 6398fd3571..cf92202b5b 100644
--- a/libavcodec/vvc/vvc_mvs.c
+++ b/libavcodec/vvc/vvc_mvs.c
@@ -125,7 +125,7 @@ int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc)
 const RefPicList *rpl = lc->sc->rpl;
 
 for (j = 0; j < 2; j++) {
-for (i = 0; i < rpl[j].nb_refs; i++) {
+for (i = 0; i < lc->sc->sh.r->num_ref_idx_active[j]; i++) {
 if (rpl[j].list[i] > lc->fc->ps.ph.poc) {
 check_diffpicount++;
 break;
-- 
2.25.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 02/16] avcodec/cbs_h266: fix sh_collocated_from_l0_flag and sh_collocated_ref_idx infer

2024-03-27 Thread Nuo Mi
we have to infer sh_collocated_from_l0_flag and sh_collocated_ref_idx from 
picture head if pps_rpl_info_in_ph_flag is true
---
 libavcodec/cbs_h266_syntax_template.c | 32 +--
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavcodec/cbs_h266_syntax_template.c 
b/libavcodec/cbs_h266_syntax_template.c
index 0aae9fdfd5..f56066d470 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -3221,19 +3221,27 @@ static int FUNC(slice_header) (CodedBitstreamContext 
*ctx, RWContext *rw,
 flag(sh_cabac_init_flag);
 else
 infer(sh_cabac_init_flag, 0);
-if (ph->ph_temporal_mvp_enabled_flag && !pps->pps_rpl_info_in_ph_flag) 
{
-if (current->sh_slice_type == VVC_SLICE_TYPE_B)
-flag(sh_collocated_from_l0_flag);
-else
-infer(sh_collocated_from_l0_flag, 1);
-if ((current->sh_collocated_from_l0_flag &&
- current->num_ref_idx_active[0] > 1) ||
-(!current->sh_collocated_from_l0_flag &&
- current->num_ref_idx_active[1] > 1)) {
-unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
-ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] 
- 1);
+if (ph->ph_temporal_mvp_enabled_flag) {
+if (!pps->pps_rpl_info_in_ph_flag) {
+if (current->sh_slice_type == VVC_SLICE_TYPE_B)
+flag(sh_collocated_from_l0_flag);
+else
+infer(sh_collocated_from_l0_flag, 1);
+if ((current->sh_collocated_from_l0_flag &&
+current->num_ref_idx_active[0] > 1) ||
+(!current->sh_collocated_from_l0_flag &&
+current->num_ref_idx_active[1] > 1)) {
+unsigned int idx = current->sh_collocated_from_l0_flag ? 0 
: 1;
+ue(sh_collocated_ref_idx, 0, 
current->num_ref_idx_active[idx] - 1);
+} else {
+infer(sh_collocated_ref_idx, 0);
+}
 } else {
-infer(sh_collocated_ref_idx, 0);
+if (current->sh_slice_type == VVC_SLICE_TYPE_B)
+infer(sh_collocated_from_l0_flag, 
ph->ph_collocated_from_l0_flag);
+else
+infer(sh_collocated_from_l0_flag, 1);
+infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx);
 }
 }
 if (!pps->pps_wp_info_in_ph_flag &&
-- 
2.25.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 00/16] avcodec/vvcdec: support subpicture

2024-03-27 Thread Nuo Mi
Changes since v1:
add v2-0004-avcodec-vvcdec-fix-uninitialized-last-element-of-.patch to address
the clang-usan and clang-asan failures reported by Frank

Frank Plowman (2):
  avcodec/vvcdec: fix uninitialized last element of xxx_bd and
ctb_to_xxx_bd arrays
  avcodec/vvcdec: support rectangular single-slice subpics

Nuo Mi (14):
  avcodec/vvcdec: NoBackwardPredFlag, only check active pictures
  avcodec/cbs_h266: fix sh_collocated_from_l0_flag and
sh_collocated_ref_idx infer
  avcodec/vvcdec: misc, add specification name for pps members
  avcodec/vvcdec: derive subpic postion for PPS
  avcodec/vvcdec: ff_vvc_decode_neighbour, support subpicture
  avcodec/vvcdec: misc, rename x_ctb, y_ctb, ctu_x, ctu_y to rx, ry to
avoid misleading
  avcodec/vvcdec: refact out deblock_is_boundary
  avcodec/vvcdec: deblock, support subpicture
  avcodec/vvcdec: refact, movie the lc->sc assignment to task_run_stage
to simplify the code
  avcodec/vvcdec: sao, refact out tile_edge arrays
  avcodec/vvcdec: sao, support subpicture
  avcodec/vvcdec: alf, support subpicture
  avcodec/vvcdec: mvs, support subpicture
  avcodec/vvcdec: inter prediction, support subpicture

 libavcodec/cbs_h266.h |  10 +-
 libavcodec/cbs_h266_syntax_template.c |  37 ++--
 libavcodec/vvc/vvc_ctu.c  |  12 +-
 libavcodec/vvc/vvc_ctu.h  |   6 +-
 libavcodec/vvc/vvc_filter.c   | 233 +-
 libavcodec/vvc/vvc_filter.h   |   6 +-
 libavcodec/vvc/vvc_inter.c|  79 ++---
 libavcodec/vvc/vvc_mvs.c  |  35 ++--
 libavcodec/vvc/vvc_ps.c   | 153 ++---
 libavcodec/vvc/vvc_ps.h   |  12 +-
 libavcodec/vvc/vvc_thread.c   |  66 ++--
 11 files changed, 396 insertions(+), 253 deletions(-)

--
2.25.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] examples/decode_filter_video: Add loop for draining the filtergraph

2024-03-27 Thread Anton Khirnov
Quoting Tobias Rapp (2024-03-27 13:46:40)
> On 27/03/2024 13:06, Stefano Sabatini wrote:
> 
> > On date Wednesday 2024-03-27 11:51:31 +0100, Tobias Rapp wrote:
> >> Depending on the filters used the filtergraph can produce trailing data
> >> after feeding it the last input frame. Update the example to include the
> >> necessary loop for draining the filtergrap.
> >>
> >> Signed-off-by: Tobias Rapp 
> >> ---
> >>   doc/examples/decode_filter_video.c | 19 +++
> >>   1 file changed, 19 insertions(+)
> >>
> >> diff --git a/doc/examples/decode_filter_video.c 
> >> b/doc/examples/decode_filter_video.c
> >> index 454c192..a57e6df 100644
> >> --- a/doc/examples/decode_filter_video.c
> >> +++ b/doc/examples/decode_filter_video.c
> >> @@ -276,6 +276,25 @@ int main(int argc, char **argv)
> >>   }
> >>   av_packet_unref(packet);
> >>   }
> >> +if (ret == AVERROR_EOF) {
> >> +/* signal EOF to the filtergraph */
> >> +if (av_buffersrc_add_frame_flags(buffersrc_ctx, NULL, 0) < 0) {
> >> +av_log(NULL, AV_LOG_ERROR, "Error while closing the 
> >> filtergraph\n");
> >> +goto end;
> >> +}
> >> +
> >> +/* pull remaining frames from the filtergraph */
> >> +while (1) {
> >> +ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
> >> +if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
> >> +break;
> > how are we supposed to handle the EAGAIN case? Shouldn't this be a
> > sleep and retry?
> 
> Good suggestion. I could add something like usleep(100) upon EAGAIN.

No, EAGAIN from a filter after EOF on all inputs is a bug.

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

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


Re: [FFmpeg-devel] [PATCH 2/2] examples/decode_filter_video: Add loop for draining the filtergraph

2024-03-27 Thread Tobias Rapp

On 27/03/2024 13:06, Stefano Sabatini wrote:


On date Wednesday 2024-03-27 11:51:31 +0100, Tobias Rapp wrote:

Depending on the filters used the filtergraph can produce trailing data
after feeding it the last input frame. Update the example to include the
necessary loop for draining the filtergrap.

Signed-off-by: Tobias Rapp 
---
  doc/examples/decode_filter_video.c | 19 +++
  1 file changed, 19 insertions(+)

diff --git a/doc/examples/decode_filter_video.c 
b/doc/examples/decode_filter_video.c
index 454c192..a57e6df 100644
--- a/doc/examples/decode_filter_video.c
+++ b/doc/examples/decode_filter_video.c
@@ -276,6 +276,25 @@ int main(int argc, char **argv)
  }
  av_packet_unref(packet);
  }
+if (ret == AVERROR_EOF) {
+/* signal EOF to the filtergraph */
+if (av_buffersrc_add_frame_flags(buffersrc_ctx, NULL, 0) < 0) {
+av_log(NULL, AV_LOG_ERROR, "Error while closing the 
filtergraph\n");
+goto end;
+}
+
+/* pull remaining frames from the filtergraph */
+while (1) {
+ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
+if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
+break;

how are we supposed to handle the EAGAIN case? Shouldn't this be a
sleep and retry?


Good suggestion. I could add something like usleep(100) upon EAGAIN.

Will post an updated patch.

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

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


Re: [FFmpeg-devel] [PATCH 4/6 v2] avutil/mastering_display_metadata: add a new allocator function that returns a size

2024-03-27 Thread James Almer

On 3/27/2024 9:40 AM, Anton Khirnov wrote:

Quoting James Almer (2024-03-27 13:35:35)

On 3/27/2024 4:41 AM, Anton Khirnov wrote:

Quoting James Almer (2024-03-25 22:13:25)

On 3/25/2024 6:02 PM, Andreas Rheinhardt wrote:

James Almer:

I don't mind a function like that being added to simplify future
additions, but this API is orthogonal to the frame side data one. It's
also used in packets, for example, and right now lavf is using
sizeof(AVMasteringDisplayMetadata) because
av_mastering_display_metadata_alloc() is not useful.



The API proposed by me is supposed to make API like
av_mastering_display_metadata_alloc_size() redundant and therefore these
two additions are not orthogonal.


Just because there's a frame side data type for MDM does not make the
new alloc function redundant.


The commit message says:


av_mastering_display_metadata_alloc() is not useful in scenarios where you need 
to
know the runtime size of AVMasteringDisplayMetadata.


In what scenarios besides side data do you need to know the size of this
struct?


None within our libraries that i can think of, but library users can
have scenarios we need to provide for. MDM is a standalone API, so lets
not try to make its usability depend on a separate one.
I'm replacing a helper with a better one, it should not be so controversial.


Breaking API to benefit hypothetical use cases IS a controversial change
in my view.


Then I can leave the old on in place. But don't insist on telling people 
to use a frame side data specific alloc function if they want a MDM 
struct, because said function will not be usable for all side data types 
anyway (see video enc params, iamf params), so it's just making things 
more complex for the user for no reason.

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

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


Re: [FFmpeg-devel] [PATCH 4/6 v2] avutil/mastering_display_metadata: add a new allocator function that returns a size

2024-03-27 Thread Anton Khirnov
Quoting James Almer (2024-03-27 13:35:35)
> On 3/27/2024 4:41 AM, Anton Khirnov wrote:
> > Quoting James Almer (2024-03-25 22:13:25)
> >> On 3/25/2024 6:02 PM, Andreas Rheinhardt wrote:
> >>> James Almer:
>  I don't mind a function like that being added to simplify future
>  additions, but this API is orthogonal to the frame side data one. It's
>  also used in packets, for example, and right now lavf is using
>  sizeof(AVMasteringDisplayMetadata) because
>  av_mastering_display_metadata_alloc() is not useful.
> 
> >>>
> >>> The API proposed by me is supposed to make API like
> >>> av_mastering_display_metadata_alloc_size() redundant and therefore these
> >>> two additions are not orthogonal.
> >>
> >> Just because there's a frame side data type for MDM does not make the
> >> new alloc function redundant.
> > 
> > The commit message says:
> > 
> >> av_mastering_display_metadata_alloc() is not useful in scenarios where you 
> >> need to
> >> know the runtime size of AVMasteringDisplayMetadata.
> > 
> > In what scenarios besides side data do you need to know the size of this
> > struct?
> 
> None within our libraries that i can think of, but library users can 
> have scenarios we need to provide for. MDM is a standalone API, so lets 
> not try to make its usability depend on a separate one.
> I'm replacing a helper with a better one, it should not be so controversial.

Breaking API to benefit hypothetical use cases IS a controversial change
in my view.

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

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


Re: [FFmpeg-devel] [PATCH 4/6 v2] avutil/mastering_display_metadata: add a new allocator function that returns a size

2024-03-27 Thread James Almer

On 3/27/2024 4:41 AM, Anton Khirnov wrote:

Quoting James Almer (2024-03-25 22:13:25)

On 3/25/2024 6:02 PM, Andreas Rheinhardt wrote:

James Almer:

I don't mind a function like that being added to simplify future
additions, but this API is orthogonal to the frame side data one. It's
also used in packets, for example, and right now lavf is using
sizeof(AVMasteringDisplayMetadata) because
av_mastering_display_metadata_alloc() is not useful.



The API proposed by me is supposed to make API like
av_mastering_display_metadata_alloc_size() redundant and therefore these
two additions are not orthogonal.


Just because there's a frame side data type for MDM does not make the
new alloc function redundant.


The commit message says:


av_mastering_display_metadata_alloc() is not useful in scenarios where you need 
to
know the runtime size of AVMasteringDisplayMetadata.


In what scenarios besides side data do you need to know the size of this
struct?


None within our libraries that i can think of, but library users can 
have scenarios we need to provide for. MDM is a standalone API, so lets 
not try to make its usability depend on a separate one.

I'm replacing a helper with a better one, it should not be so controversial.
___
ffmpeg-devel mailing list
ffmpeg-devel@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/6 v2] avutil/frame: add a flag to not create duplicate entries in a side data array

2024-03-27 Thread Anton Khirnov
Quoting James Almer (2024-03-27 12:49:49)
> >  * T does have a MULTI prop, then user decides whether to replace,
> >add, or do nothing
> > 
> > I think the default behaviour for MULTI types should be adding, and the
> > other two cases should be covered by the user explicitly.
> > 
> > Then we only need a single flag, which only applies to non-MULTI types,
> > and chooses whether to replace or not.
> 
> I don't follow. How does a single flag let you choose between all these 
> scenarios?

I doesn't, my point is that for MULTI types the functions should always
add a new instance, because very few scenarios need anything else.

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

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


Re: [FFmpeg-devel] [PATCH] avformat/dvdvideodec: remove `if ((ret = ...) < 0)` pattern

2024-03-27 Thread Anton Khirnov
Quoting Stefano Sabatini (2024-03-27 12:27:24)
> it's increasing the line count and therefore decreasing readability

I don't think this holds in general.

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

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


  1   2   >