libcamera/test/v4l2_videodevice/capture_async.cpp
Laurent Pinchart 6a31a8d8e2 libcamera: buffer: Rename buffer.h to framebuffer.h
libcamera names header files based on the classes they define. The
buffer.h file is an exception. Rename it to framebuffer.h.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-11 17:42:02 +03: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/framebuffer.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)