Configure webrtcsrc in python script

Hi,

I’m trying to do the equivalent of this pipe in python

gst-launch-1.0 webrtcsrc signaller::producer-peer-id=<webrtcsink-peer-id> ...

But I don’t know how to configure signaller. It seems that I need to pass a valid signaller when I make the webrtcsrc component, otherwise I’ve got an error.

    def add_webrtcsrc(self, peer_id: str):        
        webrtcsrc = Gst.ElementFactory.make("webrtcsrc")

        signaller = webrtcsrc.get_property("signaller")
        signaller.set_property("producer-peer-id", peer_id)
        
        webrtcsrc.set_property("signaller", signaller)

        self._pipeline.add(webrtcsrc):
        return webrtcsrc

webrtcsrc.set_property(“signaller”, signaller)
TypeError: property ‘signaller’ can only be set in constructor

Any idea how to do that? Thanks

You can remove the line webrtcsrc.set_property("signaller", signaller). The getter retrieves a reference to the signaller, so you don’t need to set it back.

However, you will need to connect a ‘pad-added’ handler for webrtcsrc to add the sink element and link it to the newly added (“sometimes”) pad.

Ok. I was doing that at first but I was not sure it did something. Because later on, this is not working (the error is logged). It fails whatever I connect to webrtcsrc.

if not Gst.Element.link(webrtcsrc, webrtcechoprobe):
      self._logger.error("Failed to link webrtcsrc -> webrtcechoprobe")

So is it related to your second comment?

I don’t understand what to do^^

The pads for webrtcsrc are “sometimes” pads because their availability depends on the incoming stream content. For instance, webrtcsrc will create an “audio” pad if an audio stream is present, etc. But this is not statically known, so you need to connect a handler to the “pad-added” signal which will be called back when a pad is added and where you can add and link the elements that will handle this particular stream.

A simple example for this would be:

def webrtcsrc_pad_added_cb(webrtcsrc, pad, udata):
    pipeline = udata
    
    if pad.get_name().startswith('audio'):
        audiosink = Gst.ElementFactory.make("autoaudiosink")
        pipeline.add(audiosink)
        pad.link(audiosink.get_static_pad('sink'))
        audiosink.sync_state_with_parent()

def add_webrtcsrc(self, peer_id: str):        
    webrtcsrc = Gst.ElementFactory.make("webrtcsrc")

    signaller = webrtcsrc.get_property("signaller")
    signaller.set_property("producer-peer-id", peer_id)

    webrtcsrc.connect('pad-added', webrtcsrc_pad_added_cb, self._pipeline)

    self._pipeline.add(webrtcsrc):
    return webrtcsrc

Thanks.
The call back is never called unfortunately. Is webrtcsrc connecting to the peer when I start the pipeline, or is there something to do?

Yes, you need to start the pipeline for webrtcsrc to change state and start a session with the producer.

Edit: or did you mean you were already doing this?

Yes I started the pipeline. But I forgot to add the webrtcsrc element to it :sweat_smile:
Anyway, it is working. Thank you so much!