* added a SAP server, with some kludges because the SAP client in vlc
authorCyril Deguet <asmax@videolan.org>
Mon, 17 Feb 2003 22:03:42 +0000 (22:03 +0000)
committerCyril Deguet <asmax@videolan.org>
Mon, 17 Feb 2003 22:03:42 +0000 (22:03 +0000)
  is not RFC-compliant...

python/vlrs/announce.py [new file with mode: 0644]
python/vlrs/rtsp.py
python/vlrs/sap.py [new file with mode: 0644]
python/vlrs/session.py
python/vlrs/vlrs.py

diff --git a/python/vlrs/announce.py b/python/vlrs/announce.py
new file mode 100644 (file)
index 0000000..4608ce3
--- /dev/null
@@ -0,0 +1,27 @@
+#!/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
index b44ac37..1b353bb 100755 (executable)
 
 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):
diff --git a/python/vlrs/sap.py b/python/vlrs/sap.py
new file mode 100644 (file)
index 0000000..421822a
--- /dev/null
@@ -0,0 +1,71 @@
+#!/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)
index eadd10f..65ce26f 100755 (executable)
@@ -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):
index 7c8ab7c..7f8df9d 100755 (executable)
@@ -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: