summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-23 00:54:08 +0100
committerwm4 <wm4@nowhere>2014-01-23 00:54:08 +0100
commitaf5c393d2c0b508b0fbd68f18fb9d0b4f34c61ca (patch)
tree8f02525e99f033840b85432510e6268458887e80 /demux/demux_mkv.c
parent16534bbd8181a09cc56ec58f98a79b465af8a40d (diff)
downloadmpv-af5c393d2c0b508b0fbd68f18fb9d0b4f34c61ca.tar.bz2
mpv-af5c393d2c0b508b0fbd68f18fb9d0b4f34c61ca.tar.xz
demux_mkv: nicer edition output
If there's more than one edition, print the list of editions, including the edition name, whether the edition is selected, whether the edition is default, and the command line option to select the edition. (Similar to stream list.) Move reading the tags to a separate function process_tags(), which is called when all other state is parsed. Otherwise, that tags will be lost if chapters are read after the tags.
Diffstat (limited to 'demux/demux_mkv.c')
-rw-r--r--demux/demux_mkv.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 29765ca3b4..52862cd3b8 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -173,6 +173,8 @@ typedef struct mkv_demuxer {
mkv_track_t **tracks;
int num_tracks;
+ struct ebml_tags *tags;
+
uint64_t tc_scale, cluster_tc;
uint64_t cluster_start;
@@ -783,6 +785,14 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
int selected_edition = -1;
int num_editions = file_chapters.n_edition_entry;
struct ebml_edition_entry *editions = file_chapters.edition_entry;
+ for (int i = 0; i < num_editions; i++) {
+ struct demux_edition new = {
+ .demuxer_id = editions[i].edition_uid,
+ .default_edition = editions[i].edition_flag_default,
+ .metadata = talloc_zero(demuxer, struct mp_tags),
+ };
+ MP_TARRAY_APPEND(demuxer, demuxer->editions, demuxer->num_editions, new);
+ }
if (wanted_edition >= 0 && wanted_edition < num_editions) {
selected_edition = wanted_edition;
MP_VERBOSE(demuxer, "User-specified edition: %d\n",
@@ -894,9 +904,6 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
}
}
}
- if (num_editions > 1)
- MP_INFO(demuxer, "Found %d editions, will play #%d (first is 0).\n",
- num_editions, selected_edition);
demuxer->num_editions = num_editions;
demuxer->edition = selected_edition;
@@ -908,6 +915,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
static int demux_mkv_read_tags(demuxer_t *demuxer)
{
+ struct mkv_demuxer *mkv_d = demuxer->priv;
stream_t *s = demuxer->stream;
struct ebml_parse_ctx parse_ctx = {demuxer->log};
@@ -915,10 +923,22 @@ static int demux_mkv_read_tags(demuxer_t *demuxer)
if (ebml_read_element(s, &parse_ctx, &tags, &ebml_tags_desc) < 0)
return -1;
- for (int i = 0; i < tags.n_tag; i++) {
- struct ebml_tag tag = tags.tag[i];
- if (tag.targets.target_track_uid || tag.targets.target_edition_uid ||
- tag.targets.target_attachment_uid)
+ mkv_d->tags = talloc_memdup(mkv_d, &tags, sizeof(tags));
+ talloc_steal(mkv_d->tags, parse_ctx.talloc_ctx);
+ return 0;
+}
+
+static void process_tags(demuxer_t *demuxer)
+{
+ struct mkv_demuxer *mkv_d = demuxer->priv;
+ struct ebml_tags *tags = mkv_d->tags;
+
+ if (!tags)
+ return;
+
+ for (int i = 0; i < tags->n_tag; i++) {
+ struct ebml_tag tag = tags->tag[i];
+ if (tag.targets.target_track_uid || tag.targets.target_attachment_uid)
continue;
if (tag.targets.target_chapter_uid) {
@@ -927,6 +947,23 @@ static int demux_mkv_read_tags(demuxer_t *demuxer)
tag.simple_tag[j].tag_name,
tag.simple_tag[j].tag_string);
}
+ } else if (tag.targets.target_edition_uid) {
+ struct demux_edition *edition = NULL;
+ for (int n = 0; n < demuxer->num_editions; n++) {
+ if (demuxer->editions[n].demuxer_id ==
+ tag.targets.target_edition_uid)
+ {
+ edition = &demuxer->editions[n];
+ break;
+ }
+ }
+ if (edition) {
+ for (int j = 0; j < tag.n_simple_tag; j++) {
+ mp_tags_set_bstr(edition->metadata,
+ tag.simple_tag[j].tag_name,
+ tag.simple_tag[j].tag_string);
+ }
+ }
} else {
for (int j = 0; j < tag.n_simple_tag; j++) {
demux_info_add_bstr(demuxer, tag.simple_tag[j].tag_name,
@@ -934,9 +971,6 @@ static int demux_mkv_read_tags(demuxer_t *demuxer)
}
}
}
-
- talloc_free(parse_ctx.talloc_ctx);
- return 0;
}
static int demux_mkv_read_attachments(demuxer_t *demuxer)
@@ -1798,6 +1832,7 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check)
MP_VERBOSE(demuxer, "All headers are parsed!\n");
+ process_tags(demuxer);
display_create_tracks(demuxer);
return 0;