Commit dc99ee6b authored by James Almer's avatar James Almer

avcodec/noise_bsf: move the reference in the bsf internal buffer

There's no need to allocate a new packet for it.
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent ed1f08bf
...@@ -35,45 +35,38 @@ typedef struct NoiseContext { ...@@ -35,45 +35,38 @@ typedef struct NoiseContext {
unsigned int state; unsigned int state;
} NoiseContext; } NoiseContext;
static int noise(AVBSFContext *ctx, AVPacket *out) static int noise(AVBSFContext *ctx, AVPacket *pkt)
{ {
NoiseContext *s = ctx->priv_data; NoiseContext *s = ctx->priv_data;
AVPacket *in;
int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1); int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1);
int i, ret = 0; int i, ret = 0;
if (amount <= 0) if (amount <= 0)
return AVERROR(EINVAL); return AVERROR(EINVAL);
ret = ff_bsf_get_packet(ctx, &in); ret = ff_bsf_get_packet_ref(ctx, pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (s->dropamount > 0 && s->state % s->dropamount == 0) { if (s->dropamount > 0 && s->state % s->dropamount == 0) {
s->state++; s->state++;
av_packet_free(&in); av_packet_unref(pkt);
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }
ret = av_new_packet(out, in->size); ret = av_packet_make_writable(pkt);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
ret = av_packet_copy_props(out, in); for (i = 0; i < pkt->size; i++) {
if (ret < 0) s->state += pkt->data[i] + 1;
goto fail;
memcpy(out->data, in->data, in->size);
for (i = 0; i < out->size; i++) {
s->state += out->data[i] + 1;
if (s->state % amount == 0) if (s->state % amount == 0)
out->data[i] = s->state; pkt->data[i] = s->state;
} }
fail: fail:
if (ret < 0) if (ret < 0)
av_packet_unref(out); av_packet_unref(pkt);
av_packet_free(&in);
return ret; return ret;
} }
......
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