[FFmpeg-cvslog] lavf: add internal AVIOContext.maxsize

Michael Niedermayer git at videolan.org
Fri Dec 16 06:25:16 CET 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Dec 16 05:54:03 2011 +0100| [47572323f2f908913b4d031af733047d481fb1f6] | committer: Michael Niedermayer

lavf: add internal AVIOContext.maxsize
This allows simple and generic limiting of allocations used for packets.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/avio.h  |    6 ++++++
 libavformat/utils.c |   10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/libavformat/avio.h b/libavformat/avio.h
index 7cf14f9..920526f 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -120,6 +120,12 @@ typedef struct {
      * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
      */
     int seekable;
+
+    /**
+     * max filesize, used to limit allocations
+     * This field is internal to libavformat and access from outside is not allowed.
+     */
+     int64_t maxsize;
 } AVIOContext;
 
 /* unbuffered I/O */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 183aaff..10cd6f3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -267,7 +267,15 @@ AVInputFormat *av_find_input_format(const char *short_name)
 
 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
 {
-    int ret= av_new_packet(pkt, size);
+    int ret;
+
+    if(s->maxsize>0){
+        int64_t remaining= s->maxsize - avio_tell(s);
+        if(remaining>=0)
+            size= FFMIN(size, remaining);
+    }
+
+    ret= av_new_packet(pkt, size);
 
     if(ret<0)
         return ret;



More information about the ffmpeg-cvslog mailing list