libcamera/test/v4l2_videodevice/capture_async.cpp
Kieran Bingham 27aff949fb libcamera/base: Move extended base functionality
Move the functionality for the following components to the new
base support library:

 - BoundMethod
 - EventDispatcher
 - EventDispatcherPoll
 - Log
 - Message
 - Object
 - Signal
 - Semaphore
 - Thread
 - Timer

While it would be preferable to see these split to move one component
per commit, these components are all interdependent upon each other,
which leaves us with one big change performing the move for all of them.

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-06-25 16:11:08 +01:00

91 lines
1.9 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* libcamera V4L2 API tests
*/
#include <iostream>
#include <libcamera/buffer.h>
#include <libcamera/base/event_dispatcher.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>
#include "v4l2_videodevice_test.h"
class CaptureAsyncTest : public V4L2VideoDeviceTest
{
public:
CaptureAsyncTest()
: V4L2VideoDeviceTest("vimc", "Raw Capture 0"), frames(0) {}
void receiveBuffer(FrameBuffer *buffer)
{
std::cout << "Buffer received" << std::endl;
frames++;
/* Requeue the buffer for further use. */
capture_->queueBuffer(buffer);
}
protected:
int run()
{
const unsigned int bufferCount = 8;
EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
Timer timeout;
int ret;
ret = capture_->allocateBuffers(bufferCount, &buffers_);
if (ret < 0) {
std::cout << "Failed to allocate buffers" << std::endl;
return TestFail;
}
capture_->bufferReady.connect(this, &CaptureAsyncTest::receiveBuffer);
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)
return TestFail;
timeout.start(10000);
while (timeout.isRunning()) {
dispatcher->processEvents();
if (frames > 30)
break;
}
if (frames < 1) {
std::cout << "Failed to capture any frames within timeout." << std::endl;
return TestFail;
}
if (frames < 30) {
std::cout << "Failed to capture 30 frames within timeout." << std::endl;
return TestFail;
}
std::cout << "Processed " << frames << " frames" << std::endl;
ret = capture_->streamOff();
if (ret)
return TestFail;
return TestPass;
}
private:
unsigned int frames;
};
TEST_REGISTER(CaptureAsyncTest)