From f6f5bd28dc8743f0eaf776b567cef87df55c906e Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Mon, 3 Nov 2025 21:30:12 +0000 Subject: [PATCH] gstreamer: Associate libcamera::Stream with GstPad 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 Reviewed-by: Nicolas Dufresne Signed-off-by: Kieran Bingham --- 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); + return static_cast(gst_pad_get_element_private(pad)); +} - if (self->pool) - return gst_libcamera_pool_get_stream(self->pool); - - 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); } }