From patchwork Thu Mar 2 08:53:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 2729 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.31.14 with SMTP id f14csp153862vsf; Thu, 2 Mar 2017 00:54:13 -0800 (PST) X-Received: by 10.28.139.134 with SMTP id n128mr7281017wmd.125.1488444853305; Thu, 02 Mar 2017 00:54:13 -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 t3si10237182wmd.79.2017.03.02.00.54.12; Thu, 02 Mar 2017 00:54:13 -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 E39A86883A9; Thu, 2 Mar 2017 10:53:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1EF7E68837F for ; Thu, 2 Mar 2017 10:53:11 +0200 (EET) Received: by mail-wm0-f67.google.com with SMTP id u63so11221471wmu.2 for ; Thu, 02 Mar 2017 00:53:22 -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=n//JxOhJXUAP3+qGHGXvcppfgyL0GZ6c0CR0IOxztIY=; b=GbWOLMGMLAKfLziVu6Ll8cwr5JacY1hGkG6pGm67Wze8oy2GE1Dp9QNfWRGTrQByfM Rwkg3mJ0taZxvdYDRm0kMjaNu440Q8mOBOzuJMvl8MulQKAbUSmdxtfWzvdjMJcciBm4 qCVthC5cgBqiDp51Gjv3Vku7FMo1UwjwH/wFKht9EquIANlZzs/Yg10D2Fe1XmT0h5cz xWwfk8E21Fk5Djlv6qR7wYTILxKsxEySSgq+LaiTIs2/GmDbfmLzXlmG4ZEpqejmFR6F CoyHjG4SU3iBd6GePGhTkbOHo3x+bgVg6cFmiZXZkIoW7HiISMU9n6I32T7l4WK02kJt u9yw== 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=n//JxOhJXUAP3+qGHGXvcppfgyL0GZ6c0CR0IOxztIY=; b=JvR5BHBrYP6AhviY9cIATPP3RbysUlLzyQzBrNQ8348VZZtiCoe979hSVhqK+3GuvZ 8mL2vD4+xQd+pMWuKmphMezG2u1pWfkh6ux8Bkh7pmT45/7WNxRDBpCb3VsjU7Zxwrov bhhrDj/Rh/QH3dPgOs7ZRKtslqdktnoUBGdXO5IhPLoUttKWf8J9bh0WX2QqxF61pELj bwhfwQxTx5jomowkC5j1Df0BrqSQ4IVoL4xT4VNIBVJ5SF8lZm76+u3z4zPU/HwT3hqo 4SgV7C8B0/fueOhgQb77os6r5i//qoxIhKArmet50lpEqPqDEoGysS2w3hyfXf6cT2iF ZYfQ== X-Gm-Message-State: AMke39ntojU5bu0f/Hn20zo4GUZ9HDktUpEpnLyIQe5asKBkyhLg5+ZnawdpjgBPF+OPhA== X-Received: by 10.28.152.212 with SMTP id a203mr6853319wme.36.1488444801891; Thu, 02 Mar 2017 00:53:21 -0800 (PST) Received: from localhost.localdomain (p4FF003DA.dip0.t-ipconnect.de. [79.240.3.218]) by smtp.googlemail.com with ESMTPSA id s18sm26177390wmb.18.2017.03.02.00.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 00:53:21 -0800 (PST) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Mar 2017 09:53:08 +0100 Message-Id: <20170302085309.11471-7-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170302085309.11471-1-nfxjfg@googlemail.com> References: <20170210123541.32375-1-nfxjfg@googlemail.com> <20170302085309.11471-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH v3 6/7] 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 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 e059b88720..10c66eee75 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2197,6 +2197,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 @@ -2498,18 +2526,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; }