From patchwork Sat Mar 28 13:25:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 18459 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 3F3E144BE23 for ; Sat, 28 Mar 2020 15:25:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2794E68B6BA; Sat, 28 Mar 2020 15:25:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92C2068B5E8 for ; Sat, 28 Mar 2020 15:25:24 +0200 (EET) X-QQ-mid: bizesmtp18t1585401907teghl32b Received: from localhost (unknown [114.245.17.93]) by esmtp6.qq.com (ESMTP) with id ; Sat, 28 Mar 2020 21:25:06 +0800 (CST) X-QQ-SSF: 01100000002000K0ZTF0000A0000000 X-QQ-FEAT: Oj0A4zlq//fcZWs70qcBA2KKHBfTUz/OapB8BFWQySpVBUALGWWrrPch+UE3x pyFmDQiePxI0FSojooI8IPjmRuaXmJ8HFPu+0VseqjxqEuWQdOGQFti1kn/Hv41TwKHKqfY QFi7vwHAizHdUscBY1tzACnXBcDrV5kIdKzDnswhTo+q/vizsyP0snS1MLJA3xjhEK6ckSs C5bYi2MYuiF1hH51D2EUK4G5Nc84nBME1nPp9c4LW5J9MVZvubPGfimZwXsdW/hgFR8pCHH fnsAQI4MMiKGpTL2WWYmUJKWunFhghsg+Pytk+y3pcBEf7eZgOJNtx2YEDPloVB8L8UP40b uti4ze52unKAToJ2NI= X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Mar 2020 21:25:03 +0800 Message-Id: <20200328132504.98885-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200328115413.xn3w6sbolevpztgr@phare.normalesup.org> References: <20200328115413.xn3w6sbolevpztgr@phare.normalesup.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v4 1/2] Revert "avformat/dashdec: refine adaptionset attribute members" 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: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This reverts commit e134c20374ee3cbc6d04885d306b02c9871683a2. Signed-off-by: Steven Liu --- libavformat/dashdec.c | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 5bbe5d3985..271202b0a5 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -122,19 +122,6 @@ struct representation { typedef struct DASHContext { const AVClass *class; char *base_url; - char *adaptionset_contenttype_val; - char *adaptionset_par_val; - char *adaptionset_lang_val; - char *adaptionset_minbw_val; - char *adaptionset_maxbw_val; - char *adaptionset_minwidth_val; - char *adaptionset_maxwidth_val; - char *adaptionset_minheight_val; - char *adaptionset_maxheight_val; - char *adaptionset_minframerate_val; - char *adaptionset_maxframerate_val; - char *adaptionset_segmentalignment_val; - char *adaptionset_bitstreamswitching_val; int n_videos; struct representation **videos; @@ -1124,26 +1111,12 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr period_segmentlist_node) { int ret = 0; - DASHContext *c = s->priv_data; xmlNodePtr fragment_template_node = NULL; xmlNodePtr content_component_node = NULL; xmlNodePtr adaptionset_baseurl_node = NULL; xmlNodePtr adaptionset_segmentlist_node = NULL; xmlNodePtr adaptionset_supplementalproperty_node = NULL; xmlNodePtr node = NULL; - c->adaptionset_contenttype_val = xmlGetProp(adaptionset_node, "contentType"); - c->adaptionset_par_val = xmlGetProp(adaptionset_node, "par"); - c->adaptionset_lang_val = xmlGetProp(adaptionset_node, "lang"); - c->adaptionset_minbw_val = xmlGetProp(adaptionset_node, "minBandwidth"); - c->adaptionset_maxbw_val = xmlGetProp(adaptionset_node, "maxBandwidth"); - c->adaptionset_minwidth_val = xmlGetProp(adaptionset_node, "minWidth"); - c->adaptionset_maxwidth_val = xmlGetProp(adaptionset_node, "maxWidth"); - c->adaptionset_minheight_val = xmlGetProp(adaptionset_node, "minHeight"); - c->adaptionset_maxheight_val = xmlGetProp(adaptionset_node, "maxHeight"); - c->adaptionset_minframerate_val = xmlGetProp(adaptionset_node, "minFrameRate"); - c->adaptionset_maxframerate_val = xmlGetProp(adaptionset_node, "maxFrameRate"); - c->adaptionset_segmentalignment_val = xmlGetProp(adaptionset_node, "segmentAlignment"); - c->adaptionset_bitstreamswitching_val = xmlGetProp(adaptionset_node, "bitstreamSwitching"); node = xmlFirstElementChild(adaptionset_node); while (node) { From patchwork Sat Mar 28 13:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 18460 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 2B99C44BE23 for ; Sat, 28 Mar 2020 15:25:38 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D55768B6CE; Sat, 28 Mar 2020 15:25:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D31968B5E8 for ; Sat, 28 Mar 2020 15:25:30 +0200 (EET) X-QQ-mid: bizesmtp21t1585401914tvg2ybvq Received: from localhost (unknown [114.245.17.93]) by esmtp6.qq.com (ESMTP) with id ; Sat, 28 Mar 2020 21:25:13 +0800 (CST) X-QQ-SSF: 01100000002000K0ZTF0000A0000000 X-QQ-FEAT: urqllK+UIe4ZVtUusQCClZUii0XR+eldlHzQYcUWIWPEIwzLsuFx7oVpcWRGn Wpl+25a3ewwtZ6iknPP8hns/Wvmmx2DBDkp5QDK16Js13fPYKuyppZul5lT2hQh2B28ErbF jR0nQ3yVWDeJeN9ju1z0tyHJPPMyqV9Xoc3WIsJS9OPC/Gs+2fQ9/IVv4KpMvIOzzuqAdl4 HkJQV6puUw6z6LaSESEreictXSj4kfn8sEtXG6FQi3xTvRyLRVegQscPS8G1p71LnLeCAfr RCOd68zeBUjEZYMRVVIh5o4eSDC1A7bXjT1E+hUhkM7tu62/DabmSVntNnUhg/72LAoRQSY Mcf3ztvVHvrkTzfUNQ= X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Mar 2020 21:25:04 +0800 Message-Id: <20200328132504.98885-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200328132504.98885-1-lq@chinaffmpeg.org> References: <20200328115413.xn3w6sbolevpztgr@phare.normalesup.org> <20200328132504.98885-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v4 2/2] avformat/dashdec: refine adaptionset attribute members 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: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" all the members is used check all the representation useable. Signed-off-by: Steven Liu --- libavformat/dashdec.c | 203 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 199 insertions(+), 4 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 271202b0a5..63caa696f8 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -108,6 +108,7 @@ struct representation { int64_t cur_seg_offset; int64_t cur_seg_size; struct fragment *cur_seg; + char *lang; /* Currently active Media Initialization Section */ struct fragment *init_section; @@ -123,6 +124,16 @@ typedef struct DASHContext { const AVClass *class; char *base_url; + char *adaptionset_lang; + uint64_t adaptionset_minbw; + uint64_t adaptionset_maxbw; + uint64_t adaptionset_minwidth; + uint64_t adaptionset_maxwidth; + uint64_t adaptionset_minheight; + uint64_t adaptionset_maxheight; + AVRational adaptionset_minframerate; + AVRational adaptionset_maxframerate; + int n_videos; struct representation **videos; int n_audios; @@ -156,6 +167,85 @@ typedef struct DASHContext { } DASHContext; +static int get_ratio_from_string(AVRational *dst, const char *src) +{ + char *end = NULL; + char *end_ptr = NULL; + long num, den; + + num = strtol(src, &end_ptr, 10); + if (errno == ERANGE || end_ptr == src) + return AVERROR_INVALIDDATA; + + if (num > INT_MAX) + return AVERROR_INVALIDDATA; + + if (end_ptr[0] == '\0') { + dst->den = 1; + dst->num = (int)num; + return 0; + } + + if (end_ptr[0] != '/') + return AVERROR_INVALIDDATA; + + end_ptr++; + den = strtol(end_ptr, &end, 10); + if (errno == ERANGE || end == src) + return AVERROR_INVALIDDATA; + + if (den > INT_MAX) + return AVERROR_INVALIDDATA; + + dst->den = (int)den; + + return 0; +} + +static int dash_prop_get_uint64(AVFormatContext *s, xmlNodePtr node, uint64_t *dst, const char *key) +{ + char *end_ptr = NULL; + char *val = xmlGetProp(node, key); + int ret = 0; + uint64_t tmpval = 0; + + if (val) { + tmpval = strtoull(val, &end_ptr, 10); + if (errno == ERANGE) { + av_log(s, AV_LOG_WARNING, "overflow/underflow when get value of %s\n", key); + ret = AVERROR_INVALIDDATA; + goto out; + } + if (end_ptr == val || end_ptr[0] != '\0') { + av_log(s, AV_LOG_ERROR, "The %s field value is " + "not a valid number: %s\n", key, val); + ret = AVERROR_INVALIDDATA; + goto out; + } + *dst = tmpval; +out: + xmlFree(val); + } + return ret; +} + +static int dash_get_prop_ratio(AVFormatContext *s, xmlNodePtr node, AVRational *member, const char *key) +{ + char *val = xmlGetProp(node, key); + int ret = 0; + AVRational rate; + + if (val) { + ret = get_ratio_from_string(&rate, val); + if (ret < 0) + av_log(s, AV_LOG_WARNING, "Ignoring invalid %s frame rate '%s'\n", key, val); + xmlFree(val); + } + member->num = rate.num; + member->den = rate.den; + return ret; +} + static int ishttp(char *url) { const char *proto_name = avio_find_protocol_name(url); @@ -872,6 +962,15 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, ret = AVERROR(ENOMEM); goto end; } + 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; + } + } 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"); @@ -1057,15 +1156,55 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, } if (rep) { + uint64_t width = 0; + uint64_t height = 0; + if (rep->fragment_duration > 0 && !rep->fragment_timescale) rep->fragment_timescale = 1; rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; + if (rep_bandwidth_val && (rep->bandwidth > c->adaptionset_maxbw || rep->bandwidth < c->adaptionset_minbw)) { + av_log(s, AV_LOG_WARNING, "The bandwidth of representation %s is incorrect, " + "will ignore this representation.\n", rep_id_val); + free_representation(rep); + goto end; + } + + if (dash_prop_get_uint64(s, representation_node, &width, "width") < 0) + av_log(s, AV_LOG_WARNING, "Ignoring the width of representation %s is incorrect.\n", rep_id_val); + if (width > c->adaptionset_maxwidth || width < c->adaptionset_minwidth) { + av_log(s, AV_LOG_WARNING, "will ignore representation %s, width is %"PRIu64".\n", rep_id_val, width); + free_representation(rep); + goto end; + } + + if (dash_prop_get_uint64(s, representation_node, &height, "height") < 0) + av_log(s, AV_LOG_WARNING, "Ignoring the height of representation %s is incorrect.\n", rep_id_val); + if (height > c->adaptionset_maxheight || height < c->adaptionset_minheight) { + av_log(s, AV_LOG_WARNING, "will ignore representation %s, height is %"PRIu64".\n", rep_id_val, height); + free_representation(rep); + goto end; + } + 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) { - ret = av_parse_video_rate(&rep->framerate, rep_framerate_val); + ret = get_ratio_from_string(&rep->framerate, rep_framerate_val); if (ret < 0) - av_log(s, AV_LOG_VERBOSE, "Ignoring invalid frame rate '%s'\n", rep_framerate_val); + av_log(s, AV_LOG_WARNING, "Ignoring invalid frame rate '%s'\n", rep_framerate_val); + if (c->adaptionset_maxframerate.num > 0) { + if (av_cmp_q(rep->framerate, c->adaptionset_maxframerate) == 1) { + av_log(s, AV_LOG_WARNING, "will ignore representation %s, framerate is %s.\n", rep_id_val, rep_framerate_val); + free_representation(rep); + goto end; + } + } + if (c->adaptionset_minframerate.num > 0) { + if (av_cmp_q(rep->framerate, c->adaptionset_minframerate) == -1) { + av_log(s, AV_LOG_WARNING, "will ignore representation %s, framerate is %s.\n", rep_id_val, rep_framerate_val); + free_representation(rep); + goto end; + } + } } switch (type) { @@ -1093,6 +1232,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, subtitle_rep_idx += type == AVMEDIA_TYPE_SUBTITLE; end: + if (rep_id_val) xmlFree(rep_id_val); if (rep_bandwidth_val) @@ -1103,6 +1243,45 @@ end: return ret; } +static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node) +{ + int ret = 0; + DASHContext *c = s->priv_data; + + if (!adaptionset_node) { + av_log(s, AV_LOG_WARNING, "Cannot get AdaptionSet\n"); + return AVERROR(EINVAL); + } + + c->adaptionset_lang = xmlGetProp(adaptionset_node, "lang"); + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_minbw, "minBandwidth") < 0) + c->adaptionset_minbw = 0; + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_maxbw, "maxBandwidth") < 0) + c->adaptionset_maxbw = UINT64_MAX; + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_minwidth, "minWidth") < 0) + c->adaptionset_minwidth = 0; + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_maxwidth, "maxWidth") < 0) + c->adaptionset_maxwidth = UINT64_MAX; + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_minheight, "minHeight") < 0) + c->adaptionset_minheight = 0; + + if (dash_prop_get_uint64(s, adaptionset_node, &c->adaptionset_maxheight, "maxHeight") < 0) + c->adaptionset_maxheight = UINT64_MAX; + + if (dash_get_prop_ratio(s, adaptionset_node, &c->adaptionset_minframerate, "minFrameRate") < 0) + c->adaptionset_minframerate = av_make_q(0, 0); + + if (dash_get_prop_ratio(s, adaptionset_node, &c->adaptionset_maxframerate, "maxFrameRate") < 0) + c->adaptionset_maxframerate = av_make_q(0, 0); + + return ret; +} + static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr adaptionset_node, xmlNodePtr mpd_baseurl_node, @@ -1111,6 +1290,7 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr period_segmentlist_node) { int ret = 0; + DASHContext *c = s->priv_data; xmlNodePtr fragment_template_node = NULL; xmlNodePtr content_component_node = NULL; xmlNodePtr adaptionset_baseurl_node = NULL; @@ -1118,6 +1298,10 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr adaptionset_supplementalproperty_node = NULL; xmlNodePtr node = NULL; + ret = parse_manifest_adaptationset_attr(s, adaptionset_node); + if (ret < 0) + return ret; + node = xmlFirstElementChild(adaptionset_node); while (node) { if (!av_strcasecmp(node->name, (const char *)"SegmentTemplate")) { @@ -1143,12 +1327,15 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, adaptionset_segmentlist_node, adaptionset_supplementalproperty_node); if (ret < 0) { - return ret; + goto end; } } node = xmlNextElementSibling(node); } - return 0; + +end: + av_freep(&c->adaptionset_lang); + return ret; } static int parse_programinformation(AVFormatContext *s, xmlNodePtr node) @@ -2121,6 +2308,10 @@ static int dash_read_header(AVFormatContext *s) av_dict_set_int(&rep->assoc_stream->metadata, "variant_bitrate", rep->bandwidth, 0); if (rep->id[0]) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + if (rep->lang) { + av_dict_set(&rep->assoc_stream->metadata, "lang", rep->lang, 0); + av_freep(&rep->lang); + } } for (i = 0; i < c->n_subtitles; i++) { rep = c->subtitles[i]; @@ -2128,6 +2319,10 @@ static int dash_read_header(AVFormatContext *s) rep->assoc_stream = s->streams[rep->stream_index]; if (rep->id[0]) av_dict_set(&rep->assoc_stream->metadata, "id", rep->id, 0); + if (rep->lang) { + av_dict_set(&rep->assoc_stream->metadata, "lang", rep->lang, 0); + av_freep(&rep->lang); + } } }