diff options
author | Anssi Hannula <anssi.hannula@iki.fi> | 2014-01-03 09:47:26 +0200 |
---|---|---|
committer | Anssi Hannula <anssi.hannula@iki.fi> | 2014-04-06 17:55:03 +0300 |
commit | 05ce529a596c75276b7cd873614529c9c6407fbc (patch) | |
tree | 141ed0556f96d7856751b7d88e19001ffdec032c /libavformat/hls.c | |
parent | 6b4b73e75da926aa09dab06789643fb491dfe0ca (diff) | |
download | ffmpeg-05ce529a596c75276b7cd873614529c9c6407fbc.tar.gz |
avformat/hls: factor identical playlist allocations out of parse_playlist
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Diffstat (limited to 'libavformat/hls.c')
-rw-r--r-- | libavformat/hls.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c index ea6b4cf1a1..9a36ab2f00 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -465,6 +465,22 @@ static void handle_rendition_args(struct rendition_info *info, const char *key, */ } +/* used by parse_playlist to allocate a new variant+playlist when the + * playlist is detected to be a Media Playlist (not Master Playlist) + * and we have no parent Master Playlist (parsing of which would have + * allocated the variant and playlist already) */ +static int ensure_playlist(HLSContext *c, struct playlist **pls, const char *url) +{ + if (*pls) + return 0; + if (!new_variant(c, NULL, url, NULL)) + return AVERROR(ENOMEM); + *pls = c->playlists[c->n_playlists - 1]; + return 0; +} + +/* pls = NULL => Master Playlist or parentless Media Playlist + * pls = !NULL => parented Media Playlist, playlist+variant allocated */ static int parse_playlist(HLSContext *c, const char *url, struct playlist *pls, AVIOContext *in) { @@ -539,22 +555,14 @@ static int parse_playlist(HLSContext *c, const char *url, &info); new_rendition(c, &info, url); } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) { - if (!pls) { - if (!new_variant(c, NULL, url, NULL)) { - ret = AVERROR(ENOMEM); - goto fail; - } - pls = c->playlists[c->n_playlists - 1]; - } + ret = ensure_playlist(c, &pls, url); + if (ret < 0) + goto fail; pls->target_duration = atoi(ptr) * AV_TIME_BASE; } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) { - if (!pls) { - if (!new_variant(c, NULL, url, NULL)) { - ret = AVERROR(ENOMEM); - goto fail; - } - pls = c->playlists[c->n_playlists - 1]; - } + ret = ensure_playlist(c, &pls, url); + if (ret < 0) + goto fail; pls->start_seq_no = atoi(ptr); } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { if (pls) |