From patchwork Tue Dec 26 01:12:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin NG X-Patchwork-Id: 6969 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp6289313jad; Mon, 25 Dec 2017 17:13:06 -0800 (PST) X-Google-Smtp-Source: ACJfBosKGoLDat1F6PQBl9E+onjPW4kqCbM9OZouDE2EMAwXZ5t+dQlJUepjIW+k1tmG2E0bRGrg X-Received: by 10.223.187.130 with SMTP id q2mr5863977wrg.181.1514250786553; Mon, 25 Dec 2017 17:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514250786; cv=none; d=google.com; s=arc-20160816; b=SalOKgCcbn+rpfwWQ64XuId3Tl1yIFqZS79a3pyIygcKGX6lXcuTZyt2reQMpqWS31 hj6IHvNwBOxA87+WZy8elT9lMtfYUg3aXCKvEPpR2n/TzBISFxTlbTfUFGyL/0aHW0r+ 97VNdK/foC1Z+cUVRQTxrHi1Uy4Mm07OgOG0/WnWxi0qFnqdaDuyFnkBti27DsY09Gyk XJp3t1u2kTKXkFcxX8AVOjLHwKWWnQlg4fw2ZRih3ZcNQljwwhoKVl0hYQv6cGL0Nmmu FE/g1APtjo47a0xWjq6nDHFXOO7/UaUDoEd4d4DKVQV6ZPccefoZCCHOHti2N8aOEnuI /toA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:spamdiagnosticmetadata :spamdiagnosticoutput:content-language:accept-language:message-id :date:thread-index:thread-topic:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=basXyejjGDU5Loq53KKeHwrjc2Z1p9EsvvLmy3xPvSY=; b=Ta9/fINdTFHeOB5qXSCwCx9PnJZJ7UMqGXw/knWmP5ecMWAR1lTc2Vs1Zg0lxWOvl5 yUv/IOeVFA//M5jhpGzp36wzJAFE6GwnlcM2lWIqmflFlaQoZq7LHFGiRa1C5mbCnrLi 37lzS0jXPghup7FY+WmJq8gXxdkfuCXKZdHk4TgCVGvVCqtFpEYSE4dBVtXlVYT+/BtB 2X189wp3yL772VkChd+c+wxuUE/QfaCj/B57sGUM2YJ7ObdvhJCZmrvQV6e48mGU+3+E ng+A3G35MT5TppF8mN2S6aJpXYJxhUHLycW/o6zYAVoJF5vrjWSb+/WLr5DBFe3htbNn wXdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com header.s=selector1 header.b=hgDsrDJ3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=hotmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d24si10983897wmi.130.2017.12.25.17.13.05; Mon, 25 Dec 2017 17:13:06 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com header.s=selector1 header.b=hgDsrDJ3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ADD7C680983; Tue, 26 Dec 2017 03:12:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-oln040092002048.outbound.protection.outlook.com [40.92.2.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7966468002C for ; Tue, 26 Dec 2017 03:12:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=zWK3OLF3n7R/hR9WHCt/7CJFvAWF7wAWfg0wx06sy+o=; b=hgDsrDJ3s0n+a9FrO69seBx1kBt+QbMh/XKDJRlRHtUxdbMUUtQOFc4DgIOxvHn6MRG1gKmVgeoGCx+A0Sa483SAXRkoVp5LYLu4yOh6ZRZKJoaRin//PSh0zSnsEa/ENyF+nPJsW+rqwQ3hAzlOkUpFQP045tkAdEc58b1G2XslJj16e834ENUI6yPySOGH7b1zL1YVfkN+Rb6Fat6VPBKrNGVPqvRFq47q9A1evqn3b+EG3AM8nlX0SdNBHREVvoEX7R7HGwcxpp1FHFYBnEOSSgOxsIGPGS2xQb9cRuRWDH0iqEQg9SZtuMUXv1mOkIjeShq88yYT6sIn7w5vaQ== Received: from BY2NAM01FT012.eop-nam01.prod.protection.outlook.com (10.152.68.60) by BY2NAM01HT222.eop-nam01.prod.protection.outlook.com (10.152.69.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.302.6; Tue, 26 Dec 2017 01:12:54 +0000 Received: from DM5PR22MB0681.namprd22.prod.outlook.com (10.152.68.54) by BY2NAM01FT012.mail.protection.outlook.com (10.152.69.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.302.6 via Frontend Transport; Tue, 26 Dec 2017 01:12:54 +0000 Received: from DM5PR22MB0681.namprd22.prod.outlook.com ([10.172.189.151]) by DM5PR22MB0681.namprd22.prod.outlook.com ([10.172.189.151]) with mapi id 15.20.0345.017; Tue, 26 Dec 2017 01:12:54 +0000 From: Colin NG To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] libavformat/dashdec: Fix for ticket 6658 (Dash demuxer segfault) Thread-Index: AQHTfeaoF5d1sO/esEOz2esIdJ1C7g== Date: Tue, 26 Dec 2017 01:12:54 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:4B59ADB8FD9F65513C1EC14E4CD760028CD67926595354109E9C70D8A3CFCA52; UpperCasedChecksum:503174F8F14AF523F026B0633FDE68A8747D2EAB2CDF79AAD93944398D4FAC38; SizeAsReceived:6954; Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [IogPxsNFXKYSSoHya72vKmYV6bJ7PNU5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BY2NAM01HT222; 6:bdhNkL2FcvYPFQ25ZvH/y/l6s4I1tvmgcczrDHuUuN3992wdPzc/XuBN2vo90hb5seV0emDwXI3lP+hK2iROVq6YpwsBWg/xJ7yRCEwVLloM/gDmUl/LeHYKffWTsHo+GwXrwg7kfwK9svM3L3JdEtqjD7UNzMcntPQRfxkMm8xwhGQMttK7VM3gCnSwfwta2uxFzGcpJWp8sjYCRHVQJg595IstmojT1Xiavg3Q8yvqBPstlIzuUR0QJAEbcKiwWOPDGegRW9VmIVM2GHUlQUufMKG79NZlTGZcMKCMTUrdUnd4Mo8LjSGpr6eVEwF2jAVPNs66w6xQ6Bqv2xTPksG7AqUGN2P1WbYSWhLHAuk=; 5:YtI1RzYhyz9UW1DulpltPnxf3EOcIwgp1L8D445OeoiMGbHch4QEYB/T3IXayInQM0xU7eqPFrfAvOKIm2cSdtNAagdOwW5H32qDPH82abZmOfjkgtcapJitmbT8yW8JCcA3L9pefvEAHIpdXLFSoAVqKILkL3O4LN54lMoAEP8=; 24:Y6dqKsunee5524EA3UY7c2/ldHfHN9JDWco57cU+obuXYK+spXR3rtbId+S0TnwPC0UjRZq9s3n7A85mNOOB7gPCk2rCD5kVGjWVImuC+ys=; 7:UqPiz8uGGp3KSNz8zvpvkHOEdvzXGtqtaSYOxtRo1FuhEDktGV8AiPYYU4EoD1xkFS8vkIYm5FPn2oLmGcxrlJpyKNvpKvi244mp4Hwvl4CiJksZ4On/pB+sHJIiEf1ycC48TOmshmjQuOp+HUBfBH8OVgOoH6i1osJJVdY3Tb8C0xn7GUlLv3CCP/rjgnG4kvVbAuA6cOhbstF1AfTDF9+qFZ636W9/1Yt+u3Bfq1yUckXH/SZfdcWRnjzqoRA9 x-incomingheadercount: 45 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(201702181274)(2017031322404)(1601125374)(1603101448)(1701031045); SRVR:BY2NAM01HT222; x-ms-exchange-slblob-mailprops: 3tYrFWTD79Ba2f19bYPeQIWYD6otjBXGzJ2X5tBf9cshmSul7MRyNK8q87vi/S1M+JlxvWF5WbhNCg0FlAjr3s4Lf7+C/eCa2G5Iym/1rKi03J+/y8kqnnqCU1gYFz7n5HGPg0jf9mrUjSld+hLNqIgIxPF6esqrTAKS1h3T6Ia1d54UJ4dgUQudmT+JHnE2JZSao2DzhFWZMidLQ/bgePC6lRmNXcVx5sJ61Q18s+OcBExFanSt1mxdxkz3zr+bOOA9UCLOfgWHmy46sKeQrNyyURg1bHutDXbG1ZtJy4O0B4J6rveWSK7sPAPCIpnNnjxNbOnBbEwJQImE7mEwGVMvxADnIGyhRXbF7XeiS03RmY6Y32OatS6JJb6KU/jsRZaXAMqgyELM3xdEAIt1Mehe3dBo4fa24fhDjWMm3c9unrJJAh5DNpWUzEPS4e8NLfnOf2ZTe01ygtUUtSGYr/sUCJDfoS54KwiLVHFqDnvZDisAVeBLjdMYMGP1IBUSpxE9ajHZeSW2KxaHaHqJ2oaCSILuxezA7V0vUv8g9HoNF1HJbX17xxbKG8eGvmVy4iPrJWI7zwkuzCsjMe9iB1L7P+/4zTNciGxSI9kZ+Pv4Zn3K8b9xVlWmR49Alh04ZSJkxTRnW2ltwe0i/xlaNq7ZHptmMjiyOAyfPqwK8sBhSNyduPsVSkUdYHR65cXYMNC3gZkThzy0NME2WeGyK9T7p7LdmjP6IJstUBXJxyfPNFfB3ZzRoEK1Kv8/GH2dFH26FMyG/EvZ99XeffZKLVgUxdIwJPfe x-ms-traffictypediagnostic: BY2NAM01HT222: x-ms-office365-filtering-correlation-id: 2316fa18-2d39-4727-2824-08d54bfdca6f x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:BY2NAM01HT222; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BY2NAM01HT222; x-forefront-prvs: 053315510E x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:BY2NAM01HT222; H:DM5PR22MB0681.namprd22.prod.outlook.com; FPR:; SPF:None; LANG:; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2316fa18-2d39-4727-2824-08d54bfdca6f X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Dec 2017 01:12:54.6322 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2NAM01HT222 Subject: [FFmpeg-devel] [PATCH] libavformat/dashdec: Fix for ticket 6658 (Dash demuxer segfault) 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: Colin NG Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" - Add function 'resolve_content_path' to propagate the baseURL from upper level nodes. * if no baseURL is available, the path of mpd file will be set as the baseURL. - Remove checking for newly established connection. - Establish the communication protocol in each connection rather than applying one protocol to all connection. --- libavformat/dashdec.c | 107 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 13 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 3798649..e41ba96 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -148,6 +148,11 @@ static uint64_t get_current_time_in_sec(void) return av_gettime() / 1000000; } +static int ishttp(char *url) { + const char *proto_name = avio_find_protocol_name(url); + return av_strstart(proto_name, "http", NULL); +} + static uint64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime) { struct tm timeinfo; @@ -392,7 +397,8 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5)) return AVERROR_INVALIDDATA; - ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp); + av_freep(pb); + ret = avio_open2(pb, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp); if (ret >= 0) { // update cookies on http response with setcookies. char *new_cookies = NULL; @@ -639,6 +645,84 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat return 0; } +static int resolve_content_path(AVFormatContext *s, const char *url, xmlNodePtr *baseurl_nodes, int n_baseurl_nodes) { + + char *tmp_str = av_mallocz(MAX_URL_SIZE); + char *path = av_mallocz(MAX_URL_SIZE); + char *mpdName = NULL; + xmlNodePtr node = NULL; + char *baseurl = NULL; + char *root_url = NULL; + char *text = NULL; + + int isRootHttp = 0; + char token ='/'; + int start = 0; + int rootId = 0; + int updated = 0; + int size = 0; + int i; + + if (!tmp_str || !path) { + updated = AVERROR(ENOMEM); + goto end; + } + + av_strlcpy(tmp_str, url, strlen(url) + 1); + mpdName = strtok (tmp_str, "/"); + while (mpdName = strtok (NULL, "/")) { + size = strlen(mpdName); + } + + av_strlcpy (path, url, strlen(url) - size + 1); + for (rootId = n_baseurl_nodes - 1; rootId > 0; rootId --) { + if (!(node = baseurl_nodes[rootId])) { + continue; + } + if (ishttp(xmlNodeGetContent(node))) { + break; + } + } + + node = baseurl_nodes[rootId]; + baseurl = xmlNodeGetContent(node); + root_url = (av_strcasecmp(baseurl, "")) ? baseurl : path; + if (node) { + xmlNodeSetContent(node, root_url); + } + + size = strlen(root_url); + isRootHttp = ishttp(root_url); + + if (root_url[size - 1] == token) { + av_strlcat(root_url, "/", size + 2); + size += 2; + } + + for (i = 0; i < n_baseurl_nodes; ++i) { + if (i == rootId) { + continue; + } + text = xmlNodeGetContent(baseurl_nodes[i]); + if (text) { + memset(tmp_str, 0, strlen(tmp_str)); + if (!ishttp(text) && isRootHttp) { + av_strlcpy(tmp_str, root_url, size + 1); + } + start = (text[0] == token); + av_strlcat(tmp_str, text + start, MAX_URL_SIZE); + xmlNodeSetContent(baseurl_nodes[i], tmp_str); + updated = 1; + xmlFree(text); + } + } + +end: + av_free(path); + av_free(tmp_str); + return updated; + +} static int parse_manifest_representation(AVFormatContext *s, const char *url, xmlNodePtr node, xmlNodePtr adaptionset_node, @@ -698,6 +782,11 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, baseurl_nodes[2] = adaptionset_baseurl_node; baseurl_nodes[3] = representation_baseurl_node; + ret = resolve_content_path(s, url, baseurl_nodes, 4); + if (ret == AVERROR(ENOMEM) || ret == 0) { + goto end; + } + if (representation_segmenttemplate_node || fragment_template_node) { fragment_timeline_node = NULL; fragment_templates_tab[0] = representation_segmenttemplate_node; @@ -993,6 +1082,9 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) } mpd_baseurl_node = find_child_node_by_name(node, "BaseURL"); + if (!mpd_baseurl_node) { + mpd_baseurl_node = xmlNewNode(NULL, "BaseURL"); + } // at now we can handle only one period, with the longest duration node = xmlFirstElementChild(node); @@ -1315,6 +1407,7 @@ static int read_from_url(struct representation *pls, struct fragment *seg, } else { ret = avio_read(pls->input, buf, buf_size); } + if (ret > 0) pls->cur_seg_offset += ret; @@ -1343,18 +1436,6 @@ static int open_input(DASHContext *c, struct representation *pls, struct fragmen goto cleanup; } - /* Seek to the requested position. If this was a HTTP request, the offset - * should already be where want it to, but this allows e.g. local testing - * without a HTTP server. */ - if (!ret && seg->url_offset) { - int64_t seekret = avio_seek(pls->input, seg->url_offset, SEEK_SET); - if (seekret < 0) { - av_log(pls->parent, AV_LOG_ERROR, "Unable to seek to offset %"PRId64" of DASH fragment '%s'\n", seg->url_offset, seg->url); - ret = (int) seekret; - ff_format_io_close(pls->parent, &pls->input); - } - } - cleanup: av_dict_free(&opts); pls->cur_seg_offset = 0;