From 3a6c4bd146cc6647daf458bbc048bd861e702f62 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 12 Jun 2019 13:09:57 +0100 Subject: libcamera: Rename V4L2Device to V4L2VideoDevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In preparation of creating a new V4L2Device base class, rename V4L2Device to V4L2VideoDevice. This is a project wide rename without any intended functional change. Signed-off-by: Jacopo Mondi Signed-off-by: Kieran Bingham Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- test/v4l2_device/buffer_sharing.cpp | 186 ---------------------------------- test/v4l2_device/capture_async.cpp | 89 ---------------- test/v4l2_device/double_open.cpp | 41 -------- test/v4l2_device/formats.cpp | 54 ---------- test/v4l2_device/meson.build | 18 ---- test/v4l2_device/request_buffers.cpp | 36 ------- test/v4l2_device/stream_on_off.cpp | 38 ------- test/v4l2_device/v4l2_device_test.cpp | 87 ---------------- test/v4l2_device/v4l2_device_test.h | 42 -------- 9 files changed, 591 deletions(-) delete mode 100644 test/v4l2_device/buffer_sharing.cpp delete mode 100644 test/v4l2_device/capture_async.cpp delete mode 100644 test/v4l2_device/double_open.cpp delete mode 100644 test/v4l2_device/formats.cpp delete mode 100644 test/v4l2_device/meson.build delete mode 100644 test/v4l2_device/request_buffers.cpp delete mode 100644 test/v4l2_device/stream_on_off.cpp delete mode 100644 test/v4l2_device/v4l2_device_test.cpp delete mode 100644 test/v4l2_device/v4l2_device_test.h (limited to 'test/v4l2_device') diff --git a/test/v4l2_device/buffer_sharing.cpp b/test/v4l2_device/buffer_sharing.cpp deleted file mode 100644 index e63ddff8..00000000 --- a/test/v4l2_device/buffer_sharing.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - * - * Validate the function of exporting buffers from a V4L2Device and - * the ability to import them to another V4L2Device instance. - * Ensure that the Buffers can successfully be queued and dequeued - * between both devices. - */ - -#include - -#include -#include -#include -#include - -#include "v4l2_device_test.h" - -class BufferSharingTest : public V4L2DeviceTest -{ -public: - BufferSharingTest() - : V4L2DeviceTest("vivid", "vivid-000-vid-cap"), - output_(nullptr), framesCaptured_(0), framesOutput_(0) {} - -protected: - int init() - { - int ret = V4L2DeviceTest::init(); - if (ret) - return ret; - - /* media_ already represents VIVID */ - MediaEntity *entity = media_->getEntityByName("vivid-000-vid-out"); - if (!entity) - return TestSkip; - - output_ = new V4L2Device(entity); - if (!output_) { - std::cout << "Failed to create output device" << std::endl; - return TestFail; - } - - ret = output_->open(); - if (ret) { - std::cout << "Failed to open output device" << std::endl; - return TestFail; - } - - V4L2DeviceFormat format = {}; - - ret = capture_->getFormat(&format); - if (ret) { - std::cout << "Failed to get capture format" << std::endl; - return TestFail; - } - - ret = output_->setFormat(&format); - if (ret) { - std::cout << "Failed to set output format" << std::endl; - return TestFail; - } - - pool_.createBuffers(bufferCount); - - ret = capture_->exportBuffers(&pool_); - if (ret) { - std::cout << "Failed to export buffers" << std::endl; - return TestFail; - } - - ret = output_->importBuffers(&pool_); - if (ret) { - std::cout << "Failed to import buffers" << std::endl; - return TestFail; - } - - return 0; - } - - void captureBufferReady(Buffer *buffer) - { - std::cout << "Received capture buffer: " << buffer->index() - << " sequence " << buffer->sequence() << std::endl; - - output_->queueBuffer(buffer); - framesCaptured_++; - } - - void outputBufferReady(Buffer *buffer) - { - std::cout << "Received output buffer: " << buffer->index() - << " sequence " << buffer->sequence() << std::endl; - - capture_->queueBuffer(buffer); - framesOutput_++; - } - - int run() - { - EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); - Timer timeout; - int ret; - - capture_->bufferReady.connect(this, &BufferSharingTest::captureBufferReady); - output_->bufferReady.connect(this, &BufferSharingTest::outputBufferReady); - - /* Queue all the buffers to the capture device. */ - for (Buffer &buffer : pool_.buffers()) { - if (capture_->queueBuffer(&buffer)) - return TestFail; - } - - ret = capture_->streamOn(); - if (ret) { - std::cout << "Failed to start streaming on the capture device" << std::endl; - return TestFail; - } - - ret = output_->streamOn(); - if (ret) { - std::cout << "Failed to start streaming on the output device" << std::endl; - return TestFail; - } - - timeout.start(10000); - while (timeout.isRunning()) { - dispatcher->processEvents(); - if (framesCaptured_ > 30 && framesOutput_ > 30) - break; - } - - if ((framesCaptured_ < 1) || (framesOutput_ < 1)) { - std::cout << "Failed to process any frames within timeout." << std::endl; - return TestFail; - } - - if ((framesCaptured_ < 30) || (framesOutput_ < 30)) { - std::cout << "Failed to process 30 frames within timeout." << std::endl; - return TestFail; - } - - ret = capture_->streamOff(); - if (ret) { - std::cout << "Failed to stop streaming on the capture device" << std::endl; - return TestFail; - } - - ret = output_->streamOff(); - if (ret) { - std::cout << "Failed to stop streaming on the output device" << std::endl; - return TestFail; - } - - return TestPass; - } - - void cleanup() - { - std::cout - << "Captured " << framesCaptured_ << " frames and " - << "output " << framesOutput_ << " frames" - << std::endl; - - output_->streamOff(); - output_->releaseBuffers(); - output_->close(); - - delete output_; - - V4L2DeviceTest::cleanup(); - } - -private: - const unsigned int bufferCount = 4; - - V4L2Device *output_; - - unsigned int framesCaptured_; - unsigned int framesOutput_; -}; - -TEST_REGISTER(BufferSharingTest); diff --git a/test/v4l2_device/capture_async.cpp b/test/v4l2_device/capture_async.cpp deleted file mode 100644 index 69b1d5a1..00000000 --- a/test/v4l2_device/capture_async.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - */ - -#include -#include -#include -#include - -#include - -#include "v4l2_device_test.h" - -class CaptureAsyncTest : public V4L2DeviceTest -{ -public: - CaptureAsyncTest() - : V4L2DeviceTest("vimc", "Raw Capture 0"), frames(0) {} - - void receiveBuffer(Buffer *buffer) - { - std::cout << "Received buffer " << buffer->index() << std::endl; - frames++; - - /* Requeue the buffer for further use. */ - capture_->queueBuffer(buffer); - } - -protected: - int run() - { - const unsigned int bufferCount = 8; - - EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); - Timer timeout; - int ret; - - pool_.createBuffers(bufferCount); - - ret = capture_->exportBuffers(&pool_); - if (ret) - return TestFail; - - capture_->bufferReady.connect(this, &CaptureAsyncTest::receiveBuffer); - - /* Queue all the buffers to the device. */ - for (Buffer &b : pool_.buffers()) { - if (capture_->queueBuffer(&b)) - 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); diff --git a/test/v4l2_device/double_open.cpp b/test/v4l2_device/double_open.cpp deleted file mode 100644 index 53850620..00000000 --- a/test/v4l2_device/double_open.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - */ - -#include - -#include "v4l2_device_test.h" - -namespace { - -class DoubleOpen : public V4L2DeviceTest -{ -public: - DoubleOpen() - : V4L2DeviceTest("vimc", "Raw Capture 0") {} -protected: - int run() - { - int ret; - - /* - * Expect failure: The device has already been opened by the - * V4L2DeviceTest base class - */ - ret = capture_->open(); - if (!ret) { - std::cout << "Double open erroneously succeeded" << std::endl; - capture_->close(); - return TestFail; - } - - return TestPass; - } -}; - -} /* namespace */ - -TEST_REGISTER(DoubleOpen); diff --git a/test/v4l2_device/formats.cpp b/test/v4l2_device/formats.cpp deleted file mode 100644 index 6be045ff..00000000 --- a/test/v4l2_device/formats.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 device format handling test - */ - -#include -#include - -#include "v4l2_device.h" - -#include "v4l2_device_test.h" - -using namespace std; -using namespace libcamera; - -class Format : public V4L2DeviceTest -{ -public: - Format() - : V4L2DeviceTest("vimc", "Raw Capture 0") {} -protected: - int run() - { - V4L2DeviceFormat format = {}; - - int ret = capture_->getFormat(&format); - if (ret) { - cerr << "Failed to get format" << endl; - return TestFail; - } - - format.size = { UINT_MAX, UINT_MAX }; - ret = capture_->setFormat(&format); - if (ret) { - cerr << "Failed to set format: image resolution is invalid: " - << "(UINT_MAX x UINT_MAX) but setFormat() should not fail." - << endl; - return TestFail; - } - - if (format.size.width == UINT_MAX || - format.size.height == UINT_MAX) { - cerr << "Failed to update image format = (UINT_MAX x UINT_MAX)" - << endl; - return TestFail; - } - - return TestPass; - } -}; - -TEST_REGISTER(Format); diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build deleted file mode 100644 index de540b1b..00000000 --- a/test/v4l2_device/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -# Tests are listed in order of complexity. -# They are not alphabetically sorted. -v4l2_device_tests = [ - [ 'double_open', 'double_open.cpp' ], - [ 'formats', 'formats.cpp' ], - [ 'request_buffers', 'request_buffers.cpp' ], - [ 'stream_on_off', 'stream_on_off.cpp' ], - [ 'capture_async', 'capture_async.cpp' ], - [ 'buffer_sharing', 'buffer_sharing.cpp' ], -] - -foreach t : v4l2_device_tests - exe = executable(t[0], [t[1], 'v4l2_device_test.cpp'], - dependencies : libcamera_dep, - link_with : test_libraries, - include_directories : test_includes_internal) - test(t[0], exe, suite : 'v4l2_device', is_parallel : false) -endforeach diff --git a/test/v4l2_device/request_buffers.cpp b/test/v4l2_device/request_buffers.cpp deleted file mode 100644 index 7b7b06b2..00000000 --- a/test/v4l2_device/request_buffers.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - */ - -#include "v4l2_device_test.h" - -class RequestBuffersTest : public V4L2DeviceTest -{ -public: - RequestBuffersTest() - : V4L2DeviceTest("vimc", "Raw Capture 0") {} - -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) - return TestFail; - - return TestPass; - } -}; - -TEST_REGISTER(RequestBuffersTest); diff --git a/test/v4l2_device/stream_on_off.cpp b/test/v4l2_device/stream_on_off.cpp deleted file mode 100644 index b158b8e4..00000000 --- a/test/v4l2_device/stream_on_off.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - */ - -#include "v4l2_device_test.h" - -class StreamOnStreamOffTest : public V4L2DeviceTest -{ -public: - StreamOnStreamOffTest() - : V4L2DeviceTest("vimc", "Raw Capture 0") {} -protected: - int run() - { - const unsigned int bufferCount = 8; - - pool_.createBuffers(bufferCount); - - int ret = capture_->exportBuffers(&pool_); - if (ret) - return TestFail; - - ret = capture_->streamOn(); - if (ret) - return TestFail; - - ret = capture_->streamOff(); - if (ret) - return TestFail; - - return TestPass; - } -}; - -TEST_REGISTER(StreamOnStreamOffTest); diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp deleted file mode 100644 index baad48f8..00000000 --- a/test/v4l2_device/v4l2_device_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * libcamera V4L2 API tests - */ - -#include -#include - -#include "v4l2_device_test.h" - -#include "device_enumerator.h" -#include "media_device.h" - -using namespace std; -using namespace libcamera; - -bool exists(const std::string &path) -{ - struct stat sb; - - if (stat(path.c_str(), &sb) == 0) - return true; - - return false; -} - -int V4L2DeviceTest::init() -{ - enumerator_ = DeviceEnumerator::create(); - if (!enumerator_) { - cerr << "Failed to create device enumerator" << endl; - return TestFail; - } - - if (enumerator_->enumerate()) { - cerr << "Failed to enumerate media devices" << endl; - return TestFail; - } - - DeviceMatch dm(driver_); - dm.add(entity_); - - media_ = enumerator_->search(dm); - if (!media_) - return TestSkip; - - MediaEntity *entity = media_->getEntityByName(entity_); - if (!entity) - return TestSkip; - - capture_ = new V4L2Device(entity); - if (!capture_) - return TestFail; - - if (!media_->acquire()) - return TestFail; - - int ret = media_->disableLinks(); - media_->release(); - if (ret) - return TestFail; - - if (capture_->open()) - return TestFail; - - V4L2DeviceFormat format = {}; - if (capture_->getFormat(&format)) - return TestFail; - - format.size.width = 640; - format.size.height = 480; - if (capture_->setFormat(&format)) - return TestFail; - - return TestPass; -} - -void V4L2DeviceTest::cleanup() -{ - capture_->streamOff(); - capture_->releaseBuffers(); - capture_->close(); - - delete capture_; -}; diff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h deleted file mode 100644 index 651c005f..00000000 --- a/test/v4l2_device/v4l2_device_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2018, Google Inc. - * - * vl42device_test.h - libcamera v4l2device test base class - */ -#ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_ -#define __LIBCAMERA_V4L2_DEVICE_TEST_H_ - -#include - -#include - -#include "test.h" - -#include "device_enumerator.h" -#include "media_device.h" -#include "v4l2_device.h" - -using namespace libcamera; - -class V4L2DeviceTest : public Test -{ -public: - V4L2DeviceTest(const char *driver, const char *entity) - : driver_(driver), entity_(entity), capture_(nullptr) - { - } - -protected: - int init(); - void cleanup(); - - std::string driver_; - std::string entity_; - std::unique_ptr enumerator_; - std::shared_ptr media_; - V4L2Device *capture_; - BufferPool pool_; -}; - -#endif /* __LIBCAMERA_V4L2_DEVICE_TEST_H_ */ -- cgit v1.2.1