[vlc-devel] [PATCH] access_out/livehttp.c: additional segments naming pattern
Łukasz Korbel
korbel85 at gmail.com
Fri Mar 9 21:15:47 CET 2012
>From 2e39440e230258a905bb8ccf3af9101081b3bdea Mon Sep 17 00:00:00 2001
From: Lukasz Korbel <korbel85 at gmail.com>
Date: Fri, 9 Mar 2012 20:31:13 +0100
Subject: [PATCH 2/2] access_output/livehttp.c: additional segments naming
pattern
In some cases having segments names not plain indexes may be useful.
Added option name-pattern.
Added timestamp name pattern - names are timestamps (seconds since
Epoch) of broadcast time (estimated).
---
modules/access_output/livehttp.c | 38 ++++++++++++++++++++++++++++++++++++--
1 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
index d335a64..c1b9f94 100644
--- a/modules/access_output/livehttp.c
+++ b/modules/access_output/livehttp.c
@@ -82,6 +82,13 @@ 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) ")
+
vlc_module_begin ()
set_description( N_("HTTP Live streaming output") )
set_shortname( N_("LiveHTTP" ))
@@ -101,6 +108,8 @@ 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 )
set_callbacks( Open, Close )
vlc_module_end ()
@@ -116,6 +125,7 @@ static const char *const ppsz_sout_options[] = {
"index",
"index-url",
"ratecontrol",
+ "name-pattern",
NULL
};
@@ -128,8 +138,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 +197,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 +234,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: index, timestamp",
+ SOUT_CFG_PREFIX, p_sys->psz_namePattern);
+ return NULL;
+ }
+
free ( psz_result );
if ( ret < 0 )
return NULL;
--
1.7.5.4
More information about the vlc-devel
mailing list