summaryrefslogtreecommitdiff
path: root/src/apps/ipa-verify
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-07-03 15:49:54 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2024-07-03 16:41:41 +0200
commit196abb8d1d6e0fe9d190315e72a85eb12d16a554 (patch)
tree465ebd4d269a6bac215b06edf2ecdabc9d9b37de /src/apps/ipa-verify
parent27e4d3fc3a4dc3e6ddaef17d6e7c8f5e56c79507 (diff)
ipa: rkisp1: Move ov4689 and ov5640 black levels into sensor helpers
Move black levels for tuning files that contained a BLC block into the camera sensor helpers. ov4689.yaml had 66@12bit while the datasheet states 64@12bit. Use the value from the datasheet (scaled to 16bit). ov5640.yaml had 256@12bit while the datasheet states 16@10bit. Looking at the commit message the 256 most likely stems from the imx219 tuning file and 16@10bit is the same as the 64@12bit from the ov4689. This seems more likely and is therefore used. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/apps/ipa-verify')
0 files changed, 0 insertions, 0 deletions
/a> 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * v4l2_camera.cpp - V4L2 compatibility camera
 */

#include "v4l2_camera.h"

#include <errno.h>

#include "log.h"
#include "utils.h"

using namespace libcamera;

LOG_DECLARE_CATEGORY(V4L2Compat);

V4L2FrameMetadata::V4L2FrameMetadata(Buffer *buffer)
	: index_(buffer->index()), bytesused_(buffer->bytesused()),
	  timestamp_(buffer->timestamp()), sequence_(buffer->sequence()),
	  status_(buffer->status())
{
}

V4L2Camera::V4L2Camera(std::shared_ptr<Camera> camera)
	: camera_(camera), isRunning_(false)
{
	camera_->requestCompleted.connect(this, &V4L2Camera::requestComplete);
}

V4L2Camera::~V4L2Camera()
{
	camera_->release();
}

int V4L2Camera::open()
{
	/* \todo Support multiple open. */
	if (camera_->acquire() < 0) {
		LOG(V4L2Compat, Error) << "Failed to acquire camera";
		return -EINVAL;
	}

	config_ = camera_->generateConfiguration({ StreamRole::Viewfinder });
	if (!config_) {
		camera_->release();
		return -EINVAL;
	}

	return 0;
}

void V4L2Camera::close()
{
	camera_->release();
}

void V4L2Camera::getStreamConfig(StreamConfiguration *streamConfig)
{
	*streamConfig = config_->at(0);
}

std::vector<V4L2FrameMetadata> V4L2Camera::completedBuffers()
{
	std::vector<V4L2FrameMetadata> v;

	bufferLock_.lock();
	for (std::unique_ptr<V4L2FrameMetadata> &metadata : completedBuffers_)
		v.push_back(*metadata.get());
	completedBuffers_.clear();
	bufferLock_.unlock();

	return v;
}

void V4L2Camera::requestComplete(Request *request)
{
	if (request->status() == Request::RequestCancelled)
		return;

	/* We only have one stream at the moment. */
	bufferLock_.lock();
	Buffer *buffer = request->buffers().begin()->second;
	std::unique_ptr<V4L2FrameMetadata> metadata =
		utils::make_unique<V4L2FrameMetadata>(buffer);
	completedBuffers_.push_back(std::move(metadata));
	bufferLock_.unlock();

	bufferSema_.release();
}

int V4L2Camera::configure(StreamConfiguration *streamConfigOut,
			  const Size &size, PixelFormat pixelformat,
			  unsigned int bufferCount)
{
	StreamConfiguration &streamConfig = config_->at(0);
	streamConfig.size.width = size.width;
	streamConfig.size.height = size.height;
	streamConfig.pixelFormat = pixelformat;
	streamConfig.bufferCount = bufferCount;
	/* \todo memoryType (interval vs external) */

	CameraConfiguration::Status validation = config_->validate();
	if (validation == CameraConfiguration::Invalid) {
		LOG(V4L2Compat, Debug) << "Configuration invalid";
		return -EINVAL;
	}
	if (validation == CameraConfiguration::Adjusted)
		LOG(V4L2Compat, Debug) << "Configuration adjusted";

	LOG(V4L2Compat, Debug) << "Validated configuration is: "
			      << streamConfig.toString();

	int ret = camera_->configure(config_.get());
	if (ret < 0)
		return ret;

	*streamConfigOut = config_->at(0);

	return 0;
}

int V4L2Camera::allocBuffers(unsigned int count)
{
	int ret = camera_->allocateBuffers();
	return ret == -EACCES ? -EBUSY : ret;
}

void V4L2Camera::freeBuffers()
{
	camera_->freeBuffers();
}

FileDescriptor V4L2Camera::getBufferFd(unsigned int index)
{
	Stream *stream = *camera_->streams().begin();