Commit 00568c5d authored by Cyril Deguet's avatar Cyril Deguet
Browse files

* added a SAP server, with some kludges because the SAP client in vlc

  is not RFC-compliant...
parent e95c82a6
#!/usr/bin/python -O
#
# VideoLAN RTSP Server
#
# Author: Cyril Deguet <asmax@via.ecp.fr>
import cfg
from sap import SapServer
from session import Session
class AnnounceList:
"List of streams to be announced"
def __init__(self):
# Create the SAP server
self.multicastList = {}
self.sapServer = SapServer()
self.sapServer.start()
def readPlaylist(self):
pass
def addMulticastSession(self, session):
"Add a multicast session in the announce list"
self.multicastList[session.id] = session
......@@ -10,37 +10,7 @@
import cfg, mimetools, re, socket, time, SocketServer, string, sys
def ntpTime():
"return the current time in NTP decimal format"
return "%d" % (int(time.time()) + 2208988800L)
class SdpMessage:
"Build a SDP message"
uri = "http://www.videolan.org"
def __init__(self, sessionName, address, uri):
"Build the message"
self.sessionName = sessionName
self.address = address
self.uri = uri
def getMessage(self):
"Return the SDP message"
msg = "v=0\r\n" + \
"o=asmax " + ntpTime() + " " + ntpTime() + \
" IN IP4 sphinx.via.ecp.fr\r\n" + \
"s=" + self.sessionName + "\r\n" + \
"u=" + self.uri + "\r\n" + \
"t=0 0\r\n" + \
"c=IN IP4 " + self.address + "/1\r\n" + \
"m=video 1234 RTP/MP2T 33\r\n" + \
"a=control:" + self.uri + "\r\n"
return msg
from sap import SdpMessage
class RtspServerHandler(SocketServer.StreamRequestHandler):
......
#!/usr/bin/python -O
#
# VideoLAN RTSP Server
#
# Author: Cyril Deguet <asmax@via.ecp.fr>
import cfg,socket,struct,time,threading
def ntpTime():
"return the current time in NTP decimal format"
return "%d" % (int(time.time()) + 2208988800L)
class SdpMessage:
"Build a SDP message"
uri = "http://www.videolan.org"
def __init__(self, sessionName, address, uri):
"Build the message"
self.sessionName = sessionName
self.address = address
self.uri = uri
def getMessage(self):
"Return the SDP message"
msg = "v=0\r\n" + \
"o=asmax " + ntpTime() + " " + ntpTime() + \
" IN IP4 sphinx.via.ecp.fr\r\n" + \
"s=" + self.sessionName + "\r\n" + \
"u=" + self.uri + "\r\n" + \
"t=0 0\r\n" + \
"c=IN IP4 " + self.address + "/1\r\n" + \
"m=video 1234 RTP/MP2T 33\r\n" + \
"a=control:" + self.uri + "\r\n"
return msg
class SapServer(threading.Thread):
"SAP server class"
PORT = 9875
GROUP = "224.2.127.254"
TTL = 1
def __init__(self):
# Open the socket
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, self.TTL)
self.sock.connect((self.GROUP, self.PORT))
def sendMessage(self, message):
"Message must be a SdpMessage"
# FIXME
header = " " + struct.pack("!BH", 12, 4212) + socket.inet_aton('138.195.156.214')
data = header + message.getMessage()
self.sock.send(data)
def announce(self):
for id, session in cfg.announceList.multicastList.items():
message = SdpMessage(session.name, session.dest, session.uri)
self.sendMessage(message)
def run(self):
while 1:
self.announce()
time.sleep(1)
......@@ -20,6 +20,7 @@ class Session:
self.state = 'ready'
media = cfg.playlist.getMedia(self.uri)
self.fileName = media['file']
self.name = media['name']
address = "rtp/ts://" + dest
self.streamer = VlcStreamer(self.fileName, address)
......@@ -35,6 +36,7 @@ class Session:
except VlcError:
print "Streamer: play failed"
return -1
cfg.announceList.addMulticastSession(self)
return 0
def pause(self):
......
......@@ -5,8 +5,9 @@
# Author: Cyril Deguet <asmax@via.ecp.fr>
import cfg, SocketServer, string, sys
import cfg, sap, SocketServer, string, sys, time
from announce import AnnounceList
from playlist import PlayList
from rtsp import RtspServerHandler
from session import SessionList
......@@ -21,6 +22,7 @@ if len(sys.argv) == 1:
cfg.playlist = PlayList()
cfg.playlist.readConfig(sys.argv[1])
cfg.sessionList = SessionList()
cfg.announceList = AnnounceList()
rtspServer = SocketServer.TCPServer(('', PORT), RtspServerHandler)
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment