-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrtspServer.py
executable file
·63 lines (53 loc) · 1.95 KB
/
rtspServer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
import sys, socket, signal, commands, re
from rtspServerWorker import rtspServerWorker
from netInterfaceStatus import getServerIP
# class rtspServer:
def clean():
# Make sure that rtspServer.log file is clean
fLog = open('logs/rtspServer.log', 'w')
# Make sure that all dvblast sockets are deleted before you start the rtsp state machine
cmd = 'rm -rf /tmp/dvblast*'
fLog.write('Info rtspServer: Cleaning dvblast sockets before starting\n')
outtext = commands.getoutput(cmd)
(exitstatus, outtext) = commands.getstatusoutput(cmd)
# if not exitstatus:
# fLog.write('Info rtspServer: Dvblast sockets clean\n')
# Make sure that all the pidCfgFiles are clean before you start the rtsp state machine
cmd = 'ls -l dvb-t/pid*'
fLog.write('Info rtspServer: Cleaning all pidCfgFiles\n')
outtext = commands.getoutput(cmd)
(exitstatus, outtext) = commands.getstatusoutput(cmd)
if not exitstatus:
linesArray = outtext.split('\n')
for line in linesArray:
matchPidCfgFile = re.search(r'pid([\w]+)', line)
if matchPidCfgFile:
f = open('dvb-t/pid' + matchPidCfgFile.group(1) + '.cfg', 'w')
f.close()
fLog.write('Info rtspServer: pidCfgFiles clean\n')
fLog.close()
# def main(self):
def rtspServer():
# Cleaning everything
clean()
# Make sure you have root privileges to run this script
# it is necesary that we can open the "554" port
serverPort = 554
rtspSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ipAddrServer = getServerIP()
rtspSocket.bind((ipAddrServer, serverPort))
while (1):
# Listen for incoming connections
rtspSocket.listen(1)
# Create the client profile and store necesary information
clientInfo = {}
clientInfo['rtspSocket'], addr = rtspSocket.accept()
clientInfo['addr_IP'] = addr[0]
clientInfo['addr_PORT'] = addr[1]
# Run the rtspServerWorker for that specific client
rtspServerWorker(clientInfo).run()
rtspSocket.close()
if __name__ == "__main__":
# (rtspServer()).main()
rtspServer()