diff mbox

[FFmpeg-devel] libavformat/subfile: Improve AVSEEK_SIZE/SEEK_END seeking

Message ID 20190620043341.3176-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 4877b5869ee1b3d17a3ed9b5b6d0988bd8b02b21
Headers show

Commit Message

Andreas Rheinhardt June 20, 2019, 4:33 a.m. UTC
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: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/subfile.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Andreas Rheinhardt July 1, 2019, 5:35 a.m. UTC | #1
Andreas Rheinhardt:
> 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: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/subfile.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/subfile.c b/libavformat/subfile.c
> index b527f2bee1..2f162e0a34 100644
> --- a/libavformat/subfile.c
> +++ b/libavformat/subfile.c
> @@ -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)
>  {
>      SubfileContext *c = h->priv_data;
> -    int64_t new_pos = -1;
> +    int64_t new_pos = -1, end;
>      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)
> -        return c->end - c->start;
> +        return end - c->start;
>      switch (whence) {
>      case SEEK_SET:
>          new_pos = c->start + pos;
> @@ -129,7 +135,7 @@ static int64_t subfile_seek(URLContext *h, int64_t pos, int whence)
>          new_pos += pos;
>          break;
>      case SEEK_END:
> -        new_pos = c->end + c->pos;
> +        new_pos = end + c->pos;
>          break;
>      }
>      if (new_pos < c->start)
> 
Ping.

- Andreas
Nicolas George July 1, 2019, 10:21 a.m. UTC | #2
Andreas Rheinhardt (12019-06-20):
> 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: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/subfile.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)

Sorry, I forgot about this patch. Applied, thanks.

Regards,
diff mbox

Patch

diff --git a/libavformat/subfile.c b/libavformat/subfile.c
index b527f2bee1..2f162e0a34 100644
--- a/libavformat/subfile.c
+++ b/libavformat/subfile.c
@@ -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)
 {
     SubfileContext *c = h->priv_data;
-    int64_t new_pos = -1;
+    int64_t new_pos = -1, end;
     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)
-        return c->end - c->start;
+        return end - c->start;
     switch (whence) {
     case SEEK_SET:
         new_pos = c->start + pos;
@@ -129,7 +135,7 @@  static int64_t subfile_seek(URLContext *h, int64_t pos, int whence)
         new_pos += pos;
         break;
     case SEEK_END:
-        new_pos = c->end + c->pos;
+        new_pos = end + c->pos;
         break;
     }
     if (new_pos < c->start)