summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-24 14:04:09 +0200
committerwm4 <wm4@nowhere>2014-05-24 16:17:51 +0200
commita4d487f5b2930611bf908243510d6f0351ebcf58 (patch)
tree000fc31412c31ea60ef0b7c59af087e6402b4541 /demux
parente3c20bf3505679641f247471603ad298d04036bd (diff)
downloadmpv-a4d487f5b2930611bf908243510d6f0351ebcf58.tar.bz2
mpv-a4d487f5b2930611bf908243510d6f0351ebcf58.tar.xz
stream: don't use end_pos
Stop using it in most places, and prefer STREAM_CTRL_GET_SIZE. The advantage is that always the correct size will be used. There can be no doubt anymore whether the end_pos value is outdated (as it happens often with files that are being downloaded). Some streams still use end_pos. They don't change size, and it's easier to emulate STREAM_CTRL_GET_SIZE using end_pos, instead of adding a STREAM_CTRL_GET_SIZE implementation to these streams. Make sure int64_t is always used for STREAM_CTRL_GET_SIZE (it was uint64_t before). Remove the seek flags mess, and replace them with a seekable flag. Every stream must set it consistently now, and an assertion in stream.c checks this. Don't distinguish between streams that can only be forward or backwards seeked, since we have no such stream types.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c3
-rw-r--r--demux/demux_lavf.c25
-rw-r--r--demux/demux_mkv.c17
-rw-r--r--demux/demux_raw.c9
4 files changed, 32 insertions, 22 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 4da1adb134..ba231b5af6 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -587,8 +587,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
.type = desc->type,
.stream = stream,
.stream_pts = MP_NOPTS_VALUE,
- .seekable = (stream->flags & MP_STREAM_SEEK) == MP_STREAM_SEEK &&
- stream->end_pos > 0,
+ .seekable = stream->seekable,
.accurate_seek = true,
.filepos = -1,
.opts = global->opts,
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index b5a6ef998c..2b43f4f27f 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -135,17 +135,18 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence)
return -1;
MP_DBG(demuxer, "mp_seek(%p, %"PRId64", %d)\n",
stream, pos, whence);
- if (whence == SEEK_CUR)
+ if (whence == SEEK_END || whence == AVSEEK_SIZE) {
+ int64_t end;
+ if (stream_control(stream, STREAM_CTRL_GET_SIZE, &end) != STREAM_OK)
+ return -1;
+ if (whence == AVSEEK_SIZE)
+ return end;
+ pos += end;
+ } else if (whence == SEEK_CUR) {
pos += stream_tell(stream);
- else if (whence == SEEK_END && stream->end_pos > 0)
- pos += stream->end_pos;
- else if (whence == SEEK_SET)
- /* ok */;
- else if (whence == AVSEEK_SIZE && stream->end_pos > 0) {
- stream_update_size(stream);
- return stream->end_pos;
- } else
+ } else if (whence != SEEK_SET) {
return -1;
+ }
if (pos < 0)
return -1;
@@ -824,11 +825,13 @@ static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, int flags)
if (flags & SEEK_FACTOR) {
struct stream *s = demuxer->stream;
- if (s->end_pos > 0 && demuxer->ts_resets_possible &&
+ int64_t end = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &end);
+ if (end > 0 && demuxer->ts_resets_possible &&
!(priv->avif->flags & AVFMT_NO_BYTE_SEEK))
{
avsflags |= AVSEEK_FLAG_BYTE;
- priv->last_pts = s->end_pos * rel_seek_secs;
+ priv->last_pts = end * rel_seek_secs;
} else if (priv->avfc->duration != 0 &&
priv->avfc->duration != AV_NOPTS_VALUE)
{
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 20864aa297..4b08ce2a13 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1058,7 +1058,9 @@ static int demux_mkv_read_seekhead(demuxer_t *demuxer)
(unsigned)seek->seek_id, pos);
get_header_element(demuxer, seek->seek_id, pos);
// This is nice to warn against incomplete files.
- if (pos >= s->end_pos)
+ int64_t end = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &end);
+ if (pos >= end)
MP_WARN(demuxer, "SeekHead position beyond "
"end of file - incomplete file?\n");
}
@@ -1723,7 +1725,9 @@ static int read_mkv_segment_header(demuxer_t *demuxer, int64_t *segment_end)
MP_VERBOSE(demuxer, " (skipping)\n");
if (*segment_end <= 0)
break;
- if (*segment_end >= s->end_pos)
+ int64_t end = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &end);
+ if (*segment_end >= end)
return 0;
if (!stream_seek(s, *segment_end)) {
MP_WARN(demuxer, "Failed to seek in file\n");
@@ -1794,7 +1798,9 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check)
}
MP_VERBOSE(demuxer, "Seeking to %"PRIu64" to read header element 0x%x.\n",
elem->pos, (unsigned)elem->id);
- if (elem->pos >= s->end_pos) {
+ int64_t end = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &end);
+ if (elem->pos >= end) {
MP_WARN(demuxer, "SeekHead position beyond "
"end of file - incomplete file?\n");
continue;
@@ -2748,7 +2754,10 @@ static void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs, int flags)
return;
}
- target_filepos = (uint64_t) (s->end_pos * rel_seek_secs);
+ int64_t size = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &size);
+
+ target_filepos = (uint64_t) (size * rel_seek_secs);
for (i = 0; i < mkv_d->num_indexes; i++)
if (mkv_d->indexes[i].tnum == v_tnum)
if ((index == NULL)
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index 9d649c07a0..3c605e3f96 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -214,8 +214,8 @@ static void raw_seek(demuxer_t *demuxer, float rel_seek_secs, int flags)
{
struct priv *p = demuxer->priv;
stream_t *s = demuxer->stream;
- stream_update_size(s);
- int64_t end = s->end_pos;
+ int64_t end = 0;
+ stream_control(s, STREAM_CTRL_GET_SIZE, &end);
int64_t pos = (flags & SEEK_ABSOLUTE) ? 0 : stream_tell(s);
if (flags & SEEK_FACTOR)
pos += end * rel_seek_secs;
@@ -235,9 +235,8 @@ static int raw_control(demuxer_t *demuxer, int cmd, void *arg)
switch (cmd) {
case DEMUXER_CTRL_GET_TIME_LENGTH: {
stream_t *s = demuxer->stream;
- stream_update_size(s);
- int64_t end = s->end_pos;
- if (!end)
+ int64_t end = 0;
+ if (stream_control(s, STREAM_CTRL_GET_SIZE, &end) != STREAM_OK)
return DEMUXER_CTRL_DONTKNOW;
*((double *) arg) = (end / p->frame_size) / p->frame_rate;