Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Fei Wang <fei.w.wang-at-intel.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Xu Guangxin <guangxin.xu@intel.com>, Fei Wang <fei.w.wang@intel.com>
Subject: [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process
Date: Tue,  7 Jun 2022 15:08:28 +0800
Message-ID: <20220607070830.2654218-2-fei.w.wang@intel.com> (raw)
In-Reply-To: <20220607070830.2654218-1-fei.w.wang@intel.com>

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 | 13 ++++++++++++-
 libavcodec/hevcdec.c   |  4 ++--
 libavcodec/hevcdec.h   |  3 +++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 3f8fe1ef18..3ea2fb6c0b 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -172,8 +172,19 @@ 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)
 {
+    unref_missing_refs(s);
     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++) {
@@ -418,7 +429,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)
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".

  reply	other threads:[~2022-06-07  7:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  7:08 [FFmpeg-devel] [PATCH v1 1/4] lavc/hevc_refs: fix dpb logical for IRAP Fei Wang
2022-06-07  7:08 ` Fei Wang [this message]
2022-06-07 12:06   ` [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process Michael Niedermayer
2022-06-09  5:34     ` Wang, Fei W
2022-06-09 14:04       ` Michael Niedermayer
2022-06-14  1:50         ` Wang, Fei W
2022-06-07  7:08 ` [FFmpeg-devel] [PATCH v1 3/4] lavc/hevc_refs: exclude current frame from long term refs Fei Wang
2022-06-07  7:08 ` [FFmpeg-devel] [PATCH v1 4/4] lavc/hevcdec: respect the value of no_output_of_prior_pics_flag Fei Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220607070830.2654218-2-fei.w.wang@intel.com \
    --to=fei.w.wang-at-intel.com@ffmpeg.org \
    --cc=fei.w.wang@intel.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=guangxin.xu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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