+}
+
+
+/**
+ * Wrapper around playlist_cmp_* function
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp( const void *first, const void *second )
+{
+ if( sort_order == -1 )
+ return -1 * sort_function( *(playlist_item_t **)first,
+ *(playlist_item_t **)second );
+ else
+ return sort_function( *(playlist_item_t **)first,
+ *(playlist_item_t **)second );
+}
+
+
+/**
+ * Compare two items according to the title
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_album( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ int i_ret = meta_sort( first, second, vlc_meta_Album, false );
+ /* Items came from the same album: compare the track numbers */
+ if( i_ret == 0 )
+ i_ret = meta_sort( first, second, vlc_meta_TrackNumber, true );
+
+ return i_ret;
+}
+
+
+/**
+ * Compare two items according to the artist
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_artist( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ int i_ret = meta_sort( first, second, vlc_meta_Artist, false );
+ /* Items came from the same artist: compare the albums */
+ if( i_ret == 0 )
+ i_ret = playlist_cmp_album( first, second );
+
+ return i_ret;
+}
+
+
+/**
+ * Compare two items according to the description
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_desc( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return meta_sort( first, second, vlc_meta_Description, false );
+}
+
+
+/**
+ * Compare two items according to the duration
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_duration( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return input_item_GetDuration( first->p_input ) -
+ input_item_GetDuration( second->p_input );
+}
+
+
+/**
+ * Compare two items according to the genre
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_genre( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return meta_sort( first, second, vlc_meta_Genre, false );
+}
+
+
+/**
+ * Compare two items according to the ID
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_id( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return first->i_id - second->i_id;
+}
+
+
+/**
+ * Compare two items according to the rating
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_rating( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return meta_sort( first, second, vlc_meta_Rating, true );
+}
+
+
+/**
+ * Compare two items according to the title
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_title( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ return meta_strcasecmp_title( first, second );
+}
+
+
+/**
+ * Compare two items according to the title, with the nodes first in the list
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_title_nodes_first( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ /* If first is a node but not second */
+ if( first->i_children == -1 && second->i_children >= 0 )
+ return -1;
+ /* If second is a node but not first */
+ else if( first->i_children >= 0 && second->i_children == -1 )
+ return 1;
+ /* Both are nodes or both are not nodes */
+ else
+ return meta_strcasecmp_title( first, second );
+}
+
+
+/**
+ * Compare two item according to the title as a numeric value
+ * @param first: the first item
+ * @param second: the second item
+ * @return -1, 0 or 1 like strcmp
+ */
+static int playlist_cmp_title_num( const playlist_item_t *first,
+ const playlist_item_t *second )
+{
+ int i_ret;
+ char *psz_first = input_item_GetTitleFbName( first->p_input );
+ char *psz_second = input_item_GetTitleFbName( second->p_input );