diff options
author | wm4 <wm4@nowhere> | 2014-11-02 17:20:04 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-11-02 17:29:41 +0100 |
commit | 969757baa0af99d905a9b8c99f0c92efa4e0fb33 (patch) | |
tree | 2db51b2e3bc89dce550fc1c9fbf31c7471a41fce /demux | |
parent | 1cebd16350229d2ab1441f5061079ce9240fb22f (diff) |
player: always use demux_chapter
Instead of defining a separate data structure in the core.
For some odd reason, demux_chapter exported the chapter time in
nano-seconds. Change that to the usual timestamps (rename the field
to make any code relying on this to fail compilation), and also remove
the unused chapter end time.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux.c | 20 | ||||
-rw-r--r-- | demux/demux.h | 8 | ||||
-rw-r--r-- | demux/demux_disc.c | 2 | ||||
-rw-r--r-- | demux/demux_lavf.c | 6 | ||||
-rw-r--r-- | demux/demux_mkv.c | 2 |
5 files changed, 23 insertions, 15 deletions
diff --git a/demux/demux.c b/demux/demux.c index 48b1babe35..d4206228d5 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1076,9 +1076,9 @@ static int chapter_compare(const void *p1, const void *p2) struct demux_chapter *c1 = (void *)p1; struct demux_chapter *c2 = (void *)p2; - if (c1->start > c2->start) + if (c1->pts > c2->pts) return 1; - else if (c1->start < c2->start) + else if (c1->pts < c2->pts) return -1; return c1->original_index > c2->original_index ? 1 :-1; // never equal } @@ -1090,12 +1090,11 @@ static void demuxer_sort_chapters(demuxer_t *demuxer) } int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name, - uint64_t start, uint64_t end, uint64_t demuxer_id) + double pts, uint64_t demuxer_id) { struct demux_chapter new = { .original_index = demuxer->num_chapters, - .start = start, - .end = end, + .pts = pts, .name = name.len ? bstrdup0(demuxer, name) : NULL, .metadata = talloc_zero(demuxer, struct mp_tags), .demuxer_id = demuxer_id, @@ -1309,3 +1308,14 @@ void demux_unpause(demuxer_t *demuxer) pthread_cond_signal(&in->wakeup); pthread_mutex_unlock(&in->lock); } + +struct demux_chapter *demux_copy_chapter_data(struct demux_chapter *c, int num) +{ + struct demux_chapter *new = talloc_array(NULL, struct demux_chapter, num); + for (int n = 0; n < num; n++) { + new[n] = c[n]; + new[n].name = talloc_strdup(new, new[n].name); + new[n].metadata = mp_tags_dup(new, new[n].metadata); + } + return new; +} diff --git a/demux/demux.h b/demux/demux.h index 2d7e95ed5e..7892718027 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -123,7 +123,7 @@ typedef struct demuxer_desc { typedef struct demux_chapter { int original_index; - uint64_t start, end; + double pts; char *name; struct mp_tags *metadata; uint64_t demuxer_id; // for mapping to internal demuxer data structures @@ -268,8 +268,8 @@ void demuxer_help(struct mp_log *log); int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name, struct bstr type, struct bstr data); -int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name, - uint64_t start, uint64_t end, uint64_t demuxer_id); +int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name, + double pts, uint64_t demuxer_id); double demuxer_get_time_length(struct demuxer *demuxer); @@ -284,6 +284,8 @@ void demux_update(demuxer_t *demuxer); struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d, enum stream_type t, int id); +struct demux_chapter *demux_copy_chapter_data(struct demux_chapter *c, int num); + bool demux_matroska_uid_cmp(struct matroska_segment_uid *a, struct matroska_segment_uid *b); diff --git a/demux/demux_disc.c b/demux/demux_disc.c index d0054079c1..e92198f0af 100644 --- a/demux/demux_disc.c +++ b/demux/demux_disc.c @@ -275,7 +275,7 @@ static void add_stream_chapters(struct demuxer *demuxer) double p = n; if (stream_control(demuxer->stream, STREAM_CTRL_GET_CHAPTER_TIME, &p) < 1) continue; - demuxer_add_chapter(demuxer, bstr0(""), p * 1e9, 0, 0); + demuxer_add_chapter(demuxer, bstr0(""), p, 0); } } diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index e6b62adb12..8cfcfc449f 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -769,13 +769,9 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) for (i = 0; i < avfc->nb_chapters; i++) { AVChapter *c = avfc->chapters[i]; - uint64_t start = av_rescale_q(c->start, c->time_base, - (AVRational){1, 1000000000}); - uint64_t end = av_rescale_q(c->end, c->time_base, - (AVRational){1, 1000000000}); t = av_dict_get(c->metadata, "title", NULL, 0); int index = demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(""), - start, end, i); + c->start * av_q2d(c->time_base), i); mp_tags_copy_from_av_dictionary(demuxer->chapters[index].metadata, c->metadata); } diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 97db573e20..72020ce123 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -879,7 +879,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) BSTR_P(name)); if (idx == selected_edition) { - demuxer_add_chapter(demuxer, name, chapter.start, chapter.end, + demuxer_add_chapter(demuxer, name, chapter.start / 1e9, ca->chapter_uid); } if (m_chapters) { |