[v4,1/3] gstreamer: Associate libcamera::Stream with GstPad
diff mbox series

Message ID 20251103213014.62713-2-uajain@igalia.com
State Accepted
Headers show
Series
  • gstreamer: Assorted fixes
Related show

Commit Message

Umang Jain Nov. 3, 2025, 9:30 p.m. UTC
Instead of trying to figure out which libcamera::Stream, the GstPad
is configured with (from the libcamera pool), associate the Stream
with the GstPad directly. The association can be set using
gst_pad_set_element_private().

Add the gst_libcamera_pad_set_stream() helper to associate the stream
with the pad. Additionally, modify the gst_libcamera_pad_get_stream()
to use to the getter helper gst_pad_get_element_private().

Signed-off-by: Umang Jain <uajain@igalia.com>
---
 src/gstreamer/gstlibcamerapad.cpp | 11 ++++++-----
 src/gstreamer/gstlibcamerapad.h   |  2 ++
 src/gstreamer/gstlibcamerasrc.cpp |  6 +++++-
 3 files changed, 13 insertions(+), 6 deletions(-)

Comments

Nicolas Dufresne Nov. 4, 2025, 1:40 p.m. UTC | #1
Le lundi 03 novembre 2025 à 21:30 +0000, Umang Jain a écrit :
> Instead of trying to figure out which libcamera::Stream, the GstPad
> is configured with (from the libcamera pool), associate the Stream
> with the GstPad directly. The association can be set using
> gst_pad_set_element_private().
> 
> Add the gst_libcamera_pad_set_stream() helper to associate the stream
> with the pad. Additionally, modify the gst_libcamera_pad_get_stream()
> to use to the getter helper gst_pad_get_element_private().
> 
> Signed-off-by: Umang Jain <uajain@igalia.com>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

> ---
>  src/gstreamer/gstlibcamerapad.cpp | 11 ++++++-----
>  src/gstreamer/gstlibcamerapad.h   |  2 ++
>  src/gstreamer/gstlibcamerasrc.cpp |  6 +++++-
>  3 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/src/gstreamer/gstlibcamerapad.cpp
> b/src/gstreamer/gstlibcamerapad.cpp
> index 22b96719..b37c4b34 100644
> --- a/src/gstreamer/gstlibcamerapad.cpp
> +++ b/src/gstreamer/gstlibcamerapad.cpp
> @@ -192,12 +192,13 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const
> GstVideoInfo *info)
>  Stream *
>  gst_libcamera_pad_get_stream(GstPad *pad)
>  {
> -	auto *self = GST_LIBCAMERA_PAD(pad);
> -
> -	if (self->pool)
> -		return gst_libcamera_pool_get_stream(self->pool);
> +	return static_cast<Stream *>(gst_pad_get_element_private(pad));
> +}
>  
> -	return nullptr;
> +void
> +gst_libcamera_pad_set_stream(GstPad *pad, Stream *stream)
> +{
> +	gst_pad_set_element_private(pad, stream);
>  }
>  
>  void
> diff --git a/src/gstreamer/gstlibcamerapad.h b/src/gstreamer/gstlibcamerapad.h
> index f98b8a7f..bbd7c687 100644
> --- a/src/gstreamer/gstlibcamerapad.h
> +++ b/src/gstreamer/gstlibcamerapad.h
> @@ -33,4 +33,6 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const
> GstVideoInfo *info);
>  
>  libcamera::Stream *gst_libcamera_pad_get_stream(GstPad *pad);
>  
> +void gst_libcamera_pad_set_stream(GstPad *pad, libcamera::Stream *stream);
> +
>  void gst_libcamera_pad_set_latency(GstPad *pad, GstClockTime latency);
> diff --git a/src/gstreamer/gstlibcamerasrc.cpp
> b/src/gstreamer/gstlibcamerasrc.cpp
> index 011a12fc..bd79b769 100644
> --- a/src/gstreamer/gstlibcamerasrc.cpp
> +++ b/src/gstreamer/gstlibcamerasrc.cpp
> @@ -357,7 +357,7 @@ int GstLibcameraSrcState::processRequest()
>  		GstBuffer *buffer = wrap->detachBuffer(stream);
>  
>  		FrameBuffer *fb =
> gst_libcamera_buffer_get_frame_buffer(buffer);
> -		const StreamConfiguration &stream_cfg = config_->at(i);
> +		const StreamConfiguration &stream_cfg = stream-
> >configuration();
>  		GstBufferPool *video_pool =
> gst_libcamera_pad_get_video_pool(srcpad);
>  
>  		if (video_pool) {
> @@ -692,6 +692,9 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
>  		gst_libcamera_pad_set_pool(srcpad, pool);
>  		gst_libcamera_pad_set_video_pool(srcpad, video_pool);
>  
> +		/* Associate the configured stream with the source pad. */
> +		gst_libcamera_pad_set_stream(srcpad, stream_cfg.stream());
> +
>  		/* Clear all reconfigure flags. */
>  		gst_pad_check_reconfigure(srcpad);
>  	}
> @@ -888,6 +891,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask
> *task,
>  		for (GstPad *srcpad : state->srcpads_) {
>  			gst_libcamera_pad_set_latency(srcpad,
> GST_CLOCK_TIME_NONE);
>  			gst_libcamera_pad_set_pool(srcpad, nullptr);
> +			gst_libcamera_pad_set_stream(srcpad, nullptr);
>  		}
>  	}
>

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcamerapad.cpp b/src/gstreamer/gstlibcamerapad.cpp
index 22b96719..b37c4b34 100644
--- a/src/gstreamer/gstlibcamerapad.cpp
+++ b/src/gstreamer/gstlibcamerapad.cpp
@@ -192,12 +192,13 @@  void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info)
 Stream *
 gst_libcamera_pad_get_stream(GstPad *pad)
 {
-	auto *self = GST_LIBCAMERA_PAD(pad);
-
-	if (self->pool)
-		return gst_libcamera_pool_get_stream(self->pool);
+	return static_cast<Stream *>(gst_pad_get_element_private(pad));
+}
 
-	return nullptr;
+void
+gst_libcamera_pad_set_stream(GstPad *pad, Stream *stream)
+{
+	gst_pad_set_element_private(pad, stream);
 }
 
 void
diff --git a/src/gstreamer/gstlibcamerapad.h b/src/gstreamer/gstlibcamerapad.h
index f98b8a7f..bbd7c687 100644
--- a/src/gstreamer/gstlibcamerapad.h
+++ b/src/gstreamer/gstlibcamerapad.h
@@ -33,4 +33,6 @@  void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info);
 
 libcamera::Stream *gst_libcamera_pad_get_stream(GstPad *pad);
 
+void gst_libcamera_pad_set_stream(GstPad *pad, libcamera::Stream *stream);
+
 void gst_libcamera_pad_set_latency(GstPad *pad, GstClockTime latency);
diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
index 011a12fc..bd79b769 100644
--- a/src/gstreamer/gstlibcamerasrc.cpp
+++ b/src/gstreamer/gstlibcamerasrc.cpp
@@ -357,7 +357,7 @@  int GstLibcameraSrcState::processRequest()
 		GstBuffer *buffer = wrap->detachBuffer(stream);
 
 		FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);
-		const StreamConfiguration &stream_cfg = config_->at(i);
+		const StreamConfiguration &stream_cfg = stream->configuration();
 		GstBufferPool *video_pool = gst_libcamera_pad_get_video_pool(srcpad);
 
 		if (video_pool) {
@@ -692,6 +692,9 @@  gst_libcamera_src_negotiate(GstLibcameraSrc *self)
 		gst_libcamera_pad_set_pool(srcpad, pool);
 		gst_libcamera_pad_set_video_pool(srcpad, video_pool);
 
+		/* Associate the configured stream with the source pad. */
+		gst_libcamera_pad_set_stream(srcpad, stream_cfg.stream());
+
 		/* Clear all reconfigure flags. */
 		gst_pad_check_reconfigure(srcpad);
 	}
@@ -888,6 +891,7 @@  gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,
 		for (GstPad *srcpad : state->srcpads_) {
 			gst_libcamera_pad_set_latency(srcpad, GST_CLOCK_TIME_NONE);
 			gst_libcamera_pad_set_pool(srcpad, nullptr);
+			gst_libcamera_pad_set_stream(srcpad, nullptr);
 		}
 	}