[FFmpeg-devel] [PATCH] libavformat/http: fix support for reconnect_at_eof

Rémi Denis-Courmont remi at remlab.net
Wed Oct 9 16:48:01 EEST 2024


Le 9 octobre 2024 13:16:37 GMT+03:00, Radoslav Gerganov <rgerganov at gmail.com> a écrit :
>Fix regression introduced with commit 69fcc09 which doesn't honor
>reconnect_at_eof and breaks support for live/endless streams. For such
>streams we should reconnect at EOF and clients set the reconnect_at_eof
>option to signal this.
>
>Signed-off-by: Radoslav Gerganov <rgerganov at gmail.com>
>---
> libavformat/http.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
>diff --git a/libavformat/http.c b/libavformat/http.c
>index ec60bc0b17..27f8b98744 100644
>--- a/libavformat/http.c
>+++ b/libavformat/http.c
>@@ -1988,12 +1988,13 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo
>     if (s->off && h->is_streamed)
>         return AVERROR(ENOSYS);
> 
>-    /* do not try to make a new connection if seeking past the end of the file */
>-    if (s->end_off || s->filesize != UINT64_MAX) {
>-        uint64_t end_pos = s->end_off ? s->end_off : s->filesize;
>-        if (s->off >= end_pos)
>-            return s->off;
>-    }
>+    if (!s->reconnect_at_eof)
>+        /* do not try to make a new connection if seeking past the end of the file */
>+        if (s->end_off || s->filesize != UINT64_MAX) {
>+            uint64_t end_pos = s->end_off ? s->end_off : s->filesize;
>+            if (s->off >= end_pos)
>+                return s->off;
>+        }

AFAICT, reconnecting blindly makes no sense if the file size is known, flag or no flag.

With that said the current code seems odd. Normal seek semantics allow for seeking to or even past the end of a file. The offset should not be capped like this. The server will return 416 which should be treated as "successfully" seeking. Or if the file has changed size in the mean time, it will return 206 and we can continue streaming.

But either way, this patch doesn't look right.

> 
>     /* if the location changed (redirect), revert to the original uri */
>     if (strcmp(s->uri, s->location)) {


More information about the ffmpeg-devel mailing list