summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Heinold <henning@itconsulting-heinold.de>2014-11-10 22:34:39 +0100
committerTim-Philipp Müller <tim@centricular.com>2014-11-17 00:23:13 +0000
commit8aa263006865584b5dcc05378d18ff052e6f188e (patch)
treec2261829f0e36d51e4f741c360b509bd91af3d0b
parent0b36fe59e1725ffa2905b3aac5f424b1299791c6 (diff)
examples: port python rtp PCMA client/server tests to 1.0
https://bugzilla.gnome.org/show_bug.cgi?id=739930
-rwxr-xr-xtests/examples/rtp/client-PCMA.py87
-rwxr-xr-xtests/examples/rtp/server-alsasrc-PCMA.py80
2 files changed, 90 insertions, 77 deletions
diff --git a/tests/examples/rtp/client-PCMA.py b/tests/examples/rtp/client-PCMA.py
index 5830b1081..9d2fd4291 100755
--- a/tests/examples/rtp/client-PCMA.py
+++ b/tests/examples/rtp/client-PCMA.py
@@ -1,12 +1,12 @@
-#! /usr/bin/env python
+#! /usr/bin/env python
-import pygst
-pygst.require("0.10")
-import gst
-import gobject
+import gi
+import sys
+gi.require_version('Gst', '1.0')
+from gi.repository import GObject, Gst
#
-# A simple RTP receiver
+# A simple RTP receiver
#
# receives alaw encoded RTP audio on port 5002, RTCP is received on port 5003.
# the receiver RTCP reports are sent to port 5007
@@ -15,14 +15,14 @@ import gobject
# RTP |udpsrc | | rtpbin | |pcmadepay| |alawdec| |alsasink|
# port=5002 | src->recv_rtp recv_rtp->sink src->sink src->sink |
# '-------' | | '---------' '-------' '--------'
-# | |
+# | |
# | | .-------.
# | | |udpsink| RTCP
# | send_rtcp->sink | port=5007
# .-------. | | '-------' sync=false
# RTCP |udpsrc | | | async=false
-# port=5003 | src->recv_rtcp |
-# '-------' '----------'
+# port=5003 | src->recv_rtcp |
+# '-------' '----------'
AUDIO_CAPS = 'application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)PCMA'
AUDIO_DEPAY = 'rtppcmadepay'
@@ -33,7 +33,10 @@ DEST = '127.0.0.1'
RTP_RECV_PORT = 5002
RTCP_RECV_PORT = 5003
-RTCP_SEND_PORT = 5007
+RTCP_SEND_PORT = 5007
+
+GObject.threads_init()
+Gst.init(sys.argv)
#gst-launch -v rtpbin name=rtpbin \
# udpsrc caps=$AUDIO_CAPS port=$RTP_RECV_PORT ! rtpbin.recv_rtp_sink_0 \
@@ -42,74 +45,76 @@ RTCP_SEND_PORT = 5007
# rtpbin.send_rtcp_src_0 ! udpsink port=$RTCP_SEND_PORT host=$DEST sync=false async=false
def pad_added_cb(rtpbin, new_pad, depay):
- sinkpad = gst.Element.get_static_pad(depay, 'sink')
- lres = gst.Pad.link(new_pad, sinkpad)
+ sinkpad = Gst.Element.get_static_pad(depay, 'sink')
+ lres = Gst.Pad.link(new_pad, sinkpad)
-# the pipeline to hold eveything
-pipeline = gst.Pipeline('rtp_client')
+# the pipeline to hold eveything
+pipeline = Gst.Pipeline('rtp_client')
# the udp src and source we will use for RTP and RTCP
-rtpsrc = gst.element_factory_make('udpsrc', 'rtpsrc')
+rtpsrc = Gst.ElementFactory.make('udpsrc', 'rtpsrc')
rtpsrc.set_property('port', RTP_RECV_PORT)
# we need to set caps on the udpsrc for the RTP data
-caps = gst.caps_from_string(AUDIO_CAPS)
+caps = Gst.caps_from_string(AUDIO_CAPS)
rtpsrc.set_property('caps', caps)
-rtcpsrc = gst.element_factory_make('udpsrc', 'rtcpsrc')
+rtcpsrc = Gst.ElementFactory.make('udpsrc', 'rtcpsrc')
rtcpsrc.set_property('port', RTCP_RECV_PORT)
-rtcpsink = gst.element_factory_make('udpsink', 'rtcpsink')
+rtcpsink = Gst.ElementFactory.make('udpsink', 'rtcpsink')
rtcpsink.set_property('port', RTCP_SEND_PORT)
rtcpsink.set_property('host', DEST)
# no need for synchronisation or preroll on the RTCP sink
rtcpsink.set_property('async', False)
-rtcpsink.set_property('sync', False)
+rtcpsink.set_property('sync', False)
pipeline.add(rtpsrc, rtcpsrc, rtcpsink)
# the depayloading and decoding
-audiodepay = gst.element_factory_make(AUDIO_DEPAY, 'audiodepay')
-audiodec = gst.element_factory_make(AUDIO_DEC, 'audiodec')
+audiodepay = Gst.ElementFactory.make(AUDIO_DEPAY, 'audiodepay')
+audiodec = Gst.ElementFactory.make(AUDIO_DEC, 'audiodec')
# the audio playback and format conversion
-audioconv = gst.element_factory_make('audioconvert', 'audioconv')
-audiores = gst.element_factory_make('audioresample', 'audiores')
-audiosink = gst.element_factory_make(AUDIO_SINK, 'audiosink')
+audioconv = Gst.ElementFactory.make('audioconvert', 'audioconv')
+audiores = Gst.ElementFactory.make('audioresample', 'audiores')
+audiosink = Gst.ElementFactory.make(AUDIO_SINK, 'audiosink')
# add depayloading and playback to the pipeline and link
pipeline.add(audiodepay, audiodec, audioconv, audiores, audiosink)
-res = gst.element_link_many(audiodepay, audiodec, audioconv, audiores, audiosink)
+audiodepay.link(audiodec)
+audiodec.link(audioconv)
+audioconv.link(audiores)
+audiores.link(audiosink)
# the rtpbin element
-rtpbin = gst.element_factory_make('rtpbin', 'rtpbin')
+rtpbin = Gst.ElementFactory.make('rtpbin', 'rtpbin')
pipeline.add(rtpbin)
# now link all to the rtpbin, start by getting an RTP sinkpad for session 0
-srcpad = gst.Element.get_static_pad(rtpsrc, 'src')
-sinkpad = gst.Element.get_request_pad(rtpbin, 'recv_rtp_sink_0')
-lres = gst.Pad.link(srcpad, sinkpad)
+srcpad = Gst.Element.get_static_pad(rtpsrc, 'src')
+sinkpad = Gst.Element.get_request_pad(rtpbin, 'recv_rtp_sink_0')
+lres = Gst.Pad.link(srcpad, sinkpad)
# get an RTCP sinkpad in session 0
-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)
+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)
# get an RTCP srcpad for sending RTCP back to the sender
-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)
-
-rtpbin.connect('pad-added', pad_added_cb, audiodepay)
+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)
-gst.Element.set_state(pipeline, gst.STATE_PLAYING)
+rtpbin.connect('pad-added', pad_added_cb, audiodepay)
-mainloop = gobject.MainLoop()
-mainloop.run()
+Gst.Element.set_state(pipeline, Gst.State.PLAYING)
-gst.Element.set_state(pipeline, gst.STATE_NULL)
+mainloop = GObject.MainLoop()
+mainloop.run()
+Gst.Element.set_state(pipeline, Gst.State.NULL)
diff --git a/tests/examples/rtp/server-alsasrc-PCMA.py b/tests/examples/rtp/server-alsasrc-PCMA.py
index 2caf0b985..37276a4a9 100755
--- a/tests/examples/rtp/server-alsasrc-PCMA.py
+++ b/tests/examples/rtp/server-alsasrc-PCMA.py
@@ -1,13 +1,15 @@
-#! /usr/bin/env python
+#! /usr/bin/env python
+
+import gi
+import sys
+gi.require_version('Gst', '1.0')
+from gi.repository import GObject, Gst
-import gobject, pygst
-pygst.require("0.10")
-import gst
#gst-launch -v rtpbin name=rtpbin audiotestsrc ! audioconvert ! alawenc ! rtppcmapay ! rtpbin.send_rtp_sink_0 \
# 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 \
-# udpsrc port=10002 ! rtpbin.recv_rtcp_sink_0
+# udpsrc port=10002 ! rtpbin.recv_rtcp_sink_0
DEST_HOST = '127.0.0.1'
@@ -17,74 +19,80 @@ AUDIO_PAY = 'rtppcmapay'
RTP_SEND_PORT = 5002
RTCP_SEND_PORT = 5003
-RTCP_RECV_PORT = 5007
+RTCP_RECV_PORT = 5007
+
+GObject.threads_init()
+Gst.init(sys.argv)
# the pipeline to hold everything
-pipeline = gst.Pipeline('rtp_server')
+pipeline = Gst.Pipeline('rtp_server')
# the pipeline to hold everything
-audiosrc = gst.element_factory_make(AUDIO_SRC, 'audiosrc')
-audioconv = gst.element_factory_make('audioconvert', 'audioconv')
-audiores = gst.element_factory_make('audioresample', 'audiores')
+audiosrc = Gst.ElementFactory.make(AUDIO_SRC, 'audiosrc')
+audioconv = Gst.ElementFactory.make('audioconvert', 'audioconv')
+audiores = Gst.ElementFactory.make('audioresample', 'audiores')
# the pipeline to hold everything
-audioenc = gst.element_factory_make(AUDIO_ENC, 'audioenc')
-audiopay = gst.element_factory_make(AUDIO_PAY, 'audiopay')
+audioenc = Gst.ElementFactory.make(AUDIO_ENC, 'audioenc')
+audiopay = Gst.ElementFactory.make(AUDIO_PAY, 'audiopay')
# add capture and payloading to the pipeline and link
pipeline.add(audiosrc, audioconv, audiores, audioenc, audiopay)
-res = gst.element_link_many(audiosrc, audioconv, audiores, audioenc, audiopay)
+audiosrc.link(audioconv)
+audioconv.link(audiores)
+audiores.link(audioenc)
+audioenc.link(audiopay)
# the rtpbin element
-rtpbin = gst.element_factory_make('rtpbin', 'rtpbin')
+rtpbin = Gst.ElementFactory.make('rtpbin', 'rtpbin')
-pipeline.add(rtpbin)
+pipeline.add(rtpbin)
# the udp sinks and source we will use for RTP and RTCP
-rtpsink = gst.element_factory_make('udpsink', 'rtpsink')
+rtpsink = Gst.ElementFactory.make('udpsink', 'rtpsink')
rtpsink.set_property('port', RTP_SEND_PORT)
rtpsink.set_property('host', DEST_HOST)
-rtcpsink = gst.element_factory_make('udpsink', 'rtcpsink')
+rtcpsink = Gst.ElementFactory.make('udpsink', 'rtcpsink')
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)
-rtcpsink.set_property('sync', False)
+rtcpsink.set_property('sync', False)
-rtcpsrc = gst.element_factory_make('udpsrc', 'rtcpsrc')
+rtcpsrc = Gst.ElementFactory.make('udpsrc', 'rtcpsrc')
rtcpsrc.set_property('port', RTCP_RECV_PORT)
-pipeline.add(rtpsink, rtcpsink, rtcpsrc)
+pipeline.add(rtpsink, rtcpsink, rtcpsrc)
# now link all to the rtpbin, start by getting an RTP sinkpad for session 0
-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)
+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)
# get the RTP srcpad that was created when we requested the sinkpad above and
# link it to the rtpsink sinkpad
-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)
+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)
# get an RTCP srcpad for sending RTCP to the receiver
-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)
+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)
# we also want to receive RTCP, request an RTCP sinkpad for session 0 and
# link it to the srcpad of the udpsrc for RTCP
-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)
+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)
# set the pipeline to playing
-gst.Element.set_state(pipeline, gst.STATE_PLAYING)
+Gst.Element.set_state(pipeline, Gst.State.PLAYING)
# we need to run a GLib main loop to get the messages
-mainloop = gobject.MainLoop()
-mainloop.run()
+mainloop = GObject.MainLoop()
+mainloop.run()
-gst.Element.set_state(pipeline, gst.STATE_NULL)
+Gst.Element.set_state(pipeline, Gst.State.NULL)