summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/buffer.cpp13
-rw-r--r--src/libcamera/request.cpp5
-rw-r--r--src/libcamera/stream.cpp47
3 files changed, 63 insertions, 2 deletions
diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp
index ecbf2524..99358633 100644
--- a/src/libcamera/buffer.cpp
+++ b/src/libcamera/buffer.cpp
@@ -269,7 +269,8 @@ void BufferPool::destroyBuffers()
* for a stream with Stream::createBuffer().
*/
Buffer::Buffer(unsigned int index, const Buffer *metadata)
- : index_(index), status_(Buffer::BufferSuccess), request_(nullptr),
+ : index_(index), dmabuf_({ -1, -1, -1 }),
+ status_(Buffer::BufferSuccess), request_(nullptr),
stream_(nullptr)
{
if (metadata) {
@@ -290,6 +291,16 @@ Buffer::Buffer(unsigned int index, const Buffer *metadata)
*/
/**
+ * \fn Buffer::dmabufs()
+ * \brief Retrieve the dmabuf file descriptors for all buffer planes
+ *
+ * The dmabufs array contains one dmabuf file descriptor per plane. Unused
+ * entries are set to -1.
+ *
+ * \return The dmabuf file descriptors
+ */
+
+/**
* \fn Buffer::bytesused()
* \brief Retrieve the number of bytes occupied by the data in the buffer
* \return Number of bytes occupied in the buffer
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index 19131472..ee2158fc 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -106,10 +106,15 @@ Request::~Request()
*
* \return 0 on success or a negative error code otherwise
* \retval -EEXIST The request already contains a buffer for the stream
+ * \retval -EINVAL The buffer does not reference a valid Stream
*/
int Request::addBuffer(std::unique_ptr<Buffer> buffer)
{
Stream *stream = buffer->stream();
+ if (!stream) {
+ LOG(Request, Error) << "Invalid stream reference";
+ return -EINVAL;
+ }
auto it = bufferMap_.find(stream);
if (it != bufferMap_.end()) {
diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
index 37a9bc0a..98178e06 100644
--- a/src/libcamera/stream.cpp
+++ b/src/libcamera/stream.cpp
@@ -424,17 +424,26 @@ Stream::Stream()
}
/**
- * \brief Create a Buffer instance
+ * \brief Create a Buffer instance referencing the memory buffer \a index
* \param[in] index The desired buffer index
*
* This method creates a Buffer instance that references a BufferMemory from
* the stream's buffers pool by its \a index. The index shall be lower than the
* number of buffers in the pool.
*
+ * This method is only valid for streams that use the InternalMemory type. It
+ * will return a null pointer when called on streams using the ExternalMemory
+ * type.
+ *
* \return A newly created Buffer on success or nullptr otherwise
*/
std::unique_ptr<Buffer> Stream::createBuffer(unsigned int index)
{
+ if (memoryType_ != InternalMemory) {
+ LOG(Stream, Error) << "Invalid stream memory type";
+ return nullptr;
+ }
+
if (index >= bufferPool_.count()) {
LOG(Stream, Error) << "Invalid buffer index " << index;
return nullptr;
@@ -448,6 +457,42 @@ std::unique_ptr<Buffer> Stream::createBuffer(unsigned int index)
}
/**
+ * \brief Create a Buffer instance that represents a memory area identified by
+ * dmabuf file descriptors
+ * \param[in] fds The dmabuf file descriptors for each plane
+ *
+ * This method creates a Buffer instance that references buffer memory
+ * allocated outside of libcamera through dmabuf file descriptors. The \a
+ * dmabuf array shall contain a file descriptor for each plane in the buffer,
+ * and unused entries shall be set to -1.
+ *
+ * The buffer is created without a valid index, as it does not yet map to any of
+ * the stream's BufferMemory instances. An index will be assigned at the time
+ * the buffer is queued to the camera in a request. Applications may thus
+ * create any number of Buffer instances, providing that no more than the
+ * number of buffers allocated for the stream are queued at any given time.
+ *
+ * This method is only valid for streams that use the ExternalMemory type. It
+ * will return a null pointer when called on streams using the InternalMemory
+ * type.
+ *
+ * \return A newly created Buffer on success or nullptr otherwise
+ */
+std::unique_ptr<Buffer> Stream::createBuffer(const std::array<int, 3> &fds)
+{
+ if (memoryType_ != ExternalMemory) {
+ LOG(Stream, Error) << "Invalid stream memory type";
+ return nullptr;
+ }
+
+ Buffer *buffer = new Buffer();
+ buffer->dmabuf_ = fds;
+ buffer->stream_ = this;
+
+ return std::unique_ptr<Buffer>(buffer);
+}
+
+/**
* \fn Stream::bufferPool()
* \brief Retrieve the buffer pool for the stream
*