summaryrefslogtreecommitdiff
path: root/libavcodec/noise_bsf.c
diff options
context:
space:
mode:
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-04-17 18:47:25 +0100
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-04-17 18:47:40 +0100
commitaf9cac1be1750ecc0e12c6788a3aeed1f1a778be (patch)
tree2e34226dbd4010774f6ffef448aab4b7d4f88544 /libavcodec/noise_bsf.c
parent6d160afab2fa8d3bfb216fee96d3537ffc9e86e8 (diff)
parent33d18982fa03feb061c8f744a4f0a9175c1f63ab (diff)
downloadffmpeg-af9cac1be1750ecc0e12c6788a3aeed1f1a778be.tar.gz
Merge commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab'
* commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab': lavc: add a new bitstream filtering API Conversions-by: Hendrik Leppkes <h.leppkes@gmail.com> Conversions-by: Derek Buitenguis <derek.buitenhuis@gmail.com> Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/noise_bsf.c')
-rw-r--r--libavcodec/noise_bsf.c70
1 files changed, 53 insertions, 17 deletions
diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
index 556ad5c549..9b4f4e4961 100644
--- a/libavcodec/noise_bsf.c
+++ b/libavcodec/noise_bsf.c
@@ -22,34 +22,70 @@
#include <string.h>
#include "avcodec.h"
+#include "bsf.h"
+
+#include "libavutil/log.h"
#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+typedef struct NoiseContext {
+ const AVClass *class;
+ int amount;
+ unsigned int state;
+} NoiseContext;
-static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
- uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe){
- unsigned int *state= bsfc->priv_data;
- int amount= args ? atoi(args) : (*state % 10001+1);
- int i;
+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;
- if(amount <= 0)
+ if (amount <= 0)
return AVERROR(EINVAL);
- *poutbuf= av_malloc(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!*poutbuf)
- return AVERROR(ENOMEM);
+ ret = ff_bsf_get_packet(ctx, &in);
+ if (ret < 0)
+ return ret;
+
+ ret = av_new_packet(out, in->size);
+ if (ret < 0)
+ goto fail;
+
+ ret = av_packet_copy_props(out, in);
+ if (ret < 0)
+ goto fail;
+
+ memcpy(out->data, in->data, in->size);
- memcpy(*poutbuf, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
- for(i=0; i<buf_size; i++){
- (*state) += (*poutbuf)[i] + 1;
- if(*state % amount == 0)
- (*poutbuf)[i] = *state;
+ for (i = 0; i < out->size; i++) {
+ s->state += out->data[i] + 1;
+ if (s->state % amount == 0)
+ out->data[i] = s->state;
}
- return 1;
+fail:
+ if (ret < 0)
+ av_packet_unref(out);
+ av_packet_free(&in);
+ return ret;
}
-AVBitStreamFilter ff_noise_bsf={
+#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 = {
.name = "noise",
.priv_data_size = sizeof(int),
+ .priv_class = &noise_class,
.filter = noise,
};