#define RATECONTROL_TEXT N_("Use muxers rate control mechanism")
#define KEYURI_TEXT N_("AES key URI to place in playlist")
-#define KEYURI_LONGTEXT N_("Location from where client will retrieve the stream decryption key")
#define KEYFILE_TEXT N_("AES key file")
#define KEYFILE_LONGTEXT N_("File containing the 16 bytes encryption key")
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;
p_sys->segments_t = vlc_array_new();
p_sys->stuffing_size = 0;
+ p_sys->i_opendts = VLC_TS_INVALID;
p_sys->psz_indexPath = NULL;
psz_idx = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "index" );
free( segment );
}
+/************************************************************************
+ * segmentAmountNeeded: check that playlist has atleast 3*p_sys->i_seglength of segments
+ * return how many segments are needed for that (max of p_sys->i_segment )
+ ************************************************************************/
+static uint32_t segmentAmountNeeded( sout_access_out_sys_t *p_sys )
+{
+ float duration = .0f;
+ for( unsigned index = 1; index <= vlc_array_count( p_sys->segments_t ) ; index++ )
+ {
+ output_segment_t* segment = vlc_array_item_at_index( p_sys->segments_t, vlc_array_count( p_sys->segments_t ) - index );
+ duration += segment->f_seglength;
+
+ if( duration >= (float)( 3 * p_sys->i_seglen ) )
+ return __MAX(index, p_sys->i_numsegs);
+ }
+ return vlc_array_count( p_sys->segments_t )-1;
+
+}
+
+
+/************************************************************************
+ * 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
************************************************************************/
{
uint32_t i_firstseg;
+ unsigned i_index_offset = 0;
if ( p_sys->i_numsegs == 0 || p_sys->i_segment < p_sys->i_numsegs )
i_firstseg = 1;
else
- i_firstseg = ( p_sys->i_segment - p_sys->i_numsegs ) + 1;
+ {
+ unsigned numsegs = segmentAmountNeeded( p_sys );
+ i_firstseg = ( p_sys->i_segment - numsegs ) + 1;
+ i_index_offset = vlc_array_count( p_sys->segments_t ) - numsegs;
+ }
// First update index
if ( p_sys->psz_indexPath )
for ( uint32_t i = i_firstseg; i <= p_sys->i_segment; i++ )
{
- //scale to 0..numsegs-1
- uint32_t index = i-i_firstseg;
+ //scale to i_index_offset..numsegs + i_index_offset
+ uint32_t index = i - i_firstseg + i_index_offset;
output_segment_t *segment = (output_segment_t *)vlc_array_item_at_index( p_sys->segments_t, index );
if( p_sys->key_uri &&
}
// 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;
}
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;
if ( p_sys->i_handle < 0 )
{
p_sys->i_opendts = output ? output->i_dts : p_buffer->i_dts;
+ //For first segment we can get negative duration otherwise...?
+ if( ( p_sys->i_opendts != VLC_TS_INVALID ) &&
+ ( p_buffer->i_dts < p_sys->i_opendts ) )
+ p_sys->i_opendts = p_buffer->i_dts;
if ( openNextFile( p_access, p_sys ) < 0 )
return -1;
}