]> git.sesse.net Git - ffmpeg/commitdiff
avformat/dashdec: Return early for unsupported representations
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 19 Sep 2020 10:08:00 +0000 (12:08 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 21 Sep 2020 02:32:12 +0000 (04:32 +0200)
This allows to reduce the level of indentation for parsing the supported
representations (audio, video and subtitles). It also allows to avoid
some allocations and frees for unsupported representations.

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/dashdec.c

index d75ff92a7b17da69073538a608a6fdc164b88e4e..3b6ae29b1b0df4bb6ffe3e8e7b36170f8caa6252 100644 (file)
@@ -852,9 +852,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
     char *val = NULL;
     xmlNodePtr baseurl_nodes[4];
     xmlNodePtr representation_node = node;
-    char *rep_id_val = xmlGetProp(representation_node, "id");
-    char *rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
-    char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
+    char *rep_id_val, *rep_bandwidth_val;
     enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
 
     // try get information from representation
@@ -866,28 +864,29 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
     // try get information from adaption set
     if (type == AVMEDIA_TYPE_UNKNOWN)
         type = get_content_type(adaptionset_node);
-    if (type == AVMEDIA_TYPE_UNKNOWN) {
+    if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO &&
+        type != AVMEDIA_TYPE_SUBTITLE) {
         av_log(s, AV_LOG_VERBOSE, "Parsing '%s' - skipp not supported representation type\n", url);
-    } else if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
+        return 0;
+    }
         // convert selected representation to our internal struct
         rep = av_mallocz(sizeof(struct representation));
-        if (!rep) {
-            ret = AVERROR(ENOMEM);
-            goto end;
-        }
+        if (!rep)
+            return AVERROR(ENOMEM);
         if (c->adaptionset_lang) {
             rep->lang = av_strdup(c->adaptionset_lang);
             if (!rep->lang) {
                 av_log(s, AV_LOG_ERROR, "alloc language memory failure\n");
                 av_freep(&rep);
-                ret = AVERROR(ENOMEM);
-                goto end;
+                return AVERROR(ENOMEM);
             }
         }
         rep->parent = s;
         representation_segmenttemplate_node = find_child_node_by_name(representation_node, "SegmentTemplate");
         representation_baseurl_node = find_child_node_by_name(representation_node, "BaseURL");
         representation_segmentlist_node = find_child_node_by_name(representation_node, "SegmentList");
+        rep_id_val        = xmlGetProp(representation_node, "id");
+        rep_bandwidth_val = xmlGetProp(representation_node, "bandwidth");
 
         baseurl_nodes[0] = mpd_baseurl_node;
         baseurl_nodes[1] = period_baseurl_node;
@@ -1054,10 +1053,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
             rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0;
             strncpy(rep->id, rep_id_val ? rep_id_val : "", sizeof(rep->id));
             rep->framerate = av_make_q(0, 0);
-            if (type == AVMEDIA_TYPE_VIDEO && rep_framerate_val) {
+            if (type == AVMEDIA_TYPE_VIDEO) {
+                char *rep_framerate_val = xmlGetProp(representation_node, "frameRate");
+                if (rep_framerate_val) {
                 ret = av_parse_video_rate(&rep->framerate, rep_framerate_val);
                 if (ret < 0)
                     av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val);
+                xmlFree(rep_framerate_val);
+                }
             }
 
             switch (type) {
@@ -1073,15 +1076,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url,
             }
             if (ret < 0)
                 goto free;
-    }
 
 end:
     if (rep_id_val)
         xmlFree(rep_id_val);
     if (rep_bandwidth_val)
         xmlFree(rep_bandwidth_val);
-    if (rep_framerate_val)
-        xmlFree(rep_framerate_val);
 
     return ret;
 enomem: