From patchwork Wed Feb 15 09:24:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 2559 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1866821vsb; Wed, 15 Feb 2017 01:25:28 -0800 (PST) X-Received: by 10.28.189.195 with SMTP id n186mr6612541wmf.77.1487150727961; Wed, 15 Feb 2017 01:25:27 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v11si7034875wmg.13.2017.02.15.01.25.27; Wed, 15 Feb 2017 01:25:27 -0800 (PST) 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=@googlemail.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 289C2689AC9; Wed, 15 Feb 2017 11:24:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AD0F0689A71 for ; Wed, 15 Feb 2017 11:24:20 +0200 (EET) Received: by mail-wm0-f65.google.com with SMTP id r18so7180118wmd.3 for ; Wed, 15 Feb 2017 01:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mVwH91PnGaLC3KZuLDfLMefgtxL832mbUN491YXwEOI=; b=IHZsTwilseW4/nF0cdqfUTZtezZ+LuTVaRqWIFHpL3rrV4fXQMRh5ETg1xCWYyE9kI l17vK64MAeVkbJkJSM+dMD6weL5E3mf6bVpkafaN5g0d3ZQVxtSkB6/7e6lFC+JgbcMX oAlaEmzXFHWmTQCVXpt6FuIQNpRwItnKVW6HE1aJNN9+WB1lH5nOaCe1M5XDKxcLmS08 ZQEpfUffzT5to9TvU0MKigk54/qD+hdlYsNcLRsUTU5y+yIGmIutrx348jdqdjdn8W8D aVZRgjYFiPXX3NuZVjcC8xTrEaRzwy3eSUOHVu+tpGv1snt/pSjzjMUb7CfufOguDB3s sDNQ== 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:in-reply-to :references; bh=mVwH91PnGaLC3KZuLDfLMefgtxL832mbUN491YXwEOI=; b=W654AdD0Ty9PR14ZoZ4v8xtZhIMyc+PKw+Uj9xTLFyCK4C/eZGUyM8MPxKJQV98wIn VWiOihSchcLlioKU0GAwZVJ4FTrxHNAXAOU22926Jyk2WYr1CQqsJ3hLpIdanMy2xg1H Lm3lNfOjs5HNUSvOU9xE2EL9paFB5iub84gqCi14omRYxb59B6MOUzKhKaBQozNavrUQ 29fpGBZZtQU8dHSFfIQZkRzMC+YtulamjylbbNCdnaecGeTeTnYa0cFE0bAFmNPNSjEG DGunDBlbMakKz4DN93EMDtJyCx4N50YQKJkHu9s01Ne4pQldcOcVcDVCvIB8LYJaQhnY r7MQ== X-Gm-Message-State: AMke39l5ghZBX6mvVtITvDksW8OYaMZm/90mNKLPuXaTs+EbmdKTwM11v2rFb92ZkTj7fA== X-Received: by 10.28.125.22 with SMTP id y22mr7171796wmc.112.1487150666136; Wed, 15 Feb 2017 01:24:26 -0800 (PST) Received: from localhost.localdomain (p4FF0242F.dip0.t-ipconnect.de. [79.240.36.47]) by smtp.googlemail.com with ESMTPSA id u189sm6787730wmu.1.2017.02.15.01.24.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 01:24:25 -0800 (PST) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Feb 2017 10:24:21 +0100 Message-Id: <20170215092423.5358-7-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215092423.5358-1-nfxjfg@googlemail.com> References: <20170210123541.32375-1-nfxjfg@googlemail.com> <20170215092423.5358-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH v2 6/8] ffmpeg: restructure sending EOF to filters 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: wm4 , Anton Khirnov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Anton Khirnov Be more careful when an input stream encounters EOF when its filtergraph has not been configured yet. The current code would immediately mark the corresponding output streams as finished, while there may still be buffered frames waiting for frames to appear on other filtergraph inputs. This should fix the random FATE failures for complex filtergraph tests after a3a0230a9870b9018dc7415ae5872784d524cfe5 This merges Libav commit 94ebf55. It was previously skipped. This is the last filter init related Libav commit that was skipped, so this also removes the commits from doc/libav-merge.txt. Signed-off-by: wm4 --- doc/libav-merge.txt | 1 - ffmpeg.c | 43 ++++++++++++++++++++++++++++++++----------- ffmpeg.h | 2 ++ ffmpeg_filter.c | 9 +++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/doc/libav-merge.txt b/doc/libav-merge.txt index 23b48d1e2b..39d846f8fc 100644 --- a/doc/libav-merge.txt +++ b/doc/libav-merge.txt @@ -95,7 +95,6 @@ Stuff that didn't reach the codebase: - 0cef06df0 checkasm: add HEVC MC tests - e7078e842 hevcdsp: add x86 SIMD for MC - QSV scaling filter (62c58c5) -- ffmpeg.c filter init decoupling (3e265ca,a3a0230,d2e56cf,94ebf55) Collateral damage that needs work locally: ------------------------------------------ diff --git a/ffmpeg.c b/ffmpeg.c index 83088e5195..e9ef04a542 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2193,6 +2193,34 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame) return 0; } +static int ifilter_send_eof(InputFilter *ifilter) +{ + int i, j, ret; + + ifilter->eof = 1; + + if (ifilter->filter) { + ret = av_buffersrc_add_frame_flags(ifilter->filter, NULL, AV_BUFFERSRC_FLAG_PUSH); + if (ret < 0) + return ret; + } else { + // the filtergraph was never configured + FilterGraph *fg = ifilter->graph; + for (i = 0; i < fg->nb_inputs; i++) + if (!fg->inputs[i]->eof) + break; + if (i == fg->nb_inputs) { + // All the input streams have finished without the filtergraph + // ever being configured. + // Mark the output streams as finished. + for (j = 0; j < fg->nb_outputs; j++) + finish_output_stream(fg->outputs[j]->ost); + } + } + + return 0; +} + // This does not quite work like avcodec_decode_audio4/avcodec_decode_video2. // There is the following difference: if you got a frame, you must call // it again with pkt=NULL. pkt==NULL is treated differently from pkt.size==0 @@ -2494,18 +2522,11 @@ out: static int send_filter_eof(InputStream *ist) { - int i, j, ret; + int i, ret; for (i = 0; i < ist->nb_filters; i++) { - if (ist->filters[i]->filter) { - ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL); - if (ret < 0) - return ret; - } else { - // the filtergraph was never configured - FilterGraph *fg = ist->filters[i]->graph; - for (j = 0; j < fg->nb_outputs; j++) - finish_output_stream(fg->outputs[j]->ost); - } + ret = ifilter_send_eof(ist->filters[i]); + if (ret < 0) + return ret; } return 0; } diff --git a/ffmpeg.h b/ffmpeg.h index 56e35ebb9c..5d20d453eb 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -248,6 +248,8 @@ typedef struct InputFilter { uint64_t channel_layout; AVBufferRef *hw_frames_ctx; + + int eof; } InputFilter; typedef struct OutputFilter { diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index 4d9a4e2eb8..816c906c7e 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -1128,6 +1128,15 @@ int configure_filtergraph(FilterGraph *fg) } } + /* send the EOFs for the finished inputs */ + for (i = 0; i < fg->nb_inputs; i++) { + if (fg->inputs[i]->eof) { + ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL); + if (ret < 0) + return ret; + } + } + return 0; }