libcamera/test/libtest/buffer_source.cpp
Laurent Pinchart 395d43d6d7 libcamera: v4l2_videodevice: Drop toV4L2PixelFormat()
The V4L2VideoDevice::toV4L2PixelFormat() function is incorrectly
implemented, as it will pick a multi-planar format if the device
supports the multi-planar API, even if only single-planar formats are
supported. This currently works because the implementation calls
V4L2PixelFormat::fromPixelFormat(), which ignores the multiplanar
argument and always returns a single-planar format.

Fixing this isn't trivial. As we don't need to support multi-planar V4L2
formats at this point, drop the function instead of pretending
everything is fine, and call V4L2PixelFormat::fromPixelFormat() directly
from pipeline handlers. As the single-planar case is the most common,
set the multiplanar argument to false by default to avoid long lines.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
2021-09-07 19:17:46 +03:00

92 lines
2 KiB
C++

/* 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"
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 = V4L2PixelFormat::fromPixelFormat(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_;
}