Rpi 4 & 5 Libcamera & Capturing while streaming on Android 14
jan at radicalsystems.co.za
jan at radicalsystems.co.za
Wed Jun 5 09:06:53 CEST 2024
Hi Laurent
Thanks for the reply, I really appreciate the help.
After a lot of debugging yesterday and realtime tracing, I realized that the mmap failure occur regularly while streaming.
These are the values you requested (my info message did not show up and changed it to LOG error):
06-04 13:45:52.472 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:45:52.472 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:45:52.472 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:45:52.473 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:45:52.473 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:45:52.603 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:45:52.603 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:45:52.857 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:45:52.857 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:45:52.887 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:45:52.887 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:45:52.918 3324 3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
So, some goes through and the larger memory size fails.
But it seems this is not my real cause of error, but rather here:
06-04 13:46:54.783 3213 3296 D Camera2CaptureRequestBuilder: createCaptureRequest
06-04 13:46:54.795 3324 3534 E libcamera: ERROR Camera camera.cpp:675 Camera in Running state trying acquire() requiring state Available
06-04 13:46:54.795 3324 3534 E libcamera: ERROR HAL camera_device.cpp:390 '/base/axi/pcie at 120000/rp1/i2c at 88000/imx708 at 1a': Failed to acquire the camera
06-04 13:46:54.795 3324 3534 E libcamera: ERROR HAL camera3_hal.cpp:81 Failed to open camera module '0'
06-04 13:46:54.796 3324 3534 E libcamera: FATAL HAL generic_frame_buffer_allocator.cpp:106 gralloc_open() failed: -87
While streaming it is running and analytics detects a face, it must capture the image.
And as above Camera2CaptureRequestBuilder::createCaptureRequest is initiated from Android.
Then it seems it tries to open another instance of the camera: -> Camera camera.cpp:675 Camera in Running state trying acquire() requiring state Available.
But the camera is in state running and not available, then on that error creates a list of failures.
Usb camera works, and other platforms do.
So I'm usure how to remedy this issue.
Any ideas are welcome
Cheers
Jan
-----Original Message-----
From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Sent: Tuesday, June 4, 2024 10:14 PM
To: jan at radicalsystems.co.za
Cc: libcamera-devel at lists.libcamera.org
Subject: Re: Rpi 4 & 5 Libcamera & Mmap permission issue on Android 14
Hello Jan,
On Tue, Jun 04, 2024 at 12:26:20PM +0200, jan at radicalsystems.co.za wrote:
> Hi Libcamera Fundis!
>
> Having a problem capturing an image on Android 14 (& 13).
>
> Tombstone looks like this:
>
> 06-03 15:13:03.880 308 578 I DMABUFHEAPS: Using : Non-legacy ION heaps
> 06-03 15:13:03.880 308 578 I [minigbm:gbm_mesa_internals.cpp(233)]:
> Found GPU v3d
> 06-03 15:13:04.052 308 359 E libcamera: ERROR Buffer
> mapped_framebuffer.cpp:230 Failed to mmap plane: Permission denied
>
> .... lots of Permission denied!
>
> 06-03 15:13:11.282 308 359 E libcamera: ERROR Buffer
> mapped_framebuffer.cpp:230 Failed to mmap plane: Permission denied
> 06-03 15:13:12.008 308 579 E libcamera: ERROR Camera camera.cpp:675
> Camera in Running state trying acquire() requiring state Available
> 06-03 15:13:12.008 308 579 E libcamera: ERROR HAL
> camera_device.cpp:390 '/base/axi/pcie at 120000/rp1/i2c at 88000/imx708 at 1a':
> Failed to acquire the camera
> 06-03 15:13:12.008 308 579 E libcamera: ERROR HAL camera3_hal.cpp:81 Failed to open camera module '0'
> 06-03 15:13:12.008 308 579 E libcamera: FATAL HAL
> generic_frame_buffer_allocator.cpp:106 gralloc_open() failed: -87
>
> MLKIT Streaming & analyzing works until trying to capture an image the
> above happens.
>
> The various Android versions for Rpi5 I could find gave the same issue.
>
> I tried Emteria, AOSP & LineageOS 13 & 14
>
> Android built from Raspberry Vanilla and even replacing with later
> libcamera had the same issue.
>
> I’m not sure if this is purely a configuration problem, wrt to
> policies or permissions or specifically to the RPi’s architecture.
>
> Please help, I can rebuild and test.
>
> I have tried the latest code pulled into RaspVanilla, but had the same issue.
This doesn't ring a bell, but let's see if we can debug it.
The first step is to figure out if the mmap() parameters are right. In MappedFrameBuffer::MappedFrameBuffer(), at the location of the failure, could you print the value of fd, info.mapLength, and mmapFlags ?
Something like the following should do:
diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp
index b3104e0504d4..baa0587b4fcf 100644
--- a/src/libcamera/mapped_framebuffer.cpp
+++ b/src/libcamera/mapped_framebuffer.cpp
@@ -223,6 +223,9 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)
const int fd = plane.fd.get();
auto &info = mappedBuffers[fd];
if (!info.address) {
+ LOG(Buffer, Info)
+ << "Mapping fd: " << fd << ", length: "
+ << info.mapLength << ", flags: " << mmapFlags;
void *address = mmap(nullptr, info.mapLength, mmapFlags,
MAP_SHARED, fd, 0);
if (address == MAP_FAILED) {
(I haven't tested it though)
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list