1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

demux_mkv_timeline: move uids array to context too

Again removes some indirections and extra arguments.

Also replace some memcpy/memmoves with assignments. (Assignments became
possible only later, when reference UIDs were turned into a struct.)
This commit is contained in:
wm4 2015-02-25 13:26:43 +01:00
parent 2bf0a5f2bc
commit 02bd54c0ac

View File

@ -57,6 +57,7 @@ struct tl_ctx {
struct timeline_part *timeline; struct timeline_part *timeline;
int num_parts; int num_parts;
struct matroska_segment_uid *uids;
uint64_t start_time; // When the next part should start on the complete timeline. uint64_t start_time; // When the next part should start on the complete timeline.
uint64_t missing_time; // Total missing time so far. uint64_t missing_time; // Total missing time so far.
uint64_t last_end_time; // When the last part ended on the complete timeline. uint64_t last_end_time; // When the last part ended on the complete timeline.
@ -149,27 +150,24 @@ static char **find_files(const char *original_file)
return results; return results;
} }
static bool has_source_request(struct matroska_segment_uid *uids, static bool has_source_request(struct tl_ctx *ctx,
int num_sources,
struct matroska_segment_uid *new_uid) struct matroska_segment_uid *new_uid)
{ {
for (int i = 0; i < num_sources; ++i) { for (int i = 0; i < ctx->num_sources; ++i) {
if (demux_matroska_uid_cmp(uids + i, new_uid)) if (demux_matroska_uid_cmp(&ctx->uids[i], new_uid))
return true; return true;
} }
return false; return false;
} }
// segment = get Nth segment of a multi-segment file // segment = get Nth segment of a multi-segment file
static bool check_file_seg(struct tl_ctx *ctx, struct matroska_segment_uid **uids, static bool check_file_seg(struct tl_ctx *ctx, char *filename, int segment)
char *filename, int segment)
{ {
bool was_valid = false; bool was_valid = false;
struct demuxer_params params = { struct demuxer_params params = {
.force_format = "mkv", .force_format = "mkv",
.matroska_num_wanted_uids = ctx->num_sources, .matroska_num_wanted_uids = ctx->num_sources,
.matroska_wanted_uids = *uids, .matroska_wanted_uids = ctx->uids,
.matroska_wanted_segment = segment, .matroska_wanted_segment = segment,
.matroska_was_valid = &was_valid, .matroska_was_valid = &was_valid,
.disable_cache = true, .disable_cache = true,
@ -185,7 +183,7 @@ static bool check_file_seg(struct tl_ctx *ctx, struct matroska_segment_uid **uid
struct matroska_data *m = &d->matroska_data; struct matroska_data *m = &d->matroska_data;
for (int i = 1; i < ctx->num_sources; i++) { for (int i = 1; i < ctx->num_sources; i++) {
struct matroska_segment_uid *uid = *uids + i; struct matroska_segment_uid *uid = &ctx->uids[i];
if (ctx->sources[i]) if (ctx->sources[i])
continue; continue;
/* Accept the source if the segment uid matches and the edition /* Accept the source if the segment uid matches and the edition
@ -201,12 +199,12 @@ static bool check_file_seg(struct tl_ctx *ctx, struct matroska_segment_uid **uid
if (!c->has_segment_uid) if (!c->has_segment_uid)
continue; continue;
if (has_source_request(*uids, ctx->num_sources, &c->uid)) if (has_source_request(ctx, &c->uid))
continue; continue;
/* Set the requested segment. */ /* Set the requested segment. */
MP_TARRAY_GROW(NULL, *uids, ctx->num_sources); MP_TARRAY_GROW(NULL, ctx->uids, ctx->num_sources);
(*uids)[ctx->num_sources] = c->uid; ctx->uids[ctx->num_sources] = c->uid;
/* Add a new source slot. */ /* Add a new source slot. */
MP_TARRAY_APPEND(NULL, ctx->sources, ctx->num_sources, NULL); MP_TARRAY_APPEND(NULL, ctx->sources, ctx->num_sources, NULL);
@ -230,11 +228,10 @@ static bool check_file_seg(struct tl_ctx *ctx, struct matroska_segment_uid **uid
return was_valid; return was_valid;
} }
static void check_file(struct tl_ctx *ctx, struct matroska_segment_uid **uids, static void check_file(struct tl_ctx *ctx, char *filename, int first)
char *filename, int first)
{ {
for (int segment = first; ; segment++) { for (int segment = first; ; segment++) {
if (!check_file_seg(ctx, uids, filename, segment)) if (!check_file_seg(ctx, filename, segment))
break; break;
} }
} }
@ -248,8 +245,7 @@ static bool missing(struct tl_ctx *ctx)
return false; return false;
} }
static void find_ordered_chapter_sources(struct tl_ctx *ctx, static void find_ordered_chapter_sources(struct tl_ctx *ctx)
struct matroska_segment_uid **uids)
{ {
struct MPOpts *opts = ctx->global->opts; struct MPOpts *opts = ctx->global->opts;
void *tmp = talloc_new(NULL); void *tmp = talloc_new(NULL);
@ -277,7 +273,7 @@ static void find_ordered_chapter_sources(struct tl_ctx *ctx,
talloc_steal(tmp, filenames); talloc_steal(tmp, filenames);
} }
// Possibly get further segments appended to the first segment // Possibly get further segments appended to the first segment
check_file(ctx, uids, main_filename, 1); check_file(ctx, main_filename, 1);
} }
int old_source_count; int old_source_count;
@ -287,7 +283,7 @@ static void find_ordered_chapter_sources(struct tl_ctx *ctx,
if (!missing(ctx)) if (!missing(ctx))
break; break;
MP_VERBOSE(ctx, "Checking file %s\n", filenames[i]); MP_VERBOSE(ctx, "Checking file %s\n", filenames[i]);
check_file(ctx, uids, filenames[i], 0); check_file(ctx, filenames[i], 0);
} }
} while (old_source_count != ctx->num_sources); } while (old_source_count != ctx->num_sources);
@ -296,10 +292,8 @@ static void find_ordered_chapter_sources(struct tl_ctx *ctx,
int j = 1; int j = 1;
for (int i = 1; i < ctx->num_sources; i++) { for (int i = 1; i < ctx->num_sources; i++) {
if (ctx->sources[i]) { if (ctx->sources[i]) {
struct matroska_segment_uid *source_uid = *uids + i;
struct matroska_segment_uid *target_uid = *uids + j;
ctx->sources[j] = ctx->sources[i]; ctx->sources[j] = ctx->sources[i];
memmove(target_uid, source_uid, sizeof(*source_uid)); ctx->uids[j] = ctx->uids[i];
j++; j++;
} }
} }
@ -533,11 +527,10 @@ void build_ordered_chapter_timeline(struct timeline *tl)
ctx->sources[0] = demuxer; ctx->sources[0] = demuxer;
ctx->num_sources = 1; ctx->num_sources = 1;
struct matroska_segment_uid *uids = ctx->uids = talloc_zero_array(NULL, struct matroska_segment_uid,
talloc_zero_array(NULL, struct matroska_segment_uid,
m->num_ordered_chapters + 1); m->num_ordered_chapters + 1);
memcpy(uids[0].segment, m->uid.segment, 16); ctx->uids[0] = m->uid;
uids[0].edition = 0; ctx->uids[0].edition = 0;
for (int i = 0; i < m->num_ordered_chapters; i++) { for (int i = 0; i < m->num_ordered_chapters; i++) {
struct matroska_chapter *c = m->ordered_chapters + i; struct matroska_chapter *c = m->ordered_chapters + i;
@ -548,16 +541,18 @@ void build_ordered_chapter_timeline(struct timeline *tl)
if (!c->has_segment_uid || demux_matroska_uid_cmp(&c->uid, &m->uid)) if (!c->has_segment_uid || demux_matroska_uid_cmp(&c->uid, &m->uid))
continue; continue;
if (has_source_request(uids, ctx->num_sources, &c->uid)) if (has_source_request(ctx, &c->uid))
continue; continue;
memcpy(uids + ctx->num_sources, &c->uid, sizeof(c->uid)); ctx->uids[ctx->num_sources] = c->uid;
ctx->sources[ctx->num_sources] = NULL; ctx->sources[ctx->num_sources] = NULL;
ctx->num_sources++; ctx->num_sources++;
} }
find_ordered_chapter_sources(ctx, &uids); find_ordered_chapter_sources(ctx);
talloc_free(uids);
talloc_free(ctx->uids);
ctx->uids = NULL;
struct demux_chapter *chapters = struct demux_chapter *chapters =
talloc_zero_array(tl, struct demux_chapter, m->num_ordered_chapters); talloc_zero_array(tl, struct demux_chapter, m->num_ordered_chapters);