[FFmpeg-devel,2/3] avformat/utils: Do not use "i" as a context pointer, "i" is normally the integer counter in loops

Submitted by Michael Niedermayer on Sept. 26, 2018, 10 p.m.

Details

Message ID 20180926220026.29751-2-michael@niedermayer.cc
State Accepted
Headers show

Commit Message

Michael Niedermayer Sept. 26, 2018, 10 p.m.
This avoids surprising developers. Its bad to surprise developers with
such unexpected things.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/utils.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

Comments

James Almer Sept. 26, 2018, 10:15 p.m.
On 9/26/2018 7:00 PM, Michael Niedermayer wrote:
> This avoids surprising developers. Its bad to surprise developers with
> such unexpected things.
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/utils.c | 42 +++++++++++++++++++++---------------------
>  1 file changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 7e5783c14c..c1835b1ab5 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3461,7 +3461,7 @@ static int extract_extradata_check(AVStream *st)
>  
>  static int extract_extradata_init(AVStream *st)
>  {
> -    AVStreamInternal *i = st->internal;
> +    AVStreamInternal *avsti = st->internal;

How about sti instead? AVStream is usually set as st.

>      const AVBitStreamFilter *f;
>      int ret;
>  
> @@ -3474,66 +3474,66 @@ static int extract_extradata_init(AVStream *st)
>      if (!ret)
>          goto finish;
>  
> -    i->extract_extradata.pkt = av_packet_alloc();
> -    if (!i->extract_extradata.pkt)
> +    avsti->extract_extradata.pkt = av_packet_alloc();
> +    if (!avsti->extract_extradata.pkt)
>          return AVERROR(ENOMEM);
>  
> -    ret = av_bsf_alloc(f, &i->extract_extradata.bsf);
> +    ret = av_bsf_alloc(f, &avsti->extract_extradata.bsf);
>      if (ret < 0)
>          goto fail;
>  
> -    ret = avcodec_parameters_copy(i->extract_extradata.bsf->par_in,
> +    ret = avcodec_parameters_copy(avsti->extract_extradata.bsf->par_in,
>                                    st->codecpar);
>      if (ret < 0)
>          goto fail;
>  
> -    i->extract_extradata.bsf->time_base_in = st->time_base;
> +    avsti->extract_extradata.bsf->time_base_in = st->time_base;
>  
> -    ret = av_bsf_init(i->extract_extradata.bsf);
> +    ret = av_bsf_init(avsti->extract_extradata.bsf);
>      if (ret < 0)
>          goto fail;
>  
>  finish:
> -    i->extract_extradata.inited = 1;
> +    avsti->extract_extradata.inited = 1;
>  
>      return 0;
>  fail:
> -    av_bsf_free(&i->extract_extradata.bsf);
> -    av_packet_free(&i->extract_extradata.pkt);
> +    av_bsf_free(&avsti->extract_extradata.bsf);
> +    av_packet_free(&avsti->extract_extradata.pkt);
>      return ret;
>  }
>  
>  static int extract_extradata(AVStream *st, AVPacket *pkt)
>  {
> -    AVStreamInternal *i = st->internal;
> +    AVStreamInternal *avsti = st->internal;
>      AVPacket *pkt_ref;
>      int ret;
>  
> -    if (!i->extract_extradata.inited) {
> +    if (!avsti->extract_extradata.inited) {
>          ret = extract_extradata_init(st);
>          if (ret < 0)
>              return ret;
>      }
>  
> -    if (i->extract_extradata.inited && !i->extract_extradata.bsf)
> +    if (avsti->extract_extradata.inited && !avsti->extract_extradata.bsf)
>          return 0;
>  
> -    pkt_ref = i->extract_extradata.pkt;
> +    pkt_ref = avsti->extract_extradata.pkt;
>      ret = av_packet_ref(pkt_ref, pkt);
>      if (ret < 0)
>          return ret;
>  
> -    ret = av_bsf_send_packet(i->extract_extradata.bsf, pkt_ref);
> +    ret = av_bsf_send_packet(avsti->extract_extradata.bsf, pkt_ref);
>      if (ret < 0) {
>          av_packet_unref(pkt_ref);
>          return ret;
>      }
>  
> -    while (ret >= 0 && !i->avctx->extradata) {
> +    while (ret >= 0 && !avsti->avctx->extradata) {
>          int extradata_size;
>          uint8_t *extradata;
>  
> -        ret = av_bsf_receive_packet(i->extract_extradata.bsf, pkt_ref);
> +        ret = av_bsf_receive_packet(avsti->extract_extradata.bsf, pkt_ref);
>          if (ret < 0) {
>              if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
>                  return ret;
> @@ -3544,13 +3544,13 @@ static int extract_extradata(AVStream *st, AVPacket *pkt)
>                                              &extradata_size);
>  
>          if (extradata) {
> -            i->avctx->extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
> -            if (!i->avctx->extradata) {
> +            avsti->avctx->extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
> +            if (!avsti->avctx->extradata) {
>                  av_packet_unref(pkt_ref);
>                  return AVERROR(ENOMEM);
>              }
> -            memcpy(i->avctx->extradata, extradata, extradata_size);
> -            i->avctx->extradata_size = extradata_size;
> +            memcpy(avsti->avctx->extradata, extradata, extradata_size);
> +            avsti->avctx->extradata_size = extradata_size;
>          }
>          av_packet_unref(pkt_ref);
>      }

This is going to make eventual merges a pain, but ok.
Carl Eugen Hoyos Sept. 26, 2018, 10:19 p.m.
2018-09-27 0:00 GMT+02:00, Michael Niedermayer <michael@niedermayer.cc>:
> This avoids surprising developers. Its bad to surprise developers with
> such unexpected things.

+1

Carl Eugen
Michael Niedermayer Oct. 6, 2018, 8:14 p.m.
On Wed, Sep 26, 2018 at 07:15:36PM -0300, James Almer wrote:
> On 9/26/2018 7:00 PM, Michael Niedermayer wrote:
> > This avoids surprising developers. Its bad to surprise developers with
> > such unexpected things.
> > 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/utils.c | 42 +++++++++++++++++++++---------------------
> >  1 file changed, 21 insertions(+), 21 deletions(-)
> > 
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index 7e5783c14c..c1835b1ab5 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -3461,7 +3461,7 @@ static int extract_extradata_check(AVStream *st)
> >  
> >  static int extract_extradata_init(AVStream *st)
> >  {
> > -    AVStreamInternal *i = st->internal;
> > +    AVStreamInternal *avsti = st->internal;
> 
> How about sti instead? AVStream is usually set as st.

good idea, will change it

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7e5783c14c..c1835b1ab5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3461,7 +3461,7 @@  static int extract_extradata_check(AVStream *st)
 
 static int extract_extradata_init(AVStream *st)
 {
-    AVStreamInternal *i = st->internal;
+    AVStreamInternal *avsti = st->internal;
     const AVBitStreamFilter *f;
     int ret;
 
@@ -3474,66 +3474,66 @@  static int extract_extradata_init(AVStream *st)
     if (!ret)
         goto finish;
 
-    i->extract_extradata.pkt = av_packet_alloc();
-    if (!i->extract_extradata.pkt)
+    avsti->extract_extradata.pkt = av_packet_alloc();
+    if (!avsti->extract_extradata.pkt)
         return AVERROR(ENOMEM);
 
-    ret = av_bsf_alloc(f, &i->extract_extradata.bsf);
+    ret = av_bsf_alloc(f, &avsti->extract_extradata.bsf);
     if (ret < 0)
         goto fail;
 
-    ret = avcodec_parameters_copy(i->extract_extradata.bsf->par_in,
+    ret = avcodec_parameters_copy(avsti->extract_extradata.bsf->par_in,
                                   st->codecpar);
     if (ret < 0)
         goto fail;
 
-    i->extract_extradata.bsf->time_base_in = st->time_base;
+    avsti->extract_extradata.bsf->time_base_in = st->time_base;
 
-    ret = av_bsf_init(i->extract_extradata.bsf);
+    ret = av_bsf_init(avsti->extract_extradata.bsf);
     if (ret < 0)
         goto fail;
 
 finish:
-    i->extract_extradata.inited = 1;
+    avsti->extract_extradata.inited = 1;
 
     return 0;
 fail:
-    av_bsf_free(&i->extract_extradata.bsf);
-    av_packet_free(&i->extract_extradata.pkt);
+    av_bsf_free(&avsti->extract_extradata.bsf);
+    av_packet_free(&avsti->extract_extradata.pkt);
     return ret;
 }
 
 static int extract_extradata(AVStream *st, AVPacket *pkt)
 {
-    AVStreamInternal *i = st->internal;
+    AVStreamInternal *avsti = st->internal;
     AVPacket *pkt_ref;
     int ret;
 
-    if (!i->extract_extradata.inited) {
+    if (!avsti->extract_extradata.inited) {
         ret = extract_extradata_init(st);
         if (ret < 0)
             return ret;
     }
 
-    if (i->extract_extradata.inited && !i->extract_extradata.bsf)
+    if (avsti->extract_extradata.inited && !avsti->extract_extradata.bsf)
         return 0;
 
-    pkt_ref = i->extract_extradata.pkt;
+    pkt_ref = avsti->extract_extradata.pkt;
     ret = av_packet_ref(pkt_ref, pkt);
     if (ret < 0)
         return ret;
 
-    ret = av_bsf_send_packet(i->extract_extradata.bsf, pkt_ref);
+    ret = av_bsf_send_packet(avsti->extract_extradata.bsf, pkt_ref);
     if (ret < 0) {
         av_packet_unref(pkt_ref);
         return ret;
     }
 
-    while (ret >= 0 && !i->avctx->extradata) {
+    while (ret >= 0 && !avsti->avctx->extradata) {
         int extradata_size;
         uint8_t *extradata;
 
-        ret = av_bsf_receive_packet(i->extract_extradata.bsf, pkt_ref);
+        ret = av_bsf_receive_packet(avsti->extract_extradata.bsf, pkt_ref);
         if (ret < 0) {
             if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
                 return ret;
@@ -3544,13 +3544,13 @@  static int extract_extradata(AVStream *st, AVPacket *pkt)
                                             &extradata_size);
 
         if (extradata) {
-            i->avctx->extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
-            if (!i->avctx->extradata) {
+            avsti->avctx->extradata = av_mallocz(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+            if (!avsti->avctx->extradata) {
                 av_packet_unref(pkt_ref);
                 return AVERROR(ENOMEM);
             }
-            memcpy(i->avctx->extradata, extradata, extradata_size);
-            i->avctx->extradata_size = extradata_size;
+            memcpy(avsti->avctx->extradata, extradata, extradata_size);
+            avsti->avctx->extradata_size = extradata_size;
         }
         av_packet_unref(pkt_ref);
     }