libcamera  v0.0.0
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 <string>
13 #include <vector>
14 
15 #include <libcamera/base/class.h>
16 #include <libcamera/base/log.h>
17 
18 #include <libcamera/color_space.h>
19 #include <libcamera/geometry.h>
20 
24 
25 namespace libcamera {
26 
27 class MediaDevice;
28 
30  uint32_t mbus_code;
32  std::optional<ColorSpace> colorSpace;
33 
34  const std::string toString() const;
35  uint8_t bitsPerPixel() const;
36 };
37 
38 class V4L2Subdevice : public V4L2Device
39 {
40 public:
41  using Formats = std::map<unsigned int, std::vector<SizeRange>>;
42 
43  enum Whence {
46  };
47 
48  explicit V4L2Subdevice(const MediaEntity *entity);
49  ~V4L2Subdevice();
50 
51  int open();
52 
53  const MediaEntity *entity() const { return entity_; }
54 
55  int getSelection(unsigned int pad, unsigned int target,
56  Rectangle *rect);
57  int setSelection(unsigned int pad, unsigned int target,
58  Rectangle *rect);
59 
60  Formats formats(unsigned int pad);
61 
62  int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
63  Whence whence = ActiveFormat);
64  int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
65  Whence whence = ActiveFormat);
66 
67  const std::string &model();
68 
69  static std::unique_ptr<V4L2Subdevice>
70  fromEntityName(const MediaDevice *media, const std::string &entity);
71 
72 protected:
73  std::string logPrefix() const override;
74 
75 private:
77 
78  std::vector<unsigned int> enumPadCodes(unsigned int pad);
79  std::vector<SizeRange> enumPadSizes(unsigned int pad,
80  unsigned int code);
81 
82  const MediaEntity *entity_;
83 
84  std::string model_;
85 };
86 
87 } /* namespace libcamera */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition: media_device.h:26
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:89
Describe a rectangle's position and dimensions.
Definition: geometry.h:236
Describe a two-dimensional size.
Definition: geometry.h:50
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:30
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:39
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:525
int open()
Open a V4L2 subdevice.
Definition: v4l2_subdevice.cpp:269
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Set selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:326
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_subdevice.cpp:535
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Get selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:290
Formats formats(unsigned int pad)
Enumerate all media bus codes and frame sizes on a pad.
Definition: v4l2_subdevice.cpp:365
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition: v4l2_subdevice.h:41
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:43
@ ActiveFormat
The format operation applies to ACTIVE formats.
Definition: v4l2_subdevice.h:44
@ TryFormat
The format operation applies to TRY formats.
Definition: v4l2_subdevice.h:45
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:435
const std::string & model()
Retrieve the model name of the device.
Definition: v4l2_subdevice.cpp:479
V4L2Subdevice(const MediaEntity *entity)
Create a V4L2 subdevice from a MediaEntity using its device node path.
Definition: v4l2_subdevice.cpp:255
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:399
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:53
Class and enums to represent color spaces.
Data structures related to geometric objects.
Types and helper functions to handle libcamera image formats.
Logging infrastructure.
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
Top-level libcamera namespace.
Definition: backtrace.h:17
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:29
std::optional< ColorSpace > colorSpace
The color space of the pixels.
Definition: v4l2_subdevice.h:32
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:30
const std::string toString() const
Assemble and return a string describing the format.
Definition: v4l2_subdevice.cpp:191
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition: v4l2_subdevice.cpp:211
Size size
The image size in pixels.
Definition: v4l2_subdevice.h:31
Common base for V4L2 devices and subdevices.