@@ -48,11 +48,11 @@ struct RequestWrap {
4848 RequestWrap (std::unique_ptr<Request> request);
4949 ~RequestWrap ();
5050
51- void attachBuffer (Stream *stream , GstBuffer *buffer);
52- GstBuffer *detachBuffer (Stream *stream );
51+ void attachBuffer (GstPad *srcpad , GstBuffer *buffer);
52+ GstBuffer *detachBuffer (GstPad *srcpad );
5353
5454 std::unique_ptr<Request> request_;
55- std::map<Stream *, GstBuffer *> buffers_;
55+ std::map<GstPad *, GstBuffer *> buffers_;
5656
5757 GstClockTime latency_;
5858 GstClockTime pts_;
@@ -65,32 +65,33 @@ RequestWrap::RequestWrap(std::unique_ptr<Request> request)
6565
6666RequestWrap::~RequestWrap ()
6767{
68- for (std::pair<Stream *const , GstBuffer *> &item : buffers_) {
68+ for (std::pair<GstPad *const , GstBuffer *> &item : buffers_) {
6969 if (item.second )
7070 gst_buffer_unref (item.second );
7171 }
7272}
7373
74- void RequestWrap::attachBuffer (Stream *stream , GstBuffer *buffer)
74+ void RequestWrap::attachBuffer (GstPad *srcpad , GstBuffer *buffer)
7575{
7676 FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer (buffer);
77+ Stream *stream = gst_libcamera_pad_get_stream (srcpad);
7778
7879 request_->addBuffer (stream, fb);
7980
80- auto item = buffers_.find (stream );
81+ auto item = buffers_.find (srcpad );
8182 if (item != buffers_.end ()) {
8283 gst_buffer_unref (item->second );
8384 item->second = buffer;
8485 } else {
85- buffers_[stream ] = buffer;
86+ buffers_[srcpad ] = buffer;
8687 }
8788}
8889
89- GstBuffer *RequestWrap::detachBuffer (Stream *stream )
90+ GstBuffer *RequestWrap::detachBuffer (GstPad *srcpad )
9091{
9192 GstBuffer *buffer = nullptr ;
9293
93- auto item = buffers_.find (stream );
94+ auto item = buffers_.find (srcpad );
9495 if (item != buffers_.end ()) {
9596 buffer = item->second ;
9697 item->second = nullptr ;
@@ -189,7 +190,6 @@ int GstLibcameraSrcState::queueRequest()
189190 std::make_unique<RequestWrap>(std::move (request));
190191
191192 for (GstPad *srcpad : srcpads_) {
192- Stream *stream = gst_libcamera_pad_get_stream (srcpad);
193193 GstLibcameraPool *pool = gst_libcamera_pad_get_pool (srcpad);
194194 GstBuffer *buffer;
195195 GstFlowReturn ret;
@@ -204,7 +204,7 @@ int GstLibcameraSrcState::queueRequest()
204204 return -ENOBUFS;
205205 }
206206
207- wrap->attachBuffer (stream , buffer);
207+ wrap->attachBuffer (srcpad , buffer);
208208 }
209209
210210 GST_TRACE_OBJECT (src_, " Requesting buffers" );
@@ -354,10 +354,10 @@ int GstLibcameraSrcState::processRequest()
354354 for (gsize i = 0 ; i < srcpads_.size (); i++) {
355355 GstPad *srcpad = srcpads_[i];
356356 Stream *stream = gst_libcamera_pad_get_stream (srcpad);
357- GstBuffer *buffer = wrap->detachBuffer (stream );
357+ GstBuffer *buffer = wrap->detachBuffer (srcpad );
358358
359359 FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer (buffer);
360- const StreamConfiguration &stream_cfg = config_-> at (i );
360+ const StreamConfiguration &stream_cfg = stream-> configuration ( );
361361 GstBufferPool *video_pool = gst_libcamera_pad_get_video_pool (srcpad);
362362
363363 if (video_pool) {
@@ -574,12 +574,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,
574574 gst_buffer_pool_set_config (GST_BUFFER_POOL_CAST (pool), config);
575575 }
576576
577- if (!gst_buffer_pool_set_active (pool, true )) {
578- GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
579- (" Failed to active buffer pool" ),
580- (" gst_libcamera_src_negotiate() failed." ));
577+ if (!gst_buffer_pool_set_active (pool, true ))
581578 return { nullptr , -EINVAL };
582- }
583579
584580 return { std::exchange (pool, nullptr ), 0 };
585581}
@@ -680,8 +676,12 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
680676 std::tie (video_pool, ret) =
681677 gst_libcamera_create_video_pool (self, srcpad,
682678 caps, &info);
683- if (ret)
679+ if (ret) {
680+ GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
681+ (" Failed to create video pool: %s" , g_strerror (-ret)),
682+ (" gst_libcamera_src_negotiate() failed." ));
684683 return false ;
684+ }
685685 }
686686
687687 GstLibcameraPool *pool = gst_libcamera_pool_new (self->allocator ,
@@ -692,6 +692,9 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)
692692 gst_libcamera_pad_set_pool (srcpad, pool);
693693 gst_libcamera_pad_set_video_pool (srcpad, video_pool);
694694
695+ /* Associate the configured stream with the source pad. */
696+ gst_libcamera_pad_set_stream (srcpad, stream_cfg.stream ());
697+
695698 /* Clear all reconfigure flags. */
696699 gst_pad_check_reconfigure (srcpad);
697700 }
@@ -888,6 +891,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,
888891 for (GstPad *srcpad : state->srcpads_ ) {
889892 gst_libcamera_pad_set_latency (srcpad, GST_CLOCK_TIME_NONE);
890893 gst_libcamera_pad_set_pool (srcpad, nullptr );
894+ gst_libcamera_pad_set_stream (srcpad, nullptr );
891895 }
892896 }
893897
0 commit comments