[vlc-devel] [RFC 07/10] input/demux: handle MRL-sections in src/input/demux.c

Filip Roséen filip at atch.se
Mon Nov 28 03:22:26 CET 2016


These changes simply moves the functionality for dealing with
MRL-sections from src/input/input/.c to src/input/demux.c
---
 src/input/demux.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/input/input.c | 68 -------------------------------------------------------
 2 files changed, 63 insertions(+), 69 deletions(-)

diff --git a/src/input/demux.c b/src/input/demux.c
index 352e3df..fc37683 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <assert.h>
+#include <limits.h>
 
 #include "demux.h"
 #include <libvlc.h>
@@ -34,6 +35,7 @@
 #include <vlc_url.h>
 #include <vlc_modules.h>
 #include <vlc_strings.h>
+#include <vlc_stream_extractor.h>
 
 #include "input_internal.h"
 
@@ -143,6 +145,63 @@ static const char* DemuxNameFromExtension( char const* ext,
     return result ? result->name : NULL;
 }
 
+static const char *MRLSeekPoint( const char *str, int *title, int *chapter )
+{
+    char *end;
+    unsigned long u;
+
+    /* Look for the title */
+    u = strtoul( str, &end, 0 );
+    *title = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
+    str = end;
+
+    /* Look for the chapter */
+    if( *str == ':' )
+    {
+        str++;
+        u = strtoul( str, &end, 0 );
+        *chapter = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
+        str = end;
+    }
+    else
+        *chapter = -1;
+
+    return str;
+}
+
+
+
+static void demux_HandleMRLSections( const char *p,
+                         int *pi_title_start, int *pi_title_end,
+                         int *pi_chapter_start, int *pi_chapter_end )
+{
+    *pi_title_start = *pi_title_end = *pi_chapter_start = *pi_chapter_end = -1;
+
+    int title_start, chapter_start, title_end, chapter_end;
+
+    if( !p )
+        return;
+
+    if( *p != '-' )
+        p = MRLSeekPoint( p, &title_start, &chapter_start );
+    else
+        title_start = chapter_start = -1;
+
+    if( *p == '-' )
+        p = MRLSeekPoint( p + 1, &title_end, &chapter_end );
+    else
+        title_end = chapter_end = -1;
+
+    if( *p ) /* syntax error */
+        return;
+
+    *pi_title_start = title_start;
+    *pi_title_end = title_end;
+    *pi_chapter_start = chapter_start;
+    *pi_chapter_end = chapter_end;
+}
+
+
 /*****************************************************************************
  * demux_New:
  *  if s is NULL then load a access_demux
@@ -333,9 +392,12 @@ demux_t *input_DemuxNew( input_source_t* in, const char *access_name,
             goto out;
         }
 
-        /* Add stream filters */
         stream = stream_FilterAutoNew( stream );
 
+        demux_HandleMRLSections( anchor,
+            &in->i_title_start, &in->i_title_end,
+            &in->i_seekpoint_start, &in->i_seekpoint_end );
+
         char *filters = var_InheritString( in, "stream-filter" );
         if( filters != NULL )
         {
diff --git a/src/input/input.c b/src/input/input.c
index 025e284..4daea42 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -31,7 +31,6 @@
 
 #include <vlc_common.h>
 
-#include <limits.h>
 #include <assert.h>
 #include <math.h>
 #include <sys/stat.h>
@@ -74,8 +73,6 @@ static int  UpdateTitleSeekpointFromDemux( input_thread_t * );
 static void UpdateGenericFromDemux( input_thread_t * );
 static void UpdateTitleListfromDemux( input_thread_t * );
 
-static void MRLSections( const char *, int *, int *, int *, int *);
-
 static input_source_t *InputSourceNew( input_thread_t *, const char *,
                                        const char *psz_forced_demux,
                                        bool b_in_can_fail );
@@ -2282,10 +2279,6 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
     msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
              psz_mrl, psz_access, psz_demux, psz_path );
 
-    /* Find optional titles and seekpoints */
-    MRLSections( psz_anchor, &in->i_title_start, &in->i_title_end,
-                 &in->i_seekpoint_start, &in->i_seekpoint_end );
-
     if( input_priv(p_input)->master == NULL /* XXX ugly */)
     {   /* On master stream only, use input-list */
         char *str = var_InheritString( p_input, "input-list" );
@@ -2884,67 +2877,6 @@ void input_SplitMRL( const char **access, const char **demux,
     *access = p;
 }
 
-static const char *MRLSeekPoint( const char *str, int *title, int *chapter )
-{
-    char *end;
-    unsigned long u;
-
-    /* Look for the title */
-    u = strtoul( str, &end, 0 );
-    *title = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
-    str = end;
-
-    /* Look for the chapter */
-    if( *str == ':' )
-    {
-        str++;
-        u = strtoul( str, &end, 0 );
-        *chapter = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
-        str = end;
-    }
-    else
-        *chapter = -1;
-
-    return str;
-}
-
-
-/*****************************************************************************
- * MRLSections: parse title and seekpoint info from the Media Resource Locator.
- *
- * Syntax:
- * [url][@[title_start][:chapter_start][-[title_end][:chapter_end]]]
- *****************************************************************************/
-static void MRLSections( const char *p,
-                         int *pi_title_start, int *pi_title_end,
-                         int *pi_chapter_start, int *pi_chapter_end )
-{
-    *pi_title_start = *pi_title_end = *pi_chapter_start = *pi_chapter_end = -1;
-
-    int title_start, chapter_start, title_end, chapter_end;
-
-    if( !p )
-        return;
-
-    if( *p != '-' )
-        p = MRLSeekPoint( p, &title_start, &chapter_start );
-    else
-        title_start = chapter_start = -1;
-
-    if( *p == '-' )
-        p = MRLSeekPoint( p + 1, &title_end, &chapter_end );
-    else
-        title_end = chapter_end = -1;
-
-    if( *p ) /* syntax error */
-        return;
-
-    *pi_title_start = title_start;
-    *pi_title_end = title_end;
-    *pi_chapter_start = chapter_start;
-    *pi_chapter_end = chapter_end;
-}
-
 static int input_SlaveSourceAdd( input_thread_t *p_input,
                                  enum slave_type i_type, const char *psz_uri,
                                  unsigned i_flags )
-- 
2.10.2



More information about the vlc-devel mailing list