Dynamic Relay - Code

  • Main CGI script
The following script (r.mp4.m) starts relying mechanism. It first checks whether the relay is already established and if it is so, the script simply exits.

If the relay is not established, the script starts relay to to the DSS2 host (using rtptrans or equivalently combination of rtpdump and rtpplay). Finally, before exit, the script spawns control script (r.ch.2) and parses PID of rtp-transport programs.

#!/bin/bash

multip=226.91.0.22 # multicast IP on the local host multport=38028 # multicast port on the local host multporta=38030 # multicast port on the local host host=194.109.218.117 # IP number of the remote DSS port=48028 # UDP port on the remote DSS porta=58030 # UDP port on the remote DSS sdp=l-rel-mp4 # sdp file on the host

locsdp=rtsp://204.181.65.11:7071/a-v-m loccip=204.181.65

#### no need to change anything beyond this point

pids="" # PID of the video rtp-transport pidsa="" # PID of the audio rtp-transport

rtpd="/var/www/cgi-bin/rtpdump" rtpp="/var/www/cgi-bin/rtpplay"

if [ $loccip == $( echo $REMOTE_ADDR | cut -f1,2,3 -d. ) ] then echo Content-type: application/x-quicktime-media-link echo echo \<\?xml version=\"1.0\"\?\> echo \<\?quicktime type=\"application/x-quicktime-media-link\"\?\> echo \<embed src=\"$locsdp\" autoplay=\"true\" \/\> exit 0 fi

if [ -f "/tmp/$host.rel" ] then if [ $(netstat -au | grep $host | grep -c ESTABLISHED) -gt 0 ] then echo Content-type: application/x-quicktime-media-link echo echo \<\?xml version=\"1.0\"\?\> echo \<\?quicktime type=\"application/x-quicktime-media-link\"\?\> echo \<embed src=\"rtsp://$host/$sdp\" autoplay=\"true\" \/\> exit $NOPROCESS else zombpr1=$(ps auxw | grep rtpdump | grep $multport | awk '{ print($2) }') let "zombpr2 = $zombpr1 + 2" let "zombpr3 = $zombpr1 + 4" kill -9 $zombpr1 $zombpr2 $zombpr3 rm -fr /tmp/$host.rel fi fi $rtpd -F dump $multip/$multport | $rtpp $host/$port/127 &> /tmp/$host.rel & pids="$pids $!" let "pids = $pids -1" $rtpd -F dump $multip/$multporta | $rtpp $host/$porta/127 &> /dev/null & pidsa="$pidsa $!" let "pidsa = $pidsa -1" /var/www/cgi-bin/r.ch.2 $host $pids $pidsa < /dev/null > /dev/null 2>&1 &

echo Content-type: application/x-quicktime-media-link echo echo \<\?xml version=\"1.0\"\?\> echo \<\?quicktime type=\"application/x-quicktime-media-link\"\?\> echo \<embed src=\"rtsp://$host/$sdp\" autoplay=\"true\" \/\>

exit 0

Control mechanism is established through relay.ch script. It checks whiter any client at DSS2 server is requesting the stream, and if not after 50 unsuccessful relaying cycles, the script stops RTPTRANS.

#!/bin/sh
until [  $(grep -c refused /tmp/$1.rel) -gt 25 ]; do
sleep 1s
done

rm -f /tmp/$1.rel kill -9 $2 > /dev/null kill -9 $3 > /dev/null

  • SDP file at DSS2
SDP file on the second server DSS2 describes to relay, and is a standard SDP file:

v=0
o=- 1012366293653228 1012366293653230 IN IP4 194.109.218.117
s=Relay to Mont
e=NONE
t=0 0
a=sendonly
a=x-bufferdelay:4
c=IN IP4 194.109.218.117
b=RR:0
m=video 46946 RTP/AVP 31
a=cliprect:16,16,256,336

  • CODE
Scripts are available in the following tar file scripts.tar.
Open_Source_Streaming_Platform

Server_Side
_Darwin_Streaming_Server
_Icecast_Streaming_Server
_RTPTOOLS

Content_Production_Side
_Mbone_-_OpenMash_Tools
_Autostart_Script_VIC
_Live_Encoding_-_Mbone_Tools
_MPEG_4_IP
_MP3_Live_Streaming
_SMIL

Dynamic_Relaying_of_RTSP_Servers
_Dynamic_Relay_-_Flow
_Dynamic_Relay_-_Code
_Dynamic_Relay_&_MP3_alias

OSSA_Streaming_Protocol
_SDP_Exchange_&_Public_Keys
_Stream_Scanner

Logfile_Analyzer