From patchwork Fri Jul 23 09:33:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 29030 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp1234660ios; Fri, 23 Jul 2021 02:34:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqFXoHy6JOc7mdCyP3u0niWXicg2bEHIjBXtnuxCx4IjdcLcsEElDvZNgQQszZXVG+PSmM X-Received: by 2002:a05:6402:17d3:: with SMTP id s19mr4482866edy.49.1627032862622; Fri, 23 Jul 2021 02:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627032862; cv=none; d=google.com; s=arc-20160816; b=PqPIkSLcANDFVF2bFFjzqKxAaOSgGYiI1Z0EyIB2Zh+YBphB3VDNJ/u/LlXqCx79JC 4tmjYdzRgUFScOOZylgSt9f90iU/Nw3zioZQJvhX9VJ87JWjoBKRKvZsW5YifVcP4HWj ly16OfvHoW40+ZyiH+LMYA6zYFhYlTOdzRd2JhtXW6NbXfB5BLUdphrjr9Ew0AzmN6ot Fii3GERI3KjxnPRJT6lCcF47DEFqnuMZkjbIGEMSi0uLBam8MCM2YE8BD7Xan3J0koBH NOh4H6sr6/lAx4ucInX/E0Qukz0sfqp3TFDjDobT0h9C6ZVEsiFHqv3KWqybVZN3nEIH XDtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=qNl6kaO7ogb6i5cXaw0HS+5BKgcYN3nx8ySjNg1xwI8=; b=iGLR2aOwkuhX58gUxNUOzgD3bE9EbwcrqiduVYjH6Q5v8GAZdvmDnutNHrg7WBhuhC klO0HM41pl24iSPQOl3FA99oNnPx4gzfpUqgkwgxwzhkHpLAqM7aaP95nQn0UWKqArzo GCOirWFMckwYzXlw97KB8ZxaqPL38pnP9xW4YA8LrdqTpvrTvhjtSYNQH6TvWkFmW7/G nImfDgiKJ27HphZXOJ57tp37z82h+/34N2xG3r1QSu7FM2fp8KXH1VJOJx8LPwY0aNDe Hn+86IoPFl9+IEL8HxPrrmGZZpyYDVi6kOvNHwIT43CCU+Ub54ivOJE+ZQYA+zKux8GM 3OFA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v22si33762896ejc.505.2021.07.23.02.34.22; Fri, 23 Jul 2021 02:34:22 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 54BF168A2FE; Fri, 23 Jul 2021 12:34:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42B8A689CDF for ; Fri, 23 Jul 2021 12:34:10 +0300 (EEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4GWPKF6xtJzQkC5 for ; Fri, 23 Jul 2021 11:34:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id mWAEB_dUKLAd for ; Fri, 23 Jul 2021 11:34:06 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jul 2021 15:03:40 +0530 Message-Id: <20210723093341.2000-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-Rspamd-Queue-Id: 004521845 X-Rspamd-UID: f8c480 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/noise: don't force non-zero value for amount X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: F1Y2eeEUNLKJ Currently, the user is forced to accept some noise in packet payload, even if not requested. --- doc/bitstream_filters.texi | 13 +++++-------- libavcodec/noise_bsf.c | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index d10842ae47..2b84bda1fc 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -534,20 +534,17 @@ container. Can be used for fuzzing or testing error resilience/concealment. Parameters: @table @option @item amount -A numeral string, whose value is related to how often output bytes will -be modified. Therefore, values below or equal to 0 are forbidden, and -the lower the more frequent bytes will be modified, with 1 meaning -every byte is modified. +Accepts a positive integer. Lower the value, more frequently bytes will be modified, +with @var{1} meaning every byte is modified. Default is @var{0}. @item dropamount -A numeral string, whose value is related to how often packets will be dropped. -Therefore, values below or equal to 0 are forbidden, and the lower the more -frequent packets will be dropped, with 1 meaning every packet is dropped. +Accepts a positive integer. Lower the value, more frequently packets will be dropped, +with @var{1} meaning every packet is dropped. Default is @var{0}. @end table The following example applies the modification to every byte but does not drop any packets. @example -ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv +ffmpeg -i INPUT -c copy -bsf noise=amount=1 output.mkv @end example @section null diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c index 6ebd369633..c1b0203442 100644 --- a/libavcodec/noise_bsf.c +++ b/libavcodec/noise_bsf.c @@ -33,20 +33,28 @@ typedef struct NoiseContext { unsigned int state; } NoiseContext; -static int noise(AVBSFContext *ctx, AVPacket *pkt) +static int noise_init(AVBSFContext *ctx) { NoiseContext *s = ctx->priv_data; - int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1); - int i, ret; - if (amount <= 0) + if (!s->amount && !s->dropamount) { + av_log(ctx, AV_LOG_ERROR, "At least one of amount and dropamount must be set.\n"); return AVERROR(EINVAL); + } + + return 0; +} + +static int noise(AVBSFContext *ctx, AVPacket *pkt) +{ + NoiseContext *s = ctx->priv_data; + int i, ret; ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - if (s->dropamount > 0 && s->state % s->dropamount == 0) { + if (s->dropamount && s->state % s->dropamount == 0) { s->state++; av_packet_unref(pkt); return AVERROR(EAGAIN); @@ -60,7 +68,7 @@ static int noise(AVBSFContext *ctx, AVPacket *pkt) for (i = 0; i < pkt->size; i++) { s->state += pkt->data[i] + 1; - if (s->state % amount == 0) + if (s->amount && s->state % s->amount == 0) pkt->data[i] = s->state; } @@ -86,5 +94,6 @@ const AVBitStreamFilter ff_noise_bsf = { .name = "noise", .priv_data_size = sizeof(NoiseContext), .priv_class = &noise_class, + .init = noise_init, .filter = noise, };