Commit b406f387 authored by Marton Balint's avatar Marton Balint

avcodec/noise_bsf: add support for dropping packets

Signed-off-by: 's avatarMarton Balint <cus@passwd.hu>
parent fe924220
...@@ -220,19 +220,27 @@ ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi ...@@ -220,19 +220,27 @@ ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi
@section noise @section noise
Damages the contents of packets without damaging the container. Can be Damages the contents of packets or simply drops them without damaging the
used for fuzzing or testing error resilience/concealment. container. Can be used for fuzzing or testing error resilience/concealment.
Parameters: Parameters:
@table @option
@item amount
A numeral string, whose value is related to how often output bytes will 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 be modified. Therefore, values below or equal to 0 are forbidden, and
the lower the more frequent bytes will be modified, with 1 meaning the lower the more frequent bytes will be modified, with 1 meaning
every byte is modified. 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 @example
ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
@end example @end example
applies the modification to every byte.
@section null @section null
This bitstream filter passes the packets through unchanged. This bitstream filter passes the packets through unchanged.
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
typedef struct NoiseContext { typedef struct NoiseContext {
const AVClass *class; const AVClass *class;
int amount; int amount;
int dropamount;
unsigned int state; unsigned int state;
} NoiseContext; } NoiseContext;
...@@ -48,6 +49,12 @@ static int noise(AVBSFContext *ctx, AVPacket *out) ...@@ -48,6 +49,12 @@ static int noise(AVBSFContext *ctx, AVPacket *out)
if (ret < 0) if (ret < 0)
return ret; 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); ret = av_new_packet(out, in->size);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
...@@ -73,6 +80,7 @@ fail: ...@@ -73,6 +80,7 @@ fail:
#define OFFSET(x) offsetof(NoiseContext, x) #define OFFSET(x) offsetof(NoiseContext, x)
static const AVOption options[] = { static const AVOption options[] = {
{ "amount", NULL, OFFSET(amount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX }, { "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 }, { NULL },
}; };
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 100 #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, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment