From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.142.180.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135250; b=JkGMRByl7dzD7TVPP5EE4LYbK4+0/FhsgHeJpZiOzSPAtPtSvsRy2CVaf4pSlSbcvSrQ R/NMhTsZiAA9r003sA4bJk65JGSFL+feT7DUz+8JeOOMpQ6cbDWgQvjhiG2Kbi0I7OuLf JAeI95U3Uqw3Qu4KlxC5LGaHEApIyvRnU6YAoWqjr1nuORiTx2EgAv0vxa4v55Ss+O3yL jaO1qRt/QrYPHfGeor1FBOtZ4tdlB4WQ/64jglP8yoQZAaEpLa2e/76VwyqB+4MbaTO01 H/8TCZWsRd+uWlHS3tv3woGO8J2pwwSgkIfgf1GOmkboWwP6eV9wvKYZzjFTNbx2FCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135250; h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=FUzgBSI5w4h85FKz54kLsr+2Zp2n3q6D6gYvpdogqYg=; b=5VknZlNn4d1y/Z0j18pqV7ERmt1XbSG7bb/d+XN633g/P+sa50jPAN/QBlP+DDoyhnxr hdOwToX2KNk3/oeBLco/fv8gWrNoWbas6JHvupbtZWwlNQjKSFbS4k/cHuSl/3/OpcO9i bh6fnKO8VGu8y6Wl5V07guokkISSWJ+Znsju5fNSybOfZcDDEGZn6NTvqOfHpXt3Rj2XA ZAWwd6cbI4xISG6eR+HtQeu/CR8IhfprfXusqylK1w/SZdinJFPcs0tiB6KGdxTCZgblx oAqfpur09OAViZr/hI9Ms77/oqdGetyLYDpCOvK4cjiRLPHWnCCuZhPLw+STz7aUYaw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.remote-ip=185.142.180.65 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F5BD606A687; Tue, 1 Dec 2026 14:27:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0F5BD606A687 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256:X25519MLKEM768) (Exim 4.100.1) (envelope-from ) id 1xYOpD-000000000x2-2xKE; Tue, 01 Dec 2026 14:27:19 +0000 Date: Tue, 1 Dec 2026 14:25:40 +0000 From: Daniel Golle To: Nicolas Dufresne , Paul Kocialkowski Cc: devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab , Hans Verkuil , Marco Felsch , Michael Tretter , Detlev Casanova Subject: Re: [PATCH 02/14] media: uapi: Add H.264 stateless encode support Message-ID: References: <20260522101653.2565125-1-paulk@sys-base.io> <20260522101653.2565125-3-paulk@sys-base.io> <1a1feaf854e6e1c34af468b7501988f2cf68ebca.camel@collabora.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1a1feaf854e6e1c34af468b7501988f2cf68ebca.camel@collabora.com> Hi Nicolas, Paul, Some input from a second encoder of a different vendor, as Paul asked for in the follow-ups thread. Two weeks ago I posted an RFC for the Rockchip RKVENC v1 encoder of the RV1126 ("vepu541") and RK3566/RK3568 ("vepu540") [1]. It is stateful for now, but its hardware back end takes a per-picture description without V4L2 types, so I went through this uAPI and the review with that hardware in mind. It is Rockchip's own IP, not a Hantro/Verisilicon derivative. What matters about the block here: - The driver writes SPS and PPS (and VPS for HEVC). The hardware writes the slice header and the slice data from registers. The H.264 slice header registers take nal_ref_idc, nal_unit_type, slice_type, pic_parameter_set_id, frame_num, idr_pic_id, pic_order_cnt_lsb, cabac_init_idc, disable_deblocking_filter_idc and the alpha/beta offsets, plus copies of the SPS/PPS fields the slice header syntax depends on (log2_max_frame_num_minus4, log2_max_pic_order_cnt_lsb_minus4, entropy_coding_mode_flag, transform_8x8_mode_flag, pic_init_qp, the chroma QP offsets, deblocking_filter_control_present_flag). For this class of hardware the slice header fields are register inputs to the driver, never bitstream the kernel writes itself. - It writes pic_order_cnt_type 0 slice headers (pic_order_cnt_lsb is a register field), so unlike the H1/VEPU1/VEPU2 case Arun described it does not need POC type 2. - One reconstructed picture is written and one reference is read per picture. My driver alternates two slots with sliding window marking, which is what this uAPI assumes today. I have not investigated long-term references on this block. - My driver codes one slice per picture. The block has slice split registers that I have not characterised. If the hardware splits slices by itself, first_mb_in_slice and the header fields of every slice after the first come from the hardware, so a per-slice array in the uAPI would have to allow "one entry, hardware decides". - The bitstream buffer has a start offset register, so the CPU can write the parameter sets at the head of the CAPTURE buffer and the hardware appends behind them. On 32-bit SoCs that matters: only the CAPTURE buffer needs a kernel mapping, OUTPUT frames are imported with DMA_ATTR_NO_KERNEL_MAPPING, and 4K streams fit the vmalloc space. - A bitstream buffer overflow raises its own interrupt and the picture can be encoded again. On your review points: > > + __u8 nal_ref_idc; > > This is fixed in this implementation, and will be derivable with > support for other reference model. I'd remove. Fine for RKVENC v1, as long as the core hands the derived value to the driver: it is a register field here. > > + __u8 slice_type; > > I think we should do like Vulkan here though. They split the frame > invariant (StdVideoEncodeH264PictureInfo) from the slice parameters > (StdVideoEncodeH264SliceHeader). The split works for this hardware too. It has a single set of slice header registers, so its driver would constrain the slice array to one entry through the state constrain callback of the core, or to "hardware split" once the slice split registers are understood. > > + __u8 colour_plane_id; > > I'm not aware of any HW capable of != 0 here, so I'd be keen on > dropping. RKVENC v1 has no separate colour plane coding either. One constraint for slice_qp_delta: for HEVC the slice QP in the header register has to equal the QP the picture is quantised with, so the core must not report a slice QP that differs from the QP it hands to the driver. Arun already noted that the encode params are published before rate control sets slice_qp_delta; with this hardware that mismatch would be visible in the bitstream. Resolution-dependent restrictions, which the state constrain callback or format negotiation has to be able to express: - H.264 P pictures are coded wrongly unless the picture is at least 3 macroblocks wide and 2 high (1x1 works); the driver codes those sizes as IDR only. - HEVC P pictures of a single 64-pixel CTU row decode wrongly. - H.264 pictures at most 2 macroblocks wide and more than 1 high hang the encoder and have to be refused. Rate control. Nicolas wrote in the VEPU510 thread that the in-kernel rate control is the part to share between interfaces. The RKVENC v1 driver has frame-level CBR in the kernel with the hardware row rate control off. It has run in RV1126 IP cameras streaming RTSP since October, and these are the lessons from that: 1. I and P pictures need one QP state. With separate I and P QP histories a static camera scene showed a once-per-second pulse: the P QP settled at 24-26 while the I QP stayed at 33-37. Deriving the I QP from the mean P QP of the previous GOP minus a fixed delta (4 for HEVC, 2 for H.264, the defaults of Rockchip's MPP library) removed it. Arun named the separate I and P QP histories as one cause of his VEPU2 results too. 2. A per-picture P QP step of 4 turned into a 32/36 limit cycle on skip-heavy pictures. A step of 1 with an exponentially smoothed P complexity removed it. 3. The I/P complexity ratio of static scenes is large: 37 measured at 720p. A clamp of 16 starved the I pictures; 64 works. 4. A bitstream overflow is a normal event, not a fault. CAPTURE buffers are sized well below the worst case (half the pixel count, for the vmalloc reason above), and a camera starting in the dark drives the QP down until the first bright picture overflows. The rate control needs the buffer size and has to re-encode the picture coarser. 5. Error reporting belongs in the spec. When an encode fails, the CAPTURE buffer comes back in the ERROR state with a payload of 0. GStreamer 1.28's V4L2 buffer pool treats an empty CAPTURE buffer from an M2M device as the legacy drain marker, ends the stream and posts no error, so the pipeline stops silently. The stateless encoder spec should state how a failed encode is reported and that only V4L2_BUF_FLAG_LAST marks the end of a drain. If any of this would be easier to discuss against code, the back end of [1] is in rkvenc-vepu541*.c and the rate control in rkvenc-rc.c. Cheers, Daniel [1] https://lore.kernel.org/all/cover.1794666330.git.daniel@makrotopia.org/