]> git.sesse.net Git - vlc/blobdiff - modules/access_output/livehttp.c
mediacodec: avoid IllegalStateException on some weird devices
[vlc] / modules / access_output / livehttp.c
index 52a383d4a23975d0c0a1e69fb208cb886533e739..8323b528103f74a279b185a3889293c49403e1f0 100644 (file)
@@ -33,6 +33,9 @@
 #include <time.h>
 #include <fcntl.h>
 #include <errno.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -157,7 +160,8 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     p_sys->i_seglen = var_GetInteger( p_access, SOUT_CFG_PREFIX "seglen" );
-    p_sys->i_seglenm = CLOCK_FREQ * p_sys->i_seglen;
+    /* Try to get within +-10% of asked segment length, so lower limit is 90% of segment length*/
+    p_sys->i_seglenm = CLOCK_FREQ * p_sys->i_seglen * 0.9;
 
     p_sys->i_numsegs = var_GetInteger( p_access, SOUT_CFG_PREFIX "numsegs" );
     p_sys->b_splitanywhere = var_GetBool( p_access, SOUT_CFG_PREFIX "splitanywhere" );
@@ -169,7 +173,7 @@ static int Open( vlc_object_t *p_this )
     if ( psz_idx )
     {
         char *psz_tmp;
-        psz_tmp = str_format( p_access, psz_idx );
+        psz_tmp = str_format_time( psz_idx );
         free( psz_idx );
         if ( !psz_tmp )
         {
@@ -199,12 +203,12 @@ static int Open( vlc_object_t *p_this )
 /*****************************************************************************
  * formatSegmentPath: create segment path name based on seg #
  *****************************************************************************/
-static char *formatSegmentPath( sout_access_out_t *p_access, char *psz_path, uint32_t i_seg, bool b_sanitize )
+static char *formatSegmentPath( char *psz_path, uint32_t i_seg, bool b_sanitize )
 {
     char *psz_result;
     char *psz_firstNumSign;
 
-    if ( ! ( psz_result  = str_format( p_access, psz_path ) ) )
+    if ( ! ( psz_result  = str_format_time( psz_path ) ) )
         return NULL;
 
     psz_firstNumSign = psz_result + strcspn( psz_result, SEG_NUMBER_PLACEHOLDER );
@@ -268,7 +272,7 @@ static int updateIndexAndDel( sout_access_out_t *p_access, sout_access_out_sys_t
         for ( uint32_t i = i_firstseg; i <= p_sys->i_segment; i++ )
         {
             char *psz_name;
-            if ( ! ( psz_name = formatSegmentPath( p_access, psz_idxFormat, i, false ) ) )
+            if ( ! ( psz_name = formatSegmentPath( psz_idxFormat, i, false ) ) )
             {
                 free( psz_idxTmp );
                 fclose( fp );
@@ -312,7 +316,7 @@ static int updateIndexAndDel( sout_access_out_t *p_access, sout_access_out_sys_t
     // Then take care of deletion
     if ( p_sys->b_delsegs && i_firstseg > 1 )
     {
-        char *psz_name = formatSegmentPath( p_access, p_access->psz_path, i_firstseg-1, true );
+        char *psz_name = formatSegmentPath( p_access->psz_path, i_firstseg-1, true );
          if ( psz_name )
          {
              vlc_unlink( psz_name );
@@ -387,7 +391,7 @@ static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t
 
     uint32_t i_newseg = p_sys->i_segment + 1;
 
-    char *psz_seg = formatSegmentPath( p_access, p_access->psz_path, i_newseg, true );
+    char *psz_seg = formatSegmentPath( p_access->psz_path, i_newseg, true );
     if ( !psz_seg )
         return -1;
 
@@ -419,7 +423,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
 
     while( p_buffer )
     {
-        if ( p_sys->i_handle >= 0 && ( p_sys->b_splitanywhere || ( p_buffer->i_flags & BLOCK_FLAG_TYPE_I ) ) && ( p_buffer->i_dts-p_sys->i_opendts ) > p_sys->i_seglenm )
+        if ( p_sys->i_handle >= 0 && ( p_sys->b_splitanywhere || ( p_buffer->i_flags & BLOCK_FLAG_HEADER ) ) && ( p_buffer->i_dts-p_sys->i_opendts ) > p_sys->i_seglenm )
         {
             closeCurrentSegment( p_access, p_sys, false );
         }