2010-01-30 22:26:47 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 22:26:47 +00:00
|
|
|
*
|
stream: change license to LGPL
All relevant authors have agreed.
There are two exceptions, patches by authors who could not be reached.
This commit tries to remove their copyright.
a0f08fbe: messes with the seeking code corner cases. The EOF flag logic
was changed at some point, and always had a flaky history (see e.g.
347cf972 50274ca3 70411f27 5999efb9 0d5e6084 ff08d0c3 2e2f77e3 de5566f0
9554a844, all which happened after that patch, MPlayer ones without that
patch). I claim that all of the copyright the patch might have added is
gone. Except the message in stream_seek(), which this commit removes.
The other code removed/changed in stream_seek() is probably not from
that patch, but it doesn't hurt to be sure, and also makes it more
readable. (It might change the behavior so that sometimes the eof flag
is set after a seek, but it doesn't matter here.)
2aa6acd9: it looks like the seek_forward() modified by this patch was
later moved to stream.c and renamed to stream_skip_read() in a790f2133.
(Looking closer at it, it was actually modified again a bunch of times,
fixing the logic.) I rewrote it in this commit. The code ended up rather
similar, which probably could lead to doubts whether this was done
properly, but I guess the reader of this will just have to believe me. I
knew what stream_skip_read() was supposed to do (which was reinforced
when I tried to replace it on the caller side), without reading the
pre-existing code in detail. I had to "relearn" the logic how buf_pos
and bug_len work - it was actually easy to see from stream_read_char()
how to skip the data, essentially by generalizing its logic from 1 byte
to N bytes. From the old code I only "used" the fact that it's obviously
a while(len>0) look, that has to call stream_fill_buffer repeatedly to
make progress. At first I actually didn't use stream_fill_buffer_by(),
but the variant without _by, but readded it when I checked why the old
code used it (see cd7ec016e7). This has to be good enough. In the end,
it's hard to argue that this could be implemented in a way not using
such a loop.
Other than this, I could add the usual remarks about how this code was
not modularized in the past, and how stream.c contained DVD code, and
how this was later modularized, moving the copyright to other files, and
so on. Also, if someone wrote a stream module, and was not asked about
LGPL relicensing, we don't consider the entry in stream_list[]
copyrightable.
2017-06-19 14:07:42 +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.
|
2010-01-30 22:26:47 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 22:26:47 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
stream: change license to LGPL
All relevant authors have agreed.
There are two exceptions, patches by authors who could not be reached.
This commit tries to remove their copyright.
a0f08fbe: messes with the seeking code corner cases. The EOF flag logic
was changed at some point, and always had a flaky history (see e.g.
347cf972 50274ca3 70411f27 5999efb9 0d5e6084 ff08d0c3 2e2f77e3 de5566f0
9554a844, all which happened after that patch, MPlayer ones without that
patch). I claim that all of the copyright the patch might have added is
gone. Except the message in stream_seek(), which this commit removes.
The other code removed/changed in stream_seek() is probably not from
that patch, but it doesn't hurt to be sure, and also makes it more
readable. (It might change the behavior so that sometimes the eof flag
is set after a seek, but it doesn't matter here.)
2aa6acd9: it looks like the seek_forward() modified by this patch was
later moved to stream.c and renamed to stream_skip_read() in a790f2133.
(Looking closer at it, it was actually modified again a bunch of times,
fixing the logic.) I rewrote it in this commit. The code ended up rather
similar, which probably could lead to doubts whether this was done
properly, but I guess the reader of this will just have to believe me. I
knew what stream_skip_read() was supposed to do (which was reinforced
when I tried to replace it on the caller side), without reading the
pre-existing code in detail. I had to "relearn" the logic how buf_pos
and bug_len work - it was actually easy to see from stream_read_char()
how to skip the data, essentially by generalizing its logic from 1 byte
to N bytes. From the old code I only "used" the fact that it's obviously
a while(len>0) look, that has to call stream_fill_buffer repeatedly to
make progress. At first I actually didn't use stream_fill_buffer_by(),
but the variant without _by, but readded it when I checked why the old
code used it (see cd7ec016e7). This has to be good enough. In the end,
it's hard to argue that this could be implemented in a way not using
such a loop.
Other than this, I could add the usual remarks about how this code was
not modularized in the past, and how stream.c contained DVD code, and
how this was later modularized, moving the copyright to other files, and
so on. Also, if someone wrote a stream module, and was not asked about
LGPL relicensing, we don't consider the entry in stream_list[]
copyrightable.
2017-06-19 14:07:42 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2010-01-30 22:26:47 +00:00
|
|
|
*
|
stream: change license to LGPL
All relevant authors have agreed.
There are two exceptions, patches by authors who could not be reached.
This commit tries to remove their copyright.
a0f08fbe: messes with the seeking code corner cases. The EOF flag logic
was changed at some point, and always had a flaky history (see e.g.
347cf972 50274ca3 70411f27 5999efb9 0d5e6084 ff08d0c3 2e2f77e3 de5566f0
9554a844, all which happened after that patch, MPlayer ones without that
patch). I claim that all of the copyright the patch might have added is
gone. Except the message in stream_seek(), which this commit removes.
The other code removed/changed in stream_seek() is probably not from
that patch, but it doesn't hurt to be sure, and also makes it more
readable. (It might change the behavior so that sometimes the eof flag
is set after a seek, but it doesn't matter here.)
2aa6acd9: it looks like the seek_forward() modified by this patch was
later moved to stream.c and renamed to stream_skip_read() in a790f2133.
(Looking closer at it, it was actually modified again a bunch of times,
fixing the logic.) I rewrote it in this commit. The code ended up rather
similar, which probably could lead to doubts whether this was done
properly, but I guess the reader of this will just have to believe me. I
knew what stream_skip_read() was supposed to do (which was reinforced
when I tried to replace it on the caller side), without reading the
pre-existing code in detail. I had to "relearn" the logic how buf_pos
and bug_len work - it was actually easy to see from stream_read_char()
how to skip the data, essentially by generalizing its logic from 1 byte
to N bytes. From the old code I only "used" the fact that it's obviously
a while(len>0) look, that has to call stream_fill_buffer repeatedly to
make progress. At first I actually didn't use stream_fill_buffer_by(),
but the variant without _by, but readded it when I checked why the old
code used it (see cd7ec016e7). This has to be good enough. In the end,
it's hard to argue that this could be implemented in a way not using
such a loop.
Other than this, I could add the usual remarks about how this code was
not modularized in the past, and how stream.c contained DVD code, and
how this was later modularized, moving the copyright to other files, and
so on. Also, if someone wrote a stream module, and was not asked about
LGPL relicensing, we don't consider the entry in stream_list[]
copyrightable.
2017-06-19 14:07:42 +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/>.
|
2010-01-30 22:26:47 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_STREAM_H
|
|
|
|
#define MPLAYER_STREAM_H
|
2001-04-22 16:56:20 +00:00
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2012-11-17 17:12:13 +00:00
|
|
|
#include <stdbool.h>
|
2010-11-02 01:17:41 +00:00
|
|
|
#include <stdio.h>
|
2002-09-15 22:38:01 +00:00
|
|
|
#include <string.h>
|
2002-01-07 09:22:01 +00:00
|
|
|
#include <inttypes.h>
|
2002-03-23 21:52:13 +00:00
|
|
|
#include <sys/types.h>
|
2010-03-06 07:24:41 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2011-02-25 16:10:00 +00:00
|
|
|
|
2002-09-15 22:38:01 +00:00
|
|
|
#define STREAM_BUFFER_SIZE 2048
|
2013-01-24 16:43:07 +00:00
|
|
|
#define STREAM_MAX_SECTOR_SIZE (8 * 1024)
|
2002-09-15 22:38:01 +00:00
|
|
|
|
stream: add stream_unread_buffer()
demux_lavf probes up to 2 MB of data in the worst case. When the ffmpeg
demuxer is actually opened, the stream is seeked back to 0, and the
previously read data is thrown away.
This wasn't a problem for playback of local files, but it's less than
ideal for playing from slow media (like web streams), and breaks
completely if the media is not seekable (pipes, some web streams).
This new function is intended to allow fixing this. demux_lavf will use
it to put the read probe data back into the buffer.
The simplest way of implementing this function is by making it
transparently extend the normal stream buffer. This makes sure no
existing code is broken by new weird special cases. For simplicity
and to avoid possible performance loss due to extra dereferencing
when accessing the buffer, we just extend the static buffer from
8 KB to 2 MB. Normally, most of these 2 MB will stay uncommitted, so
there's no associated waste of memory. If demux_lavf really reads all
2 MB, the memory will be committed and stay unused, though.
2013-05-24 21:20:09 +00:00
|
|
|
// Max buffer for initial probe.
|
|
|
|
#define STREAM_MAX_BUFFER_SIZE (2 * 1024 * 1024)
|
|
|
|
|
2013-06-06 18:39:53 +00:00
|
|
|
|
|
|
|
// stream->mode
|
2003-04-02 16:25:07 +00:00
|
|
|
#define STREAM_READ 0
|
|
|
|
#define STREAM_WRITE 1
|
2013-06-06 18:39:53 +00:00
|
|
|
|
2013-08-25 20:50:16 +00:00
|
|
|
// flags for stream_open_ext (this includes STREAM_READ and STREAM_WRITE)
|
2014-08-31 17:49:39 +00:00
|
|
|
#define STREAM_SAFE_ONLY 4
|
2014-08-31 22:12:47 +00:00
|
|
|
#define STREAM_NETWORK_ONLY 8
|
2013-08-25 20:50:16 +00:00
|
|
|
|
2014-08-31 17:49:39 +00:00
|
|
|
#define STREAM_UNSAFE -3
|
2013-08-25 20:50:16 +00:00
|
|
|
#define STREAM_NO_MATCH -2
|
2007-08-28 22:38:45 +00:00
|
|
|
#define STREAM_UNSUPPORTED -1
|
2003-04-02 16:25:07 +00:00
|
|
|
#define STREAM_ERROR 0
|
|
|
|
#define STREAM_OK 1
|
|
|
|
|
2013-10-02 19:19:16 +00:00
|
|
|
enum stream_ctrl {
|
2014-12-13 19:25:31 +00:00
|
|
|
STREAM_CTRL_GET_SIZE = 1,
|
|
|
|
|
|
|
|
// Cache
|
2016-03-29 09:29:52 +00:00
|
|
|
STREAM_CTRL_GET_CACHE_INFO,
|
2014-04-09 17:15:23 +00:00
|
|
|
STREAM_CTRL_SET_CACHE_SIZE,
|
2016-01-18 16:50:12 +00:00
|
|
|
STREAM_CTRL_SET_READAHEAD,
|
2014-12-13 19:25:31 +00:00
|
|
|
|
|
|
|
// stream_memory.c
|
2013-10-02 19:19:16 +00:00
|
|
|
STREAM_CTRL_SET_CONTENTS,
|
2014-12-13 19:25:31 +00:00
|
|
|
|
|
|
|
// stream_rar.c
|
2013-12-06 22:00:19 +00:00
|
|
|
STREAM_CTRL_GET_BASE_FILENAME,
|
2014-12-13 19:25:31 +00:00
|
|
|
|
|
|
|
// Certain network protocols
|
|
|
|
STREAM_CTRL_AVSEEK,
|
|
|
|
STREAM_CTRL_HAS_AVSEEK,
|
|
|
|
STREAM_CTRL_GET_METADATA,
|
|
|
|
|
|
|
|
// TV
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
STREAM_CTRL_TV_SET_SCAN,
|
|
|
|
STREAM_CTRL_SET_TV_FREQ,
|
|
|
|
STREAM_CTRL_GET_TV_FREQ,
|
|
|
|
STREAM_CTRL_SET_TV_COLORS,
|
|
|
|
STREAM_CTRL_GET_TV_COLORS,
|
|
|
|
STREAM_CTRL_TV_SET_NORM,
|
|
|
|
STREAM_CTRL_TV_STEP_NORM,
|
|
|
|
STREAM_CTRL_TV_SET_CHAN,
|
2015-02-02 15:47:32 +00:00
|
|
|
STREAM_CTRL_TV_GET_CHAN,
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
STREAM_CTRL_TV_STEP_CHAN,
|
|
|
|
STREAM_CTRL_TV_LAST_CHAN,
|
|
|
|
STREAM_CTRL_DVB_SET_CHANNEL,
|
2016-01-08 19:19:57 +00:00
|
|
|
STREAM_CTRL_DVB_SET_CHANNEL_NAME,
|
|
|
|
STREAM_CTRL_DVB_GET_CHANNEL_NAME,
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
STREAM_CTRL_DVB_STEP_CHANNEL,
|
2014-12-13 19:25:31 +00:00
|
|
|
|
|
|
|
// Optical discs
|
|
|
|
STREAM_CTRL_GET_TIME_LENGTH,
|
|
|
|
STREAM_CTRL_GET_DVD_INFO,
|
|
|
|
STREAM_CTRL_GET_DISC_NAME,
|
|
|
|
STREAM_CTRL_GET_NUM_CHAPTERS,
|
|
|
|
STREAM_CTRL_GET_CURRENT_TIME,
|
|
|
|
STREAM_CTRL_GET_CHAPTER_TIME,
|
|
|
|
STREAM_CTRL_SEEK_TO_TIME,
|
|
|
|
STREAM_CTRL_GET_ASPECT_RATIO,
|
|
|
|
STREAM_CTRL_GET_NUM_ANGLES,
|
|
|
|
STREAM_CTRL_GET_ANGLE,
|
|
|
|
STREAM_CTRL_SET_ANGLE,
|
|
|
|
STREAM_CTRL_GET_NUM_TITLES,
|
|
|
|
STREAM_CTRL_GET_TITLE_LENGTH, // double* (in: title number, out: len)
|
|
|
|
STREAM_CTRL_GET_LANG,
|
|
|
|
STREAM_CTRL_GET_CURRENT_TITLE,
|
|
|
|
STREAM_CTRL_SET_CURRENT_TITLE,
|
2013-10-02 19:19:16 +00:00
|
|
|
};
|
2003-04-02 16:25:07 +00:00
|
|
|
|
2016-03-29 09:29:52 +00:00
|
|
|
// for STREAM_CTRL_GET_CACHE_INFO
|
|
|
|
struct stream_cache_info {
|
|
|
|
int64_t size;
|
|
|
|
int64_t fill;
|
|
|
|
bool idle;
|
|
|
|
int64_t speed;
|
|
|
|
};
|
|
|
|
|
2012-02-19 13:15:41 +00:00
|
|
|
struct stream_lang_req {
|
2013-01-24 16:43:07 +00:00
|
|
|
int type; // STREAM_AUDIO, STREAM_SUB
|
|
|
|
int id;
|
|
|
|
char name[50];
|
2012-02-19 13:15:41 +00:00
|
|
|
};
|
2008-10-16 18:28:38 +00:00
|
|
|
|
2013-06-04 23:59:04 +00:00
|
|
|
struct stream_dvd_info_req {
|
|
|
|
unsigned int palette[16];
|
|
|
|
int num_subs;
|
|
|
|
};
|
|
|
|
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
// for STREAM_CTRL_SET_TV_COLORS
|
|
|
|
#define TV_COLOR_BRIGHTNESS 1
|
|
|
|
#define TV_COLOR_HUE 2
|
|
|
|
#define TV_COLOR_SATURATION 3
|
|
|
|
#define TV_COLOR_CONTRAST 4
|
|
|
|
|
2014-07-30 00:21:35 +00:00
|
|
|
// for STREAM_CTRL_AVSEEK
|
|
|
|
struct stream_avseek {
|
|
|
|
int stream_index;
|
|
|
|
int64_t timestamp;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
struct stream;
|
2003-04-02 16:25:07 +00:00
|
|
|
typedef struct stream_info_st {
|
2013-01-24 16:43:07 +00:00
|
|
|
const char *name;
|
2013-06-06 18:39:53 +00:00
|
|
|
// opts is set from ->opts
|
2014-05-24 12:06:13 +00:00
|
|
|
int (*open)(struct stream *st);
|
2014-06-10 21:56:05 +00:00
|
|
|
const char *const *protocols;
|
2014-08-31 22:12:47 +00:00
|
|
|
bool can_write; // correctly checks for READ/WRITE modes
|
|
|
|
bool is_safe; // opening is no security issue, even with remote provided URLs
|
|
|
|
bool is_network; // used to restrict remote playlist entries to remote URLs
|
2003-04-02 16:25:07 +00:00
|
|
|
} stream_info_t;
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct stream {
|
2013-08-02 15:02:34 +00:00
|
|
|
const struct stream_info_st *info;
|
|
|
|
|
2013-01-24 16:43:07 +00:00
|
|
|
// Read
|
|
|
|
int (*fill_buffer)(struct stream *s, char *buffer, int max_len);
|
|
|
|
// Write
|
|
|
|
int (*write_buffer)(struct stream *s, char *buffer, int len);
|
|
|
|
// Seek
|
|
|
|
int (*seek)(struct stream *s, int64_t pos);
|
|
|
|
// Control
|
|
|
|
// Will be later used to let streams like dvd and cdda report
|
|
|
|
// their structure (ie tracks, chapters, etc)
|
|
|
|
int (*control)(struct stream *s, int cmd, void *arg);
|
|
|
|
// Close
|
|
|
|
void (*close)(struct stream *s);
|
|
|
|
|
|
|
|
int sector_size; // sector size (seek will be aligned on this size if non 0)
|
2013-05-25 13:03:30 +00:00
|
|
|
int read_chunk; // maximum amount of data to read at once to limit latency
|
2013-01-24 16:43:07 +00:00
|
|
|
unsigned int buf_pos, buf_len;
|
2014-05-24 12:04:09 +00:00
|
|
|
int64_t pos;
|
2013-01-24 16:43:07 +00:00
|
|
|
int eof;
|
|
|
|
int mode; //STREAM_READ or STREAM_WRITE
|
|
|
|
void *priv; // used for DVD, TV, RTSP etc
|
2013-08-02 15:02:34 +00:00
|
|
|
char *url; // filename/url (possibly including protocol prefix)
|
|
|
|
char *path; // filename (url without protocol prefix)
|
2013-01-24 16:43:07 +00:00
|
|
|
char *mime_type; // when HTTP streaming is used
|
2013-07-11 19:10:42 +00:00
|
|
|
char *demuxer; // request demuxer to be used
|
2013-01-24 16:43:07 +00:00
|
|
|
char *lavf_type; // name of expected demuxer type for lavf
|
2015-02-06 20:32:44 +00:00
|
|
|
bool streaming : 1; // known to be a network stream if true
|
2014-05-24 12:04:09 +00:00
|
|
|
bool seekable : 1; // presence of general byte seeking support
|
|
|
|
bool fast_skip : 1; // consider stream fast enough to fw-seek by skipping
|
2014-08-31 22:12:47 +00:00
|
|
|
bool is_network : 1; // original stream_info_t.is_network flag
|
2014-05-24 12:04:09 +00:00
|
|
|
bool allow_caching : 1; // stream cache makes sense
|
2017-02-02 17:03:29 +00:00
|
|
|
bool caching : 1; // is a cache, or accesses a cache
|
2017-02-02 17:24:27 +00:00
|
|
|
bool is_local_file : 1; // from the filesystem
|
|
|
|
bool is_directory : 1; // directory on the filesystem
|
2016-12-04 22:15:31 +00:00
|
|
|
bool access_references : 1; // open other streams
|
2013-12-21 19:36:45 +00:00
|
|
|
struct mp_log *log;
|
|
|
|
struct mpv_global *global;
|
2013-05-11 20:19:33 +00:00
|
|
|
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
struct mp_cancel *cancel; // cancellation notification
|
|
|
|
|
2017-02-02 17:03:29 +00:00
|
|
|
struct stream *underlying; // e.g. cache wrapper
|
stream: add stream_unread_buffer()
demux_lavf probes up to 2 MB of data in the worst case. When the ffmpeg
demuxer is actually opened, the stream is seeked back to 0, and the
previously read data is thrown away.
This wasn't a problem for playback of local files, but it's less than
ideal for playing from slow media (like web streams), and breaks
completely if the media is not seekable (pipes, some web streams).
This new function is intended to allow fixing this. demux_lavf will use
it to put the read probe data back into the buffer.
The simplest way of implementing this function is by making it
transparently extend the normal stream buffer. This makes sure no
existing code is broken by new weird special cases. For simplicity
and to avoid possible performance loss due to extra dereferencing
when accessing the buffer, we just extend the static buffer from
8 KB to 2 MB. Normally, most of these 2 MB will stay uncommitted, so
there's no associated waste of memory. If demux_lavf really reads all
2 MB, the memory will be committed and stay unused, though.
2013-05-24 21:20:09 +00:00
|
|
|
|
|
|
|
// Includes additional padding in case sizes get rounded up by sector size.
|
|
|
|
unsigned char buffer[];
|
2001-04-22 16:56:20 +00:00
|
|
|
} stream_t;
|
|
|
|
|
2008-08-12 09:49:37 +00:00
|
|
|
int stream_fill_buffer(stream_t *s);
|
2010-02-21 23:30:34 +00:00
|
|
|
|
2014-05-19 21:27:09 +00:00
|
|
|
struct mp_cache_opts;
|
|
|
|
bool stream_wants_cache(stream_t *stream, struct mp_cache_opts *opts);
|
2016-09-06 18:09:56 +00:00
|
|
|
int stream_enable_cache_defaults(stream_t **stream);
|
cache: make the stream cache a proper stream that wraps other streams
Before this commit, the cache was franken-hacked on top of the stream
API. You had to use special functions (like cache_stream_fill_buffer()
instead of stream_fill_buffer()), which would access the stream in a
cached manner.
The whole idea about the previous design was that the cache runs in a
thread or in a forked process, while the cache awa functions made sure
the stream instance looked consistent to the user. If you used the
normal functions instead of the special ones while the cache was
running, you were out of luck.
Make it a bit more reasonable by turning the cache into a stream on its
own. This makes it behave exactly like a normal stream. The stream
callbacks call into the original (uncached) stream to do work. No
special cache functions or redirections are needed. The only different
thing about cache streams is that they are created by special functions,
instead of being part of the auto_open_streams[] array.
To make things simpler, remove the threading implementation, which was
messed into the code. The threading code could perhaps be kept, but I
don't really want to have to worry about this special case. A proper
threaded implementation will be added later.
Remove the cache enabling code from stream_radio.c. Since enabling the
cache involves replacing the old stream with a new one, the code as-is
can't be kept. It would be easily possible to enable the cache by
requesting a cache size (which is also much simpler). But nobody uses
stream_radio.c and I can't even test this thing, and the cache is
probably not really important for it either.
2013-05-24 16:49:09 +00:00
|
|
|
|
|
|
|
// Internal
|
2014-05-19 21:27:09 +00:00
|
|
|
int stream_cache_init(stream_t *cache, stream_t *stream,
|
|
|
|
struct mp_cache_opts *opts);
|
2014-06-22 00:50:52 +00:00
|
|
|
int stream_file_cache_init(stream_t *cache, stream_t *stream,
|
|
|
|
struct mp_cache_opts *opts);
|
cache: make the stream cache a proper stream that wraps other streams
Before this commit, the cache was franken-hacked on top of the stream
API. You had to use special functions (like cache_stream_fill_buffer()
instead of stream_fill_buffer()), which would access the stream in a
cached manner.
The whole idea about the previous design was that the cache runs in a
thread or in a forked process, while the cache awa functions made sure
the stream instance looked consistent to the user. If you used the
normal functions instead of the special ones while the cache was
running, you were out of luck.
Make it a bit more reasonable by turning the cache into a stream on its
own. This makes it behave exactly like a normal stream. The stream
callbacks call into the original (uncached) stream to do work. No
special cache functions or redirections are needed. The only different
thing about cache streams is that they are created by special functions,
instead of being part of the auto_open_streams[] array.
To make things simpler, remove the threading implementation, which was
messed into the code. The threading code could perhaps be kept, but I
don't really want to have to worry about this special case. A proper
threaded implementation will be added later.
Remove the cache enabling code from stream_radio.c. Since enabling the
cache involves replacing the old stream with a new one, the code as-is
can't be kept. It would be easily possible to enable the cache by
requesting a cache size (which is also much simpler). But nobody uses
stream_radio.c and I can't even test this thing, and the cache is
probably not really important for it either.
2013-05-24 16:49:09 +00:00
|
|
|
|
2006-12-18 20:50:31 +00:00
|
|
|
int stream_write_buffer(stream_t *s, unsigned char *buf, int len);
|
2001-07-31 23:18:16 +00:00
|
|
|
|
2013-01-24 16:43:07 +00:00
|
|
|
inline static int stream_read_char(stream_t *s)
|
|
|
|
{
|
|
|
|
return (s->buf_pos < s->buf_len) ? s->buffer[s->buf_pos++] :
|
cache: make the stream cache a proper stream that wraps other streams
Before this commit, the cache was franken-hacked on top of the stream
API. You had to use special functions (like cache_stream_fill_buffer()
instead of stream_fill_buffer()), which would access the stream in a
cached manner.
The whole idea about the previous design was that the cache runs in a
thread or in a forked process, while the cache awa functions made sure
the stream instance looked consistent to the user. If you used the
normal functions instead of the special ones while the cache was
running, you were out of luck.
Make it a bit more reasonable by turning the cache into a stream on its
own. This makes it behave exactly like a normal stream. The stream
callbacks call into the original (uncached) stream to do work. No
special cache functions or redirections are needed. The only different
thing about cache streams is that they are created by special functions,
instead of being part of the auto_open_streams[] array.
To make things simpler, remove the threading implementation, which was
messed into the code. The threading code could perhaps be kept, but I
don't really want to have to worry about this special case. A proper
threaded implementation will be added later.
Remove the cache enabling code from stream_radio.c. Since enabling the
cache involves replacing the old stream with a new one, the code as-is
can't be kept. It would be easily possible to enable the cache by
requesting a cache size (which is also much simpler). But nobody uses
stream_radio.c and I can't even test this thing, and the cache is
probably not really important for it either.
2013-05-24 16:49:09 +00:00
|
|
|
(stream_fill_buffer(s) ? s->buffer[s->buf_pos++] : -256);
|
2001-04-22 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 16:43:07 +00:00
|
|
|
unsigned char *stream_read_line(stream_t *s, unsigned char *mem, int max,
|
|
|
|
int utf16);
|
2013-08-25 18:40:21 +00:00
|
|
|
int stream_skip_bom(struct stream *s);
|
2006-03-16 14:42:51 +00:00
|
|
|
|
2013-01-24 16:43:07 +00:00
|
|
|
inline static int stream_eof(stream_t *s)
|
|
|
|
{
|
|
|
|
return s->eof;
|
2001-04-22 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 16:43:07 +00:00
|
|
|
inline static int64_t stream_tell(stream_t *s)
|
|
|
|
{
|
|
|
|
return s->pos + s->buf_pos - s->buf_len;
|
2001-04-22 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-06 20:15:21 +00:00
|
|
|
bool stream_skip(stream_t *s, int64_t len);
|
|
|
|
bool stream_seek(stream_t *s, int64_t pos);
|
2013-05-24 09:56:49 +00:00
|
|
|
int stream_read(stream_t *s, char *mem, int total);
|
2013-05-27 19:53:40 +00:00
|
|
|
int stream_read_partial(stream_t *s, char *buf, int buf_size);
|
2013-06-21 19:06:36 +00:00
|
|
|
struct bstr stream_peek(stream_t *s, int len);
|
2013-12-13 23:51:00 +00:00
|
|
|
void stream_drop_buffers(stream_t *s);
|
2015-08-17 22:10:54 +00:00
|
|
|
int64_t stream_get_size(stream_t *s);
|
2001-04-22 16:56:20 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
struct mpv_global;
|
2013-06-11 10:16:42 +00:00
|
|
|
|
2011-02-25 16:10:00 +00:00
|
|
|
struct bstr stream_read_complete(struct stream *s, void *talloc_ctx,
|
2013-06-11 10:16:42 +00:00
|
|
|
int max_size);
|
2015-03-27 12:27:40 +00:00
|
|
|
struct bstr stream_read_file(const char *filename, void *talloc_ctx,
|
|
|
|
struct mpv_global *global, int max_size);
|
2006-03-01 21:56:30 +00:00
|
|
|
int stream_control(stream_t *s, int cmd, void *arg);
|
2001-04-22 16:56:20 +00:00
|
|
|
void free_stream(stream_t *s);
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
struct stream *stream_create(const char *url, int flags,
|
|
|
|
struct mp_cancel *c, struct mpv_global *global);
|
2013-12-21 19:36:45 +00:00
|
|
|
struct stream *stream_open(const char *filename, struct mpv_global *global);
|
|
|
|
stream_t *open_output_stream(const char *filename, struct mpv_global *global);
|
2013-06-20 22:47:58 +00:00
|
|
|
stream_t *open_memory_stream(void *data, int len);
|
2011-02-10 10:15:21 +00:00
|
|
|
|
2013-08-02 15:03:30 +00:00
|
|
|
void mp_url_unescape_inplace(char *buf);
|
2013-08-25 20:58:29 +00:00
|
|
|
char *mp_url_escape(void *talloc_ctx, const char *s, const char *ok);
|
2013-08-02 15:03:30 +00:00
|
|
|
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
struct mp_cancel *mp_cancel_new(void *talloc_ctx);
|
|
|
|
void mp_cancel_trigger(struct mp_cancel *c);
|
|
|
|
bool mp_cancel_test(struct mp_cancel *c);
|
2015-02-06 18:19:15 +00:00
|
|
|
bool mp_cancel_wait(struct mp_cancel *c, double timeout);
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
void mp_cancel_reset(struct mp_cancel *c);
|
2014-11-18 12:39:17 +00:00
|
|
|
void *mp_cancel_get_event(struct mp_cancel *c); // win32 HANDLE
|
lua: add an utility function for starting processes
Because 1) Lua is terrible, and 2) popen() is terrible. Unfortunately,
since Unix is also terrible, this turned out more complicated than I
hoped. As a consequence and to avoid that this code has to be maintained
forever, add a disclaimer that any function in Lua's utils module can
disappear any time. The complexity seems a bit ridiculous, especially
for a feature so far removed from actual video playback, so if it turns
out that we don't really need this function, it will be dropped again.
The motivation for this commit is the same as with 8e4fa5fc.
Note that there is an "#ifndef __GLIBC__". The GNU people are very
special people and thought it'd be convenient to actually declare
"environ", even though the POSIX people, which are also very special
people, state that no header declares this and that the user has to
declare this manually. Since the GNU people overtook the Unix world with
their very clever "embrace, extend, extinguish" strategy, but not 100%,
and trying to build without _GNU_SOURCE is hopeless; but since there
might be Unix environments which support _GNU_SOURCE features partially,
this means that in practice "environ" will be randomly declared or not
declared by system headers. Also, gcc was written by very clever people
too, and prints a warning if an external variable is declared twice (I
didn't check, but I suppose redeclaring is legal C, and not even the gcc
people are clever enough to only warn against a definitely not legal C
construct, although sometimes they do this), ...and since we at mpv hate
compiler warnings, we seek to silence them all. Adding a configure test
just for a warning seems too radical, so we special-case this against
__GLIBC__, which is hopefully not defined on other libcs, especially not
libcs which don't implement all aspects of _GNU_SOURCE, and redefine
"environ" on systems even if the headers define it already (because they
support _GNU_SOURCE - as I mentioned before, the clever GNU people wrote
software THAT portable that other libcs just gave up and implemented
parts of _GNU_SOURCE, although probably not all), which means that
compiling mpv will print a warning about "environ" being redefined, but
at least this won't happen on my system, so all is fine. However, should
someone complain about this warning, I will force whoever complained
about this warning to read this ENTIRE commit message, and if possible,
will also force them to eat a printed-out copy of the GNU Manifesto, and
if that is not enough, maybe this person could even be forced to
convince the very clever POSIX people of not doing crap like this:
having the user to manually declare somewhat central symbols - but I
doubt it's possible, because the POSIX people are too far gone and only
care about maintaining compatibility with old versions of AIX and HP-UX.
Oh, also, this code contains some subtle and obvious issues, but writing
about this is not fun.
2014-10-18 23:42:28 +00:00
|
|
|
int mp_cancel_get_fd(struct mp_cancel *c);
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
|
2014-01-08 20:46:42 +00:00
|
|
|
// stream_file.c
|
|
|
|
char *mp_file_url_to_filename(void *talloc_ctx, bstr url);
|
2014-09-25 21:38:23 +00:00
|
|
|
char *mp_file_get_path(void *talloc_ctx, bstr url);
|
2014-01-08 20:46:42 +00:00
|
|
|
|
2014-10-14 19:01:30 +00:00
|
|
|
// stream_lavf.c
|
|
|
|
struct AVDictionary;
|
|
|
|
void mp_setup_av_network_options(struct AVDictionary **dict,
|
|
|
|
struct mpv_global *global,
|
2016-09-06 18:09:56 +00:00
|
|
|
struct mp_log *log);
|
2014-10-14 19:01:30 +00:00
|
|
|
|
2014-06-30 10:49:01 +00:00
|
|
|
void stream_print_proto_list(struct mp_log *log);
|
2015-05-23 13:26:55 +00:00
|
|
|
char **stream_get_proto_list(void);
|
2016-08-07 16:10:05 +00:00
|
|
|
bool stream_has_proto(const char *proto);
|
2014-06-30 10:49:01 +00:00
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_STREAM_H */
|