<div dir="auto"><div>Hi Roman,</div><div dir="auto"><br></div><div dir="auto">Thanks for the update.</div><div dir="auto"><br></div><div dir="auto">Unfortunately I don't really understand why removing that change gets your environment working. I think I probably need some guidance from the libcamera team about buffer allocations happening in the android layer. Perhaps you can post a log of your new errors?</div><div dir="auto"><br></div><div dir="auto">The buffer allocation change, while not critical, really wants to go in with this series. So hopefully we can come to some conclusion soon.</div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Naush<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, 10 Nov 2021, 4:47 pm Roman Stratiienko, <<a href="mailto:r.stratiienko@gmail.com">r.stratiienko@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Oh it works perfectly if I revert [PATCH 2/3] pipeline: raspberrypi:<br>
Rework the internal buffer allocation scheme</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
ср, 10 нояб. 2021 г. в 18:25, Roman Stratiienko <<a href="mailto:r.stratiienko@gmail.com" target="_blank" rel="noreferrer">r.stratiienko@gmail.com</a>>:<br>
><br>
> Hi Naush,<br>
><br>
> Thank you for the patches.<br>
> I tested my setup with them and it made the behaviour slightly<br>
> different. Now the camera app draws the first frame and freezes.<br>
> I'm now playing with overallocation. Meanwhile I would like to ask one thing.<br>
> Cache hit is determined by comparing file descriptors and sizes of the buffers.<br>
> Is it safe to do in case of external buffers? FD may be different for<br>
> the same buffer, using inode for this purpose looks like a better<br>
> solution.<br>
> What do you think?<br>
><br>
> вт, 9 нояб. 2021 г. в 15:39, Roman Stratiienko <<a href="mailto:r.stratiienko@gmail.com" target="_blank" rel="noreferrer">r.stratiienko@gmail.com</a>>:<br>
> ><br>
> > вт, 9 нояб. 2021 г. в 15:35, Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank" rel="noreferrer">naush@raspberrypi.com</a>>:<br>
> > ><br>
> > > Hi Roman,<br>
> > ><br>
> > > On Tue, 9 Nov 2021 at 13:28, Roman Stratiienko <<a href="mailto:r.stratiienko@gmail.com" target="_blank" rel="noreferrer">r.stratiienko@gmail.com</a>> wrote:<br>
> > >><br>
> > >> To make Android happy I've applied one patch:<br>
> > >><br>
> > >> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
> > >> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
> > >> @@ -429,9 +429,10 @@ CameraConfiguration::Status<br>
> > >> RPiCameraConfiguration::validate()<br>
> > >>                         rawCount++;<br>
> > >>                 } else {<br>
> > >> +                       cfg.bufferCount = 3;<br>
> > >>                         outSize[outCount] = std::make_pair(count, cfg.size);<br>
> > >>                         /* Record the largest resolution for fixups later. */<br>
> > >>                         if (maxSize < cfg.size) {<br>
> > >><br>
> > >> (Similar are done in other pipelines).<br>
> > >><br>
> > >> And it seems to me that it somehow conflicts with raspberrypi pipeline<br>
> > >> internals.<br>
> > ><br>
> > ><br>
> > > The problem seems to be the number of cache slots is not set up correctly for your usage.<br>
> > > From what I can gather, the Android layer allocated its own buffers to use by the pipeline<br>
> > > handler, but the number of cache slots the pipeline handler allocates is smaller than<br>
> > > the total number of buffers available.  Hence the failure where the cache may not be able<br>
> > > to find a free slot to use.<br>
> > ><br>
> > > I've been meaning to address this bit of logic for a long time now, so perhaps this is<br>
> > > a good time to do this.  It's not a big change, but there are certain assumptions to be made<br>
> > > to balance between over allocation and loss of performance.  I will post a patch soon, would<br>
> > > you be able to try it out in your environment and report if it solves your issue?<br>
> ><br>
> ><br>
> > Sure. With great pleasure.<br>
> ><br>
> ><br>
> > ><br>
> > > Thanks,<br>
> > > Naush<br>
> > ><br>
> > >><br>
> > >><br>
> > >> вт, 9 нояб. 2021 г. в 13:54, Roman Stratiienko <<a href="mailto:r.stratiienko@gmail.com" target="_blank" rel="noreferrer">r.stratiienko@gmail.com</a>>:<br>
> > >> ><br>
> > >> > Hi Naushir,<br>
> > >> ><br>
> > >> > Thanks a lot for your support. You were right, it returns with error<br>
> > >> > in that place. I'm correctly investigating why there is no buffer in<br>
> > >> > the cache.<br>
> > >> ><br>
> > >> > вт, 9 нояб. 2021 г. в 12:32, Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank" rel="noreferrer">naush@raspberrypi.com</a>>:<br>
> > >> > ><br>
> > >> > ><br>
> > >> > > On Tue, 9 Nov 2021 at 10:26, Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank" rel="noreferrer">naush@raspberrypi.com</a>> wrote:<br>
> > >> > >><br>
> > >> > >> Hi Roman,<br>
> > >> > >><br>
> > >> > >> Not sure if the email thread is the best place to discuss your issue, so perhaps create a bug report at <a href="http://bugs.libcamera.org" rel="noreferrer noreferrer" target="_blank">bugs.libcamera.org</a>.<br>
> > >> > >> Onto the actual issue - it seems like the ISP gets starved of request buffers and fails to produce output and the pipeline handler stalls.<br>
> > >> > >> The reason it gets starved is likely to be due to the following errors in the log:<br>
> > >> > >><br>
> > >> > >> 10-07 14:37:46.726   360   442 D libcamera: DEBUG RPISTREAM rpi_stream.cpp:226 Queuing buffer 1048579 for ISP Output1<br>
> > >> > >> 10-07 14:37:46.727   360   442 E libcamera: ERROR RPISTREAM rpi_stream.cpp:231 Failed to queue buffer for ISP Output1<br>
> > >> > >> 10-07 14:37:46.727   360   442 D libcamera: DEBUG RPISTREAM rpi_stream.cpp:226 Queuing buffer 1048580 for ISP Output1<br>
> > >> > >> 10-07 14:37:46.727   360   442 E libcamera: ERROR RPISTREAM rpi_stream.cpp:231 Failed to queue buffer for ISP Output1<br>
> > >> > >> 10-07 14:37:46.727   360   442 D libcamera: DEBUG RPISTREAM rpi_stream.cpp:226 Queuing buffer 1048581 for ISP Output1<br>
> > >> > >> 10-07 14:37:46.728   360   442 E libcamera: ERROR RPISTREAM rpi_stream.cpp:231 Failed to queue buffer for ISP Output1<br>
> > >> > >><br>
> > >> > >> I cannot tell further why the qbuf ioctl has failed.  Perhaps something in dmesg would tell us?  Could you expand on how your request<br>
> > >> > >> buffers have been allocated?<br>
> > >> > ><br>
> > >> > ><br>
> > >> > > Just a pointer for you to investigate... The logs suggest that V4L2VideoDevice::queueBuffer() fails at:<br>
> > >> > ><br>
> > >> > > ret = cache_->get(*buffer);<br>
> > >> > > if (ret < 0)<br>
> > >> > >         return ret;<br>
> > >> > ><br>
> > >> > > as all other error paths through that function log a message, and we see none.  So it may not necessarily be the ioctl that fails.<br>
> > >> > ><br>
> > >> > > Naush<br>
> > >> > ><br>
> > >> > >><br>
> > >> > >><br>
> > >> > >> Thanks,<br>
> > >> > >> Naush<br>
> > >> > >><br>
> > >> > >><br>
> > >> > >> On Mon, 8 Nov 2021 at 20:20, Roman Stratiienko <<a href="mailto:r.stratiienko@gmail.com" target="_blank" rel="noreferrer">r.stratiienko@gmail.com</a>> wrote:<br>
> > >> > >>><br>
> > >> > >>> Yes, I am on the very latest rpi branch without any custom patches. I had to upgrade it because of new media control used in mainline libcamera.<br>
> > >> > >>><br>
> > >> > >>> пн, 8 нояб. 2021 г., 22:12 Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank" rel="noreferrer">kieran.bingham@ideasonboard.com</a>>:<br>
> > >> > >>>><br>
> > >> > >>>> Hi Roman,<br>
> > >> > >>>><br>
> > >> > >>>> Quoting Roman Stratiienko (2021-11-08 17:46:56)<br>
> > >> > >>>> > Hi guys,<br>
> > >> > >>>> ><br>
> > >> > >>>> > I have stuck with camera bring-up for Android. Could somebody who has<br>
> > >> > >>>> > experience in it help me to find a right way to solve this. Logs are<br>
> > >> > >>>> > available here:<br>
> > >> > >>>> > <a href="https://github.com/kbingham/libcamera/issues/31" rel="noreferrer noreferrer" target="_blank">https://github.com/kbingham/libcamera/issues/31</a><br>
> > >> > >>>><br>
> > >> > >>>> The RPi kernel, and pipeline handler have had a large change recently to<br>
> > >> > >>>> convert to using MediaController. It may require ensuring you have the<br>
> > >> > >>>> latest kernel from RPi, along with the latest libcamera.<br>
> > >> > >>>><br>
> > >> > >>>> You mentioned that you have " rpi-kernel v5.10.y", do you know if this<br>
> > >> > >>>> contains the commits that update to the new MediaController drivers?<br>
> > >> > >>>><br>
> > >> > >>>> I assume you are building your own kernel, so you'll want to make sure<br>
> > >> > >>>> you're on the (very, very) latest branch, and it might be something to<br>
> > >> > >>>> check on the RPi forums otherwise.<br>
> > >> > >>>><br>
> > >> > >>>> --<br>
> > >> > >>>> Kieran<br>
> > >> > >>>><br>
> > >> > >>>><br>
> > >> > >>>> ><br>
> > >> > >>>> > Thanks in advance,<br>
> > >> > >>>> > Roman<br>
</blockquote></div></div></div>