| Message ID | 20261106151345.32491-3-johannes.goede@oss.qualcomm.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Hi Hans, On 11/6/2026 5:13 PM, Hans de Goede wrote: > Add camss_util.[h|cpp] files with some small helper functions shared > between Camss* classes. > > Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> > --- > src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ > src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ > 2 files changed, 58 insertions(+) > create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp > create mode 100644 src/libcamera/pipeline/camss/camss_util.h > > diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp > new file mode 100644 > index 000000000..96b1bbc72 > --- /dev/null > +++ b/src/libcamera/pipeline/camss/camss_util.cpp > @@ -0,0 +1,39 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Qualcomm CAMSS utility functions > + * > + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. > + */ > + > +#include "camss_util.h" > + > +#include <libcamera/base/log.h> > + > +#include <libcamera/stream.h> > + > +#include "libcamera/internal/v4l2_videodevice.h" > + > +namespace libcamera { > + > +LOG_DECLARE_CATEGORY(Camss) > + > +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, > + const StreamConfiguration &cfg, > + const char *msgPrefix) Quite a long name :-) Anyway i will comment latter in the code but i think that the pipeline handler should maintain valid configurations which will return them in Generate configuration. However for the usecases where application need to fill stream configuration maybe is needed. I want to discuss for qcom hw accelerated video encoder usecase. The encoder has strict requirement for stride and scanline usually 128 which means that we may use stream role to output that kind of buffers and document that. Just to explain in android, based on GrallocUsage flags the both components which are producers and consumers need satisfy the agreed requirements. Other option is to let application fill the stride and hopefully it is supported by the hw engine which outputs the buffer. However not sure how this work in libcamera because in Generate configurations there is only stream role there is no other hint for stride/scanline alignment... And here if stride is not supported (changed by the driver) we return an error. So what the client of libcamera suppose to do when there is no information for the supported strides? I did not check the libcamera interface recently so apologies if this is already handled. > +{ > + if (cfg.pixelFormat != fmt.fourcc.toPixelFormat(false) || cfg.size != fmt.size || > + cfg.stride != fmt.planes[0].bpl) { > + LOG(Camss, Error) > + << msgPrefix > + << " StreamConfiguration vs V4L2DeviceFormat mismatch" > + << " pixelFormat " << cfg.pixelFormat << ", " << fmt.fourcc.toPixelFormat(false) > + << " size " << cfg.size << ", " << fmt.size > + << " stride " << cfg.stride << ", " << fmt.planes[0].bpl > + << " frameSize " << cfg.frameSize << ", " << fmt.planes[0].size; > + return false; > + } > + > + return true; > +} > + > +} /* namespace libcamera */ > diff --git a/src/libcamera/pipeline/camss/camss_util.h b/src/libcamera/pipeline/camss/camss_util.h > new file mode 100644 > index 000000000..111c305aa > --- /dev/null > +++ b/src/libcamera/pipeline/camss/camss_util.h > @@ -0,0 +1,19 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * Qualcomm CAMSS utility functions > + * > + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. > + */ > + > +#pragma once > + > +namespace libcamera { > + > +struct StreamConfiguration; > +class V4L2DeviceFormat; > + > +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, > + const StreamConfiguration &cfg, > + const char *msgPrefix); > + > +} /* namespace libcamera */
Hi Gjorgji, On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: > Hi Hans, > > On 11/6/2026 5:13 PM, Hans de Goede wrote: >> Add camss_util.[h|cpp] files with some small helper functions shared >> between Camss* classes. >> >> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >> --- >> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >> 2 files changed, 58 insertions(+) >> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >> >> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >> new file mode 100644 >> index 000000000..96b1bbc72 >> --- /dev/null >> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >> @@ -0,0 +1,39 @@ >> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >> +/* >> + * Qualcomm CAMSS utility functions >> + * >> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >> + */ >> + >> +#include "camss_util.h" >> + >> +#include <libcamera/base/log.h> >> + >> +#include <libcamera/stream.h> >> + >> +#include "libcamera/internal/v4l2_videodevice.h" >> + >> +namespace libcamera { >> + >> +LOG_DECLARE_CATEGORY(Camss) >> + >> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >> + const StreamConfiguration &cfg, >> + const char *msgPrefix) > > Quite a long name :-) > Anyway i will comment latter in the code but i think that the pipeline handler should maintain > valid configurations which will return them in Generate configuration. Agreed. This function is not about this though. When we submit a V4L2DeviceFormat to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it are not supported, like changing an odd width of say 1023 to 1024 because odd configs are not supported. This function verifies that the streamconfig we started with (after validation) and the actually configured fmt on the pad as returned by the setfmt call on the pad agree. I noticed that most pipeline-handlers simply assume what they pass into setfmt actually get applied unchanged but the kernel API does not guarantee that, so I added this helper to verify the format we calculated in the pipeline-handler and the one the kernel-driver ends up using internally actually match. > However for the usecases where application need to fill stream configuration maybe is needed. > I want to discuss for qcom hw accelerated video encoder usecase. I guess your mostly talking about allowing the app to set a stride here, the actual pixelfmt, width and height are already under app control (although the validate call can change them if the app requests unsupported formats). For things like stride, I know that Laurent wants to get libcamera out of the business of allocating the memory buffers and instead have the app allocate the buffers and pass in a dmabuf fd, which would put the stride under control of the app I believe. libcamera already has an API for app managed buffers. > The encoder has strict requirement for stride and scanline usually 128 which means that we may > use stream role to output that kind of buffers and document that. > > Just to explain in android, based on GrallocUsage flags the both components which are producers and > consumers need satisfy the agreed requirements. > > Other option is to let application fill the stride and hopefully it is supported > by the hw engine which outputs the buffer. > However not sure how this work in libcamera because in Generate configurations there is > only stream role there is no other hint for stride/scanline alignment... > > And here if stride is not supported (changed by the driver) we return an error. So what the > client of libcamera suppose to do when there is no information for the supported strides? > > I did not check the libcamera interface recently so apologies if this is already handled. Should have read the other paragraphs before replying, see above. Regards, Hans > > >> +{ >> + if (cfg.pixelFormat != fmt.fourcc.toPixelFormat(false) || cfg.size != fmt.size || >> + cfg.stride != fmt.planes[0].bpl) { >> + LOG(Camss, Error) >> + << msgPrefix >> + << " StreamConfiguration vs V4L2DeviceFormat mismatch" >> + << " pixelFormat " << cfg.pixelFormat << ", " << fmt.fourcc.toPixelFormat(false) >> + << " size " << cfg.size << ", " << fmt.size >> + << " stride " << cfg.stride << ", " << fmt.planes[0].bpl >> + << " frameSize " << cfg.frameSize << ", " << fmt.planes[0].size; >> + return false; >> + } >> + >> + return true; >> +} >> + >> +} /* namespace libcamera */ >> diff --git a/src/libcamera/pipeline/camss/camss_util.h b/src/libcamera/pipeline/camss/camss_util.h >> new file mode 100644 >> index 000000000..111c305aa >> --- /dev/null >> +++ b/src/libcamera/pipeline/camss/camss_util.h >> @@ -0,0 +1,19 @@ >> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >> +/* >> + * Qualcomm CAMSS utility functions >> + * >> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >> + */ >> + >> +#pragma once >> + >> +namespace libcamera { >> + >> +struct StreamConfiguration; >> +class V4L2DeviceFormat; >> + >> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >> + const StreamConfiguration &cfg, >> + const char *msgPrefix); >> + >> +} /* namespace libcamera */ >
Hi Hans, On 11/19/2026 10:20 AM, Hans de Goede wrote: > Hi Gjorgji, > > On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: >> Hi Hans, >> >> On 11/6/2026 5:13 PM, Hans de Goede wrote: >>> Add camss_util.[h|cpp] files with some small helper functions shared >>> between Camss* classes. >>> >>> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >>> --- >>> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >>> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >>> 2 files changed, 58 insertions(+) >>> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >>> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >>> >>> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >>> new file mode 100644 >>> index 000000000..96b1bbc72 >>> --- /dev/null >>> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >>> @@ -0,0 +1,39 @@ >>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>> +/* >>> + * Qualcomm CAMSS utility functions >>> + * >>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>> + */ >>> + >>> +#include "camss_util.h" >>> + >>> +#include <libcamera/base/log.h> >>> + >>> +#include <libcamera/stream.h> >>> + >>> +#include "libcamera/internal/v4l2_videodevice.h" >>> + >>> +namespace libcamera { >>> + >>> +LOG_DECLARE_CATEGORY(Camss) >>> + >>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>> + const StreamConfiguration &cfg, >>> + const char *msgPrefix) >> >> Quite a long name :-) >> Anyway i will comment latter in the code but i think that the pipeline handler should maintain >> valid configurations which will return them in Generate configuration. > > Agreed. This function is not about this though. When we submit a V4L2DeviceFormat > to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it > are not supported, like changing an odd width of say 1023 to 1024 because odd > configs are not supported. > > This function verifies that the streamconfig we started with (after validation) > and the actually configured fmt on the pad as returned by the setfmt call on the pad > agree. > > I noticed that most pipeline-handlers simply assume what they pass into setfmt > actually get applied unchanged but the kernel API does not guarantee that, so > I added this helper to verify the format we calculated in the pipeline-handler > and the one the kernel-driver ends up using internally actually match. I have noticed that as well, there should be check if the configuration generated by the pipeline handler is actually untouched. That guarantee is not in place, so yes there nothing else you can do but validate before proceeding. > >> However for the usecases where application need to fill stream configuration maybe is needed. >> I want to discuss for qcom hw accelerated video encoder usecase. > > I guess your mostly talking about allowing the app to set a stride here, > the actual pixelfmt, width and height are already under app control > (although the validate call can change them if the app requests unsupported > formats). > > For things like stride, I know that Laurent wants to get libcamera out of > the business of allocating the memory buffers and instead have the app allocate > the buffers and pass in a dmabuf fd, which would put the stride under control > of the app I believe. libcamera already has an API for app managed buffers. Yes there is API for app managed buffers, but how this fits with generated configuration stride? I think i need more time to see how things evolved over the years i will get back on this topic. > >> The encoder has strict requirement for stride and scanline usually 128 which means that we may >> use stream role to output that kind of buffers and document that. >> >> Just to explain in android, based on GrallocUsage flags the both components which are producers and >> consumers need satisfy the agreed requirements. >> >> Other option is to let application fill the stride and hopefully it is supported >> by the hw engine which outputs the buffer. >> However not sure how this work in libcamera because in Generate configurations there is >> only stream role there is no other hint for stride/scanline alignment... >> >> And here if stride is not supported (changed by the driver) we return an error. So what the >> client of libcamera suppose to do when there is no information for the supported strides? >> >> I did not check the libcamera interface recently so apologies if this is already handled. > > Should have read the other paragraphs before replying, see above. Thanks, more less everything is answered. ~Gjorgji > > Regards, > > Hans > > >> >> >>> +{ >>> + if (cfg.pixelFormat != fmt.fourcc.toPixelFormat(false) || cfg.size != fmt.size || >>> + cfg.stride != fmt.planes[0].bpl) { >>> + LOG(Camss, Error) >>> + << msgPrefix >>> + << " StreamConfiguration vs V4L2DeviceFormat mismatch" >>> + << " pixelFormat " << cfg.pixelFormat << ", " << fmt.fourcc.toPixelFormat(false) >>> + << " size " << cfg.size << ", " << fmt.size >>> + << " stride " << cfg.stride << ", " << fmt.planes[0].bpl >>> + << " frameSize " << cfg.frameSize << ", " << fmt.planes[0].size; >>> + return false; >>> + } >>> + >>> + return true; >>> +} >>> + >>> +} /* namespace libcamera */ >>> diff --git a/src/libcamera/pipeline/camss/camss_util.h b/src/libcamera/pipeline/camss/camss_util.h >>> new file mode 100644 >>> index 000000000..111c305aa >>> --- /dev/null >>> +++ b/src/libcamera/pipeline/camss/camss_util.h >>> @@ -0,0 +1,19 @@ >>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>> +/* >>> + * Qualcomm CAMSS utility functions >>> + * >>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>> + */ >>> + >>> +#pragma once >>> + >>> +namespace libcamera { >>> + >>> +struct StreamConfiguration; >>> +class V4L2DeviceFormat; >>> + >>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>> + const StreamConfiguration &cfg, >>> + const char *msgPrefix); >>> + >>> +} /* namespace libcamera */ >> >
Hi, On 19-Nov-26 13:04, Gjorgji Rosikopulos (Consultant) wrote: > Hi Hans, > > On 11/19/2026 10:20 AM, Hans de Goede wrote: >> Hi Gjorgji, >> >> On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: >>> Hi Hans, >>> >>> On 11/6/2026 5:13 PM, Hans de Goede wrote: >>>> Add camss_util.[h|cpp] files with some small helper functions shared >>>> between Camss* classes. >>>> >>>> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >>>> --- >>>> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >>>> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >>>> 2 files changed, 58 insertions(+) >>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >>>> >>>> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >>>> new file mode 100644 >>>> index 000000000..96b1bbc72 >>>> --- /dev/null >>>> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >>>> @@ -0,0 +1,39 @@ >>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>>> +/* >>>> + * Qualcomm CAMSS utility functions >>>> + * >>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>>> + */ >>>> + >>>> +#include "camss_util.h" >>>> + >>>> +#include <libcamera/base/log.h> >>>> + >>>> +#include <libcamera/stream.h> >>>> + >>>> +#include "libcamera/internal/v4l2_videodevice.h" >>>> + >>>> +namespace libcamera { >>>> + >>>> +LOG_DECLARE_CATEGORY(Camss) >>>> + >>>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>>> + const StreamConfiguration &cfg, >>>> + const char *msgPrefix) >>> >>> Quite a long name :-) >>> Anyway i will comment latter in the code but i think that the pipeline handler should maintain >>> valid configurations which will return them in Generate configuration. >> >> Agreed. This function is not about this though. When we submit a V4L2DeviceFormat >> to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it >> are not supported, like changing an odd width of say 1023 to 1024 because odd >> configs are not supported. >> >> This function verifies that the streamconfig we started with (after validation) >> and the actually configured fmt on the pad as returned by the setfmt call on the pad >> agree. >> >> I noticed that most pipeline-handlers simply assume what they pass into setfmt >> actually get applied unchanged but the kernel API does not guarantee that, so >> I added this helper to verify the format we calculated in the pipeline-handler >> and the one the kernel-driver ends up using internally actually match. > > I have noticed that as well, there should be check if the configuration > generated by the pipeline handler is actually untouched. That guarantee is not > in place, so yes there nothing else you can do but validate before proceeding. > >> >>> However for the usecases where application need to fill stream configuration maybe is needed. >>> I want to discuss for qcom hw accelerated video encoder usecase. >> >> I guess your mostly talking about allowing the app to set a stride here, >> the actual pixelfmt, width and height are already under app control >> (although the validate call can change them if the app requests unsupported >> formats). >> >> For things like stride, I know that Laurent wants to get libcamera out of >> the business of allocating the memory buffers and instead have the app allocate >> the buffers and pass in a dmabuf fd, which would put the stride under control >> of the app I believe. libcamera already has an API for app managed buffers. > > Yes there is API for app managed buffers, but how this fits with generated configuration stride? the initially generated config's stride can be overridden by the application and then validate() should pass the new stride on to the kernel driver and report the resulting stride (which will be unchanged if supported by the driver) back in the validated config. Regards, Hans
On 11/21/2026 4:14 PM, Hans de Goede wrote: > Hi, > > On 19-Nov-26 13:04, Gjorgji Rosikopulos (Consultant) wrote: >> Hi Hans, >> >> On 11/19/2026 10:20 AM, Hans de Goede wrote: >>> Hi Gjorgji, >>> >>> On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: >>>> Hi Hans, >>>> >>>> On 11/6/2026 5:13 PM, Hans de Goede wrote: >>>>> Add camss_util.[h|cpp] files with some small helper functions shared >>>>> between Camss* classes. >>>>> >>>>> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >>>>> --- >>>>> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >>>>> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >>>>> 2 files changed, 58 insertions(+) >>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >>>>> >>>>> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >>>>> new file mode 100644 >>>>> index 000000000..96b1bbc72 >>>>> --- /dev/null >>>>> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >>>>> @@ -0,0 +1,39 @@ >>>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>>>> +/* >>>>> + * Qualcomm CAMSS utility functions >>>>> + * >>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>>>> + */ >>>>> + >>>>> +#include "camss_util.h" >>>>> + >>>>> +#include <libcamera/base/log.h> >>>>> + >>>>> +#include <libcamera/stream.h> >>>>> + >>>>> +#include "libcamera/internal/v4l2_videodevice.h" >>>>> + >>>>> +namespace libcamera { >>>>> + >>>>> +LOG_DECLARE_CATEGORY(Camss) >>>>> + >>>>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>>>> + const StreamConfiguration &cfg, >>>>> + const char *msgPrefix) >>>> >>>> Quite a long name :-) >>>> Anyway i will comment latter in the code but i think that the pipeline handler should maintain >>>> valid configurations which will return them in Generate configuration. >>> >>> Agreed. This function is not about this though. When we submit a V4L2DeviceFormat >>> to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it >>> are not supported, like changing an odd width of say 1023 to 1024 because odd >>> configs are not supported. >>> >>> This function verifies that the streamconfig we started with (after validation) >>> and the actually configured fmt on the pad as returned by the setfmt call on the pad >>> agree. >>> >>> I noticed that most pipeline-handlers simply assume what they pass into setfmt >>> actually get applied unchanged but the kernel API does not guarantee that, so >>> I added this helper to verify the format we calculated in the pipeline-handler >>> and the one the kernel-driver ends up using internally actually match. >> >> I have noticed that as well, there should be check if the configuration >> generated by the pipeline handler is actually untouched. That guarantee is not >> in place, so yes there nothing else you can do but validate before proceeding. >> >>> >>>> However for the usecases where application need to fill stream configuration maybe is needed. >>>> I want to discuss for qcom hw accelerated video encoder usecase. >>> >>> I guess your mostly talking about allowing the app to set a stride here, >>> the actual pixelfmt, width and height are already under app control >>> (although the validate call can change them if the app requests unsupported >>> formats). >>> >>> For things like stride, I know that Laurent wants to get libcamera out of >>> the business of allocating the memory buffers and instead have the app allocate >>> the buffers and pass in a dmabuf fd, which would put the stride under control >>> of the app I believe. libcamera already has an API for app managed buffers. >> >> Yes there is API for app managed buffers, but how this fits with generated configuration stride? > > the initially generated config's stride can be overridden by the application and then > validate() should pass the new stride on to the kernel driver and report the resulting > stride (which will be unchanged if supported by the driver) back in the validated config. Yes that is correct, i also have no objections with this change except that the the name seems little bit long :-). The question which come to my mind is more generic to the libcamera API. Let me explain: In v4l2 the driver modifies the stride to what actually can be supported, that is helpful when two components need to agree on the supported stride between them. The application has feedback from both sides and can make some logic/guess what stride is needed to satisfy both sides. Here it seems that feedback is not available, and if stride is not supported error is returned to the app without actually closest supported stride filled. But this maybe belongs to some general discussion. Or if i miss anything apologies i was not following the latest developments on the libcamera... ~Gjorgji > > Regards, > > Hans
Hi, On 21-Nov-26 16:52, Gjorgji Rosikopulos (Consultant) wrote: > On 11/21/2026 4:14 PM, Hans de Goede wrote: >> Hi, >> >> On 19-Nov-26 13:04, Gjorgji Rosikopulos (Consultant) wrote: >>> Hi Hans, >>> >>> On 11/19/2026 10:20 AM, Hans de Goede wrote: >>>> Hi Gjorgji, >>>> >>>> On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: >>>>> Hi Hans, >>>>> >>>>> On 11/6/2026 5:13 PM, Hans de Goede wrote: >>>>>> Add camss_util.[h|cpp] files with some small helper functions shared >>>>>> between Camss* classes. >>>>>> >>>>>> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >>>>>> --- >>>>>> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >>>>>> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >>>>>> 2 files changed, 58 insertions(+) >>>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >>>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >>>>>> >>>>>> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >>>>>> new file mode 100644 >>>>>> index 000000000..96b1bbc72 >>>>>> --- /dev/null >>>>>> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >>>>>> @@ -0,0 +1,39 @@ >>>>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>>>>> +/* >>>>>> + * Qualcomm CAMSS utility functions >>>>>> + * >>>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>>>>> + */ >>>>>> + >>>>>> +#include "camss_util.h" >>>>>> + >>>>>> +#include <libcamera/base/log.h> >>>>>> + >>>>>> +#include <libcamera/stream.h> >>>>>> + >>>>>> +#include "libcamera/internal/v4l2_videodevice.h" >>>>>> + >>>>>> +namespace libcamera { >>>>>> + >>>>>> +LOG_DECLARE_CATEGORY(Camss) >>>>>> + >>>>>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>>>>> + const StreamConfiguration &cfg, >>>>>> + const char *msgPrefix) >>>>> >>>>> Quite a long name :-) >>>>> Anyway i will comment latter in the code but i think that the pipeline handler should maintain >>>>> valid configurations which will return them in Generate configuration. >>>> >>>> Agreed. This function is not about this though. When we submit a V4L2DeviceFormat >>>> to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it >>>> are not supported, like changing an odd width of say 1023 to 1024 because odd >>>> configs are not supported. >>>> >>>> This function verifies that the streamconfig we started with (after validation) >>>> and the actually configured fmt on the pad as returned by the setfmt call on the pad >>>> agree. >>>> >>>> I noticed that most pipeline-handlers simply assume what they pass into setfmt >>>> actually get applied unchanged but the kernel API does not guarantee that, so >>>> I added this helper to verify the format we calculated in the pipeline-handler >>>> and the one the kernel-driver ends up using internally actually match. >>> >>> I have noticed that as well, there should be check if the configuration >>> generated by the pipeline handler is actually untouched. That guarantee is not >>> in place, so yes there nothing else you can do but validate before proceeding. >>> >>>> >>>>> However for the usecases where application need to fill stream configuration maybe is needed. >>>>> I want to discuss for qcom hw accelerated video encoder usecase. >>>> >>>> I guess your mostly talking about allowing the app to set a stride here, >>>> the actual pixelfmt, width and height are already under app control >>>> (although the validate call can change them if the app requests unsupported >>>> formats). >>>> >>>> For things like stride, I know that Laurent wants to get libcamera out of >>>> the business of allocating the memory buffers and instead have the app allocate >>>> the buffers and pass in a dmabuf fd, which would put the stride under control >>>> of the app I believe. libcamera already has an API for app managed buffers. >>> >>> Yes there is API for app managed buffers, but how this fits with generated configuration stride? >> >> the initially generated config's stride can be overridden by the application and then >> validate() should pass the new stride on to the kernel driver and report the resulting >> stride (which will be unchanged if supported by the driver) back in the validated config. > > Yes that is correct, i also have no objections with this change except that the the name > seems little bit long :-). The question which come to my mind is more generic to the > libcamera API. Let me explain: > > In v4l2 the driver modifies the stride to what actually can be supported, > that is helpful when two components need to agree on the supported stride between them. > The application has feedback from both sides and can make some logic/guess what stride > is needed to satisfy both sides. > Here it seems that feedback is not available, and if stride is not supported error > is returned to the app without actually closest supported stride filled. The v4l2 API correct stride is returned to the app in e.g. CamssCsiCamera::validate(), and the camssV4L2DeviceFormatMatchesStreamConfig() check only is called at configure() time to check that the stride for the read-only at this point in time cfg, matches the stride from the cfg adjusted by CamssCsiCamera::validate(). So as long as the kernel driver sets the right stride on a try-fmt, then the app does get the corrected stride back in the cfg returned by validate() and if the kernel driver does not do that it is a kernel bug. Regards, Hans
On 11/25/2026 8:28 PM, Hans de Goede wrote: > Hi, > > On 21-Nov-26 16:52, Gjorgji Rosikopulos (Consultant) wrote: >> On 11/21/2026 4:14 PM, Hans de Goede wrote: >>> Hi, >>> >>> On 19-Nov-26 13:04, Gjorgji Rosikopulos (Consultant) wrote: >>>> Hi Hans, >>>> >>>> On 11/19/2026 10:20 AM, Hans de Goede wrote: >>>>> Hi Gjorgji, >>>>> >>>>> On 17-Nov-26 21:26, Gjorgji Rosikopulos (Consultant) wrote: >>>>>> Hi Hans, >>>>>> >>>>>> On 11/6/2026 5:13 PM, Hans de Goede wrote: >>>>>>> Add camss_util.[h|cpp] files with some small helper functions shared >>>>>>> between Camss* classes. >>>>>>> >>>>>>> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> >>>>>>> --- >>>>>>> src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ >>>>>>> src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ >>>>>>> 2 files changed, 58 insertions(+) >>>>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp >>>>>>> create mode 100644 src/libcamera/pipeline/camss/camss_util.h >>>>>>> >>>>>>> diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp >>>>>>> new file mode 100644 >>>>>>> index 000000000..96b1bbc72 >>>>>>> --- /dev/null >>>>>>> +++ b/src/libcamera/pipeline/camss/camss_util.cpp >>>>>>> @@ -0,0 +1,39 @@ >>>>>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */ >>>>>>> +/* >>>>>>> + * Qualcomm CAMSS utility functions >>>>>>> + * >>>>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. >>>>>>> + */ >>>>>>> + >>>>>>> +#include "camss_util.h" >>>>>>> + >>>>>>> +#include <libcamera/base/log.h> >>>>>>> + >>>>>>> +#include <libcamera/stream.h> >>>>>>> + >>>>>>> +#include "libcamera/internal/v4l2_videodevice.h" >>>>>>> + >>>>>>> +namespace libcamera { >>>>>>> + >>>>>>> +LOG_DECLARE_CATEGORY(Camss) >>>>>>> + >>>>>>> +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, >>>>>>> + const StreamConfiguration &cfg, >>>>>>> + const char *msgPrefix) >>>>>> >>>>>> Quite a long name :-) >>>>>> Anyway i will comment latter in the code but i think that the pipeline handler should maintain >>>>>> valid configurations which will return them in Generate configuration. >>>>> >>>>> Agreed. This function is not about this though. When we submit a V4L2DeviceFormat >>>>> to a pad on a v4l2-subdev, the subdev driver can modify it if some parts of it >>>>> are not supported, like changing an odd width of say 1023 to 1024 because odd >>>>> configs are not supported. >>>>> >>>>> This function verifies that the streamconfig we started with (after validation) >>>>> and the actually configured fmt on the pad as returned by the setfmt call on the pad >>>>> agree. >>>>> >>>>> I noticed that most pipeline-handlers simply assume what they pass into setfmt >>>>> actually get applied unchanged but the kernel API does not guarantee that, so >>>>> I added this helper to verify the format we calculated in the pipeline-handler >>>>> and the one the kernel-driver ends up using internally actually match. >>>> >>>> I have noticed that as well, there should be check if the configuration >>>> generated by the pipeline handler is actually untouched. That guarantee is not >>>> in place, so yes there nothing else you can do but validate before proceeding. >>>> >>>>> >>>>>> However for the usecases where application need to fill stream configuration maybe is needed. >>>>>> I want to discuss for qcom hw accelerated video encoder usecase. >>>>> >>>>> I guess your mostly talking about allowing the app to set a stride here, >>>>> the actual pixelfmt, width and height are already under app control >>>>> (although the validate call can change them if the app requests unsupported >>>>> formats). >>>>> >>>>> For things like stride, I know that Laurent wants to get libcamera out of >>>>> the business of allocating the memory buffers and instead have the app allocate >>>>> the buffers and pass in a dmabuf fd, which would put the stride under control >>>>> of the app I believe. libcamera already has an API for app managed buffers. >>>> >>>> Yes there is API for app managed buffers, but how this fits with generated configuration stride? >>> >>> the initially generated config's stride can be overridden by the application and then >>> validate() should pass the new stride on to the kernel driver and report the resulting >>> stride (which will be unchanged if supported by the driver) back in the validated config. >> >> Yes that is correct, i also have no objections with this change except that the the name >> seems little bit long :-). The question which come to my mind is more generic to the >> libcamera API. Let me explain: >> >> In v4l2 the driver modifies the stride to what actually can be supported, >> that is helpful when two components need to agree on the supported stride between them. >> The application has feedback from both sides and can make some logic/guess what stride >> is needed to satisfy both sides. >> Here it seems that feedback is not available, and if stride is not supported error >> is returned to the app without actually closest supported stride filled. > > The v4l2 API correct stride is returned to the app in e.g. CamssCsiCamera::validate(), > and the camssV4L2DeviceFormatMatchesStreamConfig() check only is called at configure() > time to check that the stride for the read-only at this point in time cfg, matches > the stride from the cfg adjusted by CamssCsiCamera::validate(). > > So as long as the kernel driver sets the right stride on a try-fmt, then the app > does get the corrected stride back in the cfg returned by validate() and if the > kernel driver does not do that it is a kernel bug. Thanks for the explanation. I miss that part with validate. ~Gjorgji > > Regards, > > Hans
diff --git a/src/libcamera/pipeline/camss/camss_util.cpp b/src/libcamera/pipeline/camss/camss_util.cpp new file mode 100644 index 000000000..96b1bbc72 --- /dev/null +++ b/src/libcamera/pipeline/camss/camss_util.cpp @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Qualcomm CAMSS utility functions + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#include "camss_util.h" + +#include <libcamera/base/log.h> + +#include <libcamera/stream.h> + +#include "libcamera/internal/v4l2_videodevice.h" + +namespace libcamera { + +LOG_DECLARE_CATEGORY(Camss) + +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, + const StreamConfiguration &cfg, + const char *msgPrefix) +{ + if (cfg.pixelFormat != fmt.fourcc.toPixelFormat(false) || cfg.size != fmt.size || + cfg.stride != fmt.planes[0].bpl) { + LOG(Camss, Error) + << msgPrefix + << " StreamConfiguration vs V4L2DeviceFormat mismatch" + << " pixelFormat " << cfg.pixelFormat << ", " << fmt.fourcc.toPixelFormat(false) + << " size " << cfg.size << ", " << fmt.size + << " stride " << cfg.stride << ", " << fmt.planes[0].bpl + << " frameSize " << cfg.frameSize << ", " << fmt.planes[0].size; + return false; + } + + return true; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/camss/camss_util.h b/src/libcamera/pipeline/camss/camss_util.h new file mode 100644 index 000000000..111c305aa --- /dev/null +++ b/src/libcamera/pipeline/camss/camss_util.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Qualcomm CAMSS utility functions + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#pragma once + +namespace libcamera { + +struct StreamConfiguration; +class V4L2DeviceFormat; + +bool camssV4L2DeviceFormatMatchesStreamConfig(const V4L2DeviceFormat &fmt, + const StreamConfiguration &cfg, + const char *msgPrefix); + +} /* namespace libcamera */
Add camss_util.[h|cpp] files with some small helper functions shared between Camss* classes. Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> --- src/libcamera/pipeline/camss/camss_util.cpp | 39 +++++++++++++++++++++ src/libcamera/pipeline/camss/camss_util.h | 19 ++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/libcamera/pipeline/camss/camss_util.cpp create mode 100644 src/libcamera/pipeline/camss/camss_util.h