mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
stream: remove chaos related to writeable streams
For some reason, we support writeable streams. (Only encoding uses that, and the use of it looks messy enough that I want to replace it with FILE or avio today.) It's a chaos: most streams do not actually check the mode parameter like they should. Simplify it, and let streams signal availability of write mode by setting a flag in the stream info struct.
This commit is contained in:
parent
80cbb3bac2
commit
aa87c143cb
@ -289,6 +289,13 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying,
|
||||
s->path = talloc_strdup(s, path);
|
||||
s->source = underlying;
|
||||
s->allow_caching = true;
|
||||
s->mode = flags & (STREAM_READ | STREAM_WRITE);
|
||||
|
||||
if ((s->mode & STREAM_WRITE) && !sinfo->can_write) {
|
||||
MP_ERR(s, "No write access implemented.\n");
|
||||
talloc_free(s);
|
||||
return STREAM_ERROR;
|
||||
}
|
||||
|
||||
// Parse options
|
||||
if (sinfo->priv_size) {
|
||||
@ -306,8 +313,7 @@ static int open_internal(const stream_info_t *sinfo, struct stream *underlying,
|
||||
}
|
||||
}
|
||||
|
||||
s->mode = flags & (STREAM_READ | STREAM_WRITE);
|
||||
int r = sinfo->open(s, s->mode);
|
||||
int r = sinfo->open(s);
|
||||
if (r != STREAM_OK) {
|
||||
talloc_free(s);
|
||||
return r;
|
||||
|
@ -110,13 +110,14 @@ struct stream;
|
||||
typedef struct stream_info_st {
|
||||
const char *name;
|
||||
// opts is set from ->opts
|
||||
int (*open)(struct stream *st, int mode);
|
||||
int (*open)(struct stream *st);
|
||||
const char **protocols;
|
||||
int priv_size;
|
||||
const void *priv_defaults;
|
||||
const struct m_option *options;
|
||||
const char **url_options;
|
||||
bool stream_filter;
|
||||
bool can_write;
|
||||
} stream_info_t;
|
||||
|
||||
typedef struct stream {
|
||||
|
@ -20,11 +20,8 @@
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
static int open_f(stream_t *stream, int mode)
|
||||
static int open_f(stream_t *stream)
|
||||
{
|
||||
if (mode != STREAM_READ)
|
||||
return STREAM_ERROR;
|
||||
|
||||
stream->type = STREAMTYPE_AVDEVICE;
|
||||
stream->demuxer = "lavf";
|
||||
|
||||
|
@ -712,7 +712,7 @@ static void select_initial_angle(stream_t *s) {
|
||||
bd_free_title_info(info);
|
||||
}
|
||||
|
||||
static int bluray_stream_open(stream_t *s, int mode)
|
||||
static int bluray_stream_open(stream_t *s)
|
||||
{
|
||||
struct bluray_priv_s *b = s->priv;
|
||||
|
||||
|
@ -283,7 +283,7 @@ static int control(stream_t *stream, int cmd, void *arg)
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static int open_cdda(stream_t *st, int m)
|
||||
static int open_cdda(stream_t *st)
|
||||
{
|
||||
cdda_priv *priv = st->priv;
|
||||
cdda_priv *p = priv;
|
||||
@ -292,10 +292,6 @@ static int open_cdda(stream_t *st, int m)
|
||||
cdrom_drive_t *cdd = NULL;
|
||||
int last_track;
|
||||
|
||||
if (m != STREAM_READ) {
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (!p->device) {
|
||||
if (cdrom_device)
|
||||
p->device = talloc_strdup(NULL, cdrom_device);
|
||||
|
@ -627,7 +627,7 @@ static int dvb_streaming_start(stream_t *stream, int tuner_type, char *progname)
|
||||
|
||||
|
||||
|
||||
static int dvb_open(stream_t *stream, int mode)
|
||||
static int dvb_open(stream_t *stream)
|
||||
{
|
||||
// I don't force the file format bacause, although it's almost always TS,
|
||||
// there are some providers that stream an IP multicast with M$ Mpeg4 inside
|
||||
@ -637,10 +637,6 @@ static int dvb_open(stream_t *stream, int mode)
|
||||
char *progname;
|
||||
int tuner_type = 0, i;
|
||||
|
||||
|
||||
if(mode != STREAM_READ)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
||||
priv->fe_fd = priv->sec_fd = priv->dvr_fd = -1;
|
||||
priv->config = dvb_get_config(stream);
|
||||
if(priv->config == NULL)
|
||||
|
@ -663,7 +663,7 @@ static int control(stream_t *stream,int cmd,void* arg)
|
||||
}
|
||||
|
||||
|
||||
static int open_s(stream_t *stream, int mode)
|
||||
static int open_s(stream_t *stream)
|
||||
{
|
||||
int k;
|
||||
dvd_priv_t *d = stream->priv;
|
||||
@ -932,7 +932,7 @@ fail:
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static int ifo_stream_open (stream_t *stream, int mode)
|
||||
static int ifo_stream_open (stream_t *stream)
|
||||
{
|
||||
char* filename;
|
||||
dvd_priv_t *priv = talloc_ptrtype(stream, priv);
|
||||
@ -963,7 +963,7 @@ static int ifo_stream_open (stream_t *stream, int mode)
|
||||
free(filename);
|
||||
stream->url=talloc_strdup(stream, "dvd://");
|
||||
|
||||
return open_s(stream, mode);
|
||||
return open_s(stream);
|
||||
}
|
||||
|
||||
const stream_info_t stream_info_dvd = {
|
||||
|
@ -664,7 +664,7 @@ static struct priv *new_dvdnav_stream(stream_t *stream, char *filename)
|
||||
return priv;
|
||||
}
|
||||
|
||||
static int open_s(stream_t *stream, int mode)
|
||||
static int open_s(stream_t *stream)
|
||||
{
|
||||
struct priv *priv, *p;
|
||||
priv = p = stream->priv;
|
||||
|
@ -3,11 +3,8 @@
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
static int s_open (struct stream *stream, int mode)
|
||||
static int s_open (struct stream *stream)
|
||||
{
|
||||
if (mode != STREAM_READ)
|
||||
return STREAM_ERROR;
|
||||
|
||||
stream->type = STREAMTYPE_EDL;
|
||||
stream->demuxer = "edl";
|
||||
|
||||
|
@ -204,7 +204,7 @@ static bool check_stream_network(stream_t *stream)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int open_f(stream_t *stream, int mode)
|
||||
static int open_f(stream_t *stream)
|
||||
{
|
||||
int fd;
|
||||
struct priv *priv = talloc_ptrtype(stream, priv);
|
||||
@ -213,15 +213,8 @@ static int open_f(stream_t *stream, int mode)
|
||||
};
|
||||
stream->priv = priv;
|
||||
|
||||
int m = O_CLOEXEC;
|
||||
if (mode == STREAM_READ)
|
||||
m |= O_RDONLY;
|
||||
else if (mode == STREAM_WRITE)
|
||||
m |= O_RDWR | O_CREAT | O_TRUNC;
|
||||
else {
|
||||
MP_ERR(stream, "Unknown open mode %d\n", mode);
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
bool write = stream->mode == STREAM_WRITE;
|
||||
int m = O_CLOEXEC | (write ? O_RDWR | O_CREAT | O_TRUNC : O_RDONLY);
|
||||
|
||||
char *filename = mp_file_url_to_filename(stream, bstr0(stream->url));
|
||||
if (filename) {
|
||||
@ -231,7 +224,7 @@ static int open_f(stream_t *stream, int mode)
|
||||
}
|
||||
|
||||
if (!strcmp(filename, "-")) {
|
||||
if (mode == STREAM_READ) {
|
||||
if (!write) {
|
||||
MP_INFO(stream, "Reading from stdin...\n");
|
||||
fd = 0;
|
||||
#if HAVE_SETMODE
|
||||
@ -301,4 +294,5 @@ const stream_info_t stream_info_file = {
|
||||
.name = "file",
|
||||
.open = open_f,
|
||||
.protocols = (const char*[]){ "file", "", NULL },
|
||||
.can_write = true,
|
||||
};
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "bstr/bstr.h"
|
||||
#include "talloc.h"
|
||||
|
||||
static int open_f(stream_t *stream, int mode);
|
||||
static int open_f(stream_t *stream);
|
||||
static char **read_icy(stream_t *stream);
|
||||
|
||||
static int fill_buffer(stream_t *s, char *buffer, int max_len)
|
||||
@ -113,7 +113,7 @@ static int control(stream_t *s, int cmd, void *arg)
|
||||
// avio doesn't seem to support this - emulate it by reopening
|
||||
close_f(s);
|
||||
s->priv = NULL;
|
||||
return open_f(s, STREAM_READ);
|
||||
return open_f(s);
|
||||
}
|
||||
}
|
||||
return STREAM_UNSUPPORTED;
|
||||
@ -127,10 +127,9 @@ static int interrupt_cb(void *ctx)
|
||||
|
||||
static const char * const prefix[] = { "lavf://", "ffmpeg://" };
|
||||
|
||||
static int open_f(stream_t *stream, int mode)
|
||||
static int open_f(stream_t *stream)
|
||||
{
|
||||
struct MPOpts *opts = stream->opts;
|
||||
int flags = 0;
|
||||
AVIOContext *avio = NULL;
|
||||
int res = STREAM_ERROR;
|
||||
AVDictionary *dict = NULL;
|
||||
@ -139,15 +138,7 @@ static int open_f(stream_t *stream, int mode)
|
||||
stream->seek = NULL;
|
||||
stream->seekable = false;
|
||||
|
||||
if (mode == STREAM_READ)
|
||||
flags = AVIO_FLAG_READ;
|
||||
else if (mode == STREAM_WRITE)
|
||||
flags = AVIO_FLAG_WRITE;
|
||||
else {
|
||||
MP_ERR(stream, "Unknown open mode %d\n", mode);
|
||||
res = STREAM_UNSUPPORTED;
|
||||
goto out;
|
||||
}
|
||||
int flags = stream->mode == STREAM_WRITE ? AVIO_FLAG_WRITE : AVIO_FLAG_READ;
|
||||
|
||||
const char *filename = stream->url;
|
||||
if (!filename) {
|
||||
@ -330,4 +321,5 @@ const stream_info_t stream_info_ffmpeg = {
|
||||
"rtmpt", "rtmpte", "rtmpts", "srtp", "tcp", "udp", "tls", "unix", "sftp",
|
||||
"md5",
|
||||
NULL },
|
||||
.can_write = true,
|
||||
};
|
||||
|
@ -55,7 +55,7 @@ static int control(stream_t *s, int cmd, void *arg)
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static int open_f(stream_t *stream, int mode)
|
||||
static int open_f(stream_t *stream)
|
||||
{
|
||||
stream->fill_buffer = fill_buffer;
|
||||
stream->seek = seek;
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "stream.h"
|
||||
|
||||
static int
|
||||
mf_stream_open (stream_t *stream, int mode)
|
||||
mf_stream_open (stream_t *stream)
|
||||
{
|
||||
stream->type = STREAMTYPE_MF;
|
||||
stream->demuxer = "mf";
|
||||
|
@ -25,14 +25,14 @@
|
||||
|
||||
#include "stream.h"
|
||||
|
||||
static int open_s(stream_t *stream,int mode)
|
||||
static int open_s(stream_t *stream)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const stream_info_t stream_info_null = {
|
||||
.name = "null",
|
||||
.open = open_s,
|
||||
.protocols = (const char*[]){ "null", NULL },
|
||||
.can_write = true,
|
||||
};
|
||||
|
@ -1510,15 +1510,12 @@ pvr_stream_read (stream_t *stream, char *buffer, int size)
|
||||
}
|
||||
|
||||
static int
|
||||
pvr_stream_open (stream_t *stream, int mode)
|
||||
pvr_stream_open (stream_t *stream)
|
||||
{
|
||||
struct v4l2_capability vcap;
|
||||
struct v4l2_ext_controls ctrls;
|
||||
struct pvr_t *pvr = NULL;
|
||||
|
||||
if (mode != STREAM_READ)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
||||
pvr = pvr_init ();
|
||||
pvr->log = stream->log;
|
||||
|
||||
|
@ -86,7 +86,7 @@ static int rar_entry_control(stream_t *s, int cmd, void *arg)
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
static int rar_entry_open(stream_t *stream, int mode)
|
||||
static int rar_entry_open(stream_t *stream)
|
||||
{
|
||||
if (!strchr(stream->path, '|'))
|
||||
return STREAM_ERROR;
|
||||
@ -158,11 +158,8 @@ static void rar_filter_close(stream_t *s)
|
||||
free_stream(m);
|
||||
}
|
||||
|
||||
static int rar_filter_open(stream_t *stream, int mode)
|
||||
static int rar_filter_open(stream_t *stream)
|
||||
{
|
||||
if (mode != STREAM_READ)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
||||
struct stream *rar = stream->source;
|
||||
if (!rar)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
@ -87,10 +87,9 @@ static void close_f(stream_t *s){
|
||||
smbc_close(p->fd);
|
||||
}
|
||||
|
||||
static int open_f (stream_t *stream, int mode)
|
||||
static int open_f (stream_t *stream)
|
||||
{
|
||||
char *filename;
|
||||
mode_t m = 0;
|
||||
int64_t len;
|
||||
int fd, err;
|
||||
|
||||
@ -99,14 +98,7 @@ static int open_f (stream_t *stream, int mode)
|
||||
|
||||
filename = stream->url;
|
||||
|
||||
if(mode == STREAM_READ)
|
||||
m = O_RDONLY;
|
||||
else if (mode == STREAM_WRITE) //who's gonna do that ?
|
||||
m = O_RDWR|O_CREAT|O_TRUNC;
|
||||
else {
|
||||
MP_ERR(stream, "[smb] Unknown open mode %d\n", mode);
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
mode_t m = stream->mode == STREAM_WRITE ? O_RDWR|O_CREAT|O_TRUNC : O_RDONLY;
|
||||
|
||||
if(!filename) {
|
||||
MP_ERR(stream, "[smb] Bad url\n");
|
||||
@ -149,4 +141,5 @@ const stream_info_t stream_info_smb = {
|
||||
.name = "smb",
|
||||
.open = open_f,
|
||||
.protocols = (const char*[]){"smb", NULL},
|
||||
.can_write = true, //who's gonna do that?
|
||||
};
|
||||
|
@ -86,7 +86,7 @@ tv_stream_close (stream_t *stream)
|
||||
{
|
||||
}
|
||||
static int
|
||||
tv_stream_open (stream_t *stream, int mode)
|
||||
tv_stream_open (stream_t *stream)
|
||||
{
|
||||
|
||||
stream->type = STREAMTYPE_TV;
|
||||
|
@ -78,7 +78,7 @@ static void close_s(stream_t *stream) {
|
||||
free(stream->priv);
|
||||
}
|
||||
|
||||
static int open_s(stream_t *stream,int mode)
|
||||
static int open_s(stream_t *stream)
|
||||
{
|
||||
int ret,ret2,f,sect,tmp;
|
||||
mp_vcd_priv_t* vcd;
|
||||
@ -90,14 +90,6 @@ static int open_s(stream_t *stream,int mode)
|
||||
char device[20] = "\\\\.\\?:";
|
||||
#endif
|
||||
|
||||
if(mode != STREAM_READ
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
|| GetVersion() > 0x80000000 // Win9x
|
||||
#endif
|
||||
) {
|
||||
return STREAM_UNSUPPORTED;
|
||||
}
|
||||
|
||||
char *dev = stream->url;
|
||||
if (strncmp("vcd://", dev, 6) != 0)
|
||||
return STREAM_UNSUPPORTED;
|
||||
|
Loading…
Reference in New Issue
Block a user