Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 27/35] lavf/async: switch to new FIFO API
Date: Tue, 11 Jan 2022 21:46:02 +0100
Message-ID: <20220111204610.14262-27-anton@khirnov.net> (raw)
In-Reply-To: <20220111204610.14262-1-anton@khirnov.net>

---
 libavformat/async.c | 62 ++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/libavformat/async.c b/libavformat/async.c
index 5a81507ef1..59b0e7d352 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -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);
 
@@ -104,34 +104,48 @@ static void ring_reset(RingBuffer *ring)
 
 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.33.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".

  parent reply	other threads:[~2022-01-11 20:49 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 20:45 [FFmpeg-devel] [PATCH 01/35] lavu/fifo: disallow overly large fifo sizes Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 02/35] lavu/fifo: make the contents of AVFifoBuffer private on next major bump Anton Khirnov
2022-01-13 14:22   ` Andreas Rheinhardt
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 03/35] lavu/fifo: introduce the notion of element size Anton Khirnov
2022-01-13 16:50   ` Andreas Rheinhardt
2022-01-13 16:59   ` James Almer
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 04/35] lavu/fifo: add new functions for determinining reading/writing size Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 05/35] lavu/fifo: add a new FIFO grow function Anton Khirnov
2022-01-13 17:04   ` James Almer
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 06/35] lavu/fifo: add a new function for draining the FIFO Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 07/35] lavu/fifo: add new FIFO writing functions Anton Khirnov
2022-01-13 17:31   ` Andreas Rheinhardt
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 08/35] lavu/fifo: add new FIFO read/peek functions Anton Khirnov
2022-01-13 17:41   ` Andreas Rheinhardt
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 09/35] lavu/fifo: add a flag for automatically growing the FIFO as needed Anton Khirnov
2022-01-13 17:53   ` Andreas Rheinhardt
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 10/35] lavu/fifo: deprecate old API Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 11/35] lavu/tests/fifo: switch to the new API Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 12/35] lavc/avcodec: switch to new FIFO API Anton Khirnov
2022-01-13 18:21   ` Andreas Rheinhardt
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 13/35] lavc/amfenc: " Anton Khirnov
2022-01-12 14:46   ` Michael Niedermayer
2022-01-12 19:29     ` Anton Khirnov
2022-01-13 14:14       ` Michael Niedermayer
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 14/35] lavc/cuviddec: do not reallocate the fifo unnecessarily Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 15/35] lavc/cuviddec: convert to the new FIFO API Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 16/35] lavc/libvorbisenc: switch to " Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 17/35] lavc/libvpxenc: switch to the " Anton Khirnov
2022-01-12 18:15   ` James Zern
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 18/35] lavc/libvpxenc: remove unneeded context variable Anton Khirnov
2022-01-12 18:15   ` James Zern
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 19/35] lavc/nvenc: switch to the new FIFO API Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 20/35] lavc/qsvdec: " Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 21/35] lavc/qsvenc: switch to " Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 22/35] lavf/dvenc: return an error on audio/video desync Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 23/35] lavf/dvenc: switch to new FIFO API Anton Khirnov
2022-01-11 20:45 ` [FFmpeg-devel] [PATCH 24/35] lavf/mpegenc: " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 25/35] lavf/swfenc: " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 26/35] lavf/udp: " Anton Khirnov
2022-01-13 18:45   ` Andreas Rheinhardt
2022-01-11 20:46 ` Anton Khirnov [this message]
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 28/35] lavd/jack: switch to the " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 29/35] lavu/audio_fifo: drop an unnecessary include Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 30/35] lavu/audio_fifo: switch to new FIFO API Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 31/35] lavu/threadmessage: " Anton Khirnov
2022-01-13 19:03   ` Andreas Rheinhardt
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 32/35] lavfi/qsvvpp: " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 33/35] lavfi/vf_deshake_opencl: " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 34/35] ffplay: " Anton Khirnov
2022-01-11 20:46 ` [FFmpeg-devel] [PATCH 35/35] ffmpeg: " Anton Khirnov
2022-01-13 13:59 ` [FFmpeg-devel] [PATCH 01/35] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt
2022-01-13 14:27 ` Anton Khirnov
2022-01-13 14:38   ` Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220111204610.14262-27-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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