diff mbox series

[FFmpeg-devel,v2,1/4] lavc/hevc_refs: fix dpb logical for IRAP

Message ID 20220614012302.2808428-1-fei.w.wang@intel.com
State New
Headers show
Series [FFmpeg-devel,v2,1/4] lavc/hevc_refs: fix dpb logical for IRAP | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Fei Wang June 14, 2022, 1:22 a.m. UTC
From: Xu Guangxin <guangxin.xu@intel.com>

According to C.5.2.2, item 2. When we got an IRAP, and the
NoOutputOfPriorPicsFlag = 0, we need bump all outputable frames.

Tested-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
---
Update:
1. fixed segment fault for some special clip in 2nd patch.

 libavcodec/hevc_refs.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Xiang, Haihao July 14, 2022, 8:58 a.m. UTC | #1
On Tue, 2022-06-14 at 09:22 +0800, Fei Wang wrote:
> From: Xu Guangxin <guangxin.xu@intel.com>
> 
> According to C.5.2.2, item 2. When we got an IRAP, and the
> NoOutputOfPriorPicsFlag = 0, we need bump all outputable frames.
> 
> Tested-by: Fei Wang <fei.w.wang@intel.com>
> Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
> ---
> Update:
> 1. fixed segment fault for some special clip in 2nd patch.
> 
>  libavcodec/hevc_refs.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index fe18ca2b1d..3f8fe1ef18 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -174,21 +174,24 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame,
> int poc)
>  
>  int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
>  {
> +    if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
> +        const static int mask = HEVC_FRAME_FLAG_BUMPING |
> HEVC_FRAME_FLAG_OUTPUT;
> +        for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> +            HEVCFrame *frame = &s->DPB[i];
> +            if ((frame->flags & mask) == HEVC_FRAME_FLAG_OUTPUT &&
> +                frame->sequence != s->seq_decode) {
> +                if (s->sh.no_output_of_prior_pics_flag == 1)
> +                    ff_hevc_unref_frame(s, frame, HEVC_FRAME_FLAG_OUTPUT);
> +                else
> +                    frame->flags |= HEVC_FRAME_FLAG_BUMPING;
> +            }
> +        }
> +    }
>      do {
>          int nb_output = 0;
>          int min_poc   = INT_MAX;
>          int i, min_idx, ret;
>  
> -        if (s->sh.no_output_of_prior_pics_flag == 1 && s->no_rasl_output_flag 
> == 1) {
> -            for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> -                HEVCFrame *frame = &s->DPB[i];
> -                if (!(frame->flags & HEVC_FRAME_FLAG_BUMPING) && frame->poc
> != s->poc &&
> -                        frame->sequence == s->seq_output) {
> -                    ff_hevc_unref_frame(s, frame, HEVC_FRAME_FLAG_OUTPUT);
> -                }
> -            }
> -        }
> -
>          for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
>              HEVCFrame *frame = &s->DPB[i];
>              if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) &&

LGTM

-Haihao
diff mbox series

Patch

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fe18ca2b1d..3f8fe1ef18 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -174,21 +174,24 @@  int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
 
 int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
 {
+    if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
+        const static int mask = HEVC_FRAME_FLAG_BUMPING | HEVC_FRAME_FLAG_OUTPUT;
+        for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
+            HEVCFrame *frame = &s->DPB[i];
+            if ((frame->flags & mask) == HEVC_FRAME_FLAG_OUTPUT &&
+                frame->sequence != s->seq_decode) {
+                if (s->sh.no_output_of_prior_pics_flag == 1)
+                    ff_hevc_unref_frame(s, frame, HEVC_FRAME_FLAG_OUTPUT);
+                else
+                    frame->flags |= HEVC_FRAME_FLAG_BUMPING;
+            }
+        }
+    }
     do {
         int nb_output = 0;
         int min_poc   = INT_MAX;
         int i, min_idx, ret;
 
-        if (s->sh.no_output_of_prior_pics_flag == 1 && s->no_rasl_output_flag == 1) {
-            for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
-                HEVCFrame *frame = &s->DPB[i];
-                if (!(frame->flags & HEVC_FRAME_FLAG_BUMPING) && frame->poc != s->poc &&
-                        frame->sequence == s->seq_output) {
-                    ff_hevc_unref_frame(s, frame, HEVC_FRAME_FLAG_OUTPUT);
-                }
-            }
-        }
-
         for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
             HEVCFrame *frame = &s->DPB[i];
             if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) &&