mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Paul Kocialkowski <paulk@sys-base.io>,
	 Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	 Hans Verkuil <hverkuil@kernel.org>,
	Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH RFC 01/10] media: hevc: Add H.265 syntax definitions
Date: Tue, 10 Nov 2026 10:07:31 +0000	[thread overview]
Message-ID: <20261110-hevc-encode-uapi-v1-1-38ae9fcfedd4@gmail.com> (raw)
In-Reply-To: <20261110-hevc-encode-uapi-v1-0-38ae9fcfedd4@gmail.com>

From: Arun Iyengar <aiyengar1990@gmail.com>

Add the ITU-T Rec. H.265 constants that a stateless HEVC encoder needs
to produce a bitstream: NAL unit type codes (Table 7-1), profile IDCs
(Annex A), access unit delimiter picture types (Table 7-2) and the VUI
colour description code points (Tables E.3 to E.5, shared with ITU-T
H.273).

Also add small helpers that classify NAL unit types (IRAP, IDR, BLA,
leading and sub-layer non-reference pictures), since the reference
picture set and picture order count rules depend on them.

These are kernel-internal definitions: the uAPI carries nal_unit_type as
the raw H.265 value, like the HEVC decoding controls already do.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 include/media/v4l2-hevc.h | 132 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 131 insertions(+), 1 deletion(-)

diff --git a/include/media/v4l2-hevc.h b/include/media/v4l2-hevc.h
index 973c96be16be..cc649b212a6d 100644
--- a/include/media/v4l2-hevc.h
+++ b/include/media/v4l2-hevc.h
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
- * Helper functions for HEVC stateless codecs.
+ * Helper functions and ITU-T Rec. H.265 syntax definitions for HEVC stateless
+ * codecs.
  */
 
 #ifndef _MEDIA_V4L2_HEVC_H
@@ -38,4 +39,133 @@ v4l2_hevc_pps_num_tile_rows(const struct v4l2_ctrl_hevc_pps *pps)
 		     ARRAY_SIZE(pps->row_height_minus1));
 }
 
+/* ITU-T Rec. H.265 Table 7-1: NAL unit type codes */
+#define V4L2_HEVC_NAL_TRAIL_N		0
+#define V4L2_HEVC_NAL_TRAIL_R		1
+#define V4L2_HEVC_NAL_TSA_N		2
+#define V4L2_HEVC_NAL_TSA_R		3
+#define V4L2_HEVC_NAL_STSA_N		4
+#define V4L2_HEVC_NAL_STSA_R		5
+#define V4L2_HEVC_NAL_RADL_N		6
+#define V4L2_HEVC_NAL_RADL_R		7
+#define V4L2_HEVC_NAL_RASL_N		8
+#define V4L2_HEVC_NAL_RASL_R		9
+#define V4L2_HEVC_NAL_RSV_VCL_N14	14
+#define V4L2_HEVC_NAL_BLA_W_LP		16
+#define V4L2_HEVC_NAL_BLA_W_RADL	17
+#define V4L2_HEVC_NAL_BLA_N_LP		18
+#define V4L2_HEVC_NAL_IDR_W_RADL	19
+#define V4L2_HEVC_NAL_IDR_N_LP		20
+#define V4L2_HEVC_NAL_CRA_NUT		21
+#define V4L2_HEVC_NAL_RSV_IRAP_VCL23	23
+#define V4L2_HEVC_NAL_VPS		32
+#define V4L2_HEVC_NAL_SPS		33
+#define V4L2_HEVC_NAL_PPS		34
+#define V4L2_HEVC_NAL_AUD		35
+#define V4L2_HEVC_NAL_EOS		36
+#define V4L2_HEVC_NAL_EOB		37
+#define V4L2_HEVC_NAL_FD		38
+#define V4L2_HEVC_NAL_PREFIX_SEI	39
+#define V4L2_HEVC_NAL_SUFFIX_SEI	40
+
+/* ITU-T Rec. H.265 Annex A: general_profile_idc */
+#define V4L2_HEVC_PROFILE_IDC_MAIN		1
+#define V4L2_HEVC_PROFILE_IDC_MAIN_10		2
+#define V4L2_HEVC_PROFILE_IDC_MAIN_STILL_PICTURE	3
+#define V4L2_HEVC_PROFILE_IDC_RANGE_EXTENSIONS	4
+
+/* ITU-T Rec. H.265 Table 7-2: pic_type in access unit delimiters */
+#define V4L2_HEVC_AUD_PIC_TYPE_I	0
+#define V4L2_HEVC_AUD_PIC_TYPE_PI	1
+#define V4L2_HEVC_AUD_PIC_TYPE_BPI	2
+
+/* ITU-T Rec. H.265 Table E.1: aspect_ratio_idc */
+#define V4L2_HEVC_VUI_ASPECT_RATIO_IDC_EXTENDED	255
+
+/* ITU-T Rec. H.265 Table E.2: video_format */
+#define V4L2_HEVC_VUI_VIDEO_FORMAT_UNSPECIFIED	5
+
+/* ITU-T Rec. H.265 Tables E.3 to E.5 (ITU-T H.273 code points) */
+#define V4L2_HEVC_VUI_COLOUR_BT709		1
+#define V4L2_HEVC_VUI_COLOUR_UNSPECIFIED	2
+#define V4L2_HEVC_VUI_COLOUR_BT470_SYSTEM_M	4
+#define V4L2_HEVC_VUI_COLOUR_BT470_SYSTEM_BG	5
+#define V4L2_HEVC_VUI_COLOUR_SMPTE170M		6
+#define V4L2_HEVC_VUI_COLOUR_SMPTE240M		7
+#define V4L2_HEVC_VUI_COLOUR_BT2020		9
+#define V4L2_HEVC_VUI_COLOUR_SMPTE431		11
+
+#define V4L2_HEVC_VUI_TRANSFER_BT709		1
+#define V4L2_HEVC_VUI_TRANSFER_UNSPECIFIED	2
+#define V4L2_HEVC_VUI_TRANSFER_SMPTE170M	6
+#define V4L2_HEVC_VUI_TRANSFER_SMPTE240M	7
+#define V4L2_HEVC_VUI_TRANSFER_LINEAR		8
+#define V4L2_HEVC_VUI_TRANSFER_SRGB		13
+#define V4L2_HEVC_VUI_TRANSFER_SMPTE2084	16
+
+#define V4L2_HEVC_VUI_MATRIX_BT709		1
+#define V4L2_HEVC_VUI_MATRIX_UNSPECIFIED	2
+#define V4L2_HEVC_VUI_MATRIX_BT470_SYSTEM_BG	5
+#define V4L2_HEVC_VUI_MATRIX_SMPTE170M		6
+#define V4L2_HEVC_VUI_MATRIX_SMPTE240M		7
+#define V4L2_HEVC_VUI_MATRIX_BT2020_NCL		9
+#define V4L2_HEVC_VUI_MATRIX_BT2020_CL		10
+
+/* Maximum number of temporal sub-layers (sps_max_sub_layers_minus1 + 1) */
+#define V4L2_HEVC_MAX_SUB_LAYERS	7
+
+/* Maximum number of pictures in a short-term RPS (7.4.8) */
+#define V4L2_HEVC_MAX_ST_RPS_PICS	16
+
+/* Maximum number of long-term pictures signalled in a slice header */
+#define V4L2_HEVC_MAX_LT_PICS		16
+
+static inline bool v4l2_hevc_nal_is_irap(unsigned int nal_unit_type)
+{
+	return nal_unit_type >= V4L2_HEVC_NAL_BLA_W_LP &&
+	       nal_unit_type <= V4L2_HEVC_NAL_RSV_IRAP_VCL23;
+}
+
+static inline bool v4l2_hevc_nal_is_idr(unsigned int nal_unit_type)
+{
+	return nal_unit_type == V4L2_HEVC_NAL_IDR_W_RADL ||
+	       nal_unit_type == V4L2_HEVC_NAL_IDR_N_LP;
+}
+
+static inline bool v4l2_hevc_nal_is_bla(unsigned int nal_unit_type)
+{
+	return nal_unit_type >= V4L2_HEVC_NAL_BLA_W_LP &&
+	       nal_unit_type <= V4L2_HEVC_NAL_BLA_N_LP;
+}
+
+/*
+ * Sub-layer non-reference picture (3.132): even nal_unit_type values in the
+ * VCL range below RSV_VCL_N14.
+ */
+static inline bool v4l2_hevc_nal_is_sub_layer_non_ref(unsigned int nal_unit_type)
+{
+	return nal_unit_type <= V4L2_HEVC_NAL_RSV_VCL_N14 &&
+	       !(nal_unit_type & 1);
+}
+
+static inline bool v4l2_hevc_nal_is_leading(unsigned int nal_unit_type)
+{
+	return nal_unit_type >= V4L2_HEVC_NAL_RADL_N &&
+	       nal_unit_type <= V4L2_HEVC_NAL_RASL_R;
+}
+
+static inline char v4l2_hevc_slice_type_char(unsigned char slice_type)
+{
+	switch (slice_type) {
+	case V4L2_HEVC_SLICE_TYPE_B:
+		return 'B';
+	case V4L2_HEVC_SLICE_TYPE_P:
+		return 'P';
+	case V4L2_HEVC_SLICE_TYPE_I:
+		return 'I';
+	default:
+		return 'X';
+	}
+}
+
 #endif /* _MEDIA_V4L2_HEVC_H */

-- 
2.55.0



  reply	other threads:[~2026-11-10 10:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 10:07 [PATCH RFC 00/10] media: Add a V4L2 HEVC stateless encode uAPI and helpers Arun Iyengar via B4 Relay
2026-11-10 10:07 ` Arun Iyengar via B4 Relay [this message]
2026-11-10 10:07 ` [PATCH RFC 02/10] media: uapi: Add HEVC stateless encode support Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 03/10] media: hevc: Add stateless encode RBSP writer Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 04/10] media: hevc: Add KUnit tests for the " Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 05/10] media: hevc: Add stateless encode core Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 06/10] media: hevc: Add KUnit tests for the " Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 07/10] media: v4l2-hevc-enc: Add a constant bitrate mode Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 08/10] media: v4l2-hevc-enc: Add QP limits for the I pictures Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 09/10] media: v4l2-hevc-enc: Re-encode oversized pictures Arun Iyengar via B4 Relay
2026-11-10 10:07 ` [PATCH RFC 10/10] media: docs: Document the HEVC stateless encode uAPI Arun Iyengar via B4 Relay

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=20261110-hevc-encode-uapi-v1-1-38ae9fcfedd4@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=paulk@sys-base.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®