summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Hannula <anssi.hannula@iki.fi>2013-12-28 09:41:24 +0200
committerAnssi Hannula <anssi.hannula@iki.fi>2013-12-31 03:18:53 +0200
commitd52882faef368264f9fe5a595274ec84d3446132 (patch)
tree3fe44b6260e18cdba75b2b308645aa2138a1c9fc
parent53765ae33b8b0baaebd1914b165bb26fb6122176 (diff)
avformat/http: allow the caller to select a request range
Add AVOptions for setting the initial offset and the ending offset, so they can be used for setting an appropriate Range header. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
-rw-r--r--libavformat/http.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 0619e2a06c..fd29966e2a 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -52,7 +52,7 @@ typedef struct {
int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
char *content_type;
char *user_agent;
- int64_t off, filesize;
+ int64_t off, filesize, req_end_offset;
int icy_data_read; ///< how much data was read since last ICY metadata packet
int icy_metaint; ///< after how many bytes of read data a new metadata packet will be found
char *location;
@@ -105,6 +105,8 @@ static const AVOption options[] = {
{"basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, {.i64 = HTTP_AUTH_BASIC}, 0, 0, D|E, "auth_type" },
{"send_expect_100", "Force sending an Expect: 100-continue header for POST", OFFSET(send_expect_100), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, E },
{"location", "The actual location of the data received", OFFSET(location), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
+{"offset", "initial byte offset", OFFSET(off), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, D },
+{"end_offset", "try to limit the request to bytes preceding this offset", OFFSET(req_end_offset), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, D },
{NULL}
};
#define HTTP_CLASS(flavor)\
@@ -643,9 +645,15 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
// Note: we send this on purpose even when s->off is 0 when we're probing,
// since it allows us to detect more reliably if a (non-conforming)
// server supports seeking by analysing the reply headers.
- if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->seekable == -1))
+ if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->req_end_offset || s->seekable == -1)) {
len += av_strlcatf(headers + len, sizeof(headers) - len,
- "Range: bytes=%"PRId64"-\r\n", s->off);
+ "Range: bytes=%"PRId64"-", s->off);
+ if (s->req_end_offset)
+ len += av_strlcatf(headers + len, sizeof(headers) - len,
+ "%"PRId64, s->req_end_offset - 1);
+ len += av_strlcpy(headers + len, "\r\n",
+ sizeof(headers) - len);
+ }
if (send_expect_100 && !has_header(s->headers, "\r\nExpect: "))
len += av_strlcatf(headers + len, sizeof(headers) - len,
"Expect: 100-continue\r\n");