[vlc-devel] [PATCH 2/3] live555: discard truncated frames

Ben Hutchings ben at decadent.org.uk
Sun May 24 16:14:15 CEST 2009


Not all demuxers can cope with truncated frames, so discard them.
---
This is required for correct demuxing of DV received over RTSP.
Possibly it would be better to change that demuxer to be able to resync,
though.

Ben.

 modules/demux/live555.cpp |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/modules/demux/live555.cpp b/modules/demux/live555.cpp
index 3a75409..02b4cdc 100644
--- a/modules/demux/live555.cpp
+++ b/modules/demux/live555.cpp
@@ -1610,23 +1610,32 @@ static void StreamRead( void *p_private, unsigned int i_size,
              pts.tv_sec * 1000000LL + pts.tv_usec );
 #endif
 
-    /* grow buffer if it looks like buffer is too small, but don't eat
-     * up all the memory on strange streams */
-    if( i_truncated_bytes > 0 && tk->i_buffer < 2000000 )
+    if( i_truncated_bytes > 0 )
     {
-        void *p_tmp;
         msg_Dbg( p_demux, "lost %d bytes", i_truncated_bytes );
-        msg_Dbg( p_demux, "increasing buffer size to %d", tk->i_buffer * 2 );
-        p_tmp = realloc( tk->p_buffer, tk->i_buffer * 2 );
-        if( p_tmp == NULL )
-        {
-            msg_Warn( p_demux, "realloc failed" );
-        }
-        else
+
+        /* grow buffer if it looks like buffer is too small, but don't eat
+         * up all the memory on strange streams */
+        if( tk->i_buffer < 2000000 )
         {
-            tk->p_buffer = (uint8_t*)p_tmp;
-            tk->i_buffer *= 2;
+            void *p_tmp;
+            msg_Dbg( p_demux, "increasing buffer size to %d", tk->i_buffer * 2 );
+            p_tmp = realloc( tk->p_buffer, tk->i_buffer * 2 );
+            if( p_tmp == NULL )
+            {
+                msg_Warn( p_demux, "realloc failed" );
+            }
+            else
+            {
+                tk->p_buffer = (uint8_t*)p_tmp;
+                tk->i_buffer *= 2;
+            }
         }
+
+        /* discard truncated frame; not all demuxers can cope with them */
+        p_sys->event = 0xff;
+        tk->waiting = 0;
+        return;
     }
 
     assert( i_size <= tk->i_buffer );
-- 
1.6.3.1





More information about the vlc-devel mailing list