[libcamera-devel,v2,3/3] libcamera: pipeline: uvcvideo: create a V4L2Device for the default video entity

Message ID 20190125143951.27992-4-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamera: pipeline: uvcvideo: attach to a V4L2Device
Related show

Commit Message

Niklas Söderlund Jan. 25, 2019, 2:39 p.m. UTC
Add a V4L2Device for the default video entity in the media graph. The
UVC pipeline needs to search for the entity marked with the
MEDIA_ENT_FL_DEFAULT flag as the entity names in the media graph varies
depending on which device is used.

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

Comments

Laurent Pinchart Jan. 25, 2019, 2:49 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Fri, Jan 25, 2019 at 03:39:51PM +0100, Niklas Söderlund wrote:
> Add a V4L2Device for the default video entity in the media graph. The
> UVC pipeline needs to search for the entity marked with the
> MEDIA_ENT_FL_DEFAULT flag as the entity names in the media graph varies
> depending on which device is used.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/pipeline/uvcvideo.cpp | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
> index 1a445edfa8df777c..e3a475704c080e90 100644
> --- a/src/libcamera/pipeline/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo.cpp
> @@ -11,6 +11,7 @@
>  #include "log.h"
>  #include "media_device.h"
>  #include "pipeline_handler.h"
> +#include "v4l2_device.h"
>  
>  namespace libcamera {
>  
> @@ -26,15 +27,20 @@ public:
>  
>  private:
>  	std::shared_ptr<MediaDevice> media_;
> +

I wouldn't have added a blank line, but it's up to you :-)

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

> +	V4L2Device *video_;
>  };
>  
>  PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager)
> -	: PipelineHandler(manager), media_(nullptr)
> +	: PipelineHandler(manager), media_(nullptr), video_(nullptr)
>  {
>  }
>  
>  PipelineHandlerUVC::~PipelineHandlerUVC()
>  {
> +	if (video_)
> +		delete video_;
> +
>  	if (media_)
>  		media_->release();
>  }
> @@ -50,6 +56,18 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
>  
>  	media_->acquire();
>  
> +	for (MediaEntity *entity : media_->entities()) {
> +		if (entity->flags() & MEDIA_ENT_FL_DEFAULT) {
> +			video_ = new V4L2Device(*entity);
> +			break;
> +		}
> +	}
> +
> +	if (!video_ || video_->open()) {
> +		media_->release();
> +		return false;
> +	}
> +
>  	std::shared_ptr<Camera> camera = Camera::create(this, media_->model());
>  	registerCamera(std::move(camera));
>  	hotplugMediaDevice(media_.get());

Patch

diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 1a445edfa8df777c..e3a475704c080e90 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -11,6 +11,7 @@ 
 #include "log.h"
 #include "media_device.h"
 #include "pipeline_handler.h"
+#include "v4l2_device.h"
 
 namespace libcamera {
 
@@ -26,15 +27,20 @@  public:
 
 private:
 	std::shared_ptr<MediaDevice> media_;
+
+	V4L2Device *video_;
 };
 
 PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager)
-	: PipelineHandler(manager), media_(nullptr)
+	: PipelineHandler(manager), media_(nullptr), video_(nullptr)
 {
 }
 
 PipelineHandlerUVC::~PipelineHandlerUVC()
 {
+	if (video_)
+		delete video_;
+
 	if (media_)
 		media_->release();
 }
@@ -50,6 +56,18 @@  bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
 
 	media_->acquire();
 
+	for (MediaEntity *entity : media_->entities()) {
+		if (entity->flags() & MEDIA_ENT_FL_DEFAULT) {
+			video_ = new V4L2Device(*entity);
+			break;
+		}
+	}
+
+	if (!video_ || video_->open()) {
+		media_->release();
+		return false;
+	}
+
 	std::shared_ptr<Camera> camera = Camera::create(this, media_->model());
 	registerCamera(std::move(camera));
 	hotplugMediaDevice(media_.get());