Commit 45eeff74 authored by Ilkka Ollakka's avatar Ilkka Ollakka

livehttp: refactor segment change and writing into own functions

parent 82d7c41a
...@@ -201,6 +201,8 @@ struct sout_access_out_sys_t ...@@ -201,6 +201,8 @@ struct sout_access_out_sys_t
static int LoadCryptFile( sout_access_out_t *p_access); static int LoadCryptFile( sout_access_out_t *p_access);
static int CryptSetup( sout_access_out_t *p_access, char *keyfile ); static int CryptSetup( sout_access_out_t *p_access, char *keyfile );
static int CheckSegmentChange( sout_access_out_t *p_access, block_t *p_buffer );
static ssize_t writeSegment( sout_access_out_t *p_access );
/***************************************************************************** /*****************************************************************************
* Open: open the file * Open: open the file
*****************************************************************************/ *****************************************************************************/
...@@ -891,30 +893,21 @@ static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t ...@@ -891,30 +893,21 @@ static ssize_t openNextFile( sout_access_out_t *p_access, sout_access_out_sys_t
p_sys->i_segment = i_newseg; p_sys->i_segment = i_newseg;
return fd; return fd;
} }
/***************************************************************************** /*****************************************************************************
* Write: standard write on a file descriptor. * CheckSegmentChange: Check if segment needs to be closed and new opened
*****************************************************************************/ *****************************************************************************/
static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) static int CheckSegmentChange( sout_access_out_t *p_access, block_t *p_buffer )
{ {
size_t i_write = 0;
sout_access_out_sys_t *p_sys = p_access->p_sys; sout_access_out_sys_t *p_sys = p_access->p_sys;
block_t *p_temp;
while( p_buffer )
{
if ( ( p_sys->b_splitanywhere || ( p_buffer->i_flags & BLOCK_FLAG_HEADER ) ) )
{
bool crypted = false;
block_t *output = p_sys->block_buffer; block_t *output = p_sys->block_buffer;
p_sys->block_buffer = NULL;
if( p_sys->i_handle > 0 && if( p_sys->i_handle > 0 &&
( p_buffer->i_dts - p_sys->i_opendts + ( ( p_buffer->i_dts - p_sys->i_opendts +
p_buffer->i_length * CLOCK_FREQ / INT64_C(1000000) ( p_buffer->i_length * CLOCK_FREQ / INT64_C(1000000) )
) >= 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 ( p_sys->i_handle < 0 )
{ {
...@@ -923,10 +916,20 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -923,10 +916,20 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
if( ( p_sys->i_opendts != VLC_TS_INVALID ) && if( ( p_sys->i_opendts != VLC_TS_INVALID ) &&
( p_buffer->i_dts < p_sys->i_opendts ) ) ( p_buffer->i_dts < p_sys->i_opendts ) )
p_sys->i_opendts = p_buffer->i_dts; p_sys->i_opendts = p_buffer->i_dts;
if ( openNextFile( p_access, p_sys ) < 0 ) if ( openNextFile( p_access, p_sys ) < 0 )
return -1; return VLC_EGENERIC;
} }
return VLC_SUCCESS;
}
static ssize_t writeSegment( sout_access_out_t *p_access )
{
sout_access_out_sys_t *p_sys = p_access->p_sys;
block_t *output = p_sys->block_buffer;
p_sys->block_buffer = NULL;
ssize_t i_write=0;
bool crypted = false;
while( output ) while( output )
{ {
if( p_sys->key_uri && !crypted ) if( p_sys->key_uri && !crypted )
...@@ -964,11 +967,11 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -964,11 +967,11 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
{ {
if ( errno == EINTR ) if ( errno == EINTR )
continue; continue;
block_ChainRelease ( p_buffer );
return -1; return -1;
} }
p_sys->f_seglen = p_sys->f_seglen =
(float)output->i_length / INT64_C(1000000) + (float)(output->i_length / INT64_C(1000000) ) +
(float)(output->i_dts - p_sys->i_opendts) / CLOCK_FREQ; (float)(output->i_dts - p_sys->i_opendts) / CLOCK_FREQ;
if ( (size_t)val >= output->i_buffer ) if ( (size_t)val >= output->i_buffer )
...@@ -985,6 +988,34 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -985,6 +988,34 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
} }
i_write += val; i_write += val;
} }
return i_write;
}
/*****************************************************************************
* Write: standard write on a file descriptor.
*****************************************************************************/
static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
{
size_t i_write = 0;
sout_access_out_sys_t *p_sys = p_access->p_sys;
block_t *p_temp;
while( p_buffer )
{
if( ( p_sys->b_splitanywhere || ( p_buffer->i_flags & BLOCK_FLAG_HEADER ) ) )
{
if( unlikely( CheckSegmentChange( p_access, p_buffer ) != VLC_SUCCESS ) )
{
block_ChainRelease ( p_buffer );
return -1;
}
ssize_t writevalue = writeSegment( p_access );
if( unlikely( writevalue < 0 ) )
{
block_ChainRelease ( p_buffer );
return -1;
}
i_write += writevalue;
} }
p_temp = p_buffer->p_next; p_temp = p_buffer->p_next;
......
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