[FFmpeg-devel] [PATCH 17/21] avformat/dashdec: Return early for unsupported representations

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Sep 19 19:36:06 EEST 2020


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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/dashdec.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index d75ff92a7b..3b6ae29b1b 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -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:
-- 
2.25.1



More information about the ffmpeg-devel mailing list