From patchwork Thu May 18 13:37:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 3697 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp669900vsk; Thu, 18 May 2017 06:37:56 -0700 (PDT) X-Received: by 10.223.154.226 with SMTP id a89mr3034282wrc.192.1495114676078; Thu, 18 May 2017 06:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495114676; cv=none; d=google.com; s=arc-20160816; b=Va3ruEmijp7gnAHY1ENYiYlnxzvrPUvoHBJ5bhhTF5ci3lIOUZUuPdgcqq1Yvz0N/4 qRcnbAZi9KXWmVskHvTVBwSigRnTtZ5n4/qwkPyMNUvp1bkXii1Ew76kgTHRzjvznfqF 1HnLoEpOAVU9LQ9wnwnZlTlA0XbuMI7ylAVVYe13NFsn3j9wC5LOYvznIZI5241SXF5z 0oMfDuiq8rGwnouy+0ubycAji8+saVhuj8UdsJTWLIssANBjwyB6hxLooAXWQSpRMTWO ST0xR7Nq/6vPntSTUoxRVt/FPHhBBVi42snQ+eFsWAfeDfbHl7x6XVBJvuWqkmqBexjQ kgBw== 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:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=7iy1KIsLWek42WdikJLYPXjSVRkf4OdGrgBRyn45JqE=; b=rufCqtjESmRGxgkpqhQUY1SPWSCwO6oeM4g86CpjNT6aHLOlyTVmPemGBhwbpMdl7d yT1Y0GV6jyu2dCabLMMeBlOb6eACj2W3264WF5nYdz0eHouH8XgH2y5cvlLxDMZtTs3B 9klXNSZxDxjPxATbzTHCtivP+uMG5J75ITxqfBiYynlA/YDDDx5iLRg0FaBL/ZU7/icG 69JaebX2kIWsiscwCIQsOmDenX4Z8DBeFj7JKjVpMchD+Ena32uouF9UA/vLhQUUIijK 9Snp3H0vQXWsxY9f6+Sh4fdEuJJ9Rbioz8vVzcmDOwTQr5rsueu1QQv9Q2DFcMn7LdhM Velg== 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 m3si6880195wmm.82.2017.05.18.06.37.55; Thu, 18 May 2017 06:37:56 -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 9DB8A68991D; Thu, 18 May 2017 16:37:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B80146882BF for ; Thu, 18 May 2017 16:37:46 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id u26so5878249pfd.2 for ; Thu, 18 May 2017 06:37:46 -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:mime-version :content-transfer-encoding; bh=+Ho6swOurVGRB88pqrX7cIRNbaTGJJq36ibieM41B0k=; b=tuQqSEEjDXdOAg0Kz23YzzcMB2utp1hZbDreQfU7cn4N+tfSLlDs54DhibgoUUgW85 ChShGifng4zBQIxMBnWXJP+kzCOATxR/bsxVJro+qfwTujhRgAAvaHQ8fkrJH7KqrqQt r5IrFXdR+xXf9i0ULdfTABZwFT3vb39/car1mNweXWuYv9xR2D8vcwvf9XKgrcpY/KAV 0D2GY6qNPLe3IMmDk+oa8uivUulPx6qAXv5yBow+Si598IJl/L3rS61OU3jU+x2TRPYN LjSgLsrzN4xYs+DLRTLs8eUaPtV1qG9zOMIxVeJY7rPYrk9plPNf9Fdh2zAP+FZvF5Rg hcig== 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:mime-version :content-transfer-encoding; bh=+Ho6swOurVGRB88pqrX7cIRNbaTGJJq36ibieM41B0k=; b=V3YMhZZOuLoOqOvvfjwGQ/c0l5nDFW+bAMqX7TwJIWj6UlCrHSI04yRZB4oYws7u3O QKBrvuovAHmSYAy4ZVI1BHJ9Sadhwy9IeQOW7Djn/dtC4b+2ixJ2yyo7sjCy4JsLDeQx toaLqQ2zJJKnlK9RlBQwTpHTa8AYIirkJmiQP12XVJRklH63t9scsg5Tvk4aMgAHZnKd +0lQXAJXXxOFmFLCLxhhiSjQsA+yIgfBhdmn3HuvTDi7/xaIC2fpUgYSyjpT1HhgWDD+ WXig64miMP3ExUinBoVIzWf1kWPy2hNZ6OGU06qnC/dYIAAnOBlE/aHhjf0Y6NSIHSav Jk1Q== X-Gm-Message-State: AODbwcAzKNRpOmGHfuQdoM7z4V3CUTSJRPVxyphfuQf69Y13+tAwX6tu /G/Gc4SOf9uxEg== X-Received: by 10.98.178.72 with SMTP id x69mr4517556pfe.74.1495114665117; Thu, 18 May 2017 06:37:45 -0700 (PDT) Received: from localhost.localdomain ([114.124.211.36]) by smtp.gmail.com with ESMTPSA id t22sm8922580pfi.89.2017.05.18.06.37.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 06:37:44 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 May 2017 20:37:21 +0700 Message-Id: <20170518133721.23603-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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" Should fix Ticket6349. Modifying data pointer may make it unaligned. 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 | 3 ++- libavfilter/framequeue.c | 2 ++ libavfilter/framequeue.h | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 08b86b0..1b6c432 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,7 @@ int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe) *rframe = NULL; if (!ff_inlink_check_available_frame(link)) return 0; + av_assert1(!link->fifo.samples_skipped); 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; /**