Commit 70a5aff3 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

playlist: fix playlist_GetNodeDuration()

- If duration is unknown (-1), treat it as zero for the sum. The error
  of one microsecond per item was usually negligible. But it was
  catastrophic if the total length was actually zero: we would return a
  negative total.
- Do not special case input item node type. Other item types can have
  children, e.g. directories.
- Remove redundant negative test.

(This does not fix the unlikely signed integer overflow if the total
length exceeds INT64_MAX.)
parent 81e06874
......@@ -702,19 +702,14 @@ void playlist_SendAddNotify( playlist_t *p_playlist, playlist_item_t *item )
*/
mtime_t playlist_GetNodeDuration( playlist_item_t* node )
{
mtime_t mt_duration = 0;
mtime_t duration = input_item_GetDuration( node->p_input );
if( duration == -1 )
duration = 0;
if( node->i_children != -1 )
for( int i = 0; i < node->i_children; i++ )
{
input_item_t* p_input = node->pp_children[i]->p_input;
if ( p_input->i_type == ITEM_TYPE_NODE )
mt_duration += playlist_GetNodeDuration( node->pp_children[i] );
else
mt_duration += input_item_GetDuration( p_input );
}
for( int i = 0; i < node->i_children; i++ )
duration += playlist_GetNodeDuration( node->pp_children[i] );
return mt_duration;
return duration;
}
/***************************************************************************
......
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