From 7da6b95283af4d8ad0fc9ce75422dce2c3875ba9 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Mon, 4 Feb 2019 18:29:11 +0100 Subject: libcamera: pipeline: ipu3: Create video devices and subdevices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(-) (limited to 'src') diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 3f096bf1..9629057a 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)); -- cgit v1.2.1