From ff0e8e14c3e9d1003153324d0368735dd84cb4b7 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 6 May 2022 20:27:20 +0200 Subject: avformat/utils: Move avpriv_new_chapter to demux_utils.c It is demuxer-only: Muxers deal only with chapters given to them; they don't create any of their own. Signed-off-by: Andreas Rheinhardt --- libavformat/demux_utils.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'libavformat/demux_utils.c') diff --git a/libavformat/demux_utils.c b/libavformat/demux_utils.c index 10ae887359..cfd6084d54 100644 --- a/libavformat/demux_utils.c +++ b/libavformat/demux_utils.c @@ -32,3 +32,44 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) { ffstream(st)->need_parsing = type; } + +AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, + int64_t start, int64_t end, const char *title) +{ + FFFormatContext *const si = ffformatcontext(s); + AVChapter *chapter = NULL; + int ret; + + if (end != AV_NOPTS_VALUE && start > end) { + av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start); + return NULL; + } + + if (!s->nb_chapters) { + si->chapter_ids_monotonic = 1; + } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { + for (unsigned i = 0; i < s->nb_chapters; i++) + if (s->chapters[i]->id == id) + chapter = s->chapters[i]; + if (!chapter) + si->chapter_ids_monotonic = 0; + } + + if (!chapter) { + chapter = av_mallocz(sizeof(*chapter)); + if (!chapter) + return NULL; + ret = av_dynarray_add_nofree(&s->chapters, &s->nb_chapters, chapter); + if (ret < 0) { + av_free(chapter); + return NULL; + } + } + av_dict_set(&chapter->metadata, "title", title, 0); + chapter->id = id; + chapter->time_base = time_base; + chapter->start = start; + chapter->end = end; + + return chapter; +} -- cgit v1.2.3