libcamera: converter_v4l2_m2m: Add suport for V4L2 requests

To actually use requests with the m2m device, requests need to be
allocated on the underlying media device. This can only be done if the
media device is opened which means acquiring it. Add a function to check
if the m2m device supports requests by acquiring the media device,
asking it and then releasing it again. Also add a function to allocate
requests that acquires the internal media device and releases it after
allocating the requests.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-11-25 17:28:17 +01:00
parent 041625628c
commit 6d8109f4f1
2 changed files with 40 additions and 1 deletions

View File

@@ -73,6 +73,11 @@ public:
std::pair<Rectangle, Rectangle> inputCropBounds() override { return inputCropBounds_; }
std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) override;
int allocateRequests(unsigned int count,
std::vector<std::unique_ptr<V4L2Request>> *requests);
bool supportsRequests();
private:
class V4L2M2MStream : protected Loggable
{
@@ -122,6 +127,8 @@ private:
std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
std::map<FrameBuffer *, unsigned int> queue_;
std::pair<Rectangle, Rectangle> inputCropBounds_;
std::shared_ptr<MediaDevice> media_;
};
} /* namespace libcamera */

View File

@@ -9,6 +9,7 @@
#include "libcamera/internal/converter/converter_v4l2_m2m.h"
#include <algorithm>
#include <errno.h>
#include <limits.h>
#include <memory>
#include <set>
@@ -266,7 +267,7 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)
* \param[in] media The media device implementing the converter
*/
V4L2M2MConverter::V4L2M2MConverter(std::shared_ptr<MediaDevice> media)
: Converter(media)
: Converter(media), media_(media)
{
if (deviceNode().empty())
return;
@@ -742,6 +743,37 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input,
return 0;
}
/**
* \copydoc libcamera::MediaDevice::allocateRequests
*/
int V4L2M2MConverter::allocateRequests(unsigned int count,
std::vector<std::unique_ptr<V4L2Request>> *requests)
{
/* \todo The acquire() must be moved to the right place. */
media_->acquire();
if (!media_->busy())
LOG(Converter, Error)
<< "MediaDevice must be valid.";
int ret = media_->allocateRequests(count, requests);
media_->release();
return ret;
}
/**
* \copydoc libcamera::MediaDevice::supportsRequests
*/
bool V4L2M2MConverter::supportsRequests()
{
/* \todo The acquire() must be moved to the right place. */
media_->acquire();
if (!media_->busy())
LOG(Converter, Error)
<< "MediaDevice must be valid.";
bool ret = media_->supportsRequests();
media_->release();
return ret;
}
/*
* \todo This should be extended to include Feature::Flag to denote
* what each converter supports feature-wise.