Dynamically add and remove elements in bin
I have a question regarding adding and removing elements from a bin element. I'm trying to implement a bin, which contains multiple webrtcbins, which sens a camera stream to multiple peers. My current idea is that the bin initially contains the following pipeline:
tee ! queue ! fakesink
When a peer requests to watch the camera stream I dynamically want to add the a new branch to the tee, as so:
tee ! queue ! webrtcbin
I use the following code to link and sync the element (viewer_id is a unique id representing the viewer and tee is a reference to the tee inside my own bin):
let bin_id = format!("webrtcbin_{}", viewer_id);
let webrtc = gst::ElementFactory::make("webrtcbin", &*bin_id).unwrap();
let queue_name = format!("queue_{}", viewer_id);
let webrtc_queue = gst::ElementFactory::make("queue", &*queue_name).unwrap();
bin.add_many(&[&webrtc, &webrtc_queue])?;
//This function sets up on-negotiation-needed and the other webrtcbin signals
setup_callbacks(&webrtc, app_control, &viewer)?;
gst::Element::link_many(&[tee, &webrtc_queue, &webrtc])?;
webrtc.sync_state_with_parent()?;
webrtc_queue.sync_state_with_parent()?;
My problem is that the newly added elements will not automatically have their CAPS negotiated (at least so it seems). Is there anything I should be aware of when dynamically adding elements to a bin? Or do I need to manually negotiate the CAPS of the elements I add inside the bin?