libcamera  v0.2.0+31-5e4dc46a
Supporting cameras in Linux since 2019
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 
27 
28 namespace libcamera {
29 
30 class 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_STREAMS;
40  }
41 };
42 
44  uint32_t mbus_code;
46  std::optional<ColorSpace> colorSpace;
47 
48  const std::string toString() const;
49  uint8_t bitsPerPixel() const;
50 };
51 
52 std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f);
53 
54 class V4L2Subdevice : public V4L2Device
55 {
56 public:
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 
98 protected:
99  std::string logPrefix() const override;
100 
101 private:
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 */
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
Size size
The image size in pixels.
Definition: v4l2_subdevice.h:45
Utilities to help constructing class interfaces.
The MediaDevice represents a Media Controller device with its full graph of connected objects...
Definition: media_device.h:25
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:31
Class and enums to represent color spaces.
std::optional< ColorSpace > colorSpace
The color space of the pixels.
Definition: v4l2_subdevice.h:46
Top-level libcamera namespace.
Definition: backtrace.h:17
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:75
Describe a two-dimensional size.
Definition: geometry.h:52
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition: v4l2_subdevice.h:57
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:44
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:88
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
V4L2 subdevice routing table.
Definition: v4l2_subdevice.h:64
Describe a rectangle&#39;s position and dimensions.
Definition: geometry.h:242
Common base for V4L2 devices and subdevices.
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:43
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition: geometry.cpp:91
const V4L2SubdeviceCapability & caps() const
Retrieve the subdevice V4L2 capabilities.
Definition: v4l2_subdevice.h:93
bool hasStreams() const
Retrieve if a subdevice supports the V4L2 streams API.
Definition: v4l2_subdevice.h:37
bool isReadOnly() const
Retrieve if a subdevice is registered as read-only.
Definition: v4l2_subdevice.h:33
Data structures related to geometric objects.
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:59
Types and helper functions to handle libcamera image formats.
Logging infrastructure.
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:54
struct v4l2_subdev_capability object wrapper and helpers
Definition: v4l2_subdevice.h:32