summaryrefslogtreecommitdiffstats
path: root/stream/stream_file.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-02 17:02:34 +0200
committerwm4 <wm4@nowhere>2013-08-02 17:02:34 +0200
commitbc1d61cf4296ab41564adb896e454e48c292e451 (patch)
tree461dfa0cb61af73b62838608aa8fbb3dd99d3642 /stream/stream_file.c
parent964194b55bf86d7c8b76febe8bf54c49648e79c1 (diff)
downloadmpv-bc1d61cf4296ab41564adb896e454e48c292e451.tar.bz2
mpv-bc1d61cf4296ab41564adb896e454e48c292e451.tar.xz
stream: redo URL parsing, replace m_struct usage with m_config
Move the URL parsing code from m_option.c to stream.c, and simplify it dramatically. This code originates from times when http code used this, but now it's just relict from other stream implementations reusing this code. Remove the unused bits and simplify the rest. stream_vcd is insane, and the priv struct is different on every platform, so drop the URL parsing. This means you can't specify a track anymore, only the device. (Does anyone use stream_vcd? Not like this couldn't be fixed, but it doesn't seem worth the effort, especially because it'd require potentially touching platform specific code.)
Diffstat (limited to 'stream/stream_file.c')
-rw-r--r--stream/stream_file.c45
1 files changed, 2 insertions, 43 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c
index b9e4f2f2e1..dc85314f71 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -32,34 +32,12 @@
#include "core/mp_msg.h"
#include "stream.h"
#include "core/m_option.h"
-#include "core/m_struct.h"
struct priv {
int fd;
bool close;
};
-static struct stream_priv_s {
- char* filename;
- char *filename2;
-} stream_priv_dflts = {
- NULL, NULL
-};
-
-#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
-/// URL definition
-static const m_option_t stream_opts_fields[] = {
- {"string", ST_OFF(filename), CONF_TYPE_STRING, 0, 0 ,0, NULL},
- {"filename", ST_OFF(filename2), CONF_TYPE_STRING, 0, 0 ,0, NULL},
- { NULL, NULL, 0, 0, 0, 0, NULL }
-};
-static const struct m_struct_st stream_opts = {
- "file",
- sizeof(struct stream_priv_s),
- &stream_priv_dflts,
- stream_opts_fields
-};
-
static int fill_buffer(stream_t *s, char* buffer, int max_len){
struct priv *p = s->priv;
int r = read(p->fd,buffer,max_len);
@@ -128,13 +106,12 @@ static void s_close(stream_t *s)
close(p->fd);
}
-static int open_f(stream_t *stream,int mode, void* opts)
+static int open_f(stream_t *stream, int mode)
{
int f;
mode_t m = 0;
int64_t len;
- unsigned char *filename;
- struct stream_priv_s* p = (struct stream_priv_s*)opts;
+ char *filename = stream->path;
struct priv *priv = talloc_ptrtype(stream, priv);
*priv = (struct priv) { .fd = -1 };
stream->priv = priv;
@@ -145,22 +122,9 @@ static int open_f(stream_t *stream,int mode, void* opts)
m = O_RDWR|O_CREAT|O_TRUNC;
else {
mp_msg(MSGT_OPEN,MSGL_ERR, "[file] Unknown open mode %d\n",mode);
- m_struct_free(&stream_opts,opts);
return STREAM_UNSUPPORTED;
}
- if(p->filename)
- filename = p->filename;
- else if(p->filename2)
- filename = p->filename2;
- else
- filename = NULL;
- if(!filename) {
- mp_msg(MSGT_OPEN,MSGL_ERR, "[file] No filename\n");
- m_struct_free(&stream_opts,opts);
- return STREAM_ERROR;
- }
-
#if HAVE_DOS_PATHS
// extract '/' from '/x:/path'
if( filename[ 0 ] == '/' && filename[ 1 ] && filename[ 2 ] == ':' )
@@ -195,7 +159,6 @@ static int open_f(stream_t *stream,int mode, void* opts)
if(f<0) {
mp_tmsg(MSGT_OPEN, MSGL_ERR, "Cannot open file '%s': %s\n", filename,
strerror(errno));
- m_struct_free(&stream_opts,opts);
return STREAM_ERROR;
}
#ifndef __MINGW32__
@@ -203,7 +166,6 @@ static int open_f(stream_t *stream,int mode, void* opts)
if (fstat(f, &st) == 0 && S_ISDIR(st.st_mode)) {
mp_tmsg(MSGT_OPEN,MSGL_ERR,"File is a directory: '%s'\n",filename);
close(f);
- m_struct_free(&stream_opts,opts);
return STREAM_ERROR;
}
#endif
@@ -234,7 +196,6 @@ static int open_f(stream_t *stream,int mode, void* opts)
stream->read_chunk = 64*1024;
stream->close = s_close;
- m_struct_free(&stream_opts,opts);
return STREAM_OK;
}
@@ -242,6 +203,4 @@ const stream_info_t stream_info_file = {
"file",
open_f,
{ "file", "", NULL },
- &stream_opts,
- 1 // Urls are an option string
};