From patchwork Thu Feb 28 16:29:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 660 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 767B9610B7 for ; Thu, 28 Feb 2019 17:29:27 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E11549 for ; Thu, 28 Feb 2019 17:29:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551371367; bh=OiouI0WIP4KokHgWBXtzSeN3x/+3HQnLsvei202zKR4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OOKIgQCeIGbXDeK9BuuL+WtAbQlITzslL0YQa1juoUAn4MvXVadYUpKN4IO7OyYuM EAie4tSdcvu4d4yYX5tIppEwoA3UsNzLMUz9ErsxRFYIlEwHo+cyFBUXNzFfqSsoai XVdDWHxjV7xLSAzB7sCfhGriB0GJEGpyqymrniMI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 18:29:10 +0200 Message-Id: <20190228162913.6508-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> References: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] libcamera: buffer: Add buffer completion status X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 16:29:27 -0000 Add a new field to the Buffer class to report its completion status, with a new cancel() method to mark the buffer as cancelled. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/buffer.h | 10 ++++++++++ src/libcamera/buffer.cpp | 35 +++++++++++++++++++++++++++++++++++ src/libcamera/v4l2_device.cpp | 2 ++ 3 files changed, 47 insertions(+) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index dc9aaad12a81..f740ade9bb4f 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -40,12 +40,19 @@ private: class Buffer final { public: + enum Status { + BufferSuccess, + BufferError, + BufferCancelled, + }; + Buffer(); unsigned int index() const { return index_; } unsigned int bytesused() const { return bytesused_; } uint64_t timestamp() const { return timestamp_; } unsigned int sequence() const { return sequence_; } + Status status() const { return status_; } std::vector &planes() { return planes_; } Signal completed; @@ -54,10 +61,13 @@ private: friend class BufferPool; friend class V4L2Device; + void cancel(); + unsigned int index_; unsigned int bytesused_; uint64_t timestamp_; unsigned int sequence_; + Status status_; std::vector planes_; }; diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 80dd9c854a4b..524eb47d4364 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -181,6 +181,20 @@ void *Plane::mem() * objects if the image format is multi-planar. */ +/** + * \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. + */ + Buffer::Buffer() : index_(-1) { @@ -229,6 +243,27 @@ Buffer::Buffer() * \return Sequence number of the buffer */ +/** + * \fn Buffer::status() + * \brief Retrieve the buffer status + * + * The buffer status reports whether the buffer has completed successfully + * (BufferSuccess) or if an error occurred (BufferError). + * + * \return The buffer status + */ + +/** + * \brief Mark a buffer as cancel by setting its status to BufferCancelled + */ +void Buffer::cancel() +{ + bytesused_ = 0; + timestamp_ = 0; + sequence_ = 0; + status_ = BufferCancelled; +} + /** * \class BufferPool * \brief A pool of buffers diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 31200a6e7d6f..054499e4b888 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -793,6 +793,8 @@ Buffer *V4L2Device::dequeueBuffer() 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; return buffer; }