[libcamera-devel,v2,1/3] libcamera: pipeline: Replace resize() with erase() in validate()

Message ID 20200324175643.22382-2-kgupta@es.iitr.ac.in
State New
Delegated to: Kieran Bingham
Headers show
Series
  • Use StreamFormats in pipelines
Related show

Commit Message

Kaaira Gupta March 24, 2020, 5:56 p.m. UTC
Replace .resize() with .erase() in validate() calls in all pipelines,
because resize() calls default constructor StreamConfiguration() when it
tries to increase the size.

Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp     | 8 ++++++--
 src/libcamera/pipeline/rkisp1/rkisp1.cpp | 8 ++++++--
 src/libcamera/pipeline/uvcvideo.cpp      | 8 ++++++--
 src/libcamera/pipeline/vimc.cpp          | 8 ++++++--
 4 files changed, 24 insertions(+), 8 deletions(-)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 1b44460..36f3990 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -298,9 +298,13 @@  CameraConfiguration::Status IPU3CameraConfiguration::validate()
 	if (config_.empty())
 		return Invalid;
 
-	/* Cap the number of entries to the available streams. */
+	/*
+	 * Cap the number of entries to the available streams.
+	 * Use erase() instead of resize() because resize() uses default constructor
+	 * when it increases config_'s size, which we wish to avoid.
+	 */
 	if (config_.size() > 2) {
-		config_.resize(2);
+		config_.erase(config_.begin() + 2, config_.end());
 		status = Adjusted;
 	}
 
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 2f909ce..04b0ed3 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -447,9 +447,13 @@  CameraConfiguration::Status RkISP1CameraConfiguration::validate()
 	if (config_.empty())
 		return Invalid;
 
-	/* Cap the number of entries to the available streams. */
+	/*
+	 * Cap the number of entries to the available streams.
+	 * Use erase() instead of resize() because resize() uses default constructor
+	 * when it increases config_'s size, which we wish to avoid.
+	 */
 	if (config_.size() > 1) {
-		config_.resize(1);
+		config_.erase(config_.begin() + 1, config_.end());
 		status = Adjusted;
 	}
 
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index ffbddf2..462eae2 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -97,9 +97,13 @@  CameraConfiguration::Status UVCCameraConfiguration::validate()
 	if (config_.empty())
 		return Invalid;
 
-	/* Cap the number of entries to the available streams. */
+	/*
+	 * Cap the number of entries to the available streams.
+	 * Use erase() instead of resize() because resize() uses default constructor
+	 * when it increases config_'s size, which we wish to avoid.
+	 */
 	if (config_.size() > 1) {
-		config_.resize(1);
+		config_.erase(config_.begin() + 1, config_.end());
 		status = Adjusted;
 	}
 
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index b04a972..4c991ff 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -123,9 +123,13 @@  CameraConfiguration::Status VimcCameraConfiguration::validate()
 	if (config_.empty())
 		return Invalid;
 
-	/* Cap the number of entries to the available streams. */
+	/*
+	 * Cap the number of entries to the available streams.
+	 * Use erase() instead of resize() because resize() uses default constructor
+	 * when it increases config_'s size, which we wish to avoid.
+	 */
 	if (config_.size() > 1) {
-		config_.resize(1);
+		config_.erase(config_.begin() + 1, config_.end());
 		status = Adjusted;
 	}