From patchwork Mon Mar 16 02:41:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3110 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA1F460417 for ; Mon, 16 Mar 2020 03:42:31 +0100 (CET) X-Halon-ID: b6354c3c-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b6354c3c-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:00 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:41 +0100 Message-Id: <20200316024146.2474424-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/6] libcamera: stream: Add StillCaptureRaw role X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:32 -0000 Add role to be used for streams capturing frames in a raw format for still capture in a low frame rate. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- include/libcamera/stream.h | 1 + src/libcamera/stream.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h index 29a8030dff71d58f..c4c0241ec9f34727 100644 --- a/include/libcamera/stream.h +++ b/include/libcamera/stream.h @@ -58,6 +58,7 @@ private: enum StreamRole { StillCapture, + StillCaptureRaw, VideoRecording, Viewfinder, }; diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index f34ea08de03b744e..571bf41e072d00c1 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -363,6 +363,10 @@ std::string StreamConfiguration::toString() const * \var StillCapture * The stream is intended to capture high-resolution, high-quality still images * with low frame rate. The captured frames may be exposed with flash. + * \var StillCaptureRaw + * The stream is intended to capture high-resolution, high-quality still images + * with low frame rate in a raw format. The captured frames may be exposed with + * flash. * \var VideoRecording * The stream is intended to capture video for the purpose of recording or * streaming. The video stream may produce a high frame rate and may be From patchwork Mon Mar 16 02:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3111 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2BD4462928 for ; Mon, 16 Mar 2020 03:42:32 +0100 (CET) X-Halon-ID: b67a6636-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b67a6636-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:01 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:42 +0100 Message-Id: <20200316024146.2474424-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 2/6] cam: Add option to capture StillCaptureRaw stream X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:32 -0000 Add a role name 'stillraw' to request a StillCaptureRaw stream. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/cam/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index f73e77f381779853..dc86b5fee20ffa00 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -155,7 +155,7 @@ int CamApp::parseOptions(int argc, char *argv[]) { KeyValueParser streamKeyValue; streamKeyValue.addOption("role", OptionString, - "Role for the stream (viewfinder, video, still)", + "Role for the stream (viewfinder, video, still, stillraw)", ArgumentRequired); streamKeyValue.addOption("width", OptionInteger, "Width in pixels", ArgumentRequired); @@ -217,6 +217,8 @@ int CamApp::prepareConfig() roles.push_back(StreamRole::VideoRecording); } else if (opt["role"].toString() == "still") { roles.push_back(StreamRole::StillCapture); + } else if (opt["role"].toString() == "stillraw") { + roles.push_back(StreamRole::StillCaptureRaw); } else { std::cerr << "Unknown stream role " << opt["role"].toString() << std::endl; From patchwork Mon Mar 16 02:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3112 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C5EAF62928 for ; Mon, 16 Mar 2020 03:42:32 +0100 (CET) X-Halon-ID: b6bd6afa-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b6bd6afa-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:01 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:43 +0100 Message-Id: <20200316024146.2474424-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 3/6] [DNI] include: drm_fourcc: Add Bayer FourCC and modifiers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:33 -0000 Add Bayer format and modifiers for patch submitted for upstream inclusion. The formats have not been accepted upstream yet so should not yet be merged i libcamera. The formats is however needed to demonstrate RAW capture on the IPU3 pipeline. Signed-off-by: Niklas Söderlund --- include/linux/drm_fourcc.h | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h index 4bb1bfe93d5f4390..69240dfe1df0df28 100644 --- a/include/linux/drm_fourcc.h +++ b/include/linux/drm_fourcc.h @@ -288,6 +288,62 @@ extern "C" { /* Compressed formats */ #define DRM_FORMAT_MJPEG fourcc_code('M', 'J', 'P', 'G') /* Motion-JPEG */ +/* + * Bayer formats + * + * Bayer formats contain green, red and blue components, with alternating lines + * of red and green, and blue and green pixels in different orders. For each + * block of 2x2 pixels there is one pixel with a red filter, two with a green + * filter, and one with a blue filter. The filters can be arranged in different + * patterns. + * + * For example, RGGB: + * row0: RGRGRGRG... + * row1: GBGBGBGB... + * row3: RGRGRGRG... + * row4: GBGBGBGB... + * ... + * + * Vendors have different methods to pack the sampling formats to increase data + * density. For this reason the fourcc only describes pixel sample size and the + * filter pattern for each block of 2x2 pixels. A modifier is needed to + * describe the memory layout. + * + * In addition to vendor modifiers for memory layout DRM_FORMAT_MOD_LINEAR may + * be used to describe a layout where all samples are placed consecutively in + * memory. If the sample does not fit inside a single byte, the sample storage + * is extended to the minimum number of (little endian) bytes that can hold the + * sample and any unused most-significant bits are defined as padding. + * + * For example, SRGGB10: + * Each 10-bit sample is contained in 2 consecutive little endian bytes, where + * the 6 most-significant bits are unused. + */ + +/* 8-bit Bayer formats */ +#define DRM_FORMAT_SRGGB8 fourcc_code('R', 'G', 'G', 'B') +#define DRM_FORMAT_SGRBG8 fourcc_code('G', 'R', 'B', 'G') +#define DRM_FORMAT_SGBRG8 fourcc_code('G', 'B', 'R', 'G') +#define DRM_FORMAT_SBGGR8 fourcc_code('B', 'A', '8', '1') + +/* 10-bit Bayer formats */ +#define DRM_FORMAT_SRGGB10 fourcc_code('R', 'G', '1', '0') +#define DRM_FORMAT_SGRBG10 fourcc_code('B', 'A', '1', '0') +#define DRM_FORMAT_SGBRG10 fourcc_code('G', 'B', '1', '0') +#define DRM_FORMAT_SBGGR10 fourcc_code('B', 'G', '1', '0') + +/* 12-bit Bayer formats */ +#define DRM_FORMAT_SRGGB12 fourcc_code('R', 'G', '1', '2') +#define DRM_FORMAT_SGRBG12 fourcc_code('B', 'A', '1', '2') +#define DRM_FORMAT_SGBRG12 fourcc_code('G', 'B', '1', '2') +#define DRM_FORMAT_SBGGR12 fourcc_code('B', 'G', '1', '2') + +/* 14-bit Bayer formats */ +#define DRM_FORMAT_SRGGB14 fourcc_code('R', 'G', '1', '4') +#define DRM_FORMAT_SGRBG14 fourcc_code('B', 'A', '1', '4') +#define DRM_FORMAT_SGBRG14 fourcc_code('G', 'B', '1', '4') +#define DRM_FORMAT_SBGGR14 fourcc_code('B', 'G', '1', '4') + /* * Format Modifiers: * @@ -311,6 +367,7 @@ extern "C" { #define DRM_FORMAT_MOD_VENDOR_BROADCOM 0x07 #define DRM_FORMAT_MOD_VENDOR_ARM 0x08 #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09 +#define DRM_FORMAT_MOD_VENDOR_MIPI 0x0a /* add more to the end as needed */ @@ -412,6 +469,16 @@ extern "C" { #define I915_FORMAT_MOD_Y_TILED_CCS fourcc_mod_code(INTEL, 4) #define I915_FORMAT_MOD_Yf_TILED_CCS fourcc_mod_code(INTEL, 5) +/* + * IPU3 Bayer packing layout + * + * The IPU3 raw Bayer formats use a custom packing layout where there are no + * gaps between each 10-bit sample. It packs 25 pixels into 32 bytes leaving + * the 6 most significant bits in the last byte unused. The format is little + * endian. + */ +#define IPU3_FORMAT_MOD_PACKED fourcc_mod_code(INTEL, 8) + /* * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks * @@ -758,6 +825,33 @@ extern "C" { */ #define DRM_FORMAT_MOD_ALLWINNER_TILED fourcc_mod_code(ALLWINNER, 1) +/* Mobile Industry Processor Interface (MIPI) modifiers */ + +/* + * MIPI CSI-2 packing layout + * + * The CSI-2 RAW formats (for example Bayer) use a different packing layout + * depenindg on the sample size. + * + * - 10-bits per sample + * Every four consecutive samples are packed into 5 bytes. Each of the first 4 + * bytes contain the 8 high order bits of the pixels, and the 5th byte + * contains the 2 least-significant bits of each pixel, in the same order. + * + * - 12-bits per sample + * Every two consecutive samples are packed into three bytes. Each of the + * first two bytes contain the 8 high order bits of the pixels, and the third + * byte contains the four least-significant bits of each pixel, in the same + * order. + * + * - 14-bits per sample + * Every four consecutive samples are packed into seven bytes. Each of the + * first four bytes contain the eight high order bits of the pixels, and the + * three following bytes contains the six least-significant bits of each + * pixel, in the same order. + */ +#define MIPI_FORMAT_MOD_CSI2_PACKED fourcc_mod_code(MIPI, 1) + #if defined(__cplusplus) } #endif From patchwork Mon Mar 16 02:41:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3113 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5BD1760417 for ; Mon, 16 Mar 2020 03:42:33 +0100 (CET) X-Halon-ID: b7223de9-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b7223de9-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:02 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:44 +0100 Message-Id: <20200316024146.2474424-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 4/6] libcamera: buffer: Add helper to memcopy a FrameBuffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:33 -0000 This helper may be used to memory copy a while FrameBuffer content to another buffer. The operation is not fast and should not be used without grate care by pipelines. The intended use-case is to have an option to copy out RAW buffers from the middle of an pipeline. Signed-off-by: Niklas Söderlund --- include/libcamera/buffer.h | 1 + src/libcamera/buffer.cpp | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index 8e5ec699e3925eee..669d2591a90e5f37 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -60,6 +60,7 @@ public: private: friend class Request; /* Needed to update request_. */ friend class V4L2VideoDevice; /* Needed to update metadata_. */ + friend int FrameBufferMemCopy(FrameBuffer *destination, const FrameBuffer *source); std::vector planes_; diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 673a63d3d1658190..f680d1879b57a68b 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -211,4 +211,47 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) * core never modifies the buffer cookie. */ +int FrameBufferMemCopy(FrameBuffer *dst, const FrameBuffer *src) +{ + if (dst->planes_.size() != src->planes_.size()) { + LOG(Buffer, Error) << "Different number of planes"; + return -EINVAL; + } + + for (unsigned int i = 0; i < dst->planes_.size(); i++) { + if (dst->planes_[i].length < src->planes_[i].length) { + LOG(Buffer, Error) << "Plane " << i << " is too small"; + return -EINVAL; + } + } + + for (unsigned int i = 0; i < dst->planes_.size(); i++) { + void *out = mmap(NULL, dst->planes_[i].length, PROT_WRITE, MAP_SHARED, + dst->planes_[i].fd.fd(), 0); + + if (out == MAP_FAILED) { + LOG(Buffer, Error) << "Failed to map output plane " << i; + return -EINVAL; + } + + void *in = mmap(NULL, src->planes_[i].length, PROT_READ, MAP_SHARED, + src->planes_[i].fd.fd(), 0); + + if (in == MAP_FAILED) { + munmap(out, dst->planes_[i].length); + LOG(Buffer, Error) << "Failed to map input plane " << i; + return -EINVAL; + } + + memcpy(out, in, src->planes_[i].length); + + munmap(in, src->planes_[i].length); + munmap(out, dst->planes_[i].length); + } + + dst->metadata_ = src->metadata_; + + return 0; +} + } /* namespace libcamera */ From patchwork Mon Mar 16 02:41:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3114 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D604260417 for ; Mon, 16 Mar 2020 03:42:33 +0100 (CET) X-Halon-ID: b76e5d8f-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b76e5d8f-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:02 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:45 +0100 Message-Id: <20200316024146.2474424-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 5/6] libcamera: ipu3: Do not unconditionally queue buffers to CIO2 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:34 -0000 Instead of unconditionally cycling buffers between the CIO2 and IMGU pick a buffer when a request is queued to the pipeline. This is needed if operations are the be applied to the buffer coming from CIO2 with parameters coming from a Request. The approach to pick a CIO2 buffer when a request is queued is similar to other pipelines, where parameters and statistic buffers are picked this way. Signed-off-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 69 +++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 0c2a217c9ea8f6ba..dbb0c4328aa0efe5 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -119,6 +120,10 @@ public: int allocateBuffers(); void freeBuffers(); + FrameBuffer *getBuffer(); + void putBuffer(FrameBuffer *buffer); + int queueBuffer(FrameBuffer *buffer); + int start(); int stop(); @@ -130,6 +135,7 @@ public: private: std::vector> buffers_; + std::queue availableBuffers_; }; class IPU3Stream : public Stream @@ -157,6 +163,8 @@ public: void imguInputBufferReady(FrameBuffer *buffer); void cio2BufferReady(FrameBuffer *buffer); + std::map cio2ToRequest_; + CIO2Device cio2_; ImgUDevice *imgu_; @@ -717,11 +725,20 @@ void PipelineHandlerIPU3::stop(Camera *camera) int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) { + IPU3CameraData *data = cameraData(camera); + FrameBuffer *buffer; int error = 0; + /* Get a CIO2 buffer and track it it's used for this request. */ + buffer = data->cio2_.getBuffer(); + if (!buffer) + return -EINVAL; + data->cio2ToRequest_[buffer] = request; + data->cio2_.queueBuffer(buffer); + for (auto it : request->buffers()) { IPU3Stream *stream = static_cast(it.first); - FrameBuffer *buffer = it.second; + buffer = it.second; int ret = stream->device_->dev->queueBuffer(buffer); if (ret < 0) @@ -893,7 +910,9 @@ void IPU3CameraData::imguInputBufferReady(FrameBuffer *buffer) if (buffer->metadata().status == FrameMetadata::FrameCancelled) return; - cio2_.output_->queueBuffer(buffer); + /* Remove association between CIO2 buffer an Request. */ + cio2ToRequest_.erase(buffer); + cio2_.putBuffer(buffer); } /** @@ -1416,30 +1435,58 @@ int CIO2Device::configure(const Size &size, int CIO2Device::allocateBuffers() { int ret = output_->allocateBuffers(CIO2_BUFFER_COUNT, &buffers_); - if (ret < 0) + if (ret < 0) { LOG(IPU3, Error) << "Failed to allocate CIO2 buffers"; + return ret; + } + + for (std::unique_ptr &buffer : buffers_) + availableBuffers_.push(buffer.get()); return ret; } void CIO2Device::freeBuffers() { + while (!availableBuffers_.empty()) + availableBuffers_.pop(); + buffers_.clear(); if (output_->releaseBuffers()) LOG(IPU3, Error) << "Failed to release CIO2 buffers"; } +FrameBuffer *CIO2Device::getBuffer() +{ + if (availableBuffers_.empty()) { + LOG(IPU3, Error) << "CIO2 buffer underrun"; + return nullptr; + } + + FrameBuffer *buffer = availableBuffers_.front(); + + availableBuffers_.pop(); + + return buffer; +} + +void CIO2Device::putBuffer(FrameBuffer *buffer) +{ + availableBuffers_.push(buffer); +} + +int CIO2Device::queueBuffer(FrameBuffer *buffer) +{ + int ret = output_->queueBuffer(buffer); + if (ret) + LOG(IPU3, Error) << "Failed to queue CIO2 buffer"; + + return ret; +} + int CIO2Device::start() { - for (const std::unique_ptr &buffer : buffers_) { - int ret = output_->queueBuffer(buffer.get()); - if (ret) { - LOG(IPU3, Error) << "Failed to queue CIO2 buffer"; - return ret; - } - } - return output_->streamOn(); } From patchwork Mon Mar 16 02:41:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3115 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 95B2E62968 for ; Mon, 16 Mar 2020 03:42:34 +0100 (CET) X-Halon-ID: b7c73f31-672f-11ea-9f40-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id b7c73f31-672f-11ea-9f40-0050569116f7; Mon, 16 Mar 2020 03:42:03 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Mar 2020 03:41:46 +0100 Message-Id: <20200316024146.2474424-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> References: <20200316024146.2474424-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 6/6] libcamera: ipu3: Add support for a RAW still capture stream X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 02:42:35 -0000 Allow the RAW buffer cycling between CIO2 and IMGU to be memory copied to a new FrameBuffer in a new RAW stream. This allows users to capture the raw Bayer format coming from the sensor. As the RAW frame is memory copied queueing requests with the StillCaptureRaw stream might impact performance. Signed-off-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 83 +++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index dbb0c4328aa0efe5..18d9ad4d7318a034 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -142,11 +142,12 @@ class IPU3Stream : public Stream { public: IPU3Stream() - : active_(false), device_(nullptr) + : active_(false), raw_(false), device_(nullptr) { } bool active_; + bool raw_; std::string name_; ImgUDevice::ImgUOutput *device_; }; @@ -170,6 +171,7 @@ public: IPU3Stream outStream_; IPU3Stream vfStream_; + IPU3Stream rawStream_; }; class IPU3CameraConfiguration : public CameraConfiguration @@ -308,8 +310,8 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() return Invalid; /* Cap the number of entries to the available streams. */ - if (config_.size() > 2) { - config_.resize(2); + if (config_.size() > 3) { + config_.resize(3); status = Adjusted; } @@ -322,6 +324,8 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() Size size = {}; for (const StreamConfiguration &cfg : config_) { + if (cfg.pixelFormat.modifiers().count(IPU3_FORMAT_MOD_PACKED)) + continue; if (cfg.size.width > size.width) size.width = cfg.size.width; if (cfg.size.height > size.height) @@ -349,6 +353,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() std::set availableStreams = { &data_->outStream_, &data_->vfStream_, + &data_->rawStream_, }; streams_.clear(); @@ -360,7 +365,9 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() const Size size = cfg.size; const IPU3Stream *stream; - if (cfg.size == sensorFormat_.size) + if (cfg.pixelFormat.modifiers().count(IPU3_FORMAT_MOD_PACKED)) + stream = &data_->rawStream_; + else if (cfg.size == sensorFormat_.size) stream = &data_->outStream_; else stream = &data_->vfStream_; @@ -371,8 +378,15 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() LOG(IPU3, Debug) << "Assigned '" << stream->name_ << "' to stream " << i; - bool scale = stream == &data_->vfStream_; - adjustStream(config_[i], scale); + if (stream == &data_->rawStream_) { + cfg.pixelFormat = PixelFormat(DRM_FORMAT_SRGGB10, + { IPU3_FORMAT_MOD_PACKED }); + cfg.size = sensor->resolution(); + cfg.bufferCount = IPU3_BUFFER_COUNT; + } else { + bool scale = stream == &data_->vfStream_; + adjustStream(config_[i], scale); + } if (cfg.pixelFormat != pixelFormat || cfg.size != size) { LOG(IPU3, Debug) @@ -401,6 +415,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, std::set streams = { &data->outStream_, &data->vfStream_, + &data->rawStream_, }; config = new IPU3CameraConfiguration(camera, data); @@ -442,6 +457,21 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, break; + case StreamRole::StillCaptureRaw: { + if (streams.find(&data->rawStream_) == streams.end()) { + LOG(IPU3, Error) + << "No stream available for requested role " + << role; + break; + } + + stream = &data->rawStream_; + + cfg.pixelFormat = PixelFormat(DRM_FORMAT_SRGGB10, { IPU3_FORMAT_MOD_PACKED }); + cfg.size = data->cio2_.sensor_->resolution(); + break; + } + case StreamRole::Viewfinder: case StreamRole::VideoRecording: { /* @@ -575,6 +605,9 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) stream->active_ = true; cfg.setStream(stream); + if (stream->raw_) + continue; + ret = imgu->configureOutput(stream->device_, cfg); if (ret) return ret; @@ -625,9 +658,15 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) { + IPU3CameraData *data = cameraData(camera); IPU3Stream *ipu3stream = static_cast(stream); - V4L2VideoDevice *video = ipu3stream->device_->dev; unsigned int count = stream->configuration().bufferCount; + V4L2VideoDevice *video; + + if (ipu3stream->raw_) + video = data->cio2_.output_; + else + video = ipu3stream->device_->dev; return video->exportBuffers(count, buffers); } @@ -740,6 +779,9 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) IPU3Stream *stream = static_cast(it.first); buffer = it.second; + if (stream->raw_) + continue; + int ret = stream->device_->dev->queueBuffer(buffer); if (ret < 0) error = ret; @@ -834,6 +876,7 @@ int PipelineHandlerIPU3::registerCameras() std::set streams = { &data->outStream_, &data->vfStream_, + &data->rawStream_, }; CIO2Device *cio2 = &data->cio2_; @@ -855,6 +898,8 @@ int PipelineHandlerIPU3::registerCameras() data->outStream_.name_ = "output"; data->vfStream_.device_ = &data->imgu_->viewfinder_; data->vfStream_.name_ = "viewfinder"; + data->rawStream_.raw_ = true; + data->rawStream_.name_ = "raw"; /* * Connect video devices' 'bufferReady' signals to their @@ -946,7 +991,29 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) if (buffer->metadata().status == FrameMetadata::FrameCancelled) return; - imgu_->input_->queueBuffer(buffer); + Request *request = cio2ToRequest_[buffer]; + FrameBuffer *raw = request->findBuffer(&rawStream_); + + if (!raw) { + /* No RAW buffers present, just queue to IMGU. */ + imgu_->input_->queueBuffer(buffer); + return; + } + + /* RAW buffers present, special care is needed. */ + if (request->buffers().size() > 1) + imgu_->input_->queueBuffer(buffer); + + if (FrameBufferMemCopy(raw, buffer)) + LOG(IPU3, Debug) << "Memcopy of FrameBuffer Failed"; + + pipe_->completeBuffer(camera_, request, raw); + + if (request->buffers().size() == 1) { + cio2ToRequest_.erase(buffer); + cio2_.putBuffer(buffer); + pipe_->completeRequest(camera_, request); + } } /* -----------------------------------------------------------------------------