Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP
@ 2022-06-14  1:22 Fei Wang
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Fei Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Fei Wang @ 2022-06-14  1:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu Guangxin, Fei Wang

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) &&
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process
  2022-06-14  1:22 [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
@ 2022-06-14  1:23 ` Fei Wang
  2022-07-14  3:56   ` Xiang, Haihao
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs Fei Wang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Fei Wang @ 2022-06-14  1:23 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu Guangxin, Fei Wang

From: Xu Guangxin <guangxin.xu@intel.com>

We will generate a new frame for a missed reference. The frame can only
be used for reference. We assign an invalid decode sequence to it, so
it will not be involved in any dpb process.

Tested-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
---
 libavcodec/hevc_refs.c | 14 +++++++++++++-
 libavcodec/hevcdec.c   |  4 ++--
 libavcodec/hevcdec.h   |  3 +++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 3f8fe1ef18..89053fd1a2 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -172,6 +172,16 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
     return 0;
 }
 
+static void unref_missing_refs(HEVCContext *s)
+{
+    for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
+         HEVCFrame *frame = &s->DPB[i];
+         if (frame->sequence == HEVC_DECODE_SEQUENCE_INVALID) {
+             ff_hevc_unref_frame(s, frame, ~0);
+         }
+    }
+}
+
 int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
 {
     if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
@@ -418,7 +428,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
     }
 
     frame->poc      = poc;
-    frame->sequence = s->seq_decode;
+    frame->sequence = HEVC_DECODE_SEQUENCE_INVALID;
     frame->flags    = 0;
 
     if (s->threads_type == FF_THREAD_FRAME)
@@ -462,6 +472,8 @@ int ff_hevc_frame_rps(HEVCContext *s)
         return 0;
     }
 
+    unref_missing_refs(s);
+
     /* clear the reference flags on all frames except the current one */
     for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
         HEVCFrame *frame = &s->DPB[i];
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index f782ea6394..99785aa5d1 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -569,7 +569,7 @@ static int hls_slice_header(HEVCContext *s)
     }
 
     if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
-        s->seq_decode = (s->seq_decode + 1) & 0xff;
+        s->seq_decode = (s->seq_decode + 1) & HEVC_DECODE_SEQUENCE_MASK;
         s->max_ra     = INT_MAX;
         if (IS_IDR(s))
             ff_hevc_clear_refs(s);
@@ -614,7 +614,7 @@ static int hls_slice_header(HEVCContext *s)
             return pix_fmt;
         s->avctx->pix_fmt = pix_fmt;
 
-        s->seq_decode = (s->seq_decode + 1) & 0xff;
+        s->seq_decode = (s->seq_decode + 1) & HEVC_DECODE_SEQUENCE_MASK;
         s->max_ra     = INT_MAX;
     }
 
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index de861b88b3..9c8bcefb48 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -390,6 +390,9 @@ typedef struct DBParams {
 #define HEVC_FRAME_FLAG_LONG_REF  (1 << 2)
 #define HEVC_FRAME_FLAG_BUMPING   (1 << 3)
 
+#define HEVC_DECODE_SEQUENCE_MASK 0xff
+#define HEVC_DECODE_SEQUENCE_INVALID (HEVC_DECODE_SEQUENCE_MASK + 1)
+
 typedef struct HEVCFrame {
     AVFrame *frame;
     AVFrame *frame_grain;
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs
  2022-06-14  1:22 [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Fei Wang
@ 2022-06-14  1:23 ` Fei Wang
  2022-07-14  5:02   ` Xiang, Haihao
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag Fei Wang
  2022-07-14  8:58 ` [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Xiang, Haihao
  3 siblings, 1 reply; 9+ messages in thread
From: Fei Wang @ 2022-06-14  1:23 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu Guangxin, Fei Wang

From: Xu Guangxin <guangxin.xu@intel.com>

suppose
a. You have 3 frames, 0, 1, 4096.
b. The ltMask is 0xfff and use_msb is 0.
c. The 0, 1 are lt refs for 4096.
d. you are decoding frame 4096, and get the 0 frame.
Since 4096 & ltMask is 0 too, even you want get 0, find_ref_idx may give you 4096.
add_candidate_ref will report an error for this

Tested-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
---
 libavcodec/hevc_refs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 89053fd1a2..b3d5f96043 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -386,7 +386,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t 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 & mask) == poc)
+            if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc))
                 return ref;
         }
     }
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag
  2022-06-14  1:22 [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Fei Wang
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs Fei Wang
@ 2022-06-14  1:23 ` Fei Wang
  2022-07-14  6:16   ` Xiang, Haihao
  2022-07-14  8:58 ` [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Xiang, Haihao
  3 siblings, 1 reply; 9+ messages in thread
From: Fei Wang @ 2022-06-14  1:23 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu Guangxin, Fei Wang

From: Xu Guangxin <guangxin.xu@intel.com>

Even resolution or number of picture stores changes, we still need
follow no_output_of_prior_pics_flag in next IDR.

Tested-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
---
 libavcodec/hevcdec.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 99785aa5d1..b0317339a2 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -594,15 +594,8 @@ static int hls_slice_header(HEVCContext *s)
 
     if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) {
         const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data;
-        const HEVCSPS *last_sps = s->ps.sps;
         enum AVPixelFormat pix_fmt;
 
-        if (last_sps && IS_IRAP(s) && s->nal_unit_type != HEVC_NAL_CRA_NUT) {
-            if (sps->width != last_sps->width || sps->height != last_sps->height ||
-                sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering !=
-                last_sps->temporal_layer[last_sps->max_sub_layers - 1].max_dec_pic_buffering)
-                sh->no_output_of_prior_pics_flag = 0;
-        }
         ff_hevc_clear_refs(s);
 
         ret = set_sps(s, sps, sps->pix_fmt);
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Fei Wang
@ 2022-07-14  3:56   ` Xiang, Haihao
  2022-07-15  5:08     ` Wang, Fei W
  0 siblings, 1 reply; 9+ messages in thread
From: Xiang, Haihao @ 2022-07-14  3:56 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu, Guangxin, Wang, Fei W

On Tue, 2022-06-14 at 09:23 +0800, Fei Wang wrote:
> From: Xu Guangxin <guangxin.xu@intel.com>
> 
> We will generate a new frame for a missed reference. The frame can only
> be used for reference. We assign an invalid decode sequence to it, so
> it will not be involved in any dpb process.
> 
> Tested-by: Fei Wang <fei.w.wang@intel.com>
> Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
> ---
>  libavcodec/hevc_refs.c | 14 +++++++++++++-
>  libavcodec/hevcdec.c   |  4 ++--
>  libavcodec/hevcdec.h   |  3 +++
>  3 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index 3f8fe1ef18..89053fd1a2 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -172,6 +172,16 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame,
> int poc)
>      return 0;
>  }
>  
> +static void unref_missing_refs(HEVCContext *s)
> +{
> +    for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> +         HEVCFrame *frame = &s->DPB[i];
> +         if (frame->sequence == HEVC_DECODE_SEQUENCE_INVALID) {
> +             ff_hevc_unref_frame(s, frame, ~0);
> +         }
> +    }
> +}
> +
>  int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
>  {
>      if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
> @@ -418,7 +428,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int
> poc)
>      }
>  
>      frame->poc      = poc;
> -    frame->sequence = s->seq_decode;
> +    frame->sequence = HEVC_DECODE_SEQUENCE_INVALID;
>      frame->flags    = 0;
>  
>      if (s->threads_type == FF_THREAD_FRAME)
> @@ -462,6 +472,8 @@ int ff_hevc_frame_rps(HEVCContext *s)
>          return 0;
>      }
>  
> +    unref_missing_refs(s);
> +
>      /* clear the reference flags on all frames except the current one */
>      for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
>          HEVCFrame *frame = &s->DPB[i];
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index f782ea6394..99785aa5d1 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -569,7 +569,7 @@ static int hls_slice_header(HEVCContext *s)
>      }
>  
>      if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
> -        s->seq_decode = (s->seq_decode + 1) & 0xff;
> +        s->seq_decode = (s->seq_decode + 1) & HEVC_DECODE_SEQUENCE_MASK;
>          s->max_ra     = INT_MAX;
>          if (IS_IDR(s))
>              ff_hevc_clear_refs(s);
> @@ -614,7 +614,7 @@ static int hls_slice_header(HEVCContext *s)
>              return pix_fmt;
>          s->avctx->pix_fmt = pix_fmt;
>  
> -        s->seq_decode = (s->seq_decode + 1) & 0xff;
> +        s->seq_decode = (s->seq_decode + 1) & HEVC_DECODE_SEQUENCE_MASK;

I see 0xff is used in other places, could you replace it with
HEVC_DECODE_SEQUENCE_MASK too ?

Thanks
Haihao


>          s->max_ra     = INT_MAX;
>      }
>  
> diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
> index de861b88b3..9c8bcefb48 100644
> --- a/libavcodec/hevcdec.h
> +++ b/libavcodec/hevcdec.h
> @@ -390,6 +390,9 @@ typedef struct DBParams {
>  #define HEVC_FRAME_FLAG_LONG_REF  (1 << 2)
>  #define HEVC_FRAME_FLAG_BUMPING   (1 << 3)
>  
> +#define HEVC_DECODE_SEQUENCE_MASK 0xff
> +#define HEVC_DECODE_SEQUENCE_INVALID (HEVC_DECODE_SEQUENCE_MASK + 1)
> +
>  typedef struct HEVCFrame {
>      AVFrame *frame;
>      AVFrame *frame_grain;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs Fei Wang
@ 2022-07-14  5:02   ` Xiang, Haihao
  0 siblings, 0 replies; 9+ messages in thread
From: Xiang, Haihao @ 2022-07-14  5:02 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu, Guangxin, Wang, Fei W

On Tue, 2022-06-14 at 09:23 +0800, Fei Wang wrote:
> From: Xu Guangxin <guangxin.xu@intel.com>
> 
> suppose
> a. You have 3 frames, 0, 1, 4096.
> b. The ltMask is 0xfff and use_msb is 0.
> c. The 0, 1 are lt refs for 4096.
> d. you are decoding frame 4096, and get the 0 frame.
> Since 4096 & ltMask is 0 too, even you want get 0, find_ref_idx may give you
> 4096.
> add_candidate_ref will report an error for this
> 
> Tested-by: Fei Wang <fei.w.wang@intel.com>
> Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
> ---
>  libavcodec/hevc_refs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index 89053fd1a2..b3d5f96043 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -386,7 +386,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc,
> uint8_t 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 & mask) == poc)
> +            if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc))
>                  return ref;
>          }
>      }

LGTM

-Haihao

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag Fei Wang
@ 2022-07-14  6:16   ` Xiang, Haihao
  0 siblings, 0 replies; 9+ messages in thread
From: Xiang, Haihao @ 2022-07-14  6:16 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu, Guangxin, Wang, Fei W

On Tue, 2022-06-14 at 09:23 +0800, Fei Wang wrote:
> From: Xu Guangxin <guangxin.xu@intel.com>
> 
> Even resolution or number of picture stores changes, we still need
> follow no_output_of_prior_pics_flag in next IDR.
> 
> Tested-by: Fei Wang <fei.w.wang@intel.com>
> Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
> ---
>  libavcodec/hevcdec.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index 99785aa5d1..b0317339a2 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -594,15 +594,8 @@ static int hls_slice_header(HEVCContext *s)
>  
>      if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) {
>          const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]-
> >data;
> -        const HEVCSPS *last_sps = s->ps.sps;
>          enum AVPixelFormat pix_fmt;
>  
> -        if (last_sps && IS_IRAP(s) && s->nal_unit_type != HEVC_NAL_CRA_NUT) {
> -            if (sps->width != last_sps->width || sps->height != last_sps-
> >height ||
> -                sps->temporal_layer[sps->max_sub_layers -
> 1].max_dec_pic_buffering !=
> -                last_sps->temporal_layer[last_sps->max_sub_layers -
> 1].max_dec_pic_buffering)
> -                sh->no_output_of_prior_pics_flag = 0;
> -        }
>          ff_hevc_clear_refs(s);
>  
>          ret = set_sps(s, sps, sps->pix_fmt);

From the context, sh->no_output_of_prior_pics_flag is NoOutputOfPriorPicsFlag in
the spec. According to C.5.2.2, the decoder may set NoOutputOfPriorPicsFlag to
no_output_of_prior_pics_flag or 1, but it is not allowed to set 0 in this case.

This patch LGTM.

Thanks
Haihao


_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP
  2022-06-14  1:22 [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
                   ` (2 preceding siblings ...)
  2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag Fei Wang
@ 2022-07-14  8:58 ` Xiang, Haihao
  3 siblings, 0 replies; 9+ messages in thread
From: Xiang, Haihao @ 2022-07-14  8:58 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Xu, Guangxin, Wang, Fei W

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process
  2022-07-14  3:56   ` Xiang, Haihao
@ 2022-07-15  5:08     ` Wang, Fei W
  0 siblings, 0 replies; 9+ messages in thread
From: Wang, Fei W @ 2022-07-15  5:08 UTC (permalink / raw)
  To: ffmpeg-devel, Xiang, Haihao; +Cc: Xu, Guangxin

On Thu, 2022-07-14 at 03:56 +0000, Xiang, Haihao wrote:
> On Tue, 2022-06-14 at 09:23 +0800, Fei Wang wrote:
> > From: Xu Guangxin <guangxin.xu@intel.com>
> > 
> > We will generate a new frame for a missed reference. The frame can
> > only
> > be used for reference. We assign an invalid decode sequence to it,
> > so
> > it will not be involved in any dpb process.
> > 
> > Tested-by: Fei Wang <fei.w.wang@intel.com>
> > Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
> > ---
> >  libavcodec/hevc_refs.c | 14 +++++++++++++-
> >  libavcodec/hevcdec.c   |  4 ++--
> >  libavcodec/hevcdec.h   |  3 +++
> >  3 files changed, 18 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> > index 3f8fe1ef18..89053fd1a2 100644
> > --- a/libavcodec/hevc_refs.c
> > +++ b/libavcodec/hevc_refs.c
> > @@ -172,6 +172,16 @@ int ff_hevc_set_new_ref(HEVCContext *s,
> > AVFrame **frame,
> > int poc)
> >      return 0;
> >  }
> >  
> > +static void unref_missing_refs(HEVCContext *s)
> > +{
> > +    for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> > +         HEVCFrame *frame = &s->DPB[i];
> > +         if (frame->sequence == HEVC_DECODE_SEQUENCE_INVALID) {
> > +             ff_hevc_unref_frame(s, frame, ~0);
> > +         }
> > +    }
> > +}
> > +
> >  int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
> >  {
> >      if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
> > @@ -418,7 +428,7 @@ static HEVCFrame
> > *generate_missing_ref(HEVCContext *s, int
> > poc)
> >      }
> >  
> >      frame->poc      = poc;
> > -    frame->sequence = s->seq_decode;
> > +    frame->sequence = HEVC_DECODE_SEQUENCE_INVALID;
> >      frame->flags    = 0;
> >  
> >      if (s->threads_type == FF_THREAD_FRAME)
> > @@ -462,6 +472,8 @@ int ff_hevc_frame_rps(HEVCContext *s)
> >          return 0;
> >      }
> >  
> > +    unref_missing_refs(s);
> > +
> >      /* clear the reference flags on all frames except the current
> > one */
> >      for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> >          HEVCFrame *frame = &s->DPB[i];
> > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> > index f782ea6394..99785aa5d1 100644
> > --- a/libavcodec/hevcdec.c
> > +++ b/libavcodec/hevcdec.c
> > @@ -569,7 +569,7 @@ static int hls_slice_header(HEVCContext *s)
> >      }
> >  
> >      if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
> > -        s->seq_decode = (s->seq_decode + 1) & 0xff;
> > +        s->seq_decode = (s->seq_decode + 1) &
> > HEVC_DECODE_SEQUENCE_MASK;
> >          s->max_ra     = INT_MAX;
> >          if (IS_IDR(s))
> >              ff_hevc_clear_refs(s);
> > @@ -614,7 +614,7 @@ static int hls_slice_header(HEVCContext *s)
> >              return pix_fmt;
> >          s->avctx->pix_fmt = pix_fmt;
> >  
> > -        s->seq_decode = (s->seq_decode + 1) & 0xff;
> > +        s->seq_decode = (s->seq_decode + 1) &
> > HEVC_DECODE_SEQUENCE_MASK;
> 
> I see 0xff is used in other places, could you replace it with
> HEVC_DECODE_SEQUENCE_MASK too ?

Fixed in V3. Thanks

Fei

> 
> Thanks
> Haihao
> 
> 
> >          s->max_ra     = INT_MAX;
> >      }
> >  
> > diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
> > index de861b88b3..9c8bcefb48 100644
> > --- a/libavcodec/hevcdec.h
> > +++ b/libavcodec/hevcdec.h
> > @@ -390,6 +390,9 @@ typedef struct DBParams {
> >  #define HEVC_FRAME_FLAG_LONG_REF  (1 << 2)
> >  #define HEVC_FRAME_FLAG_BUMPING   (1 << 3)
> >  
> > +#define HEVC_DECODE_SEQUENCE_MASK 0xff
> > +#define HEVC_DECODE_SEQUENCE_INVALID (HEVC_DECODE_SEQUENCE_MASK +
> > 1)
> > +
> >  typedef struct HEVCFrame {
> >      AVFrame *frame;
> >      AVFrame *frame_grain;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-15  5:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14  1:22 [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Fei Wang
2022-07-14  3:56   ` Xiang, Haihao
2022-07-15  5:08     ` Wang, Fei W
2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 3/4] lavc/hevc_refs: exclude current frame from long term refs Fei Wang
2022-07-14  5:02   ` Xiang, Haihao
2022-06-14  1:23 ` [FFmpeg-devel] [PATCH v2 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag Fei Wang
2022-07-14  6:16   ` Xiang, Haihao
2022-07-14  8:58 ` [FFmpeg-devel] [PATCH v2 1/4] lavc/hevc_refs: fix dpb logical for IRAP Xiang, Haihao

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git