demux: remove redundant demux_chapter.name field

Instead, force everyone to use the metadata struct and set a "title"
field. This is only a problem for the timeline producers, which set up
chapters manually. (They do this because a timeline is a separate
struct.)

This fixes the behavior of the chapter-metadata property, which never
returned a "title" property for e.g. ordered chapters.
This commit is contained in:
wm4 2015-08-12 11:10:45 +02:00
parent c7329e5118
commit 828881816a
7 changed files with 13 additions and 22 deletions

View File

@ -1271,7 +1271,6 @@ int demuxer_add_chapter(demuxer_t *demuxer, char *name,
struct demux_chapter new = {
.original_index = demuxer->num_chapters,
.pts = pts,
.name = talloc_strdup(demuxer, name),
.metadata = talloc_zero(demuxer, struct mp_tags),
.demuxer_id = demuxer_id,
};
@ -1511,9 +1510,7 @@ struct demux_chapter *demux_copy_chapter_data(struct demux_chapter *c, int num)
struct demux_chapter *new = talloc_array(NULL, struct demux_chapter, num);
for (int n = 0; n < num; n++) {
new[n] = c[n];
new[n].name = talloc_strdup(new, new[n].name);
if (new[n].metadata)
new[n].metadata = mp_tags_dup(new, new[n].metadata);
new[n].metadata = mp_tags_dup(new, new[n].metadata);
}
return new;
}

View File

@ -113,7 +113,6 @@ typedef struct demux_chapter
{
int original_index;
double pts;
char *name;
struct mp_tags *metadata;
uint64_t demuxer_id; // for mapping to internal demuxer data structures
} demux_chapter_t;

View File

@ -224,9 +224,10 @@ static void build_timeline(struct timeline *tl)
};
chapters[i] = (struct demux_chapter) {
.pts = timeline[i].start,
// might want to include other metadata here
.name = talloc_strdup(chapters, tracks[i].title),
.metadata = talloc_zero(tl, struct mp_tags),
};
// might want to include other metadata here
mp_tags_set_str(chapters[i].metadata, "title", tracks[i].title);
starttime += duration;
}

View File

@ -167,7 +167,7 @@ static void copy_chapters(struct demux_chapter **chapters, int *num_chapters,
if (time >= start && time <= start + len) {
struct demux_chapter ch = {
.pts = dest_offset + time - start,
.name = talloc_strdup(*chapters, src->chapters[n].name),
.metadata = mp_tags_dup(*chapters, src->chapters[n].metadata),
};
MP_TARRAY_APPEND(NULL, *chapters, *num_chapters, ch);
}
@ -238,8 +238,9 @@ static void build_timeline(struct timeline *tl, struct tl_parts *parts)
// Add a chapter between each file.
struct demux_chapter ch = {
.pts = starttime,
.name = talloc_strdup(tl, part->filename),
.metadata = talloc_zero(tl, struct mp_tags),
};
mp_tags_set_str(ch.metadata, "title", part->filename);
MP_TARRAY_APPEND(tl, tl->chapters, tl->num_chapters, ch);
// Also copy the source file's chapters for the relevant parts

View File

@ -372,7 +372,8 @@ static void build_timeline_loop(struct tl_ctx *ctx,
break; // malformed files can cause this to happen.
chapters[i].pts = ctx->start_time / 1e9;
chapters[i].name = talloc_strdup(chapters, c->name);
chapters[i].metadata = talloc_zero(chapters, struct mp_tags);
mp_tags_set_str(chapters[i].metadata, "title", c->name);
}
/* If we're the source or it's a non-ordered edition reference,
@ -556,9 +557,6 @@ void build_ordered_chapter_timeline(struct timeline *tl)
struct demux_chapter *chapters =
talloc_zero_array(tl, struct demux_chapter, m->num_ordered_chapters);
// Stupid hack, because fuck everything.
for (int n = 0; n < m->num_ordered_chapters; n++)
chapters[n].pts = -1;
ctx->timeline = talloc_array_ptrtype(tl, ctx->timeline, 0);
ctx->num_chapters = m->num_ordered_chapters;
@ -569,9 +567,9 @@ void build_ordered_chapter_timeline(struct timeline *tl)
};
build_timeline_loop(ctx, chapters, &info, 0);
// Fuck everything (2): filter out all "unset" chapters.
// Fuck everything: filter out all "unset" chapters.
for (int n = m->num_ordered_chapters - 1; n >= 0; n--) {
if (chapters[n].pts == -1)
if (!chapters[n].metadata)
MP_TARRAY_REMOVE_AT(chapters, m->num_ordered_chapters, n);
}

View File

@ -805,7 +805,6 @@ static int get_chapter_entry(int item, int action, void *arg, void *ctx)
};
int r = m_property_read_sub(props, action, arg);
talloc_free(name);
return r;
}
@ -1178,11 +1177,8 @@ static int mp_property_chapter_metadata(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
int chapter = get_current_chapter(mpctx);
if (chapter < 0 || chapter >= mpctx->num_chapters)
if (chapter < 0)
return M_PROPERTY_UNAVAILABLE;
if (!mpctx->chapters[chapter].metadata)
return M_PROPERTY_UNAVAILABLE;
return tag_property(action, arg, mpctx->chapters[chapter].metadata);
}

View File

@ -474,7 +474,6 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
dname = talloc_asprintf(NULL, "(%d) of %d", chapter + 1,
chapter_count);
}
talloc_free(name);
return dname;
}
@ -483,7 +482,7 @@ char *chapter_name(struct MPContext *mpctx, int chapter)
{
if (chapter < 0 || chapter >= mpctx->num_chapters)
return NULL;
return talloc_strdup(NULL, mpctx->chapters[chapter].name);
return mp_tags_get_str(mpctx->chapters[chapter].metadata, "title");
}
// returns the start of the chapter in seconds (NOPTS if unavailable)