[vlc-commits] livehttp: don't open new file if current file hasn't been written to

Ilkka Ollakka git at videolan.org
Sat Nov 29 14:43:59 CET 2014


vlc/vlc-2.2 | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Sep 21 11:35:55 2014 +0100| [af482853f4e20db22be4a6942d145d6e2e867a0d] | committer: Ilkka Ollakka

livehttp: don't open new file if current file hasn't been written to

(cherry picked from commit b7d58da0e99ce80896506f6d7f4b59fc8a431b42)
Signed-off-by: Ilkka Ollakka <ileoo at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=af482853f4e20db22be4a6942d145d6e2e867a0d
---

 modules/access_output/livehttp.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/modules/access_output/livehttp.c b/modules/access_output/livehttp.c
index e59f3b4..0563f8d 100644
--- a/modules/access_output/livehttp.c
+++ b/modules/access_output/livehttp.c
@@ -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;
         }
 



More information about the vlc-commits mailing list