summaryrefslogtreecommitdiff
path: root/test/libtest/buffer_source.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libtest/buffer_source.cpp')
-rw-r--r--test/libtest/buffer_source.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp
new file mode 100644
index 00000000..066049d3
--- /dev/null
+++ b/test/libtest/buffer_source.cpp
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2020, Google Inc.
+ *
+ * A provider of external buffers, suitable for use in tests.
+ */
+
+#include "buffer_source.h"
+
+#include <iostream>
+
+#include "device_enumerator.h"
+
+#include "test.h"
+
+BufferSource::BufferSource()
+ : video_(nullptr)
+{
+}
+
+BufferSource::~BufferSource()
+{
+ if (video_) {
+ video_->releaseBuffers();
+ video_->close();
+ }
+
+ delete video_;
+ video_ = nullptr;
+
+ if (media_)
+ media_->release();
+}
+
+int BufferSource::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>> &BufferSource::buffers()
+{
+ return buffers_;
+}