From patchwork Wed Feb 6 06:08:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 538 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 1303D6102A for ; Wed, 6 Feb 2019 07:08:29 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B4B942D7 for ; Wed, 6 Feb 2019 07:08:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433308; bh=BRNAza+w9JzDD6WKA/TZlvelODYw38XZ+wNVJP90JK4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rqTEbixDU4UoN3tZdQPCbOZ3frp4a/rM80mEm7L4eGXnw5XXfXLxMyJ0gRnljQAuh H5libZTXOPRyORUiT3lEiN40UyTS3QskOVIqcg+sjAkMUSpFmeokjusUribWPD/Zvk s0pLrUBohxoV1ghZ/0LOJ5YZ0Ov3TW9CLzl2lkH4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:08:14 +0200 Message-Id: <20190206060818.13907-24-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 23/27] libcamera: pipeline: ipu3: Create video devices and subdevices 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: Wed, 06 Feb 2019 06:08:30 -0000 From: Jacopo Mondi Create the video devices and subdevices associated with an IPU3 camera. While at there, move the IPU3 pipeline handler class definition and the associated IPU3CameraData to a separate header as the class has now grown enough. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 76 ++++++++++++++++------------ 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 3f096bf1251b..9629057a1b2f 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -17,6 +17,7 @@ #include "pipeline_handler.h" #include "utils.h" #include "v4l2_device.h" +#include "v4l2_subdevice.h" namespace libcamera { @@ -49,23 +50,32 @@ private: { public: IPU3CameraData() - : dev_(nullptr) {} - ~IPU3CameraData() { delete dev_; } - V4L2Device *dev_; + : cio2_(nullptr), csi2_(nullptr), sensor_(nullptr) {} + + ~IPU3CameraData() + { + delete cio2_; + delete csi2_; + delete sensor_; + } + + V4L2Device *cio2_; + V4L2Subdevice *csi2_; + V4L2Subdevice *sensor_; + Stream stream_; }; - std::shared_ptr cio2_; - std::shared_ptr imgu_; - IPU3CameraData *cameraData(const Camera *camera) { return static_cast( PipelineHandler::cameraData(camera)); } - V4L2Device *createVideoDevice(unsigned int id); void registerCameras(); + + std::shared_ptr cio2_; + std::shared_ptr imgu_; }; PipelineHandlerIPU3::PipelineHandlerIPU3(CameraManager *manager) @@ -208,24 +218,6 @@ error_release_mdev: return false; } -/* Create video devices for the CIO2 unit associated with a camera. */ -V4L2Device *PipelineHandlerIPU3::createVideoDevice(unsigned int id) -{ - std::string cio2Name = "ipu3-cio2 " + std::to_string(id); - MediaEntity *cio2 = cio2_->getEntityByName(cio2Name); - if (!cio2) - return nullptr; - - V4L2Device *dev = new V4L2Device(cio2); - if (dev->open()) { - delete dev; - return nullptr; - } - dev->close(); - - return dev; -} - /* * Cameras are created associating an image sensor (represented by a * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four @@ -241,6 +233,7 @@ void PipelineHandlerIPU3::registerCameras() for (unsigned int id = 0; id < 4; ++id) { std::string csi2Name = "ipu3-csi2 " + std::to_string(id); MediaEntity *csi2 = cio2_->getEntityByName(csi2Name); + int ret; /* * This shall not happen, as the device enumerator matched @@ -281,18 +274,37 @@ void PipelineHandlerIPU3::registerCameras() std::shared_ptr camera = Camera::create(this, cameraName, streams); /* - * If V4L2 device creation fails, the Camera instance won't be - * registered. The 'camera' shared pointer goes out of scope - * and deletes the Camera it manages. + * Create and open video devices and subdevices associated with + * the camera. + * + * If any of these operations fails, the Camera instance won't + * be registered. The 'camera' shared pointer and the 'data' + * unique pointers go out of scope and delete the objects they + * manage. */ - data->dev_ = createVideoDevice(id); - if (!data->dev_) { + std::string cio2Name = "ipu3-cio2 " + std::to_string(id); + MediaEntity *cio2 = cio2_->getEntityByName(cio2Name); + if (!cio2) { LOG(IPU3, Error) - << "Failed to register camera[" - << numCameras << "] \"" << cameraName << "\""; + << "Failed to get entity '" << cio2Name << "'"; continue; } + data->cio2_ = new V4L2Device(cio2); + ret = data->cio2_->open(); + if (ret) + continue; + + data->sensor_ = new V4L2Subdevice(sensor); + ret = data->sensor_->open(); + if (ret) + continue; + + data->csi2_ = new V4L2Subdevice(csi2); + ret = data->csi2_->open(); + if (ret) + continue; + setCameraData(camera.get(), std::move(data)); registerCamera(std::move(camera));