]> git.sesse.net Git - vlc/blobdiff - modules/demux/mjpeg.c
mkv.cpp: avoid dependency problems with older libmatroska
[vlc] / modules / demux / mjpeg.c
index eacc31dcca58c3a0bbc8a606c0951b40b6cc68cd..8de57fbecd0f51d5a5940f7060b83b71f8145b33 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mjpeg.c : demuxes mjpeg webcam http streams
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  * $Id: mjpeg.c 7196 2004-03-29 21:29:31Z fenrir $
  *
  * Authors: Henry Jen (slowhog) <henryjen@ztune.net>
@@ -45,9 +45,12 @@ static void Close( vlc_object_t * );
     "playing from files, use 0 for live.")
 
 vlc_module_begin();
+    set_shortname( "MJPEG");
     set_description( _("JPEG camera demuxer") );
     set_capability( "demux2", 5 );
     set_callbacks( Open, Close );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_DEMUX );
     add_float( "mjpeg-fps", 0.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_FALSE );
 vlc_module_end();
 
@@ -63,6 +66,10 @@ struct demux_sys_t
     es_format_t     fmt;
     es_out_id_t     *p_es;
 
+    vlc_bool_t      b_still;
+    mtime_t         i_still_end;
+    mtime_t         i_still_length;
+
     mtime_t         i_time;
     mtime_t         i_frame_length;
     char            *psz_separator;
@@ -72,7 +79,7 @@ struct demux_sys_t
 };
 
 /*****************************************************************************
- * Peek: Helper function to peek data with incremental size. 
+ * Peek: Helper function to peek data with incremental size.
  * \return VLC_FALSE if peek no more data, VLC_TRUE otherwise.
  *****************************************************************************/
 static vlc_bool_t Peek( demux_t *p_demux, vlc_bool_t b_first )
@@ -181,7 +188,7 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         *p_header_size = -2;
         return VLC_FALSE;
     }
-    if( strncmp( p_sys->p_peek, "--", 2 ) )
+    if( strncmp( (char *)p_sys->p_peek, "--", 2 ) )
     {
         *p_header_size = 0;
         return VLC_FALSE;
@@ -271,6 +278,12 @@ static int SendBlock( demux_t *p_demux, int i )
     /* set PCR */
     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
     es_out_Send( p_demux->out, p_sys->p_es, p_block );
+
+    if( p_sys->b_still )
+    {
+        p_sys->i_still_end = mdate() + p_sys->i_still_length;
+    }
+
     return 1;
 }
 
@@ -284,20 +297,13 @@ static int Open( vlc_object_t * p_this )
     int         i_size;
     int         b_matched = VLC_FALSE;
     vlc_value_t val;
+    char *psz_ext;
 
     p_demux->pf_control = Control;
     p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
     p_sys->p_es         = NULL;
     p_sys->i_time       = 0;
 
-    var_Create( p_demux, "mjpeg-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, "mjpeg-fps", &val );
-    p_sys->i_frame_length = 0;
-    if( val.f_float )
-    {
-        p_sys->i_frame_length = 1000000.0 / val.f_float;
-    }
-
     p_sys->psz_separator = NULL;
     p_sys->i_frame_size_estimate = 15 * 1024;
 
@@ -325,6 +331,34 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
+
+    var_Create( p_demux, "mjpeg-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
+    var_Get( p_demux, "mjpeg-fps", &val );
+    p_sys->i_frame_length = 0;
+
+    /* Check for jpeg file extension */
+    p_sys->b_still = VLC_FALSE;
+    p_sys->i_still_end = 0;
+    psz_ext = strrchr( p_demux->psz_path, '.' );
+    if( psz_ext && ( !strcasecmp( psz_ext, ".jpeg" ) ||
+                     !strcasecmp( psz_ext, ".jpg" ) ) )
+    {
+        p_sys->b_still = VLC_TRUE;
+        if( val.f_float)
+        {
+            p_sys->i_still_length =1000000.0 / val.f_float;
+        }
+        else
+        {
+            /* Defaults to 1fps */
+            p_sys->i_still_length = 1000000;
+        }
+    }
+    else if ( val.f_float )
+    {
+        p_sys->i_frame_length = 1000000.0 / val.f_float;
+    }
+
     es_format_Init( &p_sys->fmt, VIDEO_ES, 0 );
     p_sys->fmt.i_codec = VLC_FOURCC('m','j','p','g');
 
@@ -332,7 +366,6 @@ static int Open( vlc_object_t * p_this )
     return VLC_SUCCESS;
 
 error:
-    msg_Warn( p_demux, "JPEG camera module discarded" );
     free( p_sys );
     return VLC_EGENERIC;
 }
@@ -345,7 +378,18 @@ error:
 static int MjpgDemux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
-    int         i;
+    int i;
+
+    if( p_sys->b_still && p_sys->i_still_end && p_sys->i_still_end < mdate() )
+    {
+        /* Still frame, wait until the pause delay is gone */
+        p_sys->i_still_end = 0;
+    }
+    else if( p_sys->b_still && p_sys->i_still_end )
+    {
+        msleep( 400 );
+        return 1;
+    }
 
     if( !Peek( p_demux, VLC_TRUE ) )
     {
@@ -373,6 +417,7 @@ static int MjpgDemux( demux_t *p_demux )
         }
     }
     i++;
+
     msg_Dbg( p_demux, "JPEG EOI detected at %d", i );
     return SendBlock( p_demux, i );
 }
@@ -431,7 +476,7 @@ static int MimeDemux( demux_t *p_demux )
                 }
             }
         }
-        if( !strncmp( p_sys->psz_separator, p_sys->p_peek + i + 2,
+        if( !strncmp( p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2),
                       strlen( p_sys->psz_separator ) ) )
         {
             b_done = VLC_TRUE;