libcamera/test/v4l2_videodevice/capture_async.cpp
Niklas Söderlund 66d4929c73 libcamera: v4l2_videodevice: Remove Buffer interface
The Buffer interface is no longer in use and can be removed. While doing
so clean up the two odd names (dequeueFrameBuffer() and
queuedFrameBuffers_) that had to be used when adding the FrameBuffer
interface.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-12 16:10:38 +01:00

88 lines
1.8 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/event_dispatcher.h>
#include <libcamera/timer.h>
#include "thread.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_->exportBuffers(bufferCount, &buffers_);
if (ret < 0)
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);