lavf: Update AVIOContext.maxsize when hitting the end.
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 16 Dec 2011 14:40:21 +0000 (15:40 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 16 Dec 2011 15:58:12 +0000 (16:58 +0100)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/utils.c

index 10cd6f3..379ee2b 100644 (file)
@@ -269,10 +269,17 @@ int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
 {
     int ret;
 
-    if(s->maxsize>0){
+    if(s->maxsize>=0){
         int64_t remaining= s->maxsize - avio_tell(s);
-        if(remaining>=0)
-            size= FFMIN(size, remaining);
+        if(remaining < size){
+            int64_t newsize= avio_size(s);
+            if(!s->maxsize || s->maxsize<newsize)
+                s->maxsize= newsize;
+            remaining= s->maxsize - avio_tell(s);
+        }
+
+        if(s->maxsize>=0 && remaining>=0)
+            size= FFMIN(size, remaining+1);
     }
 
     ret= av_new_packet(pkt, size);