]> git.sesse.net Git - vlc/blobdiff - modules/demux/mjpeg.c
* src/misc/httpd.c: bug fix to re-use the httpd host (patch by Sau)
[vlc] / modules / demux / mjpeg.c
index c57e7f6c5fe3dd33b609002d9e6470eff8f74484..0cad26d06df43099adfec4bd4bb079b3f2f0a635 100644 (file)
@@ -43,13 +43,12 @@ static void Close( vlc_object_t * );
 #define FPS_TEXT N_("Frames per Second")
 #define FPS_LONGTEXT N_("Allows you to set the desired frame rate when " \
     "playing from files, use 0 for live.")
-#define VAR_FPS "mjpeg-fps"
 
 vlc_module_begin();
     set_description( _("JPEG camera demuxer") );
     set_capability( "demux2", 5 );
     set_callbacks( Open, Close );
-    add_float( VAR_FPS, 0.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_FALSE );
+    add_float( "mjpeg-fps", 0.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_FALSE );
 vlc_module_end();
 
 /*****************************************************************************
@@ -64,6 +63,9 @@ 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_time;
     mtime_t         i_frame_length;
     char            *psz_separator;
@@ -213,7 +215,6 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
     psz_line = GetLine( p_demux, &i_pos );
     while( psz_line && *psz_line )
     {
-        msg_Dbg( p_demux, "%s", psz_line );
         if( !strncasecmp( psz_line, "Content-Type:", 13 ) )
         {
             p_ch = psz_line + 13;
@@ -235,12 +236,16 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         free( psz_line );
         psz_line = GetLine( p_demux, &i_pos );
     }
+
     if( NULL == psz_line )
     {
         msg_Err( p_demux, "no EOL" );
         *p_header_size = -3;
         return VLC_FALSE;
     }
+
+    free( psz_line );
+
     *p_header_size = i_pos;
     return b_jpeg;
 }
@@ -256,9 +261,9 @@ static int SendBlock( demux_t *p_demux, int i )
         return 0;
     }
 
-    if( 0 == p_sys->i_frame_length )
+    if( !p_sys->i_frame_length || !p_sys->i_time )
     {
-        p_block->i_dts = p_block->i_pts = mdate() + 1;
+        p_sys->i_time = p_block->i_dts = p_block->i_pts = mdate();
     }
     else
     {
@@ -269,6 +274,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() + I64C(5000000);
+    }
+
     return 1;
 }
 
@@ -282,16 +293,13 @@ static int Open( vlc_object_t * p_this )
     int         i_size;
     int         b_matched = VLC_FALSE;
     vlc_value_t val;
-    float       f_fps;
+    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       = 1;
-    var_Create( p_demux, VAR_FPS, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
-    var_Get( p_demux, VAR_FPS, &val );
-    f_fps = val.f_float;
-    p_sys->i_frame_length = 1000000.0 / f_fps;
+    p_sys->i_time       = 0;
+
     p_sys->psz_separator = NULL;
     p_sys->i_frame_size_estimate = 15 * 1024;
 
@@ -319,6 +327,24 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
+    /* 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;
+    }
+
+    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;
+    }
+
     es_format_Init( &p_sys->fmt, VIDEO_ES, 0 );
     p_sys->fmt.i_codec = VLC_FOURCC('m','j','p','g');
 
@@ -326,7 +352,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;
 }
@@ -339,7 +364,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( 40000 );
+        return 1;
+    }
 
     if( !Peek( p_demux, VLC_TRUE ) )
     {
@@ -367,6 +403,7 @@ static int MjpgDemux( demux_t *p_demux )
         }
     }
     i++;
+
     msg_Dbg( p_demux, "JPEG EOI detected at %d", i );
     return SendBlock( p_demux, i );
 }
@@ -429,17 +466,14 @@ static int MimeDemux( demux_t *p_demux )
                       strlen( p_sys->psz_separator ) ) )
         {
             b_done = VLC_TRUE;
-            msg_Dbg( p_demux, "MIME boundary detected at %d", i );
         }
         else
         {
             i++;
             i_size++;
-            msg_Dbg( p_demux, "not done" );
         }
     }
 
-    msg_Dbg( p_demux, "i is %d", i );  
     if( !b_match )
     {
         msg_Err( p_demux, "Discard non-JPEG part" );
@@ -470,7 +504,5 @@ static void Close ( vlc_object_t * p_this )
  *****************************************************************************/
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
-    demux_sys_t *p_sys = p_demux->p_sys;
-
     return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 0, i_query, args );
 }