Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
Originally committed as revision 19256 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
74a30595b2
commit
7995ed8e69
@ -23,6 +23,7 @@
|
|||||||
#include "libavutil/avstring.h"
|
#include "libavutil/avstring.h"
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <strings.h>
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "os_support.h"
|
#include "os_support.h"
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ typedef struct {
|
|||||||
unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
|
unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
|
||||||
int line_count;
|
int line_count;
|
||||||
int http_code;
|
int http_code;
|
||||||
|
int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
|
||||||
int64_t off, filesize;
|
int64_t off, filesize;
|
||||||
char location[URL_SIZE];
|
char location[URL_SIZE];
|
||||||
} HTTPContext;
|
} HTTPContext;
|
||||||
@ -124,6 +126,7 @@ static int http_open(URLContext *h, const char *uri, int flags)
|
|||||||
}
|
}
|
||||||
h->priv_data = s;
|
h->priv_data = s;
|
||||||
s->filesize = -1;
|
s->filesize = -1;
|
||||||
|
s->chunksize = -1;
|
||||||
s->off = 0;
|
s->off = 0;
|
||||||
av_strlcpy(s->location, uri, URL_SIZE);
|
av_strlcpy(s->location, uri, URL_SIZE);
|
||||||
|
|
||||||
@ -222,6 +225,9 @@ static int process_line(URLContext *h, char *line, int line_count,
|
|||||||
s->filesize = atoll(slash+1);
|
s->filesize = atoll(slash+1);
|
||||||
}
|
}
|
||||||
h->is_streamed = 0; /* we _can_ in fact seek */
|
h->is_streamed = 0; /* we _can_ in fact seek */
|
||||||
|
} else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
|
||||||
|
s->filesize = -1;
|
||||||
|
s->chunksize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -296,6 +302,27 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
HTTPContext *s = h->priv_data;
|
HTTPContext *s = h->priv_data;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
if (s->chunksize >= 0) {
|
||||||
|
if (!s->chunksize) {
|
||||||
|
char line[32];
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
do {
|
||||||
|
if (http_get_line(s, line, sizeof(line)) < 0)
|
||||||
|
return AVERROR(EIO);
|
||||||
|
} while (!*line); /* skip CR LF from last chunk */
|
||||||
|
|
||||||
|
s->chunksize = strtoll(line, NULL, 16);
|
||||||
|
|
||||||
|
dprintf(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize);
|
||||||
|
|
||||||
|
if (!s->chunksize)
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size = FFMIN(size, s->chunksize);
|
||||||
|
}
|
||||||
/* read bytes from input buffer first */
|
/* read bytes from input buffer first */
|
||||||
len = s->buf_end - s->buf_ptr;
|
len = s->buf_end - s->buf_ptr;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
@ -306,8 +333,11 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
} else {
|
} else {
|
||||||
len = url_read(s->hd, buf, size);
|
len = url_read(s->hd, buf, size);
|
||||||
}
|
}
|
||||||
if (len > 0)
|
if (len > 0) {
|
||||||
s->off += len;
|
s->off += len;
|
||||||
|
if (s->chunksize > 0)
|
||||||
|
s->chunksize -= len;
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user