From patchwork Sat Jul 8 11:21:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 4266 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1264891vsb; Sat, 8 Jul 2017 04:21:44 -0700 (PDT) X-Received: by 10.28.139.145 with SMTP id n139mr1977526wmd.53.1499512904456; Sat, 08 Jul 2017 04:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499512904; cv=none; d=google.com; s=arc-20160816; b=VZiQHmy2anFYT/GifY4qdHatBZGbgrB4W0hRVBJ3CpHMOz0RiZ9aKaRGchQGQQdrk1 KNvB2tZDUgNDL4XlEt+q76Pgzru6ub+/fV8NNtOH9u+jrrOIm2Gc4X3m/tTqN9vnpFno 0erZVmovsygHXhAqVMbuY0kyPGFbmP4Xx3s+QfyZfT3sfYS0TA7nOVe94VpBnA2SAjuA TnA0RC1YBUmUx4v5Feiy64Y6tOaJ3wB35oYEvQaUPfKYVjC5H3d0GWXXq8Mxnm3b7bPP cLVHx3iQis7Ci59s6GUTOcO6LcCT6sfurleO6ARroN7OxfRr1BvsIxVTGMFwGWN1ZFBF ZFbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=ZUXM7NJ7ZbrukhaAAOh/1zEdQ31eOCRF8QGm12w1i0g=; b=VHJKFKlWFRkjjxAEkSHp2les2RBtNzS5QX3wFm9U4YH1NPUFAugiP8Y14/XmYBA+ZX PHs4Go6LAeQZebXT6KrZms23/WLnn7fQ8OkEX+N4613qff9+7qeev6ImToVhD0FMlodh 6Z9Q9tPRM8HuGjJ+RhHIqfwlhmT2h6u9Q25sTF+XKgPWbZ0ecztQEFzzBrjVxmdhheXa v928K8RghJ5XtJmD+1VWX/kz3ZlN7AgwHvZNo7zrsgbrQFB+lDuDZlBQCwsFFOVDlayz ednnDVpcpp/7iWcij0LdkkXpoSTPefC7TSW89DCXJbCEKlpdrXNYt8VCpevx1fclow7U 1pbw== 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 76si1840737wmg.188.2017.07.08.04.21.43; Sat, 08 Jul 2017 04:21:44 -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 881CC689BBA; Sat, 8 Jul 2017 14:21:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AFC97689A5A for ; Sat, 8 Jul 2017 14:21:31 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id CD132102D0E; Sat, 8 Jul 2017 13:21:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iYpanWSbkFvu; Sat, 8 Jul 2017 13:21:33 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 62299100B78; Sat, 8 Jul 2017 13:21:33 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Jul 2017 13:21:32 +0200 Message-Id: <20170708112132.21288-1-cus@passwd.hu> X-Mailer: git-send-email 2.12.3 Subject: [FFmpeg-devel] [PATCH] avcodec/noise_bsf: add support for dropping packets 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- doc/bitstream_filters.texi | 14 +++++++++++--- libavcodec/noise_bsf.c | 8 ++++++++ libavcodec/version.h | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 926610ca7b..2dffe021f9 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -220,19 +220,27 @@ ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi @section noise -Damages the contents of packets without damaging the container. Can be -used for fuzzing or testing error resilience/concealment. +Damages the contents of packets or simply drops them without damaging the +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. +@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. +@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 @end example -applies the modification to every byte. @section null This bitstream filter passes the packets through unchanged. diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c index 0aebee1ad6..84b94032ad 100644 --- a/libavcodec/noise_bsf.c +++ b/libavcodec/noise_bsf.c @@ -31,6 +31,7 @@ typedef struct NoiseContext { const AVClass *class; int amount; + int dropamount; unsigned int state; } NoiseContext; @@ -48,6 +49,12 @@ static int noise(AVBSFContext *ctx, AVPacket *out) if (ret < 0) return ret; + if (s->dropamount > 0 && s->state % s->dropamount == 0) { + s->state++; + av_packet_free(&in); + return AVERROR(EAGAIN); + } + ret = av_new_packet(out, in->size); if (ret < 0) goto fail; @@ -73,6 +80,7 @@ fail: #define OFFSET(x) offsetof(NoiseContext, x) static const AVOption options[] = { { "amount", NULL, OFFSET(amount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX }, + { "dropamount", NULL, OFFSET(dropamount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX }, { NULL }, }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 3c5fea9327..096b062e97 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MINOR 100 -#define LIBAVCODEC_VERSION_MICRO 103 +#define LIBAVCODEC_VERSION_MICRO 104 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \