On Mon, 10 Mar 2014, Alessandro Ghedini wrote:

On sab, mar 08, 2014 at 01:16:06 +0200, Martin Storsjö wrote:
On Thu, 6 Mar 2014, Alessandro Ghedini wrote:

Original ffmpeg commit by d52882f Anssi Hannula.
---
doc/protocols.texi |  6 ++++++
libavformat/http.c | 17 ++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 4a98550..ffbb742 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -114,6 +114,12 @@ If the server supports ICY metadata, and @option{icy} was 
set to 1, this
contains the last non-empty metadata packet sent by the server. It should be
polled in regular intervals by applications interested in metadata updates
mid-stream.
+
+@item offset
+Set initial byte offset.
+
+@item end_offset
+Try to limit the request to bytes preceding this offset.
@end table

@section mmst
diff --git a/libavformat/http.c b/libavformat/http.c
index 88265ff..1f66639 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -50,8 +50,8 @@ typedef struct {
   int line_count;
   int http_code;
   int64_t chunksize;      /**< Used if "Transfer-Encoding: chunked" otherwise 
-1. */
-    int64_t off, filesize;
   char *user_agent;
+    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;
@@ -98,6 +98,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)\
@@ -514,9 +516,18 @@ static int http_connect(URLContext *h, const char *path, 
const char *local_path,
   if (!has_header(s->headers, "\r\nAccept: "))
       len += av_strlcpy(headers + len, "Accept: */*\r\n",
                         sizeof(headers) - len);
-    if (!has_header(s->headers, "\r\nRange: ") && !post)
+    // 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->req_end_offset)) {

This cherrypick seems to have lost something in translation, compared to the
original place where it was introduced.

Yeah, I left the ->seekable code out on purpose. IIRC Luca wanted modifications
to that part, and since I didn't write that code I wasn't sure I could actually
do anything useful.

I guess that either removing the comment or re-introducing the seekable code
would work.

Removing the comment isn't ok - we on purpose need to send the Range: header on every request (unless it's a POST). The exception for this is if you have the "seekable" flag as in ffmpeg. In our case when we don't have it, this line should just be kept as it already was, that is:

if (!has_header(s->headers, "\r\nRange: ") && !post)

In case the seekable flag gets added later, one needs to add the && (s->off > 0 || s->req_end_offset || s->seekable == -1) part. But for now when no seekable flag exists, we should behave as if seekable was == -1, that is the whole parenthesis is always evaluated to true.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to