An attempt at getting image data back
This commit is contained in:
83
spider-cam/libcamera/test/v4l2_subdevice/list_formats.cpp
Normal file
83
spider-cam/libcamera/test/v4l2_subdevice/list_formats.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* libcamera V4L2 Subdevice format handling test
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
|
||||
#include <libcamera/base/utils.h>
|
||||
|
||||
#include "libcamera/internal/v4l2_subdevice.h"
|
||||
|
||||
#include "v4l2_subdevice_test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
|
||||
/* List image formats on the "Scaler" subdevice of vimc media device. */
|
||||
|
||||
class ListFormatsTest : public V4L2SubdeviceTest
|
||||
{
|
||||
protected:
|
||||
int run() override;
|
||||
|
||||
private:
|
||||
void printFormats(unsigned int pad, unsigned code,
|
||||
const std::vector<SizeRange> &sizes);
|
||||
};
|
||||
|
||||
void ListFormatsTest::printFormats(unsigned int pad,
|
||||
unsigned int code,
|
||||
const std::vector<SizeRange> &sizes)
|
||||
{
|
||||
cout << "Enumerate formats on pad " << pad << endl;
|
||||
for (const SizeRange &size : sizes) {
|
||||
cout << " mbus code: " << utils::hex(code, 4) << endl;
|
||||
cout << " min width: " << dec << size.min.width << endl;
|
||||
cout << " min height: " << dec << size.min.height << endl;
|
||||
cout << " max width: " << dec << size.max.width << endl;
|
||||
cout << " max height: " << dec << size.max.height << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int ListFormatsTest::run()
|
||||
{
|
||||
/* List all formats available on existing "Scaler" pads. */
|
||||
V4L2Subdevice::Formats formats;
|
||||
|
||||
formats = scaler_->formats(0);
|
||||
if (formats.empty()) {
|
||||
cerr << "Failed to list formats on pad 0 of subdevice "
|
||||
<< scaler_->entity()->name() << endl;
|
||||
return TestFail;
|
||||
}
|
||||
for (unsigned int code : utils::map_keys(formats))
|
||||
printFormats(0, code, formats[code]);
|
||||
|
||||
formats = scaler_->formats(1);
|
||||
if (formats.empty()) {
|
||||
cerr << "Failed to list formats on pad 1 of subdevice "
|
||||
<< scaler_->entity()->name() << endl;
|
||||
return TestFail;
|
||||
}
|
||||
for (unsigned int code : utils::map_keys(formats))
|
||||
printFormats(1, code, formats[code]);
|
||||
|
||||
/* List format on a non-existing pad, format vector shall be empty. */
|
||||
formats = scaler_->formats(2);
|
||||
if (!formats.empty()) {
|
||||
cerr << "Listing formats on non-existing pad 2 of subdevice "
|
||||
<< scaler_->entity()->name()
|
||||
<< " should return an empty format list" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
return TestPass;
|
||||
}
|
||||
|
||||
TEST_REGISTER(ListFormatsTest)
|
||||
14
spider-cam/libcamera/test/v4l2_subdevice/meson.build
Normal file
14
spider-cam/libcamera/test/v4l2_subdevice/meson.build
Normal file
@@ -0,0 +1,14 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
v4l2_subdevice_tests = [
|
||||
{'name': 'list_formats', 'sources': ['list_formats.cpp']},
|
||||
{'name': 'test_formats', 'sources': ['test_formats.cpp']},
|
||||
]
|
||||
|
||||
foreach test : v4l2_subdevice_tests
|
||||
exe = executable(test['name'], test['sources'], 'v4l2_subdevice_test.cpp',
|
||||
dependencies : libcamera_private,
|
||||
link_with : test_libraries,
|
||||
include_directories : test_includes_internal)
|
||||
test(test['name'], exe, suite : 'v4l2_subdevice', is_parallel : false)
|
||||
endforeach
|
||||
78
spider-cam/libcamera/test/v4l2_subdevice/test_formats.cpp
Normal file
78
spider-cam/libcamera/test/v4l2_subdevice/test_formats.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* libcamera V4L2 Subdevice format handling test
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <limits.h>
|
||||
|
||||
#include "libcamera/internal/v4l2_subdevice.h"
|
||||
|
||||
#include "v4l2_subdevice_test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
|
||||
/* Test format handling on the "Scaler" subdevice of vimc media device. */
|
||||
|
||||
class FormatHandlingTest : public V4L2SubdeviceTest
|
||||
{
|
||||
protected:
|
||||
int run() override;
|
||||
};
|
||||
|
||||
int FormatHandlingTest::run()
|
||||
{
|
||||
V4L2SubdeviceFormat format = {};
|
||||
|
||||
/*
|
||||
* Get format on a non-existing Scaler pad: expect failure.
|
||||
*/
|
||||
int ret = scaler_->getFormat(2, &format);
|
||||
if (!ret) {
|
||||
cerr << "Getting format on a non existing pad should fail" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
ret = scaler_->getFormat(0, &format);
|
||||
if (ret) {
|
||||
cerr << "Failed to get format" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set unrealistic image resolutions and make sure it gets updated.
|
||||
*/
|
||||
format.size = { UINT_MAX, UINT_MAX };
|
||||
ret = scaler_->setFormat(0, &format);
|
||||
if (ret) {
|
||||
cerr << "Failed to set format: image resolution is wrong, 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" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
format.size = { 0, 0 };
|
||||
ret = scaler_->setFormat(0, &format);
|
||||
if (ret) {
|
||||
cerr << "Failed to set format: image resolution is wrong, but "
|
||||
<< "setFormat() should not fail." << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (format.size.isNull()) {
|
||||
cerr << "Failed to update image format" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
return TestPass;
|
||||
}
|
||||
|
||||
TEST_REGISTER(FormatHandlingTest)
|
||||
@@ -0,0 +1,68 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* VIMC-based V4L2 subdevice test
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libcamera/internal/device_enumerator.h"
|
||||
#include "libcamera/internal/media_device.h"
|
||||
#include "libcamera/internal/v4l2_subdevice.h"
|
||||
|
||||
#include "v4l2_subdevice_test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
|
||||
/*
|
||||
* This test runs on vimc media device. For a description of vimc, in the
|
||||
* context of libcamera testing, please refer to
|
||||
* 'test/media_device/media_device_link_test.cpp' file.
|
||||
*
|
||||
* If the vimc module is not loaded, the test gets skipped.
|
||||
*/
|
||||
|
||||
int V4L2SubdeviceTest::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("vimc");
|
||||
media_ = enumerator_->search(dm);
|
||||
if (!media_) {
|
||||
cerr << "Unable to find \'vimc\' media device node" << endl;
|
||||
return TestSkip;
|
||||
}
|
||||
|
||||
MediaEntity *videoEntity = media_->getEntityByName("Scaler");
|
||||
if (!videoEntity) {
|
||||
cerr << "Unable to find media entity 'Scaler'" << endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
scaler_ = new V4L2Subdevice(videoEntity);
|
||||
if (scaler_->open()) {
|
||||
cerr << "Unable to open video subdevice "
|
||||
<< scaler_->entity()->deviceNode() << endl;
|
||||
return TestSkip;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void V4L2SubdeviceTest::cleanup()
|
||||
{
|
||||
delete scaler_;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* VIMC-based V4L2 subdevice test
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/framebuffer.h>
|
||||
|
||||
#include "libcamera/internal/device_enumerator.h"
|
||||
#include "libcamera/internal/media_device.h"
|
||||
#include "libcamera/internal/v4l2_subdevice.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
class V4L2SubdeviceTest : public Test
|
||||
{
|
||||
public:
|
||||
V4L2SubdeviceTest()
|
||||
: scaler_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
int init() override;
|
||||
void cleanup() override;
|
||||
|
||||
std::unique_ptr<libcamera::DeviceEnumerator> enumerator_;
|
||||
std::shared_ptr<libcamera::MediaDevice> media_;
|
||||
libcamera::V4L2Subdevice *scaler_;
|
||||
};
|
||||
Reference in New Issue
Block a user