Commit d00d1822 authored by Ilkka Ollakka's avatar Ilkka Ollakka

livehttp: try to comply draft 11 section 6.2.2 for how long to keep segments...

livehttp: try to comply draft 11 section 6.2.2 for how long to keep segments around in sliding window
parent 90193b09
......@@ -166,6 +166,7 @@ typedef struct output_segment
char *psz_uri;
char *psz_key_uri;
char *psz_duration;
float f_seglength;
uint32_t i_segment_number;
uint8_t aes_ivs[16];
} output_segment_t;
......@@ -488,6 +489,28 @@ static void destroySegment( output_segment_t *segment )
free( segment );
}
/************************************************************************
* isFirstItemRemovable: Check for draft 11 section 6.2.2
* check that the first item has been around outside playlist
* segment->f_seglength + p_sys->i_seglen before it is removed.
************************************************************************/
static bool isFirstItemRemovable( sout_access_out_sys_t *p_sys, uint32_t i_firstseg, uint32_t i_index_offset )
{
float duration = .0f;
/* Check that segment has been out of playlist for seglenght + p_sys->i_seglen amount
* We check this by calculating duration of the items that replaced first item in playlist
*/
for(int index=0; index < i_index_offset; index++ )
{
output_segment_t *segment = vlc_array_item_at_index( p_sys->segments_t, p_sys->i_segment - i_firstseg + index );
duration += segment->f_seglength;
}
output_segment_t *first = vlc_array_item_at_index( p_sys->segments_t, 0 );
return duration >= (first->f_seglength + (float)p_sys->i_seglen);
}
/************************************************************************
* updateIndexAndDel: If necessary, update index file & delete old segments
************************************************************************/
......@@ -607,15 +630,22 @@ static int updateIndexAndDel( sout_access_out_t *p_access, sout_access_out_sys_t
}
// Then take care of deletion
while( p_sys->b_delsegs && p_sys->i_numsegs && ( (vlc_array_count( p_sys->segments_t ) ) > p_sys->i_numsegs ) )
// Try to follow pantos draft 11 section 6.2.2
while( p_sys->b_delsegs && p_sys->i_numsegs &&
isFirstItemRemovable( p_sys, i_firstseg, i_index_offset )
)
{
output_segment_t *segment = vlc_array_item_at_index( p_sys->segments_t, 0 );
msg_Dbg( p_access, "Removing segment number %d", segment->i_segment_number );
vlc_array_remove( p_sys->segments_t, 0 );
if ( segment->psz_filename )
{
vlc_unlink( segment->psz_filename );
}
destroySegment( segment );
i_index_offset -=1;
}
......@@ -656,6 +686,7 @@ static void closeCurrentSegment( sout_access_out_t *p_access, sout_access_out_sy
msg_Err( p_access, "Couldn't set duration on closed segment");
return;
}
segment->f_seglength = p_sys->f_seglen;
segment->i_segment_number = p_sys->i_segment;
......
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