[libcamera-devel,v3,5/5] gstreamer: Reset the colorSpace if not the same after validation.
diff mbox series

Message ID 20220711153711.36679-6-rishikeshdonadkar@gmail.com
State Superseded
Headers show
Series
  • Add colorimetry support to libcamera gstreamer element.
Related show

Commit Message

Rishikesh Donadkar July 11, 2022, 3:37 p.m. UTC
If the colorSpace set in the previous patch is not same after validation,
Reset the colorSpace to the previous value that was present before applying the
requested colorspace.

Signed-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>
---
 src/gstreamer/gstlibcamerasrc.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
index a7a0c440..6cb631df 100644
--- a/src/gstreamer/gstlibcamerasrc.cpp
+++ b/src/gstreamer/gstlibcamerasrc.cpp
@@ -461,6 +461,8 @@  gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,
 	GstLibcameraSrcState *state = self->state;
 	GstFlowReturn flow_ret = GST_FLOW_OK;
 	gint ret;
+	std::vector<std::optional<ColorSpace>> prevColorSpaces;
+	std::vector<std::optional<ColorSpace>> appliedColorSpaces;
 
 	GST_DEBUG_OBJECT(self, "Streaming thread has started");
 
@@ -501,9 +503,13 @@  gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,
 			break;
 		}
 
+		/*Store the colorSpaces applied pew pad. */
+		prevColorSpaces.push_back(stream_cfg.colorSpace);
+
 		/* Fixate caps and configure the stream. */
 		caps = gst_caps_make_writable(caps);
 		gst_libcamera_configure_stream_from_caps(stream_cfg, caps);
+		appliedColorSpaces.push_back(stream_cfg.colorSpace);
 	}
 
 	if (flow_ret != GST_FLOW_OK)
@@ -515,6 +521,12 @@  gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,
 		goto done;
 	}
 
+	for (gsize i = 0; i < state->srcpads_.size(); i++) {
+		StreamConfiguration &stream_cfg = state->config_->at(i);
+
+		if (stream_cfg.colorSpace != appliedColorSpaces[i])
+			stream_cfg.colorSpace = prevColorSpaces[i];
+	}
 	/*
 	 * Regardless if it has been modified, create clean caps and push the
 	 * caps event. Downstream will decide if the caps are acceptable.