diff mbox

[FFmpeg-devel] avcodec/noise_bsf: add support for dropping packets

Message ID 20170708112132.21288-1-cus@passwd.hu
State Accepted
Commit b406f387c80956a4f04ad69f524b7092660ff823
Headers show

Commit Message

Marton Balint July 8, 2017, 11:21 a.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 doc/bitstream_filters.texi | 14 +++++++++++---
 libavcodec/noise_bsf.c     |  8 ++++++++
 libavcodec/version.h       |  2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer July 8, 2017, 4:12 p.m. UTC | #1
On Sat, Jul 08, 2017 at 01:21:32PM +0200, Marton Balint wrote:
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  doc/bitstream_filters.texi | 14 +++++++++++---
>  libavcodec/noise_bsf.c     |  8 ++++++++
>  libavcodec/version.h       |  2 +-
>  3 files changed, 20 insertions(+), 4 deletions(-)

should be ok

supporting duplicatig random previous packets might be interresting
too

thx

PS: these should also be tested in fate

[...]
Marton Balint July 9, 2017, 6:12 p.m. UTC | #2
On Sat, 8 Jul 2017, Michael Niedermayer wrote:

> On Sat, Jul 08, 2017 at 01:21:32PM +0200, Marton Balint wrote:
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  doc/bitstream_filters.texi | 14 +++++++++++---
>>  libavcodec/noise_bsf.c     |  8 ++++++++
>>  libavcodec/version.h       |  2 +-
>>  3 files changed, 20 insertions(+), 4 deletions(-)
>
> should be ok

Thanks, applied.

>
> supporting duplicatig random previous packets might be interresting
> too
>
> thx
>
> PS: these should also be tested in fate

I agree :). Will put it on my todo list...

Regards,
Marton
diff mbox

Patch

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, \