[FFmpeg-cvslog] avformat/hls: factor identical playlist allocations out of parse_playlist

Anssi Hannula git at videolan.org
Sun Apr 6 16:56:43 CEST 2014


ffmpeg | branch: master | Anssi Hannula <anssi.hannula at iki.fi> | Fri Jan  3 09:47:26 2014 +0200| [05ce529a596c75276b7cd873614529c9c6407fbc] | committer: Anssi Hannula

avformat/hls: factor identical playlist allocations out of parse_playlist

Signed-off-by: Anssi Hannula <anssi.hannula at iki.fi>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=05ce529a596c75276b7cd873614529c9c6407fbc
---

 libavformat/hls.c |   36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index ea6b4cf..9a36ab2 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)



More information about the ffmpeg-cvslog mailing list