2014-11-10 21:34:39 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
import gi
|
|
|
|
import sys
|
|
|
|
gi.require_version('Gst', '1.0')
|
|
|
|
from gi.repository import GObject, Gst
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
|
2011-11-24 00:52:40 +00:00
|
|
|
#gst-launch -v rtpbin name=rtpbin audiotestsrc ! audioconvert ! alawenc ! rtppcmapay ! rtpbin.send_rtp_sink_0 \
|
2010-10-04 15:56:57 +00:00
|
|
|
# rtpbin.send_rtp_src_0 ! udpsink port=10000 host=xxx.xxx.xxx.xxx \
|
|
|
|
# rtpbin.send_rtcp_src_0 ! udpsink port=10001 host=xxx.xxx.xxx.xxx sync=false async=false \
|
2014-11-10 21:34:39 +00:00
|
|
|
# udpsrc port=10002 ! rtpbin.recv_rtcp_sink_0
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
DEST_HOST = '127.0.0.1'
|
|
|
|
|
|
|
|
AUDIO_SRC = 'audiotestsrc'
|
|
|
|
AUDIO_ENC = 'alawenc'
|
|
|
|
AUDIO_PAY = 'rtppcmapay'
|
|
|
|
|
|
|
|
RTP_SEND_PORT = 5002
|
|
|
|
RTCP_SEND_PORT = 5003
|
2014-11-10 21:34:39 +00:00
|
|
|
RTCP_RECV_PORT = 5007
|
|
|
|
|
|
|
|
GObject.threads_init()
|
|
|
|
Gst.init(sys.argv)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# the pipeline to hold everything
|
2014-11-10 21:34:39 +00:00
|
|
|
pipeline = Gst.Pipeline('rtp_server')
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# the pipeline to hold everything
|
2014-11-10 21:34:39 +00:00
|
|
|
audiosrc = Gst.ElementFactory.make(AUDIO_SRC, 'audiosrc')
|
|
|
|
audioconv = Gst.ElementFactory.make('audioconvert', 'audioconv')
|
|
|
|
audiores = Gst.ElementFactory.make('audioresample', 'audiores')
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# the pipeline to hold everything
|
2014-11-10 21:34:39 +00:00
|
|
|
audioenc = Gst.ElementFactory.make(AUDIO_ENC, 'audioenc')
|
|
|
|
audiopay = Gst.ElementFactory.make(AUDIO_PAY, 'audiopay')
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# add capture and payloading to the pipeline and link
|
|
|
|
pipeline.add(audiosrc, audioconv, audiores, audioenc, audiopay)
|
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
audiosrc.link(audioconv)
|
|
|
|
audioconv.link(audiores)
|
|
|
|
audiores.link(audioenc)
|
|
|
|
audioenc.link(audiopay)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# the rtpbin element
|
2014-11-10 21:34:39 +00:00
|
|
|
rtpbin = Gst.ElementFactory.make('rtpbin', 'rtpbin')
|
2010-10-04 15:56:57 +00:00
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
pipeline.add(rtpbin)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# the udp sinks and source we will use for RTP and RTCP
|
2014-11-10 21:34:39 +00:00
|
|
|
rtpsink = Gst.ElementFactory.make('udpsink', 'rtpsink')
|
2010-10-04 15:56:57 +00:00
|
|
|
rtpsink.set_property('port', RTP_SEND_PORT)
|
|
|
|
rtpsink.set_property('host', DEST_HOST)
|
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
rtcpsink = Gst.ElementFactory.make('udpsink', 'rtcpsink')
|
2010-10-04 15:56:57 +00:00
|
|
|
rtcpsink.set_property('port', RTCP_SEND_PORT)
|
|
|
|
rtcpsink.set_property('host', DEST_HOST)
|
|
|
|
# no need for synchronisation or preroll on the RTCP sink
|
|
|
|
rtcpsink.set_property('async', False)
|
2014-11-10 21:34:39 +00:00
|
|
|
rtcpsink.set_property('sync', False)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
rtcpsrc = Gst.ElementFactory.make('udpsrc', 'rtcpsrc')
|
2010-10-04 15:56:57 +00:00
|
|
|
rtcpsrc.set_property('port', RTCP_RECV_PORT)
|
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
pipeline.add(rtpsink, rtcpsink, rtcpsrc)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# now link all to the rtpbin, start by getting an RTP sinkpad for session 0
|
2014-11-10 21:34:39 +00:00
|
|
|
sinkpad = Gst.Element.get_request_pad(rtpbin, 'send_rtp_sink_0')
|
|
|
|
srcpad = Gst.Element.get_static_pad(audiopay, 'src')
|
|
|
|
lres = Gst.Pad.link(srcpad, sinkpad)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# get the RTP srcpad that was created when we requested the sinkpad above and
|
|
|
|
# link it to the rtpsink sinkpad
|
2014-11-10 21:34:39 +00:00
|
|
|
srcpad = Gst.Element.get_static_pad(rtpbin, 'send_rtp_src_0')
|
|
|
|
sinkpad = Gst.Element.get_static_pad(rtpsink, 'sink')
|
|
|
|
lres = Gst.Pad.link(srcpad, sinkpad)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# get an RTCP srcpad for sending RTCP to the receiver
|
2014-11-10 21:34:39 +00:00
|
|
|
srcpad = Gst.Element.get_request_pad(rtpbin, 'send_rtcp_src_0')
|
|
|
|
sinkpad = Gst.Element.get_static_pad(rtcpsink, 'sink')
|
|
|
|
lres = Gst.Pad.link(srcpad, sinkpad)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# we also want to receive RTCP, request an RTCP sinkpad for session 0 and
|
|
|
|
# link it to the srcpad of the udpsrc for RTCP
|
2014-11-10 21:34:39 +00:00
|
|
|
srcpad = Gst.Element.get_static_pad(rtcpsrc, 'src')
|
|
|
|
sinkpad = Gst.Element.get_request_pad(rtpbin, 'recv_rtcp_sink_0')
|
|
|
|
lres = Gst.Pad.link(srcpad, sinkpad)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# set the pipeline to playing
|
2014-11-10 21:34:39 +00:00
|
|
|
Gst.Element.set_state(pipeline, Gst.State.PLAYING)
|
2010-10-04 15:56:57 +00:00
|
|
|
|
|
|
|
# we need to run a GLib main loop to get the messages
|
2014-11-10 21:34:39 +00:00
|
|
|
mainloop = GObject.MainLoop()
|
|
|
|
mainloop.run()
|
2010-10-04 15:56:57 +00:00
|
|
|
|
2014-11-10 21:34:39 +00:00
|
|
|
Gst.Element.set_state(pipeline, Gst.State.NULL)
|