[vlma-devel] commit: dvblast: delegate the handling of announcements to the SAP server. (Adrien Grand )

git version control git at videolan.org
Mon Dec 28 00:19:18 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Mon Dec 28 00:12:20 2009 +0100| [16b52e65bee9cc52643a2bf0fe6fed4f0f243399] | committer: Adrien Grand 

dvblast: delegate the handling of announcements to the SAP server.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=16b52e65bee9cc52643a2bf0fe6fed4f0f243399
---

 vlma-watchdog/src/sap.py              |    7 +++++++
 vlma-watchdog/src/streamer/dvblast.py |   15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/vlma-watchdog/src/sap.py b/vlma-watchdog/src/sap.py
index fe0a1f0..e5f8399 100644
--- a/vlma-watchdog/src/sap.py
+++ b/vlma-watchdog/src/sap.py
@@ -50,11 +50,13 @@ class SAPServer(threading.Thread):
 
   def __init__(self, ip, delay=5):
     """Create a new SAP server"""
+    threading.Thread.__init__(self)
     self.ip = ip
     self.delay = delay
     self.__announces = {}
     self.__lock = threading.RLock()
     self.__logger = logging.getLogger("SAP server")
+    self.setDaemon(True)
 
   def add_dest(self, dest):
     version = int(math.floor(time.time() * 1000)) & 0xffff
@@ -68,6 +70,11 @@ class SAPServer(threading.Thread):
       del self.__announces[dest]
     self.__lock.release()
 
+  def remove_dests(self):
+    self.__lock.acquire()
+    self.__announces.clear()
+    self.__lock.release()
+
   def __send_announce(self, announce):
     is_ipv6 = self.ip.find(":") > 0
     ip = socket.inet_pton(is_ipv6 and socket.AF_INET6 or socket.AF_INET, self.ip)
diff --git a/vlma-watchdog/src/streamer/dvblast.py b/vlma-watchdog/src/streamer/dvblast.py
index aad8c81..b620bca 100644
--- a/vlma-watchdog/src/streamer/dvblast.py
+++ b/vlma-watchdog/src/streamer/dvblast.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import constants, os.path, tempfile
+import conf, constants, os.path, sap, tempfile
 from api import *
 
 class DVBlastOption(constants.Enum):
@@ -26,6 +26,8 @@ class DVBlast(Streamer):
     Streamer.__init__(self, sid, cmd, opts)
     self.type = "DVBLAST"
     self.filename = os.path.join(os.path.abspath(os.path.curdir), "dvblast-" + self.id + ".conf")
+    self.__sap_server = sap.SAPServer(conf.NETWORK_ADDRESS)
+    self.__sap_server.start()
 
   def can_stream(self, order):
     # DVBlast can stream if the order is a DVB one and if there is no
@@ -52,6 +54,15 @@ class DVBlast(Streamer):
     f.writelines(conf_file)
     f.close()
 
+  def _start_announcing(self, order):
+    for dests in order.programs.values():
+      for dest in dests:
+        if not dest.announcing is None and dest.announcing.type == "sap":
+          self.__sap_server.add_dest(dest)
+
+  def _stop_announcing(self, order):
+    self.__sap_server.remove_dests()
+
   def start_streaming(self, order):
     args = ["-e",
             "-f", str(order.frequency),
@@ -64,8 +75,10 @@ class DVBlast(Streamer):
                "-v", str(order.voltage),
                "-b", str(order.bandwidth)]
     self._write_conf_file(order)
+    self._start_announcing(order)
     self.start(args)
 
   def stop_streaming(self, order):
+    self._stop_announcing(order)
     self.stop()
 



More information about the vlma-devel mailing list