diff mbox series

[FFmpeg-devel] hevc_refs: reduce code duplication in find_ref_idx()

Message ID 20200527084822.26247-1-anton@khirnov.net
State Accepted
Commit 2a9bed8fc152943870dc9c18832e3789730ff3ad
Headers show
Series [FFmpeg-devel] hevc_refs: reduce code duplication in find_ref_idx()
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Anton Khirnov May 27, 2020, 8:48 a.m. UTC
---
 libavcodec/hevc_refs.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

Comments

Fu, Linjie May 28, 2020, 3:17 a.m. UTC | #1
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Anton Khirnov
> Sent: Wednesday, May 27, 2020 16:48
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH] hevc_refs: reduce code duplication in
> find_ref_idx()
> 
> ---
>  libavcodec/hevc_refs.c | 22 ++++++----------------
>  1 file changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index 73aa6d8caf..4f6d985ae6 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -360,24 +360,14 @@ int ff_hevc_slice_rpl(HEVCContext *s)
> 
>  static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb)
>  {
> +    int mask = use_msb ? ~0 : (1 << s->ps.sps->log2_max_poc_lsb) - 1;
>      int i;
> 
> -    if (use_msb) {
> -        for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> -            HEVCFrame *ref = &s->DPB[i];
> -            if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) {
> -                if (ref->poc == poc)
> -                    return ref;
> -            }
> -        }
> -    } else {
> -        int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1;
> -        for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> -            HEVCFrame *ref = &s->DPB[i];
> -            if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
> -                if ((ref->poc & LtMask) == poc)
> -                    return ref;
> -            }
> +    for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> +        HEVCFrame *ref = &s->DPB[i];
> +        if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
> +            if ((ref->poc & mask) == poc)
> +                return ref;
>          }
>      }
> 
> --
Thanks for the refine, it's more precise now, lgtm.

- Linjie
diff mbox series

Patch

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 73aa6d8caf..4f6d985ae6 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -360,24 +360,14 @@  int ff_hevc_slice_rpl(HEVCContext *s)
 
 static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb)
 {
+    int mask = use_msb ? ~0 : (1 << s->ps.sps->log2_max_poc_lsb) - 1;
     int i;
 
-    if (use_msb) {
-        for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
-            HEVCFrame *ref = &s->DPB[i];
-            if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) {
-                if (ref->poc == poc)
-                    return ref;
-            }
-        }
-    } else {
-        int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1;
-        for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
-            HEVCFrame *ref = &s->DPB[i];
-            if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
-                if ((ref->poc & LtMask) == poc)
-                    return ref;
-            }
+    for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
+        HEVCFrame *ref = &s->DPB[i];
+        if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
+            if ((ref->poc & mask) == poc)
+                return ref;
         }
     }