From patchwork Tue Sep 20 04:31:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: raymond X-Patchwork-Id: 653 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp217055vsd; Mon, 19 Sep 2016 21:59:16 -0700 (PDT) X-Received: by 10.28.67.2 with SMTP id q2mr1436784wma.123.1474347556545; Mon, 19 Sep 2016 21:59:16 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g123si22140848wmd.78.2016.09.19.21.59.15; Mon, 19 Sep 2016 21:59:16 -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; 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 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 5ACEE689B42; Tue, 20 Sep 2016 07:58:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 29ABE689A6C for ; Tue, 20 Sep 2016 07:58:52 +0300 (EEST) Received: by mail-pf0-f193.google.com with SMTP id n24so365454pfb.3 for ; Mon, 19 Sep 2016 21:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=AP8aD2fYEdIwBZ7nWltBgHpLavTjmmhxedZ1Wa68mIg=; b=GneKaiAvHzcgbgvH/cgo9PDlYtPMpollsox2umu8CJwBZ7KaGCy9txA9wjb/HL53Lq 74wCOWJj9A9ntAzFSduhkxEhCUBG7kR50wUXzs8KyfPTeeP3G6v+5wqao6X5A5GzDOI4 61CsKXz51AONT16TySj/n/1Uf4znl3Fs+G62skmpQgDgdqLK8dKumSwiPPH14MB/bpcj e3ja0uo+3CLRmtQ/ipGdZ1FBcv91HjrIWNEic/GCo+mdztITrRPRQAI2gIYwWW40KAs0 d/LKYW5mBqLVezPRB1u38ht1IcRpZzy1x2nDbB0bJt5ubr2+JqIWoKqBpOySeXEreJj+ 9EIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AP8aD2fYEdIwBZ7nWltBgHpLavTjmmhxedZ1Wa68mIg=; b=E0wMEpgBG28SLHgECx/DB0bbcl9RnJmqc/bcYa9m5JAjF/l7sAqMLI2zge8CnbyRRp tasYhzp0CapM65O0D1kFXv2gavbhb6GSQz/0Vi3NzTKNKbvadyi+gS0pRaABFzV2AHIU 19w3AbaApJi4xwWfzgss66lIyMbCwJADneduiu3V9/Z3rxIlBx1HI5JQLBuIhZqAZZI9 fX/Ip3KHIlqV7ZxFH4fS0BcAMKu1MvANjnAUlT3FZra7eybsdrXVnheWg52mkClemElB fNp0dCZucDxnqkoPCpY7BCn5OAn/bB8zPdr1O9YVG/PoOD9mxTAiGbSgUgSmFSOqt8zb ARTA== X-Gm-Message-State: AE9vXwPKwyzT7zI4VLizR0M9uzd/mBiUB9/yilEuICICbiXFGxRL6g04rwiCEidp8LcdSQ== X-Received: by 10.98.148.2 with SMTP id m2mr20654779pfe.129.1474345888610; Mon, 19 Sep 2016 21:31:28 -0700 (PDT) Received: from localhost.localdomain (014136134118.ctinets.com. [14.136.134.118]) by smtp.gmail.com with ESMTPSA id c66sm74864723pfd.24.2016.09.19.21.31.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Sep 2016 21:31:27 -0700 (PDT) From: raymond To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Sep 2016 12:31:16 +0800 Message-Id: <1474345876-95480-1-git-send-email-raymondzheng1412@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] avformat/concatdec: don't call open_file when seek position within a file 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: zhenghanchao@bilibili.com, raymond MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/concatdec.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index b3a430e..1cd9ec1 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -64,6 +64,8 @@ typedef struct { ConcatMatchMode stream_match_mode; unsigned auto_convert; int segment_time_metadata; + int cur_fileno; + AVFormatContext *cur_avf_saved; } ConcatContext; static int concat_probe(AVProbeData *probe) @@ -333,6 +335,8 @@ static int open_file(AVFormatContext *avf, unsigned fileno) avformat_close_input(&cat->avf); return ret; } + + cat->cur_fileno = fileno; cat->cur_file = file; if (file->start_time == AV_NOPTS_VALUE) file->start_time = !fileno ? 0 : @@ -711,13 +715,18 @@ static int real_seek(AVFormatContext *avf, int stream, left = mid; } - if ((ret = open_file(avf, left)) < 0) - return ret; + if (cat->cur_fileno != left) { + if ((ret = open_file(avf, left)) < 0) + return ret; + } else { + cat->avf = cat->cur_avf_saved; + } ret = try_seek(avf, stream, min_ts, ts, max_ts, flags); if (ret < 0 && left < cat->nb_files - 1 && cat->files[left + 1].start_time < max_ts) { + cat->avf = NULL; if ((ret = open_file(avf, left + 1)) < 0) return ret; ret = try_seek(avf, stream, min_ts, ts, max_ts, flags); @@ -730,7 +739,7 @@ static int concat_seek(AVFormatContext *avf, int stream, { ConcatContext *cat = avf->priv_data; ConcatFile *cur_file_saved = cat->cur_file; - AVFormatContext *cur_avf_saved = cat->avf; + cat->cur_avf_saved = cat->avf; int ret; if (!cat->seekable) @@ -739,12 +748,16 @@ static int concat_seek(AVFormatContext *avf, int stream, return AVERROR(ENOSYS); cat->avf = NULL; if ((ret = real_seek(avf, stream, min_ts, ts, max_ts, flags)) < 0) { - if (cat->avf) - avformat_close_input(&cat->avf); - cat->avf = cur_avf_saved; + if (cat->cur_file != cur_file_saved) { + if (cat->avf) + avformat_close_input(&cat->avf); + } + cat->avf = cat->cur_avf_saved; cat->cur_file = cur_file_saved; } else { - avformat_close_input(&cur_avf_saved); + if (cat->cur_file != cur_file_saved) { + avformat_close_input(&cat->cur_avf_saved); + } cat->eof = 0; } return ret;