rtpmanager: rename gstrtp* -> rtp*
[platform/upstream/gstreamer.git] / tests / examples / rtp / server-alsasrc-PCMA.py
1 #! /usr/bin/env python 
2
3 import gobject, pygst
4 pygst.require("0.10")
5 import gst 
6
7 #gst-launch -v rtpbin name=rtpbin audiotestsrc ! audioconvert ! alawenc ! rtppcmapay ! rtpbin.send_rtp_sink_0 \
8 #                rtpbin.send_rtp_src_0 ! udpsink port=10000 host=xxx.xxx.xxx.xxx \
9 #                rtpbin.send_rtcp_src_0 ! udpsink port=10001 host=xxx.xxx.xxx.xxx sync=false async=false \
10 #                udpsrc port=10002 ! rtpbin.recv_rtcp_sink_0 
11
12 DEST_HOST = '127.0.0.1'
13
14 AUDIO_SRC = 'audiotestsrc'
15 AUDIO_ENC = 'alawenc'
16 AUDIO_PAY = 'rtppcmapay'
17
18 RTP_SEND_PORT = 5002
19 RTCP_SEND_PORT = 5003
20 RTCP_RECV_PORT = 5007 
21
22 # the pipeline to hold everything
23 pipeline = gst.Pipeline('rtp_server')
24
25 # the pipeline to hold everything
26 audiosrc = gst.element_factory_make(AUDIO_SRC, 'audiosrc')
27 audioconv = gst.element_factory_make('audioconvert', 'audioconv')
28 audiores = gst.element_factory_make('audioresample', 'audiores')
29
30 # the pipeline to hold everything
31 audioenc = gst.element_factory_make(AUDIO_ENC, 'audioenc')
32 audiopay = gst.element_factory_make(AUDIO_PAY, 'audiopay')
33
34 # add capture and payloading to the pipeline and link
35 pipeline.add(audiosrc, audioconv, audiores, audioenc, audiopay)
36
37 res = gst.element_link_many(audiosrc, audioconv, audiores, audioenc, audiopay)
38
39 # the rtpbin element
40 rtpbin = gst.element_factory_make('rtpbin', 'rtpbin')
41
42 pipeline.add(rtpbin) 
43
44 # the udp sinks and source we will use for RTP and RTCP
45 rtpsink = gst.element_factory_make('udpsink', 'rtpsink')
46 rtpsink.set_property('port', RTP_SEND_PORT)
47 rtpsink.set_property('host', DEST_HOST)
48
49 rtcpsink = gst.element_factory_make('udpsink', 'rtcpsink')
50 rtcpsink.set_property('port', RTCP_SEND_PORT)
51 rtcpsink.set_property('host', DEST_HOST)
52 # no need for synchronisation or preroll on the RTCP sink
53 rtcpsink.set_property('async', False)
54 rtcpsink.set_property('sync', False) 
55
56 rtcpsrc = gst.element_factory_make('udpsrc', 'rtcpsrc')
57 rtcpsrc.set_property('port', RTCP_RECV_PORT)
58
59 pipeline.add(rtpsink, rtcpsink, rtcpsrc) 
60
61 # now link all to the rtpbin, start by getting an RTP sinkpad for session 0
62 sinkpad = gst.Element.get_request_pad(rtpbin, 'send_rtp_sink_0')
63 srcpad = gst.Element.get_static_pad(audiopay, 'src')
64 lres = gst.Pad.link(srcpad, sinkpad)
65
66 # get the RTP srcpad that was created when we requested the sinkpad above and
67 # link it to the rtpsink sinkpad
68 srcpad = gst.Element.get_static_pad(rtpbin, 'send_rtp_src_0')
69 sinkpad = gst.Element.get_static_pad(rtpsink, 'sink')
70 lres = gst.Pad.link(srcpad, sinkpad)
71
72 # get an RTCP srcpad for sending RTCP to the receiver
73 srcpad = gst.Element.get_request_pad(rtpbin, 'send_rtcp_src_0')
74 sinkpad = gst.Element.get_static_pad(rtcpsink, 'sink')
75 lres = gst.Pad.link(srcpad, sinkpad)
76
77 # we also want to receive RTCP, request an RTCP sinkpad for session 0 and
78 # link it to the srcpad of the udpsrc for RTCP
79 srcpad = gst.Element.get_static_pad(rtcpsrc, 'src')
80 sinkpad = gst.Element.get_request_pad(rtpbin, 'recv_rtcp_sink_0')
81 lres = gst.Pad.link(srcpad, sinkpad)
82
83 # set the pipeline to playing
84 gst.Element.set_state(pipeline, gst.STATE_PLAYING)
85
86 # we need to run a GLib main loop to get the messages
87 mainloop = gobject.MainLoop()
88 mainloop.run() 
89
90 gst.Element.set_state(pipeline, gst.STATE_NULL)