[libcamera-devel,07/20] libcamera: pipeline: simple: converter: Replace open() with isValid()
diff mbox series

Message ID 20210131224702.8838-8-laurent.pinchart@ideasonboard.com
State Accepted
Delegated to: Laurent Pinchart
Headers show
Series
  • [libcamera-devel,01/20] libcamera: pipeline: simple: Manage converter with std::unique_ptr<>
Related show

Commit Message

Laurent Pinchart Jan. 31, 2021, 10:46 p.m. UTC
Simplify the SimpleConverter interface by opening the M2M device in the
constructor. The explicit call to open() is replaced by a check through
a new isValid() function, and the unused close() function is removed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/pipeline/simple/converter.cpp | 20 ++++++--------------
 src/libcamera/pipeline/simple/converter.h   |  3 +--
 src/libcamera/pipeline/simple/simple.cpp    |  4 ++--
 3 files changed, 9 insertions(+), 18 deletions(-)

Comments

Kieran Bingham Feb. 19, 2021, 5:27 p.m. UTC | #1
On 31/01/2021 22:46, Laurent Pinchart wrote:
> Simplify the SimpleConverter interface by opening the M2M device in the
> constructor. The explicit call to open() is replaced by a check through
> a new isValid() function, and the unused close() function is removed.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/pipeline/simple/converter.cpp | 20 ++++++--------------
>  src/libcamera/pipeline/simple/converter.h   |  3 +--
>  src/libcamera/pipeline/simple/simple.cpp    |  4 ++--
>  3 files changed, 9 insertions(+), 18 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 6b3249ea92b0..f782fbc63b09 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -39,24 +39,16 @@ SimpleConverter::SimpleConverter(MediaDevice *media)
>  
>  	m2m_ = std::make_unique<V4L2M2MDevice>((*it)->deviceNode());
>  
> +	int ret = m2m_->open();
> +	if (ret < 0) {
> +		m2m_.reset();
> +		return;
> +	}
> +
>  	m2m_->output()->bufferReady.connect(this, &SimpleConverter::outputBufferReady);
>  	m2m_->capture()->bufferReady.connect(this, &SimpleConverter::captureBufferReady);
>  }
>  
> -int SimpleConverter::open()
> -{
> -	if (!m2m_)
> -		return -ENODEV;
> -
> -	return m2m_->open();
> -}
> -
> -void SimpleConverter::close()
> -{
> -	if (m2m_)
> -		m2m_->close();
> -}
> -
>  std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
>  {
>  	if (!m2m_)
> diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
> index a1503a6099ff..780bfa8f7832 100644
> --- a/src/libcamera/pipeline/simple/converter.h
> +++ b/src/libcamera/pipeline/simple/converter.h
> @@ -30,8 +30,7 @@ class SimpleConverter
>  public:
>  	SimpleConverter(MediaDevice *media);
>  
> -	int open();
> -	void close();
> +	bool isValid() const { return m2m_ != nullptr; }
>  
>  	std::vector<PixelFormat> formats(PixelFormat input);
>  	SizeRange sizes(const Size &input);
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 8c0bca36bbfb..20a4ebca94fd 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -763,9 +763,9 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
>  	/* Open the converter, if any. */
>  	if (converter) {
>  		converter_ = std::make_unique<SimpleConverter>(converter);
> -		if (converter_->open() < 0) {
> +		if (!converter_->isValid()) {
>  			LOG(SimplePipeline, Warning)
> -				<< "Failed to open converter, disabling format conversion";
> +				<< "Failed to create converter, disabling format conversion";
>  			converter_.reset();
>  		} else {
>  			converter_->bufferReady.connect(this, &SimplePipelineHandler::converterDone);
>
Paul Elder Feb. 22, 2021, 10:11 a.m. UTC | #2
Hi Laurent,

On Mon, Feb 01, 2021 at 12:46:49AM +0200, Laurent Pinchart wrote:
> Simplify the SimpleConverter interface by opening the M2M device in the
> constructor. The explicit call to open() is replaced by a check through
> a new isValid() function, and the unused close() function is removed.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/libcamera/pipeline/simple/converter.cpp | 20 ++++++--------------
>  src/libcamera/pipeline/simple/converter.h   |  3 +--
>  src/libcamera/pipeline/simple/simple.cpp    |  4 ++--
>  3 files changed, 9 insertions(+), 18 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
> index 6b3249ea92b0..f782fbc63b09 100644
> --- a/src/libcamera/pipeline/simple/converter.cpp
> +++ b/src/libcamera/pipeline/simple/converter.cpp
> @@ -39,24 +39,16 @@ SimpleConverter::SimpleConverter(MediaDevice *media)
>  
>  	m2m_ = std::make_unique<V4L2M2MDevice>((*it)->deviceNode());
>  
> +	int ret = m2m_->open();
> +	if (ret < 0) {
> +		m2m_.reset();
> +		return;
> +	}
> +
>  	m2m_->output()->bufferReady.connect(this, &SimpleConverter::outputBufferReady);
>  	m2m_->capture()->bufferReady.connect(this, &SimpleConverter::captureBufferReady);
>  }
>  
> -int SimpleConverter::open()
> -{
> -	if (!m2m_)
> -		return -ENODEV;
> -
> -	return m2m_->open();
> -}
> -
> -void SimpleConverter::close()
> -{
> -	if (m2m_)
> -		m2m_->close();
> -}
> -
>  std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
>  {
>  	if (!m2m_)
> diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
> index a1503a6099ff..780bfa8f7832 100644
> --- a/src/libcamera/pipeline/simple/converter.h
> +++ b/src/libcamera/pipeline/simple/converter.h
> @@ -30,8 +30,7 @@ class SimpleConverter
>  public:
>  	SimpleConverter(MediaDevice *media);
>  
> -	int open();
> -	void close();
> +	bool isValid() const { return m2m_ != nullptr; }
>  
>  	std::vector<PixelFormat> formats(PixelFormat input);
>  	SizeRange sizes(const Size &input);
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 8c0bca36bbfb..20a4ebca94fd 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -763,9 +763,9 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
>  	/* Open the converter, if any. */
>  	if (converter) {
>  		converter_ = std::make_unique<SimpleConverter>(converter);
> -		if (converter_->open() < 0) {
> +		if (!converter_->isValid()) {
>  			LOG(SimplePipeline, Warning)
> -				<< "Failed to open converter, disabling format conversion";
> +				<< "Failed to create converter, disabling format conversion";
>  			converter_.reset();
>  		} else {
>  			converter_->bufferReady.connect(this, &SimplePipelineHandler::converterDone);
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
index 6b3249ea92b0..f782fbc63b09 100644
--- a/src/libcamera/pipeline/simple/converter.cpp
+++ b/src/libcamera/pipeline/simple/converter.cpp
@@ -39,24 +39,16 @@  SimpleConverter::SimpleConverter(MediaDevice *media)
 
 	m2m_ = std::make_unique<V4L2M2MDevice>((*it)->deviceNode());
 
+	int ret = m2m_->open();
+	if (ret < 0) {
+		m2m_.reset();
+		return;
+	}
+
 	m2m_->output()->bufferReady.connect(this, &SimpleConverter::outputBufferReady);
 	m2m_->capture()->bufferReady.connect(this, &SimpleConverter::captureBufferReady);
 }
 
-int SimpleConverter::open()
-{
-	if (!m2m_)
-		return -ENODEV;
-
-	return m2m_->open();
-}
-
-void SimpleConverter::close()
-{
-	if (m2m_)
-		m2m_->close();
-}
-
 std::vector<PixelFormat> SimpleConverter::formats(PixelFormat input)
 {
 	if (!m2m_)
diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
index a1503a6099ff..780bfa8f7832 100644
--- a/src/libcamera/pipeline/simple/converter.h
+++ b/src/libcamera/pipeline/simple/converter.h
@@ -30,8 +30,7 @@  class SimpleConverter
 public:
 	SimpleConverter(MediaDevice *media);
 
-	int open();
-	void close();
+	bool isValid() const { return m2m_ != nullptr; }
 
 	std::vector<PixelFormat> formats(PixelFormat input);
 	SizeRange sizes(const Size &input);
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 8c0bca36bbfb..20a4ebca94fd 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -763,9 +763,9 @@  bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)
 	/* Open the converter, if any. */
 	if (converter) {
 		converter_ = std::make_unique<SimpleConverter>(converter);
-		if (converter_->open() < 0) {
+		if (!converter_->isValid()) {
 			LOG(SimplePipeline, Warning)
-				<< "Failed to open converter, disabling format conversion";
+				<< "Failed to create converter, disabling format conversion";
 			converter_.reset();
 		} else {
 			converter_->bufferReady.connect(this, &SimplePipelineHandler::converterDone);