libcamera  v0.0.0+3-3b6e2d50-dirty (2022-01-27T16:18:04+08:00)
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 #ifndef __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
8 #define __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <libcamera/base/class.h>
15 #include <libcamera/base/log.h>
16 
17 #include <libcamera/geometry.h>
18 
22 
23 namespace libcamera {
24 
25 class MediaDevice;
26 
28  uint32_t mbus_code;
30 
31  const std::string toString() const;
32  uint8_t bitsPerPixel() const;
33 };
34 
35 class V4L2Subdevice : public V4L2Device
36 {
37 public:
38  using Formats = std::map<unsigned int, std::vector<SizeRange>>;
39 
40  enum Whence {
43  };
44 
45  explicit V4L2Subdevice(const MediaEntity *entity);
46  ~V4L2Subdevice();
47 
48  int open();
49 
50  const MediaEntity *entity() const { return entity_; }
51 
52  int getSelection(unsigned int pad, unsigned int target,
53  Rectangle *rect);
54  int setSelection(unsigned int pad, unsigned int target,
55  Rectangle *rect);
56 
57  Formats formats(unsigned int pad);
58 
59  int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
60  Whence whence = ActiveFormat);
61  int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
62  Whence whence = ActiveFormat);
63 
64  static std::unique_ptr<V4L2Subdevice>
65  fromEntityName(const MediaDevice *media, const std::string &entity);
66 
67 protected:
68  std::string logPrefix() const override;
69 
70 private:
72 
73  std::vector<unsigned int> enumPadCodes(unsigned int pad);
74  std::vector<SizeRange> enumPadSizes(unsigned int pad,
75  unsigned int code);
76 
77  const MediaEntity *entity_;
78 };
79 
80 } /* namespace libcamera */
81 
82 #endif /* __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__ */
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:25
The MediaEntity represents an entity in the media graph.
Definition: media_object.h:89
Describe a rectangle's position and dimensions.
Definition: geometry.h:207
Describe a two-dimensional size.
Definition: geometry.h:51
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:27
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:36
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:453
int open()
Open a V4L2 subdevice.
Definition: v4l2_subdevice.cpp:253
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Set selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:310
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_subdevice.cpp:463
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Get selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:274
Formats formats(unsigned int pad)
Enumerate all media bus codes and frame sizes on a pad.
Definition: v4l2_subdevice.cpp:349
std::map< unsigned int, std::vector< SizeRange > > Formats
A map of supported media bus formats to frame sizes.
Definition: v4l2_subdevice.h:38
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:40
@ ActiveFormat
The format operation applies to ACTIVE formats.
Definition: v4l2_subdevice.h:41
@ TryFormat
The format operation applies to TRY formats.
Definition: v4l2_subdevice.h:42
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:418
V4L2Subdevice(const MediaEntity *entity)
Create a V4L2 subdevice from a MediaEntity using its device node path.
Definition: v4l2_subdevice.cpp:239
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:383
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:50
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: bound_method.h:15
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:27
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:28
const std::string toString() const
Assemble and return a string describing the format.
Definition: v4l2_subdevice.cpp:175
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition: v4l2_subdevice.cpp:195
Size size
The image size in pixels.
Definition: v4l2_subdevice.h:29
Common base for V4L2 devices and subdevices.