[vlc-commits] playlist: fix playlist_GetNodeDuration()

Rémi Denis-Courmont git at videolan.org
Sun May 14 18:37:28 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 14 12:15:56 2017 +0300| [70a5aff3ff09fb5717e312bd86ffde3f57a7dba3] | committer: 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.)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=70a5aff3ff09fb5717e312bd86ffde3f57a7dba3
---

 src/playlist/item.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/playlist/item.c b/src/playlist/item.c
index 6f090f2899..00153fa284 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -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;
 }
 
 /***************************************************************************



More information about the vlc-commits mailing list