summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-21 00:47:58 +0200
committerwm4 <wm4@nowhere>2013-06-25 00:11:54 +0200
commit4d33197547ec0334eb64d02b65b907b6a6dd107f (patch)
tree4a1d30b41d311eedc1f19bb90e662a1f3a4b310c /stream
parentdb2e1ef4d210f5a8a4a2555d0a78b0a4dea103ec (diff)
downloadmpv-4d33197547ec0334eb64d02b65b907b6a6dd107f.tar.bz2
mpv-4d33197547ec0334eb64d02b65b907b6a6dd107f.tar.xz
stream: readd memory streams
Diffstat (limited to 'stream')
-rw-r--r--stream/stream.c25
-rw-r--r--stream/stream.h1
2 files changed, 21 insertions, 5 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 99ae6ed103..ba05202b53 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -137,7 +137,7 @@ static const stream_info_t *const auto_open_streams[] = {
NULL
};
-static stream_t *new_stream(void);
+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,
@@ -167,7 +167,7 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo,
}
}
}
- s = new_stream();
+ s = new_stream(0);
s->opts = options;
s->url = strdup(filename);
s->flags |= mode;
@@ -647,9 +647,10 @@ void stream_update_size(stream_t *s)
}
}
-static stream_t *new_stream(void)
+static stream_t *new_stream(size_t min_size)
{
- stream_t *s = talloc_size(NULL, sizeof(stream_t) + TOTAL_BUFFER_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));
#if HAVE_WINSOCK2_H
@@ -706,6 +707,20 @@ int stream_check_interrupt(int time)
return stream_check_interrupt_cb(stream_check_interrupt_ctx, time);
}
+stream_t *open_memory_stream(void *data, int len)
+{
+ assert(len >= 0);
+ stream_t *s = new_stream(len);
+
+ s->buf_pos = 0;
+ s->buf_len = len;
+ s->start_pos = 0;
+ s->end_pos = len;
+ s->pos = len;
+ memcpy(s->buffer, data, len);
+ return s;
+}
+
int stream_enable_cache_percent(stream_t **stream, int64_t stream_cache_size,
float stream_cache_min_percent,
float stream_cache_seek_min_percent)
@@ -738,7 +753,7 @@ int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
// Can't handle a loaded buffer.
orig->buf_len = orig->buf_pos = 0;
- stream_t *cache = new_stream();
+ stream_t *cache = new_stream(0);
cache->type = STREAMTYPE_CACHE;
cache->uncached_type = orig->type;
cache->uncached_stream = orig;
diff --git a/stream/stream.h b/stream/stream.h
index aa1f943c4a..cee7fdc248 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -308,6 +308,7 @@ void free_stream(stream_t *s);
stream_t *open_stream(const char *filename, struct MPOpts *options,
int *file_format);
stream_t *open_output_stream(const char *filename, struct MPOpts *options);
+stream_t *open_memory_stream(void *data, int len);
struct demux_stream;
/// Set the callback to be used by libstream to check for user