Skip to content

Commit

Permalink
avformat: add new_http_request callback to AVIOContext
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Dec 29, 2017
1 parent 0c78b6a commit ac4930e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions libavformat/avio.h
Expand Up @@ -349,6 +349,12 @@ typedef struct AVIOContext {
* Try to buffer at least this amount of data before flushing it
*/
int min_packet_size;

/**
* Make a new request on the underlying http connection.
* This is internal only, do not use from outside.
*/
int (*new_http_request)(struct URLContext *h, char *uri);
} AVIOContext;

/**
Expand Down
1 change: 1 addition & 0 deletions libavformat/aviobuf.c
Expand Up @@ -972,6 +972,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
(*s)->seekable |= AVIO_SEEKABLE_TIME;
}
(*s)->short_seek_get = io_short_seek;
(*s)->new_http_request = h->prot->url_new_http_request;
(*s)->av_class = &ff_avio_class;
return 0;
fail:
Expand Down
13 changes: 6 additions & 7 deletions libavformat/hls.c
Expand Up @@ -26,7 +26,6 @@
* http://tools.ietf.org/html/draft-pantos-http-live-streaming
*/

#include "libavformat/http.h"
#include "libavutil/avstring.h"
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
Expand Down Expand Up @@ -618,7 +617,7 @@ static int open_url_keepalive(AVFormatContext *s, AVIOContext **pb,
URLContext *uc = ffio_geturlcontext(*pb);
av_assert0(uc);
(*pb)->eof_reached = 0;
ret = ff_http_do_new_request(uc, url);
ret = (*pb)->new_http_request(uc, url);
if (ret < 0) {
ff_format_io_close(s, pb);
}
Expand Down Expand Up @@ -670,7 +669,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
return AVERROR_INVALIDDATA;

if (is_http && c->http_persistent && *pb) {
if (c->http_persistent && *pb && (*pb)->new_http_request) {
ret = open_url_keepalive(c->ctx, pb, url);
if (ret == AVERROR_EXIT) {
return ret;
Expand Down Expand Up @@ -725,9 +724,9 @@ static int parse_playlist(HLSContext *c, const char *url,
struct variant_info variant_info;
char tmp_str[MAX_URL_SIZE];
struct segment *cur_init_section = NULL;
int is_http = av_strstart(url, "http", NULL);

if (is_http && !in && c->http_persistent && c->playlist_pb) {
if (!in && c->http_persistent &&
c->playlist_pb && c->playlist_pb->new_http_request) {
in = c->playlist_pb;
ret = open_url_keepalive(c->ctx, &c->playlist_pb, url);
if (ret == AVERROR_EXIT) {
Expand Down Expand Up @@ -761,7 +760,7 @@ static int parse_playlist(HLSContext *c, const char *url,
if (ret < 0)
return ret;

if (is_http && c->http_persistent)
if (c->http_persistent && in && in->new_http_request)
c->playlist_pb = in;
else
close_in = 1;
Expand Down Expand Up @@ -1511,7 +1510,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)

return ret;
}
if (c->http_persistent && av_strstart(seg->url, "http", NULL)) {
if (c->http_persistent && v->input && v->input->new_http_request) {
v->input_read_done = 1;
} else {
ff_format_io_close(v->parent, &v->input);
Expand Down
2 changes: 2 additions & 0 deletions libavformat/http.c
Expand Up @@ -1712,6 +1712,7 @@ const URLProtocol ff_http_protocol = {
.url_write = http_write,
.url_seek = http_seek,
.url_close = http_close,
.url_new_http_request= ff_http_do_new_request,
.url_get_file_handle = http_get_file_handle,
.url_get_short_seek = http_get_short_seek,
.url_shutdown = http_shutdown,
Expand All @@ -1732,6 +1733,7 @@ const URLProtocol ff_https_protocol = {
.url_write = http_write,
.url_seek = http_seek,
.url_close = http_close,
.url_new_http_request= ff_http_do_new_request,
.url_get_file_handle = http_get_file_handle,
.url_get_short_seek = http_get_short_seek,
.url_shutdown = http_shutdown,
Expand Down
1 change: 1 addition & 0 deletions libavformat/url.h
Expand Up @@ -62,6 +62,7 @@ typedef struct URLProtocol {
int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
int (*url_accept)(URLContext *s, URLContext **c);
int (*url_handshake)(URLContext *c);
int (*url_new_http_request)(URLContext *h, char *uri);

/**
* Read data from the protocol.
Expand Down

0 comments on commit ac4930e

Please sign in to comment.