summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-12-23 11:09:42 +0100
committerwm4 <wm4@nowhere>2019-12-23 11:09:42 +0100
commit36da3325a3ee51a22c21ebc6492f243fafc3c95f (patch)
tree512deaa94e9a2836c645490de8d76d529619ec4b /demux/demux_lavf.c
parentaf6652004d5f712e140996a17c683d437f4b8bb3 (diff)
downloadmpv-36da3325a3ee51a22c21ebc6492f243fafc3c95f.tar.bz2
mpv-36da3325a3ee51a22c21ebc6492f243fafc3c95f.tar.xz
demux: stop setting dummy stream on demux_close_stream()
Demuxers can call demux_close_stream() to close the underlying stream if it's not needed anymore. (Useful to release "heavy" resources like FDs and sockets. Plus merely keeping a file open can have visible side effects such as inability to unmount a filesystem or, on Windows, to do anything with the file.) Until now, this set demuxer->stream to a dummy stream, because most code used to assume that the stream field is non-NULL. But this requirement disappeared (in some cases, the stream field is already NULL), so stop doing that. demux_lavf.c, one of the demuxers which calls this function, still had some of this, though.
Diffstat (limited to 'demux/demux_lavf.c')
-rw-r--r--demux/demux_lavf.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 374714b769..c2f6a65395 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -290,6 +290,8 @@ static int mp_read(void *opaque, uint8_t *buf, int size)
struct demuxer *demuxer = opaque;
lavf_priv_t *priv = demuxer->priv;
struct stream *stream = priv->stream;
+ if (!stream)
+ return 0;
int ret = stream_read_partial(stream, buf, size);
@@ -303,6 +305,8 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence)
struct demuxer *demuxer = opaque;
lavf_priv_t *priv = demuxer->priv;
struct stream *stream = priv->stream;
+ if (!stream)
+ return -1;
MP_TRACE(demuxer, "mp_seek(%p, %"PRId64", %s)\n", stream, pos,
whence == SEEK_END ? "end" :
@@ -345,7 +349,7 @@ static int64_t mp_read_seek(void *opaque, int stream_idx, int64_t ts, int flags)
.flags = flags,
};
- if (stream_control(stream, STREAM_CTRL_AVSEEK, &cmd) == STREAM_OK) {
+ if (stream && stream_control(stream, STREAM_CTRL_AVSEEK, &cmd) == STREAM_OK) {
stream_drop_buffers(stream);
return 0;
}
@@ -1106,7 +1110,7 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
if (priv->own_stream)
free_stream(priv->stream);
priv->own_stream = false;
- priv->stream = demuxer->stream;
+ priv->stream = NULL;
}
return 0;
@@ -1227,7 +1231,7 @@ static void demux_seek_lavf(demuxer_t *demuxer, double seek_pts, int flags)
if (flags & SEEK_FACTOR) {
struct stream *s = priv->stream;
- int64_t end = stream_get_size(s);
+ int64_t end = s ? stream_get_size(s) : -1;
if (end > 0 && demuxer->ts_resets_possible &&
!(priv->avif_flags & AVFMT_NO_BYTE_SEEK))
{