From patchwork Fri Nov 17 00:55:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin NG X-Patchwork-Id: 6133 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp14319jah; Thu, 16 Nov 2017 16:55:50 -0800 (PST) X-Google-Smtp-Source: AGs4zMbFXNSXG847QYmtvuKPbyf0Octkpd1bEho/yeNoz1BX7kr2Iit0REC7XdpGNPWPT7T6TO7C X-Received: by 10.223.135.77 with SMTP id 13mr3195764wrz.142.1510880150651; Thu, 16 Nov 2017 16:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510880150; cv=none; d=google.com; s=arc-20160816; b=yCoIw/vYOaDZwbcJivAZtXOdEAVR89IPnaGWbIuXRx0D3z6+OqLFHvJVSzciRL0rhy rUwjkJ8rPmi2cXfQROdeJQP3tKB2vHOGAfSWHjyDkWl0GZxbKUPxiVsSbwPEAa9SvdS0 f1m0K2JQS4xxONbv/Xc2hsbHTt6xLJavjxpmmijuYsN7LEEjAGpl0tFQp8LFat/hij1/ tNWotkrWGmgSGhjcQ9hLcqMByqJmPh2cj6NXmhSR+umUce15sfAJy08UW2TcNs2JR1WQ GZKg4+doqh7JjmgQzpRGTdty6dgcp357skB9zx+smXOZuF0hZozhnUEedOrhtQt06isl tN2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=2GKg3GnN1HL0G46ZpajoQJqqI2vRLJ9eXXb46gltgE4=; b=qLxcqoMEzMXTirGs17SicGHLXvuVIgHCMfOHflf4Lp5xzjQS7kMmNZi80hem9Y7DXF RIptWndRLxM/YDS/XW9F9flKxcesfjAGptxz3Y8wrvgDikLXN2g1lQVRhm12CvMF2NvO rWKs2oV6mFQKOOlGtiHvjESK7mbQ9KyJ/+PK8kIlNV/zQe94fkXG/4OElDQ994KzRuq4 myOchhP7tahZ7joFxCDzHp/JjkMPi4LpDD/LDaMZCaMDGzx3ZIZd7YzurEnKoj3kS0r7 eHrl356GC+I0e9BAyiA+gkqRc97q+ZHGkh/q4ztjHCEOl/dNwjU8OfvUKT4FzKXd1WX9 3DZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com header.s=selector1 header.b=mlQyIorp; 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 q23si1788102wmf.261.2017.11.16.16.55.48; Thu, 16 Nov 2017 16:55:50 -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=mlQyIorp; 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 3FE18689CFD; Fri, 17 Nov 2017 02:55:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-oln040092001095.outbound.protection.outlook.com [40.92.1.95]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F2A1A689C8B for ; Fri, 17 Nov 2017 02:55:23 +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=GdUh0W2pzAm1FaIL9WLN4H07zOIroXfFGmttoWf9VBE=; b=mlQyIorp+YcRSximFhj1rNK6sC4iEtKd53/wohp6kNVFR3UzwWpZegWyEDOew22sh2ZPIXJKNO5dEARfchLab5ysu160eIkh1nmCoxR/ZMUJS+WGjEzUQxEEictspL+bYClUAPTMkKMnrCTgr05sDPPnIRNt0N/PRS4wmM0g/DjgjX2+t5MXanxVRrBB4P6iW8pyNP7f0mqWxuUYf30rN6/slqTQKGoa65oQCJ0zP2gJQYAcaPJwNkIP6uEQ6V37VD0qeJoc5qDOVrkW9ePMf7AvcuZyJ02+ICYaovcwMAwrKh5PfL2tUuQ1rIa/arDadbnTQk/oNNgMH/F8JQxDNA== Received: from SN1NAM01FT015.eop-nam01.prod.protection.outlook.com (10.152.64.59) by SN1NAM01HT204.eop-nam01.prod.protection.outlook.com (10.152.64.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.197.9; Fri, 17 Nov 2017 00:55:37 +0000 Received: from DM5PR22MB0681.namprd22.prod.outlook.com (10.152.64.57) by SN1NAM01FT015.mail.protection.outlook.com (10.152.65.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.218.12 via Frontend Transport; Fri, 17 Nov 2017 00:55:37 +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.0239.007; Fri, 17 Nov 2017 00:55:37 +0000 From: Colin NG To: FFmpeg development discussions and patches Thread-Topic: [FFmpeg-devel] [Patch] Fix for ticket 6658 (Dash demuxer segfault) Thread-Index: AQHTXz7Iqn5lXjdV2UeVq7nXq/wQTg== Date: Fri, 17 Nov 2017 00:55:37 +0000 Message-ID: References: , , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: yes X-MS-TNEF-Correlator: authentication-results: ffmpeg.org; dkim=none (message not signed) header.d=none; ffmpeg.org; dmarc=none action=none header.from=hotmail.com; x-incomingtopheadermarker: OriginalChecksum:CBD9929CF83F7009673FBA26E6FEEEFFFDE124163F6687D7410B3DF5666E8A59; UpperCasedChecksum:B37F1CC0238C70AB1574B9BE468C027F08D418CA5AD7D3D3A4E7802E24039051; SizeAsReceived:7342; Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [9vGd8yfsvOiU2ZvbQUTb04OZXyVPKBFx] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN1NAM01HT204; 6:jVq2vy/0hltv8Zkz1WFdjJ1sBuxKg15+hDYJWSJZsu4E9LZBZJIWVcsODMWYkD1DMXJznlG8pYY9C76urVO1QKbgJ5xNg41O+v3dNvj2jedbxrIutRWOUPZcqFUI7GkCn4Penn5f+byQRYYqr6nnCpCSZ8q6uHHy70mSqwmRjInFiHCsSbJJBRKd4jSOSNE3QmSkPcC3W7cL36SZaseUJdFq4JY+i622pTA61DzIrx/ZJNf6jA1YiCjgyPAIn2jslvLJPAzjUacImCiVa8M9WyagM2WpMQRDD+AyfDHKIMIxH8usJD0xyjOSIU6PlwlsRbt/tzj6yGLcyn+6vO8aZYsUJhArm7PtTi2kt9zJ8Hc=; 5:KXOIlqsxN3Suco1MhQDtJRtcH/U+MXsYoKmD045jywLiljXL2QWP0AV6aPQxuNeTIICiMubWLao0x7Mi8Awy1sYZ2KWZUYFdp1/fR9q7Mmvy2G8bMHQgp9afngT1CJ3VqsdI0JmzodWkIEp9WHxI37b1oPoD8VdgDW7aSiht3Qw=; 24:bmKoHAtADHCHmzzr2bjejaaxgYxByWC/5a9J26qDOlWdoqCYwaxhAqhBkWUIpMZQjW5kShLBdMEXwHernRFQGi3BEUIarVR4vZJbfqSMo98=; 7:Ry/inBqzj0mYf+orS84vGWBwfKaRqDfKuQ7LVzK6YogNACoc7Fu9DvAsggU1aRC8tTiE3vZKUmIoBN78KkYZiz+8Q3ZDiiTBB51N1pd4/U9Fh3Uqv/OqUu0nXfReWoBgJiO/zapSstaWRvbnDuVcYs0hoRRmWumFWBDmpkI1UgTuJQxuQY5bsLurjjnkh6Yb1FMOFIPgSodzvN7HmCy6bjUoXt196uF8b9Mt8RaaUhSICn4HClVK+evEGYKyrV/S x-incomingheadercount: 46 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 9db017cc-2781-473d-8362-08d52d55eab4 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1601125374)(1603101448)(1701031045); SRVR:SN1NAM01HT204; x-ms-traffictypediagnostic: SN1NAM01HT204: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031); SRVR:SN1NAM01HT204; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1NAM01HT204; x-forefront-prvs: 049486C505 x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:SN1NAM01HT204; 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: 9db017cc-2781-473d-8362-08d52d55eab4 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Nov 2017 00:55:37.5649 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM01HT204 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [Patch] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Excluded the fix for byte range issue and update some coding style issues. diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 0e3afd2..4d89374 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 char * ishttp(char *url) { + 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,10 @@ 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); + if (pb) av_freep(pb); + // set_httpheader_options(c, &tmp); + 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; @@ -613,6 +621,77 @@ 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) { + + int i; + char *text; + char tmp_str[MAX_URL_SIZE]; + char tmp_str_2[MAX_URL_SIZE]; + + char *path = av_mallocz(MAX_URL_SIZE); + int nameSize = 0; + int updated = 0; + + av_strlcpy(tmp_str, url, strlen(url)+1); + char *mpdName = strtok (tmp_str," /"); + + while ((mpdName =strtok (NULL, "/"))) { + nameSize = strlen(mpdName); + } + + av_strlcpy (path, url, strlen(url)-nameSize+1 ); + + int rootId = 0; + xmlNodePtr *node = NULL; + char *proto_name = NULL; + for (rootId = n_baseurl_nodes-1; rootId >0; rootId--) { + if (!(node = baseurl_nodes[rootId])) continue; + + if (ishttp(xmlNodeGetContent(node))) { + break; + } + } + + node = baseurl_nodes[rootId]; + char *baseurl = xmlNodeGetContent(node); + char *root_url = (!av_strcasecmp(baseurl, ""))? path: baseurl; + + if (node) { + xmlNodeSetContent(node, root_url); + } + + int size = strlen(root_url); + char *isRootHttp= ishttp(root_url); + + char token ='/'; + if (strncmp(&root_url[size-1],&token, 1) != 0) { + 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, sizeof(tmp_str)); + + if (!ishttp(text) && isRootHttp) { + av_strlcpy(tmp_str, root_url, size+1); + } + int start = (strncmp(text, &token, 1) == 0) ? 1: 0; + memset(tmp_str_2, 0, sizeof(tmp_str_2)); + av_strlcat(tmp_str, text+start, MAX_URL_SIZE); + xmlFree(text); + xmlNodeSetContent(baseurl_nodes[i], tmp_str); + updated = 1; + } + } + + av_free(path); + return updated; + +} static int parse_manifest_representation(AVFormatContext *s, const char *url, xmlNodePtr node, xmlNodePtr adaptionset_node, @@ -672,6 +751,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, baseurl_nodes[2] = adaptionset_baseurl_node; baseurl_nodes[3] = representation_baseurl_node; + resolve_content_path(s, url, baseurl_nodes, 4); + if (representation_segmenttemplate_node || fragment_template_node) { fragment_timeline_node = NULL; fragment_templates_tab[0] = representation_segmenttemplate_node; @@ -967,6 +1048,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(node, "BaseURL"); + } // at now we can handle only one period, with the longest duration node = xmlFirstElementChild(node); @@ -1307,11 +1391,13 @@ static int open_input(DASHContext *c, struct representation *pls, struct fragmen * (if this is in fact a HTTP request) */ av_dict_set_int(&opts, "offset", seg->url_offset, 0); av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0); + } ff_make_absolute_url(url, MAX_URL_SIZE, c->base_url, seg->url); av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64", playlist %d\n", url, seg->url_offset, pls->rep_idx); + ret = open_url(pls->parent, &pls->input, url, c->avio_opts, opts, NULL); if (ret < 0) { goto cleanup;