diff mbox

[FFmpeg-devel,v1] avcodec/bsf: replace ctx->internal-> with in-> for better readability

Message ID 20191214150310.19734-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

Limin Wang Dec. 14, 2019, 3:03 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/bsf.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

Comments

Michael Niedermayer Dec. 15, 2019, 10:42 p.m. UTC | #1
On Sat, Dec 14, 2019 at 11:03:10PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/bsf.c | 31 +++++++++++++++++--------------
>  1 file changed, 17 insertions(+), 14 deletions(-)

sounds like a good idea

thx

[...]
James Almer Dec. 15, 2019, 10:49 p.m. UTC | #2
On 12/14/2019 12:03 PM, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/bsf.c | 31 +++++++++++++++++--------------
>  1 file changed, 17 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
> index c1653cd..a5a5a03 100644
> --- a/libavcodec/bsf.c
> +++ b/libavcodec/bsf.c
> @@ -175,9 +175,11 @@ int av_bsf_init(AVBSFContext *ctx)
>  
>  void av_bsf_flush(AVBSFContext *ctx)
>  {
> -    ctx->internal->eof = 0;
> +    AVBSFInternal *in = ctx->internal;

in is used as input in the context of bsfs, so maybe bsfi instead? It's
also more in line with names like avci for the internal field in
AVCodecContext.

> +
> +    in->eof = 0;
>  
> -    av_packet_unref(ctx->internal->buffer_pkt);
> +    av_packet_unref(in->buffer_pkt);
>  
>      if (ctx->filter->flush)
>          ctx->filter->flush(ctx);
> @@ -185,26 +187,27 @@ void av_bsf_flush(AVBSFContext *ctx)
>  
>  int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
>  {
> +    AVBSFInternal *in = ctx->internal;
>      int ret;
>  
>      if (!pkt || (!pkt->data && !pkt->side_data_elems)) {
> -        ctx->internal->eof = 1;
> +        in->eof = 1;
>          return 0;
>      }
>  
> -    if (ctx->internal->eof) {
> +    if (in->eof) {
>          av_log(ctx, AV_LOG_ERROR, "A non-NULL packet sent after an EOF.\n");
>          return AVERROR(EINVAL);
>      }
>  
> -    if (ctx->internal->buffer_pkt->data ||
> -        ctx->internal->buffer_pkt->side_data_elems)
> +    if (in->buffer_pkt->data ||
> +        in->buffer_pkt->side_data_elems)
>          return AVERROR(EAGAIN);
>  
>      ret = av_packet_make_refcounted(pkt);
>      if (ret < 0)
>          return ret;
> -    av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
> +    av_packet_move_ref(in->buffer_pkt, pkt);
>  
>      return 0;
>  }
> @@ -222,16 +225,16 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
>      if (in->eof)
>          return AVERROR_EOF;
>  
> -    if (!ctx->internal->buffer_pkt->data &&
> -        !ctx->internal->buffer_pkt->side_data_elems)
> +    if (!in->buffer_pkt->data &&
> +        !in->buffer_pkt->side_data_elems)
>          return AVERROR(EAGAIN);
>  
>      tmp_pkt = av_packet_alloc();
>      if (!tmp_pkt)
>          return AVERROR(ENOMEM);
>  
> -    *pkt = ctx->internal->buffer_pkt;
> -    ctx->internal->buffer_pkt = tmp_pkt;
> +    *pkt = in->buffer_pkt;
> +    in->buffer_pkt = tmp_pkt;
>  
>      return 0;
>  }
> @@ -243,11 +246,11 @@ int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
>      if (in->eof)
>          return AVERROR_EOF;
>  
> -    if (!ctx->internal->buffer_pkt->data &&
> -        !ctx->internal->buffer_pkt->side_data_elems)
> +    if (!in->buffer_pkt->data &&
> +        !in->buffer_pkt->side_data_elems)
>          return AVERROR(EAGAIN);
>  
> -    av_packet_move_ref(pkt, ctx->internal->buffer_pkt);
> +    av_packet_move_ref(pkt, in->buffer_pkt);
>  
>      return 0;
>  }
>
Limin Wang Dec. 16, 2019, 1 a.m. UTC | #3
On Sun, Dec 15, 2019 at 07:49:41PM -0300, James Almer wrote:
> On 12/14/2019 12:03 PM, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavcodec/bsf.c | 31 +++++++++++++++++--------------
> >  1 file changed, 17 insertions(+), 14 deletions(-)
> > 
> > diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
> > index c1653cd..a5a5a03 100644
> > --- a/libavcodec/bsf.c
> > +++ b/libavcodec/bsf.c
> > @@ -175,9 +175,11 @@ int av_bsf_init(AVBSFContext *ctx)
> >  
> >  void av_bsf_flush(AVBSFContext *ctx)
> >  {
> > -    ctx->internal->eof = 0;
> > +    AVBSFInternal *in = ctx->internal;
> 
> in is used as input in the context of bsfs, so maybe bsfi instead? It's
> also more in line with names like avci for the internal field in
> AVCodecContext.

yes, for two following function have using in, so I follow the same style, 
it's preferalbe to use bsfi. I'll update the patch to change in to bsfi soon.

> 
> > +
> > +    in->eof = 0;
> >  
> > -    av_packet_unref(ctx->internal->buffer_pkt);
> > +    av_packet_unref(in->buffer_pkt);
> >  
> >      if (ctx->filter->flush)
> >          ctx->filter->flush(ctx);
> > @@ -185,26 +187,27 @@ void av_bsf_flush(AVBSFContext *ctx)
> >  
> >  int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
> >  {
> > +    AVBSFInternal *in = ctx->internal;
> >      int ret;
> >  
> >      if (!pkt || (!pkt->data && !pkt->side_data_elems)) {
> > -        ctx->internal->eof = 1;
> > +        in->eof = 1;
> >          return 0;
> >      }
> >  
> > -    if (ctx->internal->eof) {
> > +    if (in->eof) {
> >          av_log(ctx, AV_LOG_ERROR, "A non-NULL packet sent after an EOF.\n");
> >          return AVERROR(EINVAL);
> >      }
> >  
> > -    if (ctx->internal->buffer_pkt->data ||
> > -        ctx->internal->buffer_pkt->side_data_elems)
> > +    if (in->buffer_pkt->data ||
> > +        in->buffer_pkt->side_data_elems)
> >          return AVERROR(EAGAIN);
> >  
> >      ret = av_packet_make_refcounted(pkt);
> >      if (ret < 0)
> >          return ret;
> > -    av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
> > +    av_packet_move_ref(in->buffer_pkt, pkt);
> >  
> >      return 0;
> >  }
> > @@ -222,16 +225,16 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
> >      if (in->eof)
> >          return AVERROR_EOF;
> >  
> > -    if (!ctx->internal->buffer_pkt->data &&
> > -        !ctx->internal->buffer_pkt->side_data_elems)
> > +    if (!in->buffer_pkt->data &&
> > +        !in->buffer_pkt->side_data_elems)
> >          return AVERROR(EAGAIN);
> >  
> >      tmp_pkt = av_packet_alloc();
> >      if (!tmp_pkt)
> >          return AVERROR(ENOMEM);
> >  
> > -    *pkt = ctx->internal->buffer_pkt;
> > -    ctx->internal->buffer_pkt = tmp_pkt;
> > +    *pkt = in->buffer_pkt;
> > +    in->buffer_pkt = tmp_pkt;
> >  
> >      return 0;
> >  }
> > @@ -243,11 +246,11 @@ int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
> >      if (in->eof)
> >          return AVERROR_EOF;
> >  
> > -    if (!ctx->internal->buffer_pkt->data &&
> > -        !ctx->internal->buffer_pkt->side_data_elems)
> > +    if (!in->buffer_pkt->data &&
> > +        !in->buffer_pkt->side_data_elems)
> >          return AVERROR(EAGAIN);
> >  
> > -    av_packet_move_ref(pkt, ctx->internal->buffer_pkt);
> > +    av_packet_move_ref(pkt, in->buffer_pkt);
> >  
> >      return 0;
> >  }
> > 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index c1653cd..a5a5a03 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -175,9 +175,11 @@  int av_bsf_init(AVBSFContext *ctx)
 
 void av_bsf_flush(AVBSFContext *ctx)
 {
-    ctx->internal->eof = 0;
+    AVBSFInternal *in = ctx->internal;
+
+    in->eof = 0;
 
-    av_packet_unref(ctx->internal->buffer_pkt);
+    av_packet_unref(in->buffer_pkt);
 
     if (ctx->filter->flush)
         ctx->filter->flush(ctx);
@@ -185,26 +187,27 @@  void av_bsf_flush(AVBSFContext *ctx)
 
 int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
 {
+    AVBSFInternal *in = ctx->internal;
     int ret;
 
     if (!pkt || (!pkt->data && !pkt->side_data_elems)) {
-        ctx->internal->eof = 1;
+        in->eof = 1;
         return 0;
     }
 
-    if (ctx->internal->eof) {
+    if (in->eof) {
         av_log(ctx, AV_LOG_ERROR, "A non-NULL packet sent after an EOF.\n");
         return AVERROR(EINVAL);
     }
 
-    if (ctx->internal->buffer_pkt->data ||
-        ctx->internal->buffer_pkt->side_data_elems)
+    if (in->buffer_pkt->data ||
+        in->buffer_pkt->side_data_elems)
         return AVERROR(EAGAIN);
 
     ret = av_packet_make_refcounted(pkt);
     if (ret < 0)
         return ret;
-    av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
+    av_packet_move_ref(in->buffer_pkt, pkt);
 
     return 0;
 }
@@ -222,16 +225,16 @@  int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
     if (in->eof)
         return AVERROR_EOF;
 
-    if (!ctx->internal->buffer_pkt->data &&
-        !ctx->internal->buffer_pkt->side_data_elems)
+    if (!in->buffer_pkt->data &&
+        !in->buffer_pkt->side_data_elems)
         return AVERROR(EAGAIN);
 
     tmp_pkt = av_packet_alloc();
     if (!tmp_pkt)
         return AVERROR(ENOMEM);
 
-    *pkt = ctx->internal->buffer_pkt;
-    ctx->internal->buffer_pkt = tmp_pkt;
+    *pkt = in->buffer_pkt;
+    in->buffer_pkt = tmp_pkt;
 
     return 0;
 }
@@ -243,11 +246,11 @@  int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
     if (in->eof)
         return AVERROR_EOF;
 
-    if (!ctx->internal->buffer_pkt->data &&
-        !ctx->internal->buffer_pkt->side_data_elems)
+    if (!in->buffer_pkt->data &&
+        !in->buffer_pkt->side_data_elems)
         return AVERROR(EAGAIN);
 
-    av_packet_move_ref(pkt, ctx->internal->buffer_pkt);
+    av_packet_move_ref(pkt, in->buffer_pkt);
 
     return 0;
 }