[WIP,RFC,22/26] pipeline: rpi: Prefer generic raw formats
diff mbox series

Message ID 20261023-b4-raw-model-v1-22-eadb9948901b@ideasonboard.com
State New
Headers show
Series
  • Support the new common raw sensor model
Related show

Commit Message

Jai Luthra Oct. 23, 2026, 10:58 a.m. UTC
Most sensors that support the new common raw sensor model advertise both
generic raw formats, and legacy bayer-specific formats.

Break the tie by preferring the generic formats by a smidge, as all the
Raspberry Pi drivers involved in the capture path (unicam, bcm2835-isp,
cfe and pisp) can work with the newer media bus codes.

Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com>
---
 src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 8453c8668542..081866aa68ab 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -964,6 +964,7 @@  V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bit
 
 	constexpr float penaltyAr = 1500.0;
 	constexpr float penaltyBitDepth = 500.0;
+	constexpr float penaltyNonGeneric = 1.0;
 
 	/* Calculate the closest/best mode from the user requested size. */
 	for (const auto &[mbusCode, sizes] : sensorFormats_) {
@@ -987,14 +988,19 @@  V4L2SubdeviceFormat CameraData::findBestFormat(const Size &req, unsigned int bit
 			/* Add any penalties... this is not an exact science! */
 			score += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth;
 
+			/* Break ties when sensor advertises both legacy and generic codes */
+			if (MediaBusFormatInfo::info(mbusCode).genericRaw == false)
+				score += penaltyNonGeneric;
+
 			if (score <= bestScore) {
 				bestScore = score;
 				bestFormat.code = mbusCode;
 				bestFormat.size = size;
 			}
 
-			LOG(RPI, Debug) << "Format: " << size
-					<< " fmt " << *format
+			LOG(RPI, Debug) << "Format: " << *format
+					<< "_" << utils::hex(mbusCode, 4)
+					<< "_" << size
 					<< " Score: " << score
 					<< " (best " << bestScore << ")";
 		}