From patchwork Tue Apr 10 07:02:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sanilraut X-Patchwork-Id: 8373 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp721810jad; Tue, 10 Apr 2018 00:04:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx48c7XL/wX5HMRUYZWr7EC9304zyiq80jmvNSdEKFt9YC9IrvDa1uPKvIvwyFAPq94ISCAim X-Received: by 10.28.136.199 with SMTP id k190mr721570wmd.154.1523343840791; Tue, 10 Apr 2018 00:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523343840; cv=none; d=google.com; s=arc-20160816; b=cAZPVD0hZsIKDjUJDZtDgsh75Gz5HWNcyIoeqMHZWDcVXFTPS59MPIrVwWwD+51lLV RkLmp6t8chB5LsOc2XiWsaD6kNCKqM+ZJxzhNRlbTSVhHjj2mMZ0pexaqoZ+dsbLDVxN ez1fnVwV71R2u/glA4li+20OEq89AFHzUCLEKCIEFfshO0r/nmIHnvKCf4B51hggmww2 QKAxSIz7FOK4+B5B1SnVi2zh/F4lmnkWeU7mM9G/Jj7v288qTievn2XljOuGouheXLi2 TVzGI2vt3mSlpAsGo/6nUc4Qdq6swzeNehjPetYmUxo6kU/3XE0dPyeBlCDMvflfQQN8 YTUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=WAyeS2GMWYo9RM9IFV02Quo5wBN/I3BJlxjx1md8OUs=; b=iJZvWEQk3cfl0csm/z7d4zz6NmMFWbjZ+pG1CS+mevzebzZOEHjJgMe9ha2Nb0u7pa ludKEkPyNPSAqeYb5bsWamaBxbfGim/uQYxPF8FNuCv6dA96bv6h7KS92J1Q+Iy1O5eU Bk+H8oSvN+3O9IxS40yVdQG6s3Bj7QMu+wfW8KZQUCTptpadze1YQ4RQFEyxYfRHPgX+ bI/w6hLM8r8VD3R69lXOxeKQeoco8NgpihwWjzuI58WlPX7a6dt0ElnHErRAqysG01zB lhwt4unMkRBrRYWCORpP0jh3nK+Z8XIHUI3T2hhJx0nJsCW5tUkXY7bRQueHrE9PWo+c tFyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=nKO035bl; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r18si793128wmg.112.2018.04.10.00.04.00; Tue, 10 Apr 2018 00:04:00 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=nKO035bl; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A1AED689E8B; Tue, 10 Apr 2018 10:03:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74442689A49 for ; Tue, 10 Apr 2018 10:03:28 +0300 (EEST) Received: by mail-pl0-f68.google.com with SMTP id 91-v6so6865833pld.3 for ; Tue, 10 Apr 2018 00:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=IDQET4Rh8Q3qw7hcUI3zgtrCVNlLsX0+bCOCs6larys=; b=nKO035blrzQLJQqPj+7CWKHv087Kiwty1729lxnt6FcozFPr9DUrMCwIzTkZZVNlye ybk5Yw4EXaYzq1KzWIZwxwKVZ2/R3+Io5F3NlMPI8XbngCCm+qgAXnfZBtyrE9sG5N+l KPgp6VtyHRBK8vcavH5/OTtGxS/hghtTY9p+Co4kaUr3ZSvn2lEfxLMORmtnWma9VbGl 3LuhJooU3+Vg9JZLNa337b7bukuVLKzu+v6B67xjrc+25xsx4o5d0aJK4TamfAGhAppc mLjfwMXg99rnDnk2kHpP4UJgjPX0iq2sjSs3AqFxfxdalvam3ort+csFcLeEotQdKLty S3nQ== 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; bh=IDQET4Rh8Q3qw7hcUI3zgtrCVNlLsX0+bCOCs6larys=; b=o40Prj9QDjhJSWA21zCaLzUlcrX2HVL34PPoZTdqUh4D51Xjvz8R7qjZfGzn7iVEJY DK5guiEoJZtbvPT7KxpZXAq2ynC19s7QybdnAYdtQvHYI2ZugGrJTtGmx7HZ1kEi/gMf Y0bm3pgJ6FsdVNQZ5M/rDZHddk7ZyRgdxoR2GDvrp4RRoBs9F8J/yq38VWZlfGqH5qUh G+WE5jnwgqTo1S49Dt47jEPgs48viRjb1I/VT8BNGmDW+vQkQZ96Vbhee8RrRYOU6jY8 GvqGFaLcC4NOTy9YlB9/PnVnrC3i86Ev3M55it/Ql1+f05kDeAwhOUSx6IdEG0FZ69OB 0j8g== X-Gm-Message-State: AElRT7G2+XaBBgO2eKioSjkMm7RSN72+KMXghycA+NUiGs8C1UhaPMRM lLwWgDSsdTo145S9ATpgCtgJ8A== X-Received: by 2002:a17:902:207:: with SMTP id 7-v6mr42743588plc.261.1523343830362; Tue, 10 Apr 2018 00:03:50 -0700 (PDT) Received: from localhost.localdomain ([123.201.112.188]) by smtp.gmail.com with ESMTPSA id z21sm3568936pge.42.2018.04.10.00.03.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Apr 2018 00:03:49 -0700 (PDT) From: sanilraut To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Apr 2018 00:02:57 -0700 Message-Id: <1523343777-21855-1-git-send-email-raut.sanil@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH v2] libavformat/dashdec: Avoid multiple HTTP requests for initialization segment that is common among all representations 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: sanilraut MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, The following patch avoid multiple HTTP requests for initialization segment that is common among all representations. --- libavformat/dashdec.c | 82 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 8bfde4d..6304ad9 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -149,6 +149,11 @@ typedef struct DASHContext { char *allowed_extensions; AVDictionary *avio_opts; int max_url_size; + + /* Flags for init section*/ + int is_init_section_common_video; + int is_init_section_common_audio; + } DASHContext; static int ishttp(char *url) @@ -416,9 +421,9 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, if (av_strstart(proto_name, "file", NULL)) { if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) { av_log(s, AV_LOG_ERROR, - "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n" - "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n", - url); + "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n" + "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n", + url); return AVERROR_INVALIDDATA; } } else if (av_strstart(proto_name, "http", NULL)) { @@ -931,7 +936,7 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, rep->last_seq_no =(int64_t) strtoll(val, NULL, 10) - 1; xmlFree(val); } - } + } } fragment_timeline_node = find_child_node_by_name(representation_segmenttemplate_node, "SegmentTimeline"); @@ -1160,7 +1165,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in) } else { LIBXML_TEST_VERSION - doc = xmlReadMemory(buffer, filesize, c->base_url, NULL, 0); + doc = xmlReadMemory(buffer, filesize, c->base_url, NULL, 0); root_element = xmlDocGetRootElement(doc); node = root_element; @@ -1396,14 +1401,14 @@ static int refresh_manifest(AVFormatContext *s) if (c->n_videos != n_videos) { av_log(c, AV_LOG_ERROR, - "new manifest has mismatched no. of video representations, %d -> %d\n", - n_videos, c->n_videos); + "new manifest has mismatched no. of video representations, %d -> %d\n", + n_videos, c->n_videos); return AVERROR_INVALIDDATA; } if (c->n_audios != n_audios) { av_log(c, AV_LOG_ERROR, - "new manifest has mismatched no. of audio representations, %d -> %d\n", - n_audios, c->n_audios); + "new manifest has mismatched no. of audio representations, %d -> %d\n", + n_audios, c->n_audios); return AVERROR_INVALIDDATA; } @@ -1862,6 +1867,45 @@ fail: return ret; } +static int init_section_compare_video(DASHContext *c) +{ + int i = 0; + char *url = c->videos[0]->init_section->url; + int64_t url_offset = c->videos[0]->init_section->url_offset; + int64_t size = c->videos[0]->init_section->size; + for (i=0;in_videos;i++) { + if (av_strcasecmp(c->videos[i]->init_section->url,url) || c->videos[i]->init_section->url_offset != url_offset || c->videos[i]->init_section->size != size) { + return 0; + } + } + return 1; +} + +static int init_section_compare_audio(DASHContext *c) +{ + int i = 0; + char *url = c->audios[0]->init_section->url; + int64_t url_offset = c->audios[0]->init_section->url_offset; + int64_t size = c->audios[0]->init_section->size; + for (i=0;in_audios;i++) { + if (av_strcasecmp(c->audios[i]->init_section->url,url) || c->audios[i]->init_section->url_offset != url_offset || c->audios[i]->init_section->size != size) { + return 0; + } + } + return 1; +} + +static void copy_init_section(struct representation *rep_dest, struct representation *rep_src) +{ + memcpy(rep_dest->init_section, rep_src->init_section, sizeof(rep_src->init_section)); + rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size); + memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len); + rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size; + rep_dest->init_sec_data_len = rep_src->init_sec_data_len; + rep_dest->cur_timestamp = rep_src->cur_timestamp; +} + + static int dash_read_header(AVFormatContext *s) { void *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb; @@ -1890,19 +1934,35 @@ static int dash_read_header(AVFormatContext *s) s->duration = (int64_t) c->media_presentation_duration * AV_TIME_BASE; } + if (c->n_videos) { + c->is_init_section_common_video = init_section_compare_video(c); + } + /* Open the demuxer for video and audio components if available */ for (i = 0; i < c->n_videos; i++) { struct representation *cur_video = c->videos[i]; + if (i > 0 && c->is_init_section_common_video) { + copy_init_section(cur_video,c->videos[0]); + } ret = open_demux_for_component(s, cur_video); + if (ret) goto fail; cur_video->stream_index = stream_index; ++stream_index; } + if (c->n_audios) { + c->is_init_section_common_audio = init_section_compare_audio(c); + } + for (i = 0; i < c->n_audios; i++) { struct representation *cur_audio = c->audios[i]; + if (i > 0 && c->is_init_section_common_audio) { + copy_init_section(cur_audio,c->audios[0]); + } ret = open_demux_for_component(s, cur_audio); + if (ret) goto fail; cur_audio->stream_index = stream_index; @@ -1931,7 +1991,7 @@ static int dash_read_header(AVFormatContext *s) av_dict_set_int(&pls->assoc_stream->metadata, "variant_bitrate", pls->bandwidth, 0); if (pls->id[0]) av_dict_set(&pls->assoc_stream->metadata, "id", pls->id, 0); - } + } for (i = 0; i < c->n_audios; i++) { struct representation *pls = c->audios[i]; @@ -2048,7 +2108,7 @@ static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t see int64_t duration = 0; av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms], playlist %d%s\n", - seek_pos_msec, pls->rep_idx, dry_run ? " (dry)" : ""); + seek_pos_msec, pls->rep_idx, dry_run ? " (dry)" : ""); // single fragment mode if (pls->n_fragments == 1) {