* [FFmpeg-devel] [PATCH v2 00/31] New FIFO API
@ 2022-01-24 14:44 Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek() Andreas Rheinhardt
` (30 more replies)
0 siblings, 31 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:44 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is a modified version of Anton's earlier patchset [1].
The main changes are that the new FIFO API is a clean break with
the old API (the new API uses a new structure (called AVFifo)
instead of sharing AVFifoBuffer with the old API) and that it
is now documented that one may attempt to read/write more
from/to the FIFO than is currently possible and that such
an attempt leads to an error being returned. This allows to
replace loops of the form
while (av_fifo_size(fifo)) {
TYPE element;
av_fifo_generic_read(fifo, &element, sizeof(element), NULL);
// do something with element, typically: free it
}
by
TYPE element;
while (av_fifo_read(fifo, &element, 1) >= 0)
// do something with element
- Andreas
[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2022-January/291156.html
Andreas Rheinhardt (2):
avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()
avcodec/qsvenc: Reindent after the previous commit
Anton Khirnov (29):
lavu/fifo: disallow overly large fifo sizes
lavu/fifo: Add new AVFifo API based upon the notion of element size
lavu/fifo: add a flag for automatically growing the FIFO as needed
lavu/tests/fifo: switch to the new API
lavc/avcodec: switch to new FIFO API
lavc/amfenc: switch to new FIFO API
lavc/cuviddec: do not reallocate the fifo unnecessarily
lavc/cuviddec: convert to the new FIFO API
lavc/libvorbisenc: switch to new FIFO API
lavc/libvpxenc: switch to the new FIFO API
lavc/libvpxenc: remove unneeded context variable
lavc/nvenc: switch to the new FIFO API
lavc/qsvdec: switch to the new FIFO API
lavc/qsvenc: switch to new FIFO API
lavf/dvenc: return an error on audio/video desync
lavf/dvenc: switch to new FIFO API
lavf/mpegenc: switch to new FIFO API
lavf/swfenc: switch to new FIFO API
lavf/udp: switch to new FIFO API
lavf/async: switch to new FIFO API
lavd/jack: switch to the new FIFO API
lavu/audio_fifo: drop an unnecessary include
lavu/audio_fifo: switch to new FIFO API
lavu/threadmessage: switch to new FIFO API
lavfi/qsvvpp: switch to new FIFO API
lavfi/vf_deshake_opencl: switch to new FIFO API
ffplay: switch to new FIFO API
ffmpeg: switch to new FIFO API
avutil/fifo: Deprecate old FIFO API
doc/APIchanges | 17 ++
fftools/ffmpeg.c | 69 +++-----
fftools/ffmpeg.h | 6 +-
fftools/ffmpeg_filter.c | 14 +-
fftools/ffmpeg_opt.c | 4 +-
fftools/ffplay.c | 22 +--
libavcodec/amfenc.c | 43 ++---
libavcodec/amfenc.h | 2 +-
libavcodec/avcodec.c | 17 +-
libavcodec/cuviddec.c | 28 ++-
libavcodec/decode.c | 24 +--
libavcodec/internal.h | 2 +-
libavcodec/libvorbisenc.c | 20 +--
libavcodec/libvpxenc.c | 42 ++---
libavcodec/nvenc.c | 49 +++---
libavcodec/nvenc.h | 8 +-
libavcodec/qsvdec.c | 88 ++++------
libavcodec/qsvenc.c | 134 +++++++-------
libavcodec/qsvenc.h | 2 +-
libavdevice/jack.c | 30 ++--
libavfilter/qsvvpp.c | 46 ++---
libavfilter/qsvvpp.h | 2 +-
libavfilter/vf_deshake_opencl.c | 92 ++++------
libavformat/async.c | 68 ++++----
libavformat/dvenc.c | 28 +--
libavformat/mpegenc.c | 40 +++--
libavformat/swfenc.c | 22 ++-
libavformat/udp.c | 34 ++--
libavutil/audio_fifo.c | 44 ++---
libavutil/audio_fifo.h | 1 -
libavutil/fifo.c | 298 +++++++++++++++++++++++++++++---
libavutil/fifo.h | 237 ++++++++++++++++++++++++-
libavutil/tests/fifo.c | 47 +++--
libavutil/threadmessage.c | 38 ++--
libavutil/version.h | 3 +-
35 files changed, 986 insertions(+), 635 deletions(-)
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek()
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt
` (29 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Avoids code duplication. It furthermore properly checks
for buf_size to be > 0 before doing anything.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
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,
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek() Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size Andreas Rheinhardt
` (28 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
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.
---
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 <stdint.h>
+
#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;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek() Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-02-05 7:55 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed Andreas Rheinhardt
` (27 subsequent siblings)
30 siblings, 1 reply; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
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.
---
doc/APIchanges | 9 ++
libavutil/fifo.c | 224 ++++++++++++++++++++++++++++++++++++++++++++
libavutil/fifo.h | 179 +++++++++++++++++++++++++++++++++++
libavutil/version.h | 2 +-
4 files changed, 413 insertions(+), 1 deletion(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..57a9df9bef 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,15 @@ libavutil: 2021-04-27
API changes, most recent first:
+2022-01-xx - xxxxxxxxxx - lavu 57.19.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-04 - 78dc21b123e - lavu 57.16.100 - frame.h
Add AV_FRAME_DATA_DOVI_METADATA.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 55621f0dca..0e0d84258f 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -26,6 +26,230 @@
#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
+ int is_empty;
+};
+
+AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
+ unsigned int flags)
+{
+ AVFifo *f;
+ void *buffer;
+
+ if (!elem_size)
+ return NULL;
+
+ 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_t len = 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 += len;
+ if (offset_w >= f->nb_elems)
+ offset_w = 0;
+ to_write -= len;
+ }
+ f->offset_w = offset_w;
+
+ if (*nb_elems != to_write)
+ f->is_empty = 0;
+ *nb_elems -= to_write;
+
+ return ret;
+}
+
+int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
+{
+ return fifo_write_common(f, buf, &nb_elems, NULL, NULL);
+}
+
+int av_fifo_write_from_cb(AVFifo *f, AVFifoCB read_cb,
+ void *opaque, size_t *nb_elems)
+{
+ return fifo_write_common(f, NULL, nb_elems, read_cb, opaque);
+}
+
+static int fifo_peek_common(const AVFifo *f, uint8_t *buf, size_t *nb_elems,
+ size_t offset, AVFifoCB write_cb, void *opaque)
+{
+ size_t to_read = *nb_elems;
+ size_t offset_r = f->offset_r;
+ size_t can_read = av_fifo_can_read(f);
+ int ret = 0;
+
+ if (offset > can_read || to_read > can_read - offset) {
+ *nb_elems = 0;
+ return AVERROR(EINVAL);
+ }
+
+ if (offset_r >= f->nb_elems - offset)
+ offset_r -= f->nb_elems - offset;
+ else
+ offset_r += offset;
+
+ while (to_read > 0) {
+ size_t len = FFMIN(f->nb_elems - offset_r, to_read);
+ uint8_t *rptr = f->buffer + offset_r * f->elem_size;
+
+ if (write_cb) {
+ ret = write_cb(opaque, rptr, &len);
+ if (ret < 0 || len == 0)
+ break;
+ } else {
+ memcpy(buf, rptr, len * f->elem_size);
+ buf += len * f->elem_size;
+ }
+ offset_r += len;
+ if (offset_r >= f->nb_elems)
+ offset_r = 0;
+ to_read -= len;
+ }
+
+ *nb_elems -= to_read;
+
+ return ret;
+}
+
+int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
+{
+ int ret = fifo_peek_common(f, buf, &nb_elems, 0, NULL, NULL);
+ av_fifo_drain2(f, nb_elems);
+ return ret;
+}
+
+int av_fifo_read_to_cb(AVFifo *f, AVFifoCB write_cb,
+ void *opaque, size_t *nb_elems)
+{
+ int ret = fifo_peek_common(f, NULL, nb_elems, 0, write_cb, opaque);
+ av_fifo_drain2(f, *nb_elems);
+ return ret;
+}
+
+int av_fifo_peek(AVFifo *f, void *buf, size_t nb_elems, size_t offset)
+{
+ return fifo_peek_common(f, buf, &nb_elems, offset, NULL, NULL);
+}
+
+int av_fifo_peek_to_cb(AVFifo *f, AVFifoCB write_cb, void *opaque,
+ size_t *nb_elems, size_t offset)
+{
+ return fifo_peek_common(f, NULL, nb_elems, offset, write_cb, opaque);
+}
+
+void av_fifo_drain2(AVFifo *f, size_t size)
+{
+ const size_t cur_size = av_fifo_can_read(f);
+
+ av_assert0(cur_size >= size);
+ if (cur_size == size)
+ f->is_empty = 1;
+
+ if (f->offset_r >= f->nb_elems - size)
+ f->offset_r -= f->nb_elems - size;
+ else
+ f->offset_r += size;
+}
+
+void av_fifo_reset2(AVFifo *f)
+{
+ f->offset_r = f->offset_w = 0;
+ f->is_empty = 1;
+}
+
+void av_fifo_freep2(AVFifo **f)
+{
+ if (*f) {
+ av_freep(&(*f)->buffer);
+ av_freep(f);
+ }
+}
+
+
#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)
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index f4fd291e59..f455022e3c 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -28,6 +28,185 @@
#include "avutil.h"
#include "attributes.h"
+typedef struct AVFifo AVFifo;
+
+/**
+ * Callback for writing or reading from a FIFO, passed to (and invoked from) the
+ * av_fifo_*_cb() functions. It may be invoked multiple times from a single
+ * av_fifo_*_cb() call and may process less data than the maximum size indicated
+ * by nb_elems.
+ *
+ * @param opaque the opaque pointer provided to the av_fifo_*_cb() function
+ * @param buf the buffer for reading or writing the data, depending on which
+ * av_fifo_*_cb function is called
+ * @param nb_elems On entry contains the maximum number of elements that can be
+ * read from / written into buf. On success, the callback should
+ * update it to contain the number of elements actually written.
+ *
+ * @return 0 on success, a negative error code on failure (will be returned from
+ * the invoking av_fifo_*_cb() function)
+ */
+typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems);
+
+/**
+ * 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
+ *
+ * @return newly-allocated AVFifo on success, a negative error code on failure
+ */
+AVFifo *av_fifo_alloc2(size_t elems, size_t elem_size,
+ unsigned int flags);
+
+/**
+ * @return Element size for FIFO operations. This element size is set at
+ * FIFO allocation and remains constant during its lifetime
+ */
+size_t av_fifo_elem_size(const AVFifo *f);
+
+/**
+ * @return number of elements available for reading from the given FIFO.
+ */
+size_t av_fifo_can_read(const AVFifo *f);
+
+/**
+ * @return number of elements that can be written into the given FIFO.
+ */
+size_t av_fifo_can_write(const AVFifo *f);
+
+/**
+ * Enlarge an AVFifo.
+ *
+ * On success, the FIFO will be large enough to hold exactly
+ * inc + av_fifo_can_read() + av_fifo_can_write()
+ * elements. In case of failure, the old FIFO is kept unchanged.
+ *
+ * @param f AVFifo to resize
+ * @param inc number of elements to allocate for, in addition to the current
+ * allocated size
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_grow2(AVFifo *f, size_t inc);
+
+/**
+ * Write data into a FIFO.
+ *
+ * In case nb_elems > av_fifo_can_write(f), nothing is written and an error
+ * is returned.
+ *
+ * @param f the FIFO buffer
+ * @param buf Data to be written. nb_elems * av_fifo_elem_size(f) bytes will be
+ * read from buf on success.
+ * @param nb_elems number of elements to write into FIFO
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems);
+
+/**
+ * Write data from a user-provided callback into a FIFO.
+ *
+ * @param f the FIFO buffer
+ * @param read_cb Callback supplying the data to the FIFO. May be called
+ * multiple times.
+ * @param opaque opaque user data to be provided to read_cb
+ * @param nb_elems Should point to the maximum number of elements that can be
+ * written. Will be updated to contain the number of elements
+ * actually written.
+ *
+ * @return non-negative number on success, a negative error code on failure
+ */
+int av_fifo_write_from_cb(AVFifo *f, AVFifoCB read_cb,
+ void *opaque, size_t *nb_elems);
+
+/**
+ * Read data from a FIFO.
+ *
+ * In case nb_elems > av_fifo_can_read(f), nothing is read and an error
+ * is returned.
+ *
+ * @param f the FIFO buffer
+ * @param buf Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes
+ * will be written into buf on success.
+ * @param nb_elems number of elements to read from FIFO
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems);
+
+/**
+ * Feed data from a FIFO into a user-provided callback.
+ *
+ * @param f the FIFO buffer
+ * @param write_cb Callback the data will be supplied to. May be called
+ * multiple times.
+ * @param opaque opaque user data to be provided to write_cb
+ * @param nb_elems Should point to the maximum number of elements that can be
+ * read. Will be updated to contain the total number of elements
+ * actually sent to the callback.
+ *
+ * @return non-negative number on success, a negative error code on failure
+ */
+int av_fifo_read_to_cb(AVFifo *f, AVFifoCB write_cb,
+ void *opaque, size_t *nb_elems);
+
+/**
+ * Read data from a FIFO without modifying FIFO state.
+ *
+ * Returns an error if an attempt is made to peek to nonexistent elements
+ * (i.e. if offset + nb_elems is larger than av_fifo_can_read(f)).
+ *
+ * @param f the FIFO buffer
+ * @param buf Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes
+ * will be written into buf.
+ * @param nb_elems number of elements to read from FIFO
+ * @param offset number of initial elements to skip.
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_peek(AVFifo *f, void *buf, size_t nb_elems, size_t offset);
+
+/**
+ * Feed data from a FIFO into a user-provided callback.
+ *
+ * @param f the FIFO buffer
+ * @param write_cb Callback the data will be supplied to. May be called
+ * multiple times.
+ * @param opaque opaque user data to be provided to write_cb
+ * @param nb_elems Should point to the maximum number of elements that can be
+ * read. Will be updated to contain the total number of elements
+ * actually sent to the callback.
+ * @param offset number of initial elements to skip; offset + *nb_elems must not
+ * be larger than av_fifo_can_read(f).
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int av_fifo_peek_to_cb(AVFifo *f, AVFifoCB write_cb, void *opaque,
+ size_t *nb_elems, size_t offset);
+
+/**
+ * Discard the specified amount of data from an AVFifo.
+ * @param size number of elements to discard, MUST NOT be larger than
+ * av_fifo_can_read(f)
+ */
+void av_fifo_drain2(AVFifo *f, size_t size);
+
+/*
+ * Empty the AVFifo.
+ * @param f AVFifo to reset
+ */
+void av_fifo_reset2(AVFifo *f);
+
+/**
+ * Free an AVFifo and reset pointer to NULL.
+ * @param f Pointer to an AVFifo to free. *f == NULL is allowed.
+ */
+void av_fifo_freep2(AVFifo **f);
+
+
typedef struct AVFifoBuffer {
uint8_t *buffer;
uint8_t *rptr, *wptr, *end;
diff --git a/libavutil/version.h b/libavutil/version.h
index 953aac9d94..331b8f6ea9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 57
-#define LIBAVUTIL_VERSION_MINOR 18
+#define LIBAVUTIL_VERSION_MINOR 19
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (2 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API Andreas Rheinhardt
` (26 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
This will not increase the FIFO beyond 1MB, unless the caller explicitly
specifies otherwise.
---
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 57a9df9bef..75e0b1f49a 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-04 - 78dc21b123e - lavu 57.16.100 - frame.h
Add AV_FRAME_DATA_DOVI_METADATA.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 0e0d84258f..5a09dd3877 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
int is_empty;
+
+ unsigned int flags;
+ size_t auto_grow_limit;
};
AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
@@ -57,9 +63,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;
@@ -107,6 +121,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)
{
@@ -114,8 +148,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_t len = 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.
*/
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (3 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API Andreas Rheinhardt
` (25 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (4 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: " Andreas Rheinhardt
` (24 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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 0912f86a14..4023d2dd2e 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)
@@ -543,9 +536,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
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (5 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily Andreas Rheinhardt
` (23 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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;
// shift dts back by max_b_frames in timing
- AVFifoBuffer *timestamp_list;
+ AVFifo *timestamp_list;
int64_t dts_delay;
// common encoder option options
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (6 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: " Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API Andreas Rheinhardt
` (22 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (7 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to " Andreas Rheinhardt
` (21 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (8 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the " Andreas Rheinhardt
` (20 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (9 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to " Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable Andreas Rheinhardt
` (19 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (10 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the " Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API Andreas Rheinhardt
` (18 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
discard_hdr10_plus is 0 IFF hdr10_plus_fifo is non-NULL, so we can test
for the latter and avoid an extra variable.
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (11 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: " Andreas Rheinhardt
` (17 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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->timestamp_list, frame->pts);
}
/* all the pending buffers are now ready for output */
if (nv_status == NV_ENC_SUCCESS) {
- while (av_fifo_size(ctx->output_surface_queue) > 0) {
- av_fifo_generic_read(ctx->output_surface_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL);
- av_fifo_generic_write(ctx->output_surface_ready_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL);
- }
+ while (av_fifo_read(ctx->output_surface_queue, &tmp_out_surf, 1) >= 0)
+ av_fifo_write(ctx->output_surface_ready_queue, &tmp_out_surf, 1);
}
return 0;
@@ -2483,7 +2480,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
av_frame_unref(frame);
if (output_ready(avctx, avctx->internal->draining)) {
- av_fifo_generic_read(ctx->output_surface_ready_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL);
+ av_fifo_read(ctx->output_surface_ready_queue, &tmp_out_surf, 1);
res = nvenc_push_context(avctx);
if (res < 0)
@@ -2498,7 +2495,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
if (res)
return res;
- av_fifo_generic_write(ctx->unused_surface_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL);
+ av_fifo_write(ctx->unused_surface_queue, &tmp_out_surf, 1);
} else if (avctx->internal->draining) {
return AVERROR_EOF;
} else {
@@ -2513,5 +2510,5 @@ av_cold void ff_nvenc_encode_flush(AVCodecContext *avctx)
NvencContext *ctx = avctx->priv_data;
nvenc_send_frame(avctx, NULL);
- av_fifo_reset(ctx->timestamp_list);
+ av_fifo_reset2(ctx->timestamp_list);
}
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index b42a156c56..9eb129952e 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -168,10 +168,10 @@ typedef struct NvencContext
int nb_surfaces;
NvencSurface *surfaces;
- AVFifoBuffer *unused_surface_queue;
- AVFifoBuffer *output_surface_queue;
- AVFifoBuffer *output_surface_ready_queue;
- AVFifoBuffer *timestamp_list;
+ AVFifo *unused_surface_queue;
+ AVFifo *output_surface_queue;
+ AVFifo *output_surface_ready_queue;
+ AVFifo *timestamp_list;
NV_ENC_SEI_PAYLOAD *sei_data;
int sei_data_size;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: switch to the new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (12 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API Andreas Rheinhardt
@ 2022-01-24 14:45 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to " Andreas Rheinhardt
` (16 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
libavcodec/qsvdec.c | 88 ++++++++++++++++++---------------------------
1 file changed, 35 insertions(+), 53 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d9e0fef1f1..56cd5c86c9 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -56,6 +56,11 @@ static const AVRational mfx_tb = { 1, 90000 };
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;
@@ -71,7 +76,7 @@ typedef struct QSVContext {
*/
QSVFrame *work_frames;
- AVFifoBuffer *async_fifo;
+ AVFifo *async_fifo;
int zero_consume_run;
int buffered_count;
int reinit_flag;
@@ -208,16 +213,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;
@@ -235,7 +230,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);
}
@@ -502,7 +497,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;
@@ -561,6 +555,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
}
if (*sync) {
+ QSVAsyncFrame aframe;
QSVFrame *out_frame = find_frame(q, outsurf);
if (!out_frame) {
@@ -571,35 +566,36 @@ 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);
@@ -611,10 +607,10 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
frame->interlaced_frame =
!(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
- frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
+ frame->pict_type = ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
//Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
if (avctx->codec_id == AV_CODEC_ID_H264)
- frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
+ frame->key_frame = !!(aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
/* update the surface properties */
if (avctx->pix_fmt == AV_PIX_FMT_QSV)
@@ -633,14 +629,11 @@ static void qsv_decode_close_qsvcontext(QSVContext *q)
if (q->session)
MFXVideoDECODE_Close(q->session);
- while (q->async_fifo && av_fifo_size(q->async_fifo)) {
- QSVFrame *out_frame;
- mfxSyncPoint *sync;
-
- av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
- av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
-
- av_freep(&sync);
+ if (q->async_fifo) {
+ QSVAsyncFrame aframe;
+ while (av_fifo_read(q->async_fifo, &aframe, 1) >= 0)
+ av_freep(&aframe.sync);
+ av_fifo_freep2(&q->async_fifo);
}
while (cur) {
@@ -650,9 +643,6 @@ static void qsv_decode_close_qsvcontext(QSVContext *q)
cur = q->work_frames;
}
- av_fifo_free(q->async_fifo);
- q->async_fifo = NULL;
-
ff_qsv_close_internal_session(&q->internal_qs);
av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -734,7 +724,7 @@ typedef struct QSVDecContext {
int load_plugin;
- AVFifoBuffer *packet_fifo;
+ AVFifo *packet_fifo;
AVPacket buffer_pkt;
} QSVDecContext;
@@ -742,10 +732,8 @@ typedef struct QSVDecContext {
static void qsv_clear_buffers(QSVDecContext *s)
{
AVPacket pkt;
- while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
- av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
+ while (av_fifo_read(s->packet_fifo, &pkt, 1) >= 0)
av_packet_unref(&pkt);
- }
av_packet_unref(&s->buffer_pkt);
}
@@ -758,7 +746,7 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx)
qsv_clear_buffers(s);
- av_fifo_free(s->packet_fifo);
+ av_fifo_freep2(&s->packet_fifo);
return 0;
}
@@ -797,7 +785,8 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
}
s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
- s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
+ s->packet_fifo = av_fifo_alloc2(1, sizeof(AVPacket),
+ AV_FIFO_FLAG_AUTO_GROW);
if (!s->packet_fifo) {
ret = AVERROR(ENOMEM);
goto fail;
@@ -823,17 +812,10 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
if (avpkt->size) {
AVPacket input_ref;
- if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
- ret = av_fifo_realloc2(s->packet_fifo,
- av_fifo_size(s->packet_fifo) + sizeof(input_ref));
- if (ret < 0)
- return ret;
- }
-
ret = av_packet_ref(&input_ref, avpkt);
if (ret < 0)
return ret;
- av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
+ av_fifo_write(s->packet_fifo, &input_ref, 1);
}
/* process buffered data */
@@ -841,12 +823,12 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
/* prepare the input data */
if (s->buffer_pkt.size <= 0) {
/* no more data */
- if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
+ if (!av_fifo_can_read(s->packet_fifo))
return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
/* in progress of reinit, no read from fifo and keep the buffer_pkt */
if (!s->qsv.reinit_flag) {
av_packet_unref(&s->buffer_pkt);
- av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
+ av_fifo_read(s->packet_fifo, &s->buffer_pkt, 1);
}
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (13 preceding siblings ...)
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit Andreas Rheinhardt
` (15 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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 acb82f321c..a12f7bce42 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -88,6 +88,12 @@ static const struct profile_names vp9_profiles[] = {
#endif
};
+typedef struct QSVPacket {
+ AVPacket pkt;
+ mfxSyncPoint *sync;
+ mfxBitstream *bs;
+} QSVPacket;
+
static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile)
{
const struct profile_names *profiles;
@@ -1315,16 +1321,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;
@@ -1333,7 +1329,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);
@@ -1636,15 +1632,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;
@@ -1667,17 +1661,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) {
@@ -1687,13 +1681,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
@@ -1701,12 +1695,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);
@@ -1725,15 +1719,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);
@@ -1757,60 +1749,56 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
if (ret < 0)
return ret;
- if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
- (!frame && av_fifo_size(q->async_fifo))) {
- AVPacket new_pkt;
- mfxBitstream *bs;
- mfxSyncPoint *sync;
+ if ((av_fifo_can_read(q->async_fifo) >= q->async_depth) ||
+ (!frame && av_fifo_can_read(q->async_fifo))) {
+ QSVPacket qpkt;
#if QSV_VERSION_ATLEAST(1, 26)
mfxExtAVCEncodedFrameInfo *enc_info;
mfxExtBuffer **enc_buf;
#endif
enum AVPictureType pict_type;
- av_fifo_generic_read(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
- av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
- av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL);
+ av_fifo_read(q->async_fifo, &qpkt, 1);
do {
- ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
+ ret = MFXVideoCORE_SyncOperation(q->session, *qpkt.sync, 1000);
} while (ret == MFX_WRN_IN_EXECUTION);
- new_pkt.dts = av_rescale_q(bs->DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);
- new_pkt.pts = av_rescale_q(bs->TimeStamp, (AVRational){1, 90000}, avctx->time_base);
- new_pkt.size = bs->DataLength;
+ qpkt.pkt.dts = av_rescale_q(qpkt.bs->DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);
+ qpkt.pkt.pts = av_rescale_q(qpkt.bs->TimeStamp, (AVRational){1, 90000}, avctx->time_base);
+ qpkt.pkt.size = qpkt.bs->DataLength;
- if (bs->FrameType & MFX_FRAMETYPE_IDR || bs->FrameType & MFX_FRAMETYPE_xIDR) {
- new_pkt.flags |= AV_PKT_FLAG_KEY;
+ if (qpkt.bs->FrameType & MFX_FRAMETYPE_IDR || qpkt.bs->FrameType & MFX_FRAMETYPE_xIDR) {
+ qpkt.pkt.flags |= AV_PKT_FLAG_KEY;
pict_type = AV_PICTURE_TYPE_I;
- } else if (bs->FrameType & MFX_FRAMETYPE_I || bs->FrameType & MFX_FRAMETYPE_xI)
+ } else if (qpkt.bs->FrameType & MFX_FRAMETYPE_I || qpkt.bs->FrameType & MFX_FRAMETYPE_xI)
pict_type = AV_PICTURE_TYPE_I;
- else if (bs->FrameType & MFX_FRAMETYPE_P || bs->FrameType & MFX_FRAMETYPE_xP)
+ else if (qpkt.bs->FrameType & MFX_FRAMETYPE_P || qpkt.bs->FrameType & MFX_FRAMETYPE_xP)
pict_type = AV_PICTURE_TYPE_P;
- else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & MFX_FRAMETYPE_xB)
+ else if (qpkt.bs->FrameType & MFX_FRAMETYPE_B || qpkt.bs->FrameType & MFX_FRAMETYPE_xB)
pict_type = AV_PICTURE_TYPE_B;
- else if (bs->FrameType == MFX_FRAMETYPE_UNKNOWN) {
+ else if (qpkt.bs->FrameType == MFX_FRAMETYPE_UNKNOWN) {
pict_type = AV_PICTURE_TYPE_NONE;
av_log(avctx, AV_LOG_WARNING, "Unknown FrameType, set pict_type to AV_PICTURE_TYPE_NONE.\n");
} else {
- av_log(avctx, AV_LOG_ERROR, "Invalid FrameType:%d.\n", bs->FrameType);
+ av_log(avctx, AV_LOG_ERROR, "Invalid FrameType:%d.\n", qpkt.bs->FrameType);
return AVERROR_INVALIDDATA;
}
#if QSV_VERSION_ATLEAST(1, 26)
if (avctx->codec_id == AV_CODEC_ID_H264) {
- enc_buf = bs->ExtParam;
- enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
- ff_side_data_set_encoder_stats(&new_pkt,
+ enc_buf = qpkt.bs->ExtParam;
+ enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
+ ff_side_data_set_encoder_stats(&qpkt.pkt,
enc_info->QP * FF_QP2LAMBDA, NULL, 0, pict_type);
av_freep(&enc_info);
av_freep(&enc_buf);
}
#endif
- av_freep(&bs);
- av_freep(&sync);
+ av_freep(&qpkt.bs);
+ av_freep(&qpkt.sync);
- av_packet_move_ref(pkt, &new_pkt);
+ av_packet_move_ref(pkt, &qpkt.pkt);
*got_packet = 1;
}
@@ -1840,29 +1828,23 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
cur = q->work_frames;
}
- while (q->async_fifo && av_fifo_size(q->async_fifo)) {
- AVPacket pkt;
- mfxSyncPoint *sync;
- mfxBitstream *bs;
-
- av_fifo_generic_read(q->async_fifo, &pkt, sizeof(pkt), NULL);
- av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
- av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL);
-
+ if (q->async_fifo) {
+ 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 = bs->ExtParam;
- mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
+ mfxExtBuffer **enc_buf = pkt.bs->ExtParam;
+ mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
av_freep(&enc_info);
av_freep(&enc_buf);
}
#endif
- av_freep(&sync);
- av_freep(&bs);
- av_packet_unref(&pkt);
+ av_freep(&pkt.sync);
+ av_freep(&pkt.bs);
+ av_packet_unref(&pkt.pkt);
+ }
+ av_fifo_freep2(&q->async_fifo);
}
- av_fifo_free(q->async_fifo);
- q->async_fifo = NULL;
av_freep(&q->opaque_surfaces);
av_buffer_unref(&q->opaque_alloc_buf);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 65f035045c..fb278b8829 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -150,7 +150,7 @@ typedef struct QSVEncContext {
mfxExtBuffer **extparam;
- AVFifoBuffer *async_fifo;
+ AVFifo *async_fifo;
QSVFramesContext frames_ctx;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (14 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync Andreas Rheinhardt
` (14 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/qsvenc.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index a12f7bce42..a1093ae768 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1832,17 +1832,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);
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (15 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API Andreas Rheinhardt
` (13 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (16 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: " Andreas Rheinhardt
` (12 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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 = {
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (17 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: " Andreas Rheinhardt
` (11 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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 +1214,13 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
if (is_iframe &&
(s->packet_number == 0 || pts != AV_NOPTS_VALUE &&
(pts - stream->vobu_start_pts >= 36000))) {
- stream->bytes_to_iframe = av_fifo_size(stream->fifo);
+ stream->bytes_to_iframe = av_fifo_can_read(stream->fifo);
stream->align_iframe = 1;
stream->vobu_start_pts = pts;
}
}
- av_fifo_generic_write(stream->fifo, buf, size, NULL);
+ av_fifo_write(stream->fifo, buf, size);
for (;;) {
int ret = output_packet(ctx, 0);
@@ -1244,7 +1250,7 @@ static int mpeg_mux_end(AVFormatContext *ctx)
for (i = 0; i < ctx->nb_streams; i++) {
stream = ctx->streams[i]->priv_data;
- av_assert0(av_fifo_size(stream->fifo) == 0);
+ av_assert0(av_fifo_can_read(stream->fifo) == 0);
}
return 0;
}
@@ -1260,7 +1266,7 @@ static void mpeg_mux_deinit(AVFormatContext *ctx)
av_free(pkt);
pkt = tmp;
}
- av_fifo_freep(&stream->fifo);
+ av_fifo_freep2(&stream->fifo);
}
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (18 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 21/31] lavf/udp: " Andreas Rheinhardt
` (10 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 21/31] lavf/udp: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (19 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 22/31] lavf/async: " Andreas Rheinhardt
` (9 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
libavformat/udp.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 83c042d079..1737aee1c2 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);
+ av_fifo_freep2(&s->fifo);
ff_ip_reset_filters(&s->filters);
return 0;
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 22/31] lavf/async: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (20 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 21/31] lavf/udp: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the " Andreas Rheinhardt
` (8 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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_copy;
to_read -= to_copy;
@@ -376,11 +378,7 @@ static int async_read_internal(URLContext *h, void *dest, int size, int read_com
static int async_read(URLContext *h, unsigned char *buf, int size)
{
- return async_read_internal(h, buf, size, 0, NULL);
-}
-
-static void fifo_do_not_copy_func(void* dest, void* src, int size) {
- // do not copy
+ return async_read_internal(h, buf, size);
}
static int64_t async_seek(URLContext *h, int64_t pos, int whence)
@@ -422,7 +420,7 @@ static int64_t async_seek(URLContext *h, int64_t pos, int whence)
if (pos_delta > 0) {
// fast seek forwards
- async_read_internal(h, NULL, pos_delta, 1, fifo_do_not_copy_func);
+ async_read_internal(h, NULL, pos_delta);
} else {
// fast seek backwards
ring_drain(ring, pos_delta);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (21 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 22/31] lavf/async: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include Andreas Rheinhardt
` (7 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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)) * 1000000.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;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (22 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API Andreas Rheinhardt
` (6 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
Nothing in audio_fifo.h uses anything from fifo.h
---
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"
/**
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (23 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: " Andreas Rheinhardt
` (5 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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]);
+ av_fifo_reset2(af->buf[i]);
af->nb_samples = 0;
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (24 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: " Andreas Rheinhardt
` (4 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (25 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: " Andreas Rheinhardt
` (3 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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, 90000 };
+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 {
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (26 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 29/31] ffplay: " Andreas Rheinhardt
` (2 subsequent siblings)
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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(AVFilterLink *link, AVFrame *input_frame)
// Get the absolute transform data for this frame
for (int i = 0; i < RingbufCount; i++) {
- av_fifo_generic_peek_at(
- deshake_ctx->abs_motion.ringbuffers[i],
- &old_vals[i],
- deshake_ctx->abs_motion.curr_frame_offset * sizeof(float),
- sizeof(float),
- NULL
- );
+ av_fifo_peek(deshake_ctx->abs_motion.ringbuffers[i],
+ &old_vals[i], 1,
+ deshake_ctx->abs_motion.curr_frame_offset);
}
if (deshake_ctx->tripod_mode) {
@@ -1842,7 +1819,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame)
{ sizeof(cl_mem), &deshake_ctx->brief_pattern}
);
- if (av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) {
+ if (!av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX])) {
// This is the first frame we've been given to queue, meaning there is
// no previous frame to match descriptors to
@@ -1892,7 +1869,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame)
// old data (and just treat them all as part of the new values)
if (deshake_ctx->abs_motion.data_end_offset == -1) {
deshake_ctx->abs_motion.data_end_offset =
- av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) / sizeof(float) - 1;
+ av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX]) - 1;
}
goto no_motion_data;
@@ -1934,13 +1911,10 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame)
// Get the absolute transform data for the previous frame
for (int i = 0; i < RingbufCount; i++) {
- av_fifo_generic_peek_at(
+ av_fifo_peek(
deshake_ctx->abs_motion.ringbuffers[i],
- &prev_vals[i],
- av_fifo_size(deshake_ctx->abs_motion.ringbuffers[i]) - sizeof(float),
- sizeof(float),
- NULL
- );
+ &prev_vals[i], 1,
+ av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[i]) - 1);
}
new_vals[RingbufX] = prev_vals[RingbufX] + relative.translation.s[0];
@@ -2011,21 +1985,13 @@ end:
}
debug_matches.num_matches = num_vectors;
- av_fifo_generic_write(
+ av_fifo_write(
deshake_ctx->abs_motion.debug_matches,
- &debug_matches,
- sizeof(DebugMatches),
- NULL
- );
+ &debug_matches, 1);
}
for (int i = 0; i < RingbufCount; i++) {
- av_fifo_generic_write(
- deshake_ctx->abs_motion.ringbuffers[i],
- &new_vals[i],
- sizeof(float),
- NULL
- );
+ av_fifo_write(deshake_ctx->abs_motion.ringbuffers[i], &new_vals[i], 1);
}
return ff_framequeue_add(&deshake_ctx->fq, input_frame);
@@ -2063,9 +2029,9 @@ static int activate(AVFilterContext *ctx)
// If there is no more space in the ringbuffers, remove the oldest
// values to make room for the new ones
- if (av_fifo_space(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) {
+ if (!av_fifo_can_write(deshake_ctx->abs_motion.ringbuffers[RingbufX])) {
for (int i = 0; i < RingbufCount; i++) {
- av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float));
+ av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1);
}
}
ret = queue_frame(inlink, frame);
@@ -2092,7 +2058,7 @@ static int activate(AVFilterContext *ctx)
// Finish processing the rest of the frames in the queue.
while(ff_framequeue_queued_frames(&deshake_ctx->fq) != 0) {
for (int i = 0; i < RingbufCount; i++) {
- av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float));
+ av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1);
}
ret = filter_frame(inlink, ff_framequeue_take(&deshake_ctx->fq));
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 29/31] ffplay: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (27 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old " Andreas Rheinhardt
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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;
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: switch to new FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (28 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 29/31] ffplay: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old " Andreas Rheinhardt
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
---
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;
+ ret = av_fifo_write(ifilter->frame_queue, &tmp, 1);
+ if (ret < 0)
+ av_frame_free(&tmp);
+
+ return ret;
}
ret = reap_filters(1);
@@ -2526,15 +2514,13 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
sub2video_update(ist, INT64_MIN, &subtitle);
} else if (ist->nb_filters) {
if (!ist->sub2video.sub_queue)
- ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));
+ ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
if (!ist->sub2video.sub_queue)
exit_program(1);
- if (!av_fifo_space(ist->sub2video.sub_queue)) {
- ret = av_fifo_realloc2(ist->sub2video.sub_queue, 2 * av_fifo_size(ist->sub2video.sub_queue));
- if (ret < 0)
- exit_program(1);
- }
- av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL);
+
+ ret = av_fifo_write(ist->sub2video.sub_queue, &subtitle, 1);
+ if (ret < 0)
+ exit_program(1);
free_sub = 0;
}
@@ -2976,14 +2962,13 @@ static int check_init_output_file(OutputFile *of, int file_index)
/* flush the muxing queues */
for (i = 0; i < of->ctx->nb_streams; i++) {
OutputStream *ost = output_streams[of->ost_index + i];
+ AVPacket *pkt;
/* try to improve muxing time_base (only possible if nothing has been written yet) */
- if (!av_fifo_size(ost->muxing_queue))
+ if (!av_fifo_can_read(ost->muxing_queue))
ost->mux_timebase = ost->st->time_base;
- while (av_fifo_size(ost->muxing_queue)) {
- AVPacket *pkt;
- av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+ while (av_fifo_read(ost->muxing_queue, &pkt, 1) >= 0) {
ost->muxing_queue_data_size -= pkt->size;
write_packet(of, pkt, ost, 1);
av_packet_free(&pkt);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9b200b806a..81ec4d5970 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -241,7 +241,7 @@ typedef struct InputFilter {
uint8_t *name;
enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video
- AVFifoBuffer *frame_queue;
+ AVFifo *frame_queue;
// parameters configured for this input
int format;
@@ -355,7 +355,7 @@ typedef struct InputStream {
struct sub2video {
int64_t last_pts;
int64_t end_pts;
- AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init
+ AVFifo *sub_queue; ///< queue of AVSubtitle* before filter init
AVFrame *frame;
int w, h;
unsigned int initialize; ///< marks if sub2video_update should force an initialization
@@ -555,7 +555,7 @@ typedef struct OutputStream {
int max_muxing_queue_size;
/* the packets are buffered here until the muxer is ready to be initialized */
- AVFifoBuffer *muxing_queue;
+ AVFifo *muxing_queue;
/*
* The size of the AVPackets' buffers in queue.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1f6cba2c04..41d87377c7 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -178,7 +178,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
ifilter->graph = fg;
ifilter->format = -1;
- ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
exit_program(1);
@@ -286,7 +286,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ifilter->type = ist->st->codecpar->codec_type;
ifilter->name = describe_filter_link(fg, in, 1);
- ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
exit_program(1);
@@ -1106,9 +1106,8 @@ int configure_filtergraph(FilterGraph *fg)
}
for (i = 0; i < fg->nb_inputs; i++) {
- while (av_fifo_size(fg->inputs[i]->frame_queue)) {
- AVFrame *tmp;
- av_fifo_generic_read(fg->inputs[i]->frame_queue, &tmp, sizeof(tmp), NULL);
+ AVFrame *tmp;
+ while (av_fifo_read(fg->inputs[i]->frame_queue, &tmp, 1) >= 0) {
ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
av_frame_free(&tmp);
if (ret < 0)
@@ -1129,9 +1128,8 @@ int configure_filtergraph(FilterGraph *fg)
for (i = 0; i < fg->nb_inputs; i++) {
InputStream *ist = fg->inputs[i]->ist;
if (ist->sub2video.sub_queue && ist->sub2video.frame) {
- while (av_fifo_size(ist->sub2video.sub_queue)) {
- AVSubtitle tmp;
- av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
+ AVSubtitle tmp;
+ while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
sub2video_update(ist, INT64_MIN, &tmp);
avsubtitle_free(&tmp);
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 9c820ab73f..3102851885 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1589,8 +1589,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->max_muxing_queue_size = 128;
MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
- ost->max_muxing_queue_size = FFMIN(ost->max_muxing_queue_size, INT_MAX / sizeof(ost->pkt));
- ost->max_muxing_queue_size *= sizeof(ost->pkt);
ost->muxing_queue_data_size = 0;
@@ -1617,7 +1615,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
}
ost->last_mux_dts = AV_NOPTS_VALUE;
- ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
+ ost->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
if (!ost->muxing_queue)
exit_program(1);
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old FIFO API
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
` (29 preceding siblings ...)
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: " Andreas Rheinhardt
@ 2022-01-24 14:46 ` Andreas Rheinhardt
30 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-01-24 14:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Anton Khirnov
From: Anton Khirnov <anton@khirnov.net>
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().
---
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 75e0b1f49a..db6b2ab809 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,14 @@ libavutil: 2021-04-27
API changes, most recent first:
+2022-01-xx - xxxxxxxxxx - lavu 57.20.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-01-xx - xxxxxxxxxx - lavu 57.19.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 5a09dd3877..818e39694b 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -285,6 +285,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)
@@ -497,3 +499,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..40852c0f70 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 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(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
/**
@@ -308,7 +331,11 @@ int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size, void (*func)
* @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_read() when func == NULL,
+ * av_fifo_read_to_cb() otherwise
*/
+attribute_deprecated
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
/**
@@ -323,7 +350,11 @@ int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)
* indicate no more data available to write.
* If func is NULL, src is interpreted as a simple byte array for source data.
* @return the number of bytes written to the FIFO or a negative error code on failure
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_write() when func == NULL,
+ * av_fifo_write_to_cb() otherwise
*/
+attribute_deprecated
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
/**
@@ -333,7 +364,11 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
* @param f AVFifoBuffer to resize
* @param size new AVFifoBuffer size in bytes
* @return <0 for failure, >=0 otherwise
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_grow2() to increase FIFO size,
+ * decreasing FIFO size is not supported
*/
+attribute_deprecated
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
/**
@@ -344,14 +379,21 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
* @param f AVFifoBuffer to resize
* @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
* @return <0 for failure, >=0 otherwise
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_grow2(); note that unlike
+ * this function it adds to the allocated size, rather than to the used size
*/
+attribute_deprecated
int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
/**
* Read and discard the specified amount of data from an AVFifoBuffer.
* @param f AVFifoBuffer to read from
* @param size amount of data to read in bytes
+ *
+ * @deprecated use the new AVFifo-API with av_fifo_drain2()
*/
+attribute_deprecated
void av_fifo_drain(AVFifoBuffer *f, int size);
#if FF_API_FIFO_PEEK2
@@ -364,7 +406,7 @@ void av_fifo_drain(AVFifoBuffer *f, int size);
* than the used buffer size or the returned pointer will
* point outside to the buffer data.
* The used buffer size can be checked with av_fifo_size().
- * @deprecated use av_fifo_generic_peek_at()
+ * @deprecated use the new AVFifo-API with av_fifo_peek() or av_fifo_peek_to_cb()
*/
attribute_deprecated
static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
@@ -377,5 +419,6 @@ static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
return ptr;
}
#endif
+#endif
#endif /* AVUTIL_FIFO_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 331b8f6ea9..5e47f61fe6 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 57
-#define LIBAVUTIL_VERSION_MINOR 19
+#define LIBAVUTIL_VERSION_MINOR 20
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -110,6 +110,7 @@
#define FF_API_COLORSPACE_NAME (LIBAVUTIL_VERSION_MAJOR < 58)
#define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58)
#define FF_API_FIFO_PEEK2 (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_FIFO_OLD_API (LIBAVUTIL_VERSION_MAJOR < 58)
/**
* @}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size Andreas Rheinhardt
@ 2022-02-05 7:55 ` Andreas Rheinhardt
0 siblings, 0 replies; 33+ messages in thread
From: Andreas Rheinhardt @ 2022-02-05 7:55 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> From: Anton Khirnov <anton@khirnov.net>
>
> 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.
> ---
> doc/APIchanges | 9 ++
> libavutil/fifo.c | 224 ++++++++++++++++++++++++++++++++++++++++++++
> libavutil/fifo.h | 179 +++++++++++++++++++++++++++++++++++
> libavutil/version.h | 2 +-
> 4 files changed, 413 insertions(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 8df0364e4c..57a9df9bef 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,15 @@ libavutil: 2021-04-27
>
> API changes, most recent first:
>
> +2022-01-xx - xxxxxxxxxx - lavu 57.19.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-04 - 78dc21b123e - lavu 57.16.100 - frame.h
> Add AV_FRAME_DATA_DOVI_METADATA.
>
> diff --git a/libavutil/fifo.c b/libavutil/fifo.c
> index 55621f0dca..0e0d84258f 100644
> --- a/libavutil/fifo.c
> +++ b/libavutil/fifo.c
> @@ -26,6 +26,230 @@
> #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
> + int is_empty;
> +};
> +
> +AVFifo *av_fifo_alloc2(size_t nb_elems, size_t elem_size,
> + unsigned int flags)
> +{
> + AVFifo *f;
> + void *buffer;
> +
> + if (!elem_size)
> + return NULL;
> +
> + buffer = av_realloc_array(NULL, nb_elems, elem_size);
After Anton pointed out that it is ill-defined what av_realloc_array()
does in case one requests zero elements (it allocates a single byte,
although it is documented to free the buffer provided to it) this has
been changed to only allocate anything in case a positive number of
elements has been requested:
+ 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;
+ }
I intend to apply this set with this change and his change requested in
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/292349.html
applied (and with another trivial change in qsvdec necessitated by
8ca06a8148) tomorrow unless there are objections.
> + 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;
> +}
> +
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 33+ messages in thread
end of thread, other threads:[~2022-02-05 7:56 UTC | newest]
Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek() Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size Andreas Rheinhardt
2022-02-05 7:55 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 21/31] lavf/udp: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 22/31] lavf/async: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 29/31] ffplay: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old " Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git