[vlc-devel] [PATCH] Naming patterns for HLS segments
Łukasz Korbel
korbel85 at gmail.com
Fri Apr 20 18:47:03 CEST 2012
I've removed str_format entirely.
diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
index d335a64..fd3e7ad 100644
--- a/modules/access_output/livehttp.c
+++ b/modules/access_output/livehttp.c
@@ -75,7 +75,8 @@ static void Close( vlc_object_t * );
#define INDEXURL_TEXT N_("Full URL to put in index file")
#define INDEXURL_LONGTEXT N_("Full URL to put in index file. "\
- "Use #'s to represent segment number")
+ "Use #'s to represent segment number. "\
+ "Use strftime() specifiers for date/time values.")
#define DELSEGS_TEXT N_("Delete segments")
#define DELSEGS_LONGTEXT N_("Delete segments when they are no longer needed")
@@ -130,6 +131,7 @@ struct sout_access_out_sys_t
char *psz_indexUrl;
mtime_t i_opendts;
mtime_t i_seglenm;
+ time_t i_broadcastStart;
uint32_t i_segment;
size_t i_seglen;
int i_handle;
@@ -186,6 +188,11 @@ static int Open( vlc_object_t *p_this )
p_sys->psz_indexUrl = var_GetNonEmptyString( p_access,
SOUT_CFG_PREFIX "index-url" );
+ // Set broadcast start time
+ // round down to multiplication of segment length
+ p_sys->i_broadcastStart = time( NULL );
+ p_sys->i_broadcastStart = p_sys->i_broadcastStart /
p_sys->i_seglen * p_sys->i_seglen;
+
p_access->p_sys = p_sys;
p_sys->i_handle = -1;
p_sys->i_segment = 0;
@@ -207,9 +214,34 @@ static char *formatSegmentPath( sout_access_out_t
*p_access, char *psz_path, uin
char *psz_result;
char *psz_firstNumSign;
- if ( ! ( psz_result = str_format( p_access, psz_path ) ) )
- return NULL;
+ // Copy path string
+ asprintf( &psz_result, "%s", psz_path );
+
+ // Apply time formating to segment name only if string may
contain time specifiers
+ if ( strcspn( psz_result, "%" ) < strlen( psz_result ) )
+ {
+ time_t now;
+ struct tm * timeinfo;
+ int len;
+ char *psz_tmp;
+ sout_access_out_sys_t *p_sys;
+
+ // Interpolate current time based on segment length and
broadcast start time
+ p_sys = p_access->p_sys;
+ now = p_sys->i_broadcastStart + i_seg * p_sys->i_seglen;
+ timeinfo = localtime( &now );
+ // Its hard to determine output final lenght
+ // Assuming twice the lenght of format string is enough
+ len = 2 * strlen( psz_result );
+ psz_tmp = malloc( len * sizeof( char ) );
+ if ( strftime( psz_tmp, len, psz_result, timeinfo ) > 0 )
+ {
+ free( psz_result );
+ psz_result = psz_tmp;
+ }
+ }
+ // Replace placeholders with actual segment number
psz_firstNumSign = psz_result + strcspn( psz_result,
SEG_NUMBER_PLACEHOLDER );
if ( *psz_firstNumSign ) {
char *psz_newResult;
@@ -218,7 +250,7 @@ static char *formatSegmentPath( sout_access_out_t
*p_access, char *psz_path, uin
*psz_firstNumSign = '\0';
ret = asprintf( &psz_newResult, "%s%0*d%s", psz_result,
i_cnt, i_seg, psz_firstNumSign + i_cnt );
- free ( psz_result );
+ free( psz_result );
if ( ret < 0 )
return NULL;
psz_result = psz_newResult;
--
Łukasz Korbel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-livehttp.c-formatSegmentPath-added-date-time-formatt.patch
Type: application/octet-stream
Size: 3655 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120420/f6263c40/attachment.obj>
More information about the vlc-devel
mailing list