From patchwork Sun Mar 29 01:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 18477 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 8934244ADED for ; Sun, 29 Mar 2020 04:04:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FADB68B46D; Sun, 29 Mar 2020 04:04:52 +0300 (EEST) 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 4854568B1B1 for ; Sun, 29 Mar 2020 04:04:45 +0300 (EEST) X-QQ-mid: bizesmtp23t1585443869t6hmiruv Received: from localhost (unknown [114.245.17.93]) by esmtp10.qq.com (ESMTP) with id ; Sun, 29 Mar 2020 09:04:29 +0800 (CST) X-QQ-SSF: 01100000002000K0ZTF0000A0000000 X-QQ-FEAT: dMLGSgzcGosse3Yvi0wjE2PUIcaG7vAy/PBHpeLw2bcTk9VW5TC/f5aOzv+VV COW39sRKLwI/LF9Wr1WNnCYRRSwctDWiTvt9hQSoxGcenTkoKVekCa0J9B/eYINgu/iNvC/ IhaNjYT6bd46LsCvkAmpsTVl3JTvL+uQhKoNikNbiQZ3wqJ+Rd9pPK+LCE1Lvg6QhdT/88R KH9s0pqCLCnGZmpMkF0S4oXSByBNTH125QaiHLiyR6KdtElRbQ9NfK2uTa0f2RVjTv6KIb5 f/bLiYyX/LEotfsa4WNu8pVsGuKiiBCx/cTuD9yXDXiAy7OuPrtAIlzUSAKcTNSEePoQd5K nsyNoEw X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Sun, 29 Mar 2020 09:04:26 +0800 Message-Id: <20200329010426.56123-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/dashdec: add attribute lang for audio and subtitle streams 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" There should have lang in the metadata of streams which show to user Signed-off-by: Steven Liu --- libavformat/dashdec.c | 49 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 271202b0a5..2a4ef03967 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -85,6 +85,7 @@ struct representation { enum AVMediaType type; char id[20]; + char *lang; int bandwidth; AVRational framerate; AVStream *assoc_stream; /* demuxer stream associated with this representation */ @@ -144,6 +145,9 @@ typedef struct DASHContext { uint64_t period_duration; uint64_t period_start; + /* AdaptationSet Attribute */ + char *adaptionset_lang; + int is_live; AVIOInterruptCB *interrupt_callback; char *allowed_extensions; @@ -872,6 +876,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"); @@ -1103,6 +1116,19 @@ end: return ret; } +static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node) +{ + 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"); + + return 0; +} + static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr adaptionset_node, xmlNodePtr mpd_baseurl_node, @@ -1111,6 +1137,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 +1145,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")) { @@ -1142,13 +1173,15 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, adaptionset_baseurl_node, adaptionset_segmentlist_node, adaptionset_supplementalproperty_node); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto err; } node = xmlNextElementSibling(node); } - return 0; + +err: + av_freep(&c->adaptionset_lang); + return ret; } static int parse_programinformation(AVFormatContext *s, xmlNodePtr node) @@ -2121,6 +2154,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 +2165,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); + } } }