mirror of
https://github.com/mpv-player/mpv
synced 2025-03-04 05:07:51 +00:00
matroska: select the edition using the requested edition uid
This commit is contained in:
parent
069a2d047d
commit
2fe2be4df3
@ -785,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 = {};
|
||||
@ -793,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) {
|
||||
@ -802,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;
|
||||
|
@ -175,7 +175,10 @@ static bool check_file_seg(struct MPContext *mpctx, struct demuxer **sources,
|
||||
struct matroska_segment_uid *uid = uids + i;
|
||||
if (sources[i])
|
||||
continue;
|
||||
if (!memcmp(uid->segment, m->uid.segment, 16)) {
|
||||
/* Accept the source if the segment uid matches and the edition
|
||||
* either matches or isn't specified. */
|
||||
if (!memcmp(uid->segment, m->uid.segment, 16) &&
|
||||
(!uid->edition || uid->edition == m->uid.edition)) {
|
||||
mp_msg(MSGT_CPLAYER, MSGL_INFO, "Match for source %d: %s\n",
|
||||
i, d->filename);
|
||||
|
||||
@ -294,7 +297,11 @@ void build_ordered_chapter_timeline(struct MPContext *mpctx)
|
||||
memcpy(c->uid.segment, m->uid.segment, 16);
|
||||
|
||||
for (int j = 0; j < num_sources; j++)
|
||||
if (!memcmp(c->uid.segment, uids[j].segment, 16))
|
||||
/* If there isn't a segment uid, we are the source. If the segment
|
||||
* uid is our segment uid and the edition matches. We can't accept
|
||||
* the "don't care" edition value of 0 since the user may have
|
||||
* requested a non-default edition. */
|
||||
if (demux_matroska_uid_cmp(&c->uid, uids + j))
|
||||
goto found1;
|
||||
memcpy(uids + num_sources, &c->uid, sizeof(c->uid));
|
||||
sources[num_sources] = NULL;
|
||||
@ -321,7 +328,7 @@ void build_ordered_chapter_timeline(struct MPContext *mpctx)
|
||||
|
||||
int j;
|
||||
for (j = 0; j < num_sources; j++) {
|
||||
if (!memcmp(c->uid.segment, uids[j].segment, 16))
|
||||
if (demux_matroska_uid_cmp(&c->uid, uids + j))
|
||||
goto found2;
|
||||
}
|
||||
missing_time += c->end - c->start;
|
||||
|
Loading…
Reference in New Issue
Block a user