]> git.sesse.net Git - vlc/blobdiff - modules/demux/mjpeg.c
Remove change_unsafe() no-op.
[vlc] / modules / demux / mjpeg.c
index 768317fa94809cd3f0dc6382e87750261df9744c..5415864d0d402eb7907cbab818ae7918b0740f19 100644 (file)
@@ -32,7 +32,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_demux.h>
 
 #include <vlc_codecs.h>
@@ -50,8 +51,8 @@ static void Close( vlc_object_t * );
 
 vlc_module_begin();
     set_shortname( "MJPEG");
-    set_description( _("M-JPEG camera demuxer") );
-    set_capability( "demux2", 5 );
+    set_description( N_("M-JPEG camera demuxer") );
+    set_capability( "demux", 5 );
     set_callbacks( Open, Close );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_DEMUX );
@@ -80,6 +81,7 @@ struct demux_sys_t
     int             i_frame_size_estimate;
     const uint8_t   *p_peek;
     int             i_data_peeked;
+    int             i_level;
 };
 
 /*****************************************************************************
@@ -155,11 +157,8 @@ static char* GetLine( demux_t *p_demux, int *p_pos )
         i--;
     }
     p_line = malloc( i + 1 );
-    if( NULL == p_line )
-    {
-        msg_Err( p_demux, "out of memory" );
+    if( p_line == NULL )
         return NULL;
-    }
     strncpy ( p_line, (char*)p_buf, i );
     p_line[i] = '\0';
 //    msg_Dbg( p_demux, "i = %d, pos = %d, %s", i, *p_pos, p_line );
@@ -309,6 +308,7 @@ static int Open( vlc_object_t * p_this )
     p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
     p_sys->p_es         = NULL;
     p_sys->i_time       = 0;
+    p_sys->i_level      = 0;
 
     p_sys->psz_separator = NULL;
     p_sys->i_frame_size_estimate = 15 * 1024;
@@ -326,6 +326,7 @@ static int Open( vlc_object_t * p_this )
         {
             msg_Dbg( p_demux, "JPEG SOI marker detected" );
             p_demux->pf_demux = MjpgDemux;
+            p_sys->i_level++;
         }
         else
         {
@@ -345,13 +346,13 @@ static int Open( vlc_object_t * p_this )
     /* Check for jpeg file extension */
     p_sys->b_still = false;
     p_sys->i_still_end = 0;
-    if( demux2_IsPathExtension( p_demux, ".jpeg" ) ||
-        demux2_IsPathExtension( p_demux, ".jpg" ) )
+    if( demux_IsPathExtension( p_demux, ".jpeg" ) ||
+        demux_IsPathExtension( p_demux, ".jpg" ) )
     {
         p_sys->b_still = true;
         if( val.f_float)
         {
-            p_sys->i_still_length =1000000.0 / val.f_float;
+            p_sys->i_still_length = 1000000.0 / val.f_float;
         }
         else
         {
@@ -385,14 +386,11 @@ static int MjpgDemux( demux_t *p_demux )
     demux_sys_t *p_sys = p_demux->p_sys;
     int i;
 
-    if( p_sys->b_still && p_sys->i_still_end && p_sys->i_still_end < mdate() )
+    if( p_sys->b_still && p_sys->i_still_end )
     {
         /* Still frame, wait until the pause delay is gone */
+        mwait( p_sys->i_still_end );
         p_sys->i_still_end = 0;
-    }
-    else if( p_sys->b_still && p_sys->i_still_end )
-    {
-        msleep( 400 );
         return 1;
     }
 
@@ -407,8 +405,14 @@ static int MjpgDemux( demux_t *p_demux )
         return 0;
     }
     i = 3;
+FIND_NEXT_EOI:
     while( !( 0xFF == p_sys->p_peek[i-1] && 0xD9 == p_sys->p_peek[i] ) )
     {
+        if( 0xFF == p_sys->p_peek[i-1] && 0xD8 == p_sys->p_peek[i] )
+        {
+            p_sys->i_level++;
+            msg_Dbg( p_demux, "we found another JPEG SOI at %d", i );
+        }
         i++;
         if( i >= p_sys->i_data_peeked )
         {
@@ -424,6 +428,10 @@ static int MjpgDemux( demux_t *p_demux )
     i++;
 
     msg_Dbg( p_demux, "JPEG EOI detected at %d", i );
+    p_sys->i_level--;
+
+    if( p_sys->i_level > 0 )
+        goto FIND_NEXT_EOI;
     return SendBlock( p_demux, i );
 }
 
@@ -431,10 +439,9 @@ static int MimeDemux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     int         i_size, i;
-    bool  b_match;
-    bool  b_done;
 
-    b_match = CheckMimeHeader( p_demux, &i_size );
+    bool  b_match = CheckMimeHeader( p_demux, &i_size );
+
     if( i_size > 0 )
     {
         stream_Read( p_demux->s, NULL, i_size );
@@ -454,6 +461,7 @@ static int MimeDemux( demux_t *p_demux )
         msg_Warn( p_demux, "cannot peek data" );
         return 0;
     }
+
     i = 0;
     i_size = strlen( p_sys->psz_separator ) + 2;
     if( p_sys->i_data_peeked < i_size )
@@ -461,8 +469,8 @@ static int MimeDemux( demux_t *p_demux )
         msg_Warn( p_demux, "data shortage" );
         return 0;
     }
-    b_done = false;
-    while( !b_done )
+
+    for( ;; )
     {
         while( !( p_sys->p_peek[i] == '-' && p_sys->p_peek[i+1] == '-' ) )
         {
@@ -481,16 +489,15 @@ static int MimeDemux( demux_t *p_demux )
                 }
             }
         }
+
         if( !strncmp( p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2),
                       strlen( p_sys->psz_separator ) ) )
         {
-            b_done = true;
-        }
-        else
-        {
-            i++;
-            i_size++;
+            break;
         }
+
+        i++;
+        i_size++;
     }
 
     if( !b_match )
@@ -520,5 +527,5 @@ static void Close ( vlc_object_t * p_this )
  *****************************************************************************/
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
-    return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 0, i_query, args );
+    return demux_vaControlHelper( p_demux->s, 0, 0, 0, 0, i_query, args );
 }