[FFmpeg-devel] [PATCH v3] Option to prevent probing for HTTP seekability
Michael Niedermayer
michaelni at gmx.at
Tue Oct 2 22:08:11 CEST 2012
On Tue, Oct 02, 2012 at 05:10:17PM +0100, Duncan Salerno wrote:
> Some HLS servers return 403 when the Range header is present. Add an tri-state (seek, non seek, automatic detection) option to HTTP to control seekability (default: automatic), set to disabled by HLS to prevent the Range header being sent to probe.
> ---
> libavformat/hls.c | 37 +++++++++++++++++++++++++------------
> libavformat/http.c | 20 ++++++++++++++------
> 2 files changed, 39 insertions(+), 18 deletions(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 00c3cf0..abc2ac8 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -212,10 +212,15 @@ static int parse_playlist(HLSContext *c, const char *url,
> int close_in = 0;
>
> if (!in) {
> - close_in = 1;
> - if ((ret = avio_open2(&in, url, AVIO_FLAG_READ,
> - c->interrupt_callback, NULL)) < 0)
> + AVDictionary *opts = NULL;
> + /* Some HLS servers dont like being sent the range header */
> + av_dict_set(&opts, "seekable", "0", 0);
> + ret = avio_open2(&in, url, AVIO_FLAG_READ,
> + c->interrupt_callback, &opts);
> + av_dict_free(&opts);
> + if (ret < 0)
> return ret;
> + close_in = 1;
why do you move the close_in seting around ?
(if its unneeded its better not to do in this patch as it makes the
diff harder to read)
[...]
> diff --git a/libavformat/http.c b/libavformat/http.c
> index ede4e8b..04ccb2f 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -50,6 +50,7 @@ typedef struct {
> HTTPAuthState proxy_auth_state;
> char *headers;
> int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
> + int seekable; /**< Control seekability, 0 = disable, 1 = enable, -1 = probe. */
> int chunked_post;
> int end_chunked_post; /**< A flag which indicates if the end of chunked encoding has been sent. */
> int end_header; /**< A flag which indicates we have finished to read POST reply. */
> @@ -64,6 +65,7 @@ typedef struct {
> #define E AV_OPT_FLAG_ENCODING_PARAM
> #define DEC AV_OPT_FLAG_DECODING_PARAM
> static const AVOption options[] = {
> +{"seekable", "Control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, D },
> {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
> {"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
> {"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
> @@ -207,7 +209,10 @@ static int http_open(URLContext *h, const char *uri, int flags)
> {
> HTTPContext *s = h->priv_data;
>
> - h->is_streamed = 1;
> + if( s->seekable == 1 )
> + h->is_streamed = 0;
> + else
> + h->is_streamed = 1;
indent is 4 spaces in the rest of the file and in ffmpeg in general,
please keep indention consistent
>
> s->filesize = -1;
> av_strlcpy(s->location, uri, sizeof(s->location));
> @@ -318,9 +323,9 @@ static int process_line(URLContext *h, char *line, int line_count,
> if ((slash = strchr(p, '/')) && strlen(slash) > 0)
> s->filesize = strtoll(slash+1, NULL, 10);
> }
> - if (!s->is_akamai || s->filesize != 2147483647)
> + if (s->seekable != 0 && (!s->is_akamai || s->filesize != 2147483647))
probing code should be under seekable == -1 and not seekable != 0 or
am i missing something ?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121002/a4d7fcc1/attachment.asc>
More information about the ffmpeg-devel
mailing list