# HG changeset patch # User morphbr # Date 1175298928 -3600 # Node ID 07c12d2ceddf8d411d34d5bfffa3d93050f20f1a # Parent b94790c04fd5556048d8861050831dcdac12c8a3 [svn r479] * GMyth-Stream: - Error handling: file does not exist on setup (mencoder) diff -r b94790c04fd5 -r 07c12d2ceddf gmyth-stream/lib.py --- a/gmyth-stream/lib.py Fri Mar 30 23:12:52 2007 +0100 +++ b/gmyth-stream/lib.py Sat Mar 31 00:55:28 2007 +0100 @@ -4,4 +4,6 @@ return time.strftime("%Y-%m-%d %H:%M:%S"); def log(msg): - print "[%s] %s" % (now(), msg) + new_msg = "[%s] %s" % (now(), msg) + print new_msg + return new_msg diff -r b94790c04fd5 -r 07c12d2ceddf gmyth-stream/main.py --- a/gmyth-stream/main.py Fri Mar 30 23:12:52 2007 +0100 +++ b/gmyth-stream/main.py Sat Mar 31 00:55:28 2007 +0100 @@ -34,15 +34,18 @@ if (msg == "SETUP"): setup = server.getMsg(1024).strip().split(" ") if ( len(setup) == 10 ): - media.setup(setup[0], setup[1], setup[2], \ - setup[3], setup[4], setup[5], - setup[6], setup[7], setup[8], - setup[9]) + ret = media.setup(setup[0], setup[1], setup[2], \ + setup[3], setup[4], setup[5], + setup[6], setup[7], setup[8], + setup[9]) - server.Ack("SETUP") + if (ret == 0): + server.Ack("SETUP") + else: + server.sendMsg(lib.log("File does not exist: %s" % setup[0])) else: - lib.log("Wrong SETUP command from: %s" % client[0]) + server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0])) elif (msg == "PLAY"): media.play() diff -r b94790c04fd5 -r 07c12d2ceddf gmyth-stream/plugins/comm/tcp.py --- a/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 23:12:52 2007 +0100 +++ b/gmyth-stream/plugins/comm/tcp.py Sat Mar 31 00:55:28 2007 +0100 @@ -18,11 +18,11 @@ return self.con.recv(size) def sendMsg(self, msg): - self.con.send(msg) + self.con.send(msg + "\n") def Ack(self, command): msg = "[%s] Command %s received" % (lib.now(), command) - self.sendMsg(msg + "\n") + self.sendMsg(msg) def getRequest(self): self.con, self.client = self.tcp.accept() diff -r b94790c04fd5 -r 07c12d2ceddf gmyth-stream/plugins/media/mencoder.py --- a/gmyth-stream/plugins/media/mencoder.py Fri Mar 30 23:12:52 2007 +0100 +++ b/gmyth-stream/plugins/media/mencoder.py Sat Mar 31 00:55:28 2007 +0100 @@ -16,46 +16,54 @@ def setup(self, filename, mux, vcodec, vbitrate,\ fps, acodec, abitrate, width, height, port): - self.filename = filename - self.mux = mux - self.vcodec = vcodec - self.vbitrate = int(vbitrate) - self.fps = int(fps) - self.acodec = acodec - self.abitrate = int(abitrate) - self.width = int(width) - self.height = int(height) + if (os.path.exists(filename)): - self.port = int(port) - self.fifo = self.config.get("Mencoder", "fifo_path") + self.filename = filename + self.mux = mux + self.vcodec = vcodec + self.vbitrate = int(vbitrate) + self.fps = int(fps) + self.acodec = acodec + self.abitrate = int(abitrate) + self.width = int(width) + self.height = int(height) + + self.port = int(port) + self.fifo = self.config.get("Mencoder", "fifo_path") + + # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 + self.path = self.config.get("Mencoder", "path") + self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\ + " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\ + " -o %s 1> /dev/null 2> /dev/null" % ( + self.filename, self.fps, self.mux, self.acodec, self.abitrate, + self.vcodec, self.vbitrate, self.width, self.height, self.fifo) + + + if (self.socket != None): + del(self.socket) + + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.bind( ('', self.port) ) + self.socket.listen(1) + + return 0 + + else: + lib.log("File requested does not exist. SETUP failed.") + return -1 + + def play(self): try: os.mkfifo(self.fifo) except: lib.log("Fifo already exists") - # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 - self.path = self.config.get("Mencoder", "path") - self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\ - " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\ - " -o %s 1> /dev/null 2> /dev/null" % ( - self.filename, self.fps, self.mux, self.acodec, self.abitrate, - self.vcodec, self.vbitrate, self.width, self.height, self.fifo) - - - if (self.socket != None): - del(self.socket) - - self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.socket.bind( ('', self.port) ) - self.socket.listen(1) - - def play(self): - lib.log("Starting Mencoder: %s" % self.path ) # exec Mencoder - pin, pout = os.popen2(self.path) + pin, self.pout = os.popen2(self.path) pin.close() fifo = open(self.fifo) @@ -83,10 +91,11 @@ else: lib.log("Client timed out") - pout.close() def stop(self): + self.pout.close() + if (self.socket != None): lib.log("Closing socket") self.socket.close() diff -r b94790c04fd5 -r 07c12d2ceddf gmyth-stream/tests/client_ffmpeg.py --- a/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 23:12:52 2007 +0100 +++ b/gmyth-stream/tests/client_ffmpeg.py Sat Mar 31 00:55:28 2007 +0100 @@ -34,9 +34,10 @@ data = socket.recv(1024) pin.close() -pout.close() +#pout.close() socket.close() + # from select import select # r, w, x = select([pout], []. [], 0) # if pout in r: