diff mbox series

[FFmpeg-devel] avcodec/mpegvideo_dec: Combine two loops

Message ID DB6PR0101MB221440D2DF6C088FE5970EA58F6D9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 02ad827226fcf7fd22793acc0a49ed17f099f1ef
Headers show
Series [FFmpeg-devel] avcodec/mpegvideo_dec: Combine two loops | 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 Aug. 18, 2022, 6:35 p.m. UTC
(I think the check for !reference is unnecessary.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo_dec.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 406c3feacf..5b37e79e36 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -279,12 +279,12 @@  int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
         ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
     }
 
-    /* release forgotten pictures */
-    /* if (MPEG-124 / H.263) */
+    /* release non reference/forgotten frames */
     for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
-        if (&s->picture[i] != s->last_picture_ptr &&
-            &s->picture[i] != s->next_picture_ptr &&
-            s->picture[i].reference && !s->picture[i].needs_realloc) {
+        if (!s->picture[i].reference ||
+            (&s->picture[i] != s->last_picture_ptr &&
+             &s->picture[i] != s->next_picture_ptr &&
+             !s->picture[i].needs_realloc)) {
             ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
         }
     }
@@ -293,12 +293,6 @@  int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
     ff_mpeg_unref_picture(s->avctx, &s->last_picture);
     ff_mpeg_unref_picture(s->avctx, &s->next_picture);
 
-    /* release non reference frames */
-    for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
-        if (!s->picture[i].reference)
-            ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
-    }
-
     if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
         // we already have an unused image
         // (maybe it was set before reading the header)