[libcamera-devel,3/7] libcamera: pipeline: uvcvideo: Initialize CameraData from MediaDevice

Message ID 20200806130937.2991606-4-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamera: Allow for user-friendly names in applications
Related show

Commit Message

Niklas Söderlund Aug. 6, 2020, 1:09 p.m. UTC
The UVCCameraData::init() is the only consumer of the default entry in
the media graph, move the lookup of it into the init() function and pass
it the MediaDevice. This is done in preparation to extend the CameraData
initialization to consume more information form the MediaDevice.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 30 ++++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

Comments

Laurent Pinchart Aug. 8, 2020, 8:23 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Thu, Aug 06, 2020 at 03:09:33PM +0200, Niklas Söderlund wrote:
> The UVCCameraData::init() is the only consumer of the default entry in
> the media graph, move the lookup of it into the init() function and pass
> it the MediaDevice. This is done in preparation to extend the CameraData
> initialization to consume more information form the MediaDevice.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 30 ++++++++++----------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index bc892ecfac046881..b12083a7a74dae54 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -43,7 +43,7 @@ public:
>  		delete video_;
>  	}
>  
> -	int init(MediaEntity *entity);
> +	int init(MediaDevice *media);
>  	void addControl(uint32_t cid, const ControlInfo &v4l2info,
>  			ControlInfoMap::Map *ctrls);
>  	void bufferReady(FrameBuffer *buffer);
> @@ -457,18 +457,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
>  
>  	std::unique_ptr<UVCCameraData> data = std::make_unique<UVCCameraData>(this);
>  
> -	/* Locate and initialise the camera data with the default video node. */
> -	const std::vector<MediaEntity *> &entities = media->entities();
> -	auto entity = std::find_if(entities.begin(), entities.end(),
> -				   [](MediaEntity *entity) {
> -					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
> -				   });
> -	if (entity == entities.end()) {
> -		LOG(UVC, Error) << "Could not find a default video device";
> -		return false;
> -	}
> -
> -	if (data->init(*entity))
> +	if (data->init(media))
>  		return false;
>  
>  	/* Create and register the camera. */
> @@ -488,12 +477,23 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
>  	return true;
>  }
>  
> -int UVCCameraData::init(MediaEntity *entity)
> +int UVCCameraData::init(MediaDevice *media)
>  {
>  	int ret;
>  
> +	/* Locate and initialise the camera data with the default video node. */
> +	const std::vector<MediaEntity *> &entities = media->entities();
> +	auto entity = std::find_if(entities.begin(), entities.end(),
> +				   [](MediaEntity *entity) {
> +					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
> +				   });
> +	if (entity == entities.end()) {
> +		LOG(UVC, Error) << "Could not find a default video device";
> +		return -ENODEV;
> +	}
> +
>  	/* Create and open the video device. */
> -	video_ = new V4L2VideoDevice(entity);
> +	video_ = new V4L2VideoDevice(*entity);
>  	ret = video_->open();
>  	if (ret)
>  		return ret;

Patch

diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index bc892ecfac046881..b12083a7a74dae54 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -43,7 +43,7 @@  public:
 		delete video_;
 	}
 
-	int init(MediaEntity *entity);
+	int init(MediaDevice *media);
 	void addControl(uint32_t cid, const ControlInfo &v4l2info,
 			ControlInfoMap::Map *ctrls);
 	void bufferReady(FrameBuffer *buffer);
@@ -457,18 +457,7 @@  bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
 
 	std::unique_ptr<UVCCameraData> data = std::make_unique<UVCCameraData>(this);
 
-	/* Locate and initialise the camera data with the default video node. */
-	const std::vector<MediaEntity *> &entities = media->entities();
-	auto entity = std::find_if(entities.begin(), entities.end(),
-				   [](MediaEntity *entity) {
-					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
-				   });
-	if (entity == entities.end()) {
-		LOG(UVC, Error) << "Could not find a default video device";
-		return false;
-	}
-
-	if (data->init(*entity))
+	if (data->init(media))
 		return false;
 
 	/* Create and register the camera. */
@@ -488,12 +477,23 @@  bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
 	return true;
 }
 
-int UVCCameraData::init(MediaEntity *entity)
+int UVCCameraData::init(MediaDevice *media)
 {
 	int ret;
 
+	/* Locate and initialise the camera data with the default video node. */
+	const std::vector<MediaEntity *> &entities = media->entities();
+	auto entity = std::find_if(entities.begin(), entities.end(),
+				   [](MediaEntity *entity) {
+					   return entity->flags() & MEDIA_ENT_FL_DEFAULT;
+				   });
+	if (entity == entities.end()) {
+		LOG(UVC, Error) << "Could not find a default video device";
+		return -ENODEV;
+	}
+
 	/* Create and open the video device. */
-	video_ = new V4L2VideoDevice(entity);
+	video_ = new V4L2VideoDevice(*entity);
 	ret = video_->open();
 	if (ret)
 		return ret;