diff mbox series

[FFmpeg-devel,3/6] avcodec/h264_refs: Rewrite code to make control flow clearer

Message ID GV1P250MB07371C0961019DBE2766185A8F342@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit ac14d682777a7f74cea1fdf42189c4c421eed664
Headers show
Series [FFmpeg-devel,1/6] avcodec/libvpxenc: Only search for side data when intending to use it | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt March 27, 2024, 1:38 a.m. UTC
While this change IMO makes the control flow clearer
for the human reader, it is especially important for
GCC: It erroneously believes that it is possible to
enter the SHORT2(UNUSED|LONG) cases without having
entered the preceding block that initializes pic,
frame_num, structure and j; it would emit -Wmaybe-uninitialized
warnings for these variables if they were not pseudo-
initialized with av_uninit(). This patch allows to remove
the latter.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h264_refs.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

Comments

Andreas Rheinhardt March 29, 2024, 8:25 p.m. UTC | #1
Andreas Rheinhardt:
> While this change IMO makes the control flow clearer
> for the human reader, it is especially important for
> GCC: It erroneously believes that it is possible to
> enter the SHORT2(UNUSED|LONG) cases without having
> entered the preceding block that initializes pic,
> frame_num, structure and j; it would emit -Wmaybe-uninitialized
> warnings for these variables if they were not pseudo-
> initialized with av_uninit(). This patch allows to remove
> the latter.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/h264_refs.c | 22 ++++++++++------------
>  1 file changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
> index 9bc7b20988..c2ba4b9b9e 100644
> --- a/libavcodec/h264_refs.c
> +++ b/libavcodec/h264_refs.c
> @@ -646,8 +646,9 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
>              av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode,
>                     h->mmco[i].short_pic_num, h->mmco[i].long_arg);
>  
> -        if (mmco[i].opcode == MMCO_SHORT2UNUSED ||
> -            mmco[i].opcode == MMCO_SHORT2LONG) {
> +        switch (mmco[i].opcode) {
> +        case MMCO_SHORT2UNUSED:
> +        case MMCO_SHORT2LONG:
>              frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure);
>              pic       = find_short(h, frame_num, &j);
>              if (!pic) {
> @@ -659,16 +660,12 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
>                  }
>                  continue;
>              }
> -        }
> -
> -        switch (mmco[i].opcode) {
> -        case MMCO_SHORT2UNUSED:
> -            if (h->avctx->debug & FF_DEBUG_MMCO)
> -                av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
> -                       h->mmco[i].short_pic_num, h->short_ref_count);
> -            remove_short(h, frame_num, structure ^ PICT_FRAME);
> -            break;
> -        case MMCO_SHORT2LONG:
> +            if (mmco[i].opcode == MMCO_SHORT2UNUSED) {
> +                if (h->avctx->debug & FF_DEBUG_MMCO)
> +                    av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
> +                           h->mmco[i].short_pic_num, h->short_ref_count);
> +                remove_short(h, frame_num, structure ^ PICT_FRAME);
> +            } else {
>                  if (h->long_ref[mmco[i].long_arg] != pic)
>                      remove_long(h, mmco[i].long_arg, 0);
>  
> @@ -678,6 +675,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
>                      h->long_ref[mmco[i].long_arg]->long_ref = 1;
>                      h->long_ref_count++;
>                  }
> +            }
>              break;
>          case MMCO_LONG2UNUSED:
>              j   = pic_num_extract(h, mmco[i].long_arg, &structure);

Will apply the rest of this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 9bc7b20988..c2ba4b9b9e 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -646,8 +646,9 @@  int ff_h264_execute_ref_pic_marking(H264Context *h)
             av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode,
                    h->mmco[i].short_pic_num, h->mmco[i].long_arg);
 
-        if (mmco[i].opcode == MMCO_SHORT2UNUSED ||
-            mmco[i].opcode == MMCO_SHORT2LONG) {
+        switch (mmco[i].opcode) {
+        case MMCO_SHORT2UNUSED:
+        case MMCO_SHORT2LONG:
             frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure);
             pic       = find_short(h, frame_num, &j);
             if (!pic) {
@@ -659,16 +660,12 @@  int ff_h264_execute_ref_pic_marking(H264Context *h)
                 }
                 continue;
             }
-        }
-
-        switch (mmco[i].opcode) {
-        case MMCO_SHORT2UNUSED:
-            if (h->avctx->debug & FF_DEBUG_MMCO)
-                av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
-                       h->mmco[i].short_pic_num, h->short_ref_count);
-            remove_short(h, frame_num, structure ^ PICT_FRAME);
-            break;
-        case MMCO_SHORT2LONG:
+            if (mmco[i].opcode == MMCO_SHORT2UNUSED) {
+                if (h->avctx->debug & FF_DEBUG_MMCO)
+                    av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
+                           h->mmco[i].short_pic_num, h->short_ref_count);
+                remove_short(h, frame_num, structure ^ PICT_FRAME);
+            } else {
                 if (h->long_ref[mmco[i].long_arg] != pic)
                     remove_long(h, mmco[i].long_arg, 0);
 
@@ -678,6 +675,7 @@  int ff_h264_execute_ref_pic_marking(H264Context *h)
                     h->long_ref[mmco[i].long_arg]->long_ref = 1;
                     h->long_ref_count++;
                 }
+            }
             break;
         case MMCO_LONG2UNUSED:
             j   = pic_num_extract(h, mmco[i].long_arg, &structure);