diff mbox

[FFmpeg-devel,v2] avcodec/noise_bsf: move the reference in the bsf internal buffer

Message ID 20180322015304.4476-1-jamrial@gmail.com
State Accepted
Commit dc99ee6b08e54de13b4c82ff265609b6ab83e3d8
Headers show

Commit Message

James Almer March 22, 2018, 1:53 a.m. UTC
There's no need to allocate a new packet for it.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Now using av_packet_make_writable() to make sure the packet can be
written to.

 libavcodec/noise_bsf.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer March 24, 2018, 1:24 a.m. UTC | #1
On Wed, Mar 21, 2018 at 10:53:04PM -0300, James Almer wrote:
> There's no need to allocate a new packet for it.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Now using av_packet_make_writable() to make sure the packet can be
> written to.
> 
>  libavcodec/noise_bsf.c | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)

should be ok

thx

[...]
James Almer March 24, 2018, 1:29 a.m. UTC | #2
On 3/23/2018 10:24 PM, Michael Niedermayer wrote:
> On Wed, Mar 21, 2018 at 10:53:04PM -0300, James Almer wrote:
>> There's no need to allocate a new packet for it.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> Now using av_packet_make_writable() to make sure the packet can be
>> written to.
>>
>>  libavcodec/noise_bsf.c | 25 +++++++++----------------
>>  1 file changed, 9 insertions(+), 16 deletions(-)
> 
> should be ok
> 
> thx

Pushed, thanks.
diff mbox

Patch

diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
index 6bb89507fc..d79f63b777 100644
--- a/libavcodec/noise_bsf.c
+++ b/libavcodec/noise_bsf.c
@@ -35,45 +35,38 @@  typedef struct NoiseContext {
     unsigned int state;
 } NoiseContext;
 
-static int noise(AVBSFContext *ctx, AVPacket *out)
+static int noise(AVBSFContext *ctx, AVPacket *pkt)
 {
     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)
         return AVERROR(EINVAL);
 
-    ret = ff_bsf_get_packet(ctx, &in);
+    ret = ff_bsf_get_packet_ref(ctx, pkt);
     if (ret < 0)
         return ret;
 
     if (s->dropamount > 0 && s->state % s->dropamount == 0) {
         s->state++;
-        av_packet_free(&in);
+        av_packet_unref(pkt);
         return AVERROR(EAGAIN);
     }
 
-    ret = av_new_packet(out, in->size);
+    ret = av_packet_make_writable(pkt);
     if (ret < 0)
         goto fail;
 
-    ret = av_packet_copy_props(out, in);
-    if (ret < 0)
-        goto fail;
-
-    memcpy(out->data, in->data, in->size);
-
-    for (i = 0; i < out->size; i++) {
-        s->state += out->data[i] + 1;
+    for (i = 0; i < pkt->size; i++) {
+        s->state += pkt->data[i] + 1;
         if (s->state % amount == 0)
-            out->data[i] = s->state;
+            pkt->data[i] = s->state;
     }
 fail:
     if (ret < 0)
-        av_packet_unref(out);
-    av_packet_free(&in);
+        av_packet_unref(pkt);
+
     return ret;
 }