All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: kernel@collabora.com,
	Sebastian Fricke <sebastian.fricke@collabora.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 08/23] media: h264: Store all fields into the unordered list
Date: Thu, 31 Mar 2022 15:37:10 -0400	[thread overview]
Message-ID: <20220331193726.289559-9-nicolas.dufresne@collabora.com> (raw)
In-Reply-To: <20220331193726.289559-1-nicolas.dufresne@collabora.com>

When the current picture is a field, store each field into the
unordered_list and preserve both top and bottom picture order
count.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Sebastian Fricke <sebastian.fricke@collabora.com>
---
 drivers/media/v4l2-core/v4l2-h264.c | 65 +++++++++++++++++++++--------
 include/media/v4l2-h264.h           |  6 ++-
 2 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
index 58f18bb0afb6..38d8dbda0045 100644
--- a/drivers/media/v4l2-core/v4l2-h264.c
+++ b/drivers/media/v4l2-core/v4l2-h264.c
@@ -47,8 +47,6 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
 	}
 
 	for (i = 0; i < V4L2_H264_NUM_DPB_ENTRIES; i++) {
-		u32 pic_order_count;
-
 		if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))
 			continue;
 
@@ -59,8 +57,6 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
 		/*
 		 * Handle frame_num wraparound as described in section
 		 * '8.2.4.1 Decoding process for picture numbers' of the spec.
-		 * TODO: This logic will have to be adjusted when we start
-		 * supporting interlaced content.
 		 * For long term references, frame_num is set to
 		 * long_term_frame_idx which requires no wrapping.
 		 */
@@ -70,17 +66,33 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
 		else
 			b->refs[i].frame_num = dpb[i].frame_num;
 
-		if (dpb[i].fields == V4L2_H264_FRAME_REF)
-			pic_order_count = min(dpb[i].top_field_order_cnt,
-					      dpb[i].bottom_field_order_cnt);
-		else if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF)
-			pic_order_count = dpb[i].bottom_field_order_cnt;
-		else
-			pic_order_count = dpb[i].top_field_order_cnt;
+		b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt;
+		b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt;
+
+		if (b->cur_pic_fields == V4L2_H264_FRAME_REF) {
+			u8 fields = V4L2_H264_FRAME_REF;
+
+			b->unordered_reflist[b->num_valid].index = i;
+			b->unordered_reflist[b->num_valid].fields = fields;
+			b->num_valid++;
+			continue;
+		}
+
+		if (dpb[i].fields & V4L2_H264_TOP_FIELD_REF) {
+			u8 fields = V4L2_H264_TOP_FIELD_REF;
+
+			b->unordered_reflist[b->num_valid].index = i;
+			b->unordered_reflist[b->num_valid].fields = fields;
+			b->num_valid++;
+		}
 
-		b->refs[i].pic_order_count = pic_order_count;
-		b->unordered_reflist[b->num_valid].index = i;
-		b->num_valid++;
+		if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF) {
+			u8 fields = V4L2_H264_BOTTOM_FIELD_REF;
+
+			b->unordered_reflist[b->num_valid].index = i;
+			b->unordered_reflist[b->num_valid].fields = fields;
+			b->num_valid++;
+		}
 	}
 
 	for (i = b->num_valid; i < ARRAY_SIZE(b->unordered_reflist); i++)
@@ -88,6 +100,23 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
 }
 EXPORT_SYMBOL_GPL(v4l2_h264_init_reflist_builder);
 
+static s32 v4l2_h264_get_poc(const struct v4l2_h264_reflist_builder *b,
+			     const struct v4l2_h264_reference *ref)
+{
+	switch (ref->fields) {
+	case V4L2_H264_FRAME_REF:
+		return min(b->refs[ref->index].top_field_order_cnt,
+				b->refs[ref->index].bottom_field_order_cnt);
+	case V4L2_H264_TOP_FIELD_REF:
+		return b->refs[ref->index].top_field_order_cnt;
+	case V4L2_H264_BOTTOM_FIELD_REF:
+		return b->refs[ref->index].bottom_field_order_cnt;
+	}
+
+	/* not reached */
+	return 0;
+}
+
 static int v4l2_h264_p_ref_list_cmp(const void *ptra, const void *ptrb,
 				    const void *data)
 {
@@ -150,8 +179,8 @@ static int v4l2_h264_b0_ref_list_cmp(const void *ptra, const void *ptrb,
 		       builder->refs[idxb].pic_num ?
 		       -1 : 1;
 
-	poca = builder->refs[idxa].pic_order_count;
-	pocb = builder->refs[idxb].pic_order_count;
+	poca = v4l2_h264_get_poc(builder, ptra);
+	pocb = v4l2_h264_get_poc(builder, ptrb);
 
 	/*
 	 * Short term pics with POC < cur POC first in POC descending order
@@ -195,8 +224,8 @@ static int v4l2_h264_b1_ref_list_cmp(const void *ptra, const void *ptrb,
 		       builder->refs[idxb].pic_num ?
 		       -1 : 1;
 
-	poca = builder->refs[idxa].pic_order_count;
-	pocb = builder->refs[idxb].pic_order_count;
+	poca = v4l2_h264_get_poc(builder, ptra);
+	pocb = v4l2_h264_get_poc(builder, ptrb);
 
 	/*
 	 * Short term pics with POC > cur POC first in POC ascending order
diff --git a/include/media/v4l2-h264.h b/include/media/v4l2-h264.h
index e165a54c68fa..4cef717b3f18 100644
--- a/include/media/v4l2-h264.h
+++ b/include/media/v4l2-h264.h
@@ -15,7 +15,8 @@
 /**
  * struct v4l2_h264_reflist_builder - Reference list builder object
  *
- * @refs.pic_order_count: reference picture order count
+ * @refs.top_field_order_cnt: top field order count
+ * @refs.bottom_field_order_cnt: bottom field order count
  * @refs.frame_num: reference frame number
  * @refs.pic_num: reference picture number
  * @refs.longterm: set to true for a long term reference
@@ -32,7 +33,8 @@
  */
 struct v4l2_h264_reflist_builder {
 	struct {
-		s32 pic_order_count;
+		s32 top_field_order_cnt;
+		s32 bottom_field_order_cnt;
 		int frame_num;
 		u32 pic_num;
 		u16 longterm : 1;
-- 
2.34.1


  parent reply	other threads:[~2022-03-31 19:38 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 19:37 [PATCH v2 00/23] H.264 Field Decoding Support for Frame-based Decoders Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 01/23] media: doc: Document dual use of H.264 pic_num/frame_num Nicolas Dufresne
2022-03-31 20:02   ` [PATCH v2 00/23] H.264 Field Decoding Support for Frame-based Decoders Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 02/23] media: v4l2-mem2mem: Trace on implicit un-hold Nicolas Dufresne
2022-04-02 10:47   ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 03/23] media: videobuf2-v4l2: Warn on holding buffers without support Nicolas Dufresne
2022-04-02 10:52   ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 04/23] media: h264: Avoid wrapping long_term_frame_idx Nicolas Dufresne
2022-04-02 11:01   ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 05/23] media: h264: Use v4l2_h264_reference for reflist Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 06/23] media: h264: Increase reference lists size to 32 Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 12:03   ` Ezequiel Garcia
2022-04-02 12:03     ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 07/23] media: h264: Store current picture fields Nicolas Dufresne
2022-03-31 19:37 ` Nicolas Dufresne [this message]
2022-03-31 19:37 ` [PATCH v2 09/23] media: v4l2: Trace calculated p/b0/b1 initial reflist Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 10/23] media: h264: Sort p/b reflist using frame_num Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 11/23] media: v4l2: Reorder field reflist Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 12/23] media: rkvdec: Stop overclocking the decoder Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:05   ` Ezequiel Garcia
2022-04-02 11:05     ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 13/23] media: rkvdec: h264: Fix dpb_valid implementation Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:16   ` Ezequiel Garcia
2022-04-02 11:16     ` Ezequiel Garcia
2022-04-05 15:10     ` Nicolas Dufresne
2022-04-05 15:10       ` Nicolas Dufresne
2022-04-05 15:34       ` Ezequiel Garcia
2022-04-05 15:34         ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 14/23] media: rkvdec: h264: Fix bit depth wrap in pps packet Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:20   ` Ezequiel Garcia
2022-04-02 11:20     ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 15/23] media: rkvdec: h264: Validate and use pic width and height in mbs Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:32   ` Ezequiel Garcia
2022-04-02 11:32     ` Ezequiel Garcia
2022-04-05 15:44     ` Nicolas Dufresne
2022-04-05 15:44       ` Nicolas Dufresne
2022-04-05 16:04       ` Nicolas Dufresne
2022-04-05 16:04         ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 16/23] media: rkvdec: h264: Fix reference frame_num wrap for second field Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:33   ` Ezequiel Garcia
2022-04-02 11:33     ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 17/23] media: rkvdec: Enable capture buffer holding for H264 Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-04-02 11:35   ` Ezequiel Garcia
2022-04-02 11:35     ` Ezequiel Garcia
2022-03-31 19:37 ` [PATCH v2 18/23] media: rkvdec: Ensure decoded resolution fit coded resolution Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 19/23] media: rkvdec-h264: Add field decoding support Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 20/23] media: hantro: Enable HOLD_CAPTURE_BUF for H.264 Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 21/23] media: hantro: Stop using H.264 parameter pic_num Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 22/23] media: hantro: h264: Make dpb entry management more robust Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne
2022-03-31 19:37 ` [PATCH v2 23/23] media: hantro: Add H.264 field decoding support Nicolas Dufresne
2022-03-31 19:37   ` Nicolas Dufresne

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=20220331193726.289559-9-nicolas.dufresne@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sebastian.fricke@collabora.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.