[libcamera-devel] [PATCH v2 13/25] test: v4l2_videodevice: Switch to FrameBuffer interface
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Wed Jan 8 02:07:08 CET 2020
Hi Niklas,
Thank you for the patch.
On Mon, Dec 30, 2019 at 01:04:58PM +0100, Niklas Söderlund wrote:
> The V4L2VideoDevice class can now operate using a FrameBuffer interface,
> switch all test cases to use it.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> test/v4l2_videodevice/buffer_sharing.cpp | 30 ++++++-------
> test/v4l2_videodevice/capture_async.cpp | 20 ++++-----
> test/v4l2_videodevice/request_buffers.cpp | 11 +----
> test/v4l2_videodevice/stream_on_off.cpp | 6 +--
> test/v4l2_videodevice/v4l2_m2mdevice.cpp | 44 ++++++++-----------
> test/v4l2_videodevice/v4l2_videodevice_test.h | 2 +-
> 6 files changed, 48 insertions(+), 65 deletions(-)
>
> diff --git a/test/v4l2_videodevice/buffer_sharing.cpp b/test/v4l2_videodevice/buffer_sharing.cpp
> index fe48b2e98fdada8d..6acb06a24b47f653 100644
> --- a/test/v4l2_videodevice/buffer_sharing.cpp
> +++ b/test/v4l2_videodevice/buffer_sharing.cpp
> @@ -73,16 +73,14 @@ protected:
> return TestFail;
> }
>
> - pool_.createBuffers(bufferCount);
> -
> - ret = capture_->exportBuffers(&pool_);
> - if (ret) {
> - std::cout << "Failed to export buffers" << std::endl;
> + ret = capture_->exportBuffers(bufferCount, &buffers_);
> + if (ret < 0) {
> + std::cout << "Failed to allocate buffers" << std::endl;
> return TestFail;
> }
>
> - ret = output_->importBuffers(&pool_);
> - if (ret) {
> + ret = output_->importBuffers(bufferCount);
> + if (ret < 0) {
> std::cout << "Failed to import buffers" << std::endl;
> return TestFail;
> }
> @@ -90,7 +88,7 @@ protected:
> return 0;
> }
>
> - void captureBufferReady(Buffer *buffer)
> + void captureBufferReady(FrameBuffer *buffer)
> {
> const FrameMetadata &metadata = buffer->metadata();
>
> @@ -103,7 +101,7 @@ protected:
> framesCaptured_++;
> }
>
> - void outputBufferReady(Buffer *buffer)
> + void outputBufferReady(FrameBuffer *buffer)
> {
> const FrameMetadata &metadata = buffer->metadata();
>
> @@ -122,13 +120,15 @@ protected:
> Timer timeout;
> int ret;
>
> - capture_->bufferReady.connect(this, &BufferSharingTest::captureBufferReady);
> - output_->bufferReady.connect(this, &BufferSharingTest::outputBufferReady);
> + capture_->frameBufferReady.connect(this, &BufferSharingTest::captureBufferReady);
> + output_->frameBufferReady.connect(this, &BufferSharingTest::outputBufferReady);
>
> - std::vector<std::unique_ptr<Buffer>> buffers;
> - buffers = capture_->queueAllBuffers();
> - if (buffers.empty())
> - return TestFail;
> + for (const std::unique_ptr<FrameBuffer> &buffer : buffers_) {
> + if (capture_->queueBuffer(buffer.get())) {
> + std::cout << "Failed to queue buffer" << std::endl;
> + return TestFail;
> + }
> + }
>
> ret = capture_->streamOn();
> if (ret) {
> diff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp
> index f62bbd837b213a0a..a57abed3bd0debc1 100644
> --- a/test/v4l2_videodevice/capture_async.cpp
> +++ b/test/v4l2_videodevice/capture_async.cpp
> @@ -20,7 +20,7 @@ public:
> CaptureAsyncTest()
> : V4L2VideoDeviceTest("vimc", "Raw Capture 0"), frames(0) {}
>
> - void receiveBuffer(Buffer *buffer)
> + void receiveBuffer(FrameBuffer *buffer)
> {
> std::cout << "Buffer received" << std::endl;
> frames++;
> @@ -38,18 +38,18 @@ protected:
> Timer timeout;
> int ret;
>
> - pool_.createBuffers(bufferCount);
> -
> - ret = capture_->exportBuffers(&pool_);
> - if (ret)
> + ret = capture_->exportBuffers(bufferCount, &buffers_);
> + if (ret < 0)
> return TestFail;
>
> - capture_->bufferReady.connect(this, &CaptureAsyncTest::receiveBuffer);
> + capture_->frameBufferReady.connect(this, &CaptureAsyncTest::receiveBuffer);
>
> - std::vector<std::unique_ptr<Buffer>> buffers;
> - buffers = capture_->queueAllBuffers();
> - if (buffers.empty())
> - return TestFail;
> + for (const std::unique_ptr<FrameBuffer> &buffer : buffers_) {
> + if (capture_->queueBuffer(buffer.get())) {
> + std::cout << "Failed to queue buffer" << std::endl;
> + return TestFail;
> + }
> + }
>
> ret = capture_->streamOn();
> if (ret)
> diff --git a/test/v4l2_videodevice/request_buffers.cpp b/test/v4l2_videodevice/request_buffers.cpp
> index c4aedf7b3cd61e80..1dd65b05da430e63 100644
> --- a/test/v4l2_videodevice/request_buffers.cpp
> +++ b/test/v4l2_videodevice/request_buffers.cpp
> @@ -16,17 +16,10 @@ public:
> protected:
> int run()
> {
> - /*
> - * TODO:
> - * Test invalid requests
> - * Test different buffer allocations
> - */
> const unsigned int bufferCount = 8;
>
> - pool_.createBuffers(bufferCount);
> -
> - int ret = capture_->exportBuffers(&pool_);
> - if (ret)
> + int ret = capture_->exportBuffers(bufferCount, &buffers_);
> + if (ret != bufferCount)
> return TestFail;
>
> return TestPass;
> diff --git a/test/v4l2_videodevice/stream_on_off.cpp b/test/v4l2_videodevice/stream_on_off.cpp
> index 7664adc4c1f07046..552df0963633ae4b 100644
> --- a/test/v4l2_videodevice/stream_on_off.cpp
> +++ b/test/v4l2_videodevice/stream_on_off.cpp
> @@ -17,10 +17,8 @@ protected:
> {
> const unsigned int bufferCount = 8;
>
> - pool_.createBuffers(bufferCount);
> -
> - int ret = capture_->exportBuffers(&pool_);
> - if (ret)
> + int ret = capture_->exportBuffers(bufferCount, &buffers_);
> + if (ret < 0)
> return TestFail;
>
> ret = capture_->streamOn();
> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp
> index 442bcac5dc49cc59..43b99c4f7ea9bf26 100644
> --- a/test/v4l2_videodevice/v4l2_m2mdevice.cpp
> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp
> @@ -29,7 +29,7 @@ public:
> {
> }
>
> - void outputBufferComplete(Buffer *buffer)
> + void outputBufferComplete(FrameBuffer *buffer)
> {
> cout << "Received output buffer" << endl;
>
> @@ -39,7 +39,7 @@ public:
> vim2m_->output()->queueBuffer(buffer);
> }
>
> - void receiveCaptureBuffer(Buffer *buffer)
> + void receiveCaptureBuffer(FrameBuffer *buffer)
> {
> cout << "Received capture buffer" << endl;
>
> @@ -112,39 +112,31 @@ protected:
> return TestFail;
> }
>
> - capturePool_.createBuffers(bufferCount);
> - outputPool_.createBuffers(bufferCount);
> -
> - ret = capture->exportBuffers(&capturePool_);
> - if (ret) {
> + ret = capture->exportBuffers(bufferCount, &captureBuffers_);
> + if (ret < 0) {
> cerr << "Failed to export Capture Buffers" << endl;
> return TestFail;
> }
>
> - ret = output->exportBuffers(&outputPool_);
> - if (ret) {
> + ret = output->exportBuffers(bufferCount, &outputBuffers_);
> + if (ret < 0) {
> cerr << "Failed to export Output Buffers" << endl;
> return TestFail;
> }
>
> - capture->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);
> - output->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);
> + capture->frameBufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);
> + output->frameBufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);
>
> - std::vector<std::unique_ptr<Buffer>> captureBuffers;
> - captureBuffers = capture->queueAllBuffers();
> - if (captureBuffers.empty()) {
> - cerr << "Failed to queue all Capture Buffers" << endl;
> - return TestFail;
> + for (const std::unique_ptr<FrameBuffer> &buffer : captureBuffers_) {
> + if (capture->queueBuffer(buffer.get())) {
> + std::cout << "Failed to queue capture buffer" << std::endl;
> + return TestFail;
> + }
> }
>
> - /* We can't "queueAllBuffers()" on an output device, so we do it manually */
> - std::vector<std::unique_ptr<Buffer>> outputBuffers;
> - for (unsigned int i = 0; i < outputPool_.count(); ++i) {
> - Buffer *buffer = new Buffer(i);
> - outputBuffers.emplace_back(buffer);
> - ret = output->queueBuffer(buffer);
> - if (ret) {
> - cerr << "Failed to queue output buffer" << i << endl;
> + for (const std::unique_ptr<FrameBuffer> &buffer : outputBuffers_) {
> + if (output->queueBuffer(buffer.get())) {
> + std::cout << "Failed to queue output buffer" << std::endl;
> return TestFail;
> }
> }
> @@ -202,8 +194,8 @@ private:
> std::shared_ptr<MediaDevice> media_;
> V4L2M2MDevice *vim2m_;
>
> - BufferPool capturePool_;
> - BufferPool outputPool_;
> + std::vector<std::unique_ptr<FrameBuffer>> captureBuffers_;
> + std::vector<std::unique_ptr<FrameBuffer>> outputBuffers_;
>
> unsigned int outputFrames_;
> unsigned int captureFrames_;
> diff --git a/test/v4l2_videodevice/v4l2_videodevice_test.h b/test/v4l2_videodevice/v4l2_videodevice_test.h
> index 34dd231c6d9d108d..9acaceb84fe0a12f 100644
> --- a/test/v4l2_videodevice/v4l2_videodevice_test.h
> +++ b/test/v4l2_videodevice/v4l2_videodevice_test.h
> @@ -41,7 +41,7 @@ protected:
> CameraSensor *sensor_;
> V4L2Subdevice *debayer_;
> V4L2VideoDevice *capture_;
> - BufferPool pool_;
> + std::vector<std::unique_ptr<FrameBuffer>> buffers_;
> };
>
> #endif /* __LIBCAMERA_V4L2_DEVICE_TEST_H_ */
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list