From patchwork Sat Sep 19 16:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22499 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 389AE4493ED for ; Sat, 19 Sep 2020 19:39:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0A8EA68B920; Sat, 19 Sep 2020 19:37:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0A3D468B773 for ; Sat, 19 Sep 2020 19:37:30 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id q9so8115338wmj.2 for ; Sat, 19 Sep 2020 09:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OYZKNz9htLaj+VRbd7B8Tv+xOwWfuxQvvLSZ+AafMlY=; b=HccVWTBasFLoAeIY/Bw0+Etm/dM7A3z8siVQSszCU2x16BWIgFW/mVKopYxMwKPtjs L8LoKXJCVElX00CWKtvkEdDyW7rUZxdQ0NomMBItS6PaeTAbzU11TsIDZ03FT0/F8cOe mXH/zDBODuKOR994/cCO97lGjiWtIi/9iVCpTdRnDinKu+QTgLMRRerFFatr1qN4aMb1 1+52SMNIw8HUhSAXP9o1Lh75eBfQeFUVlQ5S4YGTl/yCnGzbYPZzJIdMT8o2WHdRtZSG b7uL+oZfSsWQnyqWAHqdy+vwjEcmpe+TnK3tVeS9kISX55wJgrA/C2VVhRR8eWBB4xDz REqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OYZKNz9htLaj+VRbd7B8Tv+xOwWfuxQvvLSZ+AafMlY=; b=A5abFJsrvj8LHHlxx5ymBC2AhI4+U0DLDJnMNRNdOeqA08MAMAazY3YePBPh6eru/P pcOscYW3wnEWfg4lRcnPBie1yOpIAmybvleCPByI/xvuFVuKNxtoI1N6gz2yzMT01ITZ SBTBKJx56X9tDVA+sj09nhqHd6313IKOpmYddmCdP9VkwdwYaIx6wkAk5Rv1LO/emQcL 0DfIZQd67vpIJf1Gg4pECJOlanWGfE84tAfpCjz9C3UQ6uZ2j99v0fcSiue9iqX+8OCb VdwleBWkredDrouOJkVlrXbWooMW6KiJ5xxyUV9nX/mHd7dCEU+SfNrfwXBqDIF3TCR2 fp2w== X-Gm-Message-State: AOAM532wfTWDNf9KqoDyZDjmR/Noa8vd+4xxM95XR5Hr81J0hBZ6IC3G Ss4GJChElOyZKcVnH5l2m/0hBb5383s= X-Google-Smtp-Source: ABdhPJzBb51MCcgQ8JB7tpxgq9bVtUZnuriPcvU8tueBrSiSFHsGK5ZLtbjref1WFFgZ12+Diq7nyQ== X-Received: by 2002:a1c:740c:: with SMTP id p12mr21272019wmc.176.1600533450199; Sat, 19 Sep 2020 09:37:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:06 +0200 Message-Id: <20200919163610.1099233-17-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/21] avformat/dashdec: Return early for unsupported representations X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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: