[v1,2/2] libcamera: camera_sensor: getFormat(): Use span
diff mbox series

Message ID 20250303193349.785692-2-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1,1/2] libcamera: camera_sensor: getControls(): Use span
Related show

Commit Message

Barnabás Pőcze March 3, 2025, 7:33 p.m. UTC
Do not force the caller to construct a vector.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/internal/camera_sensor.h    |  2 +-
 src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |  4 ++--
 src/libcamera/sensor/camera_sensor_legacy.cpp |  4 ++--
 src/libcamera/sensor/camera_sensor_raw.cpp    |  4 ++--
 test/camera-sensor.cpp                        | 11 +++++++----
 5 files changed, 14 insertions(+), 11 deletions(-)

Comments

Kieran Bingham July 21, 2025, 6:34 p.m. UTC | #1
Quoting Barnabás Pőcze (2025-03-03 19:33:49)
> Do not force the caller to construct a vector.
> 

As with Patch 1/2, a more comprehensive commit message might be nicer.

But I think these are reasonable, and CI is green.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/internal/camera_sensor.h    |  2 +-
>  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |  4 ++--
>  src/libcamera/sensor/camera_sensor_legacy.cpp |  4 ++--
>  src/libcamera/sensor/camera_sensor_raw.cpp    |  4 ++--
>  test/camera-sensor.cpp                        | 11 +++++++----
>  5 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> index 59a1604c5..f6ef4df17 100644
> --- a/include/libcamera/internal/camera_sensor.h
> +++ b/include/libcamera/internal/camera_sensor.h
> @@ -54,7 +54,7 @@ public:
>         virtual Size resolution() const = 0;
>  
>         virtual V4L2SubdeviceFormat
> -       getFormat(const std::vector<unsigned int> &mbusCodes,
> +       getFormat(Span<const unsigned int> mbusCodes,
>                   const Size &size, const Size maxSize = Size()) const = 0;
>         virtual int setFormat(V4L2SubdeviceFormat *format,
>                               Transform transform = Transform::Identity) = 0;
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> index eee5b09e2..ba702b454 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> @@ -339,7 +339,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
>                                             : cfg->size;
>  
>                 V4L2SubdeviceFormat sensorFormat =
> -                       sensor->getFormat({ mbusCode }, rawSize);
> +                       sensor->getFormat(std::array{ mbusCode }, rawSize);
>  
>                 if (sensorConfig &&
>                     sensorConfig->outputSize != sensorFormat.size)
> @@ -360,7 +360,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
>  
>                 uint32_t mbusCode = formatToMediaBus.at(rawFormat);
>                 V4L2SubdeviceFormat sensorFormat =
> -                       sensor->getFormat({ mbusCode }, sensorSize);
> +                       sensor->getFormat(std::array{ mbusCode }, sensorSize);
>  
>                 if (sensorFormat.size != sensorSize)
>                         return CameraConfiguration::Invalid;
> diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
> index 1eccca519..1b9b5c9a0 100644
> --- a/src/libcamera/sensor/camera_sensor_legacy.cpp
> +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
> @@ -73,7 +73,7 @@ public:
>         std::vector<Size> sizes(unsigned int mbusCode) const override;
>         Size resolution() const override;
>  
> -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
> +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
>                                       const Size &size,
>                                       const Size maxSize) const override;
>         int setFormat(V4L2SubdeviceFormat *format,
> @@ -699,7 +699,7 @@ Size CameraSensorLegacy::resolution() const
>  }
>  
>  V4L2SubdeviceFormat
> -CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
> +CameraSensorLegacy::getFormat(Span<const unsigned int> mbusCodes,
>                               const Size &size, Size maxSize) const
>  {
>         unsigned int desiredArea = size.width * size.height;
> diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp
> index c65ecbb86..7ac0f563d 100644
> --- a/src/libcamera/sensor/camera_sensor_raw.cpp
> +++ b/src/libcamera/sensor/camera_sensor_raw.cpp
> @@ -74,7 +74,7 @@ public:
>         std::vector<Size> sizes(unsigned int mbusCode) const override;
>         Size resolution() const override;
>  
> -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
> +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
>                                       const Size &size,
>                                       const Size maxSize) const override;
>         int setFormat(V4L2SubdeviceFormat *format,
> @@ -757,7 +757,7 @@ Size CameraSensorRaw::resolution() const
>  }
>  
>  V4L2SubdeviceFormat
> -CameraSensorRaw::getFormat(const std::vector<unsigned int> &mbusCodes,
> +CameraSensorRaw::getFormat(Span<const unsigned int> mbusCodes,
>                            const Size &size, Size maxSize) const
>  {
>         unsigned int desiredArea = size.width * size.height;
> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
> index 869c78896..c30a2212e 100644
> --- a/test/camera-sensor.cpp
> +++ b/test/camera-sensor.cpp
> @@ -96,10 +96,13 @@ protected:
>                 }
>  
>                 /* Use an invalid format and make sure it's not selected. */
> -               V4L2SubdeviceFormat format = sensor_->getFormat({ 0xdeadbeef,
> -                                                                 MEDIA_BUS_FMT_SBGGR10_1X10,
> -                                                                 MEDIA_BUS_FMT_BGR888_1X24 },
> -                                                               Size(1024, 768));
> +               static constexpr uint32_t mbusCodes[] = {
> +                       0xdeadbeef,
> +                       MEDIA_BUS_FMT_SBGGR10_1X10,
> +                       MEDIA_BUS_FMT_BGR888_1X24,
> +               };
> +
> +               V4L2SubdeviceFormat format = sensor_->getFormat(mbusCodes, Size(1024, 768));
>                 if (format.code != MEDIA_BUS_FMT_SBGGR10_1X10 ||
>                     format.size != Size(4096, 2160)) {
>                         cerr << "Failed to get a suitable format, expected 4096x2160-0x"
> -- 
> 2.48.1
>
Laurent Pinchart July 24, 2025, 12:19 p.m. UTC | #2
On Mon, Jul 21, 2025 at 07:34:15PM +0100, Kieran Bingham wrote:
> Quoting Barnabás Pőcze (2025-03-03 19:33:49)
> > Do not force the caller to construct a vector.
> 
> As with Patch 1/2, a more comprehensive commit message might be nicer.
> 
> But I think these are reasonable, and CI is green.
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> > ---
> >  include/libcamera/internal/camera_sensor.h    |  2 +-
> >  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |  4 ++--
> >  src/libcamera/sensor/camera_sensor_legacy.cpp |  4 ++--
> >  src/libcamera/sensor/camera_sensor_raw.cpp    |  4 ++--
> >  test/camera-sensor.cpp                        | 11 +++++++----
> >  5 files changed, 14 insertions(+), 11 deletions(-)
> > 
> > diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
> > index 59a1604c5..f6ef4df17 100644
> > --- a/include/libcamera/internal/camera_sensor.h
> > +++ b/include/libcamera/internal/camera_sensor.h
> > @@ -54,7 +54,7 @@ public:
> >         virtual Size resolution() const = 0;
> >  
> >         virtual V4L2SubdeviceFormat
> > -       getFormat(const std::vector<unsigned int> &mbusCodes,
> > +       getFormat(Span<const unsigned int> mbusCodes,

Please include span.h.

> >                   const Size &size, const Size maxSize = Size()) const = 0;
> >         virtual int setFormat(V4L2SubdeviceFormat *format,
> >                               Transform transform = Transform::Identity) = 0;
> > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> > index eee5b09e2..ba702b454 100644
> > --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> > +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
> > @@ -339,7 +339,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
> >                                             : cfg->size;
> >  
> >                 V4L2SubdeviceFormat sensorFormat =
> > -                       sensor->getFormat({ mbusCode }, rawSize);
> > +                       sensor->getFormat(std::array{ mbusCode }, rawSize);

You should then include <array>.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> >  
> >                 if (sensorConfig &&
> >                     sensorConfig->outputSize != sensorFormat.size)
> > @@ -360,7 +360,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
> >  
> >                 uint32_t mbusCode = formatToMediaBus.at(rawFormat);
> >                 V4L2SubdeviceFormat sensorFormat =
> > -                       sensor->getFormat({ mbusCode }, sensorSize);
> > +                       sensor->getFormat(std::array{ mbusCode }, sensorSize);
> >  
> >                 if (sensorFormat.size != sensorSize)
> >                         return CameraConfiguration::Invalid;
> > diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
> > index 1eccca519..1b9b5c9a0 100644
> > --- a/src/libcamera/sensor/camera_sensor_legacy.cpp
> > +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
> > @@ -73,7 +73,7 @@ public:
> >         std::vector<Size> sizes(unsigned int mbusCode) const override;
> >         Size resolution() const override;
> >  
> > -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
> > +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
> >                                       const Size &size,
> >                                       const Size maxSize) const override;
> >         int setFormat(V4L2SubdeviceFormat *format,
> > @@ -699,7 +699,7 @@ Size CameraSensorLegacy::resolution() const
> >  }
> >  
> >  V4L2SubdeviceFormat
> > -CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
> > +CameraSensorLegacy::getFormat(Span<const unsigned int> mbusCodes,
> >                               const Size &size, Size maxSize) const
> >  {
> >         unsigned int desiredArea = size.width * size.height;
> > diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp
> > index c65ecbb86..7ac0f563d 100644
> > --- a/src/libcamera/sensor/camera_sensor_raw.cpp
> > +++ b/src/libcamera/sensor/camera_sensor_raw.cpp
> > @@ -74,7 +74,7 @@ public:
> >         std::vector<Size> sizes(unsigned int mbusCode) const override;
> >         Size resolution() const override;
> >  
> > -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
> > +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
> >                                       const Size &size,
> >                                       const Size maxSize) const override;
> >         int setFormat(V4L2SubdeviceFormat *format,
> > @@ -757,7 +757,7 @@ Size CameraSensorRaw::resolution() const
> >  }
> >  
> >  V4L2SubdeviceFormat
> > -CameraSensorRaw::getFormat(const std::vector<unsigned int> &mbusCodes,
> > +CameraSensorRaw::getFormat(Span<const unsigned int> mbusCodes,
> >                            const Size &size, Size maxSize) const
> >  {
> >         unsigned int desiredArea = size.width * size.height;
> > diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
> > index 869c78896..c30a2212e 100644
> > --- a/test/camera-sensor.cpp
> > +++ b/test/camera-sensor.cpp
> > @@ -96,10 +96,13 @@ protected:
> >                 }
> >  
> >                 /* Use an invalid format and make sure it's not selected. */
> > -               V4L2SubdeviceFormat format = sensor_->getFormat({ 0xdeadbeef,
> > -                                                                 MEDIA_BUS_FMT_SBGGR10_1X10,
> > -                                                                 MEDIA_BUS_FMT_BGR888_1X24 },
> > -                                                               Size(1024, 768));
> > +               static constexpr uint32_t mbusCodes[] = {
> > +                       0xdeadbeef,
> > +                       MEDIA_BUS_FMT_SBGGR10_1X10,
> > +                       MEDIA_BUS_FMT_BGR888_1X24,
> > +               };
> > +
> > +               V4L2SubdeviceFormat format = sensor_->getFormat(mbusCodes, Size(1024, 768));
> >                 if (format.code != MEDIA_BUS_FMT_SBGGR10_1X10 ||
> >                     format.size != Size(4096, 2160)) {
> >                         cerr << "Failed to get a suitable format, expected 4096x2160-0x"
Barnabás Pőcze July 27, 2025, 6:09 p.m. UTC | #3
Hi

2025. 07. 24. 14:19 keltezéssel, Laurent Pinchart írta:
> On Mon, Jul 21, 2025 at 07:34:15PM +0100, Kieran Bingham wrote:
>> Quoting Barnabás Pőcze (2025-03-03 19:33:49)
>>> Do not force the caller to construct a vector.
>>
>> As with Patch 1/2, a more comprehensive commit message might be nicer.
>>
>> But I think these are reasonable, and CI is green.
>>
>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>>> ---
>>>   include/libcamera/internal/camera_sensor.h    |  2 +-
>>>   src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |  4 ++--
>>>   src/libcamera/sensor/camera_sensor_legacy.cpp |  4 ++--
>>>   src/libcamera/sensor/camera_sensor_raw.cpp    |  4 ++--
>>>   test/camera-sensor.cpp                        | 11 +++++++----
>>>   5 files changed, 14 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
>>> index 59a1604c5..f6ef4df17 100644
>>> --- a/include/libcamera/internal/camera_sensor.h
>>> +++ b/include/libcamera/internal/camera_sensor.h
>>> @@ -54,7 +54,7 @@ public:
>>>          virtual Size resolution() const = 0;
>>>   
>>>          virtual V4L2SubdeviceFormat
>>> -       getFormat(const std::vector<unsigned int> &mbusCodes,
>>> +       getFormat(Span<const unsigned int> mbusCodes,
> 
> Please include span.h.

It is included by the previous patch.

> 
>>>                    const Size &size, const Size maxSize = Size()) const = 0;
>>>          virtual int setFormat(V4L2SubdeviceFormat *format,
>>>                                Transform transform = Transform::Identity) = 0;
>>> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
>>> index eee5b09e2..ba702b454 100644
>>> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
>>> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
>>> @@ -339,7 +339,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
>>>                                              : cfg->size;
>>>   
>>>                  V4L2SubdeviceFormat sensorFormat =
>>> -                       sensor->getFormat({ mbusCode }, rawSize);
>>> +                       sensor->getFormat(std::array{ mbusCode }, rawSize);
> 
> You should then include <array>.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
>>>   
>>>                  if (sensorConfig &&
>>>                      sensorConfig->outputSize != sensorFormat.size)
>>> @@ -360,7 +360,7 @@ RkISP1Path::validate(const CameraSensor *sensor,
>>>   
>>>                  uint32_t mbusCode = formatToMediaBus.at(rawFormat);
>>>                  V4L2SubdeviceFormat sensorFormat =
>>> -                       sensor->getFormat({ mbusCode }, sensorSize);
>>> +                       sensor->getFormat(std::array{ mbusCode }, sensorSize);
>>>   
>>>                  if (sensorFormat.size != sensorSize)
>>>                          return CameraConfiguration::Invalid;
>>> diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
>>> index 1eccca519..1b9b5c9a0 100644
>>> --- a/src/libcamera/sensor/camera_sensor_legacy.cpp
>>> +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
>>> @@ -73,7 +73,7 @@ public:
>>>          std::vector<Size> sizes(unsigned int mbusCode) const override;
>>>          Size resolution() const override;
>>>   
>>> -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
>>> +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
>>>                                        const Size &size,
>>>                                        const Size maxSize) const override;
>>>          int setFormat(V4L2SubdeviceFormat *format,
>>> @@ -699,7 +699,7 @@ Size CameraSensorLegacy::resolution() const
>>>   }
>>>   
>>>   V4L2SubdeviceFormat
>>> -CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
>>> +CameraSensorLegacy::getFormat(Span<const unsigned int> mbusCodes,
>>>                                const Size &size, Size maxSize) const
>>>   {
>>>          unsigned int desiredArea = size.width * size.height;
>>> diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp
>>> index c65ecbb86..7ac0f563d 100644
>>> --- a/src/libcamera/sensor/camera_sensor_raw.cpp
>>> +++ b/src/libcamera/sensor/camera_sensor_raw.cpp
>>> @@ -74,7 +74,7 @@ public:
>>>          std::vector<Size> sizes(unsigned int mbusCode) const override;
>>>          Size resolution() const override;
>>>   
>>> -       V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
>>> +       V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
>>>                                        const Size &size,
>>>                                        const Size maxSize) const override;
>>>          int setFormat(V4L2SubdeviceFormat *format,
>>> @@ -757,7 +757,7 @@ Size CameraSensorRaw::resolution() const
>>>   }
>>>   
>>>   V4L2SubdeviceFormat
>>> -CameraSensorRaw::getFormat(const std::vector<unsigned int> &mbusCodes,
>>> +CameraSensorRaw::getFormat(Span<const unsigned int> mbusCodes,
>>>                             const Size &size, Size maxSize) const
>>>   {
>>>          unsigned int desiredArea = size.width * size.height;
>>> diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
>>> index 869c78896..c30a2212e 100644
>>> --- a/test/camera-sensor.cpp
>>> +++ b/test/camera-sensor.cpp
>>> @@ -96,10 +96,13 @@ protected:
>>>                  }
>>>   
>>>                  /* Use an invalid format and make sure it's not selected. */
>>> -               V4L2SubdeviceFormat format = sensor_->getFormat({ 0xdeadbeef,
>>> -                                                                 MEDIA_BUS_FMT_SBGGR10_1X10,
>>> -                                                                 MEDIA_BUS_FMT_BGR888_1X24 },
>>> -                                                               Size(1024, 768));
>>> +               static constexpr uint32_t mbusCodes[] = {
>>> +                       0xdeadbeef,
>>> +                       MEDIA_BUS_FMT_SBGGR10_1X10,
>>> +                       MEDIA_BUS_FMT_BGR888_1X24,
>>> +               };
>>> +
>>> +               V4L2SubdeviceFormat format = sensor_->getFormat(mbusCodes, Size(1024, 768));
>>>                  if (format.code != MEDIA_BUS_FMT_SBGGR10_1X10 ||
>>>                      format.size != Size(4096, 2160)) {
>>>                          cerr << "Failed to get a suitable format, expected 4096x2160-0x"
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 59a1604c5..f6ef4df17 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -54,7 +54,7 @@  public:
 	virtual Size resolution() const = 0;
 
 	virtual V4L2SubdeviceFormat
-	getFormat(const std::vector<unsigned int> &mbusCodes,
+	getFormat(Span<const unsigned int> mbusCodes,
 		  const Size &size, const Size maxSize = Size()) const = 0;
 	virtual int setFormat(V4L2SubdeviceFormat *format,
 			      Transform transform = Transform::Identity) = 0;
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
index eee5b09e2..ba702b454 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
@@ -339,7 +339,7 @@  RkISP1Path::validate(const CameraSensor *sensor,
 					    : cfg->size;
 
 		V4L2SubdeviceFormat sensorFormat =
-			sensor->getFormat({ mbusCode }, rawSize);
+			sensor->getFormat(std::array{ mbusCode }, rawSize);
 
 		if (sensorConfig &&
 		    sensorConfig->outputSize != sensorFormat.size)
@@ -360,7 +360,7 @@  RkISP1Path::validate(const CameraSensor *sensor,
 
 		uint32_t mbusCode = formatToMediaBus.at(rawFormat);
 		V4L2SubdeviceFormat sensorFormat =
-			sensor->getFormat({ mbusCode }, sensorSize);
+			sensor->getFormat(std::array{ mbusCode }, sensorSize);
 
 		if (sensorFormat.size != sensorSize)
 			return CameraConfiguration::Invalid;
diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp
index 1eccca519..1b9b5c9a0 100644
--- a/src/libcamera/sensor/camera_sensor_legacy.cpp
+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp
@@ -73,7 +73,7 @@  public:
 	std::vector<Size> sizes(unsigned int mbusCode) const override;
 	Size resolution() const override;
 
-	V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
+	V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
 				      const Size &size,
 				      const Size maxSize) const override;
 	int setFormat(V4L2SubdeviceFormat *format,
@@ -699,7 +699,7 @@  Size CameraSensorLegacy::resolution() const
 }
 
 V4L2SubdeviceFormat
-CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,
+CameraSensorLegacy::getFormat(Span<const unsigned int> mbusCodes,
 			      const Size &size, Size maxSize) const
 {
 	unsigned int desiredArea = size.width * size.height;
diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp
index c65ecbb86..7ac0f563d 100644
--- a/src/libcamera/sensor/camera_sensor_raw.cpp
+++ b/src/libcamera/sensor/camera_sensor_raw.cpp
@@ -74,7 +74,7 @@  public:
 	std::vector<Size> sizes(unsigned int mbusCode) const override;
 	Size resolution() const override;
 
-	V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
+	V4L2SubdeviceFormat getFormat(Span<const unsigned int> mbusCodes,
 				      const Size &size,
 				      const Size maxSize) const override;
 	int setFormat(V4L2SubdeviceFormat *format,
@@ -757,7 +757,7 @@  Size CameraSensorRaw::resolution() const
 }
 
 V4L2SubdeviceFormat
-CameraSensorRaw::getFormat(const std::vector<unsigned int> &mbusCodes,
+CameraSensorRaw::getFormat(Span<const unsigned int> mbusCodes,
 			   const Size &size, Size maxSize) const
 {
 	unsigned int desiredArea = size.width * size.height;
diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp
index 869c78896..c30a2212e 100644
--- a/test/camera-sensor.cpp
+++ b/test/camera-sensor.cpp
@@ -96,10 +96,13 @@  protected:
 		}
 
 		/* Use an invalid format and make sure it's not selected. */
-		V4L2SubdeviceFormat format = sensor_->getFormat({ 0xdeadbeef,
-								  MEDIA_BUS_FMT_SBGGR10_1X10,
-								  MEDIA_BUS_FMT_BGR888_1X24 },
-								Size(1024, 768));
+		static constexpr uint32_t mbusCodes[] = {
+			0xdeadbeef,
+			MEDIA_BUS_FMT_SBGGR10_1X10,
+			MEDIA_BUS_FMT_BGR888_1X24,
+		};
+
+		V4L2SubdeviceFormat format = sensor_->getFormat(mbusCodes, Size(1024, 768));
 		if (format.code != MEDIA_BUS_FMT_SBGGR10_1X10 ||
 		    format.size != Size(4096, 2160)) {
 			cerr << "Failed to get a suitable format, expected 4096x2160-0x"