You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
staging: vc04_services: codec: V4L2_PIX_FMT_RGBA32 -> JPEG encoder not functional #5418
Switch to V4L2_PIX_FMT_BGR32 (BGR4) and it works. (It is also deprecated and should be swapped for V4L2_PIX_FMT_XBGR32)
The JPEG codec is inherently YUV based, so the list of supported formats is based on the image conversion functions that had been implemented.
It also has no alpha support, so it should be using _XRGB32 and _XRGB32 formats. I'm reluctant to change them now as applications may be relying on them. I wonder if I can map those nicely in try_fmt to avoid regressions.
I was expecting V4L2_PIX_FMT_RGBA32 to work too, but you're right that it doesn't.
@6by9 I'm back with another RGBA32 thing. I switched from the JPEG encoder to H264, leaving the source intact. The encoder starts up normally but there is something wrong with color mapping:||
I'd suggest adding a log entry in dmesg for people using those deprecated formats like RGBA32 when the HW encoder starts. This would make it possible to remove support at a later stage. I'd expect only formats available in v4l2-ctl --list-formats-out to work. Using anything else should throw an error/deprecation warning. Not anyone knows that they can use any supported format as long as it has a matching length.
Er, yes, it was specifically for JPEG encode and V4L2_PIX_FMT_RGBA32 that was missing an alignment parameter.
I'd suggest adding a log entry in dmesg for people using those deprecated formats like RGBA32 when the HW encoder starts. This would make it possible to remove support at a later stage. I'd expect only formats available in v4l2-ctl --list-formats-out to work. Using anything else should throw an error/deprecation warning. Not anyone knows that they can use any supported format as long as it has a matching length.
When the application calls the VIDIOC_S_FMT ioctl with a pointer to a struct v4l2_format structure the driver checks and adjusts the parameters against hardware abilities. Drivers should not return an error code unless the type field is invalid, this is a mechanism to fathom device capabilities and to approach parameters acceptable for both the application and driver.
We do that, dropping back to the first supported format should the image format be invalid.
Adding a logging message on any fixup would result in kernel log spam (GStreamer tends to do lots of probing on startup). Allowing userspace to spam the kernel log is considered a bad thing in the kernel community.
Colour mapping issues for pixel interleaved formats are always a pain, partly in determining the correct layout in memory of a reference frame. I may have a suitable test app to mod to exercise it, but it's low priority.
Activity
6by9 commentedon Apr 12, 2023
V4L2_PIX_FMT_RGB32 is a deprecated format (see https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/pixfmt-rgb.html#deprecated-rgb-formats).
It's also not supported by the codec. Supported formats are:
Switch to V4L2_PIX_FMT_BGR32 (BGR4) and it works. (It is also deprecated and should be swapped for V4L2_PIX_FMT_XBGR32)
The JPEG codec is inherently YUV based, so the list of supported formats is based on the image conversion functions that had been implemented.
It also has no alpha support, so it should be using _XRGB32 and _XRGB32 formats. I'm reluctant to change them now as applications may be relying on them. I wonder if I can map those nicely in try_fmt to avoid regressions.
I was expecting V4L2_PIX_FMT_RGBA32 to work too, but you're right that it doesn't.
https://github.com/raspberrypi/linux/blob/rpi-6.1.y/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c#L266 is missing the 5th element in the array, so for image_encode we align to a multiple of 0, giving a stride and overall image size of 0.
6by9 commentedon Apr 12, 2023
#5426
mikegapinski commentedon Apr 13, 2023
It works! Thank you very much for the fix
mikegapinski commentedon Jul 19, 2023
@6by9 I'm back with another RGBA32 thing. I switched from the JPEG encoder to H264, leaving the source intact. The encoder starts up normally but there is something wrong with color mapping:||

Is this a similar small mapping issue between v4l2 and mmal? I am using the pikvm encoder ported over to AOSP, I think that the config is OK... https://github.com/tesla-android/android-external-tesla-android-virtual-display/blob/main/encode/m2m.c
The same thing happens with MJPEG encoder.
This means that #5426 fixed the jpeg encoder only
mikegapinski commentedon Jul 19, 2023
@6by9
I fixed it on my end with:
`frame.width = buffer->getWidth();
frame.height = buffer->getHeight();
frame.stride = buffer->getStride() * bytesPerPixel(buffer->getPixelFormat());
frame.used = static_cast<size_t>(frame.width) * static_cast<size_t>(frame.height) * bytesPerPixel(buffer->getPixelFormat());
frame.data = static_cast<uint8_t *>(malloc(frame.used));`
I'd suggest adding a log entry in dmesg for people using those deprecated formats like RGBA32 when the HW encoder starts. This would make it possible to remove support at a later stage. I'd expect only formats available in
v4l2-ctl --list-formats-outto work. Using anything else should throw an error/deprecation warning. Not anyone knows that they can use any supported format as long as it has a matching length.6by9 commentedon Jul 19, 2023
Er, yes, it was specifically for JPEG encode and V4L2_PIX_FMT_RGBA32 that was missing an alignment parameter.
The V4L2 spec requires a VIDIOC_S_FMT or VIDIOC_TRY_FMT with invalid parameters to be amended and returned.
https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-g-fmt.html#description
We do that, dropping back to the first supported format should the image format be invalid.
Adding a logging message on any fixup would result in kernel log spam (GStreamer tends to do lots of probing on startup). Allowing userspace to spam the kernel log is considered a bad thing in the kernel community.
Colour mapping issues for pixel interleaved formats are always a pain, partly in determining the correct layout in memory of a reference frame. I may have a suitable test app to mod to exercise it, but it's low priority.