From patchwork Fri Apr 19 10:18:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1077 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C6B460DCD for ; Fri, 19 Apr 2019 12:17:54 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 9BFCFFF806; Fri, 19 Apr 2019 10:17:53 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 19 Apr 2019 12:18:35 +0200 Message-Id: <20190419101839.10337-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190419101839.10337-1-jacopo@jmondi.org> References: <20190419101839.10337-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 4/8] libcamera: ipu3: Use roles in stream configuration 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: Fri, 19 Apr 2019 10:17:55 -0000 Use and inspect the stream roles provided by the application to streamConfiguration() to assign streams to their intended roles and return a default configuration associated with them. Support a limited number of usages, with the viewfinder stream able to capture both continuous video streams and still images, and the main output stream supporting still images images. This is an artificial limitation until we figure out the exact capabilities of the hardware. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 113 ++++++++++++++++++++------- 1 file changed, 83 insertions(+), 30 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9b2d96f22b2b..45edc24b5d4c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -5,6 +5,7 @@ * ipu3.cpp - Pipeline handler for Intel IPU3 */ +#include #include #include #include @@ -222,38 +223,90 @@ CameraConfiguration PipelineHandlerIPU3::streamConfiguration(Camera *camera, const std::vector &usages) { - CameraConfiguration configs; IPU3CameraData *data = cameraData(camera); - StreamConfiguration config = {}; + CameraConfiguration cameraConfig; + std::set streams = { + &data->outStream_, + &data->vfStream_, + }; - /* - * FIXME: Soraka: the maximum resolution reported by both sensors - * (2592x1944 for ov5670 and 4224x3136 for ov13858) are returned as - * default configurations but they're not correctly processed by the - * ImgU. Resolutions up tp 2560x1920 have been validated. - * - * \todo Clarify ImgU alignement requirements. - */ - config.width = 2560; - config.height = 1920; - config.pixelFormat = V4L2_PIX_FMT_NV12; - config.bufferCount = IPU3_BUFFER_COUNT; - - configs[&data->outStream_] = config; - LOG(IPU3, Debug) - << "Stream '" << data->outStream_.name_ << "' set to " - << config.width << "x" << config.height << "-0x" - << std::hex << std::setfill('0') << std::setw(8) - << config.pixelFormat; - - configs[&data->vfStream_] = config; - LOG(IPU3, Debug) - << "Stream '" << data->vfStream_.name_ << "' set to " - << config.width << "x" << config.height << "-0x" - << std::hex << std::setfill('0') << std::setw(8) - << config.pixelFormat; - - return configs; + for (const StreamUsage &usage : usages) { + std::vector::iterator found; + StreamUsage::Role role = usage.role(); + StreamConfiguration streamConfig = {}; + IPU3Stream *stream = nullptr; + + if (role == StreamUsage::Role::StillCapture) { + /* + * Don't allow viewfinder or video capture on the + * 'output stream. This is an artificial limitation + * until we figure out the capabilities of the + * hardware. + */ + if (streams.find(&data->outStream_) != streams.end()) + stream = &data->outStream_; + else if (streams.find(&data->vfStream_) != streams.end()) + stream = &data->vfStream_; + else + goto error; + + /* + * FIXME: Soraka: the maximum resolution reported by + * both sensors (2592x1944 for ov5670 and 4224x3136 for + * ov13858) are returned as default configurations but + * they're not correctly processed by the ImgU. + * Resolutions up tp 2560x1920 have been validated. + * + * \todo Clarify ImgU alignment requirements. + */ + streamConfig.width = 2560; + streamConfig.height = 1920; + } else if (role == StreamUsage::Role::Viewfinder || + role == StreamUsage::Role::VideoRecording) { + /* + * We can't use the 'output' stream for viewfinder or + * video capture usages. + */ + if (streams.find(&data->vfStream_) == streams.end()) + goto error; + + stream = &data->vfStream_; + + + /* + * Align the requested viewfinder size to the + * maximum available sensor resolution and to the + * IPU3 alignment constraints. + */ + const Size &res = data->cio2_.sensor_->resolution(); + unsigned int width = std::min(usage.size().width, + res.width); + unsigned int height = std::min(usage.size().height, + res.height); + streamConfig.width = width & ~7; + streamConfig.height = height & ~3; + } + + streams.erase(stream); + + streamConfig.pixelFormat = V4L2_PIX_FMT_NV12; + streamConfig.bufferCount = IPU3_BUFFER_COUNT; + + cameraConfig[stream] = streamConfig; + + LOG(IPU3, Debug) + << "Stream '" << stream->name_ << "' format set to " + << streamConfig.width << "x" << streamConfig.height + << "-0x" << std::hex << std::setfill('0') + << std::setw(8) << streamConfig.pixelFormat; + } + + return cameraConfig; + +error: + LOG(IPU3, Error) << "Requested stream roles not supported"; + + return CameraConfiguration{}; } int PipelineHandlerIPU3::configureStreams(Camera *camera,