changeset 3639:949bc256f1e3 libavcodec

dont copy frame if the whole mp1/2/3 frame is available in one piece in the input
author michael
date Sat, 26 Aug 2006 18:56:24 +0000
parents 62b3b622f798
children c5dffafebdff
files parser.c
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/parser.c	Sat Aug 26 18:12:16 2006 +0000
+++ b/parser.c	Sat Aug 26 18:56:24 2006 +0000
@@ -634,9 +634,7 @@
             }
             /* no header seen : find one. We need at least MPA_HEADER_SIZE
                bytes to parse it */
-            len = MPA_HEADER_SIZE - len;
-            if (len > buf_size)
-                len = buf_size;
+            len = FFMIN(MPA_HEADER_SIZE - len, buf_size);
             if (len > 0) {
                 memcpy(s->inbuf_ptr, buf_ptr, len);
                 buf_ptr += len;
@@ -736,14 +734,25 @@
         if (len < s->frame_size) {
             if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
                 s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
-            len = s->frame_size - len;
-            if (len > buf_size)
-                len = buf_size;
+            len = FFMIN(s->frame_size - len, buf_size);
             memcpy(s->inbuf_ptr, buf_ptr, len);
             buf_ptr += len;
             s->inbuf_ptr += len;
             buf_size -= len;
         }
+
+        if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf
+           && buf_size + buf_ptr - buf >= s->frame_size){
+            if(s->header_count > 0){
+                *poutbuf = buf;
+                *poutbuf_size = s->frame_size;
+            }
+            buf_ptr = buf + s->frame_size;
+            s->inbuf_ptr = s->inbuf;
+            s->frame_size = 0;
+            break;
+        }
+
         //    next_data:
         if (s->frame_size > 0 &&
             (s->inbuf_ptr - s->inbuf) >= s->frame_size) {