2009-05-08 23:51:13 +02:00
|
|
|
/*
|
2015-04-13 09:36:54 +02:00
|
|
|
* This file is part of mpv.
|
2009-05-08 23:51:13 +02:00
|
|
|
*
|
demux_mf, stream_mf: change license to LGPL
cehoyos, who did not agree to the relicensing, added bcb5c78ce3. If
there was copyright, we consider it gone, because the table changed. It
does not map file extension to a FourCC anymore, and codecs.conf is
gone. The new mapping is a libavcodec codec name (happens to be the same
as the file extension).
The same applies to commits 60ecafec, b749836b, 5b3e3be1. None of these
authors were contacted. These were before the code was replaced with a
table (in d0326807). The parts outside of demux_mf.c were removed a long
time ago. Like in the previous comment, we don't think any copyright
applies at least to the new code (at least after the FourCC removal).
iive authored 0aa37a0d, which is probably still left in some form, and
makes demux_mf.c "LGPL 3 or later".
stream_avdevice.c (unrelated) has been marked as LGPL before.
2017-06-24 13:19:51 +02: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
|
2017-10-05 15:54:10 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-05-08 23:51:13 +02:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-05-08 23:51:13 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
demux_mf, stream_mf: change license to LGPL
cehoyos, who did not agree to the relicensing, added bcb5c78ce3. If
there was copyright, we consider it gone, because the table changed. It
does not map file extension to a FourCC anymore, and codecs.conf is
gone. The new mapping is a libavcodec codec name (happens to be the same
as the file extension).
The same applies to commits 60ecafec, b749836b, 5b3e3be1. None of these
authors were contacted. These were before the code was replaced with a
table (in d0326807). The parts outside of demux_mf.c were removed a long
time ago. Like in the previous comment, we don't think any copyright
applies at least to the new code (at least after the FourCC removal).
iive authored 0aa37a0d, which is probably still left in some form, and
makes demux_mf.c "LGPL 3 or later".
stream_avdevice.c (unrelated) has been marked as LGPL before.
2017-06-24 13:19:51 +02:00
|
|
|
* GNU Lesser General Public License for more details.
|
2009-05-08 23:51:13 +02:00
|
|
|
*
|
demux_mf, stream_mf: change license to LGPL
cehoyos, who did not agree to the relicensing, added bcb5c78ce3. If
there was copyright, we consider it gone, because the table changed. It
does not map file extension to a FourCC anymore, and codecs.conf is
gone. The new mapping is a libavcodec codec name (happens to be the same
as the file extension).
The same applies to commits 60ecafec, b749836b, 5b3e3be1. None of these
authors were contacted. These were before the code was replaced with a
table (in d0326807). The parts outside of demux_mf.c were removed a long
time ago. Like in the previous comment, we don't think any copyright
applies at least to the new code (at least after the FourCC removal).
iive authored 0aa37a0d, which is probably still left in some form, and
makes demux_mf.c "LGPL 3 or later".
stream_avdevice.c (unrelated) has been marked as LGPL before.
2017-06-24 13:19:51 +02: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/>.
|
2009-05-08 23:51:13 +02:00
|
|
|
*/
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2019-11-17 01:07:47 +01:00
|
|
|
#include <math.h>
|
2002-02-06 21:15:36 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-07-10 08:28:03 +02:00
|
|
|
#include <strings.h>
|
2002-02-06 21:15:36 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2012-02-03 08:05:11 +01:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2016-01-11 19:03:40 +01:00
|
|
|
#include "mpv_talloc.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/msg.h"
|
2014-06-10 22:48:11 +02:00
|
|
|
#include "options/options.h"
|
2016-09-06 20:09:56 +02:00
|
|
|
#include "options/m_config.h"
|
2014-12-29 23:09:50 +01:00
|
|
|
#include "options/path.h"
|
|
|
|
#include "misc/ctype.h"
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2007-03-15 19:36:36 +01:00
|
|
|
#include "stream/stream.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "demux.h"
|
2002-02-06 21:15:36 +01:00
|
|
|
#include "stheader.h"
|
2014-12-22 12:54:18 +01:00
|
|
|
#include "codec_tags.h"
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
#define MF_MAX_FILE_SIZE (1024 * 1024 * 256)
|
2012-11-16 19:12:56 +01:00
|
|
|
|
2014-12-29 23:09:50 +01:00
|
|
|
typedef struct mf {
|
|
|
|
struct mp_log *log;
|
2015-12-23 21:58:01 +01:00
|
|
|
struct sh_stream *sh;
|
2014-12-29 23:09:50 +01:00
|
|
|
int curr_frame;
|
|
|
|
int nr_of_files;
|
|
|
|
char **names;
|
|
|
|
// optional
|
|
|
|
struct stream **streams;
|
|
|
|
} mf_t;
|
|
|
|
|
|
|
|
|
|
|
|
static void mf_add(mf_t *mf, const char *fname)
|
|
|
|
{
|
|
|
|
char *entry = talloc_strdup(mf, fname);
|
|
|
|
MP_TARRAY_APPEND(mf, mf->names, mf->nr_of_files, entry);
|
|
|
|
}
|
|
|
|
|
2019-12-23 11:01:29 +01:00
|
|
|
static mf_t *open_mf_pattern(void *talloc_ctx, struct demuxer *d, char *filename)
|
2014-12-29 23:09:50 +01:00
|
|
|
{
|
2019-12-23 11:01:29 +01:00
|
|
|
struct mp_log *log = d->log;
|
2014-12-29 23:09:50 +01:00
|
|
|
int error_count = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
mf_t *mf = talloc_zero(talloc_ctx, mf_t);
|
|
|
|
mf->log = log;
|
|
|
|
|
|
|
|
if (filename[0] == '@') {
|
2019-12-23 11:01:29 +01:00
|
|
|
struct stream *s = stream_create(filename + 1,
|
|
|
|
d->stream_origin | STREAM_READ, d->cancel, d->global);
|
|
|
|
if (s) {
|
|
|
|
while (1) {
|
|
|
|
char buf[512];
|
|
|
|
int len = stream_read_peek(s, buf, sizeof(buf));
|
|
|
|
if (!len)
|
|
|
|
break;
|
|
|
|
bstr data = (bstr){buf, len};
|
|
|
|
int pos = bstrchr(data, '\n');
|
|
|
|
data = bstr_splice(data, 0, pos < 0 ? data.len : pos + 1);
|
|
|
|
bstr fname = bstr_strip(data);
|
|
|
|
if (fname.len) {
|
|
|
|
if (bstrchr(fname, '\0') >= 0) {
|
|
|
|
mp_err(log, "invalid filename\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char *entry = bstrto0(mf, fname);
|
|
|
|
if (!mp_path_exists(entry)) {
|
|
|
|
mp_verbose(log, "file not found: '%s'\n", entry);
|
|
|
|
} else {
|
|
|
|
MP_TARRAY_APPEND(mf, mf->names, mf->nr_of_files, entry);
|
|
|
|
}
|
2014-12-29 23:09:50 +01:00
|
|
|
}
|
2019-12-23 11:01:29 +01:00
|
|
|
stream_seek_skip(s, stream_tell(s) + data.len);
|
2014-12-29 23:09:50 +01:00
|
|
|
}
|
2019-12-23 11:01:29 +01:00
|
|
|
free_stream(s);
|
2014-12-29 23:09:50 +01:00
|
|
|
|
|
|
|
mp_info(log, "number of files: %d\n", mf->nr_of_files);
|
|
|
|
goto exit_mf;
|
|
|
|
}
|
|
|
|
mp_info(log, "%s is not indirect filelist\n", filename + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr(filename, ',')) {
|
|
|
|
mp_info(log, "filelist: %s\n", filename);
|
|
|
|
bstr bfilename = bstr0(filename);
|
|
|
|
|
|
|
|
while (bfilename.len) {
|
|
|
|
bstr bfname;
|
|
|
|
bstr_split_tok(bfilename, ",", &bfname, &bfilename);
|
|
|
|
char *fname2 = bstrdup0(mf, bfname);
|
|
|
|
|
|
|
|
if (!mp_path_exists(fname2))
|
|
|
|
mp_verbose(log, "file not found: '%s'\n", fname2);
|
|
|
|
else {
|
|
|
|
mf_add(mf, fname2);
|
|
|
|
}
|
|
|
|
talloc_free(fname2);
|
|
|
|
}
|
|
|
|
mp_info(log, "number of files: %d\n", mf->nr_of_files);
|
|
|
|
|
|
|
|
goto exit_mf;
|
|
|
|
}
|
|
|
|
|
2021-04-04 13:11:15 +02:00
|
|
|
size_t fname_avail = strlen(filename) + 32;
|
|
|
|
char *fname = talloc_size(mf, fname_avail);
|
2014-12-29 23:09:50 +01:00
|
|
|
|
2017-07-25 21:14:06 +02:00
|
|
|
#if HAVE_GLOB
|
2014-12-29 23:09:50 +01:00
|
|
|
if (!strchr(filename, '%')) {
|
|
|
|
strcpy(fname, filename);
|
|
|
|
if (!strchr(filename, '*'))
|
|
|
|
strcat(fname, "*");
|
|
|
|
|
|
|
|
mp_info(log, "search expr: %s\n", fname);
|
|
|
|
|
|
|
|
glob_t gg;
|
|
|
|
if (glob(fname, 0, NULL, &gg)) {
|
|
|
|
talloc_free(mf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < gg.gl_pathc; i++) {
|
|
|
|
if (mp_path_isdir(gg.gl_pathv[i]))
|
|
|
|
continue;
|
|
|
|
mf_add(mf, gg.gl_pathv[i]);
|
|
|
|
}
|
|
|
|
mp_info(log, "number of files: %d\n", mf->nr_of_files);
|
|
|
|
globfree(&gg);
|
|
|
|
goto exit_mf;
|
|
|
|
}
|
2017-07-25 21:14:06 +02:00
|
|
|
#endif
|
2014-12-29 23:09:50 +01:00
|
|
|
|
2021-04-04 13:11:15 +02:00
|
|
|
// We're using arbitrary user input as printf format with 1 int argument.
|
|
|
|
// Any format which uses exactly 1 int argument would be valid, but for
|
|
|
|
// simplicity we reject all conversion specifiers except %% and simple
|
|
|
|
// integer specifier: %[.][NUM]d where NUM is 1-3 digits (%.d is valid)
|
|
|
|
const char *f = filename;
|
|
|
|
int MAXDIGS = 3, nspec = 0, bad_spec = 0, c;
|
|
|
|
|
|
|
|
while (nspec < 2 && (c = *f++)) {
|
|
|
|
if (c != '%')
|
|
|
|
continue;
|
|
|
|
if (*f != '%') {
|
|
|
|
nspec++; // conversion specifier which isn't %%
|
|
|
|
if (*f == '.')
|
|
|
|
f++;
|
|
|
|
for (int ndig = 0; mp_isdigit(*f) && ndig < MAXDIGS; ndig++, f++)
|
|
|
|
/* no-op */;
|
|
|
|
if (*f != 'd') {
|
|
|
|
bad_spec++; // not int, or beyond our validation capacity
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// *f is '%' or 'd'
|
|
|
|
f++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nspec==0 (zero specifiers) is rejected because fname wouldn't advance.
|
|
|
|
if (bad_spec || nspec != 1) {
|
|
|
|
mp_err(log, "unsupported expr format: '%s'\n", filename);
|
|
|
|
goto exit_mf;
|
|
|
|
}
|
|
|
|
|
2014-12-29 23:09:50 +01:00
|
|
|
mp_info(log, "search expr: %s\n", filename);
|
|
|
|
|
|
|
|
while (error_count < 5) {
|
2021-04-04 13:11:15 +02:00
|
|
|
if (snprintf(fname, fname_avail, filename, count++) >= fname_avail) {
|
|
|
|
mp_err(log, "format result too long: '%s'\n", filename);
|
|
|
|
goto exit_mf;
|
|
|
|
}
|
2014-12-29 23:09:50 +01:00
|
|
|
if (!mp_path_exists(fname)) {
|
|
|
|
error_count++;
|
|
|
|
mp_verbose(log, "file not found: '%s'\n", fname);
|
|
|
|
} else {
|
|
|
|
mf_add(mf, fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_info(log, "number of files: %d\n", mf->nr_of_files);
|
|
|
|
|
|
|
|
exit_mf:
|
|
|
|
return mf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename)
|
|
|
|
{
|
|
|
|
mf_t *mf = talloc_zero(talloc_ctx, mf_t);
|
|
|
|
mf->log = log;
|
|
|
|
mf_add(mf, filename);
|
|
|
|
return mf;
|
|
|
|
}
|
|
|
|
|
2016-02-28 19:14:23 +01:00
|
|
|
static void demux_seek_mf(demuxer_t *demuxer, double seek_pts, int flags)
|
2013-08-22 19:13:29 +02:00
|
|
|
{
|
2013-11-11 18:48:31 +01:00
|
|
|
mf_t *mf = demuxer->priv;
|
2019-11-17 01:07:47 +01:00
|
|
|
double newpos = seek_pts * mf->sh->codec->fps;
|
2013-11-11 18:48:31 +01:00
|
|
|
if (flags & SEEK_FACTOR)
|
2016-02-28 19:14:23 +01:00
|
|
|
newpos = seek_pts * (mf->nr_of_files - 1);
|
2019-11-17 01:07:47 +01:00
|
|
|
if (flags & SEEK_FORWARD) {
|
|
|
|
newpos = ceil(newpos);
|
|
|
|
} else {
|
|
|
|
newpos = MPMIN(floor(newpos), mf->nr_of_files - 1);
|
|
|
|
}
|
|
|
|
mf->curr_frame = MPCLAMP((int)newpos, 0, mf->nr_of_files);
|
2002-02-06 21:15:36 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 15:12:24 +02:00
|
|
|
static bool demux_mf_read_packet(struct demuxer *demuxer,
|
|
|
|
struct demux_packet **pkt)
|
2013-07-11 19:17:51 +02:00
|
|
|
{
|
2012-11-16 19:12:56 +01:00
|
|
|
mf_t *mf = demuxer->priv;
|
|
|
|
if (mf->curr_frame >= mf->nr_of_files)
|
2018-09-07 15:12:24 +02:00
|
|
|
return false;
|
2020-08-22 20:46:45 +02:00
|
|
|
bool ok = false;
|
2012-11-16 19:12:56 +01:00
|
|
|
|
|
|
|
struct stream *entry_stream = NULL;
|
|
|
|
if (mf->streams)
|
|
|
|
entry_stream = mf->streams[mf->curr_frame];
|
|
|
|
struct stream *stream = entry_stream;
|
2013-03-19 01:54:45 +01:00
|
|
|
if (!stream) {
|
|
|
|
char *filename = mf->names[mf->curr_frame];
|
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 09:41:42 +01:00
|
|
|
if (filename) {
|
|
|
|
stream = stream_create(filename, demuxer->stream_origin | STREAM_READ,
|
|
|
|
demuxer->cancel, demuxer->global);
|
|
|
|
}
|
2013-03-19 01:54:45 +01:00
|
|
|
}
|
2012-11-16 19:12:56 +01:00
|
|
|
|
|
|
|
if (stream) {
|
|
|
|
stream_seek(stream, 0);
|
2013-06-11 12:16:42 +02:00
|
|
|
bstr data = stream_read_complete(stream, NULL, MF_MAX_FILE_SIZE);
|
2012-11-16 19:12:56 +01:00
|
|
|
if (data.len) {
|
|
|
|
demux_packet_t *dp = new_demux_packet(data.len);
|
2014-09-16 18:11:00 +02:00
|
|
|
if (dp) {
|
|
|
|
memcpy(dp->buffer, data.start, data.len);
|
2016-01-12 23:48:19 +01:00
|
|
|
dp->pts = mf->curr_frame / mf->sh->codec->fps;
|
2014-09-16 18:11:00 +02:00
|
|
|
dp->keyframe = true;
|
2018-09-07 15:12:24 +02:00
|
|
|
dp->stream = mf->sh->index;
|
|
|
|
*pkt = dp;
|
2020-08-22 20:46:45 +02:00
|
|
|
ok = true;
|
2014-09-16 18:11:00 +02:00
|
|
|
}
|
2012-11-16 19:12:56 +01:00
|
|
|
}
|
|
|
|
talloc_free(data.start);
|
|
|
|
}
|
|
|
|
|
2013-03-19 01:54:45 +01:00
|
|
|
if (stream && stream != entry_stream)
|
2012-11-16 19:12:56 +01:00
|
|
|
free_stream(stream);
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2012-11-16 19:12:56 +01:00
|
|
|
mf->curr_frame++;
|
2020-08-22 20:46:45 +02:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
MP_ERR(demuxer, "error reading image file\n");
|
|
|
|
|
2018-09-07 15:12:24 +02:00
|
|
|
return true;
|
2002-02-06 21:15:36 +01:00
|
|
|
}
|
|
|
|
|
2013-02-24 17:23:38 +01:00
|
|
|
// map file extension/type to a codec name
|
2009-03-21 20:46:13 +01:00
|
|
|
|
2007-11-17 18:27:30 +01:00
|
|
|
static const struct {
|
2013-11-11 18:48:31 +01:00
|
|
|
const char *type;
|
|
|
|
const char *codec;
|
2007-11-17 18:27:30 +01:00
|
|
|
} type2format[] = {
|
2013-11-11 18:48:31 +01:00
|
|
|
{ "bmp", "bmp" },
|
|
|
|
{ "dpx", "dpx" },
|
|
|
|
{ "j2c", "jpeg2000" },
|
|
|
|
{ "j2k", "jpeg2000" },
|
|
|
|
{ "jp2", "jpeg2000" },
|
|
|
|
{ "jpc", "jpeg2000" },
|
|
|
|
{ "jpeg", "mjpeg" },
|
|
|
|
{ "jpg", "mjpeg" },
|
|
|
|
{ "jps", "mjpeg" },
|
|
|
|
{ "jls", "ljpeg" },
|
|
|
|
{ "thm", "mjpeg" },
|
|
|
|
{ "db", "mjpeg" },
|
2021-02-02 13:37:04 +01:00
|
|
|
{ "pcd", "photocd" },
|
|
|
|
{ "pfm", "pfm" },
|
2013-11-11 18:48:31 +01:00
|
|
|
{ "pcx", "pcx" },
|
|
|
|
{ "png", "png" },
|
|
|
|
{ "pns", "png" },
|
|
|
|
{ "ptx", "ptx" },
|
|
|
|
{ "tga", "targa" },
|
|
|
|
{ "tif", "tiff" },
|
|
|
|
{ "tiff", "tiff" },
|
|
|
|
{ "sgi", "sgi" },
|
|
|
|
{ "sun", "sunrast" },
|
|
|
|
{ "ras", "sunrast" },
|
|
|
|
{ "rs", "sunrast" },
|
|
|
|
{ "ra", "sunrast" },
|
|
|
|
{ "im1", "sunrast" },
|
|
|
|
{ "im8", "sunrast" },
|
|
|
|
{ "im24", "sunrast" },
|
|
|
|
{ "im32", "sunrast" },
|
|
|
|
{ "sunras", "sunrast" },
|
|
|
|
{ "xbm", "xbm" },
|
|
|
|
{ "pam", "pam" },
|
|
|
|
{ "pbm", "pbm" },
|
|
|
|
{ "pgm", "pgm" },
|
|
|
|
{ "pgmyuv", "pgmyuv" },
|
|
|
|
{ "ppm", "ppm" },
|
|
|
|
{ "pnm", "ppm" },
|
|
|
|
{ "gif", "gif" }, // usually handled by demux_lavf
|
|
|
|
{ "pix", "brender_pix" },
|
|
|
|
{ "exr", "exr" },
|
|
|
|
{ "pic", "pictor" },
|
|
|
|
{ "xface", "xface" },
|
|
|
|
{ "xwd", "xwd" },
|
|
|
|
{0}
|
2007-11-17 18:27:30 +01:00
|
|
|
};
|
|
|
|
|
2014-06-10 22:48:11 +02:00
|
|
|
static const char *probe_format(mf_t *mf, char *type, enum demux_check check)
|
2012-11-16 19:12:56 +01:00
|
|
|
{
|
2013-07-12 21:58:11 +02:00
|
|
|
if (check > DEMUX_CHECK_REQUEST)
|
2013-02-24 16:31:43 +01:00
|
|
|
return NULL;
|
2014-06-10 22:48:11 +02:00
|
|
|
char *org_type = type;
|
2012-11-16 19:12:56 +01:00
|
|
|
if (!type || !type[0]) {
|
|
|
|
char *p = strrchr(mf->names[0], '.');
|
|
|
|
if (p)
|
|
|
|
type = p + 1;
|
|
|
|
}
|
2013-07-12 21:58:11 +02:00
|
|
|
for (int i = 0; type2format[i].type; i++) {
|
|
|
|
if (type && strcasecmp(type, type2format[i].type) == 0)
|
|
|
|
return type2format[i].codec;
|
2012-11-16 19:12:56 +01:00
|
|
|
}
|
2013-07-12 21:58:11 +02:00
|
|
|
if (check == DEMUX_CHECK_REQUEST) {
|
2014-06-10 22:48:11 +02:00
|
|
|
if (!org_type) {
|
2013-12-21 20:24:20 +01:00
|
|
|
MP_ERR(mf, "file type was not set! (try --mf-type=ext)\n");
|
2013-11-11 18:48:31 +01:00
|
|
|
} else {
|
2013-12-21 20:24:20 +01:00
|
|
|
MP_ERR(mf, "--mf-type set to an unknown codec!\n");
|
2013-07-12 21:58:11 +02:00
|
|
|
}
|
2012-11-16 19:12:56 +01:00
|
|
|
}
|
2013-07-12 21:58:11 +02:00
|
|
|
return NULL;
|
2012-11-16 19:12:56 +01:00
|
|
|
}
|
2003-01-28 23:00:57 +01:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
|
2013-07-11 20:08:12 +02:00
|
|
|
{
|
2013-11-11 18:48:31 +01:00
|
|
|
mf_t *mf;
|
|
|
|
|
|
|
|
if (strncmp(demuxer->stream->url, "mf://", 5) == 0 &&
|
2017-02-02 18:24:27 +01:00
|
|
|
demuxer->stream->info && strcmp(demuxer->stream->info->name, "mf") == 0)
|
|
|
|
{
|
2019-12-23 11:01:29 +01:00
|
|
|
mf = open_mf_pattern(demuxer, demuxer, demuxer->stream->url + 5);
|
2017-02-02 18:24:27 +01:00
|
|
|
} else {
|
2013-12-21 20:24:20 +01:00
|
|
|
mf = open_mf_single(demuxer, demuxer->log, demuxer->stream->url);
|
2013-11-11 19:20:37 +01:00
|
|
|
int bog = 0;
|
|
|
|
MP_TARRAY_APPEND(mf, mf->streams, bog, demuxer->stream);
|
2013-11-11 18:48:31 +01:00
|
|
|
}
|
2013-07-12 21:58:11 +02:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
if (!mf || mf->nr_of_files < 1)
|
|
|
|
goto error;
|
2006-02-14 10:34:30 +01:00
|
|
|
|
2016-09-06 20:09:56 +02:00
|
|
|
double mf_fps;
|
|
|
|
char *mf_type;
|
|
|
|
mp_read_option_raw(demuxer->global, "mf-fps", &m_option_type_double, &mf_fps);
|
|
|
|
mp_read_option_raw(demuxer->global, "mf-type", &m_option_type_string, &mf_type);
|
|
|
|
|
2014-12-22 12:54:18 +01:00
|
|
|
const char *codec = mp_map_mimetype_to_video_codec(demuxer->stream->mime_type);
|
2016-09-06 20:09:56 +02:00
|
|
|
if (!codec || (mf_type && mf_type[0]))
|
|
|
|
codec = probe_format(mf, mf_type, check);
|
|
|
|
talloc_free(mf_type);
|
2013-11-11 18:48:31 +01:00
|
|
|
if (!codec)
|
|
|
|
goto error;
|
2003-01-28 23:00:57 +01:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
mf->curr_frame = 0;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
// create a new video stream header
|
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 21:44:53 +01:00
|
|
|
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
|
player: add track-list/N/image sub-property
This exposes whether a video track is detected as an image. This is
useful for profile conditions, property expansion and lavfi-complex, and
is more accurate than any detection even Lua scripts can perform, since
they can't differentiate between images and videos without container-fps
and audio and with duration 1 (which is the duration set by the mf
demuxer with the default --mf-fps=1).
The lavf demuxer image check is moved to where the number of frames is
available for comparison, and is modified to check the number of frames
and duration instead of the video codec. This doesn't misdetect videos
in a codec commonly used for images (e.g. mjpeg) as images, and can
detect images in a codec commonly used for videos (e.g. 1-frame gifs).
pix files are also now detected as images, while before they weren't
since the condition was checking if the AVInputFormat name ends with
_pipe, and alias_pix doesn't.
Both nb_frames and codec_info_nb_frames are checked because nb_frames is
0 for some video codecs (hevc, av1, vc1, mpeg1video, vp9 if forcing
--demuxer=lavf), and codec_info_nb_frames is 1 for others (mpeg, mpeg4,
wmv3).
The duration is checked as well because for some uncommon codecs and
containers found in FFMpeg's FATE suite, libavformat returns nb_frames =
0 and codec_info_nb_frames = 1. For some of them it even returns
duration = 0, so they are blacklisted in order to never be considered
images.
The extra codecs that would have to be blacklisted without checking the
duration are AV_CODEC_ID_4XM, AV_CODEC_ID_BINKVIDEO,
AV_CODEC_ID_DSICINVIDEO, AV_CODEC_ID_ESCAPE130, AV_CODEC_ID_MMVIDEO,
AV_CODEC_ID_NUV, AV_CODEC_ID_RL2, AV_CODEC_ID_SMACKVIDEO and
AV_CODEC_ID_XAN_WC3, while the containers are film-cpk, ivf and ogg.
The lower limit for duration is 10 because that's the duration of
1-frame gifs.
Streams with codec_info_nb_frames 0 are not considered images because
vp9 and av1 have nb_frames = 0 and codec_info_nb_frames = 0, and we
can't rely on just the duration to detect them because they could be
livestreams without an initial duration, and actually even if we could
for these codecs libavformat returns huge negative durations like
-9223372036854775808.
Some more images in the FATE suite that are really frames cut from a
video in an uncommon codec and container, like cine/bayer_gbrg8.cine,
could be detected by allowing codec_info_nb_frames = 0, but then any
present and future video codec with nb_frames = 0 and
codec_info_nb_frames = 0 would need to be added to the blacklist. Some
even have duration > 10, so to detect these images the duration check
would have to be removed, and all the previously mentioned extra codecs
and containers would have to be added added to the blacklists, which
means that images that use them (if they exist anywhere) will never be
detected. These FATE images aren't detected as such by mediainfo either
anyway, nor can a Lua script reliably detect them as images since they
have container-fps and duration > 0 and != 1, and you probably will
never see files like them anywhere else.
For attached pictures the lavf demuxer always set image to true, which
is necessary because they have duration > 10. There is a minor change in
behavior for which audio with attached pictures now has mf-fps as
container-fps instead of unavailable, but this makes it consistent with
external cover art, which was already being assigned mf-fps.
When the lavf demuxer fails, the mf one guesses if the file is an image
by its extension, so sh->image is set to true when the mf demuxer
succeds and there's only one file.
Even if you add a video's file type to --mf-type and open it with the mf
protocol, only the first frame is used, so setting image to true is
still accurate.
When converting an image to the extensions listed in demux/demux_mf.c,
tga and pam files are currently the only ones detected by the mf demuxer
rather than lavf. Actually they are detected with the image2 format, but
it is blacklisted; see d0fee0ac33a.
The mkv demuxer just sets image to true for any attached picture.
The timeline demuxer just copies the value of image from source to
destination. This sets image to true for attached pictures, standalone
images and images added with !new_stream in EDL playlists, but it is
imperfect since you could concatenate multiple images in an EDL playlist
(which should be done with the mf demuxer anyway). This is good enough
anyway since the comment of the modified function already says it is
"Imperfect and arbitrary".
2021-10-02 16:31:24 +02:00
|
|
|
struct mp_codec_params *c = sh->codec;
|
2021-10-02 17:45:27 +02:00
|
|
|
|
2016-01-12 23:48:19 +01:00
|
|
|
c->codec = codec;
|
|
|
|
c->disp_w = 0;
|
|
|
|
c->disp_h = 0;
|
2016-09-06 20:09:56 +02:00
|
|
|
c->fps = mf_fps;
|
2016-08-19 14:19:46 +02:00
|
|
|
c->reliable_fps = true;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2015-12-23 21:58:01 +01:00
|
|
|
demux_add_sh_stream(demuxer, sh);
|
|
|
|
|
|
|
|
mf->sh = sh;
|
2013-11-11 18:48:31 +01:00
|
|
|
demuxer->priv = (void *)mf;
|
|
|
|
demuxer->seekable = true;
|
2017-06-20 13:57:58 +02:00
|
|
|
demuxer->duration = mf->nr_of_files / mf->sh->codec->fps;
|
2002-02-06 21:15:36 +01:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
return 0;
|
2012-11-16 19:12:56 +01:00
|
|
|
|
|
|
|
error:
|
2013-11-11 18:48:31 +01:00
|
|
|
return -1;
|
2002-02-06 21:15:36 +01:00
|
|
|
}
|
2002-04-24 17:36:07 +02:00
|
|
|
|
2013-11-11 18:48:31 +01:00
|
|
|
static void demux_close_mf(demuxer_t *demuxer)
|
|
|
|
{
|
2002-04-24 17:36:07 +02:00
|
|
|
}
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-01-13 17:00:39 +01:00
|
|
|
const demuxer_desc_t demuxer_desc_mf = {
|
2013-07-11 20:08:12 +02:00
|
|
|
.name = "mf",
|
2013-07-12 22:12:02 +02:00
|
|
|
.desc = "image files (mf)",
|
2018-09-07 15:12:24 +02:00
|
|
|
.read_packet = demux_mf_read_packet,
|
2013-07-11 20:08:12 +02:00
|
|
|
.open = demux_open_mf,
|
|
|
|
.close = demux_close_mf,
|
|
|
|
.seek = demux_seek_mf,
|
2005-08-05 21:57:47 +02:00
|
|
|
};
|