libcamera: include/libcamera/internal/v4l2_subdevice.h Source File

libcamera v0.1.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
v4l2_subdevice.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2019, Google Inc.
4 *
5 * v4l2_subdevice.h - V4L2 Subdevice
6 */
7
8#pragma once
9
10#include <memory>
11#include <optional>
12#include <ostream>
13#include <string>
14#include <vector>
15
16#include <linux/v4l2-subdev.h>
17
18#include <libcamera/base/class.h>
19#include <libcamera/base/log.h>
20
21#include <libcamera/color_space.h>
22#include <libcamera/geometry.h>
23
24#include "libcamera/internal/formats.h"
25#include "libcamera/internal/media_object.h"
26#include "libcamera/internal/v4l2_device.h"
27
28namespace libcamera {
29
30class MediaDevice;
31
32 struct V4L2SubdeviceCapability final : v4l2_subdev_capability {
33 bool isReadOnly() const
34 {
35 return capabilities & V4L2_SUBDEV_CAP_RO_SUBDEV;
36 }
37 bool hasStreams() const
38 {
39 return capabilities & V4L2_SUBDEV_CAP_MPLEXED;
40 }
41};
42
43 struct V4L2SubdeviceFormat {
44 uint32_t mbus_code;
45 Size size;
46 std::optional<ColorSpace> colorSpace;
47
48 const std::string toString() const;
49 uint8_t bitsPerPixel() const;
50};
51
52std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f);
53
54 class V4L2Subdevice : public V4L2Device
55{
56public:
57 using Formats = std::map<unsigned int, std::vector<SizeRange>>;
58
59 enum Whence {
60 TryFormat = V4L2_SUBDEV_FORMAT_TRY,
61 ActiveFormat = V4L2_SUBDEV_FORMAT_ACTIVE,
62 };
63
64 class Routing : public std::vector<struct v4l2_subdev_route>
65 {
66 public:
67 std::string toString() const;
68 };
69
70 explicit V4L2Subdevice(const MediaEntity *entity);
71 ~V4L2Subdevice();
72
73 int open();
74
75 const MediaEntity *entity() const { return entity_; }
76
77 int getSelection(unsigned int pad, unsigned int target,
78 Rectangle *rect);
79 int setSelection(unsigned int pad, unsigned int target,
80 Rectangle *rect);
81
82 Formats formats(unsigned int pad);
83
84 int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
85 Whence whence = ActiveFormat);
86 int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
87 Whence whence = ActiveFormat);
88
89 int getRouting(Routing *routing, Whence whence = ActiveFormat);
90 int setRouting(Routing *routing, Whence whence = ActiveFormat);
91
92 const std::string &model();
93 const V4L2SubdeviceCapability &caps() const { return caps_; }
94
95 static std::unique_ptr<V4L2Subdevice>
96 fromEntityName(const MediaDevice *media, const std::string &entity);
97
98protected:
99 std::string logPrefix() const override;
100
101private:
102 LIBCAMERA_DISABLE_COPY(V4L2Subdevice)
103
104 std::optional<ColorSpace>
105 toColorSpace(const v4l2_mbus_framefmt &format) const;
106
107 std::vector<unsigned int> enumPadCodes(unsigned int pad);
108 std::vector<SizeRange> enumPadSizes(unsigned int pad,
109 unsigned int code);
110
111 const MediaEntity *entity_;
112
113 std::string model_;
114 struct V4L2SubdeviceCapability caps_;
115};
116
117} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Definition class.h:27
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:26
libcamera::MediaEntity
The MediaEntity represents an entity in the media graph.
Definition media_object.h:89
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:243
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:53
libcamera::V4L2Device
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition v4l2_device.h:32
libcamera::V4L2Subdevice::Routing
V4L2 subdevice routing table.
Definition v4l2_subdevice.h:65
libcamera::V4L2Subdevice::Routing::toString
std::string toString() const
Assemble and return a string describing the routing table.
Definition v4l2_subdevice.cpp:308
libcamera::V4L2Subdevice
A V4L2 subdevice as exposed by the Linux kernel.
Definition v4l2_subdevice.h:55
libcamera::V4L2Subdevice::fromEntityName
static std::unique_ptr< 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:735
libcamera::V4L2Subdevice::open
int open()
Open a V4L2 subdevice.
Definition v4l2_subdevice.cpp:342
libcamera::V4L2Subdevice::setSelection
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Set selection rectangle rect for target.
Definition v4l2_subdevice.cpp:417
libcamera::V4L2Subdevice::logPrefix
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition v4l2_subdevice.cpp:745
libcamera::V4L2Subdevice::setRouting
int setRouting(Routing *routing, Whence whence=ActiveFormat)
Set a routing table on the V4L2 subdevice.
Definition v4l2_subdevice.cpp:647
libcamera::V4L2Subdevice::getSelection
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Get selection rectangle rect for target.
Definition v4l2_subdevice.cpp:381
libcamera::V4L2Subdevice::caps
const V4L2SubdeviceCapability & caps() const
Retrieve the subdevice V4L2 capabilities.
Definition v4l2_subdevice.h:93
libcamera::V4L2Subdevice::Formats
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition v4l2_subdevice.h:57
libcamera::V4L2Subdevice::Whence
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition v4l2_subdevice.h:59
libcamera::V4L2Subdevice::ActiveFormat
@ ActiveFormat
The format operation applies to ACTIVE formats.
Definition v4l2_subdevice.h:61
libcamera::V4L2Subdevice::TryFormat
@ TryFormat
The format operation applies to TRY formats.
Definition v4l2_subdevice.h:60
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:555
libcamera::V4L2Subdevice::model
const std::string & model()
Retrieve the model name of the device.
Definition v4l2_subdevice.cpp:683
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:520
libcamera::V4L2Subdevice::getRouting
int getRouting(Routing *routing, Whence whence=ActiveFormat)
Retrieve the subdevice's internal routing table.
Definition v4l2_subdevice.cpp:597
libcamera::V4L2Subdevice::entity
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition v4l2_subdevice.h:75
color_space.h
Class and enums to represent color spaces.
geometry.h
Data structures related to geometric objects.
formats.h
Types and helper functions 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
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::operator<<
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91
libcamera::V4L2SubdeviceCapability
struct v4l2_subdev_capability object wrapper and helpers
Definition v4l2_subdevice.h:32
libcamera::V4L2SubdeviceCapability::isReadOnly
bool isReadOnly() const
Retrieve if a subdevice is registered as read-only.
Definition v4l2_subdevice.h:33
libcamera::V4L2SubdeviceCapability::hasStreams
bool hasStreams() const
Retrieve if a subdevice supports the V4L2 streams API.
Definition v4l2_subdevice.h:37
libcamera::V4L2SubdeviceFormat
The V4L2 sub-device image format and sizes.
Definition v4l2_subdevice.h:43
libcamera::V4L2SubdeviceFormat::colorSpace
std::optional< ColorSpace > colorSpace
The color space of the pixels.
Definition v4l2_subdevice.h:46
libcamera::V4L2SubdeviceFormat::mbus_code
uint32_t mbus_code
The image format bus code.
Definition v4l2_subdevice.h:44
libcamera::V4L2SubdeviceFormat::toString
const std::string toString() const
Assemble and return a string describing the format.
Definition v4l2_subdevice.cpp:223
libcamera::V4L2SubdeviceFormat::bitsPerPixel
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition v4l2_subdevice.cpp:236
libcamera::V4L2SubdeviceFormat::size
Size size
The image size in pixels.
Definition v4l2_subdevice.h:45
v4l2_device.h
Common base for V4L2 devices and subdevices.