diff mbox series

[FFmpeg-devel,09/10] avformat/hls: do error check in add_renditions_to_variant

Message ID tencent_15DD29024EA1A54E13048842B3ED336A7505@qq.com
State New
Headers show
Series [FFmpeg-devel,01/10] avformat/hls: fix repeated requests for media init section | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili April 12, 2022, 8:15 a.m. UTC
---
 libavformat/hls.c | 49 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index b9e2e8a04d..c102e36f52 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1666,9 +1666,10 @@  reload:
     goto restart;
 }
 
-static void add_renditions_to_variant(HLSContext *c, struct variant *var,
-                                      enum AVMediaType type, const char *group_id)
+static int add_renditions_to_variant(HLSContext *c, struct variant *var,
+                                     enum AVMediaType type, const char *group_id)
 {
+    int ret;
     int i;
 
     for (i = 0; i < c->n_renditions; i++) {
@@ -1676,18 +1677,26 @@  static void add_renditions_to_variant(HLSContext *c, struct variant *var,
 
         if (rend->type == type && !strcmp(rend->group_id, group_id)) {
 
-            if (rend->playlist)
+            if (rend->playlist) {
                 /* rendition is an external playlist
                  * => add the playlist to the variant */
-                dynarray_add(&var->playlists, &var->n_playlists, rend->playlist);
-            else
+                ret = av_dynarray_add_nofree(&var->playlists, &var->n_playlists,
+                                             rend->playlist);
+                if (ret < 0)
+                    return ret;
+            } else {
                 /* rendition is part of the variant main Media Playlist
                  * => add the rendition to the main Media Playlist */
-                dynarray_add(&var->playlists[0]->renditions,
-                             &var->playlists[0]->n_renditions,
-                             rend);
+                ret = av_dynarray_add_nofree(&var->playlists[0]->renditions,
+                                             &var->playlists[0]->n_renditions,
+                                             rend);
+                if (ret < 0)
+                    return ret;
+            }
         }
     }
+
+    return 0;
 }
 
 static void add_metadata_from_renditions(AVFormatContext *s, struct playlist *pls,
@@ -1987,12 +1996,24 @@  static int hls_read_header(AVFormatContext *s)
     for (i = 0; i < c->n_variants; i++) {
         struct variant *var = c->variants[i];
 
-        if (var->audio_group[0])
-            add_renditions_to_variant(c, var, AVMEDIA_TYPE_AUDIO, var->audio_group);
-        if (var->video_group[0])
-            add_renditions_to_variant(c, var, AVMEDIA_TYPE_VIDEO, var->video_group);
-        if (var->subtitles_group[0])
-            add_renditions_to_variant(c, var, AVMEDIA_TYPE_SUBTITLE, var->subtitles_group);
+        if (var->audio_group[0]) {
+            ret = add_renditions_to_variant(c, var, AVMEDIA_TYPE_AUDIO,
+                                            var->audio_group);
+            if (ret < 0)
+                return ret;
+        }
+        if (var->video_group[0]) {
+            ret = add_renditions_to_variant(c, var, AVMEDIA_TYPE_VIDEO,
+                                            var->video_group);
+            if (ret < 0)
+                return ret;
+        }
+        if (var->subtitles_group[0]) {
+            ret = add_renditions_to_variant(c, var, AVMEDIA_TYPE_SUBTITLE,
+                                            var->subtitles_group);
+            if (ret < 0)
+                return ret;
+        }
     }
 
     /* Create a program for each variant */