]> git.sesse.net Git - vlc/blobdiff - src/input/demux.c
Add a few harmless const
[vlc] / src / input / demux.c
index 9cc6bebdbef35704362ae59dc1ca6ad3e416f0f4..a91327cf8bf7c2ffafa78b65fdf78f6c6fc3c8e2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * demux.c
  *****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2004 the VideoLAN team
  * $Id$
  *
  * Author: Laurent Aimar <fenrir@via.ecp.fr>
@@ -18,7 +18,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.
  *****************************************************************************/
 
 #include <stdlib.h>
 
 #include "input_internal.h"
 
+static void SkipID3Tag( demux_t * );
+
 /*****************************************************************************
  * demux2_New:
  *  if s is NULL then load a access_demux
  *****************************************************************************/
 demux_t *__demux2_New( vlc_object_t *p_obj,
-                       char *psz_access, char *psz_demux, char *psz_path,
-                       stream_t *s, es_out_t *out )
+                       const char *psz_access, const char *psz_demux,
+                       const char *psz_path,
+                       stream_t *s, es_out_t *out, vlc_bool_t b_quick )
 {
     demux_t *p_demux = vlc_object_create( p_obj, VLC_OBJECT_DEMUX );
-    char *psz_module;
+    const char *psz_module;
 
-    if( p_demux == NULL )
-    {
-        return NULL;
-    }
+    if( p_demux == NULL ) return NULL;
 
     /* Parse URL */
     p_demux->psz_access = strdup( psz_access );
     p_demux->psz_demux  = strdup( psz_demux );
     p_demux->psz_path   = strdup( psz_path );
 
-    /* Take into account "demux" to be able to do :demux=demuxdump */
+    /* Take into account "demux" to be able to do :demux=dump */
     if( *p_demux->psz_demux == '\0' )
     {
         free( p_demux->psz_demux );
         p_demux->psz_demux = var_GetString( p_obj, "demux" );
     }
 
-    msg_Dbg( p_obj, "demux2_New: access='%s' demux='%s' path='%s'",
-             p_demux->psz_access, p_demux->psz_demux, p_demux->psz_path );
+    if( !b_quick )
+    {
+        msg_Dbg( p_obj, "creating demux: access='%s' demux='%s' path='%s'",
+                 p_demux->psz_access, p_demux->psz_demux, p_demux->psz_path );
+    }
 
     p_demux->s          = s;
     p_demux->out        = out;
@@ -68,19 +71,18 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
     p_demux->info.i_title  = 0;
     p_demux->info.i_seekpoint = 0;
 
-    if( s )
-        psz_module = p_demux->psz_demux;
-    else
-        psz_module = p_demux->psz_access;
+    if( s ) psz_module = p_demux->psz_demux;
+    else psz_module = p_demux->psz_access;
 
     if( s && *psz_module == '\0' && strrchr( p_demux->psz_path, '.' ) )
     {
-        /* XXX: add only file without any problem here and with strong detection.
-         *  - no .mp3, .a52, ... (aac is added as it works only by file ext anyway
-         *  - wav can't be added 'cause of a52 and dts in them as raw audio
+       /* XXX: add only file without any problem here and with strong detection.
+        *  - no .mp3, .a52, ... (aac is added as it works only by file ext
+        *     anyway
+        *  - wav can't be added 'cause of a52 and dts in them as raw audio
          */
-        static struct { char *ext; char *demux; } exttodemux[] =
-        {
+         static struct { const char *ext; const char *demux; } exttodemux[] =
+         {
             { "aac",  "aac" },
             { "aiff", "aiff" },
             { "asf",  "asf" }, { "wmv",  "asf" }, { "wma",  "asf" },
@@ -88,7 +90,7 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
             { "au",   "au" },
             { "flac", "flac" },
             { "dv",   "dv" },
-            { "m3u",  "m3u" },
+            { "m3u",  "playlist" },
             { "mkv",  "mkv" }, { "mka",  "mkv" }, { "mks",  "mkv" },
             { "mp4",  "mp4" }, { "m4a",  "mp4" }, { "mov",  "mp4" }, { "moov", "mp4" },
             { "mod",  "mod" }, { "xm",   "mod" },
@@ -96,20 +98,45 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
             { "ogg",  "ogg" }, { "ogm",  "ogg" },
             { "pva",  "pva" },
             { "rm",   "rm" },
+            { "m4v",  "m4v" },
+            { "h264",  "h264" },
             { NULL,  NULL },
         };
+        /* Here, we don't mind if it does not work, it must be quick */
+        static struct { const char *ext; const char *demux; } exttodemux_quick[] =
+        {
+            { "mp3", "mpga" },
+            { "ogg", "ogg" },
+            { "wma", "asf" },
+            { NULL, NULL }
+        };
 
-        char *psz_ext = strrchr( p_demux->psz_path, '.' ) + 1;
+        const char *psz_ext = strrchr( p_demux->psz_path, '.' ) + 1;
         int  i;
 
-        for( i = 0; exttodemux[i].ext != NULL; i++ )
+        if( !b_quick )
         {
-            if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
+            for( i = 0; exttodemux[i].ext != NULL; i++ )
             {
-                psz_module = exttodemux[i].demux;
-                break;
+                if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
+                {
+                    psz_module = exttodemux[i].demux;
+                    break;
+                }
             }
         }
+        else
+        {
+            for( i = 0; exttodemux_quick[i].ext != NULL; i++ )
+            {
+                if( !strcasecmp( psz_ext, exttodemux_quick[i].ext ) )
+                {
+                    psz_module = exttodemux_quick[i].demux;
+                    break;
+                }
+            }
+
+        }
     }
 
     /* Before module_Need (for var_Create...) */
@@ -117,6 +144,11 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
 
     if( s )
     {
+        /* ID3 tags will mess-up demuxer probing so we skip it here.
+         * ID3 parsers will called later on in the demuxer to access the
+         * skipped info. */
+        SkipID3Tag( p_demux );
+
         p_demux->p_module =
             module_Need( p_demux, "demux2", psz_module,
                          !strcmp( psz_module, p_demux->psz_demux ) ?
@@ -270,7 +302,7 @@ static int DStreamControl( stream_t *, int i_query, va_list );
 static int DStreamThread ( stream_t * );
 
 
-stream_t *__stream_DemuxNew( vlc_object_t *p_obj, char *psz_demux,
+stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux,
                              es_out_t *out )
 {
     /* We create a stream reader, and launch a thread */
@@ -285,6 +317,9 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, char *psz_demux,
     s->pf_peek   = DStreamPeek;
     s->pf_control= DStreamControl;
 
+    s->i_char_width = 1;
+    s->b_little_endian = VLC_FALSE;
+
     s->p_sys = malloc( sizeof( d_stream_sys_t) );
     p_sys = (d_stream_sys_t*)s->p_sys;
 
@@ -486,7 +521,8 @@ static int DStreamThread( stream_t *s )
     demux_t *p_demux;
 
     /* Create the demuxer */
-    if( !(p_demux = demux2_New( s, "", p_sys->psz_name, "", s, p_sys->out )) )
+    if( !(p_demux = demux2_New( s, "", p_sys->psz_name, "", s, p_sys->out,
+                               VLC_FALSE )) )
     {
         return VLC_EGENERIC;
     }
@@ -502,3 +538,37 @@ static int DStreamThread( stream_t *s )
     p_demux->b_die = VLC_TRUE;
     return VLC_SUCCESS;
 }
+
+/****************************************************************************
+ * Utility functions
+ ****************************************************************************/
+static void SkipID3Tag( demux_t *p_demux )
+{
+    uint8_t *p_peek;
+    uint8_t version, revision;
+    int i_size;
+    int b_footer;
+
+    if( !p_demux->s ) return;
+
+    /* Get 10 byte id3 header */
+    if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) return;
+
+    if( p_peek[0] != 'I' || p_peek[1] != 'D' || p_peek[2] != '3' ) return;
+
+    version = p_peek[3];
+    revision = p_peek[4];
+    b_footer = p_peek[5] & 0x10;
+    i_size = (p_peek[6]<<21) + (p_peek[7]<<14) + (p_peek[8]<<7) + p_peek[9];
+
+    if( b_footer ) i_size += 10;
+    i_size += 10;
+
+    /* Skip the entire tag */
+    stream_Read( p_demux->s, NULL, i_size );
+
+    msg_Dbg( p_demux, "ID3v2.%d revision %d tag found, skipping %d bytes",
+             version, revision, i_size );
+
+    return;
+}