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

415 Commits

Author SHA1 Message Date
Andreas Rheinhardt
0c6e5f321b avformat/avformat: Avoid including codec.h, frame.h
AVCodec is only ever used as an incomplete type (i.e. via a pointer
to an AVCodec) in avformat.h and it is not really part of the core
of avformat.h or libavformat; almost none of our internal users
make use of it (and none make use of hwcontext.h, which is implicitly
included). So switch to use struct AVCodec, but continue to include
codec.h for external users for compatibility.

Also, do the same for AVFrame and frame.h, which is implicitly included
by codec.h (via lavu/hwcontext.h).

Also, remove an unnecessary inclusion of <time.h>.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:30:08 +02:00
Kacper Michajłow
0cd2e7dcfb
avformat/http: copy only mime type from Content-Type
Content-Type can include charset and boundary which is not a part of
mime type and shouldn't be copied as such.

Fixes HLS playback when the Content-Type includes additional fields.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2023-06-29 17:28:46 -04:00
Michael J. Walsh
6f1c006959 avformat/http: cookie path attribute should be optional not compulsory
The path attribute in the Set-Cookie header is optional but treated by ffmpeg as being compulsory.

Signed-off-by: Michael J. Walsh <mjfwalsh@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-03-08 23:40:58 +01:00
Marvin Scholz
643c2b4722 avformat/http: use av_dict_iterate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-12-01 11:21:15 +01:00
James Almer
c7ce03d826 avformat/http: include version.h
This is needed to get LIBAVFORMAT_VERSION, used as part of the user agent.
Fixes a recent regression.

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-06-24 23:07:33 -03:00
Nil Admirari
c381f5412f libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv()
1. getenv() is replaced with getenv_utf8() across libavformat.
2. New versions of AviSynth+ are now called with UTF-8 filenames.
3. Old versions of AviSynth are still using ANSI strings,
   but MAX_PATH limit on filename is removed.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-06-21 13:27:46 +03:00
Steven Liu
1d6e9a7a30 avformat/http: remove unused function ff_http_get_shutdown_status
ff_http_get_shutdown_status is unused after ticket 9010 fixed.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2022-05-12 11:31:38 +08:00
Martin Storsjö
a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Justin Ruggles
0dd1ff67c8 http: Send a Range header even when the offset is 0
Using Range allows for getting the full file size from the
Content-Range header in the response, even if the server sends
back the response using chunked Transfer-Encoding, which does not
allow using Content-Length.
2022-02-11 11:31:38 +01:00
Justin Ruggles
c1228315c9 http: Improve handling of Content-Range with Transfer-Encoding:chunked
When Transfer-Encoding:chunked is used, the client must ignore a
Content-Length header, if present. However, it should not ignore a
Content-Range header, which also includes the full size of the
entity.
2022-02-11 11:31:38 +01:00
Andreas Rheinhardt
61cbfdc0a2 avformat/http: Fix double-free on error
av_dict_set() with AV_DICT_DONT_STRDUP_VAL takes ownership
of the string it is passed to as val; this includes freeing it
on error.

Fixes Coverity issue #1497468.

Reviewed-by: Eran Kornblau <eran.kornblau@kaltura.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-01 06:17:41 +01:00
erankor
f23d3a5f8f http: remove cache_redirect option
following 625ea2d, redirect caching is performed according to the http
response headers, there's no need to have it as an option -
always start from the original uri, and apply any redirects according
to the redirect_cache dictionary.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2022-01-31 14:08:33 -05:00
erankor
625ea2d2a9 http: honor response headers in redirect caching
add a dictionary that maps "src_url" -> "expiry;dst_url", the dictionary
is checked before issuing an http request, and updated after getting a
3xx redirect response.

the cache expiry is determined according to the following (in desc
priority) -
1. Expires header
2. Cache-Control containing no-cache/no-store (disables caching)
3. Cache-Control s-maxage/max-age
4. Http codes 301/308 are cached indefinitely, other codes are not
   cached
2022-01-18 17:35:26 -05:00
erankor
6348be83e8 http: make caching of redirect url optional
added "cache_redirect" option to http.
when enabled, requests issued after seek will use the latest redirected
url.
when disabled, each call to seek will revert to the original url that
was sent to http_open.

currently, the default remains 'enabled', until the next major
libavformat bump, where it will change to 'disabled'.
2021-12-31 14:27:00 -05:00
James Almer
b46817d9c3 avformat/http: prevent truncation of sanitized_path
path1 and sanitized_path are both MAX_URL_SIZE bytes long, yet the latter is
copied from the former with the addition of one extra character.

Should fix a -Wformat-truncation warning.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-25 12:06:15 -03:00
Derek Buitenhuis
a35101aae3 avformat/http: Add short_seek_size option
In 45bfe8b838, short_seek_threshold was removed
from the public AVIO struct. Although this option was private and not intended
to be used by public API users, it was nonetheless, because it provided functionality
that could otherwise not be gained via public API.

This was especially important for networked I/O like HTTP, where the internal
size for lavf could be way to small depending on the specifics of a user's
usecase, such as reading interlavd media files from cloud storage.

Add an AVOption to make this functionality accessible to the HTTP client.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2021-11-17 14:32:17 +00:00
Robert Bengtsson-Ölund
ad06929d8d avformat/http: Stop cookie_dict leaking on errors.
This solves the memory leak reported in https://trac.ffmpeg.org/ticket/9273

Signed-off-by: Robert Bengtsson-Ölund <robert.bengtsson-olund@intinor.se>
2021-06-26 20:17:57 +02:00
Andreas Rheinhardt
dc8e15ef15 avformat/http: Remove deprecated "user-agent" option
Deprecated in 27714b462d.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:09 -03:00
Moritz Barsnick
94b63e8ae8 avformat/http,tls: honor http_proxy command line variable for HTTPS
Add the "http_proxy" option and its handling to the "tls" protocol,
pass the option from the "https" protocol.

The "https" protocol already defines the "http_proxy" command line
option, like the "http" protocol does. The "http" protocol properly
honors that command line option in addition to the environment
variable. The "https" protocol doesn't, because the proxy is
evaluated in the underlying "tls" protocol, which doesn't have this
option, and thus only handles the environment variable, which it
has access to.

Fixes #7223.

Signed-off-by: Moritz Barsnick <barsnick@gmx.net>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-03-19 22:43:02 +01:00
Andreas Rheinhardt
9665fd31e8 avformat/http: Fix leak when using deprecated option
When the deprecated option "user-agent" was set to something different
than its default value, said option would always precede and overwrite
the ordinary user_agent option (regardless of whether it was explicitly
set) which leads to a leak of the user_agent option (which has a default
value, so the leak happens always).
Fix this by setting the same destination for both options; the last
option applied wins then.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-07 00:39:32 +01:00
Robin Cooksey
e22108240b lavf/http: treat 308 as 301
FFmpeg does not support POST, so there is no difference between a
308 and 301 request (see [RFC7538] section 3).

Signed-off-by: Josh Dekker <josh@itanimul.li>
2021-01-25 09:36:47 +01:00
erankor
fde5593c7c avformat/http: support retry on connection error
Add 2 new options:
- reconnect_on_http_error - a list of http status codes that should be
    retried. the list can contain explicit status codes / the strings
    4xx/5xx.
- reconnect_on_network_error - reconnects on arbitrary errors during
    connect, e.g. ECONNRESET/ETIMEDOUT

the retry employs the same exponential backoff logic as the existing
reconnect/reconnect_at_eof flags.

related tickets:
https://trac.ffmpeg.org/ticket/6066
https://trac.ffmpeg.org/ticket/7768

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-03 16:47:29 +01:00
Martin Storsjö
104e5233f0 http: Check for AVERROR_EOF in the check for premature end
When the check was added (in 3668701f96, in 2015), some IO
functions returned 0 on EOF (in particular, the TCP protocol
did, but the TLS protocol returned AVERROR_EOF). Since
0e1f771d22 in 2017, the TCP protocol also returns AVERROR_EOF
instead of 0, making the check for premature end never have the
intended effect.

Signed-off-by: Martin Storsjö <martin@martin.st>
2020-11-20 10:37:24 +02:00
Zhao Zhili
90351b5f11 avformat/http: fix memleak
Reviewed-by: "mypopy@gmail.com" <mypopy@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-09-25 10:21:28 +02:00
Joey Smith
d29c429744 avformat/http: increase BUFFER_SIZE to MAX_URL_SIZE + HTTP_HEADERS_SIZE
Some real-world sites use an authorization header with a bearer token; when
combined with lengthy request parameters to identify the video segment,
it's rather trivial these days to have a request body of more than 4k bytes.

MAX_URL_SIZE is hard-coded to 4k bytes in libavformat/internal.h, and
HTTP_HEADERS_SIZE is 4k as well in libavformat/http.h, so this patch increases
the buffer size to 8k, as that is the default request body limit in Apache, and
most other httpds seem to support at least as much, if not more.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-21 22:45:21 +02:00
Limin Wang
3b8b6d837e avformat/http: Fix for invalid use of av_strtok
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-10 22:32:34 +08:00
Marton Balint
6a7b5226e1 avformat/http: escape unsafe URL path in HTTP request
This avoids generating invalid HTTP requests if the path contains space or
other special characters.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
86b2fe9411 avformat/http: use AVBPrint to construct HTTP request
v2: Use s->buffer for creating request (as the old code did) instead of
the AVBPrint internal buffer. Some minor cosmetics.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
a3d8875df1 avformat/http: make sure URL path contains a slash
It is explicitly required by the HTTP RFC. Without this patch URLs like
http://example.com?query will not work.

Fixes ticket #8466.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Marton Balint
987ce96d41 avformat/http: split the fragment part from the HTTP URL before the request
RFC 3986 states that the fragment identifier is separated from the rest of the
URI prior to a dereference, and thus the identifying information within the
fragment itself is dereferenced solely by the user agent.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-15 18:41:36 +01:00
Steven Liu
b9606064c4 avformat/hls: support data protocol in uri for EXT-X-MAP
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-18 22:41:11 +08:00
vectronic
e81c686a95 avformat/http: add ff_http_do_new_request2 for options
add ff_http_do_new_request2() which supports options to be applied to
HTTPContext after initialisation with the new uri

Signed-off-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: vectronic <hello.vectronic@gmail.com>
2019-10-08 14:57:44 +08:00
Steven Liu
6c593fee63 avformat/http: add ff_http_get_shutdown_status api for check the status of shutdown
this function is used to get the previous shutdown status
when reusing the old connection in block mode.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-06 10:26:16 +08:00
Steven Liu
1b1b974aac avformat/http: change error message from numeric code to string
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-07-11 09:35:31 +08:00
Jun Li
4f5e660e69 avformat/doc, http, icecast, rtsp: Add option to disable send-expect-100
Fix ticket #7297
The current setting for send-expect-100 option is either
enabled if applicable or forced enabled, no option to force
disable the header. This change is to expand the option setting
to provide more flexibility, which is useful for rstp case.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-03-31 23:23:52 +02:00
Carl Eugen Hoyos
7be245498b lavf/http: Print metadata updates with -loglevel verbose.
Simplifies metadata debugging.
2019-03-20 17:43:19 +01:00
Justin Ruggles
69fcc093c1 http: Do not try to make a new request when seeking past the end of the file
This avoids making invalid HTTP Range requests for a byte range past the
known end of the file during a seek. Those requests generally return a HTTP
response of 416 Range Not Satisfiable, which causes an error response.

Reference: https://tools.ietf.org/html/rfc7233

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2019-02-26 14:48:27 -05:00
Wenxiang Qian
85f91ed760 avformat/http: Fix Out-of-Bounds access in process_line()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-17 10:29:42 +01:00
Gyan Doshi
2e2b44baba avformat/http: clarify that ffmpeg will attempt to add missing CRLF 2019-01-29 09:58:30 +05:30
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