# HG changeset patch # User morphbr # Date 1175702891 -3600 # Node ID 08a2d7d67ae55e24ce8d27c67a5158c3773f9dcd # Parent 8f9fe41efa819255d2927af79b71fc139344d8c9 [svn r502] GMyth-Streamer: code cleanup diff -r 8f9fe41efa81 -r 08a2d7d67ae5 gmyth-stream/server/main.py --- a/gmyth-stream/server/main.py Wed Apr 04 16:47:00 2007 +0100 +++ b/gmyth-stream/server/main.py Wed Apr 04 17:08:11 2007 +0100 @@ -21,7 +21,7 @@ lib.log("Starting GMyth-Stream server") -while (server.finish == 0): +while (server.finish is 0): con, client = server.getRequest() while True: @@ -31,17 +31,17 @@ lib.log("Received %s from: %s" % (msg, client) ) - if (msg == "SETUP"): + if msg is "SETUP": setup = server.getMsg(1024).strip().split(" ") size = len(setup) options = [] - if ( size < 10 ): + if size < 10: server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0])) else: - if ( size > 10 ): + if size > 10: i = 10 while (i < size): options.append(setup[i]) @@ -52,21 +52,21 @@ setup[6], setup[7], setup[8], setup[9], options) - if (ret == 0): + if ret is 0: server.Ack("SETUP") else: server.sendMsg(lib.log(ret)) - elif (msg == "PLAY"): + elif msg is "PLAY": media.play() server.Ack("PLAY") - elif (msg == "STOP"): + elif msg is "STOP": media.stop() server.Ack("STOP") - elif (msg == "CLOSE"): + elif msg is "CLOSE": server.finish = 1 media.stop() server.Ack("CLOSE") diff -r 8f9fe41efa81 -r 08a2d7d67ae5 gmyth-stream/server/plugins/media/mencoder.py --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 16:47:00 2007 +0100 +++ b/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 17:08:11 2007 +0100 @@ -9,7 +9,7 @@ from select import * from subprocess import * -class Media: +class Media(object): def __init__(self, config): @@ -33,22 +33,24 @@ for opt in options: - if (opt == "file" or opt == "dvd"): - if (self.acodec == "mp3lame"): + if opt is "file" or opt is "dvd": + + if self.acodec is "mp3lame": audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate else: audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ self.acodec, self.abitrate) - if (opt == "file"): + + if opt is "file": self.kind = "file" - self.args += " %s -mf fps=%s -of %s -noodml %s"\ + self.args += " %s -mf fps=%s -of %s %s"\ " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\ " -o %s 1> /dev/null 2> /dev/null" % ( self.filename, self.fps, self.mux, audio, self.vcodec, self.vbitrate, self.width, self.height, self.fifo) - elif (opt == "dvd"): + elif opt is "dvd": self.kind = "dvd" self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\ " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -o %s"\ @@ -56,19 +58,26 @@ self.filename, self.language, self.width, self.height, audio, self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps) - elif (opt == "local"): + elif opt is "local": self.mplayer = os.popen("which mplayer").read().strip() - elif (opt.find("language=") >= 0): + elif opt.find("language=") >= 0: try: self.language = opt.split("=")[1] except: lib.log("Bad language option") + elif opt.find("format=") >= 0: + try: + self.mux += " -mpegopts format=%s" % opt.split("=")[1] + except: + lib.log("Bad format option") + def run_mplayer(self): msg = "%s 1>/dev/null 2>/dev/null" % self.filename - if (self.kind == "dvd"): + + if self.kind is "dvd": msg = "dvd://" + msg self.mplayer += " " + msg @@ -94,15 +103,16 @@ self.kind = "" self.set_args(options) - if (self.kind == "file" and not os.path.exists(self.filename)): + if self.kind is "file" and not os.path.exists(self.filename): msg = "File requested does not exist. SETUP failed." lib.log(msg) return msg # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 + #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd self.path = self.config.get("Mencoder", "path") - if (self.socket != None): + if self.socket is not None: del(self.socket) self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) @@ -128,7 +138,7 @@ self.child_pid = os.fork() - if (self.child_pid == 0): + if self.child_pid is 0: conn,addr= self.socket.accept() lib.log("Sending Data to client: %s" % addr[0]) @@ -136,13 +146,13 @@ conn.settimeout(5) retry = 0 - while( data != "" and retry < 5): + while data is not "" and retry < 5: try: conn.send(data) r, w, x = select([conn], [], [], 0) if conn in r: back = conn.recv(1024) - if (back == "OK" and self.mplayer and not self.mplayer_pid): + if back is "OK" and self.mplayer and not self.mplayer_pid: self.run_mplayer() except socket.error: @@ -151,7 +161,7 @@ data = fifo.read(1024) - if (retry < 5): + if retry < 5: lib.log("Finished sending Data to client: %s" % addr[0]) else: lib.log("Client timed out") @@ -166,10 +176,10 @@ except: lib.log("Trying to stop before playing...") - if (self.socket != None): + if self.socket is not None: lib.log("Closing socket") self.socket.close() lib.log("Trying to stop Mencoder process") - if (self.child_pid != None): + if self.child_pid is not None: os.kill(self.child_pid, signal.SIGABRT) diff -r 8f9fe41efa81 -r 08a2d7d67ae5 gmyth-stream/server/stream.conf --- a/gmyth-stream/server/stream.conf Wed Apr 04 16:47:00 2007 +0100 +++ b/gmyth-stream/server/stream.conf Wed Apr 04 17:08:11 2007 +0100 @@ -4,7 +4,7 @@ [Media] -engine = gstreamer +engine = mencoder [Vlc]