]> git.sesse.net Git - vlc/blobdiff - modules/demux/mjpeg.c
A bit of headers cleanup
[vlc] / modules / demux / mjpeg.c
index 0cad26d06df43099adfec4bd4bb079b3f2f0a635..f4b91e45b7811e53d2181c3d1effa5b7ecbcee28 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * mjpeg.c : demuxes mjpeg webcam http streams
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
- * $Id: mjpeg.c 7196 2004-03-29 21:29:31Z fenrir $
+ * Copyright (C) 2004 the VideoLAN team
+ * $Id$
  *
  * Authors: Henry Jen (slowhog) <henryjen@ztune.net>
  *          Derk-Jan Hartman (thedj)
@@ -21,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -30,9 +30,9 @@
 #include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_demux.h>
 
-#include <codecs.h>
+#include <vlc_codecs.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -41,13 +41,17 @@ static int  Open ( vlc_object_t * );
 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 FPS_LONGTEXT N_("This is the desired frame rate when " \
+    "playing MJPEG from a file. Use 0 (this is the default value) for a " \
+    "live stream (from a camera).")
 
 vlc_module_begin();
-    set_description( _("JPEG camera demuxer") );
+    set_shortname( "MJPEG");
+    set_description( _("M-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();
 
@@ -65,6 +69,7 @@ struct demux_sys_t
 
     vlc_bool_t      b_still;
     mtime_t         i_still_end;
+    mtime_t         i_still_length;
 
     mtime_t         i_time;
     mtime_t         i_frame_length;
@@ -75,7 +80,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 )
@@ -152,7 +157,7 @@ static char* GetLine( demux_t *p_demux, int *p_pos )
         msg_Err( p_demux, "out of memory" );
         return NULL;
     }
-    strncpy ( p_line, p_buf, i );
+    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 );
     return p_line;
@@ -184,7 +189,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;
@@ -197,7 +202,9 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         *p_header_size = -3;
         return VLC_FALSE;
     }
-    if( NULL == p_sys->psz_separator )
+
+    /* Read the separator and remember it if not yet stored */
+    if( p_sys->psz_separator == NULL )
     {
         p_sys->psz_separator = psz_line;
         msg_Dbg( p_demux, "Multipart MIME detected, using separator: %s",
@@ -212,6 +219,7 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         }
         free( psz_line );
     }
+
     psz_line = GetLine( p_demux, &i_pos );
     while( psz_line && *psz_line )
     {
@@ -231,7 +239,7 @@ static vlc_bool_t CheckMimeHeader( demux_t *p_demux, int *p_header_size )
         }
         else
         {
-            msg_Dbg( p_demux, "Discard MIME header: %s", psz_line );
+            msg_Dbg( p_demux, "discard MIME header: %s", psz_line );
         }
         free( psz_line );
         psz_line = GetLine( p_demux, &i_pos );
@@ -277,7 +285,7 @@ static int SendBlock( demux_t *p_demux, int i )
 
     if( p_sys->b_still )
     {
-        p_sys->i_still_end = mdate() + I64C(5000000);
+        p_sys->i_still_end = mdate() + p_sys->i_still_length;
     }
 
     return 1;
@@ -327,6 +335,11 @@ 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;
@@ -335,12 +348,17 @@ static int Open( vlc_object_t * p_this )
                      !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;
+        }
     }
-
-    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 )
+    else if ( val.f_float )
     {
         p_sys->i_frame_length = 1000000.0 / val.f_float;
     }
@@ -373,7 +391,7 @@ static int MjpgDemux( demux_t *p_demux )
     }
     else if( p_sys->b_still && p_sys->i_still_end )
     {
-        msleep( 40000 );
+        msleep( 400 );
         return 1;
     }
 
@@ -393,11 +411,11 @@ static int MjpgDemux( demux_t *p_demux )
         i++;
         if( i >= p_sys->i_data_peeked )
         {
-            msg_Dbg( p_demux, "Did not find JPEG EOI in %d bytes",
+            msg_Dbg( p_demux, "did not find JPEG EOI in %d bytes",
                      p_sys->i_data_peeked );
             if( !Peek( p_demux, VLC_FALSE ) )
             {
-                msg_Warn( p_demux, "No more data is available at the moment" );
+                msg_Warn( p_demux, "no more data is available at the moment" );
                 return 0;
             }
         }
@@ -456,13 +474,13 @@ static int MimeDemux( demux_t *p_demux )
 
                 if( !Peek( p_demux, VLC_FALSE ) )
                 {
-                    msg_Warn( p_demux, "No more data is available at the "
+                    msg_Warn( p_demux, "no more data is available at the "
                               "moment" );
                     return 0;
                 }
             }
         }
-        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;
@@ -476,7 +494,7 @@ static int MimeDemux( demux_t *p_demux )
 
     if( !b_match )
     {
-        msg_Err( p_demux, "Discard non-JPEG part" );
+        msg_Err( p_demux, "discard non-JPEG part" );
         stream_Read( p_demux->s, NULL, i );
         return 0;
     }