From patchwork Fri Jul 23 10:34:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 29033 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp1275283ios; Fri, 23 Jul 2021 03:35:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3TqAEUY7MlhRKtyakIQje+69uzKvwPZ0Nvtxh+VZDSqyRfAv9GR8NGJfGosn+JNpFjABn X-Received: by 2002:a17:906:e088:: with SMTP id gh8mr4016115ejb.125.1627036531039; Fri, 23 Jul 2021 03:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627036531; cv=none; d=google.com; s=arc-20160816; b=xsyiNGK5YndWqedozTAfAlNtThna4kY9tkMQMfcmskS+DOq5mAjFljPAZBtacrKb7A k3N3FMwMlLS+U1tJ/dQw5YwO8i+nDAN0V5dMWK0OhZobKRQMsrKJ78/gsNXdvhv26fBv 7xGpIF/CRaG8YwmXV0hvK7o46tt3mvqeUtB4LB2oQD8hBrURQJLTBDMyqw9oEWX3BpoY lFDdmb/MeYCzRPDFj1Y5fCRGZVRblxXy6BiNB4d4SdFjcr+rJZPfpOCnwnpqTjw3llWM ZK4y5KmtKDxNpmO5LGCAqOFG2arvf+mJowiP7oy9BT4wo4Kl9FACewDm90Hb2FplQ1Jn W7BA== 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=F0qKM7ChDAnE+BogAftc4n2EEeLvNJ/dm6KsPBBlans=; b=CD1QqOTi22WbxuHNW7g03oB3MURRyndwhvUrfCrCrCxM81vP5a/x0+FNUIe0TGOqOH pADzONFBN5vUjYXUK32WF+RR3rNuCKEw33ydmk/McN0xVKmA0r/G/tcE5YLq+3D4jLk/ IF4kZysGmsodXAIqtTFQ0l6WW2PytTiNhLq+6ct9HjprjSPZ1lazttWqvqCwvFX4HdBV 5YS3PdcUPoelhWMTte9tNt47g94pb/90gn5ZWjgtbWLNRFF4M9A1qhRQoMYU0Zl0hFlJ QB4FyZa7YuHQPDwezxGBMsG1msniLiMi4D4F0o/fD+YOmT6BsDg9721YIjQsYEFqzE0o IiOw== 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 sa13si33447650ejb.425.2021.07.23.03.35.30; Fri, 23 Jul 2021 03:35:31 -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 D2C2C68ADD0; Fri, 23 Jul 2021 13:35:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D18A68A107 for ; Fri, 23 Jul 2021 13:35:19 +0300 (EEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (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-102.mailbox.org (Postfix) with ESMTPS id 4GWQgp3bJjzQk0x for ; Fri, 23 Jul 2021 12:35:18 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id nySAtcMbzAuX for ; Fri, 23 Jul 2021 12:35:15 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Jul 2021 16:04:49 +0530 Message-Id: <20210723103450.11265-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8E2A01819 X-Rspamd-UID: d29e64 Subject: [FFmpeg-devel] [PATCH v2 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: +Vb748PsRFVh 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 +++++++++++++------ tests/fate/matroska.mak | 2 +- .../fate/matroska-mastering-display-metadata | 10 ++++----- 4 files changed, 26 insertions(+), 20 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, }; diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak index ca7193a055..8dba371ff4 100644 --- a/tests/fate/matroska.mak +++ b/tests/fate/matroska.mak @@ -88,7 +88,7 @@ FATE_MATROSKA_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL MXF_DEMUXER \ MATROSKA_MUXER MATROSKA_DEMUXER \ FRAMECRC_MUXER PIPE_PROTOCOL) \ += fate-matroska-mastering-display-metadata -fate-matroska-mastering-display-metadata: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf matroska "-map 0 -map 0:0 -c:v:0 copy -c:v:1 ffv1 -c:a:0 copy -bsf:a:0 noise=amount=3 -filter:a:1 aresample -c:a:1 pcm_s16be -bsf:a:1 noise=dropamount=4" "-map 0 -c copy" "" "-show_entries stream_side_data_list:stream=index,codec_name" +fate-matroska-mastering-display-metadata: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf matroska "-map 0 -map 0:0 -c:v:0 copy -c:v:1 ffv1 -c:a:0 copy -bsf:a:0 noise=amount=3 -filter:a:1 aresample -c:a:1 pcm_s16be -bsf:a:1 noise=amount=100:dropamount=4" "-map 0 -c copy" "" "-show_entries stream_side_data_list:stream=index,codec_name" # This test tests remuxing annex B H.264 into Matroska. It also tests writing # the correct interlaced flags and overriding the sample aspect ratio, leading diff --git a/tests/ref/fate/matroska-mastering-display-metadata b/tests/ref/fate/matroska-mastering-display-metadata index 8f5d7b6a22..bd8d7cb2c9 100644 --- a/tests/ref/fate/matroska-mastering-display-metadata +++ b/tests/ref/fate/matroska-mastering-display-metadata @@ -1,4 +1,4 @@ -542ababe5c088ab925ee49373d8b8a85 *tests/data/fate/matroska-mastering-display-metadata.matroska +61c080b57ef81a6e3bc971857a6973dc *tests/data/fate/matroska-mastering-display-metadata.matroska 1669695 tests/data/fate/matroska-mastering-display-metadata.matroska #extradata 0: 4, 0x040901a3 #extradata 3: 200, 0x506463a8 @@ -29,19 +29,19 @@ 3, 0, 0, 16, 274117, 0xc439610f, S=2, 8, 88 0, 17, 17, 16, 57248, 0xa06cd7b5 1, 17, 17, 16, 2403, 0xe1a991e5 -2, 17, 17, 16, 1602, 0x5d868171 +2, 17, 17, 16, 1602, 0x98680820 3, 17, 17, 16, 273691, 0x5a3b88a5, F=0x0 0, 33, 33, 16, 57200, 0x5623da10 1, 33, 33, 16, 2400, 0x6650907f -2, 33, 33, 16, 1600, 0xa90f0044 +2, 33, 33, 16, 1600, 0xd0590820 3, 33, 33, 16, 272987, 0x48c443e7, F=0x0 0, 50, 50, 16, 57152, 0x52d89d3f 1, 50, 50, 16, 2403, 0x43398a08 -2, 50, 50, 16, 1602, 0x3a350084 +2, 50, 50, 16, 1602, 0x18990820 3, 50, 50, 16, 271465, 0x251b9cbe, F=0x0 0, 67, 67, 16, 56960, 0x431d5189 1, 67, 67, 16, 2403, 0x61cd96cb -2, 67, 67, 16, 1602, 0xd74800c6 +2, 67, 67, 16, 1602, 0x58ca0720 3, 67, 67, 16, 270800, 0x8fb2e217, F=0x0 [STREAM] index=0