2011-02-14 07:34:39 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2011-02-14 07:34:39 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-02-14 07:34:39 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2011-02-14 07:34:39 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-02-14 07:34:39 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2011-02-14 07:34:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <inttypes.h>
|
2011-02-23 15:57:08 +00:00
|
|
|
#include <assert.h>
|
2014-10-06 20:33:21 +00:00
|
|
|
#include <string.h>
|
2011-10-04 00:41:18 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2011-02-14 07:34:39 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2012-02-03 07:05:11 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2011-02-14 07:34:39 +00:00
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "demux/demux.h"
|
2015-02-17 22:46:50 +00:00
|
|
|
#include "demux/timeline.h"
|
|
|
|
#include "demux/matroska.h"
|
2016-09-06 18:09:56 +00:00
|
|
|
#include "options/m_config.h"
|
2015-02-17 22:46:50 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2018-05-17 18:58:49 +00:00
|
|
|
#include "misc/thread_tools.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/playlist.h"
|
2011-08-19 02:36:27 +00:00
|
|
|
#include "stream/stream.h"
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
struct tl_ctx {
|
|
|
|
struct mp_log *log;
|
|
|
|
struct mpv_global *global;
|
2016-09-06 18:09:56 +00:00
|
|
|
struct MPOpts *opts;
|
2015-02-20 21:08:02 +00:00
|
|
|
struct timeline *tl;
|
2015-02-17 22:46:50 +00:00
|
|
|
|
|
|
|
struct demuxer *demuxer;
|
|
|
|
|
|
|
|
struct demuxer **sources;
|
|
|
|
int num_sources;
|
|
|
|
|
|
|
|
struct timeline_part *timeline;
|
|
|
|
int num_parts;
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
struct matroska_segment_uid *uids;
|
2015-02-17 22:46:50 +00:00
|
|
|
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 last_end_time; // When the last part ended on the complete timeline.
|
|
|
|
int num_chapters; // Total number of expected chapters.
|
|
|
|
};
|
|
|
|
|
2011-10-04 00:41:18 +00:00
|
|
|
struct find_entry {
|
|
|
|
char *name;
|
|
|
|
int matchlen;
|
2012-02-28 22:01:13 +00:00
|
|
|
off_t size;
|
2011-10-04 00:41:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int cmp_entry(const void *pa, const void *pb)
|
|
|
|
{
|
|
|
|
const struct find_entry *a = pa, *b = pb;
|
|
|
|
// check "similar" filenames first
|
|
|
|
int matchdiff = b->matchlen - a->matchlen;
|
|
|
|
if (matchdiff)
|
|
|
|
return FFSIGN(matchdiff);
|
|
|
|
// check small files first
|
2012-02-28 22:01:13 +00:00
|
|
|
off_t sizediff = a->size - b->size;
|
2011-10-04 00:41:18 +00:00
|
|
|
if (sizediff)
|
|
|
|
return FFSIGN(sizediff);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-23 15:57:08 +00:00
|
|
|
|
2014-10-06 20:33:21 +00:00
|
|
|
static bool test_matroska_ext(const char *filename)
|
|
|
|
{
|
|
|
|
static const char *const exts[] = {".mkv", ".mka", ".mks", ".mk3d", NULL};
|
|
|
|
for (int n = 0; exts[n]; n++) {
|
|
|
|
const char *suffix = exts[n];
|
|
|
|
int offset = strlen(filename) - strlen(suffix);
|
|
|
|
// name must end with suffix
|
|
|
|
if (offset > 0 && strcasecmp(filename + offset, suffix) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **find_files(const char *original_file)
|
2011-02-23 15:57:08 +00:00
|
|
|
{
|
|
|
|
void *tmpmem = talloc_new(NULL);
|
|
|
|
char *basename = mp_basename(original_file);
|
|
|
|
struct bstr directory = mp_dirname(original_file);
|
|
|
|
char **results = talloc_size(NULL, 0);
|
|
|
|
char *dir_zero = bstrdup0(tmpmem, directory);
|
|
|
|
DIR *dp = opendir(dir_zero);
|
|
|
|
if (!dp) {
|
|
|
|
talloc_free(tmpmem);
|
|
|
|
return results;
|
|
|
|
}
|
2011-10-04 00:41:18 +00:00
|
|
|
struct find_entry *entries = NULL;
|
2011-02-23 15:57:08 +00:00
|
|
|
struct dirent *ep;
|
|
|
|
int num_results = 0;
|
|
|
|
while ((ep = readdir(dp))) {
|
2014-10-06 20:33:21 +00:00
|
|
|
if (!test_matroska_ext(ep->d_name))
|
2011-02-23 15:57:08 +00:00
|
|
|
continue;
|
|
|
|
// don't list the original name
|
|
|
|
if (!strcmp(ep->d_name, basename))
|
|
|
|
continue;
|
|
|
|
|
2015-05-09 13:26:47 +00:00
|
|
|
char *name = mp_path_join_bstr(results, directory, bstr0(ep->d_name));
|
2011-02-23 15:57:08 +00:00
|
|
|
char *s1 = ep->d_name;
|
|
|
|
char *s2 = basename;
|
|
|
|
int matchlen = 0;
|
|
|
|
while (*s1 && *s1++ == *s2++)
|
|
|
|
matchlen++;
|
2011-10-04 00:41:18 +00:00
|
|
|
// be a bit more fuzzy about matching the filename
|
|
|
|
matchlen = (matchlen + 3) / 5;
|
|
|
|
|
|
|
|
struct stat statbuf;
|
|
|
|
if (stat(name, &statbuf) != 0)
|
|
|
|
continue;
|
2012-02-28 22:01:13 +00:00
|
|
|
off_t size = statbuf.st_size;
|
2011-10-04 00:41:18 +00:00
|
|
|
|
2012-08-19 15:58:58 +00:00
|
|
|
entries = talloc_realloc(tmpmem, entries, struct find_entry,
|
2011-10-04 00:41:18 +00:00
|
|
|
num_results + 1);
|
2012-02-28 22:01:13 +00:00
|
|
|
entries[num_results] = (struct find_entry) { name, matchlen, size };
|
2011-02-23 15:57:08 +00:00
|
|
|
num_results++;
|
|
|
|
}
|
|
|
|
closedir(dp);
|
2011-10-04 00:41:18 +00:00
|
|
|
// NOTE: maybe should make it compare pointers instead
|
2012-10-31 23:24:08 +00:00
|
|
|
if (entries)
|
|
|
|
qsort(entries, num_results, sizeof(struct find_entry), cmp_entry);
|
2011-02-23 15:57:08 +00:00
|
|
|
results = talloc_realloc(NULL, results, char *, num_results);
|
2011-10-04 00:41:18 +00:00
|
|
|
for (int i = 0; i < num_results; i++) {
|
|
|
|
results[i] = entries[i].name;
|
2011-02-23 15:57:08 +00:00
|
|
|
}
|
|
|
|
talloc_free(tmpmem);
|
|
|
|
return results;
|
|
|
|
}
|
2011-02-14 07:34:39 +00:00
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
static bool has_source_request(struct tl_ctx *ctx,
|
2013-10-08 04:33:42 +00:00
|
|
|
struct matroska_segment_uid *new_uid)
|
|
|
|
{
|
2015-02-25 12:26:43 +00:00
|
|
|
for (int i = 0; i < ctx->num_sources; ++i) {
|
|
|
|
if (demux_matroska_uid_cmp(&ctx->uids[i], new_uid))
|
2013-10-08 04:33:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-14 00:49:07 +00:00
|
|
|
// segment = get Nth segment of a multi-segment file
|
2015-02-25 12:26:43 +00:00
|
|
|
static bool check_file_seg(struct tl_ctx *ctx, char *filename, int segment)
|
2013-04-14 00:49:07 +00:00
|
|
|
{
|
|
|
|
bool was_valid = false;
|
|
|
|
struct demuxer_params params = {
|
2015-02-20 20:21:14 +00:00
|
|
|
.force_format = "mkv",
|
2015-02-25 12:26:32 +00:00
|
|
|
.matroska_num_wanted_uids = ctx->num_sources,
|
2015-02-25 12:26:43 +00:00
|
|
|
.matroska_wanted_uids = ctx->uids,
|
2013-04-14 00:49:07 +00:00
|
|
|
.matroska_wanted_segment = segment,
|
|
|
|
.matroska_was_valid = &was_valid,
|
2016-10-22 15:17:04 +00:00
|
|
|
.disable_timeline = true,
|
stream, demux: redo origin policy thing
mpv has a very weak and very annoying policy that determines whether a
playlist should be used or not. For example, if you play a remote
playlist, you usually don't want it to be able to read local filesystem
entries. (Although for a media player the impact is small I guess.)
It's weak and annoying as in that it does not prevent certain cases
which could be interpreted as bad in some cases, such as allowing
playlists on the local filesystem to reference remote URLs. It probably
barely makes sense, but we just want to exclude some other "definitely
not a good idea" things, all while playlists generally just work, so
whatever.
The policy is:
- from the command line anything is played
- local playlists can reference anything except "unsafe" streams
("unsafe" means special stream inputs like libavfilter graphs)
- remote playlists can reference only remote URLs
- things like "memory://" and archives are "transparent" to this
This commit does... something. It replaces the weird stream flags with a
slightly clearer "origin" value, which is now consequently passed down
and used everywhere. It fixes some deviations from the described policy.
I wanted to force archives to reference only content within them, but
this would probably have been more complicated (or required different
abstractions), and I'm too lazy to figure it out, so archives are now
"transparent" (playlists within archives behave the same outside).
There may be a lot of bugs in this.
This is unfortunately a very noisy commit because:
- every stream open call now needs to pass the origin
- so does every demuxer open call (=> params param. gets mandatory)
- most stream were changed to provide the "origin" value
- the origin value needed to be passed along in a lot of places
- I was too lazy to split the commit
Fixes: #7274
2019-12-20 08:41:42 +00:00
|
|
|
.stream_flags = ctx->tl->stream_origin,
|
2013-04-14 00:49:07 +00:00
|
|
|
};
|
2015-02-20 21:08:02 +00:00
|
|
|
struct mp_cancel *cancel = ctx->tl->cancel;
|
|
|
|
if (mp_cancel_test(cancel))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
struct demuxer *d = demux_open_url(filename, ¶ms, cancel, ctx->global);
|
2015-02-20 20:56:55 +00:00
|
|
|
if (!d)
|
2013-04-14 00:49:07 +00:00
|
|
|
return false;
|
2013-10-05 07:01:49 +00:00
|
|
|
|
2015-02-17 22:55:45 +00:00
|
|
|
struct matroska_data *m = &d->matroska_data;
|
2013-10-05 07:01:49 +00:00
|
|
|
|
2015-02-25 12:26:32 +00:00
|
|
|
for (int i = 1; i < ctx->num_sources; i++) {
|
2015-02-25 12:26:43 +00:00
|
|
|
struct matroska_segment_uid *uid = &ctx->uids[i];
|
2015-02-25 12:26:32 +00:00
|
|
|
if (ctx->sources[i])
|
2015-02-17 22:55:45 +00:00
|
|
|
continue;
|
|
|
|
/* Accept the source if the segment uid matches and the edition
|
2016-10-22 15:55:31 +00:00
|
|
|
* either matches or isn't specified. */
|
2015-02-17 22:55:45 +00:00
|
|
|
if (!memcmp(uid->segment, m->uid.segment, 16) &&
|
|
|
|
(!uid->edition || uid->edition == m->uid.edition))
|
|
|
|
{
|
|
|
|
MP_INFO(ctx, "Match for source %d: %s\n", i, d->filename);
|
2013-10-08 04:33:42 +00:00
|
|
|
|
2016-10-22 15:55:31 +00:00
|
|
|
if (!uid->edition) {
|
|
|
|
m->uid.edition = 0;
|
|
|
|
} else {
|
|
|
|
for (int j = 0; j < m->num_ordered_chapters; j++) {
|
|
|
|
struct matroska_chapter *c = m->ordered_chapters + j;
|
2013-10-05 07:01:49 +00:00
|
|
|
|
2016-10-22 15:55:31 +00:00
|
|
|
if (!c->has_segment_uid)
|
|
|
|
continue;
|
2013-10-05 07:01:49 +00:00
|
|
|
|
2016-10-22 15:55:31 +00:00
|
|
|
if (has_source_request(ctx, &c->uid))
|
|
|
|
continue;
|
2013-10-19 20:58:02 +00:00
|
|
|
|
2016-10-22 15:55:31 +00:00
|
|
|
/* Set the requested segment. */
|
|
|
|
MP_TARRAY_GROW(NULL, ctx->uids, ctx->num_sources);
|
|
|
|
ctx->uids[ctx->num_sources] = c->uid;
|
2015-02-17 22:55:45 +00:00
|
|
|
|
2016-10-22 15:55:31 +00:00
|
|
|
/* Add a new source slot. */
|
|
|
|
MP_TARRAY_APPEND(NULL, ctx->sources, ctx->num_sources, NULL);
|
|
|
|
}
|
2013-04-14 00:49:07 +00:00
|
|
|
}
|
2015-02-17 22:55:45 +00:00
|
|
|
|
2015-02-25 12:26:32 +00:00
|
|
|
ctx->sources[i] = d;
|
2015-02-17 22:55:45 +00:00
|
|
|
return true;
|
2013-04-14 00:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 22:55:45 +00:00
|
|
|
|
2018-05-19 12:41:06 +00:00
|
|
|
demux_free(d);
|
2013-04-14 00:49:07 +00:00
|
|
|
return was_valid;
|
|
|
|
}
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
static void check_file(struct tl_ctx *ctx, char *filename, int first)
|
2013-04-14 00:49:07 +00:00
|
|
|
{
|
|
|
|
for (int segment = first; ; segment++) {
|
2015-02-25 12:26:43 +00:00
|
|
|
if (!check_file_seg(ctx, filename, segment))
|
2013-04-14 00:49:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 12:26:32 +00:00
|
|
|
static bool missing(struct tl_ctx *ctx)
|
2013-04-14 00:49:07 +00:00
|
|
|
{
|
2015-02-25 12:26:32 +00:00
|
|
|
for (int i = 0; i < ctx->num_sources; i++) {
|
|
|
|
if (!ctx->sources[i])
|
2013-04-14 00:49:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
static void find_ordered_chapter_sources(struct tl_ctx *ctx)
|
2011-02-14 07:34:39 +00:00
|
|
|
{
|
2016-09-06 18:09:56 +00:00
|
|
|
struct MPOpts *opts = ctx->opts;
|
2013-12-14 20:52:37 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
2011-02-14 07:34:39 +00:00
|
|
|
int num_filenames = 0;
|
|
|
|
char **filenames = NULL;
|
2015-02-25 12:26:32 +00:00
|
|
|
if (ctx->num_sources > 1) {
|
2015-02-17 22:46:50 +00:00
|
|
|
char *main_filename = ctx->demuxer->filename;
|
|
|
|
MP_INFO(ctx, "This file references data from other sources.\n");
|
2013-12-14 20:52:37 +00:00
|
|
|
if (opts->ordered_chapters_files && opts->ordered_chapters_files[0]) {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_INFO(ctx, "Loading references from '%s'.\n",
|
2014-12-26 18:58:50 +00:00
|
|
|
opts->ordered_chapters_files);
|
2013-12-14 20:52:37 +00:00
|
|
|
struct playlist *pl =
|
2018-05-18 20:19:10 +00:00
|
|
|
playlist_parse_file(opts->ordered_chapters_files,
|
|
|
|
ctx->tl->cancel, ctx->global);
|
2013-12-14 20:52:37 +00:00
|
|
|
talloc_steal(tmp, pl);
|
2019-12-28 20:12:02 +00:00
|
|
|
for (int n = 0; n < pl->num_entries; n++) {
|
|
|
|
MP_TARRAY_APPEND(tmp, filenames, num_filenames,
|
|
|
|
pl->entries[n]->filename);
|
|
|
|
}
|
2024-08-22 17:23:10 +00:00
|
|
|
} else if (!ctx->demuxer->stream->is_local_fs) {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_WARN(ctx, "Playback source is not a "
|
2014-12-26 18:58:50 +00:00
|
|
|
"normal disk file. Will not search for related files.\n");
|
2011-02-14 07:34:39 +00:00
|
|
|
} else {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_INFO(ctx, "Will scan other files in the "
|
2014-12-26 18:58:50 +00:00
|
|
|
"same directory to find referenced sources.\n");
|
2014-10-06 20:33:21 +00:00
|
|
|
filenames = find_files(main_filename);
|
2015-01-26 18:16:27 +00:00
|
|
|
num_filenames = MP_TALLOC_AVAIL(filenames);
|
2013-12-14 20:52:37 +00:00
|
|
|
talloc_steal(tmp, filenames);
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
2013-04-14 00:49:07 +00:00
|
|
|
// Possibly get further segments appended to the first segment
|
2015-02-25 12:26:43 +00:00
|
|
|
check_file(ctx, main_filename, 1);
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 07:01:49 +00:00
|
|
|
int old_source_count;
|
|
|
|
do {
|
2015-02-25 12:26:32 +00:00
|
|
|
old_source_count = ctx->num_sources;
|
2013-10-05 07:01:49 +00:00
|
|
|
for (int i = 0; i < num_filenames; i++) {
|
2015-02-25 12:26:32 +00:00
|
|
|
if (!missing(ctx))
|
2013-10-05 07:01:49 +00:00
|
|
|
break;
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_VERBOSE(ctx, "Checking file %s\n", filenames[i]);
|
2015-02-25 12:26:43 +00:00
|
|
|
check_file(ctx, filenames[i], 0);
|
2013-10-05 07:01:49 +00:00
|
|
|
}
|
2015-02-25 12:26:32 +00:00
|
|
|
} while (old_source_count != ctx->num_sources);
|
2013-04-14 00:49:07 +00:00
|
|
|
|
2015-02-25 12:26:32 +00:00
|
|
|
if (missing(ctx)) {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_ERR(ctx, "Failed to find ordered chapter part!\n");
|
2013-04-14 00:49:07 +00:00
|
|
|
int j = 1;
|
2015-02-25 12:26:32 +00:00
|
|
|
for (int i = 1; i < ctx->num_sources; i++) {
|
|
|
|
if (ctx->sources[i]) {
|
|
|
|
ctx->sources[j] = ctx->sources[i];
|
2015-02-25 12:26:43 +00:00
|
|
|
ctx->uids[j] = ctx->uids[i];
|
2011-02-14 07:34:39 +00:00
|
|
|
j++;
|
|
|
|
}
|
2014-12-26 18:58:50 +00:00
|
|
|
}
|
2015-02-25 12:26:32 +00:00
|
|
|
ctx->num_sources = j;
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
2013-12-14 20:52:37 +00:00
|
|
|
|
2018-07-26 01:16:59 +00:00
|
|
|
// Copy attachments from referenced sources so fonts are loaded for sub
|
|
|
|
// rendering.
|
|
|
|
for (int i = 1; i < ctx->num_sources; i++) {
|
|
|
|
for (int j = 0; j < ctx->sources[i]->num_attachments; j++) {
|
|
|
|
struct demux_attachment *att = &ctx->sources[i]->attachments[j];
|
|
|
|
demuxer_add_attachment(ctx->demuxer, att->name, att->type,
|
|
|
|
att->data, att->data_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-14 20:52:37 +00:00
|
|
|
talloc_free(tmp);
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
|
|
|
|
2015-01-25 23:31:04 +00:00
|
|
|
struct inner_timeline_info {
|
|
|
|
uint64_t skip; // Amount of time to skip.
|
|
|
|
uint64_t limit; // How much time is expected for the parent chapter.
|
|
|
|
};
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
static int64_t add_timeline_part(struct tl_ctx *ctx,
|
2013-10-14 22:51:03 +00:00
|
|
|
struct demuxer *source,
|
2015-01-25 23:31:04 +00:00
|
|
|
uint64_t start)
|
2013-10-07 01:42:30 +00:00
|
|
|
{
|
2014-12-26 18:58:50 +00:00
|
|
|
/* Merge directly adjacent parts. We allow for a configurable fudge factor
|
|
|
|
* because of files which specify chapter end times that are one frame too
|
|
|
|
* early; we don't want to try seeking over a one frame gap. */
|
2015-01-25 23:31:04 +00:00
|
|
|
int64_t join_diff = start - ctx->last_end_time;
|
|
|
|
if (ctx->num_parts == 0
|
2016-09-06 18:09:56 +00:00
|
|
|
|| FFABS(join_diff) > ctx->opts->chapter_merge_threshold * 1e6
|
2015-02-17 22:46:50 +00:00
|
|
|
|| source != ctx->timeline[ctx->num_parts - 1].source)
|
2014-12-26 18:58:50 +00:00
|
|
|
{
|
2013-10-07 01:42:30 +00:00
|
|
|
struct timeline_part new = {
|
2015-01-25 23:31:04 +00:00
|
|
|
.start = ctx->start_time / 1e9,
|
2013-10-07 01:42:30 +00:00
|
|
|
.source_start = start / 1e9,
|
|
|
|
.source = source,
|
|
|
|
};
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_TARRAY_APPEND(NULL, ctx->timeline, ctx->num_parts, new);
|
2015-01-25 23:31:04 +00:00
|
|
|
} else if (ctx->num_parts > 0 && join_diff) {
|
2014-12-26 18:58:50 +00:00
|
|
|
// Chapter was merged at an inexact boundary; adjust timestamps to match.
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_VERBOSE(ctx, "Merging timeline part %d with offset %g ms.\n",
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->num_parts, join_diff / 1e6);
|
|
|
|
ctx->start_time += join_diff;
|
2013-10-14 22:51:03 +00:00
|
|
|
return join_diff;
|
2013-10-07 01:42:30 +00:00
|
|
|
}
|
2013-10-14 22:51:03 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-10-07 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
static void build_timeline_loop(struct tl_ctx *ctx,
|
2014-11-02 16:20:04 +00:00
|
|
|
struct demux_chapter *chapters,
|
2015-01-25 23:31:04 +00:00
|
|
|
struct inner_timeline_info *info,
|
|
|
|
int current_source)
|
2013-10-07 01:42:30 +00:00
|
|
|
{
|
2013-10-07 03:22:19 +00:00
|
|
|
uint64_t local_starttime = 0;
|
2015-01-25 23:31:04 +00:00
|
|
|
struct demuxer *source = ctx->sources[current_source];
|
2013-10-07 01:42:30 +00:00
|
|
|
struct matroska_data *m = &source->matroska_data;
|
|
|
|
|
|
|
|
for (int i = 0; i < m->num_ordered_chapters; i++) {
|
|
|
|
struct matroska_chapter *c = m->ordered_chapters + i;
|
|
|
|
uint64_t chapter_length = c->end - c->start;
|
|
|
|
|
|
|
|
if (!c->has_segment_uid)
|
2014-12-26 18:58:50 +00:00
|
|
|
c->uid = m->uid;
|
2013-10-07 01:42:30 +00:00
|
|
|
|
2013-10-07 03:22:19 +00:00
|
|
|
local_starttime += chapter_length;
|
|
|
|
|
2014-12-26 18:58:50 +00:00
|
|
|
// If we're before the start time for the chapter, skip to the next one.
|
2015-01-25 23:31:04 +00:00
|
|
|
if (local_starttime <= info->skip)
|
2013-10-07 03:22:19 +00:00
|
|
|
continue;
|
|
|
|
|
2013-10-07 01:42:30 +00:00
|
|
|
/* Look for the source for this chapter. */
|
2015-01-25 23:31:04 +00:00
|
|
|
for (int j = 0; j < ctx->num_sources; j++) {
|
|
|
|
struct demuxer *linked_source = ctx->sources[j];
|
2013-10-07 01:42:30 +00:00
|
|
|
struct matroska_data *linked_m = &linked_source->matroska_data;
|
|
|
|
|
|
|
|
if (!demux_matroska_uid_cmp(&c->uid, &linked_m->uid))
|
|
|
|
continue;
|
|
|
|
|
2015-01-25 23:31:04 +00:00
|
|
|
if (!info->limit) {
|
2015-01-26 00:35:36 +00:00
|
|
|
if (i >= ctx->num_chapters)
|
|
|
|
break; // malformed files can cause this to happen.
|
|
|
|
|
2015-01-25 23:31:04 +00:00
|
|
|
chapters[i].pts = ctx->start_time / 1e9;
|
2015-08-12 09:10:45 +00:00
|
|
|
chapters[i].metadata = talloc_zero(chapters, struct mp_tags);
|
|
|
|
mp_tags_set_str(chapters[i].metadata, "title", c->name);
|
2013-10-07 03:22:19 +00:00
|
|
|
}
|
2013-10-07 01:42:30 +00:00
|
|
|
|
2013-10-07 03:22:19 +00:00
|
|
|
/* If we're the source or it's a non-ordered edition reference,
|
|
|
|
* just add a timeline part from the source. */
|
2016-10-22 15:55:31 +00:00
|
|
|
if (current_source == j || !linked_m->uid.edition) {
|
2017-06-20 11:57:58 +00:00
|
|
|
uint64_t source_full_length = linked_source->duration * 1e9;
|
2013-10-14 23:28:47 +00:00
|
|
|
uint64_t source_length = source_full_length - c->start;
|
|
|
|
int64_t join_diff = 0;
|
|
|
|
|
|
|
|
/* If the chapter starts after the end of a source, there's
|
|
|
|
* nothing we can get from it. Instead, mark the entire chapter
|
|
|
|
* as missing and make the chapter length 0. */
|
|
|
|
if (source_full_length <= c->start) {
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->missing_time += chapter_length;
|
2013-10-14 23:28:47 +00:00
|
|
|
chapter_length = 0;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the source length starting at the chapter start is
|
|
|
|
* shorter than the chapter it is supposed to fill, add the gap
|
|
|
|
* to missing_time. Also, modify the chapter length to be what
|
|
|
|
* we actually have to avoid playing off the end of the file
|
|
|
|
* and not switching to the next source. */
|
|
|
|
if (source_length < chapter_length) {
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->missing_time += chapter_length - source_length;
|
2013-10-14 23:28:47 +00:00
|
|
|
chapter_length = source_length;
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
join_diff = add_timeline_part(ctx, linked_source, c->start);
|
2013-10-14 22:51:03 +00:00
|
|
|
|
|
|
|
/* If we merged two chapters into a single part due to them
|
|
|
|
* being off by a few frames, we need to change the limit to
|
|
|
|
* avoid chopping the end of the intended chapter (the adding
|
|
|
|
* frames case) or showing extra content (the removing frames
|
|
|
|
* case). Also update chapter_length to incorporate the extra
|
|
|
|
* time. */
|
2015-01-25 23:31:04 +00:00
|
|
|
if (info->limit) {
|
|
|
|
info->limit += join_diff;
|
2013-10-14 22:51:03 +00:00
|
|
|
chapter_length += join_diff;
|
|
|
|
}
|
2013-10-07 03:22:19 +00:00
|
|
|
} else {
|
2014-12-26 18:58:50 +00:00
|
|
|
/* We have an ordered edition as the source. Since this
|
|
|
|
* can jump around all over the place, we need to build up the
|
|
|
|
* timeline parts for each of its chapters, but not add them as
|
|
|
|
* chapters. */
|
2015-01-25 23:31:04 +00:00
|
|
|
struct inner_timeline_info new_info = {
|
|
|
|
.skip = c->start,
|
|
|
|
.limit = c->end
|
|
|
|
};
|
2015-02-17 22:46:50 +00:00
|
|
|
build_timeline_loop(ctx, chapters, &new_info, j);
|
2014-12-26 18:58:50 +00:00
|
|
|
// Already handled by the loop call.
|
2013-10-07 03:22:19 +00:00
|
|
|
chapter_length = 0;
|
|
|
|
}
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->last_end_time = c->end;
|
2013-10-07 01:42:30 +00:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->missing_time += chapter_length;
|
2013-10-16 01:16:05 +00:00
|
|
|
chapter_length = 0;
|
2013-10-07 01:42:30 +00:00
|
|
|
found:;
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->start_time += chapter_length;
|
2013-10-07 03:22:19 +00:00
|
|
|
/* If we're after the limit on this chapter, stop here. */
|
2015-01-25 23:31:04 +00:00
|
|
|
if (info->limit && local_starttime >= info->limit) {
|
2013-10-07 03:22:19 +00:00
|
|
|
/* Back up the global start time by the overflow. */
|
2015-01-25 23:31:04 +00:00
|
|
|
ctx->start_time -= local_starttime - info->limit;
|
2013-10-07 03:22:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-10-07 01:42:30 +00:00
|
|
|
}
|
2013-10-07 03:22:19 +00:00
|
|
|
|
|
|
|
/* If we stopped before the limit, add up the missing time. */
|
2015-01-25 23:31:04 +00:00
|
|
|
if (local_starttime < info->limit)
|
|
|
|
ctx->missing_time += info->limit - local_starttime;
|
2013-10-07 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.
Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.
Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.
One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-01-11 12:52:29 +00:00
|
|
|
static void check_track_compatibility(struct tl_ctx *tl, struct demuxer *mainsrc)
|
2015-02-04 22:02:27 +00:00
|
|
|
{
|
2015-02-17 22:46:50 +00:00
|
|
|
for (int n = 0; n < tl->num_parts; n++) {
|
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.
Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.
Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.
One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-01-11 12:52:29 +00:00
|
|
|
struct timeline_part *p = &tl->timeline[n];
|
2015-02-04 22:02:27 +00:00
|
|
|
if (p->source == mainsrc)
|
|
|
|
continue;
|
|
|
|
|
demux: remove weird tripple-buffering for the sh_stream list
The demuxer infrastructure was originally single-threaded. To make it
suitable for multithreading (specifically, demuxing and decoding on
separate threads), some sort of tripple-buffering was introduced. There
are separate "struct demuxer" allocations. The demuxer thread sets the
state on d_thread. If anything changes, the state is copied to d_buffer
(the copy is protected by a lock), and the decoder thread is notified.
Then the decoder thread copies the state from d_buffer to d_user (again
while holding a lock). This avoids the need for locking in the
demuxer/decoder code itself (only demux.c needs an internal, "invisible"
lock.)
Remove the streams/num_streams fields from this tripple-buffering
schema. Move them to the internal struct, and protect them with the
internal lock. Use accessors for read access outside of demux.c.
Other than replacing all field accesses with accessors, this separates
allocating and adding sh_streams. This is needed to avoid race
conditions. Before this change, this was awkwardly handled by first
initializing the sh_stream, and then sending a stream change event. Now
the stream is allocated, then initialized, and then declared as
immutable and added (at which point it becomes visible to the decoder
thread immediately).
This change is useful for PR #2626. And eventually, we should probably
get entirely of the tripple buffering, and this makes a nice first step.
2015-12-23 20:44:53 +00:00
|
|
|
int num_source_streams = demux_get_num_stream(p->source);
|
|
|
|
for (int i = 0; i < num_source_streams; i++) {
|
|
|
|
struct sh_stream *s = demux_get_stream(p->source, i);
|
2015-02-04 22:02:27 +00:00
|
|
|
if (s->attached_picture)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!demuxer_stream_by_demuxer_id(mainsrc, s->type, s->demuxer_id)) {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_WARN(tl, "Source %s has %s stream with TID=%d, which "
|
|
|
|
"is not present in the ordered chapters main "
|
|
|
|
"file. This is a broken file. "
|
|
|
|
"The additional stream is ignored.\n",
|
|
|
|
p->source->filename, stream_type_name(s->type),
|
|
|
|
s->demuxer_id);
|
2015-02-04 22:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
demux: remove weird tripple-buffering for the sh_stream list
The demuxer infrastructure was originally single-threaded. To make it
suitable for multithreading (specifically, demuxing and decoding on
separate threads), some sort of tripple-buffering was introduced. There
are separate "struct demuxer" allocations. The demuxer thread sets the
state on d_thread. If anything changes, the state is copied to d_buffer
(the copy is protected by a lock), and the decoder thread is notified.
Then the decoder thread copies the state from d_buffer to d_user (again
while holding a lock). This avoids the need for locking in the
demuxer/decoder code itself (only demux.c needs an internal, "invisible"
lock.)
Remove the streams/num_streams fields from this tripple-buffering
schema. Move them to the internal struct, and protect them with the
internal lock. Use accessors for read access outside of demux.c.
Other than replacing all field accesses with accessors, this separates
allocating and adding sh_streams. This is needed to avoid race
conditions. Before this change, this was awkwardly handled by first
initializing the sh_stream, and then sending a stream change event. Now
the stream is allocated, then initialized, and then declared as
immutable and added (at which point it becomes visible to the decoder
thread immediately).
This change is useful for PR #2626. And eventually, we should probably
get entirely of the tripple buffering, and this makes a nice first step.
2015-12-23 20:44:53 +00:00
|
|
|
int num_main_streams = demux_get_num_stream(mainsrc);
|
|
|
|
for (int i = 0; i < num_main_streams; i++) {
|
|
|
|
struct sh_stream *m = demux_get_stream(mainsrc, i);
|
2015-02-04 22:02:27 +00:00
|
|
|
if (m->attached_picture)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
struct sh_stream *s =
|
|
|
|
demuxer_stream_by_demuxer_id(p->source, m->type, m->demuxer_id);
|
|
|
|
if (s) {
|
|
|
|
// There are actually many more things that in theory have to
|
|
|
|
// match (though mpv's implementation doesn't care).
|
2016-01-12 22:48:19 +00:00
|
|
|
if (strcmp(s->codec->codec, m->codec->codec) != 0)
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_WARN(tl, "Timeline segments have mismatching codec.\n");
|
2020-08-15 23:00:29 +00:00
|
|
|
if (s->codec->extradata_size != m->codec->extradata_size ||
|
|
|
|
(s->codec->extradata_size &&
|
|
|
|
memcmp(s->codec->extradata, m->codec->extradata,
|
|
|
|
s->codec->extradata_size) != 0))
|
|
|
|
MP_WARN(tl, "Timeline segments have mismatching codec info.\n");
|
2015-02-04 22:02:27 +00:00
|
|
|
} else {
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_WARN(tl, "Source %s lacks %s stream with TID=%d, which "
|
|
|
|
"is present in the ordered chapters main "
|
|
|
|
"file. This is a broken file.\n",
|
|
|
|
p->source->filename, stream_type_name(m->type),
|
|
|
|
m->demuxer_id);
|
2015-02-04 22:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
void build_ordered_chapter_timeline(struct timeline *tl)
|
2011-02-14 07:34:39 +00:00
|
|
|
{
|
2015-02-17 22:46:50 +00:00
|
|
|
struct demuxer *demuxer = tl->demuxer;
|
2011-02-14 07:34:39 +00:00
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
if (!demuxer->matroska_data.ordered_chapters)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct tl_ctx *ctx = talloc_ptrtype(tl, ctx);
|
|
|
|
*ctx = (struct tl_ctx){
|
|
|
|
.log = tl->log,
|
|
|
|
.global = tl->global,
|
2015-02-20 21:08:02 +00:00
|
|
|
.tl = tl,
|
2015-02-17 22:46:50 +00:00
|
|
|
.demuxer = demuxer,
|
2019-11-28 23:16:52 +00:00
|
|
|
.opts = mp_get_config_group(ctx, tl->global, &mp_opt_root),
|
2015-02-17 22:46:50 +00:00
|
|
|
};
|
|
|
|
|
2016-12-04 22:15:31 +00:00
|
|
|
if (!ctx->opts->ordered_chapters || !demuxer->access_references) {
|
2016-09-06 18:09:56 +00:00
|
|
|
MP_INFO(demuxer, "File uses ordered chapters, but "
|
|
|
|
"you have disabled support for them. Ignoring.\n");
|
|
|
|
talloc_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_INFO(ctx, "File uses ordered chapters, will build edit timeline.\n");
|
2011-02-14 07:34:39 +00:00
|
|
|
|
|
|
|
struct matroska_data *m = &demuxer->matroska_data;
|
|
|
|
|
|
|
|
// +1 because sources/uid_map[0] is original file even if all chapters
|
|
|
|
// actually use other sources and need separate entries
|
2015-02-25 12:26:32 +00:00
|
|
|
ctx->sources = talloc_zero_array(tl, struct demuxer *,
|
|
|
|
m->num_ordered_chapters + 1);
|
|
|
|
ctx->sources[0] = demuxer;
|
|
|
|
ctx->num_sources = 1;
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
ctx->uids = talloc_zero_array(NULL, struct matroska_segment_uid,
|
|
|
|
m->num_ordered_chapters + 1);
|
|
|
|
ctx->uids[0] = m->uid;
|
|
|
|
ctx->uids[0].edition = 0;
|
2011-02-14 07:34:39 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < m->num_ordered_chapters; i++) {
|
|
|
|
struct matroska_chapter *c = m->ordered_chapters + i;
|
2013-10-07 01:42:30 +00:00
|
|
|
/* 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 (!c->has_segment_uid || demux_matroska_uid_cmp(&c->uid, &m->uid))
|
|
|
|
continue;
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
if (has_source_request(ctx, &c->uid))
|
2013-10-08 04:33:42 +00:00
|
|
|
continue;
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
ctx->uids[ctx->num_sources] = c->uid;
|
2015-02-25 12:26:32 +00:00
|
|
|
ctx->sources[ctx->num_sources] = NULL;
|
|
|
|
ctx->num_sources++;
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 12:26:43 +00:00
|
|
|
find_ordered_chapter_sources(ctx);
|
|
|
|
|
|
|
|
talloc_free(ctx->uids);
|
|
|
|
ctx->uids = NULL;
|
2011-02-14 07:34:39 +00:00
|
|
|
|
2014-11-02 16:20:04 +00:00
|
|
|
struct demux_chapter *chapters =
|
2015-02-17 22:46:50 +00:00
|
|
|
talloc_zero_array(tl, struct demux_chapter, m->num_ordered_chapters);
|
|
|
|
|
|
|
|
ctx->timeline = talloc_array_ptrtype(tl, ctx->timeline, 0);
|
|
|
|
ctx->num_chapters = m->num_ordered_chapters;
|
|
|
|
|
2015-01-25 23:31:04 +00:00
|
|
|
struct inner_timeline_info info = {
|
|
|
|
.skip = 0,
|
|
|
|
.limit = 0
|
|
|
|
};
|
2015-02-17 22:46:50 +00:00
|
|
|
build_timeline_loop(ctx, chapters, &info, 0);
|
2011-02-14 07:34:39 +00:00
|
|
|
|
2015-08-12 09:10:45 +00:00
|
|
|
// Fuck everything: filter out all "unset" chapters.
|
2014-12-26 18:42:03 +00:00
|
|
|
for (int n = m->num_ordered_chapters - 1; n >= 0; n--) {
|
2015-08-12 09:10:45 +00:00
|
|
|
if (!chapters[n].metadata)
|
2014-12-26 18:42:03 +00:00
|
|
|
MP_TARRAY_REMOVE_AT(chapters, m->num_ordered_chapters, n);
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:46:50 +00:00
|
|
|
if (!ctx->num_parts) {
|
2015-01-12 12:20:56 +00:00
|
|
|
// None of the parts come from the file itself???
|
|
|
|
// Broken file, but we need at least 1 valid timeline part - add a dummy.
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_WARN(ctx, "Ordered chapters file with no parts?\n");
|
2015-01-12 12:20:56 +00:00
|
|
|
struct timeline_part new = {
|
|
|
|
.source = demuxer,
|
|
|
|
};
|
2015-02-17 22:46:50 +00:00
|
|
|
MP_TARRAY_APPEND(NULL, ctx->timeline, ctx->num_parts, new);
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|
|
|
|
|
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.
Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.
Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.
One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-01-11 12:52:29 +00:00
|
|
|
for (int n = 0; n < ctx->num_parts; n++) {
|
|
|
|
ctx->timeline[n].end = n == ctx->num_parts - 1
|
|
|
|
? ctx->start_time / 1e9
|
|
|
|
: ctx->timeline[n + 1].start;
|
2013-10-07 01:42:30 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 23:29:42 +00:00
|
|
|
/* Ignore anything less than a millisecond when reporting missing time. If
|
|
|
|
* users really notice less than a millisecond missing, maybe this can be
|
|
|
|
* revisited. */
|
2015-02-17 22:46:50 +00:00
|
|
|
if (ctx->missing_time >= 1e6) {
|
|
|
|
MP_ERR(ctx, "There are %.3f seconds missing from the timeline!\n",
|
|
|
|
ctx->missing_time / 1e9);
|
2014-12-26 18:58:50 +00:00
|
|
|
}
|
2015-02-17 22:46:50 +00:00
|
|
|
|
2015-02-04 20:20:41 +00:00
|
|
|
// With Matroska, the "master" file usually dictates track layout etc.,
|
|
|
|
// except maybe with playlist-like files.
|
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.
Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.
Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.
One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-01-11 12:52:29 +00:00
|
|
|
struct demuxer *track_layout = ctx->timeline[0].source;
|
|
|
|
for (int n = 0; n < ctx->num_parts; n++) {
|
|
|
|
if (ctx->timeline[n].source == ctx->demuxer) {
|
|
|
|
track_layout = ctx->demuxer;
|
2015-02-04 20:20:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 22:02:27 +00:00
|
|
|
|
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more
proper data structure. This probably gets rid of a few minor bugs along
the way, caused by the awkward nonsensical sharing/duplication of some
fields.
Another change (because I'm touching everything related to timeline
anyway) is that I'm removing the special semantics for parts[num_parts].
This is now strictly out of bounds, and instead of using the start time
of the next/beyond-last part, there is an end time field now.
Unfortunately, this also requires touching the code for cue and mkv
ordered chapters. From some superficial testing, they still seem to
mostly work.
One observable change is that the "no_chapters" header is per-stream
now, which is arguably more correct, and getting the old behavior would
require adding code to handle it as special-case, so just adjust
ytdl_hook.lua to the new behavior.
2019-01-11 12:52:29 +00:00
|
|
|
check_track_compatibility(ctx, track_layout);
|
|
|
|
|
|
|
|
tl->sources = ctx->sources;
|
|
|
|
tl->num_sources = ctx->num_sources;
|
|
|
|
|
|
|
|
struct timeline_par *par = talloc_ptrtype(tl, par);
|
|
|
|
*par = (struct timeline_par){
|
|
|
|
.parts = ctx->timeline,
|
|
|
|
.num_parts = ctx->num_parts,
|
|
|
|
.track_layout = track_layout,
|
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(tl, tl->pars, tl->num_pars, par);
|
|
|
|
tl->chapters = chapters;
|
|
|
|
tl->num_chapters = m->num_ordered_chapters;
|
|
|
|
tl->meta = track_layout;
|
2019-01-11 13:10:41 +00:00
|
|
|
tl->format = "mkv_oc";
|
2011-02-14 07:34:39 +00:00
|
|
|
}
|