[vlc-devel] [PATCH] access_out/livehttp.c: additional segments naming pattern

Łukasz Korbel korbel85 at gmail.com
Mon Mar 12 20:36:54 CET 2012


I have added change_string_list() macro to patch:


>From 20e77230aa618a532d53203ed9bd9aa556a3e8fa Mon Sep 17 00:00:00 2001
From: Lukasz Korbel <korbel85 at gmail.com>
Date: Mon, 12 Mar 2012 20:18:57 +0100
Subject: [PATCH] livehttp.c: name-pattern option for segments

Segments can be named either as raw indexes or as timestamps. Timestamp is
estimate times of broadcasting in seconds since Epoch.
---
 modules/access_output/livehttp.c |   46 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
index d335a64..c0a26b8 100644
--- a/modules/access_output/livehttp.c
+++ b/modules/access_output/livehttp.c
@@ -82,6 +82,20 @@ static void Close( vlc_object_t * );

 #define RATECONTROL_TEXT N_("Use muxers rate control mechanism")

+#define PATTERN_TEXT N_("Pattern for segment names")
+#define PATTERN_LONGTEXT N_("There are following patterns for naming
segments:"\
+                            " index - name is 0-padded index of segment in "\
+                            "broadcast session\n"\
+                            "timestamp - name is time of broadcasting of "\
+                            "segment (number of seconds since Epoch) ")
+
+static const char *const ppsz_segpat[] = {
+    "index", "timestamp"
+};
+static const char *const ppsz_segpat_text[] = {
+    N_("index"), N_("timestamp")
+};
+
 vlc_module_begin ()
     set_description( N_("HTTP Live streaming output") )
     set_shortname( N_("LiveHTTP" ))
@@ -101,6 +115,9 @@ vlc_module_begin ()
                 INDEX_TEXT, INDEX_LONGTEXT, true )
     add_string( SOUT_CFG_PREFIX "index-url", NULL,
                 INDEXURL_TEXT, INDEXURL_LONGTEXT, true )
+    add_string( SOUT_CFG_PREFIX "name-pattern", "index",
+                PATTERN_TEXT, PATTERN_LONGTEXT, true )
+                change_string_list( ppsz_segpat, ppsz_segpat_text, 0)
     set_callbacks( Open, Close )
 vlc_module_end ()

@@ -116,6 +133,7 @@ static const char *const ppsz_sout_options[] = {
     "index",
     "index-url",
     "ratecontrol",
+    "name-pattern",
     NULL
 };

@@ -128,8 +146,10 @@ struct sout_access_out_sys_t
     char *psz_cursegPath;
     char *psz_indexPath;
     char *psz_indexUrl;
+    char *psz_namePattern;
     mtime_t i_opendts;
     mtime_t  i_seglenm;
+    time_t i_broadcastStart;
     uint32_t i_segment;
     size_t  i_seglen;
     int i_handle;
@@ -185,11 +205,16 @@ static int Open( vlc_object_t *p_this )
     }

     p_sys->psz_indexUrl = var_GetNonEmptyString( p_access,
SOUT_CFG_PREFIX "index-url" );
-
+    p_sys->psz_namePattern = var_GetNonEmptyString( p_access,
SOUT_CFG_PREFIX "name-pattern" );
     p_access->p_sys = p_sys;
     p_sys->i_handle = -1;
     p_sys->i_segment = 0;
     p_sys->psz_cursegPath = NULL;
+    /* arbitrary time of broadcast start in seconds */
+    p_sys->i_broadcastStart = time( NULL);
+    /* round down start time to multiple of segment length*/
+    if (p_sys->i_seglen > 1)
+        p_sys->i_broadcastStart = p_sys->i_broadcastStart -
p_sys->i_broadcastStart % p_sys->i_seglen;

     p_access->pf_write = Write;
     p_access->pf_seek  = Seek;
@@ -217,7 +242,24 @@ static char *formatSegmentPath( sout_access_out_t
*p_access, char *psz_path, uin
         int ret;

         *psz_firstNumSign = '\0';
-        ret = asprintf( &psz_newResult, "%s%0*d%s", psz_result,
i_cnt, i_seg, psz_firstNumSign + i_cnt );
+
+        /* Select naming pattern*/
+        sout_access_out_sys_t *p_sys = p_access->p_sys;
+        if (strcmp( p_sys->psz_namePattern, "index") ==  0)
+            ret = asprintf( &psz_newResult, "%s%0*d%s", psz_result,
i_cnt, i_seg, psz_firstNumSign + i_cnt );
+        else if (strcmp( p_sys->psz_namePattern, "timestamp") ==  0)
+        {
+            int timestamp = p_sys->i_broadcastStart + i_seg * p_sys->i_seglen;
+            /* Write timestamp, ignore number of placeholders */
+            ret = asprintf( &psz_newResult, "%s%d%s", psz_result,
timestamp, psz_firstNumSign + i_cnt );
+        }
+        else
+        {
+            msg_Err( p_access, "Unrecognized value for %sname-pattern
(%s). Allowed values: %s",
+                               SOUT_CFG_PREFIX,
p_sys->psz_namePattern, ppsz_segpat);
+            return NULL;
+        }
+
         free ( psz_result );
         if ( ret < 0 )
             return NULL;
-- 
1.7.5.4

Best,
Łukasz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-livehttp.c-name-pattern-option-for-segments.patch
Type: text/x-patch
Size: 4352 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120312/1cf4c0df/attachment.bin>


More information about the vlc-devel mailing list