/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019-2020, Raspberry Pi (Trading) Ltd.
*
* raspberrypi.cpp - Pipeline handler for Raspberry Pi devices
*/
#include <algorithm>
#include <assert.h>
#include <fcntl.h>
#include <mutex>
#include <queue>
#include <sys/mman.h>
#include <unordered_set>
#include <libcamera/camera.h>
#include <libcamera/control_ids.h>
#include <libcamera/file_descriptor.h>
#include <libcamera/formats.h>
#include <libcamera/ipa/raspberrypi.h>
#include <libcamera/logging.h>
#include <libcamera/property_ids.h>
#include <libcamera/request.h>
#include <linux/videodev2.h>
#include "libcamera/internal/bayer_format.h"
#include "libcamera/internal/camera_sensor.h"
#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/ipa_manager.h"
#include "libcamera/internal/media_device.h"
#include "libcamera/internal/pipeline_handler.h"
#include "libcamera/internal/utils.h"
#include "libcamera/internal/v4l2_controls.h"
#include "libcamera/internal/v4l2_videodevice.h"
#include "dma_heaps.h"
#include "rpi_stream.h"
#include "staggered_ctrl.h"
namespace libcamera {
LOG_DEFINE_CATEGORY(RPI)
namespace {
bool isRaw(PixelFormat &pixFmt)
{
/*
* The isRaw test might be redundant right now the pipeline handler only
* supports RAW sensors. Leave it in for now, just as a sanity check.
*/
const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
if (!info.isValid())
return false;
return info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
}
double scoreFormat(double desired, double actual)
{
double score = desired - actual;
/* Smaller desired dimensions are preferred. */
if (score < 0.0)
score = (-score) / 8;
/* Penalise non-exact matches. */
if (actual != desired)
score *= 2;
return score;
}
V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap,
const Size &req)
{
double bestScore = std::numeric_limits<double>::max(), score;
V4L2DeviceFormat bestMode;
|