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.
This commit is contained in:
wm4 2015-05-19 21:36:52 +02:00
parent 0ed1719e1a
commit 4d2a01b776
1 changed files with 17 additions and 2 deletions

View File

@ -37,8 +37,7 @@
#include "stream/stream.h" #include "stream/stream.h"
#include "demux.h" #include "demux.h"
#include "stheader.h" #include "stheader.h"
#include "cue.h"
#include "audio/format.h"
// Demuxer list // Demuxer list
extern const struct demuxer_desc demuxer_desc_edl; 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); 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, static struct demuxer *open_given_type(struct mpv_global *global,
struct mp_log *log, struct mp_log *log,
const struct demuxer_desc *desc, 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->seekable = true;
in->d_thread->partially_seekable = true; in->d_thread->partially_seekable = true;
} }
demux_init_cuesheet(in->d_thread);
demux_init_cache(demuxer); demux_init_cache(demuxer);
demux_changed(in->d_thread, DEMUX_EVENT_ALL); demux_changed(in->d_thread, DEMUX_EVENT_ALL);
demux_update(demuxer); demux_update(demuxer);