Re: [FFmpeg-devel] [PATCH] lsws/swscale.h: introduce sws_get_gaussian_vec

2023-09-02 Thread Stefano Sabatini
On date Saturday 2023-09-02 22:07:53 +0200, Michael Niedermayer wrote:
> On Fri, Sep 01, 2023 at 08:38:26PM +0200, Stefano Sabatini wrote:
> > On date Friday 2023-09-01 18:54:40 +0200, Michael Niedermayer wrote:
> > > On Thu, Aug 31, 2023 at 07:16:20PM +0200, Stefano Sabatini wrote:
> > [...]
> > > > +/**
> > > > + * Compute and return a normalized Gaussian vector.
> > > > + *
> > > > + * @param vecp: pointer where the computed vector is put in case of
> > > > + *success
> > > > + * @param standard_deviation the standard deviation used to generate
> > > > + *the Gaussian vector, must be a non-negative value
> > > > + * @param quality the quality of the generated Gaussian vector, must
> > > > + *be a non-negative value. It affects the lenght of the 
> > > > generated
> > > > + *vector. A value equal to 3 corresponds to high quality.
> > > > + * @param log_ctx a pointer to an arbitrary struct of which the first
> > > > + *field is a pointer to an AVClass struct (used for av_log)
> > > > + *used for logging, can be NULL
> > > > + *
> > > > + * @return a negative error code on error, non negative otherwise
> > > > + */
> > > > +int sws_get_gaussian_vec(SwsVector **vecp,
> > > > + double standard_deviation, double quality,
> > > > + void *log_ctx);
> > > 
> > > which of the two do you consider better?
> > > 
> > > First, here the central part we return is the vector
> > > 
> > > SwsVector *gaus_vec = sws_getGaussianVec(NULL, 1, 2);
> > > SwsVector *temp_vec = sws_ConvolveVec(NULL, in_vec, gaus_vec);
> > > sws_averageVec(temp_vec, temp_vec, in_vec);
> > > 
> > > av_free(gaus_vec);
> > > return temp_vec; // Error checking here happens by temp_vec being NULL in 
> > > all cases of error
> > > 
> > > vs.
> > > 
> > > Second, here the central part we return is the error code
> > > 
> > > SwsVector *gaus_vec = NULL;
> > > SwsVector *temp_vec = NULL;
> > > int err = sws_getGaussianVec(_vec, 1, 2);
> > > if (err<0)
> > > goto fail;
> > > 
> > > err = sws_ConvolveVec(_vec, in_vec, gaus_vec);
> > > if (err<0)
> > > goto fail;
> > > 
> > > err = sws_averageVec(_vec, temp_vec, in_vec);
> > > if (err<0)
> > > goto fail;
> > 
> > The latter pattern enables differentiation between error codes (ENOMEM
> > or EINVAL) and provides feedback in the log message. With the former
> > you only know if it fails, but you don't know why (relevant in case
> > e.g. we make the parameter tunable by a filter and we don't want to
> > add additional validation and logging at the filter level).
> 

> can the API be designed so that optionally the user could choose to
> only check the error code after several steps ?
> (this would avoid the need for 1 check per call where the fine grained
>  information is not needed)
> I mean similar to the concept of NAN in floating point so that a failure
> can be propagated and only at the end checked.

Well, with the new approach you can do:

SwsVector *gaus_vec, *temp_vec, *avg_vec;

sws_get_gaussian_vec(_vec, 1, 2);
sws_get_convolution_vec(_vec, in_vec, gaus_vec);
sws_get_average_vec(_vec, temp_vec, in_vec);
 
av_free(gaus_vec);
av_free(temp_vec);
return avg_vec; // Error checking here happens by avg_vec being NULL in all 
cases of error

If you want to disable the log we could add a log_ctx_offset parameter.
___
ffmpeg-devel mailing list
ffmpeg-devel@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 8/8] all: Replace __FUNCTION__ by __func__

2023-09-02 Thread James Almer

On 9/2/2023 8:12 PM, Andreas Rheinhardt wrote:

Only the former is valid ISO C.


Don't you mean "the latter"?



Signed-off-by: Andreas Rheinhardt 
---
  libavdevice/opengl_enc.c | 2 +-
  libavformat/apngdec.c| 2 +-
  libavformat/demux.c  | 4 ++--
  libavformat/mux.c| 2 +-
  4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 80feda7072..b2ac6eb16a 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -152,7 +152,7 @@ typedef struct FFOpenGLFunctions {
  {\
  GLenum err_code; \
  if ((err_code = glGetError()) != GL_NO_ERROR) { \
-av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: 
%d\n", __FUNCTION__, __LINE__, err_code); \
+av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: 
%d\n", __func__, __LINE__, err_code); \
  goto fail; \
  } \
  }\
diff --git a/libavformat/apngdec.c b/libavformat/apngdec.c
index 47cdbfcbfb..8f5f37a2b1 100644
--- a/libavformat/apngdec.c
+++ b/libavformat/apngdec.c
@@ -274,7 +274,7 @@ static int decode_fctl_chunk(AVFormatContext *s, 
APNGDemuxContext *ctx, AVPacket
  "delay_den: %"PRIu16", "
  "dispose_op: %d, "
  "blend_op: %d\n",
-__FUNCTION__,
+__func__,
  sequence_number,
  width,
  height,
diff --git a/libavformat/demux.c b/libavformat/demux.c
index b218f64574..b8a7a28c52 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2533,7 +2533,7 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
  if (codec && !avctx->codec)
  if (avcodec_open2(avctx, codec, options ? [i] : 
_opt) < 0)
  av_log(ic, AV_LOG_WARNING,
-   "Failed to open codec in %s\n",__FUNCTION__);
+   "Failed to open codec in %s\n", __func__);
  }
  if (!options)
  av_dict_free(_opt);
@@ -2790,7 +2790,7 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
  av_dict_set(, "codec_whitelist", 
ic->codec_whitelist, 0);
  if (avcodec_open2(avctx, codec, (options && stream_index < 
orig_nb_streams) ? [stream_index] : ) < 0)
  av_log(ic, AV_LOG_WARNING,
-   "Failed to open codec in %s\n",__FUNCTION__);
+   "Failed to open codec in %s\n", __func__);
  av_dict_free();
  }
  }
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 0cf9ebfc19..6c6c677171 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1120,7 +1120,7 @@ static int write_packet_common(AVFormatContext *s, 
AVStream *st, AVPacket *pkt,
  int ret;
  
  if (s->debug & FF_FDEBUG_TS)

-av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __FUNCTION__,
+av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __func__,
 pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
  
  guess_pkt_duration(s, st, pkt);

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

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


[FFmpeg-devel] [PATCH 9/9] avcodec/vp8data: Use <> for inclusion of stdint.h

2023-09-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp8data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vp8data.c b/libavcodec/vp8data.c
index a41fc872f5..857406928a 100644
--- a/libavcodec/vp8data.c
+++ b/libavcodec/vp8data.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "stdint.h"
+#include 
 
 // cat 1 and 2 are defined in vp8data.h
 static const uint8_t vp8_dct_cat3_prob[] = {
-- 
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 8/8] all: Replace __FUNCTION__ by __func__

2023-09-02 Thread Andreas Rheinhardt
Only the former is valid ISO C.

Signed-off-by: Andreas Rheinhardt 
---
 libavdevice/opengl_enc.c | 2 +-
 libavformat/apngdec.c| 2 +-
 libavformat/demux.c  | 4 ++--
 libavformat/mux.c| 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 80feda7072..b2ac6eb16a 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -152,7 +152,7 @@ typedef struct FFOpenGLFunctions {
 {\
 GLenum err_code; \
 if ((err_code = glGetError()) != GL_NO_ERROR) { \
-av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: 
%d\n", __FUNCTION__, __LINE__, err_code); \
+av_log(ctx, AV_LOG_ERROR, "OpenGL error occurred in '%s', line %d: 
%d\n", __func__, __LINE__, err_code); \
 goto fail; \
 } \
 }\
diff --git a/libavformat/apngdec.c b/libavformat/apngdec.c
index 47cdbfcbfb..8f5f37a2b1 100644
--- a/libavformat/apngdec.c
+++ b/libavformat/apngdec.c
@@ -274,7 +274,7 @@ static int decode_fctl_chunk(AVFormatContext *s, 
APNGDemuxContext *ctx, AVPacket
 "delay_den: %"PRIu16", "
 "dispose_op: %d, "
 "blend_op: %d\n",
-__FUNCTION__,
+__func__,
 sequence_number,
 width,
 height,
diff --git a/libavformat/demux.c b/libavformat/demux.c
index b218f64574..b8a7a28c52 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2533,7 +2533,7 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 if (codec && !avctx->codec)
 if (avcodec_open2(avctx, codec, options ? [i] : 
_opt) < 0)
 av_log(ic, AV_LOG_WARNING,
-   "Failed to open codec in %s\n",__FUNCTION__);
+   "Failed to open codec in %s\n", __func__);
 }
 if (!options)
 av_dict_free(_opt);
@@ -2790,7 +2790,7 @@ int avformat_find_stream_info(AVFormatContext *ic, 
AVDictionary **options)
 av_dict_set(, "codec_whitelist", 
ic->codec_whitelist, 0);
 if (avcodec_open2(avctx, codec, (options && stream_index < 
orig_nb_streams) ? [stream_index] : ) < 0)
 av_log(ic, AV_LOG_WARNING,
-   "Failed to open codec in %s\n",__FUNCTION__);
+   "Failed to open codec in %s\n", __func__);
 av_dict_free();
 }
 }
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 0cf9ebfc19..6c6c677171 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1120,7 +1120,7 @@ static int write_packet_common(AVFormatContext *s, 
AVStream *st, AVPacket *pkt,
 int ret;
 
 if (s->debug & FF_FDEBUG_TS)
-av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __FUNCTION__,
+av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __func__,
pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
 
 guess_pkt_duration(s, st, pkt);
-- 
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] lsws/swscale.h: introduce sws_get_gaussian_vec

2023-09-02 Thread Michael Niedermayer
On Fri, Sep 01, 2023 at 08:38:26PM +0200, Stefano Sabatini wrote:
> On date Friday 2023-09-01 18:54:40 +0200, Michael Niedermayer wrote:
> > On Thu, Aug 31, 2023 at 07:16:20PM +0200, Stefano Sabatini wrote:
> [...]
> > > +/**
> > > + * Compute and return a normalized Gaussian vector.
> > > + *
> > > + * @param vecp: pointer where the computed vector is put in case of
> > > + *success
> > > + * @param standard_deviation the standard deviation used to generate
> > > + *the Gaussian vector, must be a non-negative value
> > > + * @param quality the quality of the generated Gaussian vector, must
> > > + *be a non-negative value. It affects the lenght of the generated
> > > + *vector. A value equal to 3 corresponds to high quality.
> > > + * @param log_ctx a pointer to an arbitrary struct of which the first
> > > + *field is a pointer to an AVClass struct (used for av_log)
> > > + *used for logging, can be NULL
> > > + *
> > > + * @return a negative error code on error, non negative otherwise
> > > + */
> > > +int sws_get_gaussian_vec(SwsVector **vecp,
> > > + double standard_deviation, double quality,
> > > + void *log_ctx);
> > 
> > which of the two do you consider better?
> > 
> > First, here the central part we return is the vector
> > 
> > SwsVector *gaus_vec = sws_getGaussianVec(NULL, 1, 2);
> > SwsVector *temp_vec = sws_ConvolveVec(NULL, in_vec, gaus_vec);
> > sws_averageVec(temp_vec, temp_vec, in_vec);
> > 
> > av_free(gaus_vec);
> > return temp_vec; // Error checking here happens by temp_vec being NULL in 
> > all cases of error
> > 
> > vs.
> > 
> > Second, here the central part we return is the error code
> > 
> > SwsVector *gaus_vec = NULL;
> > SwsVector *temp_vec = NULL;
> > int err = sws_getGaussianVec(_vec, 1, 2);
> > if (err<0)
> > goto fail;
> > 
> > err = sws_ConvolveVec(_vec, in_vec, gaus_vec);
> > if (err<0)
> > goto fail;
> > 
> > err = sws_averageVec(_vec, temp_vec, in_vec);
> > if (err<0)
> > goto fail;
> 
> The latter pattern enables differentiation between error codes (ENOMEM
> or EINVAL) and provides feedback in the log message. With the former
> you only know if it fails, but you don't know why (relevant in case
> e.g. we make the parameter tunable by a filter and we don't want to
> add additional validation and logging at the filter level).

can the API be designed so that optionally the user could choose to
only check the error code after several steps ?
(this would avoid the need for 1 check per call where the fine grained
 information is not needed)
I mean similar to the concept of NAN in floating point so that a failure
can be propagated and only at the end checked.

thx

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

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, than to die in a terrorist
attack." -- Thoughty2



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 4/6] doc/developer: add a code behaviour section to development policy

2023-09-02 Thread Michael Niedermayer
On Fri, Sep 01, 2023 at 08:10:11PM +0300, Rémi Denis-Courmont wrote:
> Le torstaina 31. elokuuta 2023, 18.28.48 EEST Stefano Sabatini a écrit :
> > On date Tuesday 2023-08-29 10:34:45 +0200, Anton Khirnov wrote:
> > > Quoting Stefano Sabatini (2023-08-27 14:38:44)
> > > 
> > > > Il sab 26 ago 2023, 20:08 Anton Khirnov  ha scritto:
> > > > > Document our longstanding de facto policies on things like
> > > > > correctness,
> > > > > thread-safety, UB, etc.
> > > > 
> > > > UB?
> > > 
> > > undefined behavior
> > 
> > yes, let's avoid acronyms
> 
> I think that developers should know common accronyms of the primary 
> programming language of the project, and it is totally reasonable to expect 
> that they are.
> 

> And yes, UB is a very well known accronym in this context. In my experience, 
> people who don't know the accronym don't know the concept either, so spelling 
> it out wouldn't even help.

There is a difference between not knowing a concept and not knowing what
concept is referenced.

"Undefined behavior" can be googled, and can to some extend be understood
from the meaning of the words by people with a math background.

googling "UB" results in "Universitätsbibliothek Wien" here and nothing on
the first page of links is related to "undefined"

So i do think, in case of a policy or some coding rules it should be spelled out

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


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

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


Re: [FFmpeg-devel] [PATCH] avformat/vpcc: fix vpcC generation for RTMP

2023-09-02 Thread James Almer

On 9/2/2023 2:02 PM, Alessandro Ros wrote:

In order to send VP9 tracks with RTMP, the enhanced RTMP specification
tells that VPCodecConfigurationRecord, a.k.a. vpcC ISO-BMFF box, must
be inserted into a metadata message. However, the function responsible
for generating vpcCs currently returns invalid boxes, that are lacking
the Version and Flag fields, inherited from FullBox. For some reason,
both flags were being added manually in movenc. This patch fixes the
issue.

Signed-off-by: Alessandro Ros 
---
  libavformat/movenc.c | 3 ---
  libavformat/vpcc.c   | 2 ++
  2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7ef6cef46a..696ae5a6c9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1441,10 +1441,7 @@ static int mov_write_vpcc_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra

   avio_wb32(pb, 0);
  ffio_wfourcc(pb, "vpcC");
-    avio_w8(pb, 1); /* version */
-    avio_wb24(pb, 0); /* flags */
  ff_isom_write_vpcc(s, pb, track->vos_data, track->vos_len, 
track->par);

-
  return update_size(pb, pos);
  }

diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
index ea66959abf..256407dd6d 100644
--- a/libavformat/vpcc.c
+++ b/libavformat/vpcc.c
@@ -208,6 +208,8 @@ int ff_isom_write_vpcc(AVFormatContext *s, 
AVIOContext *pb,

  if (ret < 0)
  return ret;

+    avio_w8(pb, 1); /* version */
+    avio_wb24(pb, 0); /* flags */
  avio_w8(pb, vpcc.profile);
  avio_w8(pb, vpcc.level);
  avio_w8(pb, (vpcc.bitdepth << 4) | (vpcc.chroma_subsampling << 1) 
| vpcc.full_range_flag);


This will change the output of the flv muxer. It might be for the 
better, since now both these values will be added to it, but it would be 
best to know that first.

___
ffmpeg-devel mailing list
ffmpeg-devel@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/vpcc: fix vpcC generation for RTMP

2023-09-02 Thread Alessandro Ros

In order to send VP9 tracks with RTMP, the enhanced RTMP specification
tells that VPCodecConfigurationRecord, a.k.a. vpcC ISO-BMFF box, must
be inserted into a metadata message. However, the function responsible
for generating vpcCs currently returns invalid boxes, that are lacking
the Version and Flag fields, inherited from FullBox. For some reason,
both flags were being added manually in movenc. This patch fixes the
issue.

Signed-off-by: Alessandro Ros 
---
 libavformat/movenc.c | 3 ---
 libavformat/vpcc.c   | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7ef6cef46a..696ae5a6c9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1441,10 +1441,7 @@ static int mov_write_vpcc_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra

  avio_wb32(pb, 0);
 ffio_wfourcc(pb, "vpcC");
-avio_w8(pb, 1); /* version */
-avio_wb24(pb, 0); /* flags */
 ff_isom_write_vpcc(s, pb, track->vos_data, track->vos_len, 
track->par);

-
 return update_size(pb, pos);
 }

diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
index ea66959abf..256407dd6d 100644
--- a/libavformat/vpcc.c
+++ b/libavformat/vpcc.c
@@ -208,6 +208,8 @@ int ff_isom_write_vpcc(AVFormatContext *s, 
AVIOContext *pb,

 if (ret < 0)
 return ret;

+avio_w8(pb, 1); /* version */
+avio_wb24(pb, 0); /* flags */
 avio_w8(pb, vpcc.profile);
 avio_w8(pb, vpcc.level);
 avio_w8(pb, (vpcc.bitdepth << 4) | (vpcc.chroma_subsampling << 1) 
| vpcc.full_range_flag);

--
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] avformat/vpcc: fix vpcC generation for RTMP

2023-09-02 Thread Alessandro Ros

In order to send VP9 tracks with RTMP, the enhanced RTMP specification
tells that VPCodecConfigurationRecord, a.k.a. vpcC ISO-BMFF box, must
be inserted into a metadata message. However, the function responsible
for generating vpcCs currently returns invalid boxes, that are lacking
the Version and Flag fields, inherited from FullBox. For some reason,
both flags were being added manually in movenc. This patch fixes the
issue.

Signed-off-by: Alessandro Ros 
---
 libavformat/movenc.c | 3 ---
 libavformat/vpcc.c   | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7ef6cef46a..696ae5a6c9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1441,10 +1441,7 @@ static int mov_write_vpcc_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra

  avio_wb32(pb, 0);
 ffio_wfourcc(pb, "vpcC");
-avio_w8(pb, 1); /* version */
-avio_wb24(pb, 0); /* flags */
 ff_isom_write_vpcc(s, pb, track->vos_data, track->vos_len, 
track->par);

-
 return update_size(pb, pos);
 }

diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
index ea66959abf..256407dd6d 100644
--- a/libavformat/vpcc.c
+++ b/libavformat/vpcc.c
@@ -208,6 +208,8 @@ int ff_isom_write_vpcc(AVFormatContext *s, 
AVIOContext *pb,

 if (ret < 0)
 return ret;

+avio_w8(pb, 1); /* version */
+avio_wb24(pb, 0); /* flags */
 avio_w8(pb, vpcc.profile);
 avio_w8(pb, vpcc.level);
 avio_w8(pb, (vpcc.bitdepth << 4) | (vpcc.chroma_subsampling << 1) 
| vpcc.full_range_flag);

--
2.34.1

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

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


[FFmpeg-devel] [PATCH 7/7] avutil/avstring: Remove obsolete version.h inclusion

2023-09-02 Thread Andreas Rheinhardt
Forgotten in 30e1e7e0f324d7bf66b3b8583a3e49fd3cd101b2.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/avstring.c  | 1 -
 libavutil/avstring.h  | 1 -
 libavutil/spherical.c | 1 +
 3 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index e460b5be7f..8751ce5576 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -32,7 +32,6 @@
 #include "bprint.h"
 #include "error.h"
 #include "macros.h"
-#include "version.h"
 
 int av_strstart(const char *str, const char *pfx, const char **ptr)
 {
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index e260263763..fd2a7ab391 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include "attributes.h"
-#include "version.h"
 
 /**
  * @addtogroup lavu_string
diff --git a/libavutil/spherical.c b/libavutil/spherical.c
index ed66344a2f..800d3459a5 100644
--- a/libavutil/spherical.c
+++ b/libavutil/spherical.c
@@ -19,6 +19,7 @@
  */
 
 #include "avstring.h"
+#include "macros.h"
 #include "mem.h"
 #include "spherical.h"
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 6/7] avutil/mem: Don't include avutil.h

2023-09-02 Thread Andreas Rheinhardt
It is not necessary at all. So remove it.
This also breaks an inclusion cycle mem.h->avutil.h->common.h->mem.h.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/avfft.c | 7 ---
 libavcodec/avpacket.c  | 1 +
 libavcodec/dirac_dwt.c | 1 +
 libavcodec/ffjni.c | 1 +
 libavcodec/iirfilter.c | 4 
 libavcodec/jpegls.c| 1 +
 libavcodec/kbdwin.c| 2 ++
 libavcodec/mpc.c   | 2 +-
 libavcodec/tests/h264_levels.c | 6 +-
 libavformat/protocols.c| 2 ++
 libavutil/dict.c   | 4 +++-
 libavutil/encryption_info.c| 2 ++
 libavutil/fifo.c   | 1 +
 libavutil/file.c   | 1 +
 libavutil/hash.c   | 2 ++
 libavutil/hmac.c   | 1 +
 libavutil/md5.c| 2 ++
 libavutil/mem.h| 4 +---
 libavutil/murmur3.c| 1 +
 libavutil/tests/lzo.c  | 2 ++
 libavutil/tests/murmur3.c  | 3 +++
 libavutil/tests/pixdesc.c  | 1 +
 libavutil/threadmessage.c  | 3 +++
 libavutil/timestamp.h  | 2 +-
 libavutil/tx_priv.h| 1 +
 tools/ffeval.c | 4 
 tools/zmqsend.c| 3 +++
 27 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index d07c495022..fb635abfff 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -16,13 +16,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+#include 
+
 #include "libavutil/attributes.h"
+#include "libavutil/macros.h"
 #include "libavutil/mem.h"
 #include "libavutil/tx.h"
 #include "avfft.h"
-#include "fft.h"
-#include "rdft.h"
-#include "dct.h"
 
 typedef struct AVTXWrapper {
 AVTXContext *ctx;
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 5fef65e97a..9ec1feb068 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -22,6 +22,7 @@
 #include 
 
 #include "libavutil/avassert.h"
+#include "libavutil/avutil.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
diff --git a/libavcodec/dirac_dwt.c b/libavcodec/dirac_dwt.c
index 4039899cf0..d473f64daa 100644
--- a/libavcodec/dirac_dwt.c
+++ b/libavcodec/dirac_dwt.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
+#include "libavutil/log.h"
 #include "dirac_dwt.h"
 
 #define TEMPLATE_8bit
diff --git a/libavcodec/ffjni.c b/libavcodec/ffjni.c
index 154be9ae99..e3cf24d3e2 100644
--- a/libavcodec/ffjni.c
+++ b/libavcodec/ffjni.c
@@ -25,6 +25,7 @@
 #include 
 
 #include "libavutil/bprint.h"
+#include "libavutil/error.h"
 #include "libavutil/log.h"
 #include "libavutil/mem.h"
 
diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index 903d64e8d4..727a370444 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -26,8 +26,12 @@
 
 #include 
 
+#include "config.h"
+
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
 
 #include "iirfilter.h"
 
diff --git a/libavcodec/jpegls.c b/libavcodec/jpegls.c
index cc598f3c17..7b4bc30e46 100644
--- a/libavcodec/jpegls.c
+++ b/libavcodec/jpegls.c
@@ -28,6 +28,7 @@
 #include 
 #include "libavutil/internal.h"
 #include "libavutil/intmath.h"
+#include "libavutil/log.h"
 #include "jpegls.h"
 
 void ff_jpegls_init_state(JLSState *state)
diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index eacdb46774..ff7a7d614e 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -17,6 +17,8 @@
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/error.h"
+#include "libavutil/libm.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/attributes.h"
 #include "libavutil/mem.h"
diff --git a/libavcodec/mpc.c b/libavcodec/mpc.c
index 6aa3e80927..46cb967cf1 100644
--- a/libavcodec/mpc.c
+++ b/libavcodec/mpc.c
@@ -27,7 +27,7 @@
  */
 
 #include 
-#include "libavutil/intmath.h"
+#include "libavutil/common.h"
 #include "mpegaudiodsp.h"
 
 #include "mpc.h"
diff --git a/libavcodec/tests/h264_levels.c b/libavcodec/tests/h264_levels.c
index 98febcc41b..af3bfe01a6 100644
--- a/libavcodec/tests/h264_levels.c
+++ b/libavcodec/tests/h264_levels.c
@@ -16,7 +16,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/common.h"
+#include 
+#include 
+
+#include "libavutil/log.h"
+#include "libavutil/macros.h"
 #include "libavcodec/h264_levels.h"
 
 static const struct {
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 9491dc7d00..360018b17c 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "libavutil/avstring.h"
 #include "libavutil/log.h"
 #include "libavutil/mem.h"
diff --git a/libavutil/dict.c b/libavutil/dict.c
index f673977a98..7f23d5336a 100644

[FFmpeg-devel] [PATCH 5/7] avutil: Move error.h from avutil.h to common.h

2023-09-02 Thread Andreas Rheinhardt
Up until now, avutil.h includes common.h which includes mem.h which
includes avutil.h, so that all these headers are in fact equivalent.
Yet mem.h does not need to include avutil.h at all and when it no longer
does, including common.h will no longer include error.h (included by
avutil.h) as well; change this by moving error.h to avutil.h, as error.h
is clearly a commonly used header.

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/avutil.h | 1 -
 libavutil/common.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 64b68bdbd3..30bec192f1 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -294,7 +294,6 @@ char av_get_picture_type_char(enum AVPictureType pict_type);
  */
 
 #include "common.h"
-#include "error.h"
 #include "rational.h"
 #include "version.h"
 #include "macros.h"
diff --git a/libavutil/common.h b/libavutil/common.h
index fd1404be6c..de2140a678 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -40,6 +40,7 @@
 #include 
 
 #include "attributes.h"
+#include "error.h"
 #include "macros.h"
 
 //rounded division & shift
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 4/7] avformat/aviobuf: Add ffio_init_(read|write)_context()

2023-09-02 Thread Andreas Rheinhardt
Most users of ffio_init_context() simply want to wrap
a buffer into an AVIOContext; they do not provide
function pointers at all.

Therefore this commit adds shortcuts for these two common
operations. This also allows to accept const data when reading
(i.e. the const is now cast away at a central place in
ffio_init_read_context() instead of at several callers).
This also allows to constify the data in ff_text_init_buf().

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/aacdec.c|  2 +-
 libavformat/asfenc.c|  6 ++
 libavformat/av1.c   |  2 +-
 libavformat/av1dec.c|  3 +--
 libavformat/avio_internal.h |  9 +
 libavformat/aviobuf.c   | 10 ++
 libavformat/hls.c   |  2 +-
 libavformat/id3v2.c |  5 ++---
 libavformat/matroskadec.c   | 12 +---
 libavformat/mmst.c  |  4 ++--
 libavformat/mov.c   |  2 +-
 libavformat/mpegts.c| 18 +++---
 libavformat/mpjpegdec.c |  2 +-
 libavformat/oggenc.c|  2 +-
 libavformat/rdt.c   |  5 ++---
 libavformat/rtpdec_asf.c|  2 +-
 libavformat/rtpdec_qt.c |  2 +-
 libavformat/rtsp.c  |  2 +-
 libavformat/sapdec.c|  3 +--
 libavformat/subtitles.c |  4 ++--
 libavformat/subtitles.h |  2 +-
 libavformat/vividas.c   | 10 ++
 22 files changed, 59 insertions(+), 50 deletions(-)

diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index a476640904..41c9a36239 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -146,7 +146,7 @@ static int handle_id3(AVFormatContext *s, AVPacket *pkt)
 return ret;
 }
 
-ffio_init_context(, pkt->data, pkt->size, 0, NULL, NULL, NULL, NULL);
+ffio_init_read_context(, pkt->data, pkt->size);
 ff_id3v2_read_dict(, , ID3v2_DEFAULT_MAGIC, 
_extra_meta);
 if ((ret = ff_id3v2_parse_priv_dict(, id3v2_extra_meta)) < 0)
 goto error;
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 244c7e7a27..2f2d9b1bab 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -773,8 +773,7 @@ static int asf_write_header(AVFormatContext *s)
 asf->packet_nb_payloads = 0;
 asf->packet_timestamp_start = -1;
 asf->packet_timestamp_end   = -1;
-ffio_init_context(>pb, asf->packet_buf, s->packet_size, 1,
-  NULL, NULL, NULL, NULL);
+ffio_init_write_context(>pb, asf->packet_buf, s->packet_size);
 
 if (s->avoid_negative_ts < 0)
 s->avoid_negative_ts = 1;
@@ -866,8 +865,7 @@ static void flush_packet(AVFormatContext *s)
 asf->packet_nb_payloads = 0;
 asf->packet_timestamp_start = -1;
 asf->packet_timestamp_end   = -1;
-ffio_init_context(>pb, asf->packet_buf, s->packet_size, 1,
-  NULL, NULL, NULL, NULL);
+ffio_init_write_context(>pb, asf->packet_buf, s->packet_size);
 }
 
 static void put_payload_header(AVFormatContext *s, ASFStream *stream,
diff --git a/libavformat/av1.c b/libavformat/av1.c
index 4455ec0504..cb86e66d09 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -107,7 +107,7 @@ int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out,
 if (!buf)
 return AVERROR(ENOMEM);
 
-ffio_init_context(, buf, len, 1, NULL, NULL, NULL, NULL);
+ffio_init_write_context(, buf, len);
 
 ret = av1_filter_obus(, in, *size, NULL);
 av_assert1(ret == len);
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 2883b320a1..8a06445958 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -167,8 +167,7 @@ static int annexb_probe(const AVProbeData *p)
 int seq = 0;
 int ret, type, cnt = 0;
 
-ffio_init_context(, p->buf, p->buf_size, 0,
-  NULL, NULL, NULL, NULL);
+ffio_init_read_context(, p->buf, p->buf_size);
 
 ret = leb(pb, _unit_size, 1);
 if (ret < 0)
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 1f5e3d474b..57796ade03 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -93,6 +93,15 @@ void ffio_init_context(FFIOContext *s,
   int (*write_packet)(void *opaque, uint8_t *buf, int 
buf_size),
   int64_t (*seek)(void *opaque, int64_t offset, int whence));
 
+/**
+ * Wrap a buffer in an AVIOContext for reading.
+ */
+void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int 
buffer_size);
+
+/**
+ * Wrap a buffer in an AVIOContext for writing.
+ */
+void ffio_init_write_context(FFIOContext *s, uint8_t *buffer, int buffer_size);
 
 /**
  * Read size bytes from AVIOContext, returning a pointer.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 4ad734a3c3..029a9e966b 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -127,6 +127,16 @@ void ffio_init_context(FFIOContext *ctx,
 ctx->short_seek_get  = NULL;
 }
 
+void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int 
buffer_size)
+{
+ffio_init_context(s, (unsigned 

[FFmpeg-devel] [PATCH 3/7] avformat/mux: Only write HEADER marker if format has .write_header

2023-09-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/mux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index fff8094341..0cf9ebfc19 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -464,9 +464,9 @@ int avformat_write_header(AVFormatContext *s, AVDictionary 
**options)
 if ((ret = avformat_init_output(s, options)) < 0)
 return ret;
 
-if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
-avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
 if (ffofmt(s->oformat)->write_header) {
+if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
+avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
 ret = ffofmt(s->oformat)->write_header(s);
 if (ret >= 0 && s->pb && s->pb->error < 0)
 ret = s->pb->error;
-- 
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 v3 14/14] vvcdec: add full vvc decoder

2023-09-02 Thread Nuo Mi
On Sun, Sep 3, 2023 at 12:08 AM Nuo Mi  wrote:

> vvc decoder plug-in to avcodec.
> split frames into slices/tiles and send them to vvc_thread for further
> decoding
> reorder and wait for the frame decoding to be done and output the frame
>
> Features:
> + Support I, P, B frames
> + Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range
> extension
> + Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF,
> LMCS, ALF
> + 295 conformace clips passed
> - Not support RPR, IBC, PALETTE, and other minor features yet
>
> Performance:
> C code FPS on i7-12700 (x86):
> BQTerrace_1920x1080_60_10_420_22_RA.vvc 77.7
> Chimera_8bit_1080P_1000_frames.vvc  174.3
> NovosobornayaSquare_1920x1080.bin   163.7
> RitualDance_1920x1080_60_10_420_32_LD.266   136.7
> RitualDance_1920x1080_60_10_420_37_RA.266   154.3
> Tango2_3840x2160_60_10_420_27_LD.26630.0
> Tango2_3840x2160_60_10_420_27_RA.26629.0
>
> C code FPS on M1 Mac Pro (ARM):
> BQTerrace_1920x1080_60_10_420_22_RA.vvc 58.7
> Chimera_8bit_1080P_1000_frames.vvc  153.3
> NovosobornayaSquare_1920x1080.bin   150.3
> RitualDance_1920x1080_60_10_420_32_LD.266   105.0
> RitualDance_1920x1080_60_10_420_37_RA.266   133.0
> Tango2_3840x2160_60_10_420_27_LD.26621.7
>
> Asm optimizations still working in progress. please check
> https://github.com/ffvvc/FFmpeg/wiki#performance-data for the latest
>
> Contributors(based on code merge order):
> Nuo Mi 
> Xu Mu 
> frankplow 
> Shaun Loo 
>

Major changes since v2:
*  Use CBS as the parameter set parser.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v4 10/13] ffmpeg: pass first video AVFrame's side data to encoder

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

This enables further configuration of output based on the results
of input decoding and filtering in a similar manner as the color
information.
---
  fftools/ffmpeg_enc.c | 13 +
  1 file changed, 13 insertions(+)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f28884e50c..0d022700cf 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -356,6 +356,19 @@ int enc_open(OutputStream *ost, AVFrame *frame)
  enc_ctx->colorspace = frame->colorspace;
  enc_ctx->chroma_sample_location = frame->chroma_location;
  
+ret = av_frame_side_data_set_extend(

+_ctx->frame_sd_set,
+(const AVFrameSideDataSet){
+.sd= frame->side_data,
+.nb_sd = frame->nb_side_data
+},
+AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES);
+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: 
%s!\n",
+   av_err2str(ret));
+return ret;
+}


Following what i suggested in my last email, this would instead be a 
loop adding all the frame->side_data entries.



+
  // Field order: autodetection
  if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | 
AV_CODEC_FLAG_INTERLACED_ME) &&
  ost->top_field_first >= 0)

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

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


[FFmpeg-devel] [PATCH v3 14/14] vvcdec: add full vvc decoder

2023-09-02 Thread Nuo Mi
vvc decoder plug-in to avcodec.
split frames into slices/tiles and send them to vvc_thread for further decoding
reorder and wait for the frame decoding to be done and output the frame

Features:
+ Support I, P, B frames
+ Support 8/10/12 bits, chroma 400, 420, 422, and 444 and range extension
+ Support VVC new tools like MIP, CCLM, AFFINE, GPM, DMVR, PROF, BDOF, 
LMCS, ALF
+ 295 conformace clips passed
- Not support RPR, IBC, PALETTE, and other minor features yet

Performance:
C code FPS on i7-12700 (x86):
BQTerrace_1920x1080_60_10_420_22_RA.vvc 77.7
Chimera_8bit_1080P_1000_frames.vvc  174.3
NovosobornayaSquare_1920x1080.bin   163.7
RitualDance_1920x1080_60_10_420_32_LD.266   136.7
RitualDance_1920x1080_60_10_420_37_RA.266   154.3
Tango2_3840x2160_60_10_420_27_LD.26630.0
Tango2_3840x2160_60_10_420_27_RA.26629.0

C code FPS on M1 Mac Pro (ARM):
BQTerrace_1920x1080_60_10_420_22_RA.vvc 58.7
Chimera_8bit_1080P_1000_frames.vvc  153.3
NovosobornayaSquare_1920x1080.bin   150.3
RitualDance_1920x1080_60_10_420_32_LD.266   105.0
RitualDance_1920x1080_60_10_420_37_RA.266   133.0
Tango2_3840x2160_60_10_420_27_LD.26621.7

Asm optimizations still working in progress. please check
https://github.com/ffvvc/FFmpeg/wiki#performance-data for the latest

Contributors(based on code merge order):
Nuo Mi 
Xu Mu 
frankplow 
Shaun Loo 
---
 libavcodec/vvc/vvcdec.c | 1025 ++-
 1 file changed, 1024 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
index 8d027af0b9..c85b7fac8c 100644
--- a/libavcodec/vvc/vvcdec.c
+++ b/libavcodec/vvc/vvcdec.c
@@ -24,32 +24,1055 @@
 
 #include "libavcodec/codec_internal.h"
 #include "libavcodec/decode.h"
-#include "libavcodec/golomb.h"
 #include "libavcodec/profiles.h"
 #include "libavcodec/vvc.h"
 
 #include "libavutil/cpu.h"
 
 #include "vvcdec.h"
+#include "vvc_ctu.h"
+#include "vvc_data.h"
+#include "vvc_refs.h"
+#include "vvc_thread.h"
+
+static int vvc_frame_start(VVCContext *s, VVCFrameContext *fc, SliceContext 
*sc)
+{
+const VVCPH *ph = >ps.ph;
+const H266RawSliceHeader *rsh   = sc->sh.r;
+int ret;
+
+// 8.3.1 Decoding process for picture order count
+if (!s->temporal_id && !ph->r->ph_non_ref_pic_flag && !(IS_RASL(s) || 
IS_RADL(s)))
+s->poc_tid0 = ph->poc;
+
+if ((ret = ff_vvc_set_new_ref(s, fc, >frame)) < 0)
+goto fail;
+
+if (!IS_IDR(s))
+ff_vvc_bump_frame(s, fc);
+
+av_frame_unref(fc->output_frame);
+
+if ((ret = ff_vvc_output_frame(s, fc, 
fc->output_frame,rsh->sh_no_output_of_prior_pics_flag, 0)) < 0)
+goto fail;
+
+if ((ret = ff_vvc_frame_rpl(s, fc, sc)) < 0)
+goto fail;
+
+if ((ret = ff_vvc_frame_thread_init(fc)) < 0)
+goto fail;
+return 0;
+fail:
+if (fc->ref)
+ff_vvc_unref_frame(fc, fc->ref, ~0);
+fc->ref = NULL;
+return ret;
+}
+
+static void ctb_arrays_free(VVCFrameContext *fc)
+{
+av_freep(>tab.deblock);
+av_freep(>tab.sao);
+av_freep(>tab.alf);
+av_freep(>tab.slice_idx);
+av_freep(>tab.coeffs);
+if (fc->tab.ctus) {
+for (int i = 0; i < fc->tab.ctu_count; i++)
+ff_vvc_ctu_free_cus(fc->tab.ctus + i);
+av_freep(>tab.ctus);
+}
+av_buffer_pool_uninit(>rpl_tab_pool);
+}
+
+static int ctb_arrays_init(VVCFrameContext *fc, const int ctu_count, const int 
ctu_size)
+{
+if (fc->tab.ctu_count != ctu_count || fc->tab.ctu_size != ctu_size) {
+ctb_arrays_free(fc);
+fc->tab.deblock = av_calloc(ctu_count, 
sizeof(*fc->tab.deblock));
+fc->tab.sao = av_calloc(ctu_count, sizeof(*fc->tab.sao));
+fc->tab.alf = av_calloc(ctu_count, sizeof(*fc->tab.alf));
+fc->tab.ctus= av_calloc(ctu_count, sizeof(*fc->tab.ctus));
+fc->tab.slice_idx   = av_malloc(ctu_count * 
sizeof(*fc->tab.slice_idx));
+if (!fc->tab.deblock || !fc->tab.sao || !fc->tab.alf || !fc->tab.ctus 
|| !fc->tab.slice_idx )
+return AVERROR(ENOMEM);
+fc->tab.coeffs = av_malloc(ctu_count * sizeof(*fc->tab.coeffs) * 
ctu_size * VVC_MAX_SAMPLE_ARRAYS);
+if (!fc->tab.coeffs)
+return AVERROR(ENOMEM);
+fc->rpl_tab_pool = av_buffer_pool_init(ctu_count * 
sizeof(RefPicListTab), av_buffer_allocz);
+if (!fc->rpl_tab_pool)
+return AVERROR(ENOMEM);
+} else {
+memset(fc->tab.deblock, 0, ctu_count * sizeof(*fc->tab.deblock));
+memset(fc->tab.sao, 0, ctu_count * sizeof(*fc->tab.sao));
+memset(fc->tab.alf, 0, ctu_count * sizeof(*fc->tab.alf));
+for (int i = 0; i < fc->tab.ctu_count; i++)
+ff_vvc_ctu_free_cus(fc->tab.ctus + i);
+memset(fc->tab.ctus, 0, 

[FFmpeg-devel] [PATCH v3 08/14] vvcdec: add inv transform 1d

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile |   3 +-
 libavcodec/vvc/vvc_itx_1d.c | 713 
 libavcodec/vvc/vvc_itx_1d.h |  52 +++
 3 files changed, 767 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_itx_1d.c
 create mode 100644 libavcodec/vvc/vvc_itx_1d.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 573964ee67..25428c0ee2 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -6,6 +6,7 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o
\
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_inter.o \
+vvc/vvc_itx_1d.o\
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
-vvc/vvc_refs.o
+vvc/vvc_refs.o
\ No newline at end of file
diff --git a/libavcodec/vvc/vvc_itx_1d.c b/libavcodec/vvc/vvc_itx_1d.c
new file mode 100644
index 00..e96919f41d
--- /dev/null
+++ b/libavcodec/vvc/vvc_itx_1d.c
@@ -0,0 +1,713 @@
+/*
+ * VVC 1D transform
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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
+ */
+
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2021, ITU/ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *this list of conditions and the following disclaimer in the documentation
+ *and/or other materials provided with the distribution.
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
+ *be used to endorse or promote products derived from this software without
+ *specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* optimizaed with partial butterfly, see Hung C-Y, Landman P (1997)
+   Compact inverse discrete cosine transform circuit for MPEG video decoding.
+ */
+
+#include "vvc_data.h"
+#include "vvc_itx_1d.h"
+#include "libavutil/avutil.h"
+
+/*
+transmatrix[2][2] = {
+{ a,  a },
+{ a, -a },
+}
+ */
+void ff_vvc_inv_dct2_2(int *out, const ptrdiff_t out_stride, const int *in, 
ptrdiff_t in_stride)
+{
+const int a = 64;
+const int x0 = in[0 * in_stride], x1 = in[1 * in_stride];
+
+out[0 * out_stride] = a * (x0 + x1);
+out[1 * out_stride] = a * (x0 - x1);
+}
+
+/*
+transmatrix[4][4] = {
+{ a,  a,  a,  a},
+{ b,  c, -c, -b},
+{ a, -a, -a,  a},
+{ c, -b,  b, -c},
+}
+ */
+void ff_vvc_inv_dct2_4(int *out, const ptrdiff_t out_stride, const int *in, 
ptrdiff_t in_stride)
+{
+const int a = 64, b = 83, c = 36;
+const int x0 = in[0 * in_stride], x1 = in[1 * in_stride];
+const int x2 = in[2 * in_stride], x3 = in[3 * in_stride];
+const int E[2] = {
+a * (x0 

[FFmpeg-devel] [PATCH v3 12/14] vvcdec: add CTU parser

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/vvc_ctu.c | 2398 +-
 libavcodec/vvc/vvc_ctu.h |   11 +
 2 files changed, 2404 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index d46a522a0d..a212d3a44a 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -22,8 +22,2379 @@
 
 #include "vvc_cabac.h"
 #include "vvc_ctu.h"
+#include "vvc_inter.h"
 #include "vvc_mvs.h"
 
+#define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
+
+#define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * 
fc->ps.pps->width32 + ((x) >> 5)]
+#define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + 
((x) >> 6)]
+
+typedef enum VVCModeType {
+MODE_TYPE_ALL,
+MODE_TYPE_INTER,
+MODE_TYPE_INTRA,
+} VVCModeType;
+
+static void set_tb_pos(const VVCFrameContext *fc, const TransformBlock *tb)
+{
+const int x_tb  = tb->x0 >> MIN_TU_LOG2;
+const int y_tb  = tb->y0 >> MIN_TU_LOG2;
+const int hs= fc->ps.sps->hshift[tb->c_idx];
+const int vs= fc->ps.sps->vshift[tb->c_idx];
+const int is_chroma = tb->c_idx != 0;
+const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
+const int end   = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
+
+for (int y = y_tb; y < end; y++) {
+const int off = y * fc->ps.pps->min_tu_width + x_tb;
+for (int i = 0; i < width; i++) {
+fc->tab.tb_pos_x0[is_chroma][off + i] = tb->x0;
+fc->tab.tb_pos_y0[is_chroma][off + i] = tb->y0;
+}
+memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width,  width);
+memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
+}
+}
+
+static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
+const TransformBlock *tb)
+{
+const int width  = tb->tb_width  << fc->ps.sps->hshift[tb->c_idx];
+const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
+
+for (int h = 0; h < height; h += MIN_TU_SIZE) {
+const int y = (tb->y0 + h) >> MIN_TU_LOG2;
+const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
+const int w = FFMAX(1, width >> MIN_TU_LOG2);
+memset(tab + off, v, w);
+}
+}
+
+// 8.7.1 Derivation process for quantization parameters
+static int get_qp_y_pred(const VVCLocalContext *lc)
+{
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps   = fc->ps.sps;
+const VVCPPS *pps   = fc->ps.pps;
+const CodingUnit *cu= lc->cu;
+const int ctb_log2_size = sps->ctb_log2_size_y;
+const int ctb_size_mask = (1 << ctb_log2_size) - 1;
+const int xQg   = lc->parse.cu_qg_top_left_x;
+const int yQg   = lc->parse.cu_qg_top_left_y;
+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;
+int qPy_pred, qPy_a, qPy_b;
+
+if (lc->na.cand_up) {
+const int first_qg_in_ctu = !(xQg & ctb_size_mask) &&  !(yQg & 
ctb_size_mask);
+const int qPy_up  = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * 
min_cb_width];
+if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg)
+return qPy_up;
+}
+
+// qPy_pred
+qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
+
+// qPy_b
+if (!lc->na.cand_up || !in_same_ctb_b)
+qPy_b = qPy_pred;
+else
+qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
+
+// qPy_a
+if (!lc->na.cand_left || !in_same_ctb_a)
+qPy_a = qPy_pred;
+else
+qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
+
+av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a < 63);
+av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b < 63);
+
+return (qPy_a + qPy_b + 1) >> 1;
+}
+
+static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t 
v)
+{
+const VVCFrameContext *fc   = lc->fc;
+const VVCPPS *pps   = fc->ps.pps;
+const CodingUnit *cu= lc->cu;
+const int log2_min_cb_size  = fc->ps.sps->min_cb_log2_size_y;
+const int x_cb  = cu->x0 >> log2_min_cb_size;
+const int y_cb  = cu->y0 >> log2_min_cb_size;
+const int cb_width  = cu->cb_width;
+const int cb_height = cu->cb_height;
+int x   = y_cb * pps->min_cb_width + x_cb;
+
+for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
+const int width = cb_width >> log2_min_cb_size;
+
+

[FFmpeg-devel] [PATCH v3 11/14] vvcdec: add dsp init and inv transform

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile  |   1 +
 libavcodec/vvc/vvcdsp.c  | 133 +++
 libavcodec/vvc/vvcdsp_template.c | 120 
 3 files changed, 254 insertions(+)
 create mode 100644 libavcodec/vvc/vvcdsp.c
 create mode 100644 libavcodec/vvc/vvcdsp_template.c

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 2559de9429..c2b67ddfc8 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -2,6 +2,7 @@ clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o\
+vvc/vvcdsp.o\
 vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c
new file mode 100644
index 00..e00f05c174
--- /dev/null
+++ b/libavcodec/vvc/vvcdsp.c
@@ -0,0 +1,133 @@
+/*
+ * VVC DSP
+ *
+ * Copyright (C) 2021 Nuo Mi
+ *
+ * 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 "vvcdsp.h"
+#include "vvc_ctu.h"
+#include "vvc_itx_1d.h"
+
+#define VVC_SIGN(v) (v < 0 ? -1 : !!v)
+
+static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t 
dst_stride, const int width, const int height)
+{
+const int padded_width = width + 2;
+int16_t *dst;
+for (int y = 0; y < height; y++) {
+dst = _dst + y * dst_stride;
+for (int x = 0; x < width; x++) {
+dst[-1] = dst[0];
+dst[width] = dst[width - 1];
+}
+}
+
+_dst--;
+//top
+memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t));
+//bottom
+_dst += dst_stride * height;
+memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t));
+}
+
+static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy,
+const int block_w, const int block_h)
+{
+int sad = 0;
+dx -= 2;
+dy -= 2;
+src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx;
+src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx;
+for (int y = 0; y < block_h; y += 2) {
+for (int x = 0; x < block_w; x++) {
+sad += FFABS(src0[x] - src1[x]);
+}
+src0 += 2 * MAX_PB_SIZE;
+src1 += 2 * MAX_PB_SIZE;
+}
+return sad;
+}
+
+#define itx_fn(type, s)
 \
+static void itx_##type##_##s(int *out, ptrdiff_t out_step, const int *in, 
ptrdiff_t in_step)\
+{  
 \
+  ff_vvc_inv_##type##_##s(out, out_step, in, in_step); 
 \
+}
+
+#define itx_fn_common(type) \
+itx_fn(type, 4);\
+itx_fn(type, 8);\
+itx_fn(type, 16);   \
+itx_fn(type, 32);   \
+
+itx_fn_common(dct2);
+itx_fn_common(dst7);
+itx_fn_common(dct8);
+itx_fn(dct2, 2);
+itx_fn(dct2, 64);
+
+typedef struct IntraEdgeParams {
+uint8_t* top;
+uint8_t* left;
+int filter_flag;
+
+uint16_t left_array[3 * MAX_TB_SIZE + 3];
+uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3];
+uint16_t top_array[3 * MAX_TB_SIZE + 3];
+uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3];
+} IntraEdgeParams;
+
+#define BIT_DEPTH 8
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+#define BIT_DEPTH 10
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+#define BIT_DEPTH 12
+#include "vvcdsp_template.c"
+#undef BIT_DEPTH
+
+void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
+{
+#undef FUNC
+#define FUNC(a, depth) a ## _ ## depth
+
+#define VVC_DSP(depth) 
 \
+FUNC(ff_vvc_inter_dsp_init, depth)(>inter);
 \
+FUNC(ff_vvc_intra_dsp_init, depth)(>intra);
 \
+FUNC(ff_vvc_itx_dsp_init, depth)(>itx);
 \
+FUNC(ff_vvc_lmcs_dsp_init, depth)(>lmcs);  
 \
+FUNC(ff_vvc_lf_dsp_init, depth)(>lf);  
 \
+FUNC(ff_vvc_sao_dsp_init, depth)(>sao);
 \
+

[FFmpeg-devel] [PATCH v3 09/14] vvcdec: add intra prediction

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile |3 +-
 libavcodec/vvc/vvc_ctu.c|   39 +
 libavcodec/vvc/vvc_ctu.h|2 +
 libavcodec/vvc/vvc_intra.c  |  768 
 libavcodec/vvc/vvc_intra.h  |   49 ++
 libavcodec/vvc/vvc_intra_template.c | 1015 +++
 6 files changed, 1875 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_intra.c
 create mode 100644 libavcodec/vvc/vvc_intra.h
 create mode 100644 libavcodec/vvc/vvc_intra_template.c

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 25428c0ee2..15312fd236 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -6,7 +6,8 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o
\
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_inter.o \
+vvc/vvc_intra.o \
 vvc/vvc_itx_1d.o\
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
-vvc/vvc_refs.o
\ No newline at end of file
+vvc/vvc_refs.o
diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index cfe26756fe..d46a522a0d 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -24,6 +24,35 @@
 #include "vvc_ctu.h"
 #include "vvc_mvs.h"
 
+void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int 
y_ctb,
+const int rx, const int ry, const int rs)
+{
+VVCFrameContext *fc = lc->fc;
+const int ctb_size = fc->ps.sps->ctb_size_y;
+
+lc->end_of_tiles_x = fc->ps.sps->width;
+lc->end_of_tiles_y = fc->ps.sps->height;
+if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
+lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
+if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
+lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
+
+lc->boundary_flags = 0;
+if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != 
fc->ps.pps->ctb_to_col_bd[rx - 1])
+lc->boundary_flags |= BOUNDARY_LEFT_TILE;
+if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
+lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
+if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != 
fc->ps.pps->ctb_to_row_bd[ry - 1])
+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;
+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]) &&
+(fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
+lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
+}
+
 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
 const int x0, const int y0, const int w, const int h)
 {
@@ -39,6 +68,16 @@ void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < 
lc->end_of_tiles_x;
 }
 
+void ff_vvc_ctu_free_cus(CTU *ctu)
+{
+while (ctu->cus) {
+CodingUnit *cu  = ctu->cus;
+AVBufferRef *buf= cu->buf;
+
+ctu->cus = ctu->cus->next;
+av_buffer_unref();
+}
+}
 
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
diff --git a/libavcodec/vvc/vvc_ctu.h b/libavcodec/vvc/vvc_ctu.h
index 36d2b1325a..e912d25b62 100644
--- a/libavcodec/vvc/vvc_ctu.h
+++ b/libavcodec/vvc/vvc_ctu.h
@@ -404,5 +404,7 @@ struct ALFParams {
 
 //utils
 void ff_vvc_set_neighbour_available(VVCLocalContext *lc, int x0, int y0, int 
w, int h);
+void ff_vvc_decode_neighbour(VVCLocalContext *lc, int x_ctb, int y_ctb, int 
rx, int ry, int rs);
+void ff_vvc_ctu_free_cus(CTU *ctu);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int 
persistent_rice_adaptation_enabled_flag);
 #endif // AVCODEC_VVC_CTU_H
diff --git a/libavcodec/vvc/vvc_intra.c b/libavcodec/vvc/vvc_intra.c
new file mode 100644
index 00..7af2af439b
--- /dev/null
+++ b/libavcodec/vvc/vvc_intra.c
@@ -0,0 +1,768 @@
+/*
+ * VVC intra prediction
+ *
+ * Copyright (C) 2021 Nuo Mi
+ *
+ * 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 

[FFmpeg-devel] [PATCH v3 07/14] vvcdec: add inter prediction

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile |1 +
 libavcodec/vvc/vvc_inter.c  |  973 +
 libavcodec/vvc/vvc_inter.h  |   42 ++
 libavcodec/vvc/vvc_inter_template.c | 1034 +++
 libavcodec/vvc/vvcdec.h |2 +
 libavcodec/vvc/vvcdsp.h |  171 +
 6 files changed, 2223 insertions(+)
 create mode 100644 libavcodec/vvc/vvc_inter.c
 create mode 100644 libavcodec/vvc/vvc_inter.h
 create mode 100644 libavcodec/vvc/vvc_inter_template.c
 create mode 100644 libavcodec/vvc/vvcdsp.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index ede66c110e..573964ee67 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,6 +5,7 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o
\
 vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
+vvc/vvc_inter.o \
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
new file mode 100644
index 00..af181dfe11
--- /dev/null
+++ b/libavcodec/vvc/vvc_inter.c
@@ -0,0 +1,973 @@
+/*
+ * VVC inter prediction
+ *
+ * Copyright (C) 2022 Nuo Mi
+ *
+ * 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 "vvc_data.h"
+#include "vvc_inter.h"
+#include "vvc_mvs.h"
+#include "vvc_refs.h"
+
+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)
+{
+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]);
+
+if (x_off < extra_before || y_off < extra_before ||
+x_off >= pic_width - block_w - extra_after ||
+y_off >= pic_height - block_h - extra_after) {
+const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << 
fc->ps.sps->pixel_shift;
+int offset = extra_before * *src_stride  + (extra_before << 
fc->ps.sps->pixel_shift);
+int buf_offset = extra_before * edge_emu_stride + (extra_before << 
fc->ps.sps->pixel_shift);
+
+fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, 
*src_stride,
+block_w + extra, block_h + extra, x_off - extra_before, y_off - 
extra_before,
+pic_width, pic_height);
+
+*src = dst + buf_offset;
+*src_stride = edge_emu_stride;
+return 1;
+}
+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)
+{
+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]);
+
+if (x_off < extra_before || y_off < extra_before ||
+x_off >= pic_width - block_w - extra_after ||
+y_off >= pic_height - block_h - extra_after||
+(x_off != x_sb || y_off !=  y_sb)) {
+const int ps= fc->ps.sps->pixel_shift;
+const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps;
+const int offset  

[FFmpeg-devel] [PATCH v3 06/14] vvcdec: add motion vector decoder

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile  |1 +
 libavcodec/vvc/vvc_ctu.c |   20 +-
 libavcodec/vvc/vvc_ctu.h |2 +
 libavcodec/vvc/vvc_mvs.c | 1806 ++
 libavcodec/vvc/vvc_mvs.h |   46 +
 5 files changed, 1874 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_mvs.c
 create mode 100644 libavcodec/vvc/vvc_mvs.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 6eb181784b..ede66c110e 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,5 +5,6 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o
\
 vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
+vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
 vvc/vvc_refs.o
diff --git a/libavcodec/vvc/vvc_ctu.c b/libavcodec/vvc/vvc_ctu.c
index 78b13ffb00..cfe26756fe 100644
--- a/libavcodec/vvc/vvc_ctu.c
+++ b/libavcodec/vvc/vvc_ctu.c
@@ -20,7 +20,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "vvc_cabac.h"
 #include "vvc_ctu.h"
+#include "vvc_mvs.h"
+
+void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
+const int x0, const int y0, const int w, const int h)
+{
+const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
+const int x0b = av_mod_uintp2(x0, log2_ctb_size);
+const int y0b = av_mod_uintp2(y0, log2_ctb_size);
+
+lc->na.cand_up   = (lc->ctb_up_flag   || y0b);
+lc->na.cand_left = (lc->ctb_left_flag || x0b);
+lc->na.cand_up_left  = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : 
lc->ctb_up_left_flag;
+lc->na.cand_up_right_sap =
+(x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : 
lc->na.cand_up;
+lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < 
lc->end_of_tiles_x;
+}
+
 
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
@@ -29,4 +47,4 @@ void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
 ep->stat_coeff[i] =
 persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 
10)) : 0;
 }
-}
+}
\ No newline at end of file
diff --git a/libavcodec/vvc/vvc_ctu.h b/libavcodec/vvc/vvc_ctu.h
index 7acb361e21..36d2b1325a 100644
--- a/libavcodec/vvc/vvc_ctu.h
+++ b/libavcodec/vvc/vvc_ctu.h
@@ -402,5 +402,7 @@ struct ALFParams {
 uint8_t applied[3];
 };
 
+//utils
+void ff_vvc_set_neighbour_available(VVCLocalContext *lc, int x0, int y0, int 
w, int h);
 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, int bit_depth, int 
persistent_rice_adaptation_enabled_flag);
 #endif // AVCODEC_VVC_CTU_H
diff --git a/libavcodec/vvc/vvc_mvs.c b/libavcodec/vvc/vvc_mvs.c
new file mode 100644
index 00..e3ab4e4571
--- /dev/null
+++ b/libavcodec/vvc/vvc_mvs.c
@@ -0,0 +1,1806 @@
+/*
+ * VVC motion vector decoder
+ *
+ * Copyright (C) 2023 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ * 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 "vvc_ctu.h"
+#include "vvc_data.h"
+#include "vvc_refs.h"
+#include "vvc_mvs.h"
+
+#define IS_SAME_MV(a, b) (AV_RN64A(a) == AV_RN64A(b))
+
+//check if the two luma locations belong to the same motion estimation region
+static av_always_inline int is_same_mer(const VVCFrameContext *fc, const int 
xN, const int yN, const int xP, const int yP)
+{
+const uint8_t plevel = fc->ps.sps->log2_parallel_merge_level;
+
+return xN >> plevel == xP >> plevel &&
+   yN >> plevel == yP >> plevel;
+}
+
+//return true if we have same mvs and ref_idxs
+static av_always_inline int compare_mv_ref_idx(const MvField *n, const MvField 
*o)
+{
+if (!o || n->pred_flag != o->pred_flag)
+return 0;
+for (int i = 0; i < 2; i++) {
+PredFlag mask = i + 1;
+if (n->pred_flag & mask) {
+const int same_ref_idx = n->ref_idx[i] == o->ref_idx[i];
+const int same_mv = IS_SAME_MV(n->mv + i, o->mv + i);
+if (!same_ref_idx || !same_mv)
+return 0;
+}
+}
+

[FFmpeg-devel] [PATCH v3 04/14] vvcdec: add cabac decoder

2023-09-02 Thread Nuo Mi
add Context-based Adaptive Binary Arithmetic Coding (CABAC) decoder
---
 libavcodec/vvc/Makefile|2 +
 libavcodec/vvc/vvc_cabac.c | 2484 
 libavcodec/vvc/vvc_cabac.h |  126 ++
 libavcodec/vvc/vvc_ctu.c   |   32 +
 libavcodec/vvc/vvc_ctu.h   |  406 ++
 libavcodec/vvc/vvcdec.h|7 +-
 6 files changed, 3055 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/vvc/vvc_cabac.c
 create mode 100644 libavcodec/vvc/vvc_cabac.h
 create mode 100644 libavcodec/vvc/vvc_ctu.c
 create mode 100644 libavcodec/vvc/vvc_ctu.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 3ea430f61a..64c9ea9688 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -2,5 +2,7 @@ clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o\
+vvc/vvc_cabac.o \
+vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
 vvc/vvc_ps.o
diff --git a/libavcodec/vvc/vvc_cabac.c b/libavcodec/vvc/vvc_cabac.c
new file mode 100644
index 00..7275f44c4d
--- /dev/null
+++ b/libavcodec/vvc/vvc_cabac.c
@@ -0,0 +1,2484 @@
+/*
+ * VVC CABAC decoder
+ *
+ * Copyright (C) 2021 Nuo Mi
+ *
+ * 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/cabac_functions.h"
+
+#include "vvc_cabac.h"
+#include "vvc_ctu.h"
+#include "vvc_data.h"
+
+#define CABAC_MAX_BIN 31
+
+#define CNU 35
+
+enum SyntaxElement {
+ALF_CTB_FLAG= 0,
+ALF_USE_APS_FLAG= ALF_CTB_FLAG  + 9,
+ALF_CTB_CC_CB_IDC,
+ALF_CTB_CC_CR_IDC   = ALF_CTB_CC_CB_IDC + 3,
+ALF_CTB_FILTER_ALT_IDX  = ALF_CTB_CC_CR_IDC + 3,
+SAO_MERGE_FLAG  = ALF_CTB_FILTER_ALT_IDX+ 2,
+SAO_TYPE_IDX,
+SPLIT_CU_FLAG,
+SPLIT_QT_FLAG   = SPLIT_CU_FLAG + 9,
+MTT_SPLIT_CU_VERTICAL_FLAG  = SPLIT_QT_FLAG + 6,
+MTT_SPLIT_CU_BINARY_FLAG= MTT_SPLIT_CU_VERTICAL_FLAG+ 5,
+NON_INTER_FLAG  = MTT_SPLIT_CU_BINARY_FLAG  + 4,
+CU_SKIP_FLAG= NON_INTER_FLAG+ 2,
+PRED_MODE_IBC_FLAG  = CU_SKIP_FLAG  + 3,
+PRED_MODE_FLAG  = PRED_MODE_IBC_FLAG+ 3,
+PRED_MODE_PLT_FLAG  = PRED_MODE_FLAG+ 2,
+CU_ACT_ENABLED_FLAG,
+INTRA_BDPCM_LUMA_FLAG,
+INTRA_BDPCM_LUMA_DIR_FLAG,
+INTRA_MIP_FLAG,
+INTRA_LUMA_REF_IDX  = INTRA_MIP_FLAG+ 4,
+INTRA_SUBPARTITIONS_MODE_FLAG   = INTRA_LUMA_REF_IDX+ 2,
+INTRA_SUBPARTITIONS_SPLIT_FLAG,
+INTRA_LUMA_MPM_FLAG,
+INTRA_LUMA_NOT_PLANAR_FLAG,
+INTRA_BDPCM_CHROMA_FLAG = INTRA_LUMA_NOT_PLANAR_FLAG+ 2,
+INTRA_BDPCM_CHROMA_DIR_FLAG,
+CCLM_MODE_FLAG,
+CCLM_MODE_IDX,
+INTRA_CHROMA_PRED_MODE,
+GENERAL_MERGE_FLAG,
+INTER_PRED_IDC,
+INTER_AFFINE_FLAG   = INTER_PRED_IDC+ 6,
+CU_AFFINE_TYPE_FLAG = INTER_AFFINE_FLAG + 3,
+SYM_MVD_FLAG,
+REF_IDX_LX,
+MVP_LX_FLAG = REF_IDX_LX+ 2,
+AMVR_FLAG,
+AMVR_PRECISION_IDX  = AMVR_FLAG + 2,
+BCW_IDX = AMVR_PRECISION_IDX+ 3,
+CU_CODED_FLAG,
+CU_SBT_FLAG,
+CU_SBT_QUAD_FLAG= CU_SBT_FLAG   + 2,
+CU_SBT_HORIZONTAL_FLAG,
+CU_SBT_POS_FLAG = CU_SBT_HORIZONTAL_FLAG+ 3,
+LFNST_IDX,
+MTS_IDX = LFNST_IDX + 3,
+COPY_ABOVE_PALETTE_INDICES_FLAG = MTS_IDX   + 4,
+PALETTE_TRANSPOSE_FLAG,
+RUN_COPY_FLAG,
+REGULAR_MERGE_FLAG  = RUN_COPY_FLAG + 8,
+MMVD_MERGE_FLAG = REGULAR_MERGE_FLAG+ 2,
+MMVD_CAND_FLAG,
+MMVD_DISTANCE_IDX,
+CIIP_FLAG,
+ 

[FFmpeg-devel] [PATCH v3 13/14] vvcdec: add CTU thread logical

2023-09-02 Thread Nuo Mi
This is the main entry point for the CTU (Coding Tree Unit) decoder.
The code will divide the CTU decoder into several stages.
It will check the stage dependencies and run the stage decoder.
---
 libavcodec/vvc/Makefile |   3 +-
 libavcodec/vvc/vvc_thread.c | 805 
 libavcodec/vvc/vvc_thread.h |  72 
 3 files changed, 879 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_thread.c
 create mode 100644 libavcodec/vvc/vvc_thread.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index c2b67ddfc8..5dfd9c8561 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -12,4 +12,5 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o  
  \
 vvc/vvc_itx_1d.o\
 vvc/vvc_mvs.o   \
 vvc/vvc_ps.o\
-vvc/vvc_refs.o
+vvc/vvc_refs.o  \
+vvc/vvc_thread.o
diff --git a/libavcodec/vvc/vvc_thread.c b/libavcodec/vvc/vvc_thread.c
new file mode 100644
index 00..9d5201f5c8
--- /dev/null
+++ b/libavcodec/vvc/vvc_thread.c
@@ -0,0 +1,805 @@
+/*
+ * VVC thread logic
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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 "libavutil/thread.h"
+
+#include "vvc_thread.h"
+#include "vvc_ctu.h"
+#include "vvc_filter.h"
+#include "vvc_inter.h"
+#include "vvc_intra.h"
+#include "vvc_refs.h"
+
+typedef struct VVCRowThread {
+VVCTask reconstruct_task;
+VVCTask deblock_v_task;
+VVCTask sao_task;
+atomic_int progress[VVC_PROGRESS_LAST];
+} VVCRowThread;
+
+typedef struct VVCColThread {
+VVCTask deblock_h_task;
+} VVCColThread;
+
+struct VVCFrameThread {
+// error return for tasks
+atomic_int ret;
+
+atomic_uchar *avails;
+
+VVCRowThread *rows;
+VVCColThread *cols;
+VVCTask *tasks;
+
+int ctu_size;
+int ctu_width;
+int ctu_height;
+int ctu_count;
+
+//protected by lock
+int nb_scheduled_tasks;
+int nb_parse_tasks;
+int row_progress[VVC_PROGRESS_LAST];
+
+AVMutex lock;
+AVCond  cond;
+};
+
+static int get_avail(const VVCFrameThread *ft, const int rx, const int ry, 
const VVCTaskType type)
+{
+atomic_uchar *avail;
+if (rx < 0 || ry < 0)
+return 1;
+avail = ft->avails + FFMIN(ry,  ft->ctu_height - 1)* ft->ctu_width + 
FFMIN(rx, ft->ctu_width - 1);
+return atomic_load(avail) & (1 << type);
+}
+
+static void set_avail(const VVCFrameThread *ft, const int rx, const int ry, 
const VVCTaskType type)
+{
+atomic_uchar *avail = ft->avails + ry * ft->ctu_width + rx;
+if (rx < 0 || rx >= ft->ctu_width || ry < 0 || ry >= ft->ctu_height)
+return;
+atomic_fetch_or(avail, 1 << type);
+}
+
+void ff_vvc_task_init(VVCTask *task, VVCTaskType type, VVCFrameContext *fc)
+{
+memset(task, 0, sizeof(*task));
+task->type   = type;
+task->fc = fc;
+}
+
+void ff_vvc_parse_task_init(VVCTask *t, VVCTaskType type, VVCFrameContext *fc,
+SliceContext *sc, EntryPoint *ep, const int ctu_idx)
+{
+const VVCFrameThread *ft = fc->frame_thread;
+const int rs = sc->sh.ctb_addr_in_curr_slice[ctu_idx];
+
+ff_vvc_task_init(t, type, fc);
+t->sc = sc;
+t->ep = ep;
+t->ctu_idx = ctu_idx;
+t->rx = rs % ft->ctu_width;
+t->ry = rs / ft->ctu_width;
+}
+
+VVCTask* ff_vvc_task_alloc(void)
+{
+return av_malloc(sizeof(VVCTask));
+}
+
+static int check_colocation_ctu(const VVCFrameContext *fc, const VVCTask *t)
+{
+if (fc->ps.ph.r->ph_temporal_mvp_enabled_flag || 
fc->ps.sps->r->sps_sbtmvp_enabled_flag) {
+//-1 to avoid we are waiting for next CTU line.
+const int y = (t->ry << fc->ps.sps->ctb_log2_size_y) - 1;
+VVCFrame *col = fc->ref->collocated_ref;
+if (col && !ff_vvc_check_progress(col, VVC_PROGRESS_MV, y))
+return 0;
+}
+return 1;
+}
+
+static int is_parse_ready(const VVCFrameContext *fc, const VVCTask *t)
+{
+av_assert0(t->type == VVC_TASK_TYPE_PARSE);
+if (!check_colocation_ctu(fc, t))
+

[FFmpeg-devel] [PATCH v3 03/14] vvcdec: add parameter parser for sps, pps, ph, sh

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile |3 +-
 libavcodec/vvc/vvc_ps.c | 1325 +++
 libavcodec/vvc/vvc_ps.h |  274 
 libavcodec/vvc/vvcdec.h |4 +
 4 files changed, 1605 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_ps.c
 create mode 100644 libavcodec/vvc/vvc_ps.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 104b17db29..3ea430f61a 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -2,4 +2,5 @@ clean::
$(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
 
 OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o\
-vvc/vvc_data.o
+vvc/vvc_data.o  \
+vvc/vvc_ps.o
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
new file mode 100644
index 00..c180a401f0
--- /dev/null
+++ b/libavcodec/vvc/vvc_ps.c
@@ -0,0 +1,1325 @@
+/*
+ * VVC parameter set parser
+ *
+ * Copyright (C) 2023 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ *
+ * 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/cbs_h266.h"
+#include "libavutil/imgutils.h"
+#include "vvc_data.h"
+#include "vvc_ps.h"
+#include "vvcdec.h"
+
+
+typedef void (*free_fn)(uint8_t *data);
+
+static void ps_free(void *opaque, uint8_t *data)
+{
+free_fn free = (free_fn)opaque;
+
+free(data);
+av_freep();
+}
+
+static AVBufferRef* ps_alloc(size_t size, free_fn free)
+{
+AVBufferRef *buf;
+uint8_t *data = av_mallocz(size);
+
+if (!data)
+return NULL;
+
+buf = av_buffer_create(data, size, ps_free, free, 0);
+if (!buf)
+av_freep();
+
+return buf;
+}
+
+static int sps_map_pixel_format(VVCSPS *sps, void *log_ctx)
+{
+const H266RawSPS *r = sps->r;
+const AVPixFmtDescriptor *desc;
+
+switch (sps->bit_depth) {
+case 8:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
+   break;
+case 10:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
+break;
+case 12:
+if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
+if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
+if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
+if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
+break;
+default:
+av_log(log_ctx, AV_LOG_ERROR,
+   "The following bit-depths are currently specified: 8, 10, 12 
bits, "
+   "chroma_format_idc is %d, depth is %d\n",
+   r->sps_chroma_format_idc, sps->bit_depth);
+return AVERROR_INVALIDDATA;
+}
+
+desc = av_pix_fmt_desc_get(sps->pix_fmt);
+if (!desc)
+return AVERROR(EINVAL);
+
+sps->hshift[0] = sps->vshift[0] = 0;
+sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
+sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
+
+sps->pixel_shift = sps->bit_depth > 8;
+
+return 0;
+}
+
+static int sps_bit_depth(VVCSPS *sps, void *log_ctx)
+{
+const H266RawSPS *r = sps->r;
+
+sps->bit_depth = r->sps_bitdepth_minus8 + 8;
+sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
+sps->log2_transform_range =
+r->sps_extended_precision_flag ? FFMAX(15, FFMIN(20, sps->bit_depth + 
6)) : 15;
+return sps_map_pixel_format(sps, log_ctx);
+}
+
+static int sps_chroma_qp_table(VVCSPS *sps)
+{
+const H266RawSPS *r = sps->r;
+const int num_qp_tables = r->sps_same_qp_table_for_chroma_flag ?
+1 : (r->sps_joint_cbcr_enabled_flag ? 3 : 2);
+
+for (int i = 0; i < num_qp_tables; i++) {
+int num_points_in_qp_table;
+int8_t 

[FFmpeg-devel] [PATCH v3 05/14] vvcdec: add reference management

2023-09-02 Thread Nuo Mi
---
 libavcodec/vvc/Makefile   |   3 +-
 libavcodec/vvc/vvc_refs.c | 526 ++
 libavcodec/vvc/vvc_refs.h |  47 
 3 files changed, 575 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vvc/vvc_refs.c
 create mode 100644 libavcodec/vvc/vvc_refs.h

diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
index 64c9ea9688..6eb181784b 100644
--- a/libavcodec/vvc/Makefile
+++ b/libavcodec/vvc/Makefile
@@ -5,4 +5,5 @@ OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o
\
 vvc/vvc_cabac.o \
 vvc/vvc_ctu.o   \
 vvc/vvc_data.o  \
-vvc/vvc_ps.o
+vvc/vvc_ps.o\
+vvc/vvc_refs.o
diff --git a/libavcodec/vvc/vvc_refs.c b/libavcodec/vvc/vvc_refs.c
new file mode 100644
index 00..010f1892ed
--- /dev/null
+++ b/libavcodec/vvc/vvc_refs.c
@@ -0,0 +1,526 @@
+/*
+ * VVC reference management
+ *
+ * Copyright (C) 2023 Nuo Mi
+ *
+ * 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 "libavutil/thread.h"
+
+#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];
+AVMutex lock;
+} FrameProgress;
+
+void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, int flags)
+{
+/* frame->frame can be NULL if context init failed */
+if (!frame->frame || !frame->frame->buf[0])
+return;
+
+frame->flags &= ~flags;
+if (!frame->flags) {
+ff_thread_release_ext_buffer(fc->avctx, >tf);
+
+av_buffer_unref(>progress_buf);
+
+av_buffer_unref(>tab_dmvr_mvf_buf);
+frame->tab_dmvr_mvf = NULL;
+
+av_buffer_unref(>rpl_buf);
+av_buffer_unref(>rpl_tab_buf);
+frame->rpl_tab= NULL;
+
+frame->collocated_ref = NULL;
+}
+}
+
+const RefPicList *ff_vvc_get_ref_list(const VVCFrameContext *fc, const 
VVCFrame *ref, int x0, int y0)
+{
+int x_cb = x0 >> fc->ps.sps->ctb_log2_size_y;
+int y_cb = y0 >> fc->ps.sps->ctb_log2_size_y;
+int pic_width_cb = fc->ps.pps->ctb_width;
+int ctb_addr_rs  = y_cb * pic_width_cb + x_cb;
+
+return (const RefPicList *)ref->rpl_tab[ctb_addr_rs];
+}
+
+void ff_vvc_clear_refs(VVCFrameContext *fc)
+{
+int i;
+for (i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++)
+ff_vvc_unref_frame(fc, >DPB[i],
+VVC_FRAME_FLAG_SHORT_REF | VVC_FRAME_FLAG_LONG_REF);
+}
+
+static void free_progress(void *opaque, uint8_t *data)
+{
+ff_mutex_destroy(&((FrameProgress*)data)->lock);
+av_free(data);
+}
+
+static AVBufferRef *alloc_progress(void)
+{
+int ret;
+AVBufferRef *buf;
+FrameProgress *p = av_mallocz(sizeof(FrameProgress));
+
+if (!p)
+return NULL;
+
+ret = ff_mutex_init(>lock, NULL);
+if (ret) {
+av_free(p);
+return NULL;
+}
+buf = av_buffer_create((void*)p, sizeof(*p), free_progress, NULL, 0);
+if (!buf)
+free_progress(NULL, (void*)p);
+return buf;
+}
+
+static VVCFrame *alloc_frame(VVCContext *s, VVCFrameContext *fc)
+{
+const VVCPPS *pps = fc->ps.pps;
+int i, j, ret;
+for (i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
+VVCFrame *frame = >DPB[i];
+if (frame->frame->buf[0])
+continue;
+
+ret = ff_thread_get_ext_buffer(fc->avctx, >tf,
+   AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
+return NULL;
+
+frame->rpl_buf = av_buffer_allocz(s->current_frame.nb_units * 
sizeof(RefPicListTab));
+if (!frame->rpl_buf)
+goto fail;
+
+frame->tab_dmvr_mvf_buf = av_buffer_pool_get(fc->tab_dmvr_mvf_pool);
+if (!frame->tab_dmvr_mvf_buf)
+goto fail;
+frame->tab_dmvr_mvf = (MvField *)frame->tab_dmvr_mvf_buf->data;
+//fixme: remove this
+memset(frame->tab_dmvr_mvf, 0, 

[FFmpeg-devel] [PATCH v3 01/14] vvcdec: add vvc decoder stub

2023-09-02 Thread Nuo Mi
---
 configure   |   1 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/vvc/Makefile |   4 +
 libavcodec/vvc/vvcdec.c |  84 +++
 libavcodec/vvc/vvcdec.h | 307 
 6 files changed, 398 insertions(+)
 create mode 100644 libavcodec/vvc/Makefile
 create mode 100644 libavcodec/vvc/vvcdec.c
 create mode 100644 libavcodec/vvc/vvcdec.h

diff --git a/configure b/configure
index 8a1902810a..442c439c3e 100755
--- a/configure
+++ b/configure
@@ -3025,6 +3025,7 @@ vp6f_decoder_select="vp6_decoder"
 vp7_decoder_select="h264pred videodsp vp8dsp"
 vp8_decoder_select="h264pred videodsp vp8dsp"
 vp9_decoder_select="videodsp vp9_parser vp9_superframe_split_bsf"
+vvc_decoder_select="cabac golomb videodsp"
 wcmv_decoder_select="inflate_wrapper"
 webp_decoder_select="vp8_decoder exif"
 wmalossless_decoder_select="llauddsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 08fd151619..fb2738d8eb 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -62,6 +62,7 @@ OBJS = ac3_parser.o   
  \
xiph.o   \
 
 # subsystems
+include $(SRC_PATH)/libavcodec/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
 OBJS-$(CONFIG_AC3DSP)  += ac3dsp.o ac3.o ac3tab.o
 OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o 
mpeg4audio_sample_rates.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 6e95ca5636..c16d80cb85 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -388,6 +388,7 @@ extern const FFCodec ff_vp9_rkmpp_decoder;
 extern const FFCodec ff_vp9_v4l2m2m_decoder;
 extern const FFCodec ff_vqa_decoder;
 extern const FFCodec ff_vqc_decoder;
+extern const FFCodec ff_vvc_decoder;
 extern const FFCodec ff_wbmp_decoder;
 extern const FFCodec ff_wbmp_encoder;
 extern const FFCodec ff_webp_decoder;
diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile
new file mode 100644
index 00..bd14dbc1df
--- /dev/null
+++ b/libavcodec/vvc/Makefile
@@ -0,0 +1,4 @@
+clean::
+   $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%)
+
+OBJS-$(CONFIG_VVC_DECODER)  +=  vvc/vvcdec.o\
diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
new file mode 100644
index 00..8d027af0b9
--- /dev/null
+++ b/libavcodec/vvc/vvcdec.c
@@ -0,0 +1,84 @@
+/*
+ * VVC video decoder
+ *
+ * Copyright (C) 2021 Nuo Mi
+ * Copyright (C) 2022 Xu Mu
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "config_components.h"
+
+#include "libavcodec/codec_internal.h"
+#include "libavcodec/decode.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/profiles.h"
+#include "libavcodec/vvc.h"
+
+#include "libavutil/cpu.h"
+
+#include "vvcdec.h"
+
+static int vvc_decode_frame(AVCodecContext *avctx, AVFrame *output,
+int *got_output, AVPacket *avpkt)
+{
+return avpkt->size;
+}
+
+static void vvc_decode_flush(AVCodecContext *avctx)
+{
+}
+
+static av_cold int vvc_decode_free(AVCodecContext *avctx)
+{
+return 0;
+}
+
+static av_cold int vvc_decode_init(AVCodecContext *avctx)
+{
+return 0;
+}
+
+#define OFFSET(x) offsetof(VVCContext, x)
+#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
+
+static const AVOption options[] = {
+{ NULL },
+};
+
+static const AVClass vvc_decoder_class = {
+.class_name = "vvc decoder",
+.item_name  = av_default_item_name,
+.option = options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+const FFCodec ff_vvc_decoder = {
+.p.name  = "vvc",
+.p.long_name = NULL_IF_CONFIG_SMALL("VVC (Versatile Video 
Coding)"),
+.p.type  = AVMEDIA_TYPE_VIDEO,
+.p.id= AV_CODEC_ID_VVC,
+.priv_data_size  = sizeof(VVCContext),
+.p.priv_class= _decoder_class,
+.init= vvc_decode_init,
+.close   = vvc_decode_free,
+FF_CODEC_DECODE_CB(vvc_decode_frame),
+.flush   = vvc_decode_flush,
+.p.capabilities  = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | 
AV_CODEC_CAP_OTHER_THREADS,
+.caps_internal   = 

Re: [FFmpeg-devel] [PATCH v4 08/13] avutil/frame: add helper for extending a set of side data

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

Additionally, extend the side data set FATE test to check for the
invalid use case of extending a set by itself.
---
  libavutil/frame.c   | 32 
  libavutil/frame.h   | 15 +++
  libavutil/tests/side_data_set.c | 16 
  tests/ref/fate/side_data_set|  7 +++
  4 files changed, 70 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 5f74e0172b..898c749631 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -879,6 +879,38 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
  return ret;
  }
  
+int av_frame_side_data_set_extend(AVFrameSideDataSet *dst,

+  const AVFrameSideDataSet src,
+  unsigned int flags)


I think a standard, more versatile add() function would be better. The 
signature would be something like


av_frame_side_data_set_add_item(AVFrameSideDataSet *set,
const AVBufferRef *buf,
unsigned int flags);

It would also be a good chance to fix the non standard behavior i had 
misfortune to introduce with av_frame_new_side_data_from_buf() by having 
this function actually create a new reference to the passed in buffer 
rather than take ownership of it.



+{
+if (src.nb_sd > 0 && src.nb_sd == dst->nb_sd &&
+src.sd == dst->sd)
+return AVERROR(EINVAL);
+
+for (int i = 0; i < src.nb_sd; i++) {
+const AVFrameSideData *sd_src = src.sd[i];
+AVBufferRef   *buf= av_buffer_ref(sd_src->buf);
+AVFrameSideData   *sd_dst =
+add_side_data_to_set_from_buf(dst, sd_src->type, buf);
+if (!sd_dst) {
+av_buffer_unref();
+av_frame_side_data_set_uninit(dst);
+return AVERROR(ENOMEM);
+}
+
+{
+int ret = av_dict_copy(_dst->metadata, sd_src->metadata, 0);
+if (ret < 0) {
+av_frame_side_data_set_uninit(dst);
+return ret;
+}
+}
+
+}
+
+return 0;
+}
+
  AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,
   enum AVFrameSideDataType 
type)
  {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8ecdf82f33..e16941c5a5 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1085,6 +1085,21 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
   size_t size,
   unsigned int flags);
  
+/**

+ * Add multiple side data entries to a set in one go.
+ *
+ * @param dst a set to which the side data should be added
+ * @param src a set from which the side data should be copied from
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ *
+ * @return negative error code on failure, >=0 on success.
+ *
+ * @see av_frame_side_data_set_new_item regarding the flags.
+ */
+int av_frame_side_data_set_extend(AVFrameSideDataSet *dst,
+  const AVFrameSideDataSet src,
+  unsigned int flags);
+
  /**
   * Get a side data entry of a specific type from a set.
   *
diff --git a/libavutil/tests/side_data_set.c b/libavutil/tests/side_data_set.c
index 056d79f655..0c9ceed962 100644
--- a/libavutil/tests/side_data_set.c
+++ b/libavutil/tests/side_data_set.c
@@ -91,6 +91,22 @@ int main(void)
  puts("\nFinal state after a single 'no-duplicates' addition:");
  print_clls(set);
  
+{

+AVFrameSideDataSet dst_set = { 0 };
+av_assert0(av_frame_side_data_set_extend(_set, set, 0) >= 0);
+
+puts("\nState of the copied set:");
+print_clls(dst_set);
+
+av_frame_side_data_set_uninit(_set);
+}
+
+{
+int ret = av_frame_side_data_set_extend(, set, 0);
+printf("\nResult of trying to extend a set by itself: %s\n",
+   av_err2str(ret));
+}
+
  av_frame_side_data_set_uninit();
  
  return 0;

diff --git a/tests/ref/fate/side_data_set b/tests/ref/fate/side_data_set
index 7d8c684d8f..3050b31014 100644
--- a/tests/ref/fate/side_data_set
+++ b/tests/ref/fate/side_data_set
@@ -12,3 +12,10 @@ 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
+
+State of the copied set:
+sd 0, Ambient viewing environment
+sd 1, Spherical Mapping
+sd 2, Content light level metadata: MaxCLL: 1337
+
+Result of trying to extend a set by itself: Invalid argument

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

To unsubscribe, visit link above, or email

Re: [FFmpeg-devel] [PATCH] lavc/libx264: enable x4->params.analyse.b_fast_pskip if mb_info is set

2023-09-02 Thread Stefano Sabatini
On date Saturday 2023-09-02 09:20:08 +, Carotti, Elias wrote:
> On Thu, 2023-08-31 at 19:09 +0200, Stefano Sabatini wrote:
> > 
> 
> > 
> > > In particular why are you turning on fast_pskip silently based on a
> > > completely different setting?
> > 
> > The patch is fixing the regression introduced by the unconditional
> > setting of b_fast_pskip.
> > 
> > Now the question is if it makes sense to set mb_info without
> > b_fast_pskip (in both case this should be probably documented).
> > 
> > @Elias can you comment about the mb_info/b_fast_pskip use case?
> 
> Sorry again for the delay in responding. 
> We can safely remove it altogether. It's true we don't need to set it
> along with mb_info.
> However, it doesn't do any harm, since fast_pskip is by default set to
> true by libx264 and only turned off either explicitly by the user, or
> when using the placebo preset, or when doing lossless encoding 
> (constant QP == 0.)
> So, I agree, let's remove these three lines.

Thanks, updated.
>From ceb00a939ab2cd0fe146020b0e4e0d80b5d16a5d Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Fri, 25 Aug 2023 11:35:01 +0200
Subject: [PATCH] lavc/libx264: do not unconditionally set
 x4->params.analyse.b_fast_pskip

Fix output change regression introduced in 418c954e318.
---
 libavcodec/libx264.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index ce849d6c9a..cc5e1ba5b1 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1190,7 +1190,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 
 x4->params.analyse.b_mb_info = x4->mb_info;
-x4->params.analyse.b_fast_pskip = 1;
 
 // update AVCodecContext with x264 parameters
 avctx->has_b_frames = x4->params.i_bframe ?
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 1/3] ffprobe: factorize side data printing to dedicated function

2023-09-02 Thread Stefano Sabatini
On date Saturday 2023-09-02 10:33:12 +0200, Andreas Rheinhardt wrote:
> Stefano Sabatini:
> > +static void print_frame_side_data(WriterContext *w,
> > +  AVFrame *frame,
> > +  AVStream *stream)
> 
> I am pretty sure both frame and stream can be constified.
> 
> > +{
> > +int i;
> 
> We support C99 variable declarations in for loops.
> 
> > +
> > +writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_LIST);
> > +
> > +for (i = 0; i < frame->nb_side_data; i++) {
> > +AVFrameSideData *sd = frame->side_data[i];
> 
> This can probably be const, too.
> 
> > +const char *name;

Updated.
>From afa387d5d529e09f91aaa3d3b721793d919a4bc8 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Thu, 31 Aug 2023 16:52:00 +0200
Subject: [PATCH] ffprobe: factorize side data printing to dedicated function

---
 fftools/ffprobe.c | 161 --
 1 file changed, 83 insertions(+), 78 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 4fcfe1164b..181a1e0785 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2578,6 +2578,87 @@ static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
 fflush(stdout);
 }
 
+static void print_frame_side_data(WriterContext *w,
+  const AVFrame *frame,
+  const AVStream *stream)
+{
+writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_LIST);
+
+for (int i = 0; i < frame->nb_side_data; i++) {
+const AVFrameSideData *sd = frame->side_data[i];
+const char *name;
+
+writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA);
+name = av_frame_side_data_name(sd->type);
+print_str("side_data_type", name ? name : "unknown");
+if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
+double rotation = av_display_rotation_get((int32_t *)sd->data);
+if (isnan(rotation))
+rotation = 0;
+writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
+print_int("rotation", rotation);
+} else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
+print_int("active_format", *sd->data);
+} else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
+char tcbuf[AV_TIMECODE_STR_SIZE];
+av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
+print_str("timecode", tcbuf);
+} else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
+uint32_t *tc = (uint32_t*)sd->data;
+int m = FFMIN(tc[0],3);
+writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST);
+for (int j = 1; j <= m ; j++) {
+char tcbuf[AV_TIMECODE_STR_SIZE];
+av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
+writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE);
+print_str("value", tcbuf);
+writer_print_section_footer(w);
+}
+writer_print_section_footer(w);
+} else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
+AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
+
+if (metadata->has_primaries) {
+print_q("red_x", metadata->display_primaries[0][0], '/');
+print_q("red_y", metadata->display_primaries[0][1], '/');
+print_q("green_x", metadata->display_primaries[1][0], '/');
+print_q("green_y", metadata->display_primaries[1][1], '/');
+print_q("blue_x", metadata->display_primaries[2][0], '/');
+print_q("blue_y", metadata->display_primaries[2][1], '/');
+
+print_q("white_point_x", metadata->white_point[0], '/');
+print_q("white_point_y", metadata->white_point[1], '/');
+}
+
+if (metadata->has_luminance) {
+print_q("min_luminance", metadata->min_luminance, '/');
+print_q("max_luminance", metadata->max_luminance, '/');
+}
+} else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
+AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
+print_dynamic_hdr10_plus(w, metadata);
+} else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
+AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
+print_int("max_content", metadata->MaxCLL);
+print_int("max_average", metadata->MaxFALL);
+} else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
+const AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
+if (tag)
+print_str(tag->key, tag->value);
+

Re: [FFmpeg-devel] [PATCH 1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description

2023-09-02 Thread Stefano Sabatini
On date Saturday 2023-09-02 01:14:42 +0200, Stefano Sabatini wrote:
> ---
>  libavcodec/avcodec.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Patchset dropped in favor of version 2.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging

2023-09-02 Thread Stefano Sabatini
Aid timestamp debugging.
---
 doc/examples/transcode.c | 43 +++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 21ea14b614..5671c6664b 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static AVFormatContext *ifmt_ctx;
 static AVFormatContext *ofmt_ctx;
@@ -435,6 +436,26 @@ static int init_filters(void)
 return 0;
 }
 
+static void log_packet(AVPacket *pkt, const AVFormatContext *fmt_ctx, const 
char *tag)
+{
+AVRational *time_base = _ctx->streams[pkt->stream_index]->time_base;
+
+av_log(NULL, AV_LOG_INFO,
+   "%s [pkt] stream:%d tb:%d/%d pts_time:%s\n",
+   tag, pkt->stream_index, time_base->num, time_base->den,
+   av_ts2timestr(pkt->pts, time_base));
+}
+
+static void log_frame(AVFrame *frame, int stream_index, const char *tag)
+{
+AVRational *time_base = >time_base;
+
+av_log(NULL, AV_LOG_INFO,
+   "%s [frame] stream:%d tb:%d/%d pts_time:%s\n",
+   tag, stream_index, time_base->num, time_base->den,
+   av_ts2timestr(frame->pts, time_base));
+}
+
 static int encode_write_frame(unsigned int stream_index, int flush)
 {
 StreamContext *stream = _ctx[stream_index];
@@ -443,16 +464,16 @@ static int encode_write_frame(unsigned int stream_index, 
int flush)
 AVPacket *enc_pkt = filter->enc_pkt;
 int ret;
 
-av_log(NULL, AV_LOG_INFO, "Encoding frame\n");
 /* encode filtered frame */
 av_packet_unref(enc_pkt);
 
-if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE)
+if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) {
 filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
stream->enc_ctx->time_base);
+log_frame(filt_frame, stream_index, "encoder <-");
+}
 
 ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
-
 if (ret < 0)
 return ret;
 
@@ -468,8 +489,8 @@ static int encode_write_frame(unsigned int stream_index, 
int flush)
  stream->enc_ctx->time_base,
  ofmt_ctx->streams[stream_index]->time_base);
 
-av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
 /* mux encoded frame */
+log_packet(enc_pkt, ofmt_ctx, "muxer <-");
 ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
 }
 
@@ -481,8 +502,11 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 FilteringContext *filter = _ctx[stream_index];
 int ret;
 
-av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n");
 /* push the decoded frame into the filtergraph */
+if (frame) {
+log_frame(frame, stream_index, "filters <-");
+}
+
 ret = av_buffersrc_add_frame(filter->buffersrc_ctx, frame);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
@@ -491,7 +515,6 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 
 /* pull filtered frames from the filtergraph */
 while (1) {
-av_log(NULL, AV_LOG_INFO, "Pulling filtered frame from filters\n");
 ret = av_buffersink_get_frame(filter->buffersink_ctx, 
filter->filtered_frame);
 if (ret < 0) {
 /* if no more frames for output - returns AVERROR(EAGAIN)
@@ -505,6 +528,8 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 
 filter->filtered_frame->time_base = 
av_buffersink_get_time_base(filter->buffersink_ctx);
 filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
+
+log_frame(filter->filtered_frame, stream_index, "filters ->");
 ret = encode_write_frame(stream_index, 0);
 av_frame_unref(filter->filtered_frame);
 if (ret < 0)
@@ -549,13 +574,11 @@ int main(int argc, char **argv)
 if ((ret = av_read_frame(ifmt_ctx, packet)) < 0)
 break;
 stream_index = packet->stream_index;
-av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", 
stream_index);
+log_packet(packet, ifmt_ctx, "demuxer ->");
 
 if (filter_ctx[stream_index].filter_graph) {
 StreamContext *stream = _ctx[stream_index];
 
-av_log(NULL, AV_LOG_DEBUG, "Going to reencode the frame\n");
-
 ret = avcodec_send_packet(stream->dec_ctx, packet);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
@@ -569,6 +592,7 @@ int main(int argc, char **argv)
 else if (ret < 0)
 goto end;
 
+log_frame(stream->dec_frame, stream_index, "decoder ->");
 stream->dec_frame->pts = 
stream->dec_frame->best_effort_timestamp;
 ret = filter_encode_write_frame(stream->dec_frame, 
stream_index);
 if (ret < 0)

[FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder

2023-09-02 Thread Stefano Sabatini
Fix crash occurring when the list of sample formats is not defined in the 
encoder,
use the decoder one in that case.

Possibly fix issue:
http://trac.ffmpeg.org/ticket/5849
---
 doc/examples/transcode.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 1d22a4b09e..3c72b9377e 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -189,8 +189,10 @@ static int open_output_file(const char *filename)
 ret = av_channel_layout_copy(_ctx->ch_layout, 
_ctx->ch_layout);
 if (ret < 0)
 return ret;
-/* take first format from list of supported formats */
-enc_ctx->sample_fmt = encoder->sample_fmts[0];
+
+/* take first format from list of supported formats or use 
decoder one */
+enc_ctx->sample_fmt = encoder->sample_fmts ? 
encoder->sample_fmts[0] : dec_ctx->sample_fmt;
+
 enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
 }
 
-- 
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 06/11] doc/examples/transcode: use av_buffersrc_add_frame()

2023-09-02 Thread Stefano Sabatini
Favor it over av_buffersrc_add_frame_flags, simplify.
---
 doc/examples/transcode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index dd64c38f15..21ea14b614 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -483,7 +483,7 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 
 av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n");
 /* push the decoded frame into the filtergraph */
-ret = av_buffersrc_add_frame_flags(filter->buffersrc_ctx, frame, 0);
+ret = av_buffersrc_add_frame(filter->buffersrc_ctx, frame);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
 return ret;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources

2023-09-02 Thread Stefano Sabatini
---
 doc/examples/transcode.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 5671c6664b..b94fdbede2 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -280,14 +280,14 @@ static int init_filter(FilteringContext *fctx, 
AVCodecContext *dec_ctx,
  dec_ctx->sample_aspect_ratio.num,
  dec_ctx->sample_aspect_ratio.den);
 
-ret = avfilter_graph_create_filter(_ctx, buffersrc, "in",
+ret = avfilter_graph_create_filter(_ctx, buffersrc, 
"video-in",
args, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
 goto end;
 }
 
-ret = avfilter_graph_create_filter(_ctx, buffersink, "out",
+ret = avfilter_graph_create_filter(_ctx, buffersink, 
"video-out",
NULL, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
@@ -321,14 +321,14 @@ static int init_filter(FilteringContext *fctx, 
AVCodecContext *dec_ctx,
  av_get_sample_fmt_name(dec_ctx->sample_fmt),
  buf);
 
-ret = avfilter_graph_create_filter(_ctx, buffersrc, "in",
+ret = avfilter_graph_create_filter(_ctx, buffersrc, 
"audio-in",
args, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer source\n");
 goto end;
 }
 
-ret = avfilter_graph_create_filter(_ctx, buffersink, "out",
+ret = avfilter_graph_create_filter(_ctx, buffersink, 
"audio-out",
NULL, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create audio buffer sink\n");
-- 
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 10/11] doc/examples/transcode: simplify selection of pix_fmt

2023-09-02 Thread Stefano Sabatini
Use ternary operator.
---
 doc/examples/transcode.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 524bb47f50..1d22a4b09e 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -178,11 +178,10 @@ static int open_output_file(const char *filename)
 enc_ctx->height = dec_ctx->height;
 enc_ctx->width = dec_ctx->width;
 enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
-/* take first format from list of supported formats */
-if (encoder->pix_fmts)
-enc_ctx->pix_fmt = encoder->pix_fmts[0];
-else
-enc_ctx->pix_fmt = dec_ctx->pix_fmt;
+
+/* take first format from list of supported formats or use 
decoder one */
+enc_ctx->pix_fmt = encoder->pix_fmts ? encoder->pix_fmts[0] : 
dec_ctx->pix_fmt;
+
 /* video time_base can be set to whatever is handy and 
supported by encoder */
 enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
 } else {
-- 
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 09/11] doc/examples/transcode: fix timestamps scaling

2023-09-02 Thread Stefano Sabatini
Set pkt_timebase in the decoder and in the decoded frame, use it for
the filterchain source, and rescale the filtered frame to the target
encoder time_base.

This fixes filtering in case the time base was not set in the decoder,
causing the error:
[in @ 0x5647fc26ec80] Invalid time base 0/1
---
 doc/examples/transcode.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index b94fdbede2..524bb47f50 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -276,7 +276,7 @@ static int init_filter(FilteringContext *fctx, 
AVCodecContext *dec_ctx,
 snprintf(args, sizeof(args),
  
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
  dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
- dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
  dec_ctx->sample_aspect_ratio.num,
  dec_ctx->sample_aspect_ratio.den);
 
@@ -303,6 +303,7 @@ static int init_filter(FilteringContext *fctx, 
AVCodecContext *dec_ctx,
 }
 } else if (dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
 char buf[64];
+
 buffersrc = avfilter_get_by_name("abuffer");
 buffersink = avfilter_get_by_name("abuffersink");
 if (!buffersrc || !buffersink) {
@@ -317,7 +318,7 @@ static int init_filter(FilteringContext *fctx, 
AVCodecContext *dec_ctx,
 av_channel_layout_describe(_ctx->ch_layout, buf, sizeof(buf));
 snprintf(args, sizeof(args),
  
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
- dec_ctx->time_base.num, dec_ctx->time_base.den, 
dec_ctx->sample_rate,
+ dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, 
dec_ctx->sample_rate,
  av_get_sample_fmt_name(dec_ctx->sample_fmt),
  buf);
 
@@ -470,6 +471,7 @@ static int encode_write_frame(unsigned int stream_index, 
int flush)
 if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) {
 filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
stream->enc_ctx->time_base);
+filt_frame->time_base = stream->enc_ctx->time_base;
 log_frame(filt_frame, stream_index, "encoder <-");
 }
 
-- 
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 05/11] doc/examples/transcode: improve reporting when the encoder is not found

2023-09-02 Thread Stefano Sabatini
Also return EINVAL in place of INVALIDDATA.
---
 doc/examples/transcode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 3c57fb36c9..dd64c38f15 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -161,8 +161,8 @@ static int open_output_file(const char *filename)
 /* in this example, we choose transcoding to same codec */
 encoder = avcodec_find_encoder(dec_ctx->codec_id);
 if (!encoder) {
-av_log(NULL, AV_LOG_FATAL, "Necessary encoder not found\n");
-return AVERROR_INVALIDDATA;
+av_log(NULL, AV_LOG_FATAL, "Necessary encoder with ID %d not 
found\n", dec_ctx->codec_id);
+return AVERROR(EINVAL);
 }
 enc_ctx = avcodec_alloc_context3(encoder);
 if (!enc_ctx) {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description

2023-09-02 Thread Stefano Sabatini
---
 libavcodec/avcodec.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 649411ac79..070e36795d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1794,9 +1794,9 @@ typedef struct AVCodecContext {
 enum AVPixelFormat sw_pix_fmt;
 
 /**
- * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
- * - encoding unused.
- * - decoding set by user.
+ * Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
+ * - encoding: unused.
+ * - decoding: set by user.
  */
 AVRational pkt_timebase;
 
-- 
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 03/11] doc/examples/transcode: apply style fixes

2023-09-02 Thread Stefano Sabatini
---
 doc/examples/transcode.c | 97 +---
 1 file changed, 50 insertions(+), 47 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index ed6ac9fa03..81a88dd577 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -82,19 +82,23 @@ static int open_input_file(const char *filename)
 AVStream *stream = ifmt_ctx->streams[i];
 const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
 AVCodecContext *codec_ctx;
+
 if (!dec) {
 av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream 
#%u\n", i);
 return AVERROR_DECODER_NOT_FOUND;
 }
+
 codec_ctx = avcodec_alloc_context3(dec);
 if (!codec_ctx) {
-av_log(NULL, AV_LOG_ERROR, "Failed to allocate the decoder context 
for stream #%u\n", i);
+av_log(NULL, AV_LOG_ERROR,
+   "Failed to allocate the decoder context for stream #%u\n", 
i);
 return AVERROR(ENOMEM);
 }
+
 ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar);
 if (ret < 0) {
-av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to 
input decoder context "
-   "for stream #%u\n", i);
+av_log(NULL, AV_LOG_ERROR,
+   "Failed to copy decoder parameters to input decoder context 
for stream #%u\n", i);
 return ret;
 }
 
@@ -103,8 +107,7 @@ static int open_input_file(const char *filename)
 codec_ctx->pkt_timebase = stream->time_base;
 
 /* Reencode video & audio and remux subtitles etc. */
-if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
-|| codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || 
codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
 if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
 codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, 
NULL);
 /* Open decoder */
@@ -141,7 +144,6 @@ static int open_output_file(const char *filename)
 return AVERROR_UNKNOWN;
 }
 
-
 for (i = 0; i < ifmt_ctx->nb_streams; i++) {
 out_stream = avformat_new_stream(ofmt_ctx, NULL);
 if (!out_stream) {
@@ -152,8 +154,7 @@ static int open_output_file(const char *filename)
 in_stream = ifmt_ctx->streams[i];
 dec_ctx = stream_ctx[i].dec_ctx;
 
-if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
-|| dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
+if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || dec_ctx->codec_type 
== AVMEDIA_TYPE_AUDIO) {
 /* in this example, we choose transcoding to same codec */
 encoder = avcodec_find_encoder(dec_ctx->codec_id);
 if (!encoder) {
@@ -241,8 +242,8 @@ static int open_output_file(const char *filename)
 return 0;
 }
 
-static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
-AVCodecContext *enc_ctx, const char *filter_spec)
+static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
+   AVCodecContext *enc_ctx, const char *filter_spec)
 {
 char args[512];
 int ret = 0;
@@ -269,29 +270,29 @@ static int init_filter(FilteringContext* fctx, 
AVCodecContext *dec_ctx,
 }
 
 snprintf(args, sizeof(args),
-
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
-dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
-dec_ctx->sample_aspect_ratio.num,
-dec_ctx->sample_aspect_ratio.den);
+ 
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
+ dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+ dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->sample_aspect_ratio.num,
+ dec_ctx->sample_aspect_ratio.den);
 
 ret = avfilter_graph_create_filter(_ctx, buffersrc, "in",
-args, NULL, filter_graph);
+   args, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
 goto end;
 }
 
 ret = avfilter_graph_create_filter(_ctx, buffersink, "out",
-NULL, NULL, filter_graph);
+   NULL, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
 goto end;
 }
 
 ret = av_opt_set_bin(buffersink_ctx, "pix_fmts",
-(uint8_t*)_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt),
-AV_OPT_SEARCH_CHILDREN);
+ (uint8_t*)_ctx->pix_fmt, 
sizeof(enc_ctx->pix_fmt),
+ 

[FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition

2023-09-02 Thread Stefano Sabatini
---
 doc/examples/transcode.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 81a88dd577..3c57fb36c9 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -82,6 +82,7 @@ static int open_input_file(const char *filename)
 AVStream *stream = ifmt_ctx->streams[i];
 const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
 AVCodecContext *codec_ctx;
+enum AVMediaType codec_type;
 
 if (!dec) {
 av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream 
#%u\n", i);
@@ -105,11 +106,13 @@ static int open_input_file(const char *filename)
 /* Inform the decoder about the timebase for the packet timestamps.
  * This is highly recommended, but not mandatory. */
 codec_ctx->pkt_timebase = stream->time_base;
+codec_type = codec_ctx->codec_type;
 
 /* Reencode video & audio and remux subtitles etc. */
-if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || 
codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
+if (codec_type == AVMEDIA_TYPE_VIDEO || codec_type == 
AVMEDIA_TYPE_AUDIO) {
+if (codec_type == AVMEDIA_TYPE_VIDEO)
 codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, 
NULL);
+
 /* Open decoder */
 ret = avcodec_open2(codec_ctx, dec, NULL);
 if (ret < 0) {
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup

2023-09-02 Thread Stefano Sabatini
---
 libavfilter/af_aresample.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index f4bcc45616..b71ed5b91c 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -28,6 +28,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
 #include "libavutil/samplefmt.h"
+#include "libavutil/timestamp.h"
 #include "libavutil/avassert.h"
 #include "libswresample/swresample.h"
 #include "avfilter.h"
@@ -164,9 +165,9 @@ static int config_output(AVFilterLink *outlink)
 av_channel_layout_describe( ->ch_layout, inchl_buf,  
sizeof(inchl_buf));
 av_channel_layout_describe(>ch_layout, outchl_buf, 
sizeof(outchl_buf));
 
-av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s 
fmt:%s r:%dHz\n",
-   inlink ->ch_layout.nb_channels, inchl_buf,  
av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
-   outlink->ch_layout.nb_channels, outchl_buf, 
av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
+av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz tb:%d/%d -> ch:%d 
chl:%s fmt:%s r:%dHz tb:%d/%d\n",
+   inlink ->ch_layout.nb_channels, inchl_buf,  
av_get_sample_fmt_name(inlink->format),  inlink->sample_rate, 
inlink->time_base.num, inlink->time_base.den,
+   outlink->ch_layout.nb_channels, outchl_buf, 
av_get_sample_fmt_name(outlink->format), outlink->sample_rate, 
outlink->time_base.num, outlink->time_base.den);
 return 0;
 }
 
-- 
2.34.1

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

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


[FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2

2023-09-02 Thread Stefano Sabatini
Apply various fixes to transcode.c, with some bonus patches fixing a
typo and adding some debug logs in the aresample filter.

In particular fixes:
http://trac.ffmpeg.org/ticket/5849

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

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


Re: [FFmpeg-devel] [PATCH v4 07/13] avutil/frame: add helper for getting side data from set

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

---
  libavutil/frame.c | 22 +-
  libavutil/frame.h | 12 
  2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index f64ddb3645..5f74e0172b 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -879,16 +879,28 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
  return ret;
  }
  
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,

-enum AVFrameSideDataType type)
+AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,


You should pass a pointer to a set, not a set.


+ enum AVFrameSideDataType type)
  {
-for (int i = 0; i < frame->nb_side_data; i++) {
-if (frame->side_data[i]->type == type)
-return frame->side_data[i];
+for (int i = 0; i < set.nb_sd; i++) {
+if (set.sd[i]->type == type)
+return set.sd[i];
  }
  return NULL;
  }
  
+AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,

+enum AVFrameSideDataType type)
+{


Thus:

AVFrameSideDataSet set = {
.sd= frame->side_data,
.nb_sd = frame->nb_side_data,
};

return av_frame_side_data_set_get_item(, type);


+return av_frame_side_data_set_get_item(
+(const AVFrameSideDataSet){
+.sd= frame->side_data,
+.nb_sd = frame->nb_side_data
+},
+type
+);
+}
+
  static int frame_copy_video(AVFrame *dst, const AVFrame *src)
  {
  const uint8_t *src_data[4];
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5aed08b796..8ecdf82f33 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1085,6 +1085,18 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
   size_t size,
   unsigned int flags);
  
+/**

+ * Get a side data entry of a specific type from a set.
+ *
+ * @param set the set from which side data should be queried from
+ * @param type type of side data to be queried
+ *
+ * @return a pointer to the side data of a given type on success, NULL if there
+ * is no side data with such type in this set.
+ */
+AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,
+ enum AVFrameSideDataType 
type);
+
  /**
   * @}
   */

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

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


Re: [FFmpeg-devel] [PATCH v4 08/13] avutil/frame: add helper for extending a set of side data

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

Additionally, extend the side data set FATE test to check for the
invalid use case of extending a set by itself.
---
  libavutil/frame.c   | 32 
  libavutil/frame.h   | 15 +++
  libavutil/tests/side_data_set.c | 16 
  tests/ref/fate/side_data_set|  7 +++
  4 files changed, 70 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 5f74e0172b..898c749631 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -879,6 +879,38 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
  return ret;
  }
  
+int av_frame_side_data_set_extend(AVFrameSideDataSet *dst,

+  const AVFrameSideDataSet src,
+  unsigned int flags)


flags is unused. Shouldn't you check for the no duplicates one?


+{
+if (src.nb_sd > 0 && src.nb_sd == dst->nb_sd &&
+src.sd == dst->sd)
+return AVERROR(EINVAL);
+
+for (int i = 0; i < src.nb_sd; i++) {
+const AVFrameSideData *sd_src = src.sd[i];
+AVBufferRef   *buf= av_buffer_ref(sd_src->buf);
+AVFrameSideData   *sd_dst =
+add_side_data_to_set_from_buf(dst, sd_src->type, buf);
+if (!sd_dst) {
+av_buffer_unref();
+av_frame_side_data_set_uninit(dst);
+return AVERROR(ENOMEM);
+}
+
+{
+int ret = av_dict_copy(_dst->metadata, sd_src->metadata, 0);
+if (ret < 0) {
+av_frame_side_data_set_uninit(dst);
+return ret;
+}
+}
+
+}
+
+return 0;
+}
+
  AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,
   enum AVFrameSideDataType 
type)
  {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8ecdf82f33..e16941c5a5 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1085,6 +1085,21 @@ AVFrameSideData 
*av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
   size_t size,
   unsigned int flags);
  
+/**

+ * Add multiple side data entries to a set in one go.
+ *
+ * @param dst a set to which the side data should be added
+ * @param src a set from which the side data should be copied from
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ *
+ * @return negative error code on failure, >=0 on success.
+ *
+ * @see av_frame_side_data_set_new_item regarding the flags.
+ */
+int av_frame_side_data_set_extend(AVFrameSideDataSet *dst,
+  const AVFrameSideDataSet src,
+  unsigned int flags);
+
  /**
   * Get a side data entry of a specific type from a set.
   *
diff --git a/libavutil/tests/side_data_set.c b/libavutil/tests/side_data_set.c
index 056d79f655..0c9ceed962 100644
--- a/libavutil/tests/side_data_set.c
+++ b/libavutil/tests/side_data_set.c
@@ -91,6 +91,22 @@ int main(void)
  puts("\nFinal state after a single 'no-duplicates' addition:");
  print_clls(set);
  
+{

+AVFrameSideDataSet dst_set = { 0 };
+av_assert0(av_frame_side_data_set_extend(_set, set, 0) >= 0);
+
+puts("\nState of the copied set:");
+print_clls(dst_set);
+
+av_frame_side_data_set_uninit(_set);
+}
+
+{
+int ret = av_frame_side_data_set_extend(, set, 0);
+printf("\nResult of trying to extend a set by itself: %s\n",
+   av_err2str(ret));
+}
+
  av_frame_side_data_set_uninit();
  
  return 0;

diff --git a/tests/ref/fate/side_data_set b/tests/ref/fate/side_data_set
index 7d8c684d8f..3050b31014 100644
--- a/tests/ref/fate/side_data_set
+++ b/tests/ref/fate/side_data_set
@@ -12,3 +12,10 @@ 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
+
+State of the copied set:
+sd 0, Ambient viewing environment
+sd 1, Spherical Mapping
+sd 2, Content light level metadata: MaxCLL: 1337
+
+Result of trying to extend a set by itself: Invalid argument

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

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


Re: [FFmpeg-devel] [PATCH v4 03/13] avutil/frame: add helper for uninitializing side data sets

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

---
  libavutil/frame.c | 5 +
  libavutil/frame.h | 8 
  2 files changed, 13 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 4b8481b756..b03f8d6c73 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -90,6 +90,11 @@ static void frame_side_data_wipe(AVFrame *frame)
  wipe_side_data(>side_data, >nb_side_data);
  }
  
+void av_frame_side_data_set_uninit(AVFrameSideDataSet *set)

+{
+wipe_side_data(>sd, >nb_sd);
+}
+
  AVFrame *av_frame_alloc(void)
  {
  AVFrame *frame = av_malloc(sizeof(*frame));
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 6155226c1d..dc87d38adc 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1057,6 +1057,14 @@ int av_frame_apply_cropping(AVFrame *frame, int flags);
   */
  const char *av_frame_side_data_name(enum AVFrameSideDataType type);
  
+/**

+ * Free all side data items and their contents, then zeroes out the
+ * struct values.
+ *
+ * @param set the set which should be uninitialized
+ */
+void av_frame_side_data_set_uninit(AVFrameSideDataSet *set);


av_frame_side_data_set_free()?


+
  /**
   * @}
   */

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

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


Re: [FFmpeg-devel] [PATCH v4 06/13] avutil/frame: add helper for adding side data to set

2023-09-02 Thread James Almer

On 9/1/2023 5:38 PM, Jan Ekström wrote:

Additionally, add an API test to check that the no-duplicates
addition works after duplicates have been inserted.
---
  libavutil/Makefile  |  1 +
  libavutil/frame.c   | 18 ++
  libavutil/frame.h   | 20 +++
  libavutil/tests/side_data_set.c | 97 +
  tests/fate/libavutil.mak|  4 ++
  tests/ref/fate/side_data_set| 14 +
  6 files changed, 154 insertions(+)
  create mode 100644 libavutil/tests/side_data_set.c
  create mode 100644 tests/ref/fate/side_data_set

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 7828c94dc5..339eaf3539 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -264,6 +264,7 @@ TESTPROGS = adler32 
\
  ripemd  \
  sha \
  sha512  \
+side_data_set   \
  softfloat   \
  tree\
  twofish \
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 0b1a8e5244..f64ddb3645 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -861,6 +861,24 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
  return ret;
  }
  
+AVFrameSideData *av_frame_side_data_set_new_item(AVFrameSideDataSet *set,


Maybe av_frame_side_data_set_new_entry(), or just 
av_frame_side_data_set_new()? I don't particularly like item.



+ enum AVFrameSideDataType type,
+ size_t size,
+ unsigned int flags)
+{
+AVBufferRef *buf = av_buffer_alloc(size);
+AVFrameSideData *ret = NULL;
+
+if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
+remove_side_data(>sd, >nb_sd, type);
+
+ret = add_side_data_to_set_from_buf(set, type, buf);
+if (!ret)
+av_buffer_unref();
+
+return ret;
+}
+
  AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  enum AVFrameSideDataType type)
  {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index dc87d38adc..5aed08b796 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1065,6 +1065,26 @@ const char *av_frame_side_data_name(enum 
AVFrameSideDataType type);
   */
  void av_frame_side_data_set_uninit(AVFrameSideDataSet *set);
  
+#define AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES (1 << 0)

+
+/**
+ * Add a new side data entry to a set.
+ *
+ * @param set a set to which the side data should be added
+ * @param type type of the added side data
+ * @param size size of the side data
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ *
+ * @return newly added side data on success, NULL on error. In case of
+ * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries
+ * of matching AVFrameSideDataType will be removed before the
+ * addition is attempted.
+ */
+AVFrameSideData *av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
+ enum AVFrameSideDataType type,
+ size_t size,
+ unsigned int flags);
+
  /**
   * @}
   */
diff --git a/libavutil/tests/side_data_set.c b/libavutil/tests/side_data_set.c
new file mode 100644
index 00..056d79f655
--- /dev/null
+++ b/libavutil/tests/side_data_set.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2023 Jan Ekström 
+ *
+ * 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 "libavutil/frame.c"
+#include "libavutil/mastering_display_metadata.h"
+
+static void print_clls(const AVFrameSideDataSet set)
+{
+for (int i = 0; i < set.nb_sd; i++) {
+AVFrameSideData *sd = set.sd[i];
+
+printf("sd %d, %s",
+   i, 

[FFmpeg-devel] [PATCH] avformat/avformat: Avoid including codec.h, frame.h

2023-09-02 Thread Andreas Rheinhardt
AVCodec is only ever used as an incomplete type (i.e. via a pointer
to an AVCodec) in avformat.h and it is not really part of the core
of avformat.h or libavformat; almost none of our internal users
make use of it (and none make use of hwcontext.h, which is implicitly
included). So switch to use struct AVCodec, but continue to include
codec.h for external users for compatibility.

Also, do the same for AVFrame and frame.h, which is implicitly included
by codec.h (via lavu/hwcontext.h).

Also, remove an unnecessary inclusion of .

Signed-off-by: Andreas Rheinhardt 
---
 libavdevice/alsa_enc.c   |  1 +
 libavdevice/opengl_enc.c |  1 +
 libavdevice/pulse_audio_enc.c|  1 +
 libavdevice/xv.c |  1 +
 libavformat/asfdec_o.c   |  2 ++
 libavformat/avformat.c   |  2 ++
 libavformat/avformat.h   | 29 -
 libavformat/dashdec.c|  1 +
 libavformat/dashenc.c|  1 +
 libavformat/dhav.c   |  2 ++
 libavformat/ftp.c|  1 +
 libavformat/hlsenc.c |  1 +
 libavformat/hlsplaylist.c|  1 +
 libavformat/http.c   |  1 +
 libavformat/img2enc.c|  2 ++
 libavformat/internal.h   |  4 ++--
 libavformat/mlvdec.c |  2 ++
 libavformat/mux.c|  2 ++
 libavformat/mux.h|  2 +-
 libavformat/mxfdec.c |  1 +
 libavformat/uncodedframecrcenc.c |  1 +
 libavformat/wavenc.c |  1 +
 libavformat/webmdashenc.c|  1 +
 libavformat/wtvdec.c |  1 +
 libavformat/yuv4mpegenc.c|  1 +
 25 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c
index 62a20c7ba4..4c7805065e 100644
--- a/libavdevice/alsa_enc.c
+++ b/libavdevice/alsa_enc.c
@@ -39,6 +39,7 @@
 
 #include 
 
+#include "libavutil/frame.h"
 #include "libavutil/internal.h"
 #include "libavutil/time.h"
 
diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 1b0cf5aa8f..80feda7072 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -49,6 +49,7 @@
 #endif
 
 #include "libavutil/common.h"
+#include "libavutil/frame.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index 3d8323233f..9e594c6424 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -26,6 +26,7 @@
 #include "libavformat/mux.h"
 #include "libavformat/version.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/frame.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/time.h"
diff --git a/libavdevice/xv.c b/libavdevice/xv.c
index 441f854121..b3d79d57a8 100644
--- a/libavdevice/xv.c
+++ b/libavdevice/xv.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include "libavutil/frame.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index 2b407c016f..10942ecfa0 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
 #include "libavutil/dict.h"
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 356b4de931..7ff0cf3429 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -23,12 +23,14 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/frame.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/samplefmt.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/codec.h"
 #include "libavcodec/bsf.h"
 #include "libavcodec/codec_desc.h"
 #include "libavcodec/packet_internal.h"
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 1916aa2dc5..10ee3c87c6 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -307,10 +307,8 @@
  * @}
  */
 
-#include 
 #include   /* FILE */
 
-#include "libavcodec/codec.h"
 #include "libavcodec/codec_par.h"
 #include "libavcodec/defs.h"
 #include "libavcodec/packet.h"
@@ -325,10 +323,13 @@
  * to avoid unnecessary rebuilds. When included externally, keep including
  * the full version information. */
 #include "libavformat/version.h"
+
+#include "libavutil/frame.h"
+#include "libavcodec/codec.h"
 #endif
 
 struct AVFormatContext;
-
+struct AVFrame;
 struct AVDeviceInfoList;
 
 /**
@@ -1569,7 +1570,7 @@ typedef struct AVFormatContext {
  * the same codec_id.
  * Demuxing: Set by user
  */
-const AVCodec *video_codec;
+const struct AVCodec *video_codec;
 
 /**
  * Forced audio codec.
@@ -1577,7 +1578,7 @@ typedef struct 

Re: [FFmpeg-devel] [PATCH] lavc/libx264: enable x4->params.analyse.b_fast_pskip if mb_info is set

2023-09-02 Thread Carotti, Elias via ffmpeg-devel
On Thu, 2023-08-31 at 19:09 +0200, Stefano Sabatini wrote:
> 

> 
> > In particular why are you turning on fast_pskip silently based on a
> > completely different setting?
> 
> The patch is fixing the regression introduced by the unconditional
> setting of b_fast_pskip.
> 
> Now the question is if it makes sense to set mb_info without
> b_fast_pskip (in both case this should be probably documented).
> 
> @Elias can you comment about the mb_info/b_fast_pskip use case?

Sorry again for the delay in responding. 
We can safely remove it altogether. It's true we don't need to set it
along with mb_info.
However, it doesn't do any harm, since fast_pskip is by default set to
true by libx264 and only turned off either explicitly by the user, or
when using the placebo preset, or when doing lossless encoding 
(constant QP == 0.)
So, I agree, let's remove these three lines.
Elias




NICE SRL, viale Monte Grappa 3/5, 20124 Milano, Italia, Registro delle Imprese 
di Milano Monza Brianza Lodi REA n. 2096882, Capitale Sociale: 10.329,14 EUR 
i.v., Cod. Fisc. e P.IVA 01133050052, Societa con Socio Unico


___
ffmpeg-devel mailing list
ffmpeg-devel@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] ffprobe: factorize side data printing to dedicated function

2023-09-02 Thread Andreas Rheinhardt
Stefano Sabatini:
> +static void print_frame_side_data(WriterContext *w,
> +  AVFrame *frame,
> +  AVStream *stream)

I am pretty sure both frame and stream can be constified.

> +{
> +int i;

We support C99 variable declarations in for loops.

> +
> +writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_LIST);
> +
> +for (i = 0; i < frame->nb_side_data; i++) {
> +AVFrameSideData *sd = frame->side_data[i];

This can probably be const, too.

> +const char *name;

___
ffmpeg-devel mailing list
ffmpeg-devel@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 4/8] avfilter/dnn_backend_openvino: fix use uninitialized values

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

Error handling was broken since neither `ret` nor `task` has being
initialized on error path.
---
 libavfilter/dnn/dnn_backend_openvino.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 85db4ecd35..7150bf0886 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -1090,37 +1090,37 @@ static int get_output_ov(void *model, const char 
*input_name, int input_width, i
 status = ov_partial_shape_create(4, dims, _shape);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed create partial shape.\n");
-goto err;
+return ov2_map_error(status, NULL);
 }
 status = ov_const_port_get_shape(ov_model->input_port, 
_shape);
 input_shape.dims[2] = input_height;
 input_shape.dims[3] = input_width;
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed create shape for model input 
resize.\n");
-goto err;
+return ov2_map_error(status, NULL);
 }
 
 status = ov_shape_to_partial_shape(input_shape, _shape);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed create partial shape for 
model input resize.\n");
-goto err;
+return ov2_map_error(status, NULL);
 }
 
 status = ov_model_reshape_single_input(ov_model->ov_model, 
partial_shape);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to reszie model input.\n");
-goto err;
+return ov2_map_error(status, NULL);
 }
 } else {
 avpriv_report_missing_feature(ctx, "Do not support dynamic 
model.");
-goto err;
+return AVERROR(ENOTSUP);
 }
 }
 
 status = ov_model_const_output_by_name(ov_model->ov_model, output_name, 
_model->output_port);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get output port.\n");
-goto err;
+return ov2_map_error(status, NULL);
 }
 if (!ov_model->compiled_model) {
 #else
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 8/8] avfilter/dnn_backend_openvino: fix wild pointer on error path

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

When ov_model_const_input_by_name/ov_model_const_output_by_name
failed, input_port/output_port can be wild pointer.

Signed-off-by: Zhao Zhili 
---
 libavfilter/dnn/dnn_backend_openvino.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 5de27719b2..ded156289b 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -210,7 +210,10 @@ static int fill_model_input_ov(OVModel *ov_model, 
OVRequestItem *request)
 
 #if HAVE_OPENVINO2
 if (!ov_model_is_dynamic(ov_model->ov_model)) {
-ov_output_const_port_free(ov_model->input_port);
+if (ov_model->input_port) {
+ov_output_const_port_free(ov_model->input_port);
+ov_model->input_port = NULL;
+}
 status = ov_model_const_input_by_name(ov_model->ov_model, 
task->input_name, _model->input_port);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get input port shape.\n");
@@ -621,8 +624,10 @@ static int init_model_ov(OVModel *ov_model, const char 
*input_name, const char *
 ov_model_free(tmp_ov_model);
 
 //update output_port
-if (ov_model->output_port)
+if (ov_model->output_port) {
 ov_output_const_port_free(ov_model->output_port);
+ov_model->output_port = NULL;
+}
 status = ov_model_const_output_by_name(ov_model->ov_model, output_name, 
_model->output_port);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get output port.\n");
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 6/8] avfilter/dnn_backend_openvino: fix leak of ov_shape_t

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavfilter/dnn/dnn_backend_openvino.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index b3910adfc3..f9944211da 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -225,6 +225,7 @@ static int fill_model_input_ov(OVModel *ov_model, 
OVRequestItem *request)
 status = ov_port_get_element_type(ov_model->input_port, );
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get input port data type.\n");
+ov_shape_free(_shape);
 return ov2_map_error(status, NULL);
 }
 } else {
@@ -236,8 +237,10 @@ static int fill_model_input_ov(OVModel *ov_model, 
OVRequestItem *request)
 input.channels = dims[1];
 input.dt = precision_to_datatype(precision);
 input.data = av_malloc(input.height * input.width * input.channels * 
get_datatype_size(input.dt));
-if (!input.data)
+if (!input.data) {
+ov_shape_free(_shape);
 return AVERROR(ENOMEM);
+}
 input_data_ptr = input.data;
 #else
 status = ie_infer_request_get_blob(request->infer_request, 
task->input_name, _blob);
@@ -300,6 +303,7 @@ static int fill_model_input_ov(OVModel *ov_model, 
OVRequestItem *request)
 }
 #if HAVE_OPENVINO2
 status = ov_tensor_create_from_host_ptr(precision, input_shape, 
input.data, );
+ov_shape_free(_shape);
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to create tensor from host 
prt.\n");
 return ov2_map_error(status, NULL);
@@ -362,12 +366,14 @@ static void infer_completion_callback(void *args)
 status = ov_port_get_element_type(ov_model->output_port, );
 if (status != OK) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get output port data type.\n");
+ov_shape_free(_shape);
 return;
 }
 output.channels = dims[1];
 output.height   = dims[2];
 output.width= dims[3];
 av_assert0(request->lltask_count <= dims[0]);
+ov_shape_free(_shape);
 #else
 IEStatusCode status;
 dimensions_t dims;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 7/8] avfilter/dnn_backend_openvino: fix input_port/output_port leaks

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavfilter/dnn/dnn_backend_openvino.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index f9944211da..5de27719b2 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -503,6 +503,10 @@ static void dnn_free_model_ov(DNNModel **model)
 }
 ff_queue_destroy(ov_model->task_queue);
 #if HAVE_OPENVINO2
+if (ov_model->input_port)
+ov_output_const_port_free(ov_model->input_port);
+if (ov_model->output_port)
+ov_output_const_port_free(ov_model->output_port);
 if (ov_model->preprocess)
 ov_preprocess_prepostprocessor_free(ov_model->preprocess);
 if (ov_model->compiled_model)
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 5/8] avfilter/dnn_backend_openvino: fix leak or ov_core_t on error path

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavfilter/dnn/dnn_backend_openvino.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 7150bf0886..b3910adfc3 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -1213,6 +1213,7 @@ static DNNModel *dnn_load_model_ov(const char 
*model_filename, DNNFunctionType f
 if (status != OK) {
 goto err;
 }
+ov_model->core = core;
 
 status = ov_core_read_model(core, model_filename, NULL, );
 if (status != OK) {
@@ -1228,7 +1229,6 @@ static DNNModel *dnn_load_model_ov(const char 
*model_filename, DNNFunctionType f
 goto err;
 }
 ov_model->ov_model = ovmodel;
-ov_model->core = core;
 #else
 ov_model->all_input_names = NULL;
 ov_model->all_output_names = NULL;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 3/8] avfilter/dnn_backend_openvino: reduce indentation in free_model_ov

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

No functional changes except ensures model isn't null.

Signed-off-by: Zhao Zhili 
---
 libavfilter/dnn/dnn_backend_openvino.c | 89 +-
 1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 951f179b7c..85db4ecd35 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -463,58 +463,61 @@ static void infer_completion_callback(void *args)
 
 static void dnn_free_model_ov(DNNModel **model)
 {
-if (*model){
-OVModel *ov_model = (*model)->model;
-while (ff_safe_queue_size(ov_model->request_queue) != 0) {
-OVRequestItem *item = 
ff_safe_queue_pop_front(ov_model->request_queue);
-if (item && item->infer_request) {
+OVModel *ov_model;
+
+if (!model || !*model)
+return;
+
+ov_model = (*model)->model;
+while (ff_safe_queue_size(ov_model->request_queue) != 0) {
+OVRequestItem *item = ff_safe_queue_pop_front(ov_model->request_queue);
+if (item && item->infer_request) {
 #if HAVE_OPENVINO2
-ov_infer_request_free(item->infer_request);
+ov_infer_request_free(item->infer_request);
 #else
-ie_infer_request_free(>infer_request);
+ie_infer_request_free(>infer_request);
 #endif
-}
-av_freep(>lltasks);
-av_freep();
 }
-ff_safe_queue_destroy(ov_model->request_queue);
+av_freep(>lltasks);
+av_freep();
+}
+ff_safe_queue_destroy(ov_model->request_queue);
 
-while (ff_queue_size(ov_model->lltask_queue) != 0) {
-LastLevelTaskItem *item = 
ff_queue_pop_front(ov_model->lltask_queue);
-av_freep();
-}
-ff_queue_destroy(ov_model->lltask_queue);
+while (ff_queue_size(ov_model->lltask_queue) != 0) {
+LastLevelTaskItem *item = ff_queue_pop_front(ov_model->lltask_queue);
+av_freep();
+}
+ff_queue_destroy(ov_model->lltask_queue);
 
-while (ff_queue_size(ov_model->task_queue) != 0) {
-TaskItem *item = ff_queue_pop_front(ov_model->task_queue);
-av_frame_free(>in_frame);
-av_frame_free(>out_frame);
-av_freep();
-}
-ff_queue_destroy(ov_model->task_queue);
+while (ff_queue_size(ov_model->task_queue) != 0) {
+TaskItem *item = ff_queue_pop_front(ov_model->task_queue);
+av_frame_free(>in_frame);
+av_frame_free(>out_frame);
+av_freep();
+}
+ff_queue_destroy(ov_model->task_queue);
 #if HAVE_OPENVINO2
-if (ov_model->preprocess)
-ov_preprocess_prepostprocessor_free(ov_model->preprocess);
-if (ov_model->compiled_model)
-ov_compiled_model_free(ov_model->compiled_model);
-if (ov_model->ov_model)
-ov_model_free(ov_model->ov_model);
-if (ov_model->core)
-ov_core_free(ov_model->core);
+if (ov_model->preprocess)
+ov_preprocess_prepostprocessor_free(ov_model->preprocess);
+if (ov_model->compiled_model)
+ov_compiled_model_free(ov_model->compiled_model);
+if (ov_model->ov_model)
+ov_model_free(ov_model->ov_model);
+if (ov_model->core)
+ov_core_free(ov_model->core);
 #else
-if (ov_model->exe_network)
-ie_exec_network_free(_model->exe_network);
-if (ov_model->network)
-ie_network_free(_model->network);
-if (ov_model->core)
-ie_core_free(_model->core);
-av_free(ov_model->all_output_names);
-av_free(ov_model->all_input_names);
+if (ov_model->exe_network)
+ie_exec_network_free(_model->exe_network);
+if (ov_model->network)
+ie_network_free(_model->network);
+if (ov_model->core)
+ie_core_free(_model->core);
+av_free(ov_model->all_output_names);
+av_free(ov_model->all_input_names);
 #endif
-av_opt_free(_model->ctx);
-av_freep(_model);
-av_freep(model);
-}
+av_opt_free(_model->ctx);
+av_freep(_model);
+av_freep(model);
 }
 
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 2/8] avfilter/dnn_backend_openvino: fix multiple memleaks

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 libavfilter/dnn/dnn_backend_openvino.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 4922833b07..951f179b7c 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -68,12 +68,12 @@ typedef struct OVModel{
 ie_core_t *core;
 ie_network_t *network;
 ie_executable_network_t *exe_network;
+const char *all_input_names;
+const char *all_output_names;
 #endif
 SafeQueue *request_queue;   // holds OVRequestItem
 Queue *task_queue;  // holds TaskItem
 Queue *lltask_queue; // holds LastLevelTaskItem
-const char *all_input_names;
-const char *all_output_names;
 } OVModel;
 
 // one request for one call to openvino
@@ -508,7 +508,10 @@ static void dnn_free_model_ov(DNNModel **model)
 ie_network_free(_model->network);
 if (ov_model->core)
 ie_core_free(_model->core);
+av_free(ov_model->all_output_names);
+av_free(ov_model->all_input_names);
 #endif
+av_opt_free(_model->ctx);
 av_freep(_model);
 av_freep(model);
 }
@@ -1255,6 +1258,7 @@ static DNNModel *dnn_load_model_ov(const char 
*model_filename, DNNFunctionType f
 goto err;
 }
 APPEND_STRING(ov_model->all_input_names, node_name)
+ie_network_name_free(_name);
 }
 status = ie_network_get_outputs_number(ov_model->network, _count);
 if (status != OK) {
@@ -1268,6 +1272,7 @@ static DNNModel *dnn_load_model_ov(const char 
*model_filename, DNNFunctionType f
 goto err;
 }
 APPEND_STRING(ov_model->all_output_names, node_name)
+ie_network_name_free(_name);
 }
 #endif
 
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 1/8] avfilter/dnn_filter_common: fix memleak

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 libavfilter/dnn_filter_common.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavfilter/dnn_filter_common.c b/libavfilter/dnn_filter_common.c
index d175c91914..3b9182c1d1 100644
--- a/libavfilter/dnn_filter_common.c
+++ b/libavfilter/dnn_filter_common.c
@@ -159,4 +159,10 @@ void ff_dnn_uninit(DnnContext *ctx)
 if (ctx->dnn_module) {
 (ctx->dnn_module->free_model)(>model);
 }
+if (ctx->model_outputnames) {
+for (int i = 0; i < ctx->nb_outputs; i++)
+av_free(ctx->model_outputnames[i]);
+
+av_freep(>model_outputnames);
+}
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH v2 0/8] avfilter: cleanup openvino

2023-09-02 Thread Zhao Zhili
From: Zhao Zhili 

v2: rebase on master.

Please pay attension that there are a lot memleaks I don't have time to
fix. With only 100 seconds of video clip, it leaks:

SUMMARY: AddressSanitizer: 1416800 byte(s) leaked in 27808 allocation(s).

Zhao Zhili (8):
  avfilter/dnn_filter_common: fix memleak
  avfilter/dnn_backend_openvino: fix multiple memleaks
  avfilter/dnn_backend_openvino: reduce indentation in free_model_ov
  avfilter/dnn_backend_openvino: fix use uninitialized values
  avfilter/dnn_backend_openvino: fix leak or ov_core_t on error path
  avfilter/dnn_backend_openvino: fix leak of ov_shape_t
  avfilter/dnn_backend_openvino: fix input_port/output_port leaks
  avfilter/dnn_backend_openvino: fix wild pointer on error path

 libavfilter/dnn/dnn_backend_openvino.c | 127 +++--
 libavfilter/dnn_filter_common.c|   6 ++
 2 files changed, 81 insertions(+), 52 deletions(-)

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