v4l2_subdevice.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* v4l2_subdevice.h - V4L2 Subdevice
*/
#ifndef __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
#define __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
#include <string>
#include <vector>
#include <libcamera/geometry.h>
#include "libcamera/internal/formats.h"
#include "libcamera/internal/log.h"
#include "libcamera/internal/media_object.h"
#include "libcamera/internal/v4l2_device.h"
namespace libcamera {
class MediaDevice;
struct V4L2SubdeviceFormat {
uint32_t mbus_code;
Size size;
const std::string toString() const;
uint8_t bitsPerPixel() const;
};
class V4L2Subdevice : public V4L2Device
{
public:
enum Whence {
ActiveFormat,
TryFormat,
};
explicit V4L2Subdevice(const MediaEntity *entity);
V4L2Subdevice(const V4L2Subdevice &) = delete;
V4L2Subdevice &operator=(const V4L2Subdevice &) = delete;
~V4L2Subdevice();
int open();
const MediaEntity *entity() const { return entity_; }
int getSelection(unsigned int pad, unsigned int target,
Rectangle *rect);
int setSelection(unsigned int pad, unsigned int target,
Rectangle *rect);
ImageFormats formats(unsigned int pad);
int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
Whence whence = ActiveFormat);
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
Whence whence = ActiveFormat);
static V4L2Subdevice *fromEntityName(const MediaDevice *media,
const std::string &entity);
protected:
std::string logPrefix() const override;
private:
std::vector<unsigned int> enumPadCodes(unsigned int pad);
std::vector<SizeRange> enumPadSizes(unsigned int pad,
unsigned int code);
const MediaEntity *entity_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__ */
libcamera::ImageFormats
Describe V4L2Device and V4L2SubDevice image formats.
Definition: formats.h:22
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:25
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:86
libcamera::V4L2Device
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:22
libcamera::V4L2Subdevice
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:33
libcamera::V4L2Subdevice::open
int open()
Open a V4L2 subdevice.
Definition: v4l2_subdevice.cpp:247
libcamera::V4L2Subdevice::fromEntityName
static V4L2Subdevice * fromEntityName(const MediaDevice *media, const std::string &entity)
Create a new video subdevice instance from entity in media device media.
Definition: v4l2_subdevice.cpp:448
libcamera::V4L2Subdevice::setSelection
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Set selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:304
libcamera::V4L2Subdevice::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_subdevice.cpp:458
libcamera::V4L2Subdevice::getSelection
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Get selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:268
libcamera::V4L2Subdevice::Whence
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:35
libcamera::V4L2Subdevice::ActiveFormat
@ ActiveFormat
The format operation applies to ACTIVE formats.
Definition: v4l2_subdevice.h:36
libcamera::V4L2Subdevice::TryFormat
@ TryFormat
The format operation applies to TRY formats.
Definition: v4l2_subdevice.h:37
libcamera::V4L2Subdevice::setFormat
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence=ActiveFormat)
Set an image format on one of the V4L2 subdevice pads.
Definition: v4l2_subdevice.cpp:411
libcamera::V4L2Subdevice::formats
ImageFormats formats(unsigned int pad)
Enumerate all media bus codes and frame sizes on a pad.
Definition: v4l2_subdevice.cpp:343
libcamera::V4L2Subdevice::V4L2Subdevice
V4L2Subdevice(const MediaEntity *entity)
Create a V4L2 subdevice from a MediaEntity using its device node path.
Definition: v4l2_subdevice.cpp:233
libcamera::V4L2Subdevice::getFormat
int getFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence=ActiveFormat)
Retrieve the image format set on one of the V4L2 subdevice pads.
Definition: v4l2_subdevice.cpp:376
libcamera::V4L2Subdevice::entity
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:47
geometry.h
Data structures related to geometric objects.
formats.h
Types and helper methods to handle libcamera image formats.
log.h
Logging infrastructure.
media_object.h
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
libcamera::Size
Describe a two-dimensional size.
Definition: geometry.h:30
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:24
libcamera::V4L2SubdeviceFormat::mbus_code
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:25
libcamera::V4L2SubdeviceFormat::toString
const std::string toString() const
Assemble and return a string describing the format.
Definition: v4l2_subdevice.cpp:174
libcamera::V4L2SubdeviceFormat::bitsPerPixel
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition: v4l2_subdevice.cpp:194
libcamera::V4L2SubdeviceFormat::size
Size size
The image size in pixels.
Definition: v4l2_subdevice.h:26
v4l2_device.h
Common base for V4L2 devices and subdevices.