Commit af482853 authored by Ilkka Ollakka's avatar Ilkka Ollakka

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

(cherry picked from commit b7d58da0e99ce80896506f6d7f4b59fc8a431b42)
Signed-off-by: default avatarIlkka Ollakka <ileoo@videolan.org>
parent e2399254
...@@ -196,6 +196,7 @@ struct sout_access_out_sys_t ...@@ -196,6 +196,7 @@ struct sout_access_out_sys_t
bool b_splitanywhere; bool b_splitanywhere;
bool b_caching; bool b_caching;
bool b_generate_iv; bool b_generate_iv;
bool b_segment_has_data;
uint8_t aes_ivs[16]; uint8_t aes_ivs[16];
gcry_cipher_hd_t aes_ctx; gcry_cipher_hd_t aes_ctx;
char *key_uri; char *key_uri;
...@@ -241,6 +242,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -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_ratecontrol = var_GetBool( p_access, SOUT_CFG_PREFIX "ratecontrol") ;
p_sys->b_caching = var_GetBool( p_access, SOUT_CFG_PREFIX "caching") ; 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_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(); p_sys->segments_t = vlc_array_new();
...@@ -764,7 +766,7 @@ static void Close( vlc_object_t * p_this ) ...@@ -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 /* Since we are flushing, check the segment change by hand and don't wait
* possible keyframe*/ * 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 ) output_block->i_dts - p_sys->i_opendts) >= p_sys->i_seglenm )
{ {
closeCurrentSegment( p_access, p_sys, false ); 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 ...@@ -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->psz_cursegPath = strdup(segment->psz_filename);
p_sys->i_handle = fd; p_sys->i_handle = fd;
p_sys->i_segment = i_newseg; p_sys->i_segment = i_newseg;
p_sys->b_segment_has_data = false;
return fd; return fd;
} }
/***************************************************************************** /*****************************************************************************
...@@ -918,15 +921,14 @@ static int CheckSegmentChange( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -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 ); msg_Dbg( p_access, "dts offset %"PRId64, p_sys->i_dts_offset );
} }
if( p_sys->i_handle > 0 && if( p_sys->i_handle > 0 && p_sys->b_segment_has_data &&
(( p_buffer->i_dts - p_sys->i_opendts + (( p_buffer->i_length + p_buffer->i_dts - p_sys->i_opendts +
p_buffer->i_length + p_sys->i_dts_offset p_sys->i_dts_offset ) >= p_sys->i_seglenm ) )
) >= p_sys->i_seglenm ) )
{ {
closeCurrentSegment( p_access, p_sys, false ); 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_dts_offset = 0;
p_sys->i_opendts = output ? output->i_dts : p_buffer->i_dts; 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 ) ...@@ -989,8 +991,8 @@ static ssize_t writeSegment( sout_access_out_t *p_access )
} }
p_sys->f_seglen = p_sys->f_seglen =
(float)(output->i_length + p_sys->i_dts_offset + (float)(output->i_length +
output->i_dts - p_sys->i_opendts) / CLOCK_FREQ; output->i_dts - p_sys->i_opendts + p_sys->i_dts_offset) / CLOCK_FREQ;
if ( (size_t)val >= output->i_buffer ) 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 ) ...@@ -1033,6 +1035,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
block_ChainRelease ( p_buffer ); block_ChainRelease ( p_buffer );
return -1; return -1;
} }
p_sys->b_segment_has_data = true;
i_write += writevalue; i_write += writevalue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment