1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

demux: always sort chapters

The condition that checked whether the chapters are out of order and
should be sorted was inverted. This likely wasn't noticed in testing,
because even if the chapters are unsorted, if the last two chapters
were sorted, the rest got sorted too.

Instead of doing this silly check, always sort the chapters after
demuxer initialization. Also make sure the sort order is stable in case
chapter start times are the same (original_index check).
This commit is contained in:
wm4 2013-04-12 13:20:37 +02:00
parent a5916f5d1d
commit 6f28c061b4
2 changed files with 7 additions and 8 deletions

View File

@ -948,6 +948,7 @@ static struct demuxer *open_given_type(struct MPOpts *opts,
opts->correct_pts =
demux_control(demuxer, DEMUXER_CTRL_CORRECT_PTS,
NULL) == DEMUXER_CTRL_OK;
demuxer_sort_chapters(demuxer);
return demuxer;
} else {
// demux_mov can return playlist instead of mov
@ -1281,10 +1282,10 @@ static int chapter_compare(const void *p1, const void *p2)
return 1;
else if (c1->start < c2->start)
return -1;
return 0;
return c1->original_index > c2->original_index ? 1 :-1; // never equal
}
static void demuxer_sort_chapters(demuxer_t *demuxer)
void demuxer_sort_chapters(demuxer_t *demuxer)
{
qsort(demuxer->chapters, demuxer->num_chapters,
sizeof(struct demux_chapter), chapter_compare);
@ -1298,6 +1299,8 @@ int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
struct demux_chapter,
demuxer->num_chapters + 32);
demuxer->chapters[demuxer->num_chapters].original_index =
demuxer->num_chapters;
demuxer->chapters[demuxer->num_chapters].start = start;
demuxer->chapters[demuxer->num_chapters].end = end;
demuxer->chapters[demuxer->num_chapters].name = name.len ?
@ -1305,12 +1308,6 @@ int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
talloc_strdup(demuxer->chapters, mp_gtext("unknown"));
demuxer->num_chapters++;
if (demuxer->num_chapters > 1
&& demuxer->chapters[demuxer->num_chapters - 2].start
< demuxer->chapters[demuxer->num_chapters - 1].start)
demuxer_sort_chapters(demuxer);
return 0;
}

View File

@ -183,6 +183,7 @@ typedef struct demuxer_desc {
typedef struct demux_chapter
{
int original_index;
uint64_t start, end;
char *name;
} demux_chapter_t;
@ -394,6 +395,7 @@ int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
uint64_t start, uint64_t end);
int demuxer_seek_chapter(struct demuxer *demuxer, int chapter,
double *seek_pts);
void demuxer_sort_chapters(demuxer_t *demuxer);
/// Get current chapter index if available.
int demuxer_get_current_chapter(struct demuxer *demuxer, double time_now);