Browse Source

Fix streaming process hang. Fix handling special characters in crosslink messages.

Maurizio Porrato 8 years ago
parent
commit
e31ca4926d
4 changed files with 58 additions and 20 deletions
  1. 46
    19
      stream.py
  2. 8
    0
      tools/dummystream.sh
  3. 3
    0
      tools/gsmstream.sh
  4. 1
    1
      twisted/plugins/frncrosslink.py

+ 46
- 19
stream.py View File

@@ -15,18 +15,56 @@ from Queue import Queue
15 15
 from twisted.internet.task import LoopingCall
16 16
 import fcntl
17 17
 
18
-STREAM_CMD="""tools/gsmdecode|ffmpeg -ar 8000 -ac 1 -f s16le -i /dev/stdin http://127.0.0.1:8090/feed.ffm"""
18
+from twisted.internet.protocol import ProcessProtocol
19 19
 
20
-silence_frame = open("sounds/silence-gsm.gsm", "rb").read()
20
+class StreamingProtocol(ProcessProtocol):
21 21
 
22
-class FRNStream(FRNClient):
22
+    _silenceFrame = open("sounds/silence-gsm.gsm", "rb").read()
23 23
 
24 24
     def __init__(self):
25 25
         self._frames = Queue()
26
-        self._stream = subprocess.Popen(STREAM_CMD, shell=True,
27
-            stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
28
-        self._streamtimer = LoopingCall.withCount(self.sendStreamFrame)
29
-        self._streamtimer.start(0.20)
26
+        self._streamTimer = LoopingCall.withCount(self.sendStreamFrame)
27
+
28
+    def connectionMade(self):
29
+        log.msg("Streaming process started")
30
+        self._streamTimer.start(0.20)
31
+
32
+    def inConnectionLost(self):
33
+        log.msg("connection lost")
34
+        self._streamTimer.stop()
35
+
36
+    def processExited(self, status):
37
+        log.msg("Streaming process exited (%s)" % str(status))
38
+
39
+    def sendStreamFrame(self, count):
40
+        for i in range(count):
41
+            if self._frames.empty():
42
+                frames = self._silenceFrame
43
+            else:
44
+                frames = self._frames.get_nowait()
45
+            self.transport.write(frames)
46
+
47
+    def feed(self, frame):
48
+        self._frames.put_nowait(frame)
49
+
50
+    def eof(self):
51
+        self.transport.closeStdin()
52
+
53
+
54
+STREAM_CMD="""tools/gsmstream.sh"""
55
+
56
+class FRNStream(FRNClient):
57
+
58
+    def __init__(self):
59
+        self._stream = StreamingProtocol()
60
+
61
+    def connectionMade(self):
62
+        FRNClient.connectionMade(self)
63
+        reactor.spawnProcess(self._stream, "bash", ["bash", "-c", STREAM_CMD], os.environ)
64
+
65
+    def connectionLost(self, reason):
66
+        FRNClient.connectionLost(self, reason)
67
+        self._stream.eof()
30 68
 
31 69
     def getClientName(self, client_id):
32 70
         if self.clientsById.has_key(client_id):
@@ -35,20 +73,9 @@ class FRNStream(FRNClient):
35 73
             return client_id
36 74
 
37 75
     def audioFrameReceived(self, from_id, frames):
38
-        self._frames.put_nowait(frames)
76
+        self._stream.feed(frames)
39 77
         self.pong()
40 78
 
41
-    def sendStreamFrame(self, count):
42
-        for i in range(count):
43
-            if self._frames.empty():
44
-                frames = silence_frame
45
-            else:
46
-                frames = self._frames.get_nowait()
47
-            self._stream.stdin.write(frames)
48
-            self._stream.stdin.flush()
49
-            self._stream.stdout.flush()
50
-            self._stream.stderr.flush()
51
-
52 79
     def loginResponse(self, info):
53 80
         log.msg("Login: %s" % info['al'])
54 81
 

+ 8
- 0
tools/dummystream.sh View File

@@ -0,0 +1,8 @@
1
+#!/bin/sh
2
+
3
+logfile=/tmp/stream.log
4
+echo -n "START " >> $logfile
5
+date >> $logfile
6
+cat > /tmp/stream.gsm
7
+echo -n "STOP " >> $logfile
8
+date >> $logfile

+ 3
- 0
tools/gsmstream.sh View File

@@ -0,0 +1,3 @@
1
+#!/bin/sh
2
+
3
+./tools/gsmdecode | ffmpeg -ar 8000 -ac 1 -f s16le -i /dev/stdin http://127.0.0.1:8090/feed.ffm

+ 1
- 1
twisted/plugins/frncrosslink.py View File

@@ -59,7 +59,7 @@ class FRNCrosslinkClient(FRNClient):
59 59
                             cl.append(" %s%s %s " % (
60 60
                                 cType.get(c['bc'], 'G'),
61 61
                                 ss,
62
-                                c['on'],
62
+                                c['on'].replace('<', '&lt;'),
63 63
                                 ))
64 64
                         sm = [cl[i*15:(i+1)*15]
65 65
                             for i in range((len(cl)+14)/15)]

Loading…
Cancel
Save