From patchwork Fri May 22 05:41:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 19803 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 645BF4400F8 for ; Fri, 22 May 2020 08:42:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F43D68AD77; Fri, 22 May 2020 08:42:25 +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 90C8C6818DB for ; Fri, 22 May 2020 08:42:18 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=rcombs.me; q=dns/txt; s=mx; t=1590126140; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: To: From: Sender; bh=TKj+w5jANUP523zRLLLKO9iH1UMpO63xODo/30W1ao4=; b=eGmEj9l7O/9RLiC2HTJkJPSRmWAkB8744fbcGsyDsN+dJx5PVEMI41B+aOTpHUUSQGwnjPwR vk+6Qpds8Z/aagLsEfEWDnhc5NcB0eyA4UXMLc0qCaCQG1EXzzgtsmNEqfSlwK/VzcDZiWCC ry4KyzaFXbsFQVyNpz+W86vqgwk= 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 5ec7662e8075f6e58cac8b5a (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:41:58 -0500 Message-Id: <20200522054200.74203-1-rcombs@rcombs.me> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavf/format: handle max probe buffer sizes <2048 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 can be useful in chained demuxers, where the header size is known. --- libavformat/format.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavformat/format.c b/libavformat/format.c index c47490c8eb..7309b0019b 100644 --- a/libavformat/format.c +++ b/libavformat/format.c @@ -231,11 +231,6 @@ int av_probe_input_buffer2(AVIOContext *pb, ff_const59 AVInputFormat **fmt, if (!max_probe_size) max_probe_size = PROBE_BUF_MAX; - else if (max_probe_size < PROBE_BUF_MIN) { - av_log(logctx, AV_LOG_ERROR, - "Specified probe size value %u cannot be < %u\n", max_probe_size, PROBE_BUF_MIN); - return AVERROR(EINVAL); - } if (offset >= max_probe_size) return AVERROR(EINVAL); @@ -251,7 +246,7 @@ int av_probe_input_buffer2(AVIOContext *pb, ff_const59 AVInputFormat **fmt, } } - for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt; + for (probe_size = FFMIN(PROBE_BUF_MIN, max_probe_size); probe_size <= max_probe_size && !*fmt; probe_size = FFMIN(probe_size << 1, FFMAX(max_probe_size, probe_size + 1))) { score = probe_size < max_probe_size ? AVPROBE_SCORE_RETRY : 0; From patchwork Fri May 22 05:41:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 19804 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 280EB44B2A8 for ; Fri, 22 May 2020 08:42:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0F10468AE4C; Fri, 22 May 2020 08:42:29 +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 6D7ED68A82D for ; Fri, 22 May 2020 08:42:22 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=rcombs.me; q=dns/txt; s=mx; t=1590126144; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: To: From: Sender; bh=QjqDvMdnBcIuQ42tlG9muWvrUsnmXLzGU847rvgFrbc=; b=aoQZ672+7Bhb98FsnNiSntS35k1PjmSh7dpE9rjIEj0ituv5Xtdj6DWJLb7YuAMNyg6bpPek SP/C5ES0vwU4ReM72lwBZa94UZSnCVBgIiYlpWTFlctPTjPO3fsWbnRfvednSw+GuvfPrpL9 I74SBhZ5ipZGQ/pdl7FxNyG8bq4= 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 5ec7662e45598550e6170ed7 (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:41:59 -0500 Message-Id: <20200522054200.74203-2-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 2/3] lavf/movdec: allow setting the header size in advance 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 is useful for chained demuxers, to avoid reading past the end of a shared initialization segment and into the first data segment unnecessarily. --- libavformat/isom.h | 1 + libavformat/mov.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 41a9c64c11..3479553da6 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -291,6 +291,7 @@ typedef struct MOVContext { int decryption_key_len; int enable_drefs; int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd + int64_t header_size; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index e11c9f4457..51d3204582 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7574,6 +7574,9 @@ static int mov_read_header(AVFormatContext *s) else atom.size = INT64_MAX; + if (mov->header_size > 0) + atom.size = mov->header_size; + /* check MOV header */ do { if (mov->moov_retry) @@ -7591,6 +7594,9 @@ static int mov_read_header(AVFormatContext *s) } av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); + if (mov->header_size > 0) + mov->next_root_atom = mov->header_size; + if (pb->seekable & AVIO_SEEKABLE_NORMAL) { if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters) mov_read_chapters(s); @@ -8162,7 +8168,9 @@ static const AVOption mov_options[] = { { "decryption_key", "The media decryption key (hex)", OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, - + { "header_size", "size of initial header, ", + OFFSET(header_size), AV_OPT_TYPE_INT64, {.i64 = -1}, + -1, INT64_MAX, FLAGS }, { NULL }, }; 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);