Exemplo n.º 1
0
    def _create_webrtc_element_for_new_connection(self, ws):
        '''
        We make a new webrtc element, and queue to feed into it, for every new peer (client).
        That way, multiple clients can connect at once.
        '''

        self.peers[ws]['webrtcbin'] = Gst.ElementFactory.make('webrtcbin')
        self.pipeline.add(self.peers[ws]['webrtcbin'])
        self.peers[ws]['webrtcbin'].add_property_notify_watch(None, True)
        if config.stun_server():
            self.peers[ws]['webrtcbin'].set_property('stun-server', 'stun://' + config.stun_server())
        if config.turn_server():
            self.peers[ws]['webrtcbin'].set_property('turn-server', 'turn://' + config.turn_server())

        if config.enable_video():
            self.peers[ws]['video_queue'] = Gst.ElementFactory.make('queue')
            self.pipeline.add(self.peers[ws]['video_queue'])
            self.webrtc_video_tee.link(self.peers[ws]['video_queue'])
            self.peers[ws]['video_queue'].link(self.peers[ws]['webrtcbin'])

        if config.enable_audio():
            self.peers[ws]['audio_queue'] = Gst.ElementFactory.make('queue')
            self.pipeline.add(self.peers[ws]['audio_queue'])
            self.webrtc_audio_tee.link(self.peers[ws]['audio_queue'])
            self.peers[ws]['audio_queue'].link(self.peers[ws]['webrtcbin'])
Exemplo n.º 2
0
    def _create_webrtc_element_for_new_connection(self, ws):
        '''
        We make a new webrtc element, and queue to feed into it, for every new peer (client).
        That way, multiple clients can connect at once.
        '''

        self.peers[ws]['webrtcbin'] = Gst.ElementFactory.make('webrtcbin')
        self.pipeline.add(self.peers[ws]['webrtcbin'])
        self.peers[ws]['webrtcbin'].set_property('bundle-policy', 'max-bundle')
        self.peers[ws]['webrtcbin'].add_property_notify_watch(None, True)
        self.peers[ws]['webrtcbin'].set_state(Gst.State.READY)

        if config.stun_server():
            self.peers[ws]['webrtcbin'].set_property('stun-server', 'stun://' + config.stun_server())
        if config.turn_server():
            self.peers[ws]['webrtcbin'].set_property('turn-server', 'turn://' + config.turn_server())

        if config.enable_video():
            self.peers[ws]['video_queue'] = Gst.ElementFactory.make('queue')
            self.peers[ws]['video_queue'].set_property('leaky', 'upstream')
            self.pipeline.add(self.peers[ws]['video_queue'])
            self.webrtc_video_tee.link(self.peers[ws]['video_queue'])
            self.peers[ws]['video_queue'].link(self.peers[ws]['webrtcbin'])
            self.peers[ws]['video_queue'].set_state(Gst.State.READY)

        if config.enable_audio():
            self.peers[ws]['audio_queue'] = Gst.ElementFactory.make('queue')
            self.peers[ws]['audio_queue'].set_property('leaky', 'upstream')
            self.pipeline.add(self.peers[ws]['audio_queue'])
            self.webrtc_audio_tee.link(self.peers[ws]['audio_queue'])
            self.peers[ws]['audio_queue'].link(self.peers[ws]['webrtcbin'])
            self.peers[ws]['audio_queue'].set_state(Gst.State.READY)

        # We set the three elements above to READY first.
        # We now move them to PLAYING
        # This appears to prevent a race-condition that can
        # intermittently cause _on_negotiation_needed to not be called.
        self.peers[ws]['webrtcbin'].set_state(Gst.State.PLAYING)

        if config.enable_video():
            self.peers[ws]['video_queue'].set_state(Gst.State.PLAYING)

        if config.enable_audio():
            self.peers[ws]['audio_queue'].set_state(Gst.State.PLAYING)
Exemplo n.º 3
0
 def _ice_servers(self):
     servers = []
     if config.stun_server():
         servers.append({'urls': 'stun:' + config.stun_server()})
     # turn server not communicated to client, as the server (this element) knowing about it is sufficient.
     return servers