From patchwork Fri May 22 05:42:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 19802 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 73CFA44B768 for ; Fri, 22 May 2020 08:42:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 537B668AD3D; Fri, 22 May 2020 08:42:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from so254-54.mailgun.net (so254-54.mailgun.net [198.61.254.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2690068A82D for ; Fri, 22 May 2020 08:42:08 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=rcombs.me; q=dns/txt; s=mx; t=1590126128; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: To: From: Sender; bh=BwT5kliuMWOPoHFlzYlhEykYcZ6/SC21LRkYsu4brh8=; b=BHYc17pyybNYztbScmJ/0B3tHknVVDSYLVph+XlGTxpn8Wyq+sJnjeyVuWG+TivHHbKzINLX PSeo38ZIMJPuiIjJHMqduxYttpOYg6x+aA0/kBip7vJ6pdnBwDbdYHh6KXU8aWQ77lFnKy8y zo7dsNMJMzVZ65uig6MWzHRsj+s= X-Mailgun-Sending-Ip: 198.61.254.54 X-Mailgun-Sid: WyJiZDU1MSIsICJmZm1wZWctZGV2ZWxAZmZtcGVnLm9yZyIsICJiMGJhIl0= Received: from rcombs-mbp.localdomain ( [24.14.135.13]) by smtp-out-n01.prod.us-east-1.postgun.com with SMTP id 5ec7662e8075f6e58cac8c1a (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 22 May 2020 05:42:06 GMT From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 May 2020 00:42:00 -0500 Message-Id: <20200522054200.74203-3-rcombs@rcombs.me> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200522054200.74203-1-rcombs@rcombs.me> References: <20200522054200.74203-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavf/dashdec: avoid reading the first data segment in read_header 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" This reduces the number of requests that have to be made during startup. --- libavformat/dashdec.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index ec2aadcee3..1bd070c7cb 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -1798,6 +1798,19 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size) DASHContext *c = v->parent->priv_data; restart: + /* load/update Media Initialization Section, if any */ + if ((ret = update_init_section(v)) < 0) + goto end; + + if (v->init_sec_buf_read_offset < v->init_sec_data_len) { + /* Push init section out first before first actual fragment */ + int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size); + memcpy(buf, v->init_sec_buf, copy_size); + v->init_sec_buf_read_offset += copy_size; + ret = copy_size; + goto end; + } + if (!v->input) { free_fragment(&v->cur_seg); v->cur_seg = get_current_fragment(v); @@ -1806,11 +1819,6 @@ restart: goto end; } - /* load/update Media Initialization Section, if any */ - ret = update_init_section(v); - if (ret) - goto end; - ret = open_input(c, v, v->cur_seg); if (ret < 0) { if (ff_check_interrupt(c->interrupt_callback)) { @@ -1823,15 +1831,6 @@ restart: } } - if (v->init_sec_buf_read_offset < v->init_sec_data_len) { - /* Push init section out first before first actual fragment */ - int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size); - memcpy(buf, v->init_sec_buf, copy_size); - v->init_sec_buf_read_offset += copy_size; - ret = copy_size; - goto end; - } - /* check the v->cur_seg, if it is null, get current and double check if the new v->cur_seg*/ if (!v->cur_seg) { v->cur_seg = get_current_fragment(v); @@ -1940,10 +1939,19 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0) goto fail; + + if (pls->init_sec_data_len <= 0) { + /* load/update Media Initialization Section, if any */ + if ((ret = update_init_section(pls)) < 0) + goto fail; + } + pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO; pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4; + if (pls->init_sec_data_len > 0) + pls->ctx->probesize = FFMIN(pls->ctx->probesize, pls->init_sec_data_len); pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE; - ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, 0); + ret = av_probe_input_buffer(&pls->pb, &in_fmt, "", NULL, 0, pls->ctx->probesize); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error when loading first fragment, playlist %d\n", (int)pls->rep_idx); avformat_free_context(pls->ctx); @@ -1954,6 +1962,9 @@ static int reopen_demux_for_component(AVFormatContext *s, struct representation pls->ctx->pb = &pls->pb; pls->ctx->io_open = nested_io_open; + if (pls->init_sec_data_len > 0) + av_dict_set_int(&in_fmt_opts, "header_size", pls->init_sec_data_len, 0); + // provide additional information from mpd if available ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url av_dict_free(&in_fmt_opts);