From patchwork Wed Apr 10 00:14:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 12679 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 1EDA744830D for ; Wed, 10 Apr 2019 03:21:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0B0D68A8E4; Wed, 10 Apr 2019 03:21:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DD596898A5 for ; Wed, 10 Apr 2019 03:21:30 +0300 (EEST) Received: by mail-ot1-f67.google.com with SMTP id e5so298012otk.12 for ; Tue, 09 Apr 2019 17:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=p16yZbwTTr12CY86StfHoHS6JJpNF94IWchH4OeJDGQ=; b=MMugZhZzlmbQXH2V91Wa9M2i5f+2urj96zU66d4yn5Dx2cNgw5nK33r8r1P6vAlGyl 9TVW87Uy/iwYdoxR39sPpgqhVtANrMLNWT7WulBFc68jkn7rtJnamyZhAm9uxK9woBg0 NRdXzRr3RfzbcjgAIKGTe64r6otMRnOG/zVXLtOyh4u8U0MWPQnv2t1GYN1gTXPRZQVv BbcWsCmY59hv/fkSbhg3rtU/0E8dL9LUe3vqBvq3ABfT99XVkZexJBhLYqD/unYwlLPk /C1ZfTp2y8q+SbhdkyO5462hee58KuT/2rYnNavTNLVjKHSqTQldy+cT3I/7NpNgSc6s AbRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=p16yZbwTTr12CY86StfHoHS6JJpNF94IWchH4OeJDGQ=; b=U9m1VqnRODz+H/Fr6zDZG/QcmIZ0+QeDWnoiS92XiZ2yx2a1hVV8FRQbAPlo7xO20s UVJTxQbF0l8DxGbZzy21qJeTik0E3JmctCM91tQZvizD/iE7XZhwh3VsKo/3pJJ/NjFW WXQU9BbLkl0YyTHfWFxXGdPAeCDbG8SpwdqbS5r46mAU/6Mt3aMoH9clJ6n3cz4Ttbvz YjwmhviVbJ7/7p2ybhscI+u0x1wDK5h4/agtFomkwLRtiREYsXpWrRVjZHlhVPkrRkAz fEo9YnPYoa4SwaTiuwTma8Rmg1InMvwcNud+5bf8YsPA4dPkP4bQk1nq5dR/LgK5eJ6d yZ1A== X-Gm-Message-State: APjAAAVWVzSgqgnkYLh5wluFo5047u51k1VMnuckM3HNvVvmboNrnDg6 huo//0TRDFvRy0VA/U1hXgcQaU9yi1DIIA== X-Google-Smtp-Source: APXvYqx2IjUOoKCmK2+hi9DwLa2740ul4LYK/gN1CNtv6T4uzztt5REBoGK7ZVvG7ywxd1rHLQ5ZwA== X-Received: by 2002:a9d:6ad1:: with SMTP id m17mr4281922otq.108.1554855329000; Tue, 09 Apr 2019 17:15:29 -0700 (PDT) Received: from tmm1-imac.lan (ip184-189-221-177.sb.sd.cox.net. [184.189.221.177]) by smtp.gmail.com with ESMTPSA id e67sm16097248ote.13.2019.04.09.17.15.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Apr 2019 17:15:28 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Apr 2019 17:14:48 -0700 Message-Id: <20190410001448.30951-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH] avformat/utils: always seek back after avformat_find_stream_info() 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: Aman Gupta Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta Previously, the initial seek position was recorded into old_offset at the beginning of avformat_find_stream_info(), and passed into estimate_timings(). In the case of mpegts with a known filesize, it was further passed into estimate_timings_from_pts() which called avio_seek(SEEK_SET) after doing its timing related seeks. (Interestingly, this seeked all the way back to the initial position before the probe, rather than only back before the timing related seeks to the end of the file). With this commit, we pull the avio_seek() out of the mpegts specific code-path and unconditionally seek all streams back to their original position after probing is complete. This effectively prevents data that is consumed during avformat_find_stream_info() from being discarded, so packets contained at the beginning of a file are still passed back to the user for playback. Signed-off-by: Aman Gupta --- libavformat/utils.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 9b3f0d28e6..94d166869a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2786,7 +2786,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) #define DURATION_MAX_RETRY 6 /* only usable for MPEG-PS streams */ -static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) +static void estimate_timings_from_pts(AVFormatContext *ic) { AVPacket pkt1, *pkt = &pkt1; AVStream *st; @@ -2905,7 +2905,6 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) skip_duration_calc: fill_all_stream_timings(ic); - avio_seek(ic->pb, old_offset, SEEK_SET); for (i = 0; i < ic->nb_streams; i++) { int j; @@ -2918,7 +2917,7 @@ skip_duration_calc: } } -static void estimate_timings(AVFormatContext *ic, int64_t old_offset) +static void estimate_timings(AVFormatContext *ic) { int64_t file_size; @@ -2934,7 +2933,7 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) !strcmp(ic->iformat->name, "mpegts")) && file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { /* get accurate estimate from the PTSes */ - estimate_timings_from_pts(ic, old_offset); + estimate_timings_from_pts(ic); ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; } else if (has_duration(ic)) { /* at least one component has timings - we use them for all @@ -4053,7 +4052,9 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (probesize) - estimate_timings(ic, old_offset); + estimate_timings(ic); + if ((ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) + avio_seek(ic->pb, old_offset, SEEK_SET); av_opt_set(ic, "skip_clear", "0", AV_OPT_SEARCH_CHILDREN);