livehttp: don't open new file if current file hasn't been written to
authorIlkka Ollakka <ileoo@videolan.org>
Sun, 21 Sep 2014 10:35:55 +0000 (11:35 +0100)
committerIlkka Ollakka <ileoo@videolan.org>
Sun, 21 Sep 2014 13:48:18 +0000 (14:48 +0100)
modules/access_output/livehttp.c

index e59f3b4..0563f8d 100644 (file)
@@ -196,6 +196,7 @@ struct sout_access_out_sys_t
     bool b_splitanywhere;
     bool b_caching;
     bool b_generate_iv;
+    bool b_segment_has_data;
     uint8_t aes_ivs[16];
     gcry_cipher_hd_t aes_ctx;
     char *key_uri;
@@ -241,6 +242,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_ratecontrol = var_GetBool( p_access, SOUT_CFG_PREFIX "ratecontrol") ;
     p_sys->b_caching = var_GetBool( p_access, SOUT_CFG_PREFIX "caching") ;
     p_sys->b_generate_iv = var_GetBool( p_access, SOUT_CFG_PREFIX "generate-iv") ;
+    p_sys->b_segment_has_data = false;
 
     p_sys->segments_t = vlc_array_new();
 
@@ -764,7 +766,7 @@ static void Close( vlc_object_t * p_this )
 
         /* Since we are flushing, check the segment change by hand and don't wait
          * possible keyframe*/
-        if( (float)(output_block->i_length + p_sys->i_dts_offset +
+        if( p_sys->b_segment_has_data &&  (float)(output_block->i_length + p_sys->i_dts_offset +
                      output_block->i_dts - p_sys->i_opendts) >= p_sys->i_seglenm )
         {
             closeCurrentSegment( p_access, p_sys, false );
@@ -896,6 +898,7 @@ static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t
     p_sys->psz_cursegPath = strdup(segment->psz_filename);
     p_sys->i_handle = fd;
     p_sys->i_segment = i_newseg;
+    p_sys->b_segment_has_data = false;
     return fd;
 }
 /*****************************************************************************
@@ -918,15 +921,14 @@ static int CheckSegmentChange( sout_access_out_t *p_access, block_t *p_buffer )
         msg_Dbg( p_access, "dts offset %"PRId64, p_sys->i_dts_offset );
     }
 
-    if( p_sys->i_handle > 0 &&
-       (( p_buffer->i_dts - p_sys->i_opendts +
-          p_buffer->i_length + p_sys->i_dts_offset
-        ) >= p_sys->i_seglenm ) )
+    if( p_sys->i_handle > 0 && p_sys->b_segment_has_data &&
+       (( p_buffer->i_length + p_buffer->i_dts - p_sys->i_opendts +
+          p_sys->i_dts_offset ) >= p_sys->i_seglenm ) )
     {
         closeCurrentSegment( p_access, p_sys, false );
     }
 
-    if ( p_sys->i_handle < 0 )
+    if ( unlikely( p_sys->i_handle < 0 ) )
     {
         p_sys->i_dts_offset = 0;
         p_sys->i_opendts = output ? output->i_dts : p_buffer->i_dts;
@@ -989,8 +991,8 @@ static ssize_t writeSegment( sout_access_out_t *p_access )
         }
 
         p_sys->f_seglen =
-            (float)(output->i_length + p_sys->i_dts_offset +
-                    output->i_dts - p_sys->i_opendts) / CLOCK_FREQ;
+            (float)(output->i_length +
+                    output->i_dts - p_sys->i_opendts + p_sys->i_dts_offset) / CLOCK_FREQ;
 
         if ( (size_t)val >= output->i_buffer )
         {
@@ -1033,6 +1035,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
                 block_ChainRelease ( p_buffer );
                 return -1;
             }
+            p_sys->b_segment_has_data = true;
             i_write += writevalue;
         }