From patchwork Thu Feb 28 16:29:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 655 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 8CBEE610B6 for ; Thu, 28 Feb 2019 17:29:25 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1ABF349 for ; Thu, 28 Feb 2019 17:29:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551371365; bh=7FvWZq179Oj/YrYcO2feox0TvkwfyhVFEakflXYIuUM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=G+0+/CjZi3itgwHc9gRc3BDojj8kukj+cvmK65JIVydpZGIdontrWTt+EbBVCNmef xGu561UXf8chutohU7RD6VvB7VYprOUO+Js+5MGXMHHWdt+0KP2Ljr3+R7vhHOlV+6 kB6bLn4lXIeIcihA4gzCNcRavG0GHkD1YqF9RYEM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 18:29:05 +0200 Message-Id: <20190228162913.6508-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> References: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/10] libcamera: pipeline: uvcvideo: Create UVCCameraData 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: Thu, 28 Feb 2019 16:29:25 -0000 Subclassing CameraData will become mandatory for pipeline handlers. Create a new UVCCameraData class and instantiate it when creating cameras to prepare for that change. The video_ and stream_ fields of the UVC pipeline handler belong to the camera data, move them there. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/uvcvideo.cpp | 74 +++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index dd20bb085a29..4ad311163a95 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -13,6 +13,7 @@ #include "log.h" #include "media_device.h" #include "pipeline_handler.h" +#include "utils.h" #include "v4l2_device.h" namespace libcamera { @@ -42,21 +43,38 @@ public: bool match(DeviceEnumerator *enumerator); private: + class UVCCameraData : public CameraData + { + public: + UVCCameraData() + { + } + + ~UVCCameraData() + { + delete video_; + } + + V4L2Device *video_; + Stream stream_; + }; + + UVCCameraData *cameraData(const Camera *camera) + { + return static_cast( + PipelineHandler::cameraData(camera)); + } + std::shared_ptr media_; - V4L2Device *video_; - Stream stream_; }; PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) - : PipelineHandler(manager), media_(nullptr), video_(nullptr) + : PipelineHandler(manager), media_(nullptr) { } PipelineHandlerUVC::~PipelineHandlerUVC() { - if (video_) - delete video_; - if (media_) media_->release(); } @@ -65,8 +83,9 @@ std::map PipelineHandlerUVC::streamConfiguration(Camera *camera, std::vector &streams) { + UVCCameraData *data = cameraData(camera); + std::map configs; - StreamConfiguration config{}; LOG(UVC, Debug) << "Retrieving default format"; @@ -75,7 +94,7 @@ PipelineHandlerUVC::streamConfiguration(Camera *camera, config.pixelFormat = V4L2_PIX_FMT_YUYV; config.bufferCount = 4; - configs[&stream_] = config; + configs[&data->stream_] = config; return configs; } @@ -83,7 +102,8 @@ PipelineHandlerUVC::streamConfiguration(Camera *camera, int PipelineHandlerUVC::configureStreams(Camera *camera, std::map &config) { - StreamConfiguration *cfg = &config[&stream_]; + UVCCameraData *data = cameraData(camera); + StreamConfiguration *cfg = &config[&data->stream_]; int ret; LOG(UVC, Debug) << "Configure the camera for resolution " @@ -94,7 +114,7 @@ int PipelineHandlerUVC::configureStreams(Camera *camera, format.height = cfg->height; format.fourcc = cfg->pixelFormat; - ret = video_->setFormat(&format); + ret = data->video_->setFormat(&format); if (ret) return ret; @@ -108,31 +128,36 @@ int PipelineHandlerUVC::configureStreams(Camera *camera, int PipelineHandlerUVC::allocateBuffers(Camera *camera, Stream *stream) { + UVCCameraData *data = cameraData(camera); const StreamConfiguration &cfg = stream->configuration(); LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; - return video_->exportBuffers(&stream->bufferPool()); + return data->video_->exportBuffers(&stream->bufferPool()); } int PipelineHandlerUVC::freeBuffers(Camera *camera, Stream *stream) { - return video_->releaseBuffers(); + UVCCameraData *data = cameraData(camera); + return data->video_->releaseBuffers(); } int PipelineHandlerUVC::start(const Camera *camera) { - return video_->streamOn(); + UVCCameraData *data = cameraData(camera); + return data->video_->streamOn(); } void PipelineHandlerUVC::stop(const Camera *camera) { - video_->streamOff(); + UVCCameraData *data = cameraData(camera); + data->video_->streamOff(); } int PipelineHandlerUVC::queueRequest(const Camera *camera, Request *request) { - Buffer *buffer = request->findBuffer(&stream_); + UVCCameraData *data = cameraData(camera); + Buffer *buffer = request->findBuffer(&data->stream_); if (!buffer) { LOG(UVC, Error) << "Attempt to queue request with invalid stream"; @@ -140,7 +165,7 @@ int PipelineHandlerUVC::queueRequest(const Camera *camera, Request *request) return -ENOENT; } - video_->queueBuffer(buffer); + data->video_->queueBuffer(buffer); return 0; } @@ -150,29 +175,36 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) DeviceMatch dm("uvcvideo"); media_ = enumerator->search(dm); - if (!media_) return false; media_->acquire(); + std::unique_ptr data = utils::make_unique(); + + /* Locate and open the default video node. */ for (MediaEntity *entity : media_->entities()) { if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { - video_ = new V4L2Device(entity); + data->video_ = new V4L2Device(entity); break; } } - if (!video_ || video_->open()) { - if (!video_) + if (!data->video_ || data->video_->open()) { + if (!data->video_) LOG(UVC, Error) << "Could not find a default video device"; return false; } - std::vector streams{ &stream_ }; + /* Create and register the camera. */ + std::vector streams{ &data->stream_ }; std::shared_ptr camera = Camera::create(this, media_->model(), streams); + + setCameraData(camera.get(), std::move(data)); registerCamera(std::move(camera)); + + /* Enable hot-unplug notifications. */ hotplugMediaDevice(media_.get()); return true;