summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-10-17 00:30:20 +0200
committerwm4 <wm4@nowhere>2013-10-17 00:32:14 +0200
commitaf0306d48d5410c7f1d12f03a4e791b8144dbecb (patch)
treecc9ecef526fe3357441dcd36c8bf92367fa302df /demux
parent1eda9554d44f167f211208b4b2e4dfeb757dd657 (diff)
parent1b30a0bbf901c04140770d37c58cb63ef676406e (diff)
downloadmpv-af0306d48d5410c7f1d12f03a4e791b8144dbecb.tar.bz2
mpv-af0306d48d5410c7f1d12f03a4e791b8144dbecb.tar.xz
Merge Matroska ordered chapter changes
This adds support for ChapterSegmentEditionUID (pull request #258), and also fixes issue #278 (pull request #292). In fact, this is a straight merge of pr/292, which also contains pr/258.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.h14
-rw-r--r--demux/demux_mkv.c58
2 files changed, 54 insertions, 18 deletions
diff --git a/demux/demux.h b/demux/demux.h
index 1e0546a6d0..0c8f9cb3f8 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -128,14 +128,19 @@ typedef struct demux_chapter
uint64_t demuxer_id; // for mapping to internal demuxer data structures
} demux_chapter_t;
+struct matroska_segment_uid {
+ unsigned char segment[16];
+ uint64_t edition;
+};
+
struct matroska_data {
- unsigned char segment_uid[16];
+ struct matroska_segment_uid uid;
// Ordered chapter information if any
struct matroska_chapter {
uint64_t start;
uint64_t end;
bool has_segment_uid;
- unsigned char segment_uid[16];
+ struct matroska_segment_uid uid;
char *name;
} *ordered_chapters;
int num_ordered_chapters;
@@ -151,7 +156,7 @@ typedef struct demux_attachment
struct demuxer_params {
int matroska_num_wanted_uids;
- unsigned char (*matroska_wanted_uids)[16];
+ struct matroska_segment_uid *matroska_wanted_uids;
int matroska_wanted_segment;
bool *matroska_was_valid;
struct ass_library *ass_library;
@@ -301,4 +306,7 @@ void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value);
char *mp_tags_get_str(struct mp_tags *tags, const char *key);
char *mp_tags_get_bstr(struct mp_tags *tags, bstr key);
+bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
+ struct matroska_segment_uid *b);
+
#endif /* MPLAYER_DEMUXER_H */
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 438697abed..ea5a22f6ee 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -377,25 +377,27 @@ static int demux_mkv_read_info(demuxer_t *demuxer)
}
if (info.n_segment_uid) {
int len = info.segment_uid.len;
- if (len != sizeof(demuxer->matroska_data.segment_uid)) {
+ if (len != sizeof(demuxer->matroska_data.uid.segment)) {
mp_msg(MSGT_DEMUX, MSGL_INFO,
"[mkv] segment uid invalid length %d\n", len);
} else {
- memcpy(demuxer->matroska_data.segment_uid, info.segment_uid.start,
+ memcpy(demuxer->matroska_data.uid.segment, info.segment_uid.start,
len);
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + segment uid");
for (int i = 0; i < len; i++)
mp_msg(MSGT_DEMUX, MSGL_V, " %02x",
- demuxer->matroska_data.segment_uid[i]);
+ demuxer->matroska_data.uid.segment[i]);
mp_msg(MSGT_DEMUX, MSGL_V, "\n");
}
}
if (demuxer->params && demuxer->params->matroska_wanted_uids) {
- unsigned char (*uids)[16] = demuxer->params->matroska_wanted_uids;
if (info.n_segment_uid) {
for (int i = 0; i < demuxer->params->matroska_num_wanted_uids; i++) {
- if (!memcmp(info.segment_uid.start, uids[i], 16))
+ struct matroska_segment_uid *uid = demuxer->params->matroska_wanted_uids + i;
+ if (!memcmp(info.segment_uid.start, uid->segment, 16)) {
+ demuxer->matroska_data.uid.edition = uid->edition;
goto out;
+ }
}
}
mp_tmsg(MSGT_DEMUX, MSGL_INFO,
@@ -783,6 +785,12 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
struct MPOpts *opts = demuxer->opts;
stream_t *s = demuxer->stream;
int wanted_edition = opts->edition_id;
+ uint64_t wanted_edition_uid = demuxer->matroska_data.uid.edition;
+
+ /* A specific edition UID was requested; ignore the user option which is
+ * only applicable to the top-level file. */
+ if (wanted_edition_uid)
+ wanted_edition = -1;
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n");
struct ebml_chapters file_chapters = {};
@@ -791,7 +799,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
&ebml_chapters_desc) < 0)
return -1;
- int selected_edition = 0;
+ int selected_edition = -1;
int num_editions = file_chapters.n_edition_entry;
struct ebml_edition_entry *editions = file_chapters.edition_entry;
if (wanted_edition >= 0 && wanted_edition < num_editions) {
@@ -800,11 +808,24 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
selected_edition);
} else
for (int i = 0; i < num_editions; i++)
- if (editions[i].edition_flag_default) {
+ if (wanted_edition_uid &&
+ editions[i].edition_uid == wanted_edition_uid) {
+ selected_edition = i;
+ break;
+ } else if (editions[i].edition_flag_default) {
selected_edition = i;
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Default edition: %d\n", i);
break;
}
+ if (selected_edition < 0) {
+ if (wanted_edition_uid) {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "[mkv] Unable to find expected edition uid: %"PRIu64"\n",
+ wanted_edition_uid);
+ return -1;
+ } else
+ selected_edition = 0;
+ }
struct matroska_chapter *m_chapters = NULL;
if (editions[selected_edition].edition_flag_ordered) {
int count = editions[selected_edition].n_chapter_atom;
@@ -847,20 +868,20 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer)
if (ca->n_chapter_segment_uid) {
chapter.has_segment_uid = true;
int len = ca->chapter_segment_uid.len;
- if (len != sizeof(chapter.segment_uid))
+ if (len != sizeof(chapter.uid.segment))
mp_msg(MSGT_DEMUX, warn_level,
"[mkv] Chapter segment uid bad length %d\n", len);
- else if (ca->n_chapter_segment_edition_uid) {
- mp_tmsg(MSGT_DEMUX, warn_level, "[mkv] Warning: "
- "unsupported edition recursion in chapter; "
- "will skip on playback!\n");
- } else {
- memcpy(chapter.segment_uid, ca->chapter_segment_uid.start,
+ else {
+ memcpy(chapter.uid.segment, ca->chapter_segment_uid.start,
len);
+ if (ca->n_chapter_segment_edition_uid)
+ chapter.uid.edition = ca->chapter_segment_edition_uid;
+ else
+ chapter.uid.edition = 0;
mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Chapter segment uid ");
for (int n = 0; n < len; n++)
mp_msg(MSGT_DEMUX, MSGL_V, "%02x ",
- chapter.segment_uid[n]);
+ chapter.uid.segment[n]);
mp_msg(MSGT_DEMUX, MSGL_V, "\n");
}
}
@@ -2738,3 +2759,10 @@ const demuxer_desc_t demuxer_desc_matroska = {
.seek = demux_mkv_seek,
.control = demux_mkv_control
};
+
+bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
+ struct matroska_segment_uid *b)
+{
+ return (!memcmp(a->segment, b->segment, 16) &&
+ a->edition == b->edition);
+}