libcamera: v4l2_subdevice: Add stream support to get/set functions
Extend the V4L2Subdevice API with stream support for the functions that get and set formats and selection rectangles. Add a Stream structure to identify a subdev pad and stream, and use it to extend the V4L2Subdevice functions that get and set formats and selection rectangles with stream support. To preserve the existing pad-based API, implement overloaded functions that wrap the new stream-based API. This allows callers that are not stream-aware to use a simpler pad-based API, instead of having to explicitly set the stream number to 0 in all API calls. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
@@ -80,6 +80,21 @@ public:
|
||||
ActiveFormat = V4L2_SUBDEV_FORMAT_ACTIVE,
|
||||
};
|
||||
|
||||
struct Stream {
|
||||
Stream()
|
||||
: pad(0), stream(0)
|
||||
{
|
||||
}
|
||||
|
||||
Stream(unsigned int p, unsigned int s)
|
||||
: pad(p), stream(s)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int pad;
|
||||
unsigned int stream;
|
||||
};
|
||||
|
||||
class Routing : public std::vector<struct v4l2_subdev_route>
|
||||
{
|
||||
public:
|
||||
@@ -93,17 +108,39 @@ public:
|
||||
|
||||
const MediaEntity *entity() const { return entity_; }
|
||||
|
||||
int getSelection(unsigned int pad, unsigned int target,
|
||||
int getSelection(const Stream &stream, unsigned int target,
|
||||
Rectangle *rect);
|
||||
int setSelection(unsigned int pad, unsigned int target,
|
||||
int getSelection(unsigned int pad, unsigned int target, Rectangle *rect)
|
||||
{
|
||||
return getSelection({ pad, 0 }, target, rect);
|
||||
}
|
||||
int setSelection(const Stream &stream, unsigned int target,
|
||||
Rectangle *rect);
|
||||
int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
|
||||
{
|
||||
return setSelection({ pad, 0 }, target, rect);
|
||||
}
|
||||
|
||||
Formats formats(unsigned int pad);
|
||||
Formats formats(const Stream &stream);
|
||||
Formats formats(unsigned int pad)
|
||||
{
|
||||
return formats({ pad, 0 });
|
||||
}
|
||||
|
||||
int getFormat(const Stream &stream, V4L2SubdeviceFormat *format,
|
||||
Whence whence = ActiveFormat);
|
||||
int getFormat(unsigned int pad, V4L2SubdeviceFormat *format,
|
||||
Whence whence = ActiveFormat)
|
||||
{
|
||||
return getFormat({ pad, 0 }, format, whence);
|
||||
}
|
||||
int setFormat(const Stream &stream, V4L2SubdeviceFormat *format,
|
||||
Whence whence = ActiveFormat);
|
||||
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
|
||||
Whence whence = ActiveFormat);
|
||||
Whence whence = ActiveFormat)
|
||||
{
|
||||
return setFormat({ pad, 0 }, format, whence);
|
||||
}
|
||||
|
||||
int getRouting(Routing *routing, Whence whence = ActiveFormat);
|
||||
int setRouting(Routing *routing, Whence whence = ActiveFormat);
|
||||
@@ -123,8 +160,8 @@ private:
|
||||
std::optional<ColorSpace>
|
||||
toColorSpace(const v4l2_mbus_framefmt &format) const;
|
||||
|
||||
std::vector<unsigned int> enumPadCodes(unsigned int pad);
|
||||
std::vector<SizeRange> enumPadSizes(unsigned int pad,
|
||||
std::vector<unsigned int> enumPadCodes(const Stream &stream);
|
||||
std::vector<SizeRange> enumPadSizes(const Stream &stream,
|
||||
unsigned int code);
|
||||
|
||||
const MediaEntity *entity_;
|
||||
@@ -133,4 +170,13 @@ private:
|
||||
struct V4L2SubdeviceCapability caps_;
|
||||
};
|
||||
|
||||
bool operator==(const V4L2Subdevice::Stream &lhs, const V4L2Subdevice::Stream &rhs);
|
||||
static inline bool operator!=(const V4L2Subdevice::Stream &lhs,
|
||||
const V4L2Subdevice::Stream &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const V4L2Subdevice::Stream &stream);
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
Reference in New Issue
Block a user