An attempt at getting image data back

This commit is contained in:
2024-07-14 00:27:33 +02:00
parent e026bc93f7
commit 6452d2e774
1314 changed files with 218350 additions and 38 deletions

View File

@@ -0,0 +1,94 @@
/* 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 <memory>
#include "libcamera/internal/device_enumerator.h"
#include "test.h"
using namespace libcamera;
BufferSource::BufferSource()
{
}
BufferSource::~BufferSource()
{
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;
}
std::unique_ptr<V4L2VideoDevice> 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 = video->toV4L2PixelFormat(config.pixelFormat);
if (video->setFormat(&format)) {
std::cout << "Failed to set format on output device" << std::endl;
return TestFail;
}
if (video->allocateBuffers(config.bufferCount, &buffers_) < 0) {
std::cout << "Failed to allocate buffers" << std::endl;
return TestFail;
}
video->close();
return TestPass;
}
const std::vector<std::unique_ptr<FrameBuffer>> &BufferSource::buffers()
{
return buffers_;
}

View File

@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2020, Google Inc.
*
* libcamera camera test helper to create FrameBuffers
*/
#pragma once
#include <libcamera/stream.h>
#include "libcamera/internal/media_device.h"
#include "libcamera/internal/v4l2_videodevice.h"
class BufferSource
{
public:
BufferSource();
~BufferSource();
int allocate(const libcamera::StreamConfiguration &config);
const std::vector<std::unique_ptr<libcamera::FrameBuffer>> &buffers();
private:
std::shared_ptr<libcamera::MediaDevice> media_;
std::vector<std::unique_ptr<libcamera::FrameBuffer>> buffers_;
};

View File

@@ -0,0 +1,55 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* libcamera Camera API tests
*/
#include <iostream>
#include "camera_test.h"
#include "test.h"
using namespace libcamera;
using namespace std;
CameraTest::CameraTest(const char *name, bool isolate)
{
cm_ = new CameraManager();
if (isolate)
setenv("LIBCAMERA_IPA_FORCE_ISOLATION", "1", 1);
if (cm_->start()) {
cerr << "Failed to start camera manager" << endl;
status_ = TestFail;
return;
}
camera_ = cm_->get(name);
if (!camera_) {
cerr << "Can not find '" << name << "' camera" << endl;
status_ = TestSkip;
return;
}
/* Sanity check that the camera has streams. */
if (camera_->streams().empty()) {
cerr << "Camera has no stream" << endl;
status_ = TestFail;
return;
}
status_ = TestPass;
}
CameraTest::~CameraTest()
{
if (camera_) {
camera_->release();
camera_.reset();
}
cm_->stop();
delete cm_;
}

View File

@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* libcamera camera test base class
*/
#pragma once
#include <memory>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
class CameraTest
{
public:
CameraTest(const char *name, bool isolate = false);
~CameraTest();
protected:
libcamera::CameraManager *cm_;
std::shared_ptr<libcamera::Camera> camera_;
int status_;
};

View File

@@ -0,0 +1,24 @@
# SPDX-License-Identifier: CC0-1.0
libtest_sources = files([
'buffer_source.cpp',
'camera_test.cpp',
'test.cpp',
])
libtest_includes = include_directories('.')
test_includes_public = [
libtest_includes,
]
test_includes_internal = [
test_includes_public,
]
libtest = static_library('libtest', libtest_sources,
dependencies : libcamera_private,
include_directories : test_includes_internal)
test_libraries = [libtest]

View File

@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* libcamera test base class
*/
#include <stdlib.h>
#include "test.h"
Test::Test()
{
}
Test::~Test()
{
}
void Test::setArgs([[maybe_unused]] int argc, char *argv[])
{
self_ = argv[0];
}
int Test::execute()
{
int ret;
ret = init();
if (ret)
return ret;
ret = run();
cleanup();
return ret;
}

View File

@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* libcamera test base class
*/
#pragma once
#include <sstream>
#include <string>
enum TestStatus {
TestPass = 0,
TestFail = -1,
TestSkip = 77,
};
class Test
{
public:
Test();
virtual ~Test();
void setArgs(int argc, char *argv[]);
int execute();
const std::string &self() const { return self_; }
protected:
virtual int init() { return 0; }
virtual int run() = 0;
virtual void cleanup() {}
private:
std::string self_;
};
#define TEST_REGISTER(Klass) \
int main(int argc, char *argv[]) \
{ \
Klass klass; \
klass.setArgs(argc, argv); \
return klass.execute(); \
}