<HTML><BODY>Hello, all.<br>I have a rtsp source and I need to restream it through my rtsp server. <br>The rtsp source can stream audio/video and sometimes only video.<br><br>I can create either audio/video pipeline or only video pipeline.<br>But I can't create working pipeline for these both cases.<br><br>I connect callback to 'pad-added' event and then I link the first video element and the first audio element (if audio exists) to rtspsrc element in 'pad-added' callback.<br>I create/add/link audio elements in 'pad-added' callback but the rtsp client has no audio in this case.<br><br>Please tell me what is wrong.<br><br><br>This pipeline works well with audio-video: <br><br>Gst.parse_launch(<br> '( rtspsrc location="rtsp://admin:admin@192.168.7.217" '<br> 'latency=0 '<br> 'timeout=5000000 '<br> 'name=rtsp_src '<br> 'rtsp_src. '<br> '! queue'<br> '! rtph264depay '<br> '! rtph264pay '<br> 'name=pay0 '<br> 'rtsp_src. '<br> '! queue'<br> '! rtppcmudepay '<br> '! rtppcmupay '<br> 'name=pay1 )'<br>)<br><br>OS: gentoo, gstreamer: version 1.6.3, gst-rtsp-server: 1.6.2, python3<br><br><br>Code:<br><br><br>#!/usr/bin/env python3<br><br>"""RTSP restreamer based on GStreamer."""<br><br>import gi<br>gi.require_version('Gst', '1.0')<br>gi.require_version('GstRtspServer', '1.0')<br>from gi.repository import Gst, GstRtspServer, GObject<br><br>loop = GObject.MainLoop()<br>GObject.threads_init()<br>Gst.init(None)<br><br><br>class AVPipeline(Gst.Pipeline):<br> <br> def __init__(self):<br> Gst.Pipeline.__init__(self)<br><br> # rtsp source<br> rtspsrc = Gst.ElementFactory.make('rtspsrc', None)<br> rtspsrc.set_property('location', 'rtsp://admin:admin@192.168.7.217')<br> rtspsrc.set_property('latency', 500)<br> rtspsrc.set_property('timeout', 2000000)<br><br> self.add(rtspsrc)<br> self.link(rtspsrc)<br> rtspsrc.connect('pad-added', self.on_pad_added)<br><br> # video<br> vqueue = Gst.ElementFactory.make('queue', None)<br> rtph264depay = Gst.ElementFactory.make('rtph264depay', None)<br> rtph264pay = Gst.ElementFactory.make('rtph264pay', None)<br> <br> rtph264pay.set_property('name', 'pay0')<br> rtph264pay.set_property('pt', 96)<br> <br> self.add(vqueue)<br> self.add(rtph264depay)<br> self.add(rtph264pay)<br><br> vqueue.link(rtph264depay)<br> rtph264depay.link(rtph264pay)<br> <br> self._tolink_video_elem = vqueue<br> <br> def on_pad_added(self, element, pad):<br> string = pad.query_caps(None).to_string()<br> if string.startswith('application/x-rtp'):<br> if 'media=(string)video' in string:<br> pad.link(self._tolink_video_elem.get_static_pad('sink'))<br> print('Video connected')<br><br> elif 'media=(string)audio' in string:<br> <br> # create audio<br> # Client doesn't get audio when I add audio elements in this point<br><br> #audio<br> aqueue = Gst.ElementFactory.make('queue', None)<br> rtppcmudepay = Gst.ElementFactory.make('rtppcmudepay', None)<br> rtppcmupay = Gst.ElementFactory.make('rtppcmupay', None)<br> <br> rtppcmupay.set_property('name', 'pay1')<br> <br> self.add(aqueue)<br> self.add(rtppcmudepay)<br> self.add(rtppcmupay)<br> <br> aqueue.link(rtppcmudepay)<br> rtppcmudepay.link(rtppcmupay)<br><br> for elem in (aqueue, rtppcmudepay, rtppcmupay):<br> elem.sync_state_with_parent()<br> <br> pad.link(aqueue.get_static_pad('sink'))<br> print('Audio connected')<br><br><br>class MyRTSPMediaFactory(GstRtspServer.RTSPMediaFactory):<br><br> LATENCY = 10000<br><br> def __init__(self):<br> GstRtspServer.RTSPMediaFactory.__init__(self)<br><br> self.set_shared(True)<br> self.set_property('latency', self.LATENCY) <br> self.set_transport_mode(GstRtspServer.RTSPTransportMode.PLAY)<br><br> def do_create_element(self, url):<br> return AVPipeline()<br><br><br>class Restreamer(object):<br><br> def __init__(self, host, port):<br> self._server = GstRtspServer.RTSPServer()<br> self._server.set_address(host)<br> self._server.set_service(str(port))<br><br> mount_points = self._server.get_mount_points()<br> factory = MyRTSPMediaFactory()<br> mount_points.add_factory('/test', factory)<br><br> self._server.attach(None)<br><br><br>def main():<br> server = Restreamer('0.0.0.0', 9999)<br> print('Started %s:%s' % (server._server.get_address(),<br> server._server.get_service()))<br> loop.run()<br><br><br>if __name__ == '__main__':<br> main()<br><br></BODY></HTML>