Skip to content

Commit

Permalink
avformat/hls: allow open_input to be re-used
Browse files Browse the repository at this point in the history
Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
  • Loading branch information
tmm1 committed Dec 22, 2017
1 parent b7d6c0c commit 03765aa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions libavformat/hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf,
pls->is_id3_timestamped = (pls->id3_mpegts_timestamp != AV_NOPTS_VALUE);
}

static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in)
{
AVDictionary *opts = NULL;
int ret;
Expand All @@ -1176,7 +1176,7 @@ 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, &pls->input, seg->url, c->avio_opts, opts, &is_http);
ret = open_url(pls->parent, in, seg->url, c->avio_opts, opts, &is_http);
} else if (seg->key_type == KEY_AES_128) {
AVDictionary *opts2 = NULL;
char iv[33], key[33], url[MAX_URL_SIZE];
Expand Down Expand Up @@ -1207,7 +1207,7 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
av_dict_set(&opts2, "key", key, 0);
av_dict_set(&opts2, "iv", iv, 0);

ret = open_url(pls->parent, &pls->input, url, opts2, opts, &is_http);
ret = open_url(pls->parent, in, url, opts2, opts, &is_http);

av_dict_free(&opts2);

Expand All @@ -1234,11 +1234,11 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
* noticed without the call, though.
*/
if (ret == 0 && !is_http && seg->key_type == KEY_NONE && seg->url_offset) {
int64_t seekret = avio_seek(pls->input, seg->url_offset, SEEK_SET);
int64_t seekret = avio_seek(*in, 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;
ff_format_io_close(pls->parent, &pls->input);
ff_format_io_close(pls->parent, in);
}
}

Expand All @@ -1264,7 +1264,7 @@ static int update_init_section(struct playlist *pls, struct segment *seg)
if (!seg->init_section)
return 0;

ret = open_input(c, pls, seg->init_section);
ret = open_input(c, pls, seg->init_section, &pls->input);
if (ret < 0) {
av_log(pls->parent, AV_LOG_WARNING,
"Failed to open an initialization section in playlist %d\n",
Expand Down Expand Up @@ -1430,7 +1430,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
if (ret)
return ret;

ret = open_input(c, v, seg);
ret = open_input(c, v, seg, &v->input);
if (ret < 0) {
if (ff_check_interrupt(c->interrupt_callback))
return AVERROR_EXIT;
Expand Down

0 comments on commit 03765aa

Please sign in to comment.