From patchwork Tue Mar 2 14:53:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26062 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 0003F44B9C5 for ; Tue, 2 Mar 2021 16:54:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C3BBC689BE0; Tue, 2 Mar 2021 16:54:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58CBE689AB3 for ; Tue, 2 Mar 2021 16:53:58 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id bm21so16929783ejb.4 for ; Tue, 02 Mar 2021 06:53:58 -0800 (PST) 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=nOGOQ5K9XIWnU7iw5HTJg6AKS5oBYNJ/MDZZRmvDbLg=; b=gv5un6Hrtr25ZUA3G8xyq5bXSb/AOEncwkMbTKu4wKBybiLx+oe/arMknkK06fAMkJ GGIUQkDmfP8NilJC7Jb0wxmVQkGlQWZJE8AGAjFMNxayQcEr8WoLZ9hzP4TlczrNdyND DiFPW0R3ltQCV1H3BDbafaAF+2naQqAYz89roFEnSB6ZgG9XaOwtnTNXF9TQeuP5Nblj cDKaWkPZqXpa5fR6w85eG92a0rgeeVbBLpgTiFGqJYuDhRFSwqcLaH7dN7FRgcIX0R6b iMy4ZLEyL5Ex7gAn/1GzUgFeh8rcAMuY6z+cdg8VcmP1svx4gmti4G9PdslLYV7snOtM trfg== 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=nOGOQ5K9XIWnU7iw5HTJg6AKS5oBYNJ/MDZZRmvDbLg=; b=HoejPgLVJY9dXq3OLIIf3aSNAIEAWJhqypjTnSw0dQNaABNWBfWHXnjLK5TBsq/NTN YHIfkwrOTST8zRmyjmLBlofXJi4pfx2KLdsZI/r8SFjW5YQsj6bfzCXLoO7luFZe6x3T dK55JLQepsF231YUmri5NbU9C/CafstdKJZ6DsHUwSb4nCzdTnsn+y0DGUiFnfCdUgOO lvv+/BYvOCVZpWEcEuVUm5WqjrqcpJ/PiTjuzTzJLwUWe9msvruYefqMnAPx31muSRVb Dp4IVsEi/HVxE5SM9OGzsYvmF+HjUoAiva9It4ls3tp8gtoW4QxA3tJZan5fF5COLq/P nPuQ== X-Gm-Message-State: AOAM532VRhT21un0twuYVjj3sOWdmVZLbXYV9Fjkyu5dKT+S3MWXji50 WdNop1khBaJz9+j61cREY9ZUlE9C6yc= X-Google-Smtp-Source: ABdhPJzGIUsQR5O0GplmOCb8g+qvKATrDrV4pf+uVXfeYViLEHFcr0mA0uDJCMSUJLgH6twAU6d84A== X-Received: by 2002:a17:906:94ca:: with SMTP id d10mr15152231ejy.107.1614696837596; Tue, 02 Mar 2021 06:53:57 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id dm20sm18557873edb.59.2021.03.02.06.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 06:53:57 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Mar 2021 15:53:50 +0100 Message-Id: <20210302145351.514945-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/dashdec: Remove limit on length of id 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" Signed-off-by: Andreas Rheinhardt --- You like this more? (It seems to me that the earlier code would have use a NULL pointer for %s in av_log if there is no id.) libavformat/dashdec.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 6b43fd6278..947b42f816 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -82,7 +82,7 @@ struct representation { AVFormatContext *ctx; int stream_index; - char id[32]; + char *id; char *lang; int bandwidth; AVRational framerate; @@ -361,6 +361,7 @@ static void free_representation(struct representation *pls) av_freep(&pls->url_template); av_freep(&pls->lang); + av_freep(&pls->id); av_freep(&pls); } @@ -842,7 +843,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, *rep_bandwidth_val; + char *rep_bandwidth_val; enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN; // try get information from representation @@ -876,8 +877,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, 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"); + val = xmlGetProp(representation_node, "id"); + if (val) { + rep->id = av_strdup(val); + xmlFree(val); + if (!rep->id) + goto enomem; + } baseurl_nodes[0] = mpd_baseurl_node; baseurl_nodes[1] = period_baseurl_node; @@ -886,7 +893,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, ret = resolve_content_path(s, url, &c->max_url_size, baseurl_nodes, 4); c->max_url_size = aligned(c->max_url_size - + (rep_id_val ? strlen(rep_id_val) : 0) + + (rep->id ? strlen(rep->id) : 0) + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0)); if (ret == AVERROR(ENOMEM) || ret == 0) goto free; @@ -906,7 +913,9 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, goto enomem; } c->max_url_size = aligned(c->max_url_size + strlen(val)); - rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, val); + rep->init_section->url = get_content_url(baseurl_nodes, 4, + c->max_url_size, rep->id, + rep_bandwidth_val, val); xmlFree(val); if (!rep->init_section->url) goto enomem; @@ -915,7 +924,9 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); if (val) { c->max_url_size = aligned(c->max_url_size + strlen(val)); - rep->url_template = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, val); + rep->url_template = get_content_url(baseurl_nodes, 4, + c->max_url_size, rep->id, + rep_bandwidth_val, val); xmlFree(val); } val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); @@ -980,7 +991,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, av_free(seg); goto free; } - seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); + seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, + rep->id, rep_bandwidth_val, NULL); if (!seg->url) goto enomem; seg->size = -1; @@ -1014,8 +1026,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragmenturl_node = xmlFirstElementChild(representation_segmentlist_node); while (fragmenturl_node) { ret = parse_manifest_segmenturlnode(s, rep, fragmenturl_node, - baseurl_nodes, - rep_id_val, + baseurl_nodes, rep->id, rep_bandwidth_val); if (ret < 0) goto free; @@ -1035,15 +1046,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } } } else { - av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", rep_id_val); + av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id '%s' \n", + rep->id ? rep->id : ""); goto free; } if (rep->fragment_duration > 0 && !rep->fragment_timescale) rep->fragment_timescale = 1; rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; - if (rep_id_val) - av_strlcpy(rep->id, rep_id_val, sizeof(rep->id)); rep->framerate = av_make_q(0, 0); if (type == AVMEDIA_TYPE_VIDEO) { char *rep_framerate_val = xmlGetProp(representation_node, "frameRate"); @@ -1070,8 +1080,6 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, goto free; end: - if (rep_id_val) - xmlFree(rep_id_val); if (rep_bandwidth_val) xmlFree(rep_bandwidth_val); @@ -2129,7 +2137,7 @@ static int dash_read_header(AVFormatContext *s) rep->assoc_stream = s->streams[rep->stream_index]; if (rep->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id[0]) + if (rep->id) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); } for (i = 0; i < c->n_audios; i++) { @@ -2138,7 +2146,7 @@ static int dash_read_header(AVFormatContext *s) rep->assoc_stream = s->streams[rep->stream_index]; if (rep->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id[0]) + if (rep->id) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); if (rep->lang) { av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); @@ -2149,7 +2157,7 @@ static int dash_read_header(AVFormatContext *s) rep = c->subtitles[i]; av_program_add_stream_index(s, 0, rep->stream_index); rep->assoc_stream = s->streams[rep->stream_index]; - if (rep->id[0]) + if (rep->id) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); if (rep->lang) { av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); From patchwork Tue Mar 2 14:53:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26063 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 EBE8E44B9C5 for ; Tue, 2 Mar 2021 16:54:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF92968AAFB; Tue, 2 Mar 2021 16:54:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 092AA68AAEB for ; Tue, 2 Mar 2021 16:54:10 +0200 (EET) Received: by mail-ed1-f47.google.com with SMTP id h10so25475889edl.6 for ; Tue, 02 Mar 2021 06:54:10 -0800 (PST) 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=Xlavmv1etUQhhspVdh2MFYUtCSwGS/pMq1fuoCq2z70=; b=Q42FWfvDzgQThw268iXX8Yrb71GOWKYp2lVGtibO2Hqo6McIck12eEIXezWpQwmU8D CEUaGpKTZTYascFcLL4Fg4f2cWggIKYAHnXg7p5LNiT23db4/lq8ClyzQX8PfB4SzsOF EojVYsQFLG7rH478zbsZXpoOrn55rUDMqMO9w4OTf6KSPKzEjhHtteLMdITOzlC58uNz wth5c8pOQQVuZ/inrp8XRGHergMwivw9cWRrLiwvAqFU2feaERq1/oR+Ba9Pbfggj15R aZ9dn8zcpE34rW4Qp8lPKDu+3ZQnfukSq3l8AohmKxLEt4BnC0kZgWgOm9T+hGlAb5tv 7sWA== 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=Xlavmv1etUQhhspVdh2MFYUtCSwGS/pMq1fuoCq2z70=; b=rm0LUXB0pAOMlREXAjzJkgjcVTdnFRWERcJbGVXkqVwVVYqIsb7Qh6FRST4EjJoefU TU5JQ3TNRbCetDhML5/PWBwLBzzecaeaQbyrj82LbPoW3bm+oLuOs3GDggPUJpN++bbh vpv/WtRB0S+UdmsWHHelzEmdF8e39wURJa7TycvswBNQBfTqBbPh4SX0GtuD9DDk5/P2 94Sp6Q8lG5REFyo/IVeXPB6POprt8O6Z/KGpdcU6sKagBA0yrYSEhe4lVS+ZlnIoCv6G vB6c1qW7NXoWQQq+KXgSqFsabHQqfRLmKfhjHkhrEC6Rfz6O2M6g1hWkyDdMF0v28Pyq ZHxg== X-Gm-Message-State: AOAM532v5DDLKzjEjUyBobAUEbdsaQ4uxizpmYwOxadvkK18K9dLxqQO HfZhYbOaXfPZkrfFIHqTGw7JNpNyZ+0= X-Google-Smtp-Source: ABdhPJygTd1ZRGmj7/kTm3m8oETypMW2mY+wt1x5TUY59j7Yrz/bZTDruPlySRQfRkH0GIR82J2H4Q== X-Received: by 2002:a50:fa42:: with SMTP id c2mr2618688edq.159.1614696849290; Tue, 02 Mar 2021 06:54:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id dm20sm18557873edb.59.2021.03.02.06.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 06:54:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Mar 2021 15:53:51 +0100 Message-Id: <20210302145351.514945-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/dashdec: Don't needlessly strdup metadata 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" Signed-off-by: Andreas Rheinhardt --- Using separate lists for audio, video and subtitles leads to lots of code duplication in this demuxer; the only place where one gains a bit is in refresh_manifest (which is already buggy in itself because it leaks upon error...). Is it really worth it? libavformat/dashdec.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 947b42f816..6f3f28dcc7 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -2039,6 +2039,14 @@ static int copy_init_section(struct representation *rep_dest, struct representat static int dash_close(AVFormatContext *s); +static void move_metadata(AVStream *st, const char *key, char **value) +{ + if (*value) { + av_dict_set(&st->metadata, key, *value, AV_DICT_DONT_STRDUP_VAL); + *value = NULL; + } +} + static int dash_read_header(AVFormatContext *s) { DASHContext *c = s->priv_data; @@ -2137,8 +2145,7 @@ static int dash_read_header(AVFormatContext *s) rep->assoc_stream = s->streams[rep->stream_index]; if (rep->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + move_metadata(rep->assoc_stream, "id", &rep->id); } for (i = 0; i < c->n_audios; i++) { rep = c->audios[i]; @@ -2146,23 +2153,15 @@ static int dash_read_header(AVFormatContext *s) rep->assoc_stream = s->streams[rep->stream_index]; if (rep->bandwidth > 0) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); - if (rep->id) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); - if (rep->lang) { - av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); - av_freep(&rep->lang); - } + move_metadata(rep->assoc_stream, "id", &rep->id); + move_metadata(rep->assoc_stream, "language", &rep->lang); } for (i = 0; i < c->n_subtitles; i++) { rep = c->subtitles[i]; av_program_add_stream_index(s, 0, rep->stream_index); rep->assoc_stream = s->streams[rep->stream_index]; - if (rep->id) - av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); - if (rep->lang) { - av_dict_set(&rep->assoc_stream->metadata, "language", rep->lang, 0); - av_freep(&rep->lang); - } + move_metadata(rep->assoc_stream, "id", &rep->id); + move_metadata(rep->assoc_stream, "language", &rep->lang); } return 0;