1.1 --- a/gmyth-stream/lib.py Fri Mar 30 23:12:52 2007 +0100
1.2 +++ b/gmyth-stream/lib.py Sat Mar 31 00:55:28 2007 +0100
1.3 @@ -4,4 +4,6 @@
1.4 return time.strftime("%Y-%m-%d %H:%M:%S");
1.5
1.6 def log(msg):
1.7 - print "[%s] %s" % (now(), msg)
1.8 + new_msg = "[%s] %s" % (now(), msg)
1.9 + print new_msg
1.10 + return new_msg
2.1 --- a/gmyth-stream/main.py Fri Mar 30 23:12:52 2007 +0100
2.2 +++ b/gmyth-stream/main.py Sat Mar 31 00:55:28 2007 +0100
2.3 @@ -34,15 +34,18 @@
2.4 if (msg == "SETUP"):
2.5 setup = server.getMsg(1024).strip().split(" ")
2.6 if ( len(setup) == 10 ):
2.7 - media.setup(setup[0], setup[1], setup[2], \
2.8 - setup[3], setup[4], setup[5],
2.9 - setup[6], setup[7], setup[8],
2.10 - setup[9])
2.11 + ret = media.setup(setup[0], setup[1], setup[2], \
2.12 + setup[3], setup[4], setup[5],
2.13 + setup[6], setup[7], setup[8],
2.14 + setup[9])
2.15
2.16 - server.Ack("SETUP")
2.17 + if (ret == 0):
2.18 + server.Ack("SETUP")
2.19 + else:
2.20 + server.sendMsg(lib.log("File does not exist: %s" % setup[0]))
2.21
2.22 else:
2.23 - lib.log("Wrong SETUP command from: %s" % client[0])
2.24 + server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
2.25
2.26 elif (msg == "PLAY"):
2.27 media.play()
3.1 --- a/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 23:12:52 2007 +0100
3.2 +++ b/gmyth-stream/plugins/comm/tcp.py Sat Mar 31 00:55:28 2007 +0100
3.3 @@ -18,11 +18,11 @@
3.4 return self.con.recv(size)
3.5
3.6 def sendMsg(self, msg):
3.7 - self.con.send(msg)
3.8 + self.con.send(msg + "\n")
3.9
3.10 def Ack(self, command):
3.11 msg = "[%s] Command %s received" % (lib.now(), command)
3.12 - self.sendMsg(msg + "\n")
3.13 + self.sendMsg(msg)
3.14
3.15 def getRequest(self):
3.16 self.con, self.client = self.tcp.accept()
4.1 --- a/gmyth-stream/plugins/media/mencoder.py Fri Mar 30 23:12:52 2007 +0100
4.2 +++ b/gmyth-stream/plugins/media/mencoder.py Sat Mar 31 00:55:28 2007 +0100
4.3 @@ -16,46 +16,54 @@
4.4 def setup(self, filename, mux, vcodec, vbitrate,\
4.5 fps, acodec, abitrate, width, height, port):
4.6
4.7 - self.filename = filename
4.8 - self.mux = mux
4.9 - self.vcodec = vcodec
4.10 - self.vbitrate = int(vbitrate)
4.11 - self.fps = int(fps)
4.12 - self.acodec = acodec
4.13 - self.abitrate = int(abitrate)
4.14 - self.width = int(width)
4.15 - self.height = int(height)
4.16 + if (os.path.exists(filename)):
4.17
4.18 - self.port = int(port)
4.19 - self.fifo = self.config.get("Mencoder", "fifo_path")
4.20 + self.filename = filename
4.21 + self.mux = mux
4.22 + self.vcodec = vcodec
4.23 + self.vbitrate = int(vbitrate)
4.24 + self.fps = int(fps)
4.25 + self.acodec = acodec
4.26 + self.abitrate = int(abitrate)
4.27 + self.width = int(width)
4.28 + self.height = int(height)
4.29 +
4.30 + self.port = int(port)
4.31 + self.fifo = self.config.get("Mencoder", "fifo_path")
4.32 +
4.33 + # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
4.34 + self.path = self.config.get("Mencoder", "path")
4.35 + self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
4.36 + " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
4.37 + " -o %s 1> /dev/null 2> /dev/null" % (
4.38 + self.filename, self.fps, self.mux, self.acodec, self.abitrate,
4.39 + self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
4.40 +
4.41 +
4.42 + if (self.socket != None):
4.43 + del(self.socket)
4.44 +
4.45 + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
4.46 + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
4.47 + self.socket.bind( ('', self.port) )
4.48 + self.socket.listen(1)
4.49 +
4.50 + return 0
4.51 +
4.52 + else:
4.53 + lib.log("File requested does not exist. SETUP failed.")
4.54 + return -1
4.55 +
4.56 + def play(self):
4.57
4.58 try:
4.59 os.mkfifo(self.fifo)
4.60 except:
4.61 lib.log("Fifo already exists")
4.62
4.63 - # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
4.64 - self.path = self.config.get("Mencoder", "path")
4.65 - self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
4.66 - " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
4.67 - " -o %s 1> /dev/null 2> /dev/null" % (
4.68 - self.filename, self.fps, self.mux, self.acodec, self.abitrate,
4.69 - self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
4.70 -
4.71 -
4.72 - if (self.socket != None):
4.73 - del(self.socket)
4.74 -
4.75 - self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
4.76 - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
4.77 - self.socket.bind( ('', self.port) )
4.78 - self.socket.listen(1)
4.79 -
4.80 - def play(self):
4.81 -
4.82 lib.log("Starting Mencoder: %s" % self.path )
4.83 # exec Mencoder
4.84 - pin, pout = os.popen2(self.path)
4.85 + pin, self.pout = os.popen2(self.path)
4.86 pin.close()
4.87
4.88 fifo = open(self.fifo)
4.89 @@ -83,10 +91,11 @@
4.90 else:
4.91 lib.log("Client timed out")
4.92
4.93 - pout.close()
4.94
4.95 def stop(self):
4.96
4.97 + self.pout.close()
4.98 +
4.99 if (self.socket != None):
4.100 lib.log("Closing socket")
4.101 self.socket.close()
5.1 --- a/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 23:12:52 2007 +0100
5.2 +++ b/gmyth-stream/tests/client_ffmpeg.py Sat Mar 31 00:55:28 2007 +0100
5.3 @@ -34,9 +34,10 @@
5.4 data = socket.recv(1024)
5.5
5.6 pin.close()
5.7 -pout.close()
5.8 +#pout.close()
5.9 socket.close()
5.10
5.11 +
5.12 # from select import select
5.13 # r, w, x = select([pout], []. [], 0)
5.14 # if pout in r: