Commit 4877b586 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by Nicolas George

libavformat/subfile: Improve AVSEEK_SIZE/SEEK_END seeking

The subfile protocol treats an end of 0 as meaning "until EOF"; this got
implemented by simply setting the end to INT64_MAX. But seeking relative
to EOF or AVSEEK_SIZE seeking hasn't been adapted; the result is that
e.g. the duration of transport streams isn't correctly determined when
this option is used. This is fixed in this patch.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
parent e51cc7ed
...@@ -116,11 +116,17 @@ static int subfile_read(URLContext *h, unsigned char *buf, int size) ...@@ -116,11 +116,17 @@ static int subfile_read(URLContext *h, unsigned char *buf, int size)
static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) static int64_t subfile_seek(URLContext *h, int64_t pos, int whence)
{ {
SubfileContext *c = h->priv_data; SubfileContext *c = h->priv_data;
int64_t new_pos = -1; int64_t new_pos = -1, end;
int ret; int ret;
if (whence == AVSEEK_SIZE || whence == SEEK_END) {
end = c->end;
if (end == INT64_MAX && (end = ffurl_seek(c->h, 0, AVSEEK_SIZE)) < 0)
return end;
}
if (whence == AVSEEK_SIZE) if (whence == AVSEEK_SIZE)
return c->end - c->start; return end - c->start;
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
new_pos = c->start + pos; new_pos = c->start + pos;
...@@ -129,7 +135,7 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence) ...@@ -129,7 +135,7 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence)
new_pos += pos; new_pos += pos;
break; break;
case SEEK_END: case SEEK_END:
new_pos = c->end + c->pos; new_pos = end + c->pos;
break; break;
} }
if (new_pos < c->start) if (new_pos < c->start)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment