[vlc-commits] demux: force demux based on (some) Content-Type values

Rémi Denis-Courmont git at videolan.org
Sun Jul 26 17:29:53 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 26 18:18:34 2015 +0300| [35c573128da68a0fbf59e3bcfef970dff41e2e1e] | committer: Rémi Denis-Courmont

demux: force demux based on (some) Content-Type values

The initial set of recognized content types is based on existing
forced psz_demux values. It is likely better not to add entries unless
detection of the file format is known to be difficult/impossible.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=35c573128da68a0fbf59e3bcfef970dff41e2e1e
---

 src/input/demux.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/input/demux.c b/src/input/demux.c
index e27a55c..5bf960f 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -32,10 +32,46 @@
 #include <vlc_meta.h>
 #include <vlc_url.h>
 #include <vlc_modules.h>
+#include <vlc_strings.h>
 
 static bool SkipID3Tag( demux_t * );
 static bool SkipAPETag( demux_t *p_demux );
 
+struct demux_type
+{
+    char type[20];
+    char demux[8];
+};
+
+static int typecmp( const void *k, const void *t )
+{
+    const char *key = k;
+    const struct demux_type *type = t;
+
+    return vlc_ascii_strcasecmp( key, type->type );
+}
+
+static const char *demux_FromContentType(const char *mime)
+{
+    static const struct demux_type types[] =
+    {   /* Must be sorted in ascending ASCII order */
+        { "audio/aac",           "m4a"     },
+        { "audio/aacp",          "m4a"     },
+        { "audio/mpeg",          "mp3"     },
+        { "application/rss+xml", "podcast" },
+        { "video/MP2T",          "ts"      },
+        { "video/dv",            "rawdv"   },
+        { "video/mpeg",          "ps"      },
+        { "video/nsa",           "nsv"     },
+        { "video/nsv",           "nsv"     },
+    };
+    const struct demux_type *type;
+
+    type = bsearch( mime, types, sizeof (types) / sizeof (types[0]),
+                    sizeof (types[0]), typecmp );
+    return (type != NULL) ? type->demux : "any";
+}
+
 #undef demux_New
 /*****************************************************************************
  * demux_New:
@@ -50,6 +86,16 @@ demux_t *demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
     if( unlikely(p_demux == NULL) )
         return NULL;
 
+    if( s != NULL && (!strcasecmp( psz_demux, "any" ) || !psz_demux[0]) )
+    {   /* Look up demux by Content-Type for hard to detect formats */
+        char *type = stream_ContentType( s );
+        if( type != NULL )
+        {
+            psz_demux = demux_FromContentType( type );
+            free( type );
+        }
+    }
+
     p_demux->p_input = p_parent_input;
     p_demux->psz_access = strdup( psz_access );
     p_demux->psz_demux = strdup( psz_demux );



More information about the vlc-commits mailing list