]> git.sesse.net Git - vlc/blobdiff - src/playlist/sort.c
adjustments to playlist API changes
[vlc] / src / playlist / sort.c
index 95abbbea364dc202688805fd980a93684b499f2b..e125b0d112cc639e5b3af8ebdf644526092cf565 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_rand.h>
 #define  VLC_INTERNAL_PLAYLIST_SORT_FUNCTIONS
 #include "vlc_playlist.h"
 #include "playlist_internal.h"
@@ -146,7 +147,7 @@ void playlist_ItemArraySort( unsigned i_items, playlist_item_t **pp_items,
 
         for( i_position = i_items - 1; i_position > 0; i_position-- )
         {
-            i_new = rand() % i_position;
+            i_new = ((unsigned)vlc_mrand48()) % (i_position+1);
             p_temp = pp_items[i_position];
             pp_items[i_position] = pp_items[i_new];
             pp_items[i_new] = p_temp;
@@ -240,8 +241,11 @@ SORTFN( SORT_DESCRIPTION, first, second )
 
 SORTFN( SORT_DURATION, first, second )
 {
-    return input_item_GetDuration( first->p_input ) -
-           input_item_GetDuration( second->p_input );
+    mtime_t time1 = input_item_GetDuration( first->p_input );
+    mtime_t time2 = input_item_GetDuration( second->p_input );
+    int i_ret = time1 > time2 ? 1 :
+                    ( time1 == time2 ? 0 : -1 );
+    return i_ret;
 }
 
 SORTFN( SORT_GENRE, first, second )