Its really implemented using a compare function, which compares two titles at a time to sort them, and it basically works like this:
- if the two titles are within 10% duration of each other, compare audio streams
- if audio streams match, or the duration was more then 10% apart:
- compare duration, if equal, compare audio streams, if equal, compare filenames
That way in the end we have the longest title (within 10%) with the most audio streams at the top of the list.
If you know how such compare functions work, they want you to return a number expressing the order, typically <0 (less), 0 (equal), >0 (greater)
// in cases where two titles are close in duration but have a different number of audio streams,
// let the number of audio streams trump maximum duration for looking for the more "important" title
if (nPercentDifference < 10)
nCompareValue = pPlaylist2->m_nNumAudioStreams - pPlaylist1->m_nNumAudioStreams;
if (nCompareValue == 0)
{
// sort order is decided first by duration, then number of audio streams, then alphabetic filename order
nCompareValue = nSeconds2 - nSeconds1;
if (nCompareValue == 0)
{
nCompareValue = pPlaylist2->m_nNumAudioStreams - pPlaylist1->m_nNumAudioStreams;
if (nCompareValue == 0)
nCompareValue = pPlaylist1->GetName().Compare(pPlaylist2->GetName());
}
}
return nCompareValue;