1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

avformat/hls: Simplify cleanup after read_header failure

by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2020-03-21 18:31:06 +01:00
parent c3ba8f0d7e
commit 0a7e911108

View File

@ -1874,7 +1874,7 @@ static int hls_read_header(AVFormatContext *s)
c->cur_timestamp = AV_NOPTS_VALUE;
if ((ret = save_avio_options(s)) < 0)
goto fail;
return ret;
/* XXX: Some HLS servers don't like being sent the range header,
in this case, need to setting http_seekable = 0 to disable
@ -1882,12 +1882,11 @@ static int hls_read_header(AVFormatContext *s)
av_dict_set_int(&c->avio_opts, "seekable", c->http_seekable, 0);
if ((ret = parse_playlist(c, s->url, NULL, s->pb)) < 0)
goto fail;
return ret;
if (c->n_variants == 0) {
av_log(s, AV_LOG_WARNING, "Empty playlist\n");
ret = AVERROR_EOF;
goto fail;
return AVERROR_EOF;
}
/* If the playlist only contained playlists (Master Playlist),
* parse each individual playlist. */
@ -1900,7 +1899,7 @@ static int hls_read_header(AVFormatContext *s)
pls->broken = 1;
if (c->n_playlists > 1)
continue;
goto fail;
return ret;
}
}
}
@ -1940,7 +1939,7 @@ static int hls_read_header(AVFormatContext *s)
program = av_new_program(s, i);
if (!program)
goto fail;
return AVERROR(ENOMEM);
av_dict_set_int(&program->metadata, "variant_bitrate", v->bandwidth, 0);
}
@ -1962,10 +1961,8 @@ static int hls_read_header(AVFormatContext *s)
char *url;
AVDictionary *seg_format_opts = NULL;
if (!(pls->ctx = avformat_alloc_context())) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!(pls->ctx = avformat_alloc_context()))
return AVERROR(ENOMEM);
if (pls->n_segments == 0)
continue;
@ -1988,10 +1985,9 @@ static int hls_read_header(AVFormatContext *s)
pls->read_buffer = av_malloc(INITIAL_BUFFER_SIZE);
if (!pls->read_buffer){
ret = AVERROR(ENOMEM);
avformat_free_context(pls->ctx);
pls->ctx = NULL;
goto fail;
return AVERROR(ENOMEM);
}
ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls,
read_data, NULL, NULL);
@ -2009,7 +2005,7 @@ static int hls_read_header(AVFormatContext *s)
avformat_free_context(pls->ctx);
pls->ctx = NULL;
av_free(url);
goto fail;
return ret;
}
av_free(url);
pls->ctx->pb = &pls->pb;
@ -2017,14 +2013,14 @@ static int hls_read_header(AVFormatContext *s)
pls->ctx->flags |= s->flags & ~AVFMT_FLAG_CUSTOM_IO;
if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
goto fail;
return ret;
av_dict_copy(&seg_format_opts, c->seg_format_opts, 0);
ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, &seg_format_opts);
av_dict_free(&seg_format_opts);
if (ret < 0)
goto fail;
return ret;
if (pls->id3_deferred_extra && pls->ctx->nb_streams == 1) {
ff_id3v2_parse_apic(pls->ctx, pls->id3_deferred_extra);
@ -2045,7 +2041,7 @@ static int hls_read_header(AVFormatContext *s)
if (pls->is_id3_timestamped || (pls->n_renditions > 0 && pls->renditions[0]->type == AVMEDIA_TYPE_AUDIO)) {
ret = avformat_find_stream_info(pls->ctx, NULL);
if (ret < 0)
goto fail;
return ret;
}
pls->has_noheader_flag = !!(pls->ctx->ctx_flags & AVFMTCTX_NOHEADER);
@ -2053,7 +2049,7 @@ static int hls_read_header(AVFormatContext *s)
/* Create new AVStreams for each stream in this playlist */
ret = update_streams_from_subdemuxer(s, pls);
if (ret < 0)
goto fail;
return ret;
/*
* Copy any metadata from playlist to main streams, but do not set
@ -2070,9 +2066,6 @@ static int hls_read_header(AVFormatContext *s)
update_noheader_flag(s);
return 0;
fail:
hls_close(s);
return ret;
}
static int recheck_discard_flags(AVFormatContext *s, int first)
@ -2426,6 +2419,7 @@ const AVInputFormat ff_hls_demuxer = {
.priv_class = &hls_class,
.priv_data_size = sizeof(HLSContext),
.flags = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = hls_probe,
.read_header = hls_read_header,
.read_packet = hls_read_packet,