2007-05-19 00:30:15 +00:00
|
|
|
/*
|
|
|
|
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-06 13:49:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-05-19 00:30:15 +00:00
|
|
|
#include "avcodec.h"
|
2013-11-23 10:43:13 +00:00
|
|
|
#include "bsf.h"
|
|
|
|
|
|
|
|
#include "libavutil/log.h"
|
2012-08-06 13:49:32 +00:00
|
|
|
#include "libavutil/mem.h"
|
2013-11-23 10:43:13 +00:00
|
|
|
#include "libavutil/opt.h"
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
typedef struct NoiseContext {
|
|
|
|
const AVClass *class;
|
|
|
|
int amount;
|
|
|
|
unsigned int state;
|
|
|
|
} NoiseContext;
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
static int noise(AVBSFContext *ctx, AVPacket *out)
|
|
|
|
{
|
|
|
|
NoiseContext *s = ctx->priv_data;
|
|
|
|
AVPacket *in;
|
|
|
|
int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1);
|
|
|
|
int i, ret = 0;
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2016-04-17 17:47:25 +00:00
|
|
|
if (amount <= 0)
|
2012-10-14 19:45:42 +00:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
ret = ff_bsf_get_packet(ctx, &in);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = av_new_packet(out, in->size);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
ret = av_packet_copy_props(out, in);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
memcpy(out->data, in->data, in->size);
|
2007-05-19 00:30:15 +00:00
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
for (i = 0; i < out->size; i++) {
|
|
|
|
s->state += out->data[i] + 1;
|
|
|
|
if (s->state % amount == 0)
|
|
|
|
out->data[i] = s->state;
|
2007-05-19 00:30:15 +00:00
|
|
|
}
|
2013-11-23 10:43:13 +00:00
|
|
|
fail:
|
|
|
|
if (ret < 0)
|
|
|
|
av_packet_unref(out);
|
|
|
|
av_packet_free(&in);
|
|
|
|
return ret;
|
2007-05-19 00:30:15 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 10:43:13 +00:00
|
|
|
#define OFFSET(x) offsetof(NoiseContext, x)
|
|
|
|
static const AVOption options[] = {
|
|
|
|
{ "amount", NULL, OFFSET(amount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass noise_class = {
|
|
|
|
.class_name = "noise",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
|
|
|
const AVBitStreamFilter ff_noise_bsf = {
|
2013-10-02 17:20:29 +00:00
|
|
|
.name = "noise",
|
2016-05-01 20:23:48 +00:00
|
|
|
.priv_data_size = sizeof(NoiseContext),
|
2013-11-23 10:43:13 +00:00
|
|
|
.priv_class = &noise_class,
|
2013-10-02 17:20:29 +00:00
|
|
|
.filter = noise,
|
2007-05-19 00:30:15 +00:00
|
|
|
};
|