From 4d2a01b776f6f5d7d5e2971115fad0a10824a1b9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 19 May 2015 21:36:52 +0200 Subject: [PATCH] demux: read cue sheets embedded in tags This reads the "CUESHEET" tag, and attempts to parse it as .cue data. If any is found, the cue tracks are added as chapters. This reuses the parser written for demux_cue.c. Fixes #1957. --- demux/demux.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index bb367055cb..b99d0263c9 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -37,8 +37,7 @@ #include "stream/stream.h" #include "demux.h" #include "stheader.h" - -#include "audio/format.h" +#include "cue.h" // Demuxer list extern const struct demuxer_desc demuxer_desc_edl; @@ -902,6 +901,21 @@ static void demux_init_cache(struct demuxer *demuxer) in->stream_base_filename = talloc_steal(demuxer, base); } +static void demux_init_cuesheet(struct demuxer *demuxer) +{ + char *cue = mp_tags_get_str(demuxer->metadata, "cuesheet"); + if (cue && !demuxer->num_chapters) { + struct cue_file *f = mp_parse_cue(bstr0(cue)); + if (f) { + for (int n = 0; n < f->num_tracks; n++) { + struct cue_track *t = &f->tracks[n]; + demuxer_add_chapter(demuxer, t->title, t->start, -1); + } + } + talloc_free(f); + } +} + static struct demuxer *open_given_type(struct mpv_global *global, struct mp_log *log, const struct demuxer_desc *desc, @@ -977,6 +991,7 @@ static struct demuxer *open_given_type(struct mpv_global *global, in->d_thread->seekable = true; in->d_thread->partially_seekable = true; } + demux_init_cuesheet(in->d_thread); demux_init_cache(demuxer); demux_changed(in->d_thread, DEMUX_EVENT_ALL); demux_update(demuxer);