[FFmpeg-cvslog] configure: afir filter no longer depends on rdft from avcodec

2022-02-06 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Feb  6 11:28:27 
2022 +0100| [cfe6df99fa172d6e78305c07a809a14f49cfd40a] | committer: Paul B Mahol

configure: afir filter no longer depends on rdft from avcodec

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

 configure | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/configure b/configure
index 5b19a35f59..5a8b52c77d 100755
--- a/configure
+++ b/configure
@@ -3605,8 +3605,6 @@ libzmq_protocol_deps="libzmq"
 libzmq_protocol_select="network"
 
 # filters
-afir_filter_deps="avcodec"
-afir_filter_select="rdft"
 ametadata_filter_deps="avformat"
 amovie_filter_deps="avcodec avformat"
 aresample_filter_deps="swresample"
@@ -7387,7 +7385,6 @@ done
 enabled zlib && add_cppflags -DZLIB_CONST
 
 # conditional library dependencies, in any order
-enabled afir_filter && prepend avfilter_deps "avcodec"
 enabled amovie_filter   && prepend avfilter_deps "avformat avcodec"
 enabled aresample_filter&& prepend avfilter_deps "swresample"
 enabled atempo_filter   && prepend avfilter_deps "avcodec"

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

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


[FFmpeg-cvslog] avfilter/asrc_sinc: switch to rdft from lavu/tx

2022-02-06 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Feb  6 12:43:16 
2022 +0100| [e597ea4c0ec193cd7dda1ab10265de5a921f0218] | committer: Paul B Mahol

avfilter/asrc_sinc: switch to rdft from lavu/tx

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

 configure   |  2 --
 libavfilter/asrc_sinc.c | 37 +
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/configure b/configure
index 5a8b52c77d..c915953430 100755
--- a/configure
+++ b/configure
@@ -3718,8 +3718,6 @@ showcqt_filter_suggest="libfontconfig libfreetype"
 showspatial_filter_deps="avcodec"
 showspatial_filter_select="fft"
 signature_filter_deps="gpl avcodec avformat"
-sinc_filter_deps="avcodec"
-sinc_filter_select="rdft"
 smartblur_filter_deps="gpl swscale"
 sobel_opencl_filter_deps="opencl"
 sofalizer_filter_deps="libmysofa"
diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index aaa81291a8..9ccb5694df 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -22,8 +22,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/opt.h"
-
-#include "libavcodec/avfft.h"
+#include "libavutil/tx.h"
 
 #include "audio.h"
 #include "avfilter.h"
@@ -42,7 +41,8 @@ typedef struct SincContext {
 float *coeffs;
 int64_t pts;
 
-RDFTContext *rdft, *irdft;
+AVTXContext *tx, *itx;
+av_tx_fn tx_fn, itx_fn;
 } SincContext;
 
 static int activate(AVFilterContext *ctx)
@@ -216,7 +216,7 @@ static int fir_to_phase(SincContext *s, float **h, int 
*len, int *post_len, floa
 {
 float *pi_wraps, *work, phase1 = (phase > 50.f ? 100.f - phase : phase) / 
50.f;
 int i, work_len, begin, end, imp_peak = 0, peak = 0;
-float imp_sum = 0, peak_imp_sum = 0;
+float imp_sum = 0, peak_imp_sum = 0, scale = 1.f;
 float prev_angle2 = 0, cum_2pi = 0, prev_angle1 = 0, cum_1pi = 0;
 
 for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1);
@@ -229,17 +229,16 @@ static int fir_to_phase(SincContext *s, float **h, int 
*len, int *post_len, floa
 
 memcpy(work, *h, *len * sizeof(*work));
 
-av_rdft_end(s->rdft);
-av_rdft_end(s->irdft);
-s->rdft = s->irdft = NULL;
-s->rdft  = av_rdft_init(av_log2(work_len), DFT_R2C);
-s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R);
-if (!s->rdft || !s->irdft) {
+av_tx_uninit(&s->tx);
+av_tx_uninit(&s->itx);
+av_tx_init(&s->tx,  &s->tx_fn,  AV_TX_FLOAT_RDFT, 0, work_len, &scale, 
AV_TX_INPLACE);
+av_tx_init(&s->itx, &s->itx_fn, AV_TX_FLOAT_RDFT, 1, work_len, &scale, 
AV_TX_INPLACE);
+if (!s->tx || !s->itx) {
 av_free(work);
 return AVERROR(ENOMEM);
 }
 
-av_rdft_calc(s->rdft, work);   /* Cepstral: */
+s->tx_fn(s->tx, work, work, sizeof(float));   /* Cepstral: */
 UNPACK(work, work_len);
 
 for (i = 0; i <= work_len; i += 2) {
@@ -263,7 +262,7 @@ static int fir_to_phase(SincContext *s, float **h, int 
*len, int *post_len, floa
 }
 
 PACK(work, work_len);
-av_rdft_calc(s->irdft, work);
+s->itx_fn(s->itx, work, work, sizeof(float));
 
 for (i = 0; i < work_len; i++)
 work[i] *= 2.f / work_len;
@@ -272,7 +271,7 @@ static int fir_to_phase(SincContext *s, float **h, int 
*len, int *post_len, floa
 work[i] *= 2;
 work[i + work_len / 2] = 0;
 }
-av_rdft_calc(s->rdft, work);
+s->tx_fn(s->tx, work, work, sizeof(float));
 
 for (i = 2; i < work_len; i += 2)   /* Interpolate between linear & min 
phase */
 work[i + 1] = phase1 * i / work_len * pi_wraps[work_len >> 1] + (1 - 
phase1) * (work[i + 1] + pi_wraps[i >> 1]) - pi_wraps[i >> 1];
@@ -286,7 +285,7 @@ static int fir_to_phase(SincContext *s, float **h, int 
*len, int *post_len, floa
 work[i + 1] = x * sinf(work[i + 1]);
 }
 
-av_rdft_calc(s->irdft, work);
+s->itx_fn(s->itx, work, work, sizeof(float));
 for (i = 0; i < work_len; i++)
 work[i] *= 2.f / work_len;
 
@@ -390,9 +389,8 @@ static int config_output(AVFilterLink *outlink)
 s->coeffs[i] = h[longer][i];
 av_free(h[longer]);
 
-av_rdft_end(s->rdft);
-av_rdft_end(s->irdft);
-s->rdft = s->irdft = NULL;
+av_tx_uninit(&s->tx);
+av_tx_uninit(&s->itx);
 
 return 0;
 }
@@ -402,9 +400,8 @@ static av_cold void uninit(AVFilterContext *ctx)
 SincContext *s = ctx->priv;
 
 av_freep(&s->coeffs);
-av_rdft_end(s->rdft);
-av_rdft_end(s->irdft);
-s->rdft = s->irdft = NULL;
+av_tx_uninit(&s->tx);
+av_tx_uninit(&s->itx);
 }
 
 static const AVFilterPad sinc_outputs[] = {

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

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


[FFmpeg-cvslog] avformat/udp: set ttl upper bound to 255

2022-02-06 Thread Zhao Zhili
ffmpeg | branch: master | Zhao Zhili  | Thu Jan 27 
00:22:59 2022 +0800| [9daac85da8ad94fde05ae6ec70555ef29a68605c] | committer: 
Marton Balint

avformat/udp: set ttl upper bound to 255

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9daac85da8ad94fde05ae6ec70555ef29a68605c
---

 libavformat/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 83c042d079..b441d2ea0d 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -134,7 +134,7 @@ static const AVOption options[] = {
 { "reuse",  "explicitly allow reusing UDP sockets",
OFFSET(reuse_socket),   AV_OPT_TYPE_BOOL,   { .i64 = -1 },-1, 1,   D|E 
},
 { "reuse_socket",   "explicitly allow reusing UDP sockets",
OFFSET(reuse_socket),   AV_OPT_TYPE_BOOL,   { .i64 = -1 },-1, 1,   
.flags = D|E },
 { "broadcast", "explicitly allow or disallow broadcast destination",   
OFFSET(is_broadcast),   AV_OPT_TYPE_BOOL,   { .i64 = 0  }, 0, 1,   E },
-{ "ttl","Time to live (multicast only)",   
OFFSET(ttl),AV_OPT_TYPE_INT,{ .i64 = 16 }, 0, INT_MAX, E },
+{ "ttl","Time to live (multicast only)",   
OFFSET(ttl),AV_OPT_TYPE_INT,{ .i64 = 16 }, 0, 255, E },
 { "connect","set if connect() should be called on socket", 
OFFSET(is_connected),   AV_OPT_TYPE_BOOL,   { .i64 =  0 }, 0, 1,   
.flags = D|E },
 { "fifo_size",  "set the UDP receiving circular buffer size, expressed 
as a number of packets with size of 188 bytes", OFFSET(circular_buffer_size), 
AV_OPT_TYPE_INT, {.i64 = 7*4096}, 0, INT_MAX, D },
 { "overrun_nonfatal", "survive in case of UDP receiving circular buffer 
overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,D },

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

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


[FFmpeg-cvslog] avformat/rtpproto: set ttl upper bound to 255

2022-02-06 Thread Zhao Zhili
ffmpeg | branch: master | Zhao Zhili  | Thu Jan 27 
00:23:00 2022 +0800| [03afa12762f8c07da0706075820d78affaefd5ef] | committer: 
Marton Balint

avformat/rtpproto: set ttl upper bound to 255

Also remove bogus millisecond reference from help text.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=03afa12762f8c07da0706075820d78affaefd5ef
---

 libavformat/rtpproto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index c92cda63bb..b970901d01 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -68,7 +68,7 @@ typedef struct RTPContext {
 #define D AV_OPT_FLAG_DECODING_PARAM
 #define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-{ "ttl","Time to live (in milliseconds, multicast only)",  
 OFFSET(ttl), AV_OPT_TYPE_INT,{ .i64 = -1 },
-1, INT_MAX, .flags = D|E },
+{ "ttl","Time to live (multicast only)",   
 OFFSET(ttl), AV_OPT_TYPE_INT,{ .i64 = -1 },
-1, 255, .flags = D|E },
 { "buffer_size","Send/Receive buffer size (in bytes)", 
 OFFSET(buffer_size), AV_OPT_TYPE_INT,{ .i64 = -1 },
-1, INT_MAX, .flags = D|E },
 { "rtcp_port",  "Custom rtcp port",
 OFFSET(rtcp_port),   AV_OPT_TYPE_INT,{ .i64 = -1 },
-1, INT_MAX, .flags = D|E },
 { "local_rtpport",  "Local rtp port",  
 OFFSET(local_rtpport),   AV_OPT_TYPE_INT,{ .i64 = -1 },
-1, INT_MAX, .flags = D|E },

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

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


[FFmpeg-cvslog] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()

2022-02-06 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Jan 13 17:30:53 2022 +0100| [2d71f93c7c0e4c624df3fd53ba162135b0cbe32a] | 
committer: Andreas Rheinhardt

avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()

Avoids code duplication. It furthermore properly checks
for buf_size to be > 0 before doing anything.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2d71f93c7c0e4c624df3fd53ba162135b0cbe32a
---

 libavutil/fifo.c | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index d741bdd395..e1f2175530 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -194,26 +194,7 @@ int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, 
int offset, int buf_siz
 int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size,
  void (*func)(void *, void *, int))
 {
-uint8_t *rptr = f->rptr;
-
-if (buf_size > av_fifo_size(f))
-return AVERROR(EINVAL);
-
-do {
-int len = FFMIN(f->end - rptr, buf_size);
-if (func)
-func(dest, rptr, len);
-else {
-memcpy(dest, rptr, len);
-dest = (uint8_t *)dest + len;
-}
-rptr += len;
-if (rptr >= f->end)
-rptr -= f->end - f->buffer;
-buf_size -= len;
-} while (buf_size > 0);
-
-return 0;
+return av_fifo_generic_peek_at(f, dest, 0, buf_size, func);
 }
 
 int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size,

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

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


[FFmpeg-cvslog] lavu/fifo: disallow overly large fifo sizes

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jan  3 
13:09:33 2022 +0100| [5939c8d3616a559fb5994e570c96e1a0ecad528b] | committer: 
Andreas Rheinhardt

lavu/fifo: disallow overly large fifo sizes

The API currently allows creating FIFOs up to
- UINT_MAX: av_fifo_alloc(), av_fifo_realloc(), av_fifo_grow()
- SIZE_MAX: av_fifo_alloc_array()
However the usable limit is determined by
- rndx/wndx being uint32_t
- av_fifo_[size,space] returning int
so no FIFO should be larger than the smallest of
- INT_MAX
- UINT32_MAX
- SIZE_MAX
(which should be INT_MAX an all commonly used platforms).
Return an error on trying to allocate FIFOs larger than this limit.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5939c8d3616a559fb5994e570c96e1a0ecad528b
---

 libavutil/fifo.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index e1f2175530..55621f0dca 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -20,14 +20,23 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "avassert.h"
 #include "common.h"
 #include "fifo.h"
 
+#define OLD_FIFO_SIZE_MAX (size_t)FFMIN3(INT_MAX, UINT32_MAX, SIZE_MAX)
+
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
 {
 AVFifoBuffer *f;
-void *buffer = av_realloc_array(NULL, nmemb, size);
+void *buffer;
+
+if (nmemb > OLD_FIFO_SIZE_MAX / size)
+return NULL;
+
+buffer = av_realloc_array(NULL, nmemb, size);
 if (!buffer)
 return NULL;
 f = av_mallocz(sizeof(AVFifoBuffer));
@@ -82,6 +91,9 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
 {
 unsigned int old_size = f->end - f->buffer;
 
+if (new_size > OLD_FIFO_SIZE_MAX)
+return AVERROR(EINVAL);
+
 if (old_size < new_size) {
 size_t offset_r = f->rptr - f->buffer;
 size_t offset_w = f->wptr - f->buffer;

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

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


[FFmpeg-cvslog] lavu/fifo: add a flag for automatically growing the FIFO as needed

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
16:32:49 2022 +0100| [14429f8fec231e1d6e0bfdb3f646e7461d11c736] | committer: 
Andreas Rheinhardt

lavu/fifo: add a flag for automatically growing the FIFO as needed

This will not increase the FIFO beyond 1MB, unless the caller explicitly
specifies otherwise.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=14429f8fec231e1d6e0bfdb3f646e7461d11c736
---

 doc/APIchanges   |  2 +-
 libavutil/fifo.c | 39 +--
 libavutil/fifo.h | 15 ++-
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index ca9c476346..0de7004e95 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -21,7 +21,7 @@ API changes, most recent first:
   av_fifo_can_write(), av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(),
   av_fifo_write_from_cb(), av_fifo_read(), av_fifo_read_to_cb(),
   av_fifo_peek(), av_fifo_peek_to_cb(), av_fifo_drain2(), av_fifo_reset2(),
-  av_fifo_freep2().
+  av_fifo_freep2(), av_fifo_auto_grow_limit().
 
 2022-01-26 - af94ab7c7c0 - lavu 57.19.100 - tx.h
   Add AV_TX_FLOAT_RDFT, AV_TX_DOUBLE_RDFT and AV_TX_INT32_RDFT.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 0001ccbd43..4137ae2fd9 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -26,6 +26,9 @@
 #include "common.h"
 #include "fifo.h"
 
+// by default the FIFO can be auto-grown to 1MB
+#define AUTO_GROW_DEFAULT_BYTES (1024 * 1024)
+
 struct AVFifo {
 uint8_t *buffer;
 
@@ -33,6 +36,9 @@ struct AVFifo {
 size_t offset_r, offset_w;
 // distinguishes the ambiguous situation offset_r == offset_w
 intis_empty;
+
+unsigned int flags;
+size_t   auto_grow_limit;
 };
 
 AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
@@ -59,9 +65,17 @@ AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
 f->elem_size = elem_size;
 f->is_empty  = 1;
 
+f->flags   = flags;
+f->auto_grow_limit = FFMAX(AUTO_GROW_DEFAULT_BYTES / elem_size, 1);
+
 return f;
 }
 
+void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems)
+{
+f->auto_grow_limit = max_elems;
+}
+
 size_t av_fifo_elem_size(const AVFifo *f)
 {
 return f->elem_size;
@@ -109,6 +123,26 @@ int av_fifo_grow2(AVFifo *f, size_t inc)
 return 0;
 }
 
+static int fifo_check_space(AVFifo *f, size_t to_write)
+{
+const size_t can_write = av_fifo_can_write(f);
+const size_t need_grow = to_write > can_write ? to_write - can_write : 0;
+size_t can_grow;
+
+if (!need_grow)
+return 0;
+
+can_grow = f->auto_grow_limit > f->nb_elems ?
+   f->auto_grow_limit - f->nb_elems : 0;
+if ((f->flags & AV_FIFO_FLAG_AUTO_GROW) && need_grow <= can_grow) {
+// allocate a bit more than necessary, if we can
+const size_t inc = (need_grow < can_grow / 2 ) ? need_grow * 2 : 
can_grow;
+return av_fifo_grow2(f, inc);
+}
+
+return AVERROR(ENOSPC);
+}
+
 static int fifo_write_common(AVFifo *f, const uint8_t *buf, size_t *nb_elems,
  AVFifoCB read_cb, void *opaque)
 {
@@ -116,8 +150,9 @@ static int fifo_write_common(AVFifo *f, const uint8_t *buf, 
size_t *nb_elems,
 size_t offset_w = f->offset_w;
 int ret = 0;
 
-if (to_write > av_fifo_can_write(f))
-return AVERROR(ENOSPC);
+ret = fifo_check_space(f, to_write);
+if (ret < 0)
+return ret;
 
 while (to_write > 0) {
 size_tlen = FFMIN(f->nb_elems - offset_w, to_write);
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index f455022e3c..55548fbeb4 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -48,13 +48,20 @@ typedef struct AVFifo AVFifo;
  */
 typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems);
 
+/**
+ * Automatically resize the FIFO on writes, so that the data fits. This
+ * automatic resizing happens up to a limit that can be modified with
+ * av_fifo_auto_grow_limit().
+ */
+#define AV_FIFO_FLAG_AUTO_GROW  (1 << 0)
+
 /**
  * Allocate and initialize an AVFifo with a given element size.
  *
  * @param elems initial number of elements that can be stored in the FIFO
  * @param elem_size Size in bytes of a single element. Further operations on
  *  the returned FIFO will implicitly use this element size.
- * @param flags currently unused, must be 0
+ * @param flags a combination of AV_FIFO_FLAG_*
  *
  * @return newly-allocated AVFifo on success, a negative error code on failure
  */
@@ -67,6 +74,12 @@ AVFifo *av_fifo_alloc2(size_t elems, size_t elem_size,
  */
 size_t av_fifo_elem_size(const AVFifo *f);
 
+/**
+ * Set the maximum size (in elements) to which the FIFO can be resized
+ * automatically. Has no effect unless AV_FIFO_FLAG_AUTO_GROW is used.
+ */
+void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems);
+
 /**
  * @return number of elements available for reading from the given FIFO.
  */

___
ffmpeg-cvslog ma

[FFmpeg-cvslog] lavu/fifo: Add new AVFifo API based upon the notion of element size

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Dec 30 
19:56:11 2021 +0100| [7329b22c058cf271e9ea3aa6e8ab2bb1c462d99f] | committer: 
Andreas Rheinhardt

lavu/fifo: Add new AVFifo API based upon the notion of element size

Many AVFifoBuffer users operate on fixed-size elements (e.g. pointers),
but the current FIFO API deals exclusively in bytes, requiring extra
complexity in all these callers.

Add a new AVFifo API creating a FIFO with an element size
that may be larger than a byte. All operations on such a FIFO then
operate on complete elements.

This API does not reuse AVFifoBuffer and its API at all, but instead uses
an opaque struct called AVFifo. The AVFifoBuffer API will be deprecated
in a future commit once all of its users have been switched to the new
API.

Not reusing AVFifoBuffer also allowed to use the full range of size_t
from the beginning.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7329b22c058cf271e9ea3aa6e8ab2bb1c462d99f
---

 doc/APIchanges  |   9 +++
 libavutil/fifo.c| 226 
 libavutil/fifo.h| 179 +
 libavutil/version.h |   2 +-
 4 files changed, 415 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 315a04c952..ca9c476346 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,15 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-02-07 - xx - lavu 57.20.100 - fifo.h
+  Add a new FIFO API, which allows setting a FIFO element size.
+  This API operates on these elements rather than on bytes.
+  Add av_fifo_alloc2(), av_fifo_elem_size(), av_fifo_can_read(),
+  av_fifo_can_write(), av_fifo_grow2(), av_fifo_drain2(), av_fifo_write(),
+  av_fifo_write_from_cb(), av_fifo_read(), av_fifo_read_to_cb(),
+  av_fifo_peek(), av_fifo_peek_to_cb(), av_fifo_drain2(), av_fifo_reset2(),
+  av_fifo_freep2().
+
 2022-01-26 - af94ab7c7c0 - lavu 57.19.100 - tx.h
   Add AV_TX_FLOAT_RDFT, AV_TX_DOUBLE_RDFT and AV_TX_INT32_RDFT.
 
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 55621f0dca..0001ccbd43 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -26,6 +26,232 @@
 #include "common.h"
 #include "fifo.h"
 
+struct AVFifo {
+uint8_t *buffer;
+
+size_t elem_size, nb_elems;
+size_t offset_r, offset_w;
+// distinguishes the ambiguous situation offset_r == offset_w
+intis_empty;
+};
+
+AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
+   unsigned int flags)
+{
+AVFifo *f;
+void *buffer = NULL;
+
+if (!elem_size)
+return NULL;
+
+if (nb_elems) {
+buffer = av_realloc_array(NULL, nb_elems, elem_size);
+if (!buffer)
+return NULL;
+}
+f = av_mallocz(sizeof(*f));
+if (!f) {
+av_free(buffer);
+return NULL;
+}
+f->buffer= buffer;
+f->nb_elems  = nb_elems;
+f->elem_size = elem_size;
+f->is_empty  = 1;
+
+return f;
+}
+
+size_t av_fifo_elem_size(const AVFifo *f)
+{
+return f->elem_size;
+}
+
+size_t av_fifo_can_read(const AVFifo *f)
+{
+if (f->offset_w <= f->offset_r && !f->is_empty)
+return f->nb_elems - f->offset_r + f->offset_w;
+return f->offset_w - f->offset_r;
+}
+
+size_t av_fifo_can_write(const AVFifo *f)
+{
+return f->nb_elems - av_fifo_can_read(f);
+}
+
+int av_fifo_grow2(AVFifo *f, size_t inc)
+{
+uint8_t *tmp;
+
+if (inc > SIZE_MAX - f->nb_elems)
+return AVERROR(EINVAL);
+
+tmp = av_realloc_array(f->buffer, f->nb_elems + inc, f->elem_size);
+if (!tmp)
+return AVERROR(ENOMEM);
+f->buffer = tmp;
+
+// move the data from the beginning of the ring buffer
+// to the newly allocated space
+if (f->offset_w <= f->offset_r && !f->is_empty) {
+const size_t copy = FFMIN(inc, f->offset_w);
+memcpy(tmp + f->nb_elems * f->elem_size, tmp, copy * f->elem_size);
+if (copy < f->offset_w) {
+memmove(tmp, tmp + copy * f->elem_size,
+(f->offset_w - copy) * f->elem_size);
+f->offset_w -= copy;
+} else
+f->offset_w = f->nb_elems + copy;
+}
+
+f->nb_elems += inc;
+
+return 0;
+}
+
+static int fifo_write_common(AVFifo *f, const uint8_t *buf, size_t *nb_elems,
+ AVFifoCB read_cb, void *opaque)
+{
+size_t to_write = *nb_elems;
+size_t offset_w = f->offset_w;
+int ret = 0;
+
+if (to_write > av_fifo_can_write(f))
+return AVERROR(ENOSPC);
+
+while (to_write > 0) {
+size_tlen = FFMIN(f->nb_elems - offset_w, to_write);
+uint8_t *wptr = f->buffer + offset_w * f->elem_size;
+
+if (read_cb) {
+ret = read_cb(opaque, wptr, &len);
+if (ret < 0 || len == 0)
+break;
+} else {
+memcpy(wptr, buf, len * f->elem_size);
+buf += len * f->elem_size;
+}
+offset_w 

[FFmpeg-cvslog] lavu/tests/fifo: switch to the new API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jan 11 
21:38:49 2022 +0100| [93ed3755746227dee13f71605d9a9d2fab6d524c] | committer: 
Andreas Rheinhardt

lavu/tests/fifo: switch to the new API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=93ed3755746227dee13f71605d9a9d2fab6d524c
---

 libavutil/tests/fifo.c | 47 +--
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c
index a17d913233..579602ccf3 100644
--- a/libavutil/tests/fifo.c
+++ b/libavutil/tests/fifo.c
@@ -23,78 +23,73 @@
 int main(void)
 {
 /* create a FIFO buffer */
-AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
+AVFifo *fifo = av_fifo_alloc2(13, sizeof(int), 0);
 int i, j, n, *p;
 
 /* fill data */
-for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
-av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+for (i = 0; av_fifo_can_write(fifo); i++)
+av_fifo_write(fifo, &i, 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, &j, 1, i);
 printf("%d: %d\n", i, j);
 }
 printf("\n");
 
 /* generic peek at FIFO */
 
-n = av_fifo_size(fifo);
-p = malloc(n);
+n = av_fifo_can_read(fifo);
+p = malloc(n * av_fifo_elem_size(fifo));
 if (p == NULL) {
 fprintf(stderr, "failed to allocate memory.\n");
 exit(1);
 }
 
-(void) av_fifo_generic_peek(fifo, p, n, NULL);
+(void) av_fifo_peek(fifo, p, n, 0);
 
 /* read data at p */
-n /= sizeof(int);
 for(i = 0; i < n; ++i)
 printf("%d: %d\n", i, p[i]);
 
 putchar('\n');
 
 /* read data */
-for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
-av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
+for (i = 0; av_fifo_can_read(fifo); i++) {
+av_fifo_read(fifo, &j, 1);
 printf("%d ", j);
 }
 printf("\n");
 
-/* test *ndx overflow */
-av_fifo_reset(fifo);
-fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5;
-
 /* fill data */
-for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
-av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+for (i = 0; av_fifo_can_write(fifo); i++)
+av_fifo_write(fifo, &i, 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, &j, 1, i);
 printf("%d: %d\n", i, j);
 }
 putchar('\n');
 
 /* test fifo_grow */
-(void) av_fifo_grow(fifo, 15 * sizeof(int));
+(void) av_fifo_grow2(fifo, 15);
 
 /* fill data */
-n = av_fifo_size(fifo) / sizeof(int);
-for (i = n; av_fifo_space(fifo) >= sizeof(int); ++i)
-av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+n = av_fifo_can_read(fifo);
+for (i = n; av_fifo_can_write(fifo); ++i)
+av_fifo_write(fifo, &i, 1);
 
 /* peek_at at FIFO */
-n = av_fifo_size(fifo) / sizeof(int);
+n = av_fifo_can_read(fifo);
 for (i = 0; i < n; i++) {
-av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
+av_fifo_peek(fifo, &j, 1, i);
 printf("%d: %d\n", i, j);
 }
 
-av_fifo_free(fifo);
+av_fifo_freep2(&fifo);
 free(p);
 
 return 0;

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

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


[FFmpeg-cvslog] lavc/avcodec: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [37e70d480218b041d247c7be92d21556343b3c9a] | committer: 
Andreas Rheinhardt

lavc/avcodec: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=37e70d480218b041d247c7be92d21556343b3c9a
---

 libavcodec/avcodec.c  | 17 ++---
 libavcodec/decode.c   | 24 +---
 libavcodec/internal.h |  2 +-
 3 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..4df834c708 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 avci->es.in_frame = av_frame_alloc();
 avci->in_pkt = av_packet_alloc();
 avci->last_pkt_props = av_packet_alloc();
-avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props));
+avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
+ AV_FIFO_FLAG_AUTO_GROW);
 if (!avci->buffer_frame || !avci->buffer_pkt  ||
 !avci->es.in_frame  || !avci->in_pkt ||
 !avci->last_pkt_props || !avci->pkt_props) {
@@ -399,13 +400,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 av_packet_unref(avci->buffer_pkt);
 
 av_packet_unref(avci->last_pkt_props);
-while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
-av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, 
sizeof(*avci->last_pkt_props),
- NULL);
+while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
 av_packet_unref(avci->last_pkt_props);
-}
-av_fifo_reset(avci->pkt_props);
 
 av_frame_unref(avci->es.in_frame);
 av_packet_unref(avci->in_pkt);
@@ -464,12 +460,11 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 av_frame_free(&avci->buffer_frame);
 av_packet_free(&avci->buffer_pkt);
 if (avci->pkt_props) {
-while (av_fifo_size(avci->pkt_props) >= 
sizeof(*avci->last_pkt_props)) {
+while (av_fifo_can_read(avci->pkt_props)) {
 av_packet_unref(avci->last_pkt_props);
-av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
+av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
 }
-av_fifo_freep(&avci->pkt_props);
+av_fifo_freep2(&avci->pkt_props);
 }
 av_packet_free(&avci->last_pkt_props);
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 4f9b949926..7423a177c7 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -165,26 +165,19 @@ static int extract_packet_props(AVCodecInternal *avci, 
const AVPacket *pkt)
 int ret = 0;
 
 if (IS_EMPTY(avci->last_pkt_props)) {
-if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) {
-av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
-} else
+if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
 return copy_packet_props(avci->last_pkt_props, pkt);
 }
 
-if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) {
-ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt));
-if (ret < 0)
-return ret;
-}
-
 ret = copy_packet_props(&tmp, pkt);
 if (ret < 0)
 return ret;
 
-av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL);
+ret = av_fifo_write(avci->pkt_props, &tmp, 1);
+if (ret < 0)
+av_packet_unref(&tmp);
 
-return 0;
+return ret;
 }
 
 static int decode_bsfs_init(AVCodecContext *avctx)
@@ -544,9 +537,10 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 avci->draining_done = 1;
 
 if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
-IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= 
sizeof(*avci->last_pkt_props))
-av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, 
sizeof(*avci->last_pkt_props), NULL);
+IS_EMPTY(avci->last_pkt_props)) {
+// May fail if the FIFO is empty.
+av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
+}
 
 if (!ret) {
 frame->best_effort_timestamp = guess_correct_pts(avctx,
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 72ca1553f6..4e864535f1 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -149,7 +149,7 @@ typedef struct AVCodecInternal {
  * for decoding.
  */
 AVPacket *last_pkt_props;
-AVFifoBuffer *pkt_props;
+AVFifo *pkt_props;
 
 /**
  * temporary buffer used for encoders to store their bitstream

___

[FFmpeg-cvslog] lavc/amfenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jan 10 
11:04:36 2022 +0100| [70611d7f3b8521a4b91d81a023d80287d4cad07b] | committer: 
Andreas Rheinhardt

lavc/amfenc: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=70611d7f3b8521a4b91d81a023d80287d4cad07b
---

 libavcodec/amfenc.c | 43 ++-
 libavcodec/amfenc.h |  2 +-
 2 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index fb23ed738c..0e5117c5a3 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -117,8 +117,9 @@ static int amf_load_library(AVCodecContext *avctx)
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
-// hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
-ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
+// hardcoded to current HW queue size - will auto-realloc if too small
+ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, 
sizeof(int64_t),
+ AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->timestamp_list) {
 return AVERROR(ENOMEM);
 }
@@ -403,7 +404,7 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
 ctx->version = 0;
 ctx->delayed_drain = 0;
 av_frame_free(&ctx->delayed_frame);
-av_fifo_freep(&ctx->timestamp_list);
+av_fifo_freep2(&ctx->timestamp_list);
 
 return 0;
 }
@@ -432,18 +433,6 @@ static int amf_copy_surface(AVCodecContext *avctx, const 
AVFrame *frame,
 return 0;
 }
 
-static inline int timestamp_queue_enqueue(AVCodecContext *avctx, int64_t 
timestamp)
-{
-AmfContext *ctx = avctx->priv_data;
-if (av_fifo_space(ctx->timestamp_list) < sizeof(timestamp)) {
-if (av_fifo_grow(ctx->timestamp_list, sizeof(timestamp)) < 0) {
-return AVERROR(ENOMEM);
-}
-}
-av_fifo_generic_write(ctx->timestamp_list, ×tamp, sizeof(timestamp), 
NULL);
-return 0;
-}
-
 static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer 
*buffer)
 {
 AmfContext  *ctx = avctx->priv_data;
@@ -479,21 +468,17 @@ static int amf_copy_buffer(AVCodecContext *avctx, 
AVPacket *pkt, AMFBuffer *buff
 pkt->pts = var.int64Value; // original pts
 
 
-AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, 
AVERROR_UNKNOWN, "timestamp_list is empty\n");
-
-av_fifo_generic_read(ctx->timestamp_list, ×tamp, sizeof(timestamp), 
NULL);
+AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, ×tamp, 1) 
>= 0,
+AVERROR_UNKNOWN, "timestamp_list is empty\n");
 
 // calc dts shift if max_b_frames > 0
 if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
 int64_t timestamp_last = AV_NOPTS_VALUE;
-AMF_RETURN_IF_FALSE(ctx, av_fifo_size(ctx->timestamp_list) > 0, 
AVERROR_UNKNOWN,
+size_t can_read = av_fifo_can_read(ctx->timestamp_list);
+
+AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN,
 "timestamp_list is empty while max_b_frames = %d\n", 
avctx->max_b_frames);
-av_fifo_generic_peek_at(
-ctx->timestamp_list,
-×tamp_last,
-(av_fifo_size(ctx->timestamp_list) / sizeof(timestamp) - 1) * 
sizeof(timestamp_last),
-sizeof(timestamp_last),
-NULL);
+av_fifo_peek(ctx->timestamp_list, ×tamp_last, 1, can_read - 1);
 if (timestamp < 0 || timestamp_last < AV_NOPTS_VALUE) {
 return AVERROR(ERANGE);
 }
@@ -710,9 +695,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SubmitInput() failed with error %d\n", res);
 
 av_frame_unref(frame);
-if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
+ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
+if (ret < 0)
 return ret;
-}
 }
 }
 
@@ -751,9 +736,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 av_frame_unref(ctx->delayed_frame);
 AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, 
"Repeated SubmitInput() failed with error %d\n", res);
 
-if ((ret = timestamp_queue_enqueue(avctx, pts)) < 0) {
+ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
+if (ret < 0)
 return ret;
-}
 } else {
 av_log(avctx, AV_LOG_WARNING, "Data acquired but delayed 
frame submission got AMF_INPUT_FULL- should not happen\n");
 }
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 358b2ef778..1ab98d2f78 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -72,7 +72,7 @@ typedef struct AmfContext {
 AVFrame*delayed_frame;
 
  

[FFmpeg-cvslog] lavc/libvorbisenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
12:40:10 2022 +0100| [a718d84e927434aac958aa44543cd5a1952309dd] | committer: 
Andreas Rheinhardt

lavc/libvorbisenc: switch to new FIFO API

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

 libavcodec/libvorbisenc.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index fa0d5f4b42..b657f0157a 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -46,7 +46,7 @@ typedef struct LibvorbisEncContext {
 vorbis_info vi; /**< vorbis_info used during init   */
 vorbis_dsp_state vd;/**< DSP state used for analysis*/
 vorbis_block vb;/**< vorbis_block used for analysis */
-AVFifoBuffer *pkt_fifo; /**< output packet buffer   */
+AVFifo *pkt_fifo;   /**< output packet buffer   */
 int eof;/**< end-of-file flag   */
 int dsp_initialized;/**< vd has been initialized*/
 vorbis_comment vc;  /**< VorbisComment info */
@@ -196,7 +196,7 @@ static av_cold int libvorbis_encode_close(AVCodecContext 
*avctx)
 vorbis_dsp_clear(&s->vd);
 vorbis_info_clear(&s->vi);
 
-av_fifo_freep(&s->pkt_fifo);
+av_fifo_freep2(&s->pkt_fifo);
 ff_af_queue_close(&s->afq);
 
 av_vorbis_parse_free(&s->vp);
@@ -271,7 +271,7 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
 avctx->frame_size = LIBVORBIS_FRAME_SIZE;
 ff_af_queue_init(avctx, &s->afq);
 
-s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE);
+s->pkt_fifo = av_fifo_alloc2(BUFFER_SIZE, 1, 0);
 if (!s->pkt_fifo) {
 ret = AVERROR(ENOMEM);
 goto error;
@@ -327,12 +327,12 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 
 /* add any available packets to the output packet buffer */
 while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) {
-if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) {
+if (av_fifo_can_write(s->pkt_fifo) < sizeof(ogg_packet) + 
op.bytes) {
 av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n");
 return AVERROR_BUG;
 }
-av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
-av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL);
+av_fifo_write(s->pkt_fifo, &op, sizeof(ogg_packet));
+av_fifo_write(s->pkt_fifo, op.packet, op.bytes);
 }
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
@@ -344,15 +344,13 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 return vorbis_error_to_averror(ret);
 }
 
-/* check for available packets */
-if (av_fifo_size(s->pkt_fifo) < sizeof(ogg_packet))
+/* Read an available packet if possible */
+if (av_fifo_read(s->pkt_fifo, &op, sizeof(ogg_packet)) < 0)
 return 0;
 
-av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
-
 if ((ret = ff_get_encode_buffer(avctx, avpkt, op.bytes, 0)) < 0)
 return ret;
-av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL);
+av_fifo_read(s->pkt_fifo, avpkt->data, op.bytes);
 
 avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos);
 

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

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


[FFmpeg-cvslog] lavc/cuviddec: do not reallocate the fifo unnecessarily

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jan  5 
15:16:23 2022 +0100| [de40342c0442ce5bd423ba373e465625bc504f3e] | committer: 
Andreas Rheinhardt

lavc/cuviddec: do not reallocate the fifo unnecessarily

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

 libavcodec/cuviddec.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index f03bbd8c4b..b1a3d674ab 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -1030,13 +1030,7 @@ static void cuvid_flush(AVCodecContext *avctx)
 if (ret < 0)
 goto error;
 
-av_fifo_freep(&ctx->frame_queue);
-
-ctx->frame_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(CuvidParsedFrame));
-if (!ctx->frame_queue) {
-av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on 
flush\n");
-return;
-}
+av_fifo_reset(ctx->frame_queue);
 
 if (ctx->cudecoder) {
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);

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

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


[FFmpeg-cvslog] lavc/libvpxenc: switch to the new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
16:46:13 2022 +0100| [4b066b53b27dc3a7227dac793fb790715b552dae] | committer: 
Andreas Rheinhardt

lavc/libvpxenc: switch to the new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b066b53b27dc3a7227dac793fb790715b552dae
---

 libavcodec/libvpxenc.c | 35 ++-
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 10e5a22fa9..ab5d31e4c4 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -128,7 +128,7 @@ typedef struct VPxEncoderContext {
 int corpus_complexity;
 int tpl_model;
 int discard_hdr10_plus;
-AVFifoBuffer *hdr10_plus_fifo;
+AVFifo *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
  * encounter a frame with ROI side data.
@@ -324,39 +324,23 @@ static av_cold void free_frame_list(struct FrameListData 
*list)
 }
 }
 
-static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus 
*data)
-{
-int err = av_fifo_grow(fifo, sizeof(*data));
-if (err < 0)
-return err;
-av_fifo_generic_write(fifo, data, sizeof(*data), NULL);
-return 0;
-}
-
-static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
+static av_cold void free_hdr10_plus_fifo(AVFifo **fifo)
 {
 FrameHDR10Plus frame_hdr10_plus;
-while (av_fifo_size(*fifo) >= sizeof(frame_hdr10_plus)) {
-av_fifo_generic_read(*fifo, &frame_hdr10_plus, 
sizeof(frame_hdr10_plus), NULL);
+while (av_fifo_read(*fifo, &frame_hdr10_plus, 1) >= 0)
 av_buffer_unref(&frame_hdr10_plus.hdr10_plus);
-}
-av_fifo_freep(fifo);
+av_fifo_freep2(fifo);
 }
 
-static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt)
+static int copy_hdr10_plus_to_pkt(AVFifo *fifo, AVPacket *pkt)
 {
 FrameHDR10Plus frame_hdr10_plus;
 uint8_t *data;
-if (!pkt)
-return 0;
-if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus))
+if (!pkt || av_fifo_peek(fifo, &frame_hdr10_plus, 1, 0) < 0)
 return 0;
-av_fifo_generic_peek(fifo, &frame_hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
 if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts)
 return 0;
-av_fifo_generic_read(fifo, &frame_hdr10_plus, sizeof(frame_hdr10_plus), 
NULL);
-if (!frame_hdr10_plus.hdr10_plus)
-return 0;
+av_fifo_drain2(fifo, 1);
 
 data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
frame_hdr10_plus.hdr10_plus->size);
 if (!data) {
@@ -933,7 +917,8 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 // it has PQ trc (SMPTE2084).
 if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) 
{
 ctx->discard_hdr10_plus = 0;
-ctx->hdr10_plus_fifo = av_fifo_alloc(sizeof(FrameHDR10Plus));
+ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus),
+  AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->hdr10_plus_fifo)
 return AVERROR(ENOMEM);
 }
@@ -1727,7 +1712,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 data.hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf);
 if (!data.hdr10_plus)
 return AVERROR(ENOMEM);
-err = add_hdr10_plus(ctx->hdr10_plus_fifo, &data);
+err = av_fifo_write(ctx->hdr10_plus_fifo, &data, 1);
 if (err < 0) {
 av_buffer_unref(&data.hdr10_plus);
 return err;

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

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


[FFmpeg-cvslog] lavc/cuviddec: convert to the new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jan  5 
15:26:33 2022 +0100| [6eaf5cd00a93cdab1f972bdaf7db46450cb1e6ec] | committer: 
Andreas Rheinhardt

lavc/cuviddec: convert to the new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6eaf5cd00a93cdab1f972bdaf7db46450cb1e6ec
---

 libavcodec/cuviddec.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index b1a3d674ab..1b525cd804 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -78,7 +78,7 @@ typedef struct CuvidContext
 AVBufferRef *hwdevice;
 AVBufferRef *hwframe;
 
-AVFifoBuffer *frame_queue;
+AVFifo  *frame_queue;
 
 int deint_mode;
 int deint_mode_current;
@@ -363,13 +363,13 @@ static int CUDAAPI cuvid_handle_picture_display(void 
*opaque, CUVIDPARSERDISPINF
 parsed_frame.dispinfo.progressive_frame = ctx->progressive_sequence;
 
 if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) {
-av_fifo_generic_write(ctx->frame_queue, &parsed_frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
 } else {
 parsed_frame.is_deinterlacing = 1;
-av_fifo_generic_write(ctx->frame_queue, &parsed_frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
 if (!ctx->drop_second_field) {
 parsed_frame.second_field = 1;
-av_fifo_generic_write(ctx->frame_queue, &parsed_frame, 
sizeof(CuvidParsedFrame), NULL);
+av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
 }
 }
 
@@ -384,7 +384,7 @@ static int cuvid_is_buffer_full(AVCodecContext *avctx)
 if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave && 
!ctx->drop_second_field)
 delay *= 2;
 
-return (av_fifo_size(ctx->frame_queue) / sizeof(CuvidParsedFrame)) + delay 
>= ctx->nb_surfaces;
+return av_fifo_can_read(ctx->frame_queue) + delay >= ctx->nb_surfaces;
 }
 
 static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
@@ -458,6 +458,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
 AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
 CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
+CuvidParsedFrame parsed_frame;
 CUdeviceptr mapped_frame = 0;
 int ret = 0, eret = 0;
 
@@ -487,16 +488,13 @@ static int cuvid_output_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret < 0)
 return ret;
 
-if (av_fifo_size(ctx->frame_queue)) {
+if (av_fifo_read(ctx->frame_queue, &parsed_frame, 1) >= 0) {
 const AVPixFmtDescriptor *pixdesc;
-CuvidParsedFrame parsed_frame;
 CUVIDPROCPARAMS params;
 unsigned int pitch = 0;
 int offset = 0;
 int i;
 
-av_fifo_generic_read(ctx->frame_queue, &parsed_frame, 
sizeof(CuvidParsedFrame), NULL);
-
 memset(¶ms, 0, sizeof(params));
 params.progressive_frame = parsed_frame.dispinfo.progressive_frame;
 params.second_field = parsed_frame.second_field;
@@ -657,7 +655,7 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
 CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
 
-av_fifo_freep(&ctx->frame_queue);
+av_fifo_freep2(&ctx->frame_queue);
 
 ctx->cudl->cuCtxPushCurrent(cuda_ctx);
 
@@ -834,7 +832,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
 goto error;
 }
 
-ctx->frame_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(CuvidParsedFrame));
+ctx->frame_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(CuvidParsedFrame), 0);
 if (!ctx->frame_queue) {
 ret = AVERROR(ENOMEM);
 goto error;
@@ -1030,7 +1028,7 @@ static void cuvid_flush(AVCodecContext *avctx)
 if (ret < 0)
 goto error;
 
-av_fifo_reset(ctx->frame_queue);
+av_fifo_reset2(ctx->frame_queue);
 
 if (ctx->cudecoder) {
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);

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

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


[FFmpeg-cvslog] lavc/libvpxenc: remove unneeded context variable

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
16:49:45 2022 +0100| [9ef4b6699b77d2b6a89f477340be040fa7329572] | committer: 
Andreas Rheinhardt

lavc/libvpxenc: remove unneeded context variable

discard_hdr10_plus is 0 IFF hdr10_plus_fifo is non-NULL, so we can test
for the latter and avoid an extra variable.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9ef4b6699b77d2b6a89f477340be040fa7329572
---

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

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index ab5d31e4c4..8f94ba15dc 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -127,7 +127,6 @@ typedef struct VPxEncoderContext {
 int tune_content;
 int corpus_complexity;
 int tpl_model;
-int discard_hdr10_plus;
 AVFifo *hdr10_plus_fifo;
 /**
  * If the driver does not support ROI then warn the first time we
@@ -896,7 +895,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 #endif
 AVDictionaryEntry* en = NULL;
 
-ctx->discard_hdr10_plus = 1;
 av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
 av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
 
@@ -916,7 +914,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
 // Keep HDR10+ if it has bit depth higher than 8 and
 // it has PQ trc (SMPTE2084).
 if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) 
{
-ctx->discard_hdr10_plus = 0;
 ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus),
   AV_FIFO_FLAG_AUTO_GROW);
 if (!ctx->hdr10_plus_fifo)
@@ -1286,7 +1283,7 @@ static int storeframe(AVCodecContext *avctx, struct 
FrameListData *cx_frame,
 }
 if (cx_frame->frame_number != -1) {
 VPxContext *ctx = avctx->priv_data;
-if (!ctx->discard_hdr10_plus) {
+if (ctx->hdr10_plus_fifo) {
 int err = copy_hdr10_plus_to_pkt(ctx->hdr10_plus_fifo, pkt);
 if (err < 0)
 return err;
@@ -1701,7 +1698,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 }
 
-if (!ctx->discard_hdr10_plus) {
+if (ctx->hdr10_plus_fifo) {
 AVFrameSideData *hdr10_plus_metadata;
 // Add HDR10+ metadata to queue.
 hdr10_plus_metadata = av_frame_get_side_data(frame, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS);

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

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


[FFmpeg-cvslog] lavc/nvenc: switch to the new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
16:59:49 2022 +0100| [587545c9e07950c8985ac3bf5bfd2c434f49a410] | committer: 
Andreas Rheinhardt

lavc/nvenc: switch to the new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=587545c9e07950c8985ac3bf5bfd2c434f49a410
---

 libavcodec/nvenc.c | 49 +++--
 libavcodec/nvenc.h |  8 
 2 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 850c46022b..effd6381da 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1568,7 +1568,7 @@ static av_cold int nvenc_alloc_surface(AVCodecContext 
*avctx, int idx)
 
 ctx->surfaces[idx].output_surface = allocOut.bitstreamBuffer;
 
-av_fifo_generic_write(ctx->unused_surface_queue, &tmp_surface, 
sizeof(tmp_surface), NULL);
+av_fifo_write(ctx->unused_surface_queue, &tmp_surface, 1);
 
 return 0;
 }
@@ -1582,18 +1582,18 @@ static av_cold int nvenc_setup_surfaces(AVCodecContext 
*avctx)
 if (!ctx->surfaces)
 return AVERROR(ENOMEM);
 
-ctx->timestamp_list = av_fifo_alloc(ctx->nb_surfaces * sizeof(int64_t));
+ctx->timestamp_list = av_fifo_alloc2(ctx->nb_surfaces, sizeof(int64_t), 0);
 if (!ctx->timestamp_list)
 return AVERROR(ENOMEM);
 
-ctx->unused_surface_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->unused_surface_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->unused_surface_queue)
 return AVERROR(ENOMEM);
 
-ctx->output_surface_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->output_surface_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->output_surface_queue)
 return AVERROR(ENOMEM);
-ctx->output_surface_ready_queue = av_fifo_alloc(ctx->nb_surfaces * 
sizeof(NvencSurface*));
+ctx->output_surface_ready_queue = av_fifo_alloc2(ctx->nb_surfaces, 
sizeof(NvencSurface*), 0);
 if (!ctx->output_surface_ready_queue)
 return AVERROR(ENOMEM);
 
@@ -1666,10 +1666,10 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
 p_nvenc->nvEncEncodePicture(ctx->nvencoder, ¶ms);
 }
 
-av_fifo_freep(&ctx->timestamp_list);
-av_fifo_freep(&ctx->output_surface_ready_queue);
-av_fifo_freep(&ctx->output_surface_queue);
-av_fifo_freep(&ctx->unused_surface_queue);
+av_fifo_freep2(&ctx->timestamp_list);
+av_fifo_freep2(&ctx->output_surface_ready_queue);
+av_fifo_freep2(&ctx->output_surface_queue);
+av_fifo_freep2(&ctx->unused_surface_queue);
 
 if (ctx->surfaces && (avctx->pix_fmt == AV_PIX_FMT_CUDA || avctx->pix_fmt 
== AV_PIX_FMT_D3D11)) {
 for (i = 0; i < ctx->nb_registered_frames; i++) {
@@ -1777,11 +1777,10 @@ static NvencSurface *get_free_frame(NvencContext *ctx)
 {
 NvencSurface *tmp_surf;
 
-if (!(av_fifo_size(ctx->unused_surface_queue) > 0))
+if (av_fifo_read(ctx->unused_surface_queue, &tmp_surf, 1) < 0)
 // queue empty
 return NULL;
 
-av_fifo_generic_read(ctx->unused_surface_queue, &tmp_surf, 
sizeof(tmp_surf), NULL);
 return tmp_surf;
 }
 
@@ -1998,16 +1997,16 @@ static void 
nvenc_codec_specific_pic_params(AVCodecContext *avctx,
 }
 }
 
-static inline void timestamp_queue_enqueue(AVFifoBuffer* queue, int64_t 
timestamp)
+static inline void timestamp_queue_enqueue(AVFifo *queue, int64_t timestamp)
 {
-av_fifo_generic_write(queue, ×tamp, sizeof(timestamp), NULL);
+av_fifo_write(queue, ×tamp, 1);
 }
 
-static inline int64_t timestamp_queue_dequeue(AVFifoBuffer* queue)
+static inline int64_t timestamp_queue_dequeue(AVFifo *queue)
 {
 int64_t timestamp = AV_NOPTS_VALUE;
-if (av_fifo_size(queue) > 0)
-av_fifo_generic_read(queue, ×tamp, sizeof(timestamp), NULL);
+// The following call might fail if the queue is empty.
+av_fifo_read(queue, ×tamp, 1);
 
 return timestamp;
 }
@@ -2152,8 +2151,8 @@ static int output_ready(AVCodecContext *avctx, int flush)
 NvencContext *ctx = avctx->priv_data;
 int nb_ready, nb_pending;
 
-nb_ready   = av_fifo_size(ctx->output_surface_ready_queue)   / 
sizeof(NvencSurface*);
-nb_pending = av_fifo_size(ctx->output_surface_queue) / 
sizeof(NvencSurface*);
+nb_ready   = av_fifo_can_read(ctx->output_surface_ready_queue);
+nb_pending = av_fifo_can_read(ctx->output_surface_queue);
 if (flush)
 return nb_ready > 0;
 return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->async_depth);
@@ -2442,16 +2441,14 @@ static int nvenc_send_frame(AVCodecContext *avctx, 
const AVFrame *frame)
 return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
 
 if (frame && frame->buf[0]) {
-av_fifo_generic_write(ctx->output_surface_queue, &in_surf, 
sizeof(in_surf), NULL);
+av_fifo_write(ctx->output_surface_queue, &in_surf, 1);
 timestamp_queue_enqueue(ctx->times

[FFmpeg-cvslog] lavc/qsvdec: switch to the new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
17:16:47 2022 +0100| [08181624e041d36742870415319a1c599a6d3870] | committer: 
Andreas Rheinhardt

lavc/qsvdec: switch to the new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=08181624e041d36742870415319a1c599a6d3870
---

 libavcodec/qsvdec.c | 90 +
 1 file changed, 36 insertions(+), 54 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 32077ab31a..f81737ab6d 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -57,6 +57,11 @@ static const AVRational mfx_tb = { 1, 9 };
 AV_NOPTS_VALUE : pts_tb.num ? \
 av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
 
+typedef struct QSVAsyncFrame {
+mfxSyncPoint *sync;
+QSVFrame *frame;
+} QSVAsyncFrame;
+
 typedef struct QSVContext {
 // the session used for decoding
 mfxSession session;
@@ -73,7 +78,7 @@ typedef struct QSVContext {
  */
 QSVFrame *work_frames;
 
-AVFifoBuffer *async_fifo;
+AVFifo *async_fifo;
 int zero_consume_run;
 int buffered_count;
 int reinit_flag;
@@ -222,16 +227,6 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 return 0;
 }
 
-static inline unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
-}
-
-static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return av_fifo_size(fifo) / qsv_fifo_item_size();
-}
-
 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum 
AVPixelFormat pix_fmt, mfxVideoParam *param)
 {
 mfxSession session = NULL;
@@ -249,7 +244,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 }
 
 if (!q->async_fifo) {
-q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
+q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVAsyncFrame), 
0);
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 }
@@ -598,7 +593,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
   AVFrame *frame, int *got_frame,
   const AVPacket *avpkt)
 {
-QSVFrame *out_frame;
 mfxFrameSurface1 *insurf;
 mfxFrameSurface1 *outsurf;
 mfxSyncPoint *sync;
@@ -657,6 +651,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 }
 
 if (*sync) {
+QSVAsyncFrame aframe;
 QSVFrame *out_frame = find_frame(q, outsurf);
 
 if (!out_frame) {
@@ -667,42 +662,43 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 }
 
 out_frame->queued += 1;
-av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_write(q->async_fifo, &sync,  sizeof(sync),  
NULL);
+
+aframe = (QSVAsyncFrame){ sync, out_frame };
+av_fifo_write(q->async_fifo, &aframe, 1);
 } else {
 av_freep(&sync);
 }
 
-if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
-(!avpkt->size && av_fifo_size(q->async_fifo))) {
+if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) ||
+(!avpkt->size && av_fifo_can_read(q->async_fifo))) {
+QSVAsyncFrame aframe;
 AVFrame *src_frame;
 
-av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_read(q->async_fifo, &sync,  sizeof(sync),  
NULL);
-out_frame->queued -= 1;
+av_fifo_read(q->async_fifo, &aframe, 1);
+aframe.frame->queued -= 1;
 
 if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
 do {
-ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
+ret = MFXVideoCORE_SyncOperation(q->session, *aframe.sync, 
1000);
 } while (ret == MFX_WRN_IN_EXECUTION);
 }
 
-av_freep(&sync);
+av_freep(&aframe.sync);
 
-src_frame = out_frame->frame;
+src_frame = aframe.frame->frame;
 
 ret = av_frame_ref(frame, src_frame);
 if (ret < 0)
 return ret;
 
-outsurf = &out_frame->surface;
+outsurf = &aframe.frame->surface;
 
 frame->pts = MFX_PTS_TO_PTS(outsurf->Data.TimeStamp, 
avctx->pkt_timebase);
 #if QSV_VERSION_ATLEAST(1, 34)
 if ((avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 34) &&
 avctx->codec_id == AV_CODEC_ID_AV1) {
-ret = qsv_export_film_grain(avctx, 
&out_frame->av1_film_grain_param, frame);
+ret = qsv_export_film_grain(avctx, 
&aframe.frame->av1_film_grain_param, frame);
 
 if (ret < 0)
 return ret;
@@ -717,10 +713,10 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
 frame->interlaced_frame =
 !(outsurf->Info.PicStruct & 

[FFmpeg-cvslog] lavc/qsvenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [35e52d21dc77653b5466c7bc0696d26edcfa8bab] | committer: 
Andreas Rheinhardt

lavc/qsvenc: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=35e52d21dc77653b5466c7bc0696d26edcfa8bab
---

 libavcodec/qsvenc.c | 126 ++--
 libavcodec/qsvenc.h |   2 +-
 2 files changed, 55 insertions(+), 73 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index ef8213097e..af20ffb1c7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -88,6 +88,12 @@ static const struct profile_names vp9_profiles[] = {
 #endif
 };
 
+typedef struct QSVPacket {
+AVPacketpkt;
+mfxSyncPoint   *sync;
+mfxBitstream   *bs;
+} QSVPacket;
+
 static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile)
 {
 const struct profile_names *profiles;
@@ -1327,16 +1333,6 @@ static int qsvenc_init_session(AVCodecContext *avctx, 
QSVEncContext *q)
 return 0;
 }
 
-static inline unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(AVPacket) + sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*);
-}
-
-static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return av_fifo_size(fifo)/qsv_fifo_item_size();
-}
-
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
 {
 int iopattern = 0;
@@ -1345,7 +1341,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext 
*q)
 
 q->param.AsyncDepth = q->async_depth;
 
-q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
+q->async_fifo = av_fifo_alloc2(q->async_depth, sizeof(QSVPacket), 0);
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 
@@ -1648,15 +1644,13 @@ static void print_interlace_msg(AVCodecContext *avctx, 
QSVEncContext *q)
 static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
 const AVFrame *frame)
 {
-AVPacket new_pkt = { 0 };
-mfxBitstream *bs = NULL;
+QSVPacket pkt = { { 0 } };
 #if QSV_VERSION_ATLEAST(1, 26)
 mfxExtAVCEncodedFrameInfo *enc_info = NULL;
 mfxExtBuffer **enc_buf = NULL;
 #endif
 
 mfxFrameSurface1 *surf = NULL;
-mfxSyncPoint *sync = NULL;
 QSVFrame *qsv_frame = NULL;
 mfxEncodeCtrl* enc_ctrl = NULL;
 int ret;
@@ -1679,17 +1673,17 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 }
 }
 
-ret = av_new_packet(&new_pkt, q->packet_size);
+ret = av_new_packet(&pkt.pkt, q->packet_size);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");
 return ret;
 }
 
-bs = av_mallocz(sizeof(*bs));
-if (!bs)
+pkt.bs = av_mallocz(sizeof(*pkt.bs));
+if (!pkt.bs)
 goto nomem;
-bs->Data  = new_pkt.data;
-bs->MaxLength = new_pkt.size;
+pkt.bs->Data  = pkt.pkt.data;
+pkt.bs->MaxLength = pkt.pkt.size;
 
 #if QSV_VERSION_ATLEAST(1, 26)
 if (avctx->codec_id == AV_CODEC_ID_H264) {
@@ -1699,13 +1693,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 
 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
 enc_info->Header.BufferSz = sizeof (*enc_info);
-bs->NumExtParam = 1;
+pkt.bs->NumExtParam = 1;
 enc_buf = av_mallocz(sizeof(mfxExtBuffer *));
 if (!enc_buf)
 goto nomem;
 enc_buf[0] = (mfxExtBuffer *)enc_info;
 
-bs->ExtParam = enc_buf;
+pkt.bs->ExtParam = enc_buf;
 }
 #endif
 
@@ -1713,12 +1707,12 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 q->set_encode_ctrl_cb(avctx, frame, &qsv_frame->enc_ctrl);
 }
 
-sync = av_mallocz(sizeof(*sync));
-if (!sync)
+pkt.sync = av_mallocz(sizeof(*pkt.sync));
+if (!pkt.sync)
 goto nomem;
 
 do {
-ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, 
sync);
+ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, 
pkt.bs, pkt.sync);
 if (ret == MFX_WRN_DEVICE_BUSY)
 av_usleep(500);
 } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
@@ -1737,15 +1731,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 
 ret = 0;
 
-if (*sync) {
-av_fifo_generic_write(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
-av_fifo_generic_write(q->async_fifo, &sync,sizeof(sync),NULL);
-av_fifo_generic_write(q->async_fifo, &bs,  sizeof(bs),NULL);
+if (*pkt.sync) {
+av_fifo_write(q->async_fifo, &pkt, 1);
 } else {
 free:
-av_freep(&sync);
-av_packet_unref(&new_pkt);
-av_freep(&bs);
+av_freep(&pkt.sync);
+av_packet_unref(&pkt.pkt);
+av_freep(&pkt.bs);
 #if QSV_VERSION_ATLEAST(1, 26)
 if (avctx->codec_id == AV_CODEC_ID_H264) {
 av_freep(&enc_info);
@@ -1769,60 +1761,56 @@ int ff_qsv_enc

[FFmpeg-cvslog] avcodec/qsvenc: Reindent after the previous commit

2022-02-06 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sat Jan 22 20:08:57 2022 +0100| [d3c6156ce33911d1aa35fee3758f310f3a237696] | 
committer: Andreas Rheinhardt

avcodec/qsvenc: Reindent after the previous commit

Signed-off-by: Andreas Rheinhardt 

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

 libavcodec/qsvenc.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index af20ffb1c7..07be4287b7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1844,17 +1844,17 @@ int ff_qsv_enc_close(AVCodecContext *avctx, 
QSVEncContext *q)
 QSVPacket pkt;
 while (av_fifo_read(q->async_fifo, &pkt, 1) >= 0) {
 #if QSV_VERSION_ATLEAST(1, 26)
-if (avctx->codec_id == AV_CODEC_ID_H264) {
-mfxExtBuffer **enc_buf = pkt.bs->ExtParam;
-mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo 
*)(*enc_buf);
-av_freep(&enc_info);
-av_freep(&enc_buf);
-}
+if (avctx->codec_id == AV_CODEC_ID_H264) {
+mfxExtBuffer **enc_buf = pkt.bs->ExtParam;
+mfxExtAVCEncodedFrameInfo *enc_info = 
(mfxExtAVCEncodedFrameInfo *)(*enc_buf);
+av_freep(&enc_info);
+av_freep(&enc_buf);
+}
 #endif
-av_freep(&pkt.sync);
-av_freep(&pkt.bs);
-av_packet_unref(&pkt.pkt);
-}
+av_freep(&pkt.sync);
+av_freep(&pkt.bs);
+av_packet_unref(&pkt.pkt);
+}
 av_fifo_freep2(&q->async_fifo);
 }
 

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

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


[FFmpeg-cvslog] lavf/dvenc: return an error on audio/video desync

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
19:19:39 2022 +0100| [7e2be84a9491ff2e03c1653e4dca7cc46b0e2383] | committer: 
Andreas Rheinhardt

lavf/dvenc: return an error on audio/video desync

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7e2be84a9491ff2e03c1653e4dca7cc46b0e2383
---

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

diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index b76539b59f..03b63cff89 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -255,8 +255,10 @@ static int dv_assemble_frame(AVFormatContext *s,
 switch (st->codecpar->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
 /* FIXME: we have to have more sensible approach than this one */
-if (c->has_video)
+if (c->has_video) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
audio data or severe sync problem.\n", c->frames);
+return AVERROR(EINVAL);
+}
 if (data_size != c->sys->frame_size) {
 av_log(s, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n",
data_size, c->sys->frame_size);
@@ -270,8 +272,10 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
 
   /* FIXME: we have to have more sensible approach than this one */
-if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE)
+if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
video data or severe sync problem.\n", c->frames);
+return AVERROR(EINVAL);
+}
 av_fifo_generic_write(c->audio_data[i], data, data_size, NULL);
 
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
st->codecpar->sample_rate);

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

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


[FFmpeg-cvslog] lavf/mpegenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [ea511196a6c85eb433e10cdbecb0b2c722faf20d] | committer: 
Andreas Rheinhardt

lavf/mpegenc: switch to new FIFO API

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

 libavformat/mpegenc.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index b1d8bf9c38..64248695bd 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -45,7 +45,7 @@ typedef struct PacketDesc {
 } PacketDesc;
 
 typedef struct StreamInfo {
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 uint8_t id;
 int max_buffer_size; /* in bytes */
 int buffer_index;
@@ -459,7 +459,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
av_get_media_type_string(st->codecpar->codec_type), i);
 return AVERROR(EINVAL);
 }
-stream->fifo = av_fifo_alloc(16);
+stream->fifo = av_fifo_alloc2(16, 1, 0);
 if (!stream->fifo)
 return AVERROR(ENOMEM);
 }
@@ -626,6 +626,12 @@ static int get_nb_frames(AVFormatContext *ctx, StreamInfo 
*stream, int len)
 return nb_frames;
 }
 
+static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
+{
+avio_write(opaque, buf, *nb_elems);
+return 0;
+}
+
 /* flush the packet on stream stream_index */
 static int flush_packet(AVFormatContext *ctx, int stream_index,
 int64_t pts, int64_t dts, int64_t scr, int 
trailer_size)
@@ -741,6 +747,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 packet_size -= pad_packet_bytes + zero_trail_bytes;
 
 if (packet_size > 0) {
+size_t fifo_data;
 /* packet header size */
 packet_size -= 6;
 
@@ -776,7 +783,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 startcode = 0x100 + id;
 }
 
-stuffing_size = payload_size - av_fifo_size(stream->fifo);
+stuffing_size = payload_size - av_fifo_can_read(stream->fifo);
 
 // first byte does not fit -> reset pts/dts + stuffing
 if (payload_size <= trailer_size && pts != AV_NOPTS_VALUE) {
@@ -814,7 +821,7 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 stuffing_size = 0;
 
 if (startcode == PRIVATE_STREAM_1 && id >= 0xa0) {
-if (payload_size < av_fifo_size(stream->fifo))
+if (payload_size < av_fifo_can_read(stream->fifo))
 stuffing_size += payload_size % stream->lpcm_align;
 }
 
@@ -907,11 +914,10 @@ static int flush_packet(AVFormatContext *ctx, int 
stream_index,
 }
 
 /* output data */
-av_assert0(payload_size - stuffing_size <= av_fifo_size(stream->fifo));
-av_fifo_generic_read(stream->fifo, ctx->pb,
- payload_size - stuffing_size,
- (void (*)(void*, void*, int))avio_write);
-stream->bytes_to_iframe -= payload_size - stuffing_size;
+fifo_data = payload_size - stuffing_size;
+av_assert0(fifo_data <= av_fifo_can_read(stream->fifo));
+av_fifo_read_to_cb(stream->fifo, fifo_avio_wrapper, ctx->pb, 
&fifo_data);
+stream->bytes_to_iframe -= fifo_data;
 } else {
 payload_size  =
 stuffing_size = 0;
@@ -1005,7 +1011,7 @@ retry:
 for (i = 0; i < ctx->nb_streams; i++) {
 AVStream *st = ctx->streams[i];
 StreamInfo *stream = st->priv_data;
-const int avail_data = av_fifo_size(stream->fifo);
+const size_t avail_data = av_fifo_can_read(stream->fifo);
 const int space = stream->max_buffer_size - stream->buffer_index;
 int rel_space = 1024LL * space / stream->max_buffer_size;
 PacketDesc *next_pkt = stream->premux_packet;
@@ -1075,7 +1081,7 @@ retry:
 st = ctx->streams[best_i];
 stream = st->priv_data;
 
-av_assert0(av_fifo_size(stream->fifo) > 0);
+av_assert0(av_fifo_can_read(stream->fifo) > 0);
 
 av_assert0(avail_space >= s->packet_size || ignore_constraints);
 
@@ -1095,7 +1101,7 @@ retry:
 es_size = flush_packet(ctx, best_i, timestamp_packet->pts,
timestamp_packet->dts, scr, trailer_size);
 } else {
-av_assert0(av_fifo_size(stream->fifo) == trailer_size);
+av_assert0(av_fifo_can_read(stream->fifo) == trailer_size);
 es_size = flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 
scr,
trailer_size);
 }
@@ -1199,7 +1205,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, 
AVPacket *pkt)
 pkt_desc->unwritten_size =
 pkt_desc->size   = size;
 
-ret = av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size);
+ret = av_fifo_grow2(stream->fifo, size);
 if (ret < 0)
 return ret;
 
@@ -1208,13 +121

[FFmpeg-cvslog] lavf/dvenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
19:25:37 2022 +0100| [60414afc9d8bb55762c798f6559622f339e00413] | committer: 
Andreas Rheinhardt

lavf/dvenc: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=60414afc9d8bb55762c798f6559622f339e00413
---

 libavformat/dvenc.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 03b63cff89..e1188109c6 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -49,7 +49,7 @@ struct DVMuxContext {
 const AVDVProfile*  sys;   /* current DV profile, e.g.: 525/60, 
625/50 */
 int   n_ast; /* number of stereo audio streams (up to 
2) */
 AVStream *ast[4];/* stereo audio streams */
-AVFifoBuffer *audio_data[4]; /* FIFO for storing excessive amounts of 
PCM */
+AVFifo   *audio_data[4]; /* FIFO for storing excessive amounts of 
PCM */
 int   frames;/* current frame number */
 int64_t   start_time;/* recording start time */
 int   has_audio; /* frame under construction has audio */
@@ -202,7 +202,7 @@ static void dv_inject_audio(DVMuxContext *c, int channel, 
uint8_t* frame_ptr)
 continue;
 
 // FIXME: maybe we have to admit that DV is a big-endian PCM
-av_fifo_generic_peek_at(c->audio_data[channel], frame_ptr + d, 
of * 2, 2, NULL);
+av_fifo_peek(c->audio_data[channel], frame_ptr + d, 2, of * 2);
 FFSWAP(uint8_t, frame_ptr[d], frame_ptr[d + 1]);
 }
 frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
@@ -272,16 +272,16 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
 
   /* FIXME: we have to have more sensible approach than this one */
-if (av_fifo_size(c->audio_data[i]) + data_size >= 
100*MAX_AUDIO_FRAME_SIZE) {
+if (av_fifo_can_write(c->audio_data[i]) < data_size) {
 av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient 
video data or severe sync problem.\n", c->frames);
 return AVERROR(EINVAL);
 }
-av_fifo_generic_write(c->audio_data[i], data, data_size, NULL);
+av_fifo_write(c->audio_data[i], data, data_size);
 
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
st->codecpar->sample_rate);
 
 /* Let us see if we've got enough audio for one DV frame. */
-c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i);
+c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) << 
i);
 
 break;
 default:
@@ -295,8 +295,8 @@ static int dv_assemble_frame(AVFormatContext *s,
 for (i=0; i < c->n_ast; i++) {
 dv_inject_audio(c, i, *frame);
 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, 
c->ast[i]->codecpar->sample_rate);
-av_fifo_drain(c->audio_data[i], reqasize);
-c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << 
i);
+av_fifo_drain2(c->audio_data[i], reqasize);
+c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) 
<< i);
 }
 
 c->has_video = 0;
@@ -374,9 +374,11 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
 ff_parse_creation_time_metadata(s, &c->start_time, 1);
 
 for (i=0; i < c->n_ast; i++) {
-if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc_array(100, 
MAX_AUDIO_FRAME_SIZE))) {
+if (!c->ast[i])
+   continue;
+c->audio_data[i] = av_fifo_alloc2(100 * MAX_AUDIO_FRAME_SIZE, 1, 0);
+if (!c->audio_data[i])
 goto bail_out;
-}
 }
 
 return c;
@@ -438,7 +440,7 @@ static void dv_deinit(AVFormatContext *s)
 DVMuxContext *c = s->priv_data;
 
 for (int i = 0; i < c->n_ast; i++)
-av_fifo_freep(&c->audio_data[i]);
+av_fifo_freep2(&c->audio_data[i]);
 }
 
 const AVOutputFormat ff_dv_muxer = {

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

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


[FFmpeg-cvslog] lavf/swfenc: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [5fe2c3773496bb79392646dddc1415adb3b6d3d7] | committer: 
Andreas Rheinhardt

lavf/swfenc: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5fe2c3773496bb79392646dddc1415adb3b6d3d7
---

 libavformat/swfenc.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 1fd2ad81a3..9eb22ee9b3 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -38,7 +38,7 @@ typedef struct SWFEncContext {
 int swf_frame_number;
 int video_frame_number;
 int tag;
-AVFifoBuffer *audio_fifo;
+AVFifo *audio_fifo;
 AVCodecParameters *audio_par, *video_par;
 AVStream *video_st;
 } SWFEncContext;
@@ -211,7 +211,7 @@ static int swf_write_header(AVFormatContext *s)
 }
 if (par->codec_id == AV_CODEC_ID_MP3) {
 swf->audio_par = par;
-swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE);
+swf->audio_fifo = av_fifo_alloc2(AUDIO_FIFO_SIZE, 1, 0);
 if (!swf->audio_fifo)
 return AVERROR(ENOMEM);
 } else {
@@ -362,6 +362,12 @@ static int swf_write_header(AVFormatContext *s)
 return 0;
 }
 
+static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
+{
+avio_write(opaque, buf, *nb_elems);
+return 0;
+}
+
 static int swf_write_video(AVFormatContext *s,
AVCodecParameters *par, const uint8_t *buf, int 
size, unsigned pkt_flags)
 {
@@ -454,12 +460,12 @@ static int swf_write_video(AVFormatContext *s,
 swf->swf_frame_number++;
 
 /* streaming sound always should be placed just before showframe tags */
-if (swf->audio_par && av_fifo_size(swf->audio_fifo)) {
-int frame_size = av_fifo_size(swf->audio_fifo);
+if (swf->audio_par && av_fifo_can_read(swf->audio_fifo)) {
+size_t frame_size = av_fifo_can_read(swf->audio_fifo);
 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
 avio_wl16(pb, swf->sound_samples);
 avio_wl16(pb, 0); // seek samples
-av_fifo_generic_read(swf->audio_fifo, pb, frame_size, 
(void*)avio_write);
+av_fifo_read_to_cb(swf->audio_fifo, fifo_avio_wrapper, pb, 
&frame_size);
 put_swf_end_tag(s);
 
 /* update FIFO */
@@ -482,12 +488,12 @@ static int swf_write_audio(AVFormatContext *s,
 if (swf->swf_frame_number == 16000)
 av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames 
reached\n");
 
-if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) {
+if (av_fifo_can_write(swf->audio_fifo) < size) {
 av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
 return -1;
 }
 
-av_fifo_generic_write(swf->audio_fifo, buf, size, NULL);
+av_fifo_write(swf->audio_fifo, buf, size);
 swf->sound_samples += av_get_audio_frame_duration2(par, size);
 
 /* if audio only stream make sure we add swf frames */
@@ -535,7 +541,7 @@ static void swf_deinit(AVFormatContext *s)
 {
 SWFEncContext *swf = s->priv_data;
 
-av_fifo_freep(&swf->audio_fifo);
+av_fifo_freep2(&swf->audio_fifo);
 }
 
 #if CONFIG_SWF_MUXER

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

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


[FFmpeg-cvslog] lavf/udp: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [70a1774f1a40386605d156aacc4eab4f44f643d6] | committer: 
Andreas Rheinhardt

lavf/udp: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=70a1774f1a40386605d156aacc4eab4f44f643d6
---

 libavformat/udp.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index b441d2ea0d..da56c8ee1d 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -98,7 +98,7 @@ typedef struct UDPContext {
 
 /* Circular Buffer variables for use in UDP receive code */
 int circular_buffer_size;
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 int circular_buffer_error;
 int64_t bitrate; /* number of bits to send per second */
 int64_t burst_bits;
@@ -500,7 +500,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
 continue;
 AV_WL32(s->tmp, len);
 
-if(av_fifo_space(s->fifo) < len + 4) {
+if (av_fifo_can_write(s->fifo) < len + 4) {
 /* No Space left */
 if (s->overrun_nonfatal) {
 av_log(h, AV_LOG_WARNING, "Circular buffer overrun. "
@@ -514,7 +514,7 @@ static void *circular_buffer_task_rx( void *_URLContext)
 goto end;
 }
 }
-av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
+av_fifo_write(s->fifo, s->tmp, len + 4);
 pthread_cond_signal(&s->cond);
 }
 
@@ -548,22 +548,22 @@ static void *circular_buffer_task_tx( void *_URLContext)
 uint8_t tmp[4];
 int64_t timestamp;
 
-len = av_fifo_size(s->fifo);
+len = av_fifo_can_read(s->fifo);
 
 while (len<4) {
 if (s->close_req)
 goto end;
 pthread_cond_wait(&s->cond, &s->mutex);
-len = av_fifo_size(s->fifo);
+len = av_fifo_can_read(s->fifo);
 }
 
-av_fifo_generic_read(s->fifo, tmp, 4, NULL);
+av_fifo_read(s->fifo, tmp, 4);
 len = AV_RL32(tmp);
 
 av_assert0(len >= 0);
 av_assert0(len <= sizeof(s->tmp));
 
-av_fifo_generic_read(s->fifo, s->tmp, len, NULL);
+av_fifo_read(s->fifo, s->tmp, len);
 
 pthread_mutex_unlock(&s->mutex);
 
@@ -906,7 +906,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 
 if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && 
s->circular_buffer_size)) {
 /* start the task going */
-s->fifo = av_fifo_alloc(s->circular_buffer_size);
+s->fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0);
 if (!s->fifo) {
 ret = AVERROR(ENOMEM);
 goto fail;
@@ -943,7 +943,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
  fail:
 if (udp_fd >= 0)
 closesocket(udp_fd);
-av_fifo_freep(&s->fifo);
+av_fifo_freep2(&s->fifo);
 ff_ip_reset_filters(&s->filters);
 return ret;
 }
@@ -970,19 +970,19 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
 if (s->fifo) {
 pthread_mutex_lock(&s->mutex);
 do {
-avail = av_fifo_size(s->fifo);
+avail = av_fifo_can_read(s->fifo);
 if (avail) { // >=size) {
 uint8_t tmp[4];
 
-av_fifo_generic_read(s->fifo, tmp, 4, NULL);
+av_fifo_read(s->fifo, tmp, 4);
 avail = AV_RL32(tmp);
 if(avail > size){
 av_log(h, AV_LOG_WARNING, "Part of datagram lost due to 
insufficient buffer size\n");
 avail = size;
 }
 
-av_fifo_generic_read(s->fifo, buf, avail, NULL);
-av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);
+av_fifo_read(s->fifo, buf, avail);
+av_fifo_drain2(s->fifo, AV_RL32(tmp) - avail);
 pthread_mutex_unlock(&s->mutex);
 return avail;
 } else if(s->circular_buffer_error){
@@ -1043,14 +1043,14 @@ static int udp_write(URLContext *h, const uint8_t *buf, 
int size)
 return err;
 }
 
-if(av_fifo_space(s->fifo) < size + 4) {
+if (av_fifo_can_write(s->fifo) < size + 4) {
 /* What about a partial packet tx ? */
 pthread_mutex_unlock(&s->mutex);
 return AVERROR(ENOMEM);
 }
 AV_WL32(tmp, size);
-av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */
-av_fifo_generic_write(s->fifo, (uint8_t *)buf, size, NULL); /* the 
data */
+av_fifo_write(s->fifo, tmp, 4); /* size of packet */
+av_fifo_write(s->fifo, buf, size); /* the data */
 pthread_cond_signal(&s->cond);
 pthread_mutex_unlock(&s->mutex);
 return size;
@@ -1112,7 +1112,7 @@ static int udp_close(URLContext *h)
 }
 #endif
 closesocket(s->udp_fd);
-av_fifo_freep(&s->fifo);
+   

[FFmpeg-cvslog] lavu/audio_fifo: drop an unnecessary include

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
13:03:53 2022 +0100| [082136209c5038e54813bb3a6e35da8a73acf0ea] | committer: 
Andreas Rheinhardt

lavu/audio_fifo: drop an unnecessary include

Nothing in audio_fifo.h uses anything from fifo.h

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=082136209c5038e54813bb3a6e35da8a73acf0ea
---

 libavutil/audio_fifo.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavutil/audio_fifo.h b/libavutil/audio_fifo.h
index d8a9194a8d..9d570b04c0 100644
--- a/libavutil/audio_fifo.h
+++ b/libavutil/audio_fifo.h
@@ -28,7 +28,6 @@
 #define AVUTIL_AUDIO_FIFO_H
 
 #include "avutil.h"
-#include "fifo.h"
 #include "samplefmt.h"
 
 /**

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

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


[FFmpeg-cvslog] lavf/async: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [36117968ad66d7e4a461eb2d22e2a5f5c494120e] | committer: 
Andreas Rheinhardt

lavf/async: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=36117968ad66d7e4a461eb2d22e2a5f5c494120e
---

 libavformat/async.c | 68 ++---
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/libavformat/async.c b/libavformat/async.c
index 5a81507ef1..547417aa1e 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -47,7 +47,7 @@
 
 typedef struct RingBuffer
 {
-AVFifoBuffer *fifo;
+AVFifo   *fifo;
 int   read_back_capacity;
 
 int   read_pos;
@@ -83,7 +83,7 @@ typedef struct Context {
 static int ring_init(RingBuffer *ring, unsigned int capacity, int 
read_back_capacity)
 {
 memset(ring, 0, sizeof(RingBuffer));
-ring->fifo = av_fifo_alloc(capacity + read_back_capacity);
+ring->fifo = av_fifo_alloc2(capacity + read_back_capacity, 1, 0);
 if (!ring->fifo)
 return AVERROR(ENOMEM);
 
@@ -93,45 +93,59 @@ static int ring_init(RingBuffer *ring, unsigned int 
capacity, int read_back_capa
 
 static void ring_destroy(RingBuffer *ring)
 {
-av_fifo_freep(&ring->fifo);
+av_fifo_freep2(&ring->fifo);
 }
 
 static void ring_reset(RingBuffer *ring)
 {
-av_fifo_reset(ring->fifo);
+av_fifo_reset2(ring->fifo);
 ring->read_pos = 0;
 }
 
 static int ring_size(RingBuffer *ring)
 {
-return av_fifo_size(ring->fifo) - ring->read_pos;
+return av_fifo_can_read(ring->fifo) - ring->read_pos;
 }
 
 static int ring_space(RingBuffer *ring)
 {
-return av_fifo_space(ring->fifo);
+return av_fifo_can_write(ring->fifo);
 }
 
-static int ring_generic_read(RingBuffer *ring, void *dest, int buf_size, void 
(*func)(void*, void*, int))
+static int ring_read(RingBuffer *ring, void *dest, int buf_size)
 {
-int ret;
+int ret = 0;
 
 av_assert2(buf_size <= ring_size(ring));
-ret = av_fifo_generic_peek_at(ring->fifo, dest, ring->read_pos, buf_size, 
func);
+if (dest)
+ret = av_fifo_peek(ring->fifo, dest, buf_size, ring->read_pos);
 ring->read_pos += buf_size;
 
 if (ring->read_pos > ring->read_back_capacity) {
-av_fifo_drain(ring->fifo, ring->read_pos - ring->read_back_capacity);
+av_fifo_drain2(ring->fifo, ring->read_pos - ring->read_back_capacity);
 ring->read_pos = ring->read_back_capacity;
 }
 
 return ret;
 }
 
-static int ring_generic_write(RingBuffer *ring, void *src, int size, int 
(*func)(void*, void*, int))
+static int wrapped_url_read(void *src, void *dst, size_t *size)
+{
+URLContext *h   = src;
+Context*c   = h->priv_data;
+int ret;
+
+ret = ffurl_read(c->inner, dst, *size);
+*size = ret > 0 ? ret : 0;
+c->inner_io_error = ret < 0 ? ret : 0;
+
+return c->inner_io_error;
+}
+
+static int ring_write(RingBuffer *ring, URLContext *h, size_t size)
 {
 av_assert2(size <= ring_space(ring));
-return av_fifo_generic_write(ring->fifo, src, size, func);
+return av_fifo_write_from_cb(ring->fifo, wrapped_url_read, h, &size);
 }
 
 static int ring_size_of_read_back(RingBuffer *ring)
@@ -161,18 +175,6 @@ static int async_check_interrupt(void *arg)
 return c->abort_request;
 }
 
-static int wrapped_url_read(void *src, void *dst, int size)
-{
-URLContext *h   = src;
-Context*c   = h->priv_data;
-int ret;
-
-ret = ffurl_read(c->inner, dst, size);
-c->inner_io_error = ret < 0 ? ret : 0;
-
-return ret;
-}
-
 static void *async_buffer_task(void *arg)
 {
 URLContext   *h= arg;
@@ -221,7 +223,7 @@ static void *async_buffer_task(void *arg)
 pthread_mutex_unlock(&c->mutex);
 
 to_copy = FFMIN(4096, fifo_space);
-ret = ring_generic_write(ring, (void *)h, to_copy, wrapped_url_read);
+ret = ring_write(ring, h, to_copy);
 
 pthread_mutex_lock(&c->mutex);
 if (ret <= 0) {
@@ -327,11 +329,11 @@ static int async_close(URLContext *h)
 return 0;
 }
 
-static int async_read_internal(URLContext *h, void *dest, int size, int 
read_complete,
-   void (*func)(void*, void*, int))
+static int async_read_internal(URLContext *h, void *dest, int size)
 {
 Context  *c   = h->priv_data;
 RingBuffer   *ring= &c->ring;
+int read_complete = !dest;
 int   to_read = size;
 int   ret = 0;
 
@@ -346,8 +348,8 @@ static int async_read_internal(URLContext *h, void *dest, 
int size, int read_com
 fifo_size = ring_size(ring);
 to_copy   = FFMIN(to_read, fifo_size);
 if (to_copy > 0) {
-ring_generic_read(ring, dest, to_copy, func);
-if (!func)
+ring_read(ring, dest, to_copy);
+if (dest)
 dest = (uint8_t *)dest + to_copy;
 c->logical_pos += to_c

[FFmpeg-cvslog] lavu/audio_fifo: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [d1bd189c6318fc016a9b6f9c8fee8a47e9b7e173] | committer: 
Andreas Rheinhardt

lavu/audio_fifo: switch to new FIFO API

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

 libavutil/audio_fifo.c | 44 +---
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/libavutil/audio_fifo.c b/libavutil/audio_fifo.c
index 243efc39e4..b1355e55a0 100644
--- a/libavutil/audio_fifo.c
+++ b/libavutil/audio_fifo.c
@@ -32,7 +32,7 @@
 #include "samplefmt.h"
 
 struct AVAudioFifo {
-AVFifoBuffer **buf; /**< single buffer for interleaved, 
per-channel buffers for planar */
+AVFifo **buf;   /**< single buffer for interleaved, 
per-channel buffers for planar */
 int nb_buffers; /**< number of buffers */
 int nb_samples; /**< number of samples currently in the 
FIFO */
 int allocated_samples;  /**< current allocated size, in samples */
@@ -48,7 +48,7 @@ void av_audio_fifo_free(AVAudioFifo *af)
 if (af->buf) {
 int i;
 for (i = 0; i < af->nb_buffers; i++) {
-av_fifo_freep(&af->buf[i]);
+av_fifo_freep2(&af->buf[i]);
 }
 av_freep(&af->buf);
 }
@@ -80,7 +80,7 @@ AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat 
sample_fmt, int channels,
 goto error;
 
 for (i = 0; i < af->nb_buffers; i++) {
-af->buf[i] = av_fifo_alloc(buf_size);
+af->buf[i] = av_fifo_alloc2(buf_size, 1, 0);
 if (!af->buf[i])
 goto error;
 }
@@ -95,15 +95,19 @@ error:
 
 int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
 {
+const size_t cur_size = av_fifo_can_read (af->buf[0]) +
+av_fifo_can_write(af->buf[0]);
 int i, ret, buf_size;
 
 if ((ret = av_samples_get_buffer_size(&buf_size, af->channels, nb_samples,
   af->sample_fmt, 1)) < 0)
 return ret;
 
-for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_realloc2(af->buf[i], buf_size)) < 0)
-return ret;
+if (buf_size > cur_size) {
+for (i = 0; i < af->nb_buffers; i++) {
+if ((ret = av_fifo_grow2(af->buf[i], buf_size - cur_size)) < 0)
+return ret;
+}
 }
 af->allocated_samples = nb_samples;
 return 0;
@@ -126,8 +130,8 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int 
nb_samples)
 
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-ret = av_fifo_generic_write(af->buf[i], data[i], size, NULL);
-if (ret != size)
+ret = av_fifo_write(af->buf[i], data[i], size);
+if (ret < 0)
 return AVERROR_BUG;
 }
 af->nb_samples += nb_samples;
@@ -137,21 +141,7 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int 
nb_samples)
 
 int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
 {
-int i, ret, size;
-
-if (nb_samples < 0)
-return AVERROR(EINVAL);
-nb_samples = FFMIN(nb_samples, af->nb_samples);
-if (!nb_samples)
-return 0;
-
-size = nb_samples * af->sample_size;
-for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_generic_peek(af->buf[i], data[i], size, NULL)) < 0)
-return AVERROR_BUG;
-}
-
-return nb_samples;
+return av_audio_fifo_peek_at(af, data, nb_samples, 0);
 }
 
 int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int 
offset)
@@ -171,7 +161,7 @@ int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int 
nb_samples, int offs
 offset *= af->sample_size;
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-if ((ret = av_fifo_generic_peek_at(af->buf[i], data[i], offset, size, 
NULL)) < 0)
+if ((ret = av_fifo_peek(af->buf[i], data[i], size, offset)) < 0)
 return AVERROR_BUG;
 }
 
@@ -190,7 +180,7 @@ int av_audio_fifo_read(AVAudioFifo *af, void **data, int 
nb_samples)
 
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++) {
-if (av_fifo_generic_read(af->buf[i], data[i], size, NULL) < 0)
+if (av_fifo_read(af->buf[i], data[i], size) < 0)
 return AVERROR_BUG;
 }
 af->nb_samples -= nb_samples;
@@ -209,7 +199,7 @@ int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
 if (nb_samples) {
 size = nb_samples * af->sample_size;
 for (i = 0; i < af->nb_buffers; i++)
-av_fifo_drain(af->buf[i], size);
+av_fifo_drain2(af->buf[i], size);
 af->nb_samples -= nb_samples;
 }
 return 0;
@@ -220,7 +210,7 @@ void av_audio_fifo_reset(AVAudioFifo *af)
 int i;
 
 for (i = 0; i < af->nb_buffers; i++)
-av_fifo_reset(af->buf[i]);
+

[FFmpeg-cvslog] lavd/jack: switch to the new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jan  6 
17:16:47 2022 +0100| [d46fd9640f0e6793eb1cf991eb4808c9c97a6a68] | committer: 
Andreas Rheinhardt

lavd/jack: switch to the new FIFO API

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

 libavdevice/jack.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavdevice/jack.c b/libavdevice/jack.c
index 0d5465e407..b9a167bed3 100644
--- a/libavdevice/jack.c
+++ b/libavdevice/jack.c
@@ -50,8 +50,8 @@ typedef struct JackData {
 jack_port_t **  ports;
 int nports;
 TimeFilter *timefilter;
-AVFifoBuffer *  new_pkts;
-AVFifoBuffer *  filled_pkts;
+AVFifo *new_pkts;
+AVFifo *filled_pkts;
 int pkt_xrun;
 int jack_xrun;
 } JackData;
@@ -81,13 +81,14 @@ static int process_callback(jack_nframes_t nframes, void 
*arg)
   self->buffer_size);
 
 /* Check if an empty packet is available, and if there's enough space to 
send it back once filled */
-if ((av_fifo_size(self->new_pkts) < sizeof(pkt)) || 
(av_fifo_space(self->filled_pkts) < sizeof(pkt))) {
+if (!av_fifo_can_read(self->new_pkts) ||
+!av_fifo_can_write(self->filled_pkts)) {
 self->pkt_xrun = 1;
 return 0;
 }
 
 /* Retrieve empty (but allocated) packet */
-av_fifo_generic_read(self->new_pkts, &pkt, sizeof(pkt), NULL);
+av_fifo_read(self->new_pkts, &pkt, 1);
 
 pkt_data  = (float *) pkt.data;
 latency   = 0;
@@ -106,7 +107,7 @@ static int process_callback(jack_nframes_t nframes, void 
*arg)
 pkt.pts = (cycle_time - (double) latency / (self->nports * 
self->sample_rate)) * 100.0;
 
 /* Send the now filled packet back, and increase packet counter */
-av_fifo_generic_write(self->filled_pkts, &pkt, sizeof(pkt), NULL);
+av_fifo_write(self->filled_pkts, &pkt, 1);
 sem_post(&self->packet_count);
 
 return 0;
@@ -134,12 +135,12 @@ static int supply_new_packets(JackData *self, 
AVFormatContext *context)
 /* Supply the process callback with new empty packets, by filling the new
  * packets FIFO buffer with as many packets as possible. process_callback()
  * can't do this by itself, because it can't allocate memory in realtime. 
*/
-while (av_fifo_space(self->new_pkts) >= sizeof(pkt)) {
+while (av_fifo_can_write(self->new_pkts)) {
 if ((test = av_new_packet(&pkt, pkt_size)) < 0) {
 av_log(context, AV_LOG_ERROR, "Could not create packet of size 
%d\n", pkt_size);
 return test;
 }
-av_fifo_generic_write(self->new_pkts, &pkt, sizeof(pkt), NULL);
+av_fifo_write(self->new_pkts, &pkt, 1);
 }
 return 0;
 }
@@ -193,9 +194,9 @@ static int start_jack(AVFormatContext *context)
 }
 
 /* Create FIFO buffers */
-self->filled_pkts = av_fifo_alloc_array(FIFO_PACKETS_NUM, 
sizeof(AVPacket));
+self->filled_pkts = av_fifo_alloc2(FIFO_PACKETS_NUM, sizeof(AVPacket), 0);
 /* New packets FIFO with one extra packet for safety against underruns */
-self->new_pkts= av_fifo_alloc_array((FIFO_PACKETS_NUM + 1), 
sizeof(AVPacket));
+self->new_pkts= av_fifo_alloc2((FIFO_PACKETS_NUM + 1), 
sizeof(AVPacket), 0);
 if (!self->new_pkts) {
 jack_client_close(self->client);
 return AVERROR(ENOMEM);
@@ -209,14 +210,13 @@ static int start_jack(AVFormatContext *context)
 
 }
 
-static void free_pkt_fifo(AVFifoBuffer **fifo)
+static void free_pkt_fifo(AVFifo **fifop)
 {
+AVFifo *fifo = *fifop;
 AVPacket pkt;
-while (av_fifo_size(*fifo)) {
-av_fifo_generic_read(*fifo, &pkt, sizeof(pkt), NULL);
+while (av_fifo_read(fifo, &pkt, 1) >= 0)
 av_packet_unref(&pkt);
-}
-av_fifo_freep(fifo);
+av_fifo_freep2(fifop);
 }
 
 static void stop_jack(JackData *self)
@@ -313,7 +313,7 @@ static int audio_read_packet(AVFormatContext *context, 
AVPacket *pkt)
 }
 
 /* Retrieve the packet filled with audio data by process_callback() */
-av_fifo_generic_read(self->filled_pkts, pkt, sizeof(*pkt), NULL);
+av_fifo_read(self->filled_pkts, pkt, 1);
 
 if ((test = supply_new_packets(self, context)))
 return test;

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

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


[FFmpeg-cvslog] lavu/threadmessage: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [90eef1c3de7b575091b9299bc396b6ebb86ca8e8] | committer: 
Andreas Rheinhardt

lavu/threadmessage: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90eef1c3de7b575091b9299bc396b6ebb86ca8e8
---

 libavutil/threadmessage.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
index 764b7fb813..6f25da76d7 100644
--- a/libavutil/threadmessage.c
+++ b/libavutil/threadmessage.c
@@ -24,7 +24,7 @@
 
 struct AVThreadMessageQueue {
 #if HAVE_THREADS
-AVFifoBuffer *fifo;
+AVFifo *fifo;
 pthread_mutex_t lock;
 pthread_cond_t cond_recv;
 pthread_cond_t cond_send;
@@ -64,7 +64,7 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
 av_free(rmq);
 return AVERROR(ret);
 }
-if (!(rmq->fifo = av_fifo_alloc(elsize * nelem))) {
+if (!(rmq->fifo = av_fifo_alloc2(nelem, elsize, 0))) {
 pthread_cond_destroy(&rmq->cond_send);
 pthread_cond_destroy(&rmq->cond_recv);
 pthread_mutex_destroy(&rmq->lock);
@@ -93,7 +93,7 @@ void av_thread_message_queue_free(AVThreadMessageQueue **mq)
 #if HAVE_THREADS
 if (*mq) {
 av_thread_message_flush(*mq);
-av_fifo_freep(&(*mq)->fifo);
+av_fifo_freep2(&(*mq)->fifo);
 pthread_cond_destroy(&(*mq)->cond_send);
 pthread_cond_destroy(&(*mq)->cond_recv);
 pthread_mutex_destroy(&(*mq)->lock);
@@ -107,9 +107,9 @@ int av_thread_message_queue_nb_elems(AVThreadMessageQueue 
*mq)
 #if HAVE_THREADS
 int ret;
 pthread_mutex_lock(&mq->lock);
-ret = av_fifo_size(mq->fifo);
+ret = av_fifo_can_read(mq->fifo);
 pthread_mutex_unlock(&mq->lock);
-return ret / mq->elsize;
+return ret;
 #else
 return AVERROR(ENOSYS);
 #endif
@@ -121,14 +121,14 @@ static int 
av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
void *msg,
unsigned flags)
 {
-while (!mq->err_send && av_fifo_space(mq->fifo) < mq->elsize) {
+while (!mq->err_send && !av_fifo_can_write(mq->fifo)) {
 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
 return AVERROR(EAGAIN);
 pthread_cond_wait(&mq->cond_send, &mq->lock);
 }
 if (mq->err_send)
 return mq->err_send;
-av_fifo_generic_write(mq->fifo, msg, mq->elsize, NULL);
+av_fifo_write(mq->fifo, msg, 1);
 /* one message is sent, signal one receiver */
 pthread_cond_signal(&mq->cond_recv);
 return 0;
@@ -138,14 +138,14 @@ static int 
av_thread_message_queue_recv_locked(AVThreadMessageQueue *mq,
void *msg,
unsigned flags)
 {
-while (!mq->err_recv && av_fifo_size(mq->fifo) < mq->elsize) {
+while (!mq->err_recv && !av_fifo_can_read(mq->fifo)) {
 if ((flags & AV_THREAD_MESSAGE_NONBLOCK))
 return AVERROR(EAGAIN);
 pthread_cond_wait(&mq->cond_recv, &mq->lock);
 }
-if (av_fifo_size(mq->fifo) < mq->elsize)
+if (!av_fifo_can_read(mq->fifo))
 return mq->err_recv;
-av_fifo_generic_read(mq->fifo, msg, mq->elsize, NULL);
+av_fifo_read(mq->fifo, msg, 1);
 /* one message space appeared, signal one sender */
 pthread_cond_signal(&mq->cond_send);
 return 0;
@@ -208,25 +208,25 @@ void 
av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
 }
 
 #if HAVE_THREADS
-static void free_func_wrap(void *arg, void *msg, int size)
+static int free_func_wrap(void *arg, void *buf, size_t *nb_elems)
 {
 AVThreadMessageQueue *mq = arg;
-mq->free_func(msg);
+uint8_t *msg = buf;
+for (size_t i = 0; i < *nb_elems; i++)
+mq->free_func(msg + i * mq->elsize);
+return 0;
 }
 #endif
 
 void av_thread_message_flush(AVThreadMessageQueue *mq)
 {
 #if HAVE_THREADS
-int used, off;
-void *free_func = mq->free_func;
+size_t used;
 
 pthread_mutex_lock(&mq->lock);
-used = av_fifo_size(mq->fifo);
-if (free_func)
-for (off = 0; off < used; off += mq->elsize)
-av_fifo_generic_peek_at(mq->fifo, mq, off, mq->elsize, 
free_func_wrap);
-av_fifo_drain(mq->fifo, used);
+used = av_fifo_can_read(mq->fifo);
+if (mq->free_func)
+av_fifo_read_to_cb(mq->fifo, free_func_wrap, mq, &used);
 /* only the senders need to be notified since the queue is empty and there
  * is nothing to read */
 pthread_cond_broadcast(&mq->cond_send);

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

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


[FFmpeg-cvslog] lavfi/qsvvpp: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [85c938fa287c61334d01adfb038ca47bed6d106c] | committer: 
Andreas Rheinhardt

lavfi/qsvvpp: switch to new FIFO API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=85c938fa287c61334d01adfb038ca47bed6d106c
---

 libavfilter/qsvvpp.c | 46 +++---
 libavfilter/qsvvpp.h |  2 +-
 2 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..35769dfd60 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -40,6 +40,11 @@
 
 static const AVRational default_tb = { 1, 9 };
 
+typedef struct QSVAsyncFrame {
+mfxSyncPoint  sync;
+QSVFrame *frame;
+} QSVAsyncFrame;
+
 static const struct {
 int mfx_iopattern;
 const char *desc;
@@ -642,16 +647,6 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 return 0;
 }
 
-static unsigned int qsv_fifo_item_size(void)
-{
-return sizeof(mfxSyncPoint) + sizeof(QSVFrame*);
-}
-
-static unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
-{
-return  av_fifo_size(fifo)/qsv_fifo_item_size();
-}
-
 int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam 
*param)
 {
 int i;
@@ -727,7 +722,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext 
**vpp, QSVVPPParam *p
 s->got_frame = 0;
 
 /** keep fifo size at least 1. Even when async_depth is 0, fifo is used. */
-s->async_fifo  = av_fifo_alloc((param->async_depth + 1) * 
qsv_fifo_item_size());
+s->async_fifo  = av_fifo_alloc2(param->async_depth + 1, 
sizeof(QSVAsyncFrame), 0);
 s->async_depth = param->async_depth;
 if (!s->async_fifo) {
 ret = AVERROR(ENOMEM);
@@ -789,7 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp)
 av_freep(&s->surface_ptrs_out);
 av_freep(&s->ext_buffers);
 av_freep(&s->frame_infos);
-av_fifo_free(s->async_fifo);
+av_fifo_freep2(&s->async_fifo);
 av_freep(vpp);
 
 return 0;
@@ -799,24 +794,23 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
 {
 AVFilterContext  *ctx = inlink->dst;
 AVFilterLink *outlink = ctx->outputs[0];
+QSVAsyncFrame aframe;
 mfxSyncPoint  sync;
 QSVFrame *in_frame, *out_frame, *tmp;
 int   ret, filter_ret;
 
-while (s->eof && qsv_fifo_size(s->async_fifo)) {
-av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL);
-av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL);
-if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0)
+while (s->eof && av_fifo_read(s->async_fifo, &aframe, 1) >= 0) {
+if (MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000) < 0)
 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");
 
-filter_ret = s->filter_frame(outlink, tmp->frame);
+filter_ret = s->filter_frame(outlink, aframe.frame->frame);
 if (filter_ret < 0) {
-av_frame_free(&tmp->frame);
+av_frame_free(&aframe.frame->frame);
 return filter_ret;
 }
-tmp->queued--;
+aframe.frame->queued--;
 s->got_frame = 1;
-tmp->frame = NULL;
+aframe.frame->frame = NULL;
 };
 
 if (!picref)
@@ -853,16 +847,14 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink 
*inlink, AVFrame *picr
  default_tb, outlink->time_base);
 
 out_frame->queued++;
-av_fifo_generic_write(s->async_fifo, &out_frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_write(s->async_fifo, &sync, sizeof(sync), NULL);
-
+aframe = (QSVAsyncFrame){ sync, out_frame };
+av_fifo_write(s->async_fifo, &aframe, 1);
 
-if (qsv_fifo_size(s->async_fifo) > s->async_depth) {
-av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL);
-av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL);
+if (av_fifo_can_read(s->async_fifo) > s->async_depth) {
+av_fifo_read(s->async_fifo, &aframe, 1);
 
 do {
-ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
+ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 
1000);
 } while (ret == MFX_WRN_IN_EXECUTION);
 
 filter_ret = s->filter_frame(outlink, tmp->frame);
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index e0f4c8f5bb..4fe07ab1f7 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -73,7 +73,7 @@ typedef struct QSVVPPContext {
 int async_depth;
 int eof;
 /** order with frame_out, sync */
-AVFifoBuffer *async_fifo;
+AVFifo *async_fifo;
 } QSVVPPContext;
 
 typedef struct QSVVPPCrop {

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

To unsub

[FFmpeg-cvslog] lavfi/vf_deshake_opencl: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jan  7 
11:41:42 2022 +0100| [c65c2ed01d83db0faba8c359a620ab2a23249532] | committer: 
Andreas Rheinhardt

lavfi/vf_deshake_opencl: switch to new FIFO API

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

 libavfilter/vf_deshake_opencl.c | 92 +
 1 file changed, 29 insertions(+), 63 deletions(-)

diff --git a/libavfilter/vf_deshake_opencl.c b/libavfilter/vf_deshake_opencl.c
index 9c761ba5ad..c2b5bef897 100644
--- a/libavfilter/vf_deshake_opencl.c
+++ b/libavfilter/vf_deshake_opencl.c
@@ -134,7 +134,7 @@ typedef struct DebugMatches {
 // for each frame
 typedef struct AbsoluteFrameMotion {
 // Array with the various ringbuffers, indexed via the RingbufferIndices 
enum
-AVFifoBuffer *ringbuffers[RingbufCount];
+AVFifo *ringbuffers[RingbufCount];
 
 // Offset to get to the current frame being processed
 // (not in bytes)
@@ -144,7 +144,7 @@ typedef struct AbsoluteFrameMotion {
 int data_start_offset;
 int data_end_offset;
 
-AVFifoBuffer *debug_matches;
+AVFifo *debug_matches;
 } AbsoluteFrameMotion;
 
 // Takes care of freeing the arrays within the DebugMatches inside of the
@@ -156,18 +156,10 @@ static void free_debug_matches(AbsoluteFrameMotion *afm) {
 return;
 }
 
-while (av_fifo_size(afm->debug_matches) > 0) {
-av_fifo_generic_read(
-afm->debug_matches,
-&dm,
-sizeof(DebugMatches),
-NULL
-);
-
+while (av_fifo_read(afm->debug_matches, &dm, 1) >= 0)
 av_freep(&dm.matches);
-}
 
-av_fifo_freep(&afm->debug_matches);
+av_fifo_freep2(&afm->debug_matches);
 }
 
 // Stores the translation, scale, rotation, and skew deltas between two frames
@@ -853,7 +845,7 @@ static IterIndices start_end_for(DeshakeOpenCLContext 
*deshake_ctx, int length)
 // clipping the offset into the appropriate range
 static void ringbuf_float_at(
 DeshakeOpenCLContext *deshake_ctx,
-AVFifoBuffer *values,
+AVFifo *values,
 float *val,
 int offset
 ) {
@@ -863,7 +855,7 @@ static void ringbuf_float_at(
 } else {
 // This expression represents the last valid index in the buffer,
 // which we use repeatedly at the end of the video.
-clip_end = deshake_ctx->smooth_window - (av_fifo_space(values) / 
sizeof(float)) - 1;
+clip_end = deshake_ctx->smooth_window - av_fifo_can_write(values) - 1;
 }
 
 if (deshake_ctx->abs_motion.data_start_offset != -1) {
@@ -881,13 +873,7 @@ static void ringbuf_float_at(
 clip_end
 );
 
-av_fifo_generic_peek_at(
-values,
-val,
-offset_clipped * sizeof(float),
-sizeof(float),
-NULL
-);
+av_fifo_peek(values, val, 1, offset_clipped);
 }
 
 // Returns smoothed current frame value of the given buffer of floats based on 
the
@@ -905,7 +891,7 @@ static float smooth(
 float *gauss_kernel,
 int length,
 float max_val,
-AVFifoBuffer *values
+AVFifo *values
 ) {
 float new_large_s = 0, new_small_s = 0, new_best = 0, old, diff_between,
   percent_of_max, inverted_percent;
@@ -1069,7 +1055,7 @@ static av_cold void deshake_opencl_uninit(AVFilterContext 
*avctx)
 cl_int cle;
 
 for (int i = 0; i < RingbufCount; i++)
-av_fifo_freep(&ctx->abs_motion.ringbuffers[i]);
+av_fifo_freep2(&ctx->abs_motion.ringbuffers[i]);
 
 if (ctx->debug_on)
 free_debug_matches(&ctx->abs_motion);
@@ -1188,10 +1174,8 @@ static int deshake_opencl_init(AVFilterContext *avctx)
 }
 
 for (int i = 0; i < RingbufCount; i++) {
-ctx->abs_motion.ringbuffers[i] = av_fifo_alloc_array(
-ctx->smooth_window,
-sizeof(float)
-);
+ctx->abs_motion.ringbuffers[i] = av_fifo_alloc2(ctx->smooth_window,
+sizeof(float), 0);
 
 if (!ctx->abs_motion.ringbuffers[i]) {
 err = AVERROR(ENOMEM);
@@ -1200,9 +1184,9 @@ static int deshake_opencl_init(AVFilterContext *avctx)
 }
 
 if (ctx->debug_on) {
-ctx->abs_motion.debug_matches = av_fifo_alloc_array(
+ctx->abs_motion.debug_matches = av_fifo_alloc2(
 ctx->smooth_window / 2,
-sizeof(DebugMatches)
+sizeof(DebugMatches), 0
 );
 
 if (!ctx->abs_motion.debug_matches) {
@@ -1424,12 +1408,9 @@ static int filter_frame(AVFilterLink *link, AVFrame 
*input_frame)
 const float luma_h_over_chroma_h = ((float)input_frame->height / 
(float)chroma_height);
 
 if (deshake_ctx->debug_on) {
-av_fifo_generic_read(
+av_fifo_read(
 deshake_ctx->abs_motion.debug_matches,
-&debug_matches,
-sizeof(DebugMatches),
-NULL
-);
+&debug_matches, 1);
 }
 
 if (input_frame->pkt_duration) {
@@ -1441,13 +1422,9 @@ static int filter_frame(AVFilt

[FFmpeg-cvslog] ffplay: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jan 10 
11:04:36 2022 +0100| [bdf9ed41fe4bdf4e254615b7333ab0feb1977e98] | committer: 
Andreas Rheinhardt

ffplay: switch to new FIFO API

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

 fftools/ffplay.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..ac48d8765d 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -115,7 +115,7 @@ typedef struct MyAVPacketList {
 } MyAVPacketList;
 
 typedef struct PacketQueue {
-AVFifoBuffer *pkt_list;
+AVFifo *pkt_list;
 int nb_packets;
 int size;
 int64_t duration;
@@ -424,19 +424,18 @@ int64_t get_valid_channel_layout(int64_t channel_layout, 
int channels)
 static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
 {
 MyAVPacketList pkt1;
+int ret;
 
 if (q->abort_request)
return -1;
 
-if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
-if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
-return -1;
-}
 
 pkt1.pkt = pkt;
 pkt1.serial = q->serial;
 
-av_fifo_generic_write(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
+ret = av_fifo_write(q->pkt_list, &pkt1, 1);
+if (ret < 0)
+return ret;
 q->nb_packets++;
 q->size += pkt1.pkt->size + sizeof(pkt1);
 q->duration += pkt1.pkt->duration;
@@ -477,7 +476,7 @@ static int packet_queue_put_nullpacket(PacketQueue *q, 
AVPacket *pkt, int stream
 static int packet_queue_init(PacketQueue *q)
 {
 memset(q, 0, sizeof(PacketQueue));
-q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
+q->pkt_list = av_fifo_alloc2(1, sizeof(MyAVPacketList), 
AV_FIFO_FLAG_AUTO_GROW);
 if (!q->pkt_list)
 return AVERROR(ENOMEM);
 q->mutex = SDL_CreateMutex();
@@ -499,10 +498,8 @@ static void packet_queue_flush(PacketQueue *q)
 MyAVPacketList pkt1;
 
 SDL_LockMutex(q->mutex);
-while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
-av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
+while (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0)
 av_packet_free(&pkt1.pkt);
-}
 q->nb_packets = 0;
 q->size = 0;
 q->duration = 0;
@@ -513,7 +510,7 @@ static void packet_queue_flush(PacketQueue *q)
 static void packet_queue_destroy(PacketQueue *q)
 {
 packet_queue_flush(q);
-av_fifo_freep(&q->pkt_list);
+av_fifo_freep2(&q->pkt_list);
 SDL_DestroyMutex(q->mutex);
 SDL_DestroyCond(q->cond);
 }
@@ -551,8 +548,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, 
int block, int *seria
 break;
 }
 
-if (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
-av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
+if (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0) {
 q->nb_packets--;
 q->size -= pkt1.pkt->size + sizeof(pkt1);
 q->duration -= pkt1.pkt->duration;

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

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


[FFmpeg-cvslog] avutil/fifo: Deprecate old FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Dec 30 
13:49:12 2021 +0100| [a10f1aec1fe59ff3aee3fb93be44142ba33a5c1d] | committer: 
Andreas Rheinhardt

avutil/fifo: Deprecate old FIFO API

Users should switch to the superior AVFifo API.

Unfortunately AVFifoBuffer fields cannot be marked as deprecated because
it would trigger a warning wherever fifo.h is #included, due to
inlined av_fifo_peek2().

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

 doc/APIchanges  |  8 
 libavutil/fifo.c|  4 
 libavutil/fifo.h| 45 -
 libavutil/version.h |  3 ++-
 4 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0de7004e95..ea402f6118 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,14 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-02-07 - xx - lavu 57.21.100 - fifo.h
+  Deprecate AVFifoBuffer and the API around it, namely av_fifo_alloc(),
+  av_fifo_alloc_array(), av_fifo_free(), av_fifo_freep(), av_fifo_reset(),
+  av_fifo_size(), av_fifo_space(), av_fifo_generic_peek_at(),
+  av_fifo_generic_peek(), av_fifo_generic_read(), av_fifo_generic_write(),
+  av_fifo_realloc2(), av_fifo_grow(), av_fifo_drain() and av_fifo_peek2().
+  Users should switch to the AVFifo-API.
+
 2022-02-07 - xx - lavu 57.20.100 - fifo.h
   Add a new FIFO API, which allows setting a FIFO element size.
   This API operates on these elements rather than on bytes.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 4137ae2fd9..0af0154945 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -287,6 +287,8 @@ void av_fifo_freep2(AVFifo **f)
 }
 
 
+#if FF_API_FIFO_OLD_API
+FF_DISABLE_DEPRECATION_WARNINGS
 #define OLD_FIFO_SIZE_MAX (size_t)FFMIN3(INT_MAX, UINT32_MAX, SIZE_MAX)
 
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
@@ -499,3 +501,5 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
 f->rptr -= f->end - f->buffer;
 f->rndx += size;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 55548fbeb4..4eb2ce42f8 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -220,6 +220,7 @@ void av_fifo_reset2(AVFifo *f);
 void av_fifo_freep2(AVFifo **f);
 
 
+#if FF_API_FIFO_OLD_API
 typedef struct AVFifoBuffer {
 uint8_t *buffer;
 uint8_t *rptr, *wptr, *end;
@@ -230,7 +231,9 @@ typedef struct AVFifoBuffer {
  * Initialize an AVFifoBuffer.
  * @param size of FIFO
  * @return AVFifoBuffer or NULL in case of memory allocation failure
+ * @deprecated use av_fifo_alloc2()
  */
+attribute_deprecated
 AVFifoBuffer *av_fifo_alloc(unsigned int size);
 
 /**
@@ -238,25 +241,33 @@ AVFifoBuffer *av_fifo_alloc(unsigned int size);
  * @param nmemb number of elements
  * @param size  size of the single element
  * @return AVFifoBuffer or NULL in case of memory allocation failure
+ * @deprecated use av_fifo_alloc2()
  */
+attribute_deprecated
 AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);
 
 /**
  * Free an AVFifoBuffer.
  * @param f AVFifoBuffer to free
+ * @deprecated use the AVFifo API with av_fifo_freep2()
  */
+attribute_deprecated
 void av_fifo_free(AVFifoBuffer *f);
 
 /**
  * Free an AVFifoBuffer and reset pointer to NULL.
  * @param f AVFifoBuffer to free
+ * @deprecated use the AVFifo API with av_fifo_freep2()
  */
+attribute_deprecated
 void av_fifo_freep(AVFifoBuffer **f);
 
 /**
  * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in 
particular it is emptied.
  * @param f AVFifoBuffer to reset
+ * @deprecated use av_fifo_reset2() with the new AVFifo-API
  */
+attribute_deprecated
 void av_fifo_reset(AVFifoBuffer *f);
 
 /**
@@ -264,7 +275,9 @@ void av_fifo_reset(AVFifoBuffer *f);
  * amount of data you can read from it.
  * @param f AVFifoBuffer to read from
  * @return size
+ * @deprecated use av_fifo_can_read() with the new AVFifo-API
  */
+attribute_deprecated
 int av_fifo_size(const AVFifoBuffer *f);
 
 /**
@@ -272,7 +285,9 @@ int av_fifo_size(const AVFifoBuffer *f);
  * amount of data you can write into it.
  * @param f AVFifoBuffer to write into
  * @return size
+ * @deprecated use av_fifo_can_write() with the new AVFifo-API
  */
+attribute_deprecated
 int av_fifo_space(const AVFifoBuffer *f);
 
 /**
@@ -285,7 +300,11 @@ int av_fifo_space(const AVFifoBuffer *f);
  * @param dest data destination
  *
  * @return a non-negative number on success, a negative error code on failure
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_peek() when func == NULL,
+ * av_fifo_peek_to_cb() otherwise
  */
+attribute_deprecated
 int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int 
buf_size, void (*func)(void*, void*, int));
 
 /**
@@ -297,7 +316,11 @@ int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, 
int offset, int buf_siz
  * @param dest data destination
  *
  * @return a non-negative n

[FFmpeg-cvslog] ffmpeg: switch to new FIFO API

2022-02-06 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jan 10 
11:04:36 2022 +0100| [e6469e68cc06f0a9a6842f250af5e1f9b97876ca] | committer: 
Andreas Rheinhardt

ffmpeg: switch to new FIFO API

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

 fftools/ffmpeg.c| 69 +++--
 fftools/ffmpeg.h|  6 ++---
 fftools/ffmpeg_filter.c | 14 +-
 fftools/ffmpeg_opt.c|  4 +--
 4 files changed, 37 insertions(+), 56 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d134b025f..d909fa58a7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -527,23 +527,17 @@ static void ffmpeg_cleanup(int ret)
 for (j = 0; j < fg->nb_inputs; j++) {
 InputFilter *ifilter = fg->inputs[j];
 struct InputStream *ist = ifilter->ist;
+AVFrame *frame;
 
-while (av_fifo_size(ifilter->frame_queue)) {
-AVFrame *frame;
-av_fifo_generic_read(ifilter->frame_queue, &frame,
- sizeof(frame), NULL);
+while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0)
 av_frame_free(&frame);
-}
-av_fifo_freep(&ifilter->frame_queue);
+av_fifo_freep2(&ifilter->frame_queue);
 av_freep(&ifilter->displaymatrix);
 if (ist->sub2video.sub_queue) {
-while (av_fifo_size(ist->sub2video.sub_queue)) {
-AVSubtitle sub;
-av_fifo_generic_read(ist->sub2video.sub_queue,
- &sub, sizeof(sub), NULL);
+AVSubtitle sub;
+while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
 avsubtitle_free(&sub);
-}
-av_fifo_freep(&ist->sub2video.sub_queue);
+av_fifo_freep2(&ist->sub2video.sub_queue);
 }
 av_buffer_unref(&ifilter->hw_frames_ctx);
 av_freep(&ifilter->name);
@@ -608,12 +602,10 @@ static void ffmpeg_cleanup(int ret)
 avcodec_parameters_free(&ost->ref_par);
 
 if (ost->muxing_queue) {
-while (av_fifo_size(ost->muxing_queue)) {
-AVPacket *pkt;
-av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), 
NULL);
+AVPacket *pkt;
+while (av_fifo_read(ost->muxing_queue, &pkt, 1) >= 0)
 av_packet_free(&pkt);
-}
-av_fifo_freep(&ost->muxing_queue);
+av_fifo_freep2(&ost->muxing_queue);
 }
 
 av_freep(&output_streams[i]);
@@ -749,11 +741,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 if (!of->header_written) {
 AVPacket *tmp_pkt;
 /* the muxer is not initialized yet, buffer the packet */
-if (!av_fifo_space(ost->muxing_queue)) {
-size_t cur_size = av_fifo_size(ost->muxing_queue);
+if (!av_fifo_can_write(ost->muxing_queue)) {
+size_t cur_size = av_fifo_can_read(ost->muxing_queue);
 unsigned int are_we_over_size =
 (ost->muxing_queue_data_size + pkt->size) > 
ost->muxing_queue_data_threshold;
-size_t limit= are_we_over_size ? ost->max_muxing_queue_size : 
INT_MAX;
+size_t limit= are_we_over_size ? ost->max_muxing_queue_size : 
SIZE_MAX;
 size_t new_size = FFMIN(2 * cur_size, limit);
 
 if (new_size <= cur_size) {
@@ -762,7 +754,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
ost->file_index, ost->st->index);
 exit_program(1);
 }
-ret = av_fifo_realloc2(ost->muxing_queue, new_size);
+ret = av_fifo_grow2(ost->muxing_queue, new_size - cur_size);
 if (ret < 0)
 exit_program(1);
 }
@@ -774,7 +766,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 exit_program(1);
 av_packet_move_ref(tmp_pkt, pkt);
 ost->muxing_queue_data_size += tmp_pkt->size;
-av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), 
NULL);
+av_fifo_write(ost->muxing_queue, &tmp_pkt, 1);
 return;
 }
 
@@ -2195,15 +2187,11 @@ static int ifilter_send_frame(InputFilter *ifilter, 
AVFrame *frame, int keep_ref
 if (!tmp)
 return AVERROR(ENOMEM);
 
-if (!av_fifo_space(ifilter->frame_queue)) {
-ret = av_fifo_realloc2(ifilter->frame_queue, 2 * 
av_fifo_size(ifilter->frame_queue));
-if (ret < 0) {
-av_frame_free(&tmp);
-return ret;
-}
-}
-av_fifo_generic_write(ifilter->frame_queue, &tmp, sizeof(tmp), 
NULL);
-return 0;
+  

[FFmpeg-cvslog] lavu/tx: refactor assembly codelet definition

2022-02-06 Thread Lynne
ffmpeg | branch: master | Lynne  | Mon Feb  7 03:30:27 2022 
+0100| [3bbe9c5e3842338c0eb491cc9d240c90df221fdb] | committer: Lynne

lavu/tx: refactor assembly codelet definition

This commit does some refactoring to make defining assembly codelets
smaller, and fixes compiler redefinition warnings. It also allows
for other assembly versions to reuse the same boilerplate code as
x86.

Finally, it also adds the out_of_place flag to all assembly codelets.
This changes nothing, as out-of-place operation was assumed to be
available anyway, but this makes it more explicit.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3bbe9c5e3842338c0eb491cc9d240c90df221fdb
---

 libavutil/tx_priv.h   |  24 
 libavutil/x86/tx_float_init.c | 140 ++
 2 files changed, 71 insertions(+), 93 deletions(-)

diff --git a/libavutil/tx_priv.h b/libavutil/tx_priv.h
index 11892df4be..28c8435c83 100644
--- a/libavutil/tx_priv.h
+++ b/libavutil/tx_priv.h
@@ -29,6 +29,8 @@
 #define TX_NAME(x) x ## _float_c
 #define TX_NAME_STR(x) x "_float_c"
 #define TX_TYPE(x) AV_TX_FLOAT_ ## x
+#define TX_FN_NAME(fn, suffix) ff_tx_ ## fn ## _float_ ## suffix
+#define TX_FN_NAME_STR(fn, suffix) #fn "_float_" #suffix
 #define MULT(x, m) ((x) * (m))
 #define SCALE_TYPE float
 typedef float TXSample;
@@ -38,6 +40,8 @@ typedef AVComplexFloat TXComplex;
 #define TX_NAME(x) x ## _double_c
 #define TX_NAME_STR(x) x "_double_c"
 #define TX_TYPE(x) AV_TX_DOUBLE_ ## x
+#define TX_FN_NAME(fn, suffix) ff_tx_ ## fn ## _double_ ## suffix
+#define TX_FN_NAME_STR(fn, suffix) #fn "_double_" #suffix
 #define MULT(x, m) ((x) * (m))
 #define SCALE_TYPE double
 typedef double TXSample;
@@ -47,6 +51,8 @@ typedef AVComplexDouble TXComplex;
 #define TX_NAME(x) x ## _int32_c
 #define TX_NAME_STR(x) x "_int32_c"
 #define TX_TYPE(x) AV_TX_INT32_ ## x
+#define TX_FN_NAME(fn, suffix) ff_tx_ ## fn ## _int32_ ## suffix
+#define TX_FN_NAME_STR(fn, suffix) #fn "_int32_" #suffix
 #define MULT(x, m) (int64_t)(x)) * (int64_t)(m)) + 0x4000) >> 31)
 #define SCALE_TYPE float
 typedef int32_t TXSample;
@@ -55,6 +61,24 @@ typedef AVComplexInt32 TXComplex;
 typedef void TXComplex;
 #endif
 
+#define TX_DECL_FN(fn, suffix) \
+void TX_FN_NAME(fn, suffix)(AVTXContext *s, void *o, void *i, ptrdiff_t 
st);
+
+#define TX_DEF(fn, tx_type, len_min, len_max, f1, f2,  
\
+   p, init_fn, suffix, cf, cd_flags, cf2)  
\
+&(const FFTXCodelet){  
\
+.name   = TX_FN_NAME_STR(fn, suffix),  
\
+.function   = TX_FN_NAME(fn, suffix),  
\
+.type   = TX_TYPE(tx_type),
\
+.flags  = FF_TX_ALIGNED | FF_TX_OUT_OF_PLACE | cd_flags,   
\
+.factors= { f1, f2 },  
\
+.min_len= len_min, 
\
+.max_len= len_max, 
\
+.init   = init_fn, 
\
+.cpu_flags  = cf2 | AV_CPU_FLAG_ ## cf,
\
+.prio   = p,   
\
+}
+
 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
 
 #define CMUL(dre, dim, are, aim, bre, bim)  \
diff --git a/libavutil/x86/tx_float_init.c b/libavutil/x86/tx_float_init.c
index 3a87711def..e60faf7fa6 100644
--- a/libavutil/x86/tx_float_init.c
+++ b/libavutil/x86/tx_float_init.c
@@ -23,19 +23,33 @@
 
 #include "config.h"
 
-/* These versions already do what we need them to do. */
-#define ff_tx_fft2_ns_float_sse3 ff_tx_fft2_float_sse3
-#define ff_tx_fft4_ns_float_sse2 ff_tx_fft4_fwd_float_sse2
+TX_DECL_FN(fft2,  sse3)
+TX_DECL_FN(fft4_fwd,  sse2)
+TX_DECL_FN(fft4_inv,  sse2)
+TX_DECL_FN(fft8,  sse3)
+TX_DECL_FN(fft8_ns,   sse3)
+TX_DECL_FN(fft8,  avx)
+TX_DECL_FN(fft8_ns,   avx)
+TX_DECL_FN(fft16, avx)
+TX_DECL_FN(fft16_ns,  avx)
+TX_DECL_FN(fft16, fma3)
+TX_DECL_FN(fft16_ns,  fma3)
+TX_DECL_FN(fft32, avx)
+TX_DECL_FN(fft32_ns,  avx)
+TX_DECL_FN(fft32, fma3)
+TX_DECL_FN(fft32_ns,  fma3)
+TX_DECL_FN(fft_sr,avx)
+TX_DECL_FN(fft_sr_ns, avx)
+TX_DECL_FN(fft_sr,avx2)
+TX_DECL_FN(fft_sr_ns, avx2)
 
 #define DECL_INIT_FN(basis, interleave)
\
-static av_cold int 
\
-ff_tx_fft_sr_codelet_init_b ##basis## _i ##interleave## _x86   
\
-(AVTXContext *s,   
\
- const FFTXCodelet *cd,
\
- uint64_t flags,   
\
- FFTXCodeletOptions *opts,  

[FFmpeg-cvslog] lavu/tx: disable debugging information when CONFIG_SMALL

2022-02-06 Thread Lynne
ffmpeg | branch: master | Lynne  | Mon Feb  7 03:42:19 2022 
+0100| [eac4c3574bb4e145a84e160c4dba1c50b60f3470] | committer: Lynne

lavu/tx: disable debugging information when CONFIG_SMALL

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

 libavutil/tx.c  | 36 +++-
 libavutil/tx_priv.h | 12 ++--
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/libavutil/tx.c b/libavutil/tx.c
index 573f4863d1..2d8d21b65f 100644
--- a/libavutil/tx.c
+++ b/libavutil/tx.c
@@ -292,6 +292,7 @@ static const FFTXCodelet * const ff_tx_null_list[] = {
 NULL,
 };
 
+#if !CONFIG_SMALL
 static void print_flags(AVBPrint *bp, uint64_t f)
 {
 int prev = 0;
@@ -371,6 +372,20 @@ static void print_cd_info(const FFTXCodelet *cd, int prio, 
int print_prio)
 av_log(NULL, AV_LOG_VERBOSE, "%s\n", bp.str);
 }
 
+static void print_tx_structure(AVTXContext *s, int depth)
+{
+const FFTXCodelet *cd = s->cd_self;
+
+for (int i = 0; i <= depth; i++)
+av_log(NULL, AV_LOG_VERBOSE, "");
+
+print_cd_info(cd, cd->prio, 0);
+
+for (int i = 0; i < s->nb_sub; i++)
+print_tx_structure(&s->sub[i], depth + 1);
+}
+#endif /* CONFIG_SMALL */
+
 typedef struct TXCodeletMatch {
 const FFTXCodelet *cd;
 int prio;
@@ -431,7 +446,9 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType 
type,
 TXCodeletMatch *cd_tmp, *cd_matches = NULL;
 unsigned int cd_matches_size = 0;
 int nb_cd_matches = 0;
+#if !CONFIG_SMALL
 AVBPrint bp = { 0 };
+#endif
 
 /* Array of all compiled codelet lists. Order is irrelevant. */
 const FFTXCodelet * const * const codelet_list[] = {
@@ -543,6 +560,7 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType 
type,
 }
 }
 
+#if !CONFIG_SMALL
 /* Print debugging info */
 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprintf(&bp, "For transform of length %i, %s, ", len,
@@ -552,6 +570,7 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType 
type,
 print_flags(&bp, flags);
 av_bprintf(&bp, ", found %i matches%s", nb_cd_matches,
nb_cd_matches ? ":" : ".");
+#endif
 
 /* No matches found */
 if (!nb_cd_matches)
@@ -560,12 +579,14 @@ av_cold int ff_tx_init_subtx(AVTXContext *s, enum 
AVTXType type,
 /* Sort the list */
 AV_QSORT(cd_matches, nb_cd_matches, TXCodeletMatch, cmp_matches);
 
+#if !CONFIG_SMALL
 av_log(NULL, AV_LOG_VERBOSE, "%s\n", bp.str);
 
 for (int i = 0; i < nb_cd_matches; i++) {
 av_log(NULL, AV_LOG_VERBOSE, "%i: ", i + 1);
 print_cd_info(cd_matches[i].cd, cd_matches[i].prio, 1);
 }
+#endif
 
 if (!s->sub) {
 s->sub = sub = av_mallocz(TX_MAX_SUB*sizeof(*sub));
@@ -614,19 +635,6 @@ end:
 return ret;
 }
 
-static void print_tx_structure(AVTXContext *s, int depth)
-{
-const FFTXCodelet *cd = s->cd_self;
-
-for (int i = 0; i <= depth; i++)
-av_log(NULL, AV_LOG_VERBOSE, "");
-
-print_cd_info(cd, cd->prio, 0);
-
-for (int i = 0; i < s->nb_sub; i++)
-print_tx_structure(&s->sub[i], depth + 1);
-}
-
 av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type,
int inv, int len, const void *scale, uint64_t flags)
 {
@@ -655,8 +663,10 @@ av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, 
enum AVTXType type,
 *ctx = &tmp.sub[0];
 *tx  = tmp.fn[0];
 
+#if !CONFIG_SMALL
 av_log(NULL, AV_LOG_VERBOSE, "Transform tree:\n");
 print_tx_structure(*ctx, 0);
+#endif
 
 return ret;
 }
diff --git a/libavutil/tx_priv.h b/libavutil/tx_priv.h
index 28c8435c83..c9eda44e61 100644
--- a/libavutil/tx_priv.h
+++ b/libavutil/tx_priv.h
@@ -27,10 +27,10 @@
 #ifdef TX_FLOAT
 #define TX_TAB(x) x ## _float
 #define TX_NAME(x) x ## _float_c
-#define TX_NAME_STR(x) x "_float_c"
+#define TX_NAME_STR(x) NULL_IF_CONFIG_SMALL(x "_float_c")
 #define TX_TYPE(x) AV_TX_FLOAT_ ## x
 #define TX_FN_NAME(fn, suffix) ff_tx_ ## fn ## _float_ ## suffix
-#define TX_FN_NAME_STR(fn, suffix) #fn "_float_" #suffix
+#define TX_FN_NAME_STR(fn, suffix) NULL_IF_CONFIG_SMALL(#fn "_float_" #suffix)
 #define MULT(x, m) ((x) * (m))
 #define SCALE_TYPE float
 typedef float TXSample;
@@ -38,10 +38,10 @@ typedef AVComplexFloat TXComplex;
 #elif defined(TX_DOUBLE)
 #define TX_TAB(x) x ## _double
 #define TX_NAME(x) x ## _double_c
-#define TX_NAME_STR(x) x "_double_c"
+#define TX_NAME_STR(x) NULL_IF_CONFIG_SMALL(x "_double_c")
 #define TX_TYPE(x) AV_TX_DOUBLE_ ## x
 #define TX_FN_NAME(fn, suffix) ff_tx_ ## fn ## _double_ ## suffix
-#define TX_FN_NAME_STR(fn, suffix) #fn "_double_" #suffix
+#define TX_FN_NAME_STR(fn, suffix) NULL_IF_CONFIG_SMALL(#fn "_double_" #suffix)
 #define MULT(x, m) ((x) * (m))
 #define SCALE_TYPE double
 typedef double TXSample;
@@ -49,10 +49,10 @@ typedef AVComplexDouble TXComplex;
 #elif defined(TX_INT32)
 #define TX_TAB(x) x ## _int32
 #define TX_NAME

[FFmpeg-cvslog] lavu/tx: wrap missed string in NULL_IF_CONFIG_SMALL

2022-02-06 Thread Lynne
ffmpeg | branch: master | Lynne  | Mon Feb  7 04:22:19 2022 
+0100| [04cc7a5548fa22241a2d6bb4f719fe8e0e0843f1] | committer: Lynne

lavu/tx: wrap missed string in NULL_IF_CONFIG_SMALL

It's the only one that isn't defined through the macros used elsewhere.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=04cc7a5548fa22241a2d6bb4f719fe8e0e0843f1
---

 libavutil/tx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/tx.c b/libavutil/tx.c
index 2d8d21b65f..c648d4a1cd 100644
--- a/libavutil/tx.c
+++ b/libavutil/tx.c
@@ -274,7 +274,7 @@ static void ff_tx_null(AVTXContext *s, void *_out, void 
*_in, ptrdiff_t stride)
 }
 
 static const FFTXCodelet ff_tx_null_def = {
-.name   = "null",
+.name   = NULL_IF_CONFIG_SMALL("null"),
 .function   = ff_tx_null,
 .type   = TX_TYPE_ANY,
 .flags  = AV_TX_UNALIGNED | FF_TX_ALIGNED |

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

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