]> git.sesse.net Git - vlc/blobdiff - modules/demux/mjpeg.c
Remove recursion into modules/demux/mkv/
[vlc] / modules / demux / mjpeg.c
index 8315ca2e12ccf75426074c2317cf975bd1103ac2..ca62a21d89203abd9b92eaff23efd6ddb11a9a1e 100644 (file)
@@ -70,10 +70,8 @@ struct demux_sys_t
     es_format_t     fmt;
     es_out_id_t     *p_es;
 
-    bool      b_still;
+    bool            b_still;
     mtime_t         i_still_end;
-    mtime_t         i_still_length;
-
     mtime_t         i_time;
     mtime_t         i_frame_length;
     char            *psz_separator;
@@ -196,7 +194,7 @@ static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         /* Some broken stream may lack the first boundary */
         if ( p_sys->psz_separator == NULL )
         {
-            msg_Warn( p_demux, "Misformed stream. Trying to work around");
+            msg_Warn( p_demux, "Malformed stream. Trying to work around");
             char *content_type = stream_ContentType( p_demux->s );
             if ( content_type == NULL )
                 return false;
@@ -299,24 +297,23 @@ static int SendBlock( demux_t *p_demux, int i )
         return 0;
     }
 
-    if( !p_sys->i_frame_length || !p_sys->i_time )
+    if( p_sys->i_frame_length )
     {
-        p_sys->i_time = p_block->i_dts = p_block->i_pts = mdate();
+        p_block->i_pts = p_sys->i_time;
+        p_sys->i_time += p_sys->i_frame_length;
     }
     else
     {
-        p_block->i_dts = p_block->i_pts = VLC_TS_0 + p_sys->i_time;
-        p_sys->i_time += p_sys->i_frame_length;
+        p_block->i_pts = mdate();
     }
+    p_block->i_dts = p_block->i_pts;
 
     /* 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;
-    }
+        p_sys->i_still_end = mdate() + p_sys->i_frame_length;
 
     return 1;
 }
@@ -327,30 +324,26 @@ static int SendBlock( demux_t *p_demux, int i )
 static int Open( vlc_object_t * p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
-    demux_sys_t *p_sys;
     int         i_size;
     bool        b_matched = false;
-    float       f_fps;
 
-    p_sys = malloc( sizeof( demux_sys_t ) );
+    if( IsMxpeg( p_demux->s ) && !p_demux->b_force )
+        // let avformat handle this case
+        return VLC_EGENERIC;
+
+    demux_sys_t *p_sys = malloc( sizeof( demux_sys_t ) );
     if( unlikely(p_sys == NULL) )
         return VLC_ENOMEM;
 
     p_demux->pf_control = Control;
     p_demux->p_sys      = p_sys;
     p_sys->p_es         = NULL;
-    p_sys->i_time       = 0;
+    p_sys->i_time       = VLC_TS_0;
     p_sys->i_level      = 0;
 
     p_sys->psz_separator = NULL;
     p_sys->i_frame_size_estimate = 15 * 1024;
 
-    if( IsMxpeg( p_demux->s ) && !p_demux->b_force )
-    {
-        // let avformat handle this case
-        goto error;
-    }
-
     b_matched = CheckMimeHeader( p_demux, &i_size);
     if( b_matched )
     {
@@ -376,31 +369,22 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
+    /* Frame rate */
+    float f_fps = var_InheritFloat( p_demux, "mjpeg-fps" );
 
-    f_fps = var_CreateGetFloat( p_demux, "mjpeg-fps" );
-    p_sys->i_frame_length = 0;
-
-    /* Check for jpeg file extension */
-    p_sys->b_still = false;
     p_sys->i_still_end = 0;
     if( demux_IsPathExtension( p_demux, ".jpeg" ) ||
         demux_IsPathExtension( p_demux, ".jpg" ) )
     {
+        /* Plain JPEG file = single still picture */
         p_sys->b_still = true;
-        if( f_fps )
-        {
-            p_sys->i_still_length = 1000000.0 / f_fps;
-        }
-        else
-        {
+        if( f_fps == 0.f )
             /* Defaults to 1fps */
-            p_sys->i_still_length = 1000000;
-        }
-    }
-    else if ( f_fps )
-    {
-        p_sys->i_frame_length = 1000000.0 / f_fps;
+            f_fps = 1.f;
     }
+    else
+        p_sys->b_still = false;
+    p_sys->i_frame_length = f_fps ? (CLOCK_FREQ / f_fps) : 0;
 
     es_format_Init( &p_sys->fmt, VIDEO_ES, 0 );
     p_sys->fmt.i_codec = VLC_CODEC_MJPG;