From patchwork Sat May 20 10:44:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 3701 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp657264vsk; Sat, 20 May 2017 03:45:10 -0700 (PDT) X-Received: by 10.28.153.143 with SMTP id b137mr9769847wme.15.1495277110115; Sat, 20 May 2017 03:45:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495277110; cv=none; d=google.com; s=arc-20160816; b=HNzjey7v6MIRPzib1yObrbYt2YkqTfxiO2DC/8pNJRlBqTVgNoDbvFo7mxJiKguvr3 xPvtzNqxWlkoDmH8fWCpQSq1UMKepz8XVw6/vXX56cMl1G31VW6FsFGTWny1w63UNNPU TLgm3wBCEBCpFMV+9qDUF6KwKekodKeNgt1hqidOnCeMHnNO93EdZ8E6OPJSvXK7jFs+ y/o3KAb9fQ4GG+pKKZ014y/DjdNZFluiGS7GhyJMkipapNZs7VxHHttxj6+3aee2BhJ3 ZLi+QvTMSMiPNWLxTbOaXSlxuoULlJP7KGb4CwAGP7oPfdq8N3Vx0fIfeGnNvOh1JLPj M/iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=kvAuWaU2aF47WGN/9Dd+QK7XB0Afjbgo5vLgkErTn6U=; b=JX63/AWTUZIGHRcFk7PjTCjY1KjfPVq9Est3nJFw3QYFjT/zfxSOlFX5E+3I0I7eqS n94qhmgE4FFxTEaRfnMj+MDBgIZCxRfGc/Nvr7lHZlTGlsi2+K4RGZBEPJ3MQg60/RZB tamX9WJGqH6rkG+kx07UvMNJJFZlg3ngmvuIA/Yat2YyjAC8gXoqprNStf58o3BQhTv5 Ns9PF9K6/J1FkjbGtq03ygaH+VCORs3eFA1c+YoRj1/wga4VN91zFVQ/7yAcT4TVMTnT sJ75ARtoGyPC0zhK0OGsLO/uydzyC8/t/dLrTkEYbW90PEEc5YvngqkIfxHf18EvEWnL gIKQ== ARC-Authentication-Results: i=1; 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 sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h8si12462073wmf.41.2017.05.20.03.45.09; Sat, 20 May 2017 03:45:10 -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 sp=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 E1A7E688385; Sat, 20 May 2017 13:45:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BFFBF68094E for ; Sat, 20 May 2017 13:45:00 +0300 (EEST) Received: by mail-pg0-f67.google.com with SMTP id s62so12361027pgc.0 for ; Sat, 20 May 2017 03:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JjzhlYi3M5MSoTnPyDagRgUo+W6SbSYHHfOiFge286I=; b=G2OWbwq87UJz8nhRkKcbSK9BdydiA5a7rVWIsoHBpsO0Fk8Kd2WHWyszgyATPpIfh6 BOGa/uv3I71iCMTvpfJTh9wGd+kSPfPm3n/PYeVhsYmIWIYoV5iHSSGfNl3VLJ5SO9Lq fSdG1jjyem6y3pJhQnfj0PZpd8qaxi3+sXUqfEYojnqPHVdod8IdraBcRhAAXXNQsjQG tjjaR56WwqpMPalj+oxotqyIRJc9BmT+ggNFKk7sK6PIEKXnVVe/3QcpAzAqm4XfMAjo vDwk4MRsDlMKHBfrnjO2rXFSBD7KZpILMKVW2mHz9B4ilnuqAAMtWpBp/TFxjZSmEnUy GANQ== 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:mime-version:content-transfer-encoding; bh=JjzhlYi3M5MSoTnPyDagRgUo+W6SbSYHHfOiFge286I=; b=T4QyzL4LopEDRnaYZjG7dU/mqqXX+mqiwjZO2/GXJ91Dw8arMxKOXjVPjpj8tPZe61 wUYEOaK3viSfx44lkM/Gxbcs9QojZXfWI6gmq5w8njQyEnC/78f3fnY+SxZGcGc5k7uj QP+2eMLX3c7lAiGBYBdu8/70qSKbwpTd3wykyaAXsCmhQ4IrmIHA9/Fgf2sd4tqu6HoB Tf6enJynyu75br1IhIoGpbQTHWkoGBgy24ObLKSBr29Buh3F8J52wXV6kZJ4k1/acd2k +uC4Bc2p7n7Vf+cnR3eQxRej5gvu6gMoFkNv+w+VEycvPzjteNqCZkSSTPoTXthplWvI kEgA== X-Gm-Message-State: AODbwcCscZ8FE6gsNDElYgwGwOc+7m288QIxWoQuxWxKEOoVYDbE0HWh /ng3XGwgJCX7vXbP X-Received: by 10.98.236.28 with SMTP id k28mr15616347pfh.3.1495277099970; Sat, 20 May 2017 03:44:59 -0700 (PDT) Received: from localhost.localdomain ([114.124.151.37]) by smtp.gmail.com with ESMTPSA id 20sm26850716pfq.42.2017.05.20.03.44.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 03:44:59 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Sat, 20 May 2017 17:44:33 +0700 Message-Id: <20170520104433.25151-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avfilter: take_samples: do not directly return frame when samples are skipped 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: Muhammad Faiz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Modifying data pointer when skipping samples may make it unaligned. Workaround for Ticket6349. This should fix the crash of ticket's testcase and a crash/regression with avxsynth (reported by Michael Niedermayer). Also change frame->nb_samples < max to frame->nb_samples <= max. This improves performance. Benchmark: ./ffmpeg -filter_complex "aevalsrc=0:n=1166,firequalizer=fixed=on" -f null null old: 25767 decicycles in take_samples, 1023 runs, 1 skips 25422 decicycles in take_samples, 2047 runs, 1 skips 25181 decicycles in take_samples, 4095 runs, 1 skips 24904 decicycles in take_samples, 8191 runs, 1 skips new: 550 decicycles in take_samples, 1024 runs, 0 skips 548 decicycles in take_samples, 2048 runs, 0 skips 545 decicycles in take_samples, 4096 runs, 0 skips 544 decicycles in take_samples, 8192 runs, 0 skips Signed-off-by: Muhammad Faiz --- libavfilter/avfilter.c | 8 +++++++- libavfilter/framequeue.c | 2 ++ libavfilter/framequeue.h | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 08b86b0..e60b024 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1191,7 +1191,7 @@ static int take_samples(AVFilterLink *link, unsigned min, unsigned max, called with enough samples. */ av_assert1(samples_ready(link, link->min_samples)); frame0 = frame = ff_framequeue_peek(&link->fifo, 0); - if (frame->nb_samples >= min && frame->nb_samples < max) { + if (!link->fifo.samples_skipped && frame->nb_samples >= min && frame->nb_samples <= max) { *rframe = ff_framequeue_take(&link->fifo); return 0; } @@ -1522,6 +1522,12 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe) *rframe = NULL; if (!ff_inlink_check_available_frame(link)) return 0; + + if (link->fifo.samples_skipped) { + frame = ff_framequeue_peek(&link->fifo, 0); + return ff_inlink_consume_samples(link, frame->nb_samples, frame->nb_samples, rframe); + } + frame = ff_framequeue_take(&link->fifo); consume_update(link, frame); *rframe = frame; diff --git a/libavfilter/framequeue.c b/libavfilter/framequeue.c index 26bfa49..fed1118 100644 --- a/libavfilter/framequeue.c +++ b/libavfilter/framequeue.c @@ -107,6 +107,7 @@ AVFrame *ff_framequeue_take(FFFrameQueue *fq) fq->tail &= fq->allocated - 1; fq->total_frames_tail++; fq->total_samples_tail += b->frame->nb_samples; + fq->samples_skipped = 0; check_consistency(fq); return b->frame; } @@ -146,5 +147,6 @@ void ff_framequeue_skip_samples(FFFrameQueue *fq, size_t samples, AVRational tim for (i = 0; i < planes && i < AV_NUM_DATA_POINTERS; i++) b->frame->data[i] = b->frame->extended_data[i]; fq->total_samples_tail += samples; + fq->samples_skipped = 1; ff_framequeue_update_peeked(fq, 0); } diff --git a/libavfilter/framequeue.h b/libavfilter/framequeue.h index 5aa2c72..c49d872 100644 --- a/libavfilter/framequeue.h +++ b/libavfilter/framequeue.h @@ -100,6 +100,11 @@ typedef struct FFFrameQueue { */ uint64_t total_samples_tail; + /** + * Indicate that samples are skipped + */ + int samples_skipped; + } FFFrameQueue; /**