[vlc-devel] [PATCH] Naming patterns for HLS segments

Łukasz Korbel korbel85 at gmail.com
Thu Apr 19 22:48:57 CEST 2012


Fixed version of patch. Use interpolated values of time to assign
proper (constant) value based on segment number.
Function str_format() changed to str_format_meta() to avoid unwanted
call to str_format_time().


---
 modules/access_output/livehttp.c |   39 +++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
index d335a64..c8a99bb 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,35 @@ 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 ) ) )
+    // Don't call str_format_time because we need interpolated time values
+    if ( ! ( psz_result  = str_format_meta( p_access, psz_path ) ) )
         return NULL;

+    // 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 +251,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;
--

Best regards,
Ł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: 3730 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120419/ce26501f/attachment.obj>


More information about the vlc-devel mailing list