summaryrefslogtreecommitdiff
path: root/src/libcamera
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-11-21 20:12:38 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-12 16:10:37 +0100
commit5967363c0b99a59f3526c51917572b807324e389 (patch)
tree134a8e070813bca1dfbf72e10d4443e951757e8d /src/libcamera
parentdea689e1f260b904697a9c2f3d05b7b5068d85e1 (diff)
libcamera: buffer: Move captured metadata to FrameMetadata
Move the metadata retrieved when dequeuing a V4L2 buffer into a FrameMetadata object. This is done as a step to migrate to the FrameBuffer interface as the functions added to Buffer around FrameMetadata match the ones in FrameBuffer. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera')
-rw-r--r--src/libcamera/buffer.cpp76
-rw-r--r--src/libcamera/pipeline/ipu3/ipu3.cpp4
-rw-r--r--src/libcamera/pipeline/rkisp1/rkisp1.cpp8
-rw-r--r--src/libcamera/request.cpp2
-rw-r--r--src/libcamera/v4l2_videodevice.cpp25
5 files changed, 38 insertions, 77 deletions
diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp
index 8c8be4ac..92ac2838 100644
--- a/src/libcamera/buffer.cpp
+++ b/src/libcamera/buffer.cpp
@@ -178,20 +178,6 @@ void BufferPool::destroyBuffers()
*/
/**
- * \enum Buffer::Status
- * Buffer completion status
- * \var Buffer::BufferSuccess
- * The buffer has completed with success and contains valid data. All its other
- * metadata (such as bytesused(), timestamp() or sequence() number) are valid.
- * \var Buffer::BufferError
- * The buffer has completed with an error and doesn't contain valid data. Its
- * other metadata are valid.
- * \var Buffer::BufferCancelled
- * The buffer has been cancelled due to capture stop. Its other metadata are
- * invalid and shall not be used.
- */
-
-/**
* \brief Construct a buffer not associated with any stream
*
* This method constructs an orphaned buffer not associated with any stream. It
@@ -199,19 +185,15 @@ void BufferPool::destroyBuffers()
* for a stream with Stream::createBuffer().
*/
Buffer::Buffer(unsigned int index, const Buffer *metadata)
- : index_(index), dmabuf_({ -1, -1, -1 }),
- status_(Buffer::BufferSuccess), request_(nullptr),
+ : index_(index), dmabuf_({ -1, -1, -1 }), request_(nullptr),
stream_(nullptr)
{
- if (metadata) {
- bytesused_ = metadata->bytesused_;
- sequence_ = metadata->sequence_;
- timestamp_ = metadata->timestamp_;
- } else {
- bytesused_ = 0;
- sequence_ = 0;
- timestamp_ = 0;
- }
+ if (metadata)
+ metadata_ = metadata->metadata();
+ else
+ metadata_ = {};
+
+ metadata_.status = FrameMetadata::FrameSuccess;
}
/**
@@ -242,39 +224,13 @@ Buffer::Buffer(unsigned int index, const Buffer *metadata)
*/
/**
- * \fn Buffer::bytesused()
- * \brief Retrieve the number of bytes occupied by the data in the buffer
- * \return Number of bytes occupied in the buffer
- */
-
-/**
- * \fn Buffer::timestamp()
- * \brief Retrieve the time when the buffer was processed
- *
- * The timestamp is expressed as a number of nanoseconds since the epoch.
- *
- * \return Timestamp when the buffer was processed
- */
-
-/**
- * \fn Buffer::sequence()
- * \brief Retrieve the buffer sequence number
- *
- * The sequence number is a monotonically increasing number assigned to the
- * buffer processed by the stream. Gaps in the sequence numbers indicate
- * dropped frames.
- *
- * \return Sequence number of the buffer
- */
-
-/**
- * \fn Buffer::status()
- * \brief Retrieve the buffer status
+ * \fn Buffer::metadata()
+ * \brief Retrieve the buffer metadata
*
- * The buffer status reports whether the buffer has completed successfully
- * (BufferSuccess) or if an error occurred (BufferError).
+ * The buffer metadata is updated when the buffer contents are modified, for
+ * example when a frame has been captured to the buffer by the hardware.
*
- * \return The buffer status
+ * \return Metadata for the buffer
*/
/**
@@ -310,10 +266,10 @@ Buffer::Buffer(unsigned int index, const Buffer *metadata)
*/
void Buffer::cancel()
{
- bytesused_ = 0;
- timestamp_ = 0;
- sequence_ = 0;
- status_ = BufferCancelled;
+ metadata_.status = FrameMetadata::FrameCancelled;
+ metadata_.sequence = 0;
+ metadata_.timestamp = 0;
+ metadata_.planes = {};
}
/**
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 6d8c3fad..34fc7929 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -928,7 +928,7 @@ int PipelineHandlerIPU3::registerCameras()
void IPU3CameraData::imguInputBufferReady(Buffer *buffer)
{
/* \todo Handle buffer failures when state is set to BufferError. */
- if (buffer->status() == Buffer::BufferCancelled)
+ if (buffer->metadata().status == FrameMetadata::FrameCancelled)
return;
cio2_.output_->queueBuffer(buffer);
@@ -962,7 +962,7 @@ void IPU3CameraData::imguOutputBufferReady(Buffer *buffer)
void IPU3CameraData::cio2BufferReady(Buffer *buffer)
{
/* \todo Handle buffer failures when state is set to BufferError. */
- if (buffer->status() == Buffer::BufferCancelled)
+ if (buffer->metadata().status == FrameMetadata::FrameCancelled)
return;
imgu_->input_->queueBuffer(buffer);
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 1e445715..979b670e 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -100,10 +100,10 @@ public:
ASSERT(frameOffset(SOE) == 0);
utils::time_point soe = std::chrono::time_point<utils::clock>()
- + std::chrono::nanoseconds(buffer->timestamp())
+ + std::chrono::nanoseconds(buffer->metadata().timestamp)
+ timeOffset(SOE);
- notifyStartOfExposure(buffer->sequence(), soe);
+ notifyStartOfExposure(buffer->metadata().sequence, soe);
}
void setDelay(unsigned int type, int frame, int msdelay)
@@ -994,8 +994,8 @@ void PipelineHandlerRkISP1::bufferReady(Buffer *buffer)
data->timeline_.bufferReady(buffer);
- if (data->frame_ <= buffer->sequence())
- data->frame_ = buffer->sequence() + 1;
+ if (data->frame_ <= buffer->metadata().sequence)
+ data->frame_ = buffer->metadata().sequence + 1;
completeBuffer(activeCamera_, request, buffer);
tryCompleteRequest(request);
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index 54dfb461..4268e314 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -238,7 +238,7 @@ bool Request::completeBuffer(Buffer *buffer)
buffer->request_ = nullptr;
- if (buffer->status() == Buffer::BufferCancelled)
+ if (buffer->metadata().status == FrameMetadata::FrameCancelled)
cancelled_ = true;
return !hasPendingBuffers();
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 4551484c..d22655c6 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1015,10 +1015,13 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)
}
if (V4L2_TYPE_IS_OUTPUT(buf.type)) {
- buf.bytesused = buffer->bytesused_;
- buf.sequence = buffer->sequence_;
- buf.timestamp.tv_sec = buffer->timestamp_ / 1000000000;
- buf.timestamp.tv_usec = (buffer->timestamp_ / 1000) % 1000000;
+ const FrameMetadata &metadata = buffer->metadata();
+
+ if (!metadata.planes.empty())
+ buf.bytesused = metadata.planes[0].bytesused;
+ buf.sequence = metadata.sequence;
+ buf.timestamp.tv_sec = metadata.timestamp / 1000000000;
+ buf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000;
}
LOG(V4L2, Debug) << "Queueing buffer " << buf.index;
@@ -1125,12 +1128,14 @@ Buffer *V4L2VideoDevice::dequeueBuffer()
fdEvent_->setEnabled(false);
buffer->index_ = buf.index;
- buffer->bytesused_ = buf.bytesused;
- buffer->timestamp_ = buf.timestamp.tv_sec * 1000000000ULL
- + buf.timestamp.tv_usec * 1000ULL;
- buffer->sequence_ = buf.sequence;
- buffer->status_ = buf.flags & V4L2_BUF_FLAG_ERROR
- ? Buffer::BufferError : Buffer::BufferSuccess;
+
+ buffer->metadata_.status = buf.flags & V4L2_BUF_FLAG_ERROR
+ ? FrameMetadata::FrameError
+ : FrameMetadata::FrameSuccess;
+ buffer->metadata_.sequence = buf.sequence;
+ buffer->metadata_.timestamp = buf.timestamp.tv_sec * 1000000000ULL
+ + buf.timestamp.tv_usec * 1000ULL;
+ buffer->metadata_.planes = { { buf.bytesused } };
return buffer;
}