[FFmpeg-cvslog] avformat/utils: Move ffio_limit() to aviobuf

Andreas Rheinhardt git at videolan.org
Thu Aug 26 02:05:43 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Aug  5 01:45:21 2021 +0200| [19093100fd5c3100f15a5c41f99e1f5792997b73] | committer: Andreas Rheinhardt

avformat/utils: Move ffio_limit() to aviobuf

It is the more natural place for it given that it only deals with I/O;
in fact, the function already has the ffio prefix and its declaration
already is in avio_internal.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavformat/aviobuf.c | 25 +++++++++++++++++++++++++
 libavformat/utils.c   | 25 -------------------------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 164b07ae6a..9322ed38bc 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1015,6 +1015,31 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
     return 0;
 }
 
+int ffio_limit(AVIOContext *s, int size)
+{
+    if (s->maxsize>= 0) {
+        int64_t pos = avio_tell(s);
+        int64_t remaining = s->maxsize - pos;
+        if (remaining < size) {
+            int64_t newsize = avio_size(s);
+            if (!s->maxsize || s->maxsize<newsize)
+                s->maxsize = newsize - !newsize;
+            if (pos > s->maxsize && s->maxsize >= 0)
+                s->maxsize = AVERROR(EIO);
+            if (s->maxsize >= 0)
+                remaining = s->maxsize - pos;
+        }
+
+        if (s->maxsize >= 0 && remaining < size && size > 1) {
+            av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG,
+                   "Truncating packet of size %d to %"PRId64"\n",
+                   size, remaining + !remaining);
+            size = remaining + !remaining;
+        }
+    }
+    return size;
+}
+
 int ffio_set_buf_size(AVIOContext *s, int buf_size)
 {
     uint8_t *buffer;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 39f082d98d..9706b141ad 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -213,31 +213,6 @@ static const AVCodec *find_probe_decoder(AVFormatContext *s, const AVStream *st,
 /* an arbitrarily chosen "sane" max packet size -- 50M */
 #define SANE_CHUNK_SIZE (50000000)
 
-int ffio_limit(AVIOContext *s, int size)
-{
-    if (s->maxsize>= 0) {
-        int64_t pos = avio_tell(s);
-        int64_t remaining= s->maxsize - pos;
-        if (remaining < size) {
-            int64_t newsize = avio_size(s);
-            if (!s->maxsize || s->maxsize<newsize)
-                s->maxsize = newsize - !newsize;
-            if (pos > s->maxsize && s->maxsize >= 0)
-                s->maxsize = AVERROR(EIO);
-            if (s->maxsize >= 0)
-                remaining = s->maxsize - pos;
-        }
-
-        if (s->maxsize >= 0 && remaining < size && size > 1) {
-            av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG,
-                   "Truncating packet of size %d to %"PRId64"\n",
-                   size, remaining + !remaining);
-            size = remaining + !remaining;
-        }
-    }
-    return size;
-}
-
 /* Read the data in sane-sized chunks and append to pkt.
  * Return the number of bytes read or an error. */
 static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)



More information about the ffmpeg-cvslog mailing list