[FFmpeg-devel] Connection timeout to HTTP resource

Stephan Holljes klaxa1337 at googlemail.com
Wed Aug 26 18:27:08 CEST 2015


Hi,

On Wed, Aug 26, 2015 at 11:35 AM, Przemysław Sobala
<przemyslaw.sobala at grupawp.pl> wrote:
> Hi
> I wanted to configure tcp connection timeout while connecting to eg.
> http://google.com:81.
>
> ffmpeg -i http://google.com:81?timeout=1000000
> doesn't pass "timeout" param to tcp proto, as tcp proto doesn't support
> URL query string

TCP does support some parsing for URL query strings (see
tcp.c:tcp_open around line 83 and following), but when used with HTTP
the query is not parsed and simply sent with the request as it
could/should contain information only relevant to the server handling
the request.

>
> ffmpeg -timeout 1000000 -i http://google.com:81
> doesn't pass "timeout" param to tcp proto, as tcp proto doestn't support
> AVDictionary and url_open2

AFAIK this should happen through AVOptions and should work. When I run
the command with -loglevel trace the parameter gets set properly. I
added logging for s->rw_timeout in tcp.c:tcp_open, and that value also
gets set correctly.

>
> So I tried to correct the second case, and ended up with patch:
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index bee349e..2f7726f 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -59,7 +59,8 @@ static const AVClass tcp_class = {
>  };
>
>  /* return non zero if error */
> -static int tcp_open(URLContext *h, const char *uri, int flags)
> +static int tcp_open(URLContext *h, const char *uri, int flags,
> +                     AVDictionary **options)
>  {
>      struct addrinfo hints = { 0 }, *ai, *cur_ai;
>      int port, fd = -1;
> @@ -244,7 +245,7 @@ static int tcp_get_file_handle(URLContext *h)
>
>  URLProtocol ff_tcp_protocol = {
>      .name                = "tcp",
> -    .url_open            = tcp_open,
> +    .url_open2           = tcp_open,
>      .url_accept          = tcp_accept,
>      .url_read            = tcp_read,
>      .url_write           = tcp_write,
>
> Now it works (ffmpeg -timeout 1000000 -i http://google.com:81). What do
> you think about that?

If that's the complete patch it doesn't really change anything since
options isn't used anywhere in tcp_open() AFAICT.
I also couldn't reproduce the behaviour you described. When running:

ffmpeg -timeout 1000000 -i http://google.com:81

with the latest git master the connection properly times out.

>
> --
> Regards
> Przemysław Sobala
>
>
> Główne Spółki Grupy Wirtualna Polska:
>
> Wirtualna Polska Holding Spółka Akcyjna z siedzibą w Warszawie, ul.
> Jutrzenki 137A, 02-231 Warszawa, wpisana do Krajowego Rejestru Sądowego -
> Rejestru Przedsiębiorców prowadzonego przez Sąd Rejonowy dla m.st. Warszawy
> w Warszawie pod nr KRS: 0000407130, kapitał zakładowy: 1 245 651,90 zł (w
> całości wpłacony), Numer Identyfikacji Podatkowej (NIP): 521-31-11-513
>
> Grupa Wirtualna Polska Spółka z ograniczoną odpowiedzialnością z siedzibą w
> Warszawie, ul. Jutrzenki 137A, 02-231 Warszawa, wpisana do Krajowego
> Rejestru Sądowego - Rejestru Przedsiębiorców prowadzonego przez Sąd Rejonowy
> dla m.st. Warszawy w Warszawie pod nr KRS: 0000373814, kapitał zakładowy:
> 311.005.050,00 zł, Numer Identyfikacji Podatkowej (NIP): 527-26-45-593
>
> WP Shopping Spółka z ograniczoną odpowiedzialnością z siedzibą w Gdańsku,
> ul. Romualda Traugutta 115 C, 80-226 Gdańsk, wpisana do Krajowego Rejestru
> Sądowego - Rejestru Przedsiębiorców prowadzonego przez Sąd Rejonowy Gdańsk -
> Północ w Gdańsku pod nr KRS: 0000546914, kapitał zakładowy: 170.000,00
> złotych (w całości wpłacony), Numer Identyfikacji Podatkowej (NIP):
> 957-07-51-216
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Regards,
Stephan


More information about the ffmpeg-devel mailing list