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 #ifndef __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
8 #define __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
9 
10 #include <string>
11 #include <vector>
12 
13 #include <libcamera/geometry.h>
14 
16 #include "libcamera/internal/log.h"
19 
20 namespace libcamera {
21 
22 class MediaDevice;
23 
25  uint32_t mbus_code;
27 
28  const std::string toString() const;
29  uint8_t bitsPerPixel() const;
30 };
31 
32 class V4L2Subdevice : public V4L2Device
33 {
34 public:
35  enum Whence {
38  };
39 
40  explicit V4L2Subdevice(const MediaEntity *entity);
41  V4L2Subdevice(const V4L2Subdevice &) = delete;
42  V4L2Subdevice &operator=(const V4L2Subdevice &) = delete;
43  ~V4L2Subdevice();
44 
45  int open();
46 
47  const MediaEntity *entity() const { return entity_; }
48 
49  int getSelection(unsigned int pad, unsigned int target,
50  Rectangle *rect);
51  int setSelection(unsigned int pad, unsigned int target,
52  Rectangle *rect);
53 
54  ImageFormats formats(unsigned int pad);
55 
56  int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
57  Whence whence = ActiveFormat);
58  int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
59  Whence whence = ActiveFormat);
60 
61  static V4L2Subdevice *fromEntityName(const MediaDevice *media,
62  const std::string &entity);
63 
64 protected:
65  std::string logPrefix() const override;
66 
67 private:
68  std::vector<unsigned int> enumPadCodes(unsigned int pad);
69  std::vector<SizeRange> enumPadSizes(unsigned int pad,
70  unsigned int code);
71 
72  const MediaEntity *entity_;
73 };
74 
75 } /* namespace libcamera */
76 
77 #endif /* __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__ */
Describe V4L2Device and V4L2SubDevice image formats.
Definition: formats.h:22
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:86
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:22
A V4L2 subdevice as exposed by the Linux kernel.
Definition: v4l2_subdevice.h:33
int open()
Open a V4L2 subdevice.
Definition: v4l2_subdevice.cpp:247
static 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:448
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Set selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:304
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_subdevice.cpp:458
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
Get selection rectangle rect for target.
Definition: v4l2_subdevice.cpp:268
Whence
Specify the type of format for getFormat() and setFormat() operations.
Definition: v4l2_subdevice.h:35
@ ActiveFormat
The format operation applies to ACTIVE formats.
Definition: v4l2_subdevice.h:36
@ TryFormat
The format operation applies to TRY formats.
Definition: v4l2_subdevice.h:37
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:411
ImageFormats formats(unsigned int pad)
Enumerate all media bus codes and frame sizes on a pad.
Definition: v4l2_subdevice.cpp:343
V4L2Subdevice(const MediaEntity *entity)
Create a V4L2 subdevice from a MediaEntity using its device node path.
Definition: v4l2_subdevice.cpp:233
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:376
const MediaEntity * entity() const
Retrieve the media entity associated with the subdevice.
Definition: v4l2_subdevice.h:47
Data structures related to geometric objects.
Types and helper methods to handle libcamera image formats.
Logging infrastructure.
Provides a class hierarchy that represents the media objects exposed by the Linux kernel Media Contro...
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
Describe a two-dimensional size.
Definition: geometry.h:30
The V4L2 sub-device image format and sizes.
Definition: v4l2_subdevice.h:24
uint32_t mbus_code
The image format bus code.
Definition: v4l2_subdevice.h:25
const std::string toString() const
Assemble and return a string describing the format.
Definition: v4l2_subdevice.cpp:174
uint8_t bitsPerPixel() const
Retrieve the number of bits per pixel for the V4L2 subdevice format.
Definition: v4l2_subdevice.cpp:194
Size size
The image size in pixels.
Definition: v4l2_subdevice.h:26
Common base for V4L2 devices and subdevices.