Commit d0fc5de3 authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit '81306fd4'

* commit '81306fd4':
  hls: eliminate ffurl_* usage
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents a588c7ac 81306fd4
......@@ -36,7 +36,6 @@
#include "avformat.h"
#include "internal.h"
#include "avio_internal.h"
#include "url.h"
#include "id3v2.h"
#define INITIAL_BUFFER_SIZE 32768
......@@ -94,7 +93,7 @@ struct playlist {
char url[MAX_URL_SIZE];
AVIOContext pb;
uint8_t* read_buffer;
URLContext *input;
AVIOContext *input;
AVFormatContext *parent;
int index;
AVFormatContext *ctx;
......@@ -248,7 +247,7 @@ static void free_playlist_list(HLSContext *c)
av_packet_unref(&pls->pkt);
av_freep(&pls->pb.buffer);
if (pls->input)
ffurl_close(pls->input);
ff_format_io_close(c->ctx, &pls->input);
if (pls->ctx) {
pls->ctx->pb = NULL;
avformat_close_input(&pls->ctx);
......@@ -582,31 +581,6 @@ static int ensure_playlist(HLSContext *c, struct playlist **pls, const char *url
return 0;
}
static int url_connect(struct playlist *pls, AVDictionary *opts, AVDictionary *opts2)
{
AVDictionary *tmp = NULL;
int ret;
av_dict_copy(&tmp, opts, 0);
av_dict_copy(&tmp, opts2, 0);
if (pls->parent->protocol_whitelist) {
pls->input->protocol_whitelist = av_strdup(pls->parent->protocol_whitelist);
if (!pls->input->protocol_whitelist) {
av_dict_free(&tmp);
return AVERROR(ENOMEM);
}
}
if ((ret = ffurl_connect(pls->input, &tmp)) < 0) {
ffurl_close(pls->input);
pls->input = NULL;
}
av_dict_free(&tmp);
return ret;
}
static void update_options(char **dest, const char *name, void *src)
{
av_freep(dest);
......@@ -615,11 +589,16 @@ static void update_options(char **dest, const char *name, void *src)
av_freep(dest);
}
static int open_url(HLSContext *c, URLContext **uc, const char *url, AVDictionary *opts)
static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
AVDictionary *opts, AVDictionary *opts2)
{
HLSContext *c = s->priv_data;
AVDictionary *tmp = NULL;
int ret;
const char *proto_name = avio_find_protocol_name(url);
int ret;
av_dict_copy(&tmp, opts, 0);
av_dict_copy(&tmp, opts2, 0);
if (!proto_name)
return AVERROR_INVALIDDATA;
......@@ -632,14 +611,11 @@ static int open_url(HLSContext *c, URLContext **uc, const char *url, AVDictionar
else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
return AVERROR_INVALIDDATA;
av_dict_copy(&tmp, c->avio_opts, 0);
av_dict_copy(&tmp, opts, 0);
ret = ffurl_open_whitelist(uc, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp, c->ctx->protocol_whitelist);
if( ret >= 0) {
ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);
if (ret >= 0) {
// update cookies on http response with setcookies.
URLContext *u = *uc;
update_options(&c->cookies, "cookies", u->priv_data);
void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb->opaque;
update_options(&c->cookies, "cookies", u);
av_dict_set(&opts, "cookies", c->cookies, 0);
}
......@@ -862,7 +838,6 @@ enum ReadFromURLMode {
READ_COMPLETE,
};
/* read from URLContext, limiting read to current segment */
static int read_from_url(struct playlist *pls, struct segment *seg,
uint8_t *buf, int buf_size,
enum ReadFromURLMode mode)
......@@ -873,10 +848,12 @@ static int read_from_url(struct playlist *pls, struct segment *seg,
if (seg->size >= 0)
buf_size = FFMIN(buf_size, seg->size - pls->cur_seg_offset);
if (mode == READ_COMPLETE)
ret = ffurl_read_complete(pls->input, buf, buf_size);
else
ret = ffurl_read(pls->input, buf, buf_size);
if (mode == READ_COMPLETE) {
ret = avio_read(pls->input, buf, buf_size);
if (ret != buf_size)
av_log(NULL, AV_LOG_ERROR, "Could not read complete segment.\n");
} else
ret = avio_read(pls->input, buf, buf_size);
if (ret > 0)
pls->cur_seg_offset += ret;
......@@ -981,7 +958,6 @@ static void handle_id3(AVIOContext *pb, struct playlist *pls)
ff_id3v2_free_extra_meta(&extra_meta);
}
/* Intercept and handle ID3 tags between URLContext and AVIOContext */
static void intercept_id3(struct playlist *pls, uint8_t *buf,
int buf_size, int *len)
{
......@@ -1105,19 +1081,19 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
seg->url, seg->url_offset, pls->index);
if (seg->key_type == KEY_NONE) {
ret = open_url(pls->parent->priv_data, &pls->input, seg->url, opts);
ret = open_url(pls->parent, &pls->input, seg->url, c->avio_opts, opts);
} else if (seg->key_type == KEY_AES_128) {
// HLSContext *c = var->parent->priv_data;
AVDictionary *opts2 = NULL;
char iv[33], key[33], url[MAX_URL_SIZE];
if (strcmp(seg->key, pls->key_url)) {
URLContext *uc;
if (open_url(pls->parent->priv_data, &uc, seg->key, opts) == 0) {
if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))
!= sizeof(pls->key)) {
AVIOContext *pb;
if (open_url(pls->parent, &pb, seg->key, c->avio_opts, opts) == 0) {
ret = avio_read(pb, pls->key, sizeof(pls->key));
if (ret != sizeof(pls->key)) {
av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
seg->key);
}
ffurl_close(uc);
ff_format_io_close(pls->parent, &pb);
} else {
av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
seg->key);
......@@ -1132,13 +1108,15 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
else
snprintf(url, sizeof(url), "crypto:%s", seg->url);
if ((ret = ffurl_alloc(&pls->input, url, AVIO_FLAG_READ,
&pls->parent->interrupt_callback)) < 0)
goto cleanup;
av_opt_set(pls->input->priv_data, "key", key, 0);
av_opt_set(pls->input->priv_data, "iv", iv, 0);
av_dict_copy(&opts2, c->avio_opts, 0);
av_dict_set(&opts2, "key", key, 0);
av_dict_set(&opts2, "iv", iv, 0);
ret = open_url(pls->parent, &pls->input, url, opts2, opts);
av_dict_free(&opts2);
if ((ret = url_connect(pls, c->avio_opts, opts)) < 0) {
if (ret < 0) {
goto cleanup;
}
ret = 0;
......@@ -1154,12 +1132,11 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
* should already be where want it to, but this allows e.g. local testing
* without a HTTP server. */
if (ret == 0 && seg->key_type == KEY_NONE && seg->url_offset) {
int seekret = ffurl_seek(pls->input, seg->url_offset, SEEK_SET);
int seekret = avio_seek(pls->input, seg->url_offset, SEEK_SET);
if (seekret < 0) {
av_log(pls->parent, AV_LOG_ERROR, "Unable to seek to offset %"PRId64" of HLS segment '%s'\n", seg->url_offset, seg->url);
ret = seekret;
ffurl_close(pls->input);
pls->input = NULL;
ff_format_io_close(pls->parent, &pls->input);
}
}
......@@ -1185,8 +1162,6 @@ static int update_init_section(struct playlist *pls, struct segment *seg)
if (!seg->init_section)
return 0;
/* this will clobber playlist URLContext stuff, so this should be
* called between segments only */
ret = open_input(c, pls, seg->init_section);
if (ret < 0) {
av_log(pls->parent, AV_LOG_WARNING,
......@@ -1197,7 +1172,7 @@ static int update_init_section(struct playlist *pls, struct segment *seg)
if (seg->init_section->size >= 0)
sec_size = seg->init_section->size;
else if ((urlsize = ffurl_size(pls->input)) >= 0)
else if ((urlsize = avio_size(pls->input)) >= 0)
sec_size = urlsize;
else
sec_size = max_init_section_size;
......@@ -1212,8 +1187,7 @@ static int update_init_section(struct playlist *pls, struct segment *seg)
ret = read_from_url(pls, seg->init_section, pls->init_sec_buf,
pls->init_sec_buf_size, READ_COMPLETE);
ffurl_close(pls->input);
pls->input = NULL;
ff_format_io_close(pls->parent, &pls->input);
if (ret < 0)
return ret;
......@@ -1340,8 +1314,7 @@ reload:
return ret;
}
ffurl_close(v->input);
v->input = NULL;
ff_format_io_close(v->parent, &v->input);
v->cur_seq_no++;
c->cur_seq_no = v->cur_seq_no;
......@@ -1513,7 +1486,7 @@ static int save_avio_options(AVFormatContext *s)
static int hls_read_header(AVFormatContext *s)
{
URLContext *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb->opaque;
void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb->opaque;
HLSContext *c = s->priv_data;
int ret = 0, i, j, stream_offset = 0;
......@@ -1525,19 +1498,18 @@ static int hls_read_header(AVFormatContext *s)
c->first_timestamp = AV_NOPTS_VALUE;
c->cur_timestamp = AV_NOPTS_VALUE;
// if the URL context is good, read important options we must broker later
if (u && u->prot->priv_data_class) {
if (u) {
// get the previous user agent & set back to null if string size is zero
update_options(&c->user_agent, "user-agent", u->priv_data);
update_options(&c->user_agent, "user-agent", u);
// get the previous cookies & set back to null if string size is zero
update_options(&c->cookies, "cookies", u->priv_data);
update_options(&c->cookies, "cookies", u);
// get the previous headers & set back to null if string size is zero
update_options(&c->headers, "headers", u->priv_data);
update_options(&c->headers, "headers", u);
// get the previous http proxt & set back to null if string size is zero
update_options(&c->http_proxy, "http_proxy", u->priv_data);
update_options(&c->http_proxy, "http_proxy", u);
}
if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
......@@ -1747,8 +1719,7 @@ static int recheck_discard_flags(AVFormatContext *s, int first)
av_log(s, AV_LOG_INFO, "Now receiving playlist %d, segment %d\n", i, pls->cur_seq_no);
} else if (first && !pls->cur_needed && pls->needed) {
if (pls->input)
ffurl_close(pls->input);
pls->input = NULL;
ff_format_io_close(pls->parent, &pls->input);
pls->needed = 0;
changed = 1;
av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i);
......@@ -1953,10 +1924,8 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
for (i = 0; i < c->n_playlists; i++) {
/* Reset reading */
struct playlist *pls = c->playlists[i];
if (pls->input) {
ffurl_close(pls->input);
pls->input = NULL;
}
if (pls->input)
ff_format_io_close(pls->parent, &pls->input);
av_packet_unref(&pls->pkt);
reset_packet(&pls->pkt);
pls->pb.eof_reached = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment