summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-02-04 18:29:11 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-02-06 08:03:03 +0200
commit7da6b95283af4d8ad0fc9ce75422dce2c3875ba9 (patch)
tree4a74161b966fa042d77e3a6a855d3c0e78923cac /src
parent8cbe8fe650efca1119c456d9c6e6a99da9e12db7 (diff)
libcamera: pipeline: ipu3: Create video devices and subdevices
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 <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/pipeline/ipu3/ipu3.cpp76
1 files changed, 44 insertions, 32 deletions
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<MediaDevice> cio2_;
- std::shared_ptr<MediaDevice> imgu_;
-
IPU3CameraData *cameraData(const Camera *camera)
{
return static_cast<IPU3CameraData *>(
PipelineHandler::cameraData(camera));
}
- V4L2Device *createVideoDevice(unsigned int id);
void registerCameras();
+
+ std::shared_ptr<MediaDevice> cio2_;
+ std::shared_ptr<MediaDevice> 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 = 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));