1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

376 Commits

Author SHA1 Message Date
kjeyapal@akamai.com
ce0a753634 avformat/http : Added check for valid URL context before calling shutdown 2018-11-22 12:06:27 +05:30
Clément Bœsch
2e341eb15b lavf/http: use AV_OPT_FLAG_DEPRECATED for user-agent option 2018-04-26 19:50:29 +02:00
Vishwanath Dixit
30940be359 avformat/http: flushing tcp receive buffer when it is write only mode
In write only mode, the TCP receive buffer's data keeps growing with
http response messages and the buffer eventually becomes full.
This results in zero tcp window size, which in turn causes unwanted
issues, like, terminated tcp connection. The issue is apparent when
http persistent connection is enabled in hls/dash live streaming use
cases. To overcome this issue, the logic here reads the buffer data
when a file transfer is completed, so that any accumulated data in
the recieve buffer gets flushed out.
2018-04-20 11:31:21 +05:30
Stephan Holljes
7b6b8c9265 lavf/http.c: Free allocated client URLContext in case of error.
Signed-off-by: Stephan Holljes <klaxa1337@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-20 01:46:32 +02:00
Richard Shaffer
c705476c47 libavformat/http: Refactor and fix additional leaks in get_cookies.
This refactors get_cookies to simplify some code paths, specifically for
skipping logic in the while loop or exiting it. It also simplifies the logic
for appending additional values to *cookies by replacing strlen/malloc/snprintf
with one call av_asnprintf.

This refactor fixes a bug where the cookie_params AVDictionary would get leaked
if we failed to allocate a new buffer for writing to *cookies.
2018-04-19 22:01:51 +02:00
Richard Shaffer
9a8811f478 libavformat/http: Fix memory leak in get_cookies. 2018-04-17 22:00:54 +02:00
wm4
b7d842c554 http: fix potentially dangerous whitespace skipping code
If the string consists entirely of whitespace, this could in theory
continue to write '\0' before the start of the memory allocation. In
practice, it didn't really happen: the generic HTTP header parsing code
already skips leading whitespaces, so the string is either empty, or
consists a non-whitespace. (The generic code and the cookie code
actually have different ideas about what bytes are whitespace: the
former uses av_isspace(), the latter uses WHITESPACES. Fortunately,
av_isspace() is a super set of the http.c specific WHITESPACES, so
there's probably no case where the above assumption could have been
broken.)
2018-03-18 12:36:24 +01:00
wm4
c0687acbf6 http: avoid out of bound accesses on broken Set-Cookie headers
It's trivial to craft a HTTP response that will make the code for
skipping trailing whitespace access and possibly overwrite bytes outside
of the memory allocation. Why this can happen is blindingly obvious: it
accesses cstr[strlen(cstr)-1] without checking whether the string is
empty.
2018-03-18 12:36:24 +01:00
wm4
39c1d170a3 http: do not print a warning message for expired cookies
libavformat prints a warning that the cookie couldn't be parsed (see
callers of parse_cookie()). This is obviously not true - it could be
parsed, but was simply ignored. Don't return an error to avoid the
warning.
2018-03-18 12:36:24 +01:00
Steven Liu
44f3430674 avformat/http: add referer option into http
add Referer message if referer have been set.
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2018-02-01 10:56:51 +08:00
wm4
43e1ccfea1 http: cosmetics: reformat reconnect check for better readability
The condition was a bit too long, and most editors will break the line
and turn it into an unreadable mess. Move out some of the conditions.

This should not change the behavior.
2018-01-15 12:37:30 +01:00
Richard Shaffer
9147c09755 avformat/http: fix memory leak in parse_cookie.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-01-12 12:31:55 +01:00
wm4
2477bfe221 http: avoid logging reconnect warning if stream was aborted
If the stream was aborted using the libavformat interrupt callback, we
don't want it to log the reconnect warning. (Exiting after logging this
warning worked well, so this is only for avoiding the ugly warning.)
2018-01-04 18:08:31 +01:00
wm4
1b283c4a0d http: bump message level for reconnect message and log timeout 2018-01-04 15:07:55 +01:00
wm4
8a108bdea0 http: block while waiting for reconnecting
It makes no sense to return an error after the first reconnect, and then
somehow resume the next time it's called. Usually this will lead to
demuxer errors. Make reconnecting block instead, until it has either
successfully reconnected, or given up.

Also make the wait reasonably interruptible. Since there is no mechanism
for this in the API, polling is the best we can do. This behaves roughly
the same as other interruptible network functions in libavformat.

(The original code would work if it returned AVERROR(EAGAIN) or so,
which would make retry_transfer_wrapper() repeat the read call. But I
think having an explicit loop for this is better anyway.)

I also snuck in a fix for reconnect_at_eof. It has to check for
AVERROR_EOF, not 0.
2018-01-04 15:07:55 +01:00
Aman Gupta
c0b08ef94f avformat/http: return EINVAL if ff_http_do_new_request is called with non-http URLContext
Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-30 09:58:03 -08:00
Aman Gupta
039007c928 avformat/http: export http_version from response
Can be used by the api user to figure out what http features the server supports based on the response received.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-26 14:52:36 -08:00
Aman Gupta
11f989945e avformat/http: avoid ff_http_do_new_request after http/1.0 response
This makes do_new_request fail early when dealing with a http/1.0 server, avoiding unnecessary "reconnecting" warnings shown to the user.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-26 14:48:14 -08:00
Karthick Jeyapal
6848201f70 avformat/http: Avoid calling http_shutdown() if end of chunk is signalled already 2017-12-25 12:07:43 +08:00
Aman Gupta
54d0ef1738 avformat/http: return EOF from ff_http_do_new_request if previous response said Connection:close
This fixes a deadlock when using the hls demuxer's new http_persistent feature
to stream a youtube live stream over HTTPS. The youtube servers are http/1.1
compliant, but return a "Connecton: close". Before this commit, the demuxer
would attempt to send a new request on the partially shutdown connection and
cause a deadlock in the tls protocol.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-12-22 16:39:37 -08:00
Aman Gupta
9395e44b8d avformat/http: add "Opening" info logging to ff_http_do_new_request
This mimics logging that was added in 53e0d5d724 for security
purposes.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-12-22 14:42:50 -08:00
Aman Gupta
28358e466d avformat/http: return EINVAL from ff_http_do_new_request() if re-used with different hostname
This will prevent improper use of ff_http_do_new_request() if the user
tries to send a request for a different host to a previously connected
persistent http/1.1 connection.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Karthick J <kjeyapal@akamai.com>
2017-12-22 14:42:35 -08:00
Jeyapal, Karthick
4ddf7476c0 libavformat/http: Handled multiple_requests option during write 2017-11-29 14:32:16 +08:00
Aman Gupta
91a565e20f avformat/http: fix chunked response w/ multiple_requests=1
Currently if you use the multiple_requests=1 option and try to
receive a chunked-encoded response, http_buf_read() will hang forever.

After this patch, EOF is emulated once a 0-byte final chunk is
received by setting a new flag. This flag is reset in ff_http_do_new_request(),
which is used to make additional requests on the open socket.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-11-14 07:36:51 -08:00
Aman Gupta
52bf0febb3 avformat/http: fix stray quote in trace logging
Signed-off-by: Aman Gupta <aman@tmm1.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-13 11:19:25 -08:00
Daniel Kucera
858db4b01f libavformat: not treat 0 as EOF
transfer_func variable passed to retry_transfer_wrapper
are h->prot->url_read and h->prot->url_write functions.
These need to return EOF or other error properly.
In case of returning >= 0, url_read/url_write is retried
until error is returned.

Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
2017-10-19 22:07:21 +02:00
Clément Bœsch
6743351558 lavf/http: fix compilation without zlib
Regression since e2f8f14052.
2017-09-15 15:10:49 +02:00
Jacek Jendrzej
e2f8f14052 lavf/http: Reset compressed header flag, fix http 302 request
Fixes ticket #6404.
Fixes ticket #6666.

Signed-off-by: Jacek Jendrzej <satbaby@kawaii.com>
2017-09-15 13:33:23 +02:00
raymondzheng
9f20cc5c84 libavformat/http: return EIO when ffurl_read return 0, but s->off < target_end
Approved-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-09 13:27:44 +02:00
Micah Galizia
28b2467074 libavformat/http: Ignore expired cookies
Signed-off-by: Micah Galizia <micahgalizia@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-01 17:55:22 +02:00
Joel Cunningham
8c8e5d5286 HTTP: improve performance by reducing forward seeks
This commit optimizes HTTP performance by reducing forward seeks, instead
favoring a read-ahead and discard on the current connection (referred to
as a short seek) for seeks that are within a TCP window's worth of data.
This improves performance because with TCP flow control, a window's worth
of data will be in the local socket buffer already or in-flight from the
sender once congestion control on the sender is fully utilizing the window.

Note: this approach doesn't attempt to differentiate from a newly opened
connection which may not be fully utilizing the window due to congestion
control vs one that is. The receiver can't get at this information, so we
assume worst case; that full window is in use (we did advertise it after all)
and that data could be in-flight

The previous behavior of closing the connection, then opening a new
with a new HTTP range value results in a massive amounts of discarded
and re-sent data when large TCP windows are used.  This has been observed
on MacOS/iOS which starts with an initial window of 256KB and grows up to
1MB depending on the bandwidth-product delay.

When seeking within a window's worth of data and we close the connection,
then open a new one within the same window's worth of data, we discard
from the current offset till the end of the window.  Then on the new
connection the server ends up re-sending the previous data from new
offset till the end of old window.

Example (assumes full window utilization):

TCP window size: 64KB
Position: 32KB
Forward seek position: 40KB

      *                      (Next window)
32KB |--------------| 96KB |---------------| 160KB
        *
  40KB |---------------| 104KB

Re-sent amount: 96KB - 40KB = 56KB

For a real world test example, I have MP4 file of ~25MB, which ffplay
only reads ~16MB and performs 177 seeks. With current ffmpeg, this results
in 177 HTTP GETs and ~73MB worth of TCP data communication.  With this
patch, ffmpeg issues 4 HTTP GETs and 3 seeks for a total of ~22MB of TCP data
communication.

To support this feature, the short seek logic in avio_seek() has been
extended to call a function to get the short seek threshold value.  This
callback has been plumbed to the URLProtocol structure, which now has
infrastructure in HTTP and TCP to get the underlying receiver window size
via SO_RCVBUF.  If the underlying URL and protocol don't support returning
a short seek threshold, the default s->short_seek_threshold is used

This feature has been tested on Windows 7 and MacOS/iOS.  Windows support
is slightly complicated by the fact that when TCP window auto-tuning is
enabled, SO_RCVBUF doesn't report the real window size, but it does if
SO_RCVBUF was manually set (disabling auto-tuning). So we can only use
this optimization on Windows in the later case

Signed-off-by: Joel Cunningham <joel.cunningham@me.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-14 17:00:30 +01:00
Michael Niedermayer
8fa18e042a avformat/http: Check for truncated buffers in http_connect()
Reported-by: SleepProgger <security@gnutp.com>
Reviewed-by: Steven Liu <lingjiujianke@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-14 04:02:51 +01:00
Ronald S. Bultje
845bb40178 http: move chunk handling from http_read_stream() to http_buf_read(). 2016-12-05 16:15:10 -05:00
Ronald S. Bultje
2a05c8f813 http: make length/offset-related variables unsigned.
Fixes #5992, reported and found by Paul Cher <paulcher@icloud.com>.
2016-12-05 16:15:10 -05:00
Michael Niedermayer
a880923170 avformat/http: Fix #ifdef FF_API_HTTP_USER_AGENT
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-17 20:14:10 +02:00
Steven Liu
27714b462d lavf/http: deprecate user-agent option 2016-09-17 13:48:34 +02:00
Moritz Barsnick
d14993478c libavformat/http: add support for content_type option in listen mode
Instead of silently ignoring the content_type option in listen mode,
apply its value to the provided "Content-Type:" header.

Signed-off-by: Moritz Barsnick <barsnick@gmx.net>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-14 10:44:38 +02:00
Moritz Barsnick
e8b355a028 libavformat/http: add support for headers option in listen mode
Instead of silently ignoring the headers option in listen mode, use
the provided headers.

Signed-off-by: Moritz Barsnick <barsnick@gmx.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-12 00:20:26 +02:00
Yuri Zats
ebda8216dc avformat/http: change seek_ret to int64
Reviewed-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-16 23:55:21 +02:00
Derek Buitenhuis
f8e89d8a29 Merge commit 'fab8156b2f30666adabe227b3d7712fd193873b1'
* commit 'fab8156b2f30666adabe227b3d7712fd193873b1':
  avio: Copy URLContext generic options into child URLContexts

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-21 15:55:09 +01:00
Martin Storsjö
fab8156b2f avio: Copy URLContext generic options into child URLContexts
Since all URLContexts have the same AVOptions, such AVOptions
will be applied on the outermost context only and removed from the
dict, while they probably make sense on all contexts.

This makes sure that rw_timeout gets propagated to the innermost
URLContext (to make sure it gets passed to the tcp protocol, when
opening a http connection for instance).

Alternatively, such matching options would be kept in the dict
and only removed after the ffurl_connect call.

Signed-off-by: Martin Storsjö <martin@martin.st>
2016-03-24 10:34:19 +02:00
Carl Eugen Hoyos
58fa694978 lavf/http: Add httpproxy to the default protocol whitelist. 2016-03-14 16:33:57 +01:00
Carl Eugen Hoyos
144ef773c7 Use correct msvc type specifiers for ptrdiff_t and size_t. 2016-03-09 14:00:22 +01:00
Derek Buitenhuis
93629735d7 avformat: Add a protocol blacklisting API
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-03-04 16:13:42 +00:00
Derek Buitenhuis
9c75148e6e Merge commit '2758cdedfb7ac61f8b5e4861f99218b6fd43491d'
This commit also disables the async fate test, because it
used internal APIs in a non-kosher way, which no longer
exists.

* commit '2758cdedfb7ac61f8b5e4861f99218b6fd43491d':
  lavf: reorganize URLProtocols

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-29 16:51:10 +00:00
Anton Khirnov
8c0ceafb0f urlprotocol: receive a list of protocols from the caller
This way, the decisions about which protocols are available for use in
any given situations can be delegated to the caller.
2016-02-22 11:45:31 +01:00
Anton Khirnov
2758cdedfb lavf: reorganize URLProtocols
Instead of a linked list constructed at av_register_all(), store them
in a constant array of pointers.

Since no registration is necessary now, this removes some global state
from lavf. This will also allow the urlprotocol layer caller to limit
the available protocols in a simple and flexible way in the following
commits.
2016-02-22 11:30:58 +01:00
Schenk, Michael
93f4b41208 avformat/http: add crypto to default whitlist to get encrypted HLS working again
I think we missed the crypto in the default_whitelist in case of http. Otherwise encrypted HLS will fail with

[hls,applehttp @ 0x2af39c00] playlist[0] open_input [http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans_aes-audio=65000-video=236000-14.ts], start_seq_no [1], cur_seq_no [14]

[hls,applehttp @ 0x2af39c00]    open_input curseqno [14] startseqno [1]

[hls,applehttp @ 0x2af39c00] HLS request for url 'http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans_aes-audio=65000-video=236000-14.ts', offset 0, playlist 0

[NULL @ 0x2af3a200] KEY_AES_128 seg->key [http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans.key] pls->key_url [http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans.key]

[hls,applehttp @ 0x2af39c00]     open_input [KEY_AES_128]

[hls,applehttp @ 0x2af39c00]      : c->persistence [0]

[hls,applehttp @ 0x2af39c00]      : c->probing     [1]

[hls,applehttp @ 0x2af39c00]      : pls->input     [NULL]

[hls,applehttp @ 0x2af39c00]        using normal http path for URL [crypto+http://playertest.longtailvideo.com/adaptive/oceans_aes/oceans_aes-audio=65000-video=236000-14.ts]

[crypto @ 0x2aff7cc0] Protocol not on whitelist 'http,https,tls,rtp,tcp,udp!

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-03 15:57:43 +01:00
Michael Niedermayer
fe3fed0b14 Update demuxers and protocols for protocol whitelist support
Reviewed-by: Andreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-02 04:16:50 +01:00
Joel Holdsworth
b4eb1f29eb avformat/http: Added http_proxy option
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-27 21:44:14 +01:00