summaryrefslogtreecommitdiff
path: root/test/camera
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-02-24 20:12:45 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-03-06 17:45:48 +0100
commit257df552a454d7afdc339ef88040e986400d2d89 (patch)
tree85f68de72ec4564aeedc6ef3f47aaa3bb2c3e695 /test/camera
parent42a00cb6172230b822f5c8a910b73e94d4be84cf (diff)
test: Extract BufferSource class out of camera tests to libtest
The BufferSource class can be used by other tests other then the camera buffer importer test, move it to libtest. The only changes to BufferSource is for it to be allowed to be split in a header and source file. This change makes it necessary for libtest to have access to internal libcamera headers. As the internal headers already are accessible to all test cases this does not increase the exposure of libcamera internals to the test cases. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'test/camera')
-rw-r--r--test/camera/buffer_import.cpp95
1 files changed, 1 insertions, 94 deletions
diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp
index 6997ea78..3f392cdc 100644
--- a/test/camera/buffer_import.cpp
+++ b/test/camera/buffer_import.cpp
@@ -16,6 +16,7 @@
#include "media_device.h"
#include "v4l2_videodevice.h"
+#include "buffer_source.h"
#include "camera_test.h"
#include "test.h"
@@ -23,100 +24,6 @@ using namespace libcamera;
namespace {
-/* A provider of external buffers, suitable for import by a Camera. */
-class BufferSource
-{
-public:
- BufferSource()
- : video_(nullptr)
- {
- }
-
- ~BufferSource()
- {
- if (video_) {
- video_->releaseBuffers();
- video_->close();
- }
-
- delete video_;
- video_ = nullptr;
-
- if (media_)
- media_->release();
- }
-
- int allocate(const StreamConfiguration &config)
- {
- /* Locate and open the video device. */
- std::string videoDeviceName = "vivid-000-vid-out";
-
- std::unique_ptr<DeviceEnumerator> enumerator =
- DeviceEnumerator::create();
- if (!enumerator) {
- std::cout << "Failed to create device enumerator" << std::endl;
- return TestFail;
- }
-
- if (enumerator->enumerate()) {
- std::cout << "Failed to enumerate media devices" << std::endl;
- return TestFail;
- }
-
- DeviceMatch dm("vivid");
- dm.add(videoDeviceName);
-
- media_ = enumerator->search(dm);
- if (!media_) {
- std::cout << "No vivid output device available" << std::endl;
- return TestSkip;
- }
-
- video_ = V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName);
- if (!video_) {
- std::cout << "Failed to get video device from entity "
- << videoDeviceName << std::endl;
- return TestFail;
- }
-
- if (video_->open()) {
- std::cout << "Unable to open " << videoDeviceName << std::endl;
- return TestFail;
- }
-
- /* Configure the format. */
- V4L2DeviceFormat format;
- if (video_->getFormat(&format)) {
- std::cout << "Failed to get format on output device" << std::endl;
- return TestFail;
- }
-
- format.size = config.size;
- format.fourcc = V4L2VideoDevice::toV4L2Fourcc(config.pixelFormat, false);
- if (video_->setFormat(&format)) {
- std::cout << "Failed to set format on output device" << std::endl;
- return TestFail;
- }
-
- if (video_->exportBuffers(config.bufferCount, &buffers_) < 0) {
- std::cout << "Failed to export buffers" << std::endl;
- return TestFail;
- }
-
- return TestPass;
- }
-
- const std::vector<std::unique_ptr<FrameBuffer>> &buffers()
- {
- return buffers_;
- }
-
-private:
- std::shared_ptr<MediaDevice> media_;
- V4L2VideoDevice *video_;
- std::vector<std::unique_ptr<FrameBuffer>> buffers_;
-};
-
class BufferImportTest : public CameraTest, public Test
{
public: