libcamera  v0.0.0+3695-a2c715d8
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 <libcamera/base/class.h>
17 #include <libcamera/base/log.h>
18 
19 #include <libcamera/color_space.h>
20 #include <libcamera/geometry.h>
21 
25 
26 namespace libcamera {
27 
28 class MediaDevice;
29 
31  uint32_t mbus_code;
33  std::optional<ColorSpace> colorSpace;
34 
35  const std::string toString() const;
36  uint8_t bitsPerPixel() const;
37 };
38 
39 std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f);
40 
41 class V4L2Subdevice : public V4L2Device
42 {
43 public:
44  using Formats = std::map<unsigned int, std::vector<SizeRange>>;
45 
46  enum Whence {
49  };
50 
51  explicit V4L2Subdevice(const MediaEntity *entity);
52  ~V4L2Subdevice();
53 
54  int open();
55 
56  const MediaEntity *entity() const { return entity_; }
57 
58  int getSelection(unsigned int pad, unsigned int target,
59  Rectangle *rect);
60  int setSelection(unsigned int pad, unsigned int target,
61  Rectangle *rect);
62 
63  Formats formats(unsigned int pad);
64 
65  int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
66  Whence whence = ActiveFormat);
67  int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
68  Whence whence = ActiveFormat);
69 
70  const std::string &model();
71 
72  static std::unique_ptr<V4L2Subdevice>
73  fromEntityName(const MediaDevice *media, const std::string &entity);
74 
75 protected:
76  std::string logPrefix() const override;
77 
78 private:
80 
81  std::vector<unsigned int> enumPadCodes(unsigned int pad);
82  std::vector<SizeRange> enumPadSizes(unsigned int pad,
83  unsigned int code);
84 
85  const MediaEntity *entity_;
86 
87  std::string model_;
88 };
89 
90 } /* 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:32
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:29
The format operation applies to TRY formats.
Definition: v4l2_subdevice.h:48
Class and enums to represent color spaces.
const std::string toString() const
Assemble and return a string describing the format.
Definition: v4l2_subdevice.cpp:193
std::optional< ColorSpace > colorSpace
The color space of the pixels.
Definition: v4l2_subdevice.h:33
Top-level libcamera namespace.
Definition: backtrace.h:17
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:56
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:44
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:31
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.
Describe a rectangle&#39;s position and dimensions.
Definition: geometry.h:242
Common base for V4L2 devices and subdevices.
The format operation applies to ACTIVE formats.
Definition: v4l2_subdevice.h:47
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:30
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition: geometry.cpp:91
Data structures related to geometric objects.
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:46
Types and helper functions to handle libcamera image formats.
Logging infrastructure.
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition: v4l2_subdevice.cpp:206
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:41