From 52c3eb69765a0d1070bf240353095c8ff546765b Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 21:10:42 +0200 Subject: core: change open_stream and demux_open signature This removes the dependency on DEMUXER_TYPE_* and the file_format parameter from the stream open functions. Remove some of the playlist handling code. It looks like this was needed only for loading linked mov files with demux_mov (which was removed long ago). Delete a minor bit of dead network-related code from stream.c as well. --- stream/stream.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 3dc25d7880..32ae0047be 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -131,10 +131,8 @@ static stream_t *new_stream(size_t min_size); static int stream_seek_unbuffered(stream_t *s, int64_t newpos); static stream_t *open_stream_plugin(const stream_info_t *sinfo, - const char *filename, - int mode, struct MPOpts *options, - int *file_format, int *ret, - char **redirected_url) + const char *filename, int mode, + struct MPOpts *options, int *ret) { void *arg = NULL; stream_t *s; @@ -162,7 +160,7 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, s->url = strdup(filename); s->flags = 0; s->mode = mode; - *ret = sinfo->open(s, mode, arg, file_format); + *ret = sinfo->open(s, mode, arg); if ((*ret) != STREAM_OK) { free(s->url); talloc_free(s); @@ -201,21 +199,14 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, static stream_t *open_stream_full(const char *filename, int mode, - struct MPOpts *options, int *file_format) + struct MPOpts *options) { int i, j, l, r; const stream_info_t *sinfo; stream_t *s; - char *redirected_url = NULL; assert(filename); - int dummy; - if (!file_format) - file_format = &dummy; - - *file_format = DEMUXER_TYPE_UNKNOWN; - for (i = 0; auto_open_streams[i]; i++) { sinfo = auto_open_streams[i]; if (!sinfo->protocols) { @@ -230,22 +221,10 @@ static stream_t *open_stream_full(const char *filename, int mode, if ((l == 0 && !strstr(filename, "://")) || ((strncasecmp(sinfo->protocols[j], filename, l) == 0) && (strncmp("://", filename + l, 3) == 0))) { - *file_format = DEMUXER_TYPE_UNKNOWN; - s = - open_stream_plugin(sinfo, filename, mode, options, - file_format, - &r, - &redirected_url); + s = open_stream_plugin(sinfo, filename, mode, options, &r); if (s) return s; - if (r == STREAM_REDIRECTED && redirected_url) { - mp_msg(MSGT_OPEN, MSGL_V, "[%s] open %s redirected to %s\n", - sinfo->info, filename, redirected_url); - s = open_stream_full(redirected_url, mode, options, - file_format); - free(redirected_url); - return s; - } else if (r != STREAM_UNSUPPORTED) { + if (r != STREAM_UNSUPPORTED) { mp_tmsg(MSGT_OPEN, MSGL_ERR, "Failed to open %s.\n", filename); return NULL; @@ -259,15 +238,14 @@ static stream_t *open_stream_full(const char *filename, int mode, return NULL; } -stream_t *open_stream(const char *filename, struct MPOpts *options, - int *file_format) +struct stream *stream_open(const char *filename, struct MPOpts *options) { - return open_stream_full(filename, STREAM_READ, options, file_format); + return open_stream_full(filename, STREAM_READ, options); } stream_t *open_output_stream(const char *filename, struct MPOpts *options) { - return open_stream_full(filename, STREAM_WRITE, options, NULL); + return open_stream_full(filename, STREAM_WRITE, options); } static int stream_reconnect(stream_t *s) @@ -655,7 +633,7 @@ int stream_check_interrupt(int time) stream_t *open_memory_stream(void *data, int len) { assert(len >= 0); - stream_t *s = open_stream("memory://", NULL, NULL); + stream_t *s = stream_open("memory://", NULL); assert(s); stream_control(s, STREAM_CTRL_SET_CONTENTS, &(bstr){data, len}); return s; -- cgit v1.2.3 From 5c1b8d4aa1d35c806159cb22d52449774eb5186e Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:05:43 +0200 Subject: stream: don't require streams to set a type Set the type only for streams that have special treatment in other parts of the code. --- stream/stream.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 32ae0047be..39fc872169 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -175,8 +175,6 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, s->cache_size = 320; } - if (s->type <= -2) - mp_msg(MSGT_OPEN, MSGL_WARN, "Warning streams need a type !!!!\n"); if (!s->seek) s->flags &= ~MP_STREAM_SEEK; if (s->seek && !(s->flags & MP_STREAM_SEEK)) @@ -595,7 +593,6 @@ static stream_t *new_stream(size_t min_size) memset(s, 0, sizeof(stream_t)); s->fd = -2; - s->type = -2; return s; } @@ -672,7 +669,6 @@ int stream_enable_cache(stream_t **stream, int64_t size, int64_t min, orig->buf_len = orig->buf_pos = 0; stream_t *cache = new_stream(0); - cache->type = STREAMTYPE_CACHE; cache->uncached_type = orig->type; cache->uncached_stream = orig; cache->flags |= MP_STREAM_SEEK; -- cgit v1.2.3 From b66c609b4826059d348f6e1c049a34cc43415383 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:06:14 +0200 Subject: stream: use talloc for some string members Minor simplification. --- stream/stream.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 39fc872169..ead4a55b3d 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -157,12 +157,11 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, } s = new_stream(0); s->opts = options; - s->url = strdup(filename); + s->url = talloc_strdup(s, filename); s->flags = 0; s->mode = mode; *ret = sinfo->open(s, mode, arg); if ((*ret) != STREAM_OK) { - free(s->url); talloc_free(s); return NULL; } @@ -598,6 +597,9 @@ static stream_t *new_stream(size_t min_size) void free_stream(stream_t *s) { + if (!s) + return; + stream_set_capture_file(s, NULL); if (s->close) @@ -605,9 +607,7 @@ void free_stream(stream_t *s) if (s->fd > 0) { close(s->fd); } - free(s->url); - if (s->uncached_stream) - free_stream(s->uncached_stream); + free_stream(s->uncached_stream); talloc_free(s); } @@ -675,9 +675,9 @@ int stream_enable_cache(stream_t **stream, int64_t size, int64_t min, cache->mode = STREAM_READ; cache->read_chunk = 4 * STREAM_BUFFER_SIZE; - cache->url = strdup(orig->url); + cache->url = talloc_strdup(cache, orig->url); cache->mime_type = talloc_strdup(cache, orig->mime_type); - cache->lavf_type = orig->lavf_type; + cache->lavf_type = talloc_strdup(cache, orig->lavf_type); cache->opts = orig->opts; cache->start_pos = orig->start_pos; cache->end_pos = orig->end_pos; -- cgit v1.2.3 From f63193f58f7214ef3a4f82be045f8a3cfd14b8ac Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:07:07 +0200 Subject: stream: remove fd member Stream implementations could set this to a unix file descriptor. The generic stream code could use it as fallback for a few things. This was confusing and insane. In most cases, the stream implementations defined all callbacks, so setting the fd member didn't have any advantages, other than avoiding defining a private struct to store it. It appears that even if the stream implementation used close() on the fd (or something equivalent), stream.c would close() it a second time (and on windows, even would call closesocket()), which should be proof for the insanity of this code. For stream_file.c, additionally make sure we don't close stdin or stdout if "-" is used as filename. For stream_vcd.c, remove the control() code. This code most likely didn't make the slightest sense, because it used a different type for stream->priv. It also leaked memory. Maybe it worked, but it's incorrect and insignificant anyway, so kill it. This code was added with commit 9521c19 (svn commit 31019). Untested for all protocols other than stream_file.c. --- stream/stream.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index ead4a55b3d..1e53b75c4e 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -315,13 +315,7 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) int orig_len = len; s->buf_pos = s->buf_len = 0; // we will retry even if we already reached EOF previously. - if (s->fill_buffer) { - len = s->fill_buffer(s, buf, len); - } else if (s->fd >= 0) { - len = read(s->fd, buf, len); - } else { - len = 0; - } + len = s->fill_buffer ? s->fill_buffer(s, buf, len) : -1; if (len < 0) len = 0; if (len == 0) { @@ -590,8 +584,6 @@ static stream_t *new_stream(size_t min_size) min_size = FFMAX(min_size, TOTAL_BUFFER_SIZE); stream_t *s = talloc_size(NULL, sizeof(stream_t) + min_size); memset(s, 0, sizeof(stream_t)); - - s->fd = -2; return s; } @@ -604,9 +596,6 @@ void free_stream(stream_t *s) if (s->close) s->close(s); - if (s->fd > 0) { - close(s->fd); - } free_stream(s->uncached_stream); talloc_free(s); } -- cgit v1.2.3 From f406482d84b8597235e17bedfb7539a5863d869e Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:11:08 +0200 Subject: stream: remove useless author/comment fields These were printed only with -v. Most streams had them set to useless or redundant values, so it's just badly maintained bloat. Since we remove the "author" field too, and since this may have copyright implications, we add the contents of the author fields to the file headers, except if the name is already part of the file header. --- stream/stream.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 1e53b75c4e..7716e51a56 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -183,10 +183,7 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo, s->uncached_type = s->type; - mp_msg(MSGT_OPEN, MSGL_V, "STREAM: [%s] %s\n", sinfo->name, filename); - mp_msg(MSGT_OPEN, MSGL_V, "STREAM: Description: %s\n", sinfo->info); - mp_msg(MSGT_OPEN, MSGL_V, "STREAM: Author: %s\n", sinfo->author); - mp_msg(MSGT_OPEN, MSGL_V, "STREAM: Comment: %s\n", sinfo->comment); + mp_msg(MSGT_OPEN, MSGL_V, "[stream] [%s] %s\n", sinfo->name, filename); if (s->mime_type) mp_msg(MSGT_OPEN, MSGL_V, "Mime-type: '%s'\n", s->mime_type); -- cgit v1.2.3