diff options
author | wm4 <wm4@nowhere> | 2015-08-18 00:10:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-08-18 00:10:54 +0200 |
commit | cf2fa9d3e5bd6b8ca3e1637080b665e896ea60a0 (patch) | |
tree | 1de6ea60ee9f38ad5b7b66d7d15ee7a806a1520b /stream/stream.c | |
parent | bf5eac8dd3f142acd0d506407f1ae853ada3c5bc (diff) | |
download | mpv-cf2fa9d3e5bd6b8ca3e1637080b665e896ea60a0.tar.bz2 mpv-cf2fa9d3e5bd6b8ca3e1637080b665e896ea60a0.tar.xz |
stream: provide a stream_get_size() convenience function
And use it everywhere, instead of retrieving the size manually. Slight
simplification.
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/stream/stream.c b/stream/stream.c index 48ae58d639..4f8ee119fb 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -468,8 +468,7 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len) // just in case this is an error e.g. due to network // timeout reset and retry // do not retry if this looks like proper eof - int64_t size = -1; - stream_control(s, STREAM_CTRL_GET_SIZE, &size); + int64_t size = stream_get_size(s); if (!s->eof && s->pos != size && stream_reconnect(s)) { s->eof = 1; // make sure EOF is set to ensure no endless recursion return stream_read_unbuffered(s, buf, orig_len); @@ -702,6 +701,15 @@ int stream_control(stream_t *s, int cmd, void *arg) return s->control ? s->control(s, cmd, arg) : STREAM_UNSUPPORTED; } +// Return the current size of the stream, or a negative value if unknown. +int64_t stream_get_size(stream_t *s) +{ + int64_t size = -1; + if (stream_control(s, STREAM_CTRL_GET_SIZE, &size) != STREAM_OK) + size = -1; + return size; +} + void free_stream(stream_t *s) { if (!s) @@ -908,8 +916,7 @@ struct bstr stream_read_complete(struct stream *s, void *talloc_ctx, int total_read = 0; int padding = 1; char *buf = NULL; - int64_t size = 0; - stream_control(s, STREAM_CTRL_GET_SIZE, &size); + int64_t size = stream_get_size(s); if (size > max_size) return (struct bstr){NULL, 0}; if (size > 0) |