diff mbox series

[FFmpeg-devel,36/50] avfilter/vf_mcdeint: use av_packet_alloc() to allocate packets

Message ID 20210204191005.48190-37-jamrial@gmail.com
State New
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer Feb. 4, 2021, 7:09 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/vf_mcdeint.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt Feb. 8, 2021, 7:16 p.m. UTC | #1
James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavfilter/vf_mcdeint.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c
> index bc7b3230d3..26baf94adb 100644
> --- a/libavfilter/vf_mcdeint.c
> +++ b/libavfilter/vf_mcdeint.c
> @@ -74,6 +74,7 @@ typedef struct MCDeintContext {
>      int mode;           ///< MCDeintMode
>      int parity;         ///< MCDeintParity
>      int qp;
> +    AVPacket *pkt;
>      AVCodecContext *enc_ctx;
>  } MCDeintContext;
>  
> @@ -112,6 +113,9 @@ static int config_props(AVFilterLink *inlink)
>          return AVERROR(EINVAL);
>      }
>  
> +    mcdeint->pkt = av_packet_alloc();
> +    if (!mcdeint->pkt)
> +        return AVERROR(ENOMEM);
>      mcdeint->enc_ctx = avcodec_alloc_context3(enc);
>      if (!mcdeint->enc_ctx)
>          return AVERROR(ENOMEM);
> @@ -154,6 +158,7 @@ static av_cold void uninit(AVFilterContext *ctx)
>  {
>      MCDeintContext *mcdeint = ctx->priv;
>  
> +    av_packet_free(&mcdeint->pkt);
>      avcodec_free_context(&mcdeint->enc_ctx);
>  }
>  
> @@ -173,7 +178,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
>      MCDeintContext *mcdeint = inlink->dst->priv;
>      AVFilterLink *outlink = inlink->dst->outputs[0];
>      AVFrame *outpic, *frame_dec;
> -    AVPacket pkt = {0};
> +    AVPacket *pkt = mcdeint->pkt;
>      int x, y, i, ret, got_frame = 0;
>  
>      outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
> @@ -184,9 +189,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
>      av_frame_copy_props(outpic, inpic);
>      inpic->quality = mcdeint->qp * FF_QP2LAMBDA;
>  
> -    av_init_packet(&pkt);
> +    av_packet_unref(pkt);

Unnecessary: The packet is clean at the beginning, because it will
always be uninitialized at the end.

>  
> -    ret = avcodec_encode_video2(mcdeint->enc_ctx, &pkt, inpic, &got_frame);
> +    ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame);
>      if (ret < 0)
>          goto end;
>  
> @@ -274,7 +279,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
>      mcdeint->parity ^= 1;
>  
>  end:
> -    av_packet_unref(&pkt);
> +    av_packet_unref(pkt);
>      av_frame_free(&inpic);
>      if (ret < 0) {
>          av_frame_free(&outpic);
>
diff mbox series

Patch

diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c
index bc7b3230d3..26baf94adb 100644
--- a/libavfilter/vf_mcdeint.c
+++ b/libavfilter/vf_mcdeint.c
@@ -74,6 +74,7 @@  typedef struct MCDeintContext {
     int mode;           ///< MCDeintMode
     int parity;         ///< MCDeintParity
     int qp;
+    AVPacket *pkt;
     AVCodecContext *enc_ctx;
 } MCDeintContext;
 
@@ -112,6 +113,9 @@  static int config_props(AVFilterLink *inlink)
         return AVERROR(EINVAL);
     }
 
+    mcdeint->pkt = av_packet_alloc();
+    if (!mcdeint->pkt)
+        return AVERROR(ENOMEM);
     mcdeint->enc_ctx = avcodec_alloc_context3(enc);
     if (!mcdeint->enc_ctx)
         return AVERROR(ENOMEM);
@@ -154,6 +158,7 @@  static av_cold void uninit(AVFilterContext *ctx)
 {
     MCDeintContext *mcdeint = ctx->priv;
 
+    av_packet_free(&mcdeint->pkt);
     avcodec_free_context(&mcdeint->enc_ctx);
 }
 
@@ -173,7 +178,7 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
     MCDeintContext *mcdeint = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFrame *outpic, *frame_dec;
-    AVPacket pkt = {0};
+    AVPacket *pkt = mcdeint->pkt;
     int x, y, i, ret, got_frame = 0;
 
     outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@@ -184,9 +189,9 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
     av_frame_copy_props(outpic, inpic);
     inpic->quality = mcdeint->qp * FF_QP2LAMBDA;
 
-    av_init_packet(&pkt);
+    av_packet_unref(pkt);
 
-    ret = avcodec_encode_video2(mcdeint->enc_ctx, &pkt, inpic, &got_frame);
+    ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame);
     if (ret < 0)
         goto end;
 
@@ -274,7 +279,7 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
     mcdeint->parity ^= 1;
 
 end:
-    av_packet_unref(&pkt);
+    av_packet_unref(pkt);
     av_frame_free(&inpic);
     if (ret < 0) {
         av_frame_free(&outpic);