# HG changeset patch # User morphbr # Date 1176132157 -3600 # Node ID b5352888e3c255115d5a8b0133637735daa08ed8 # Parent 12a61040588d80fced85124528be250644d424fc [svn r519] Gmyth-Streamer: Mencoder update diff -r 12a61040588d -r b5352888e3c2 gmyth-stream/server/main.py --- a/gmyth-stream/server/main.py Mon Apr 09 15:20:37 2007 +0100 +++ b/gmyth-stream/server/main.py Mon Apr 09 16:22:37 2007 +0100 @@ -71,7 +71,7 @@ nextport += 1 ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec, abitrate, width, height, nextport, options) - if ret == 0: + if ret == True: server.sendOk() else: server.sendNotOk(ret) diff -r 12a61040588d -r b5352888e3c2 gmyth-stream/server/plugins/media/mencoder.py --- a/gmyth-stream/server/plugins/media/mencoder.py Mon Apr 09 15:20:37 2007 +0100 +++ b/gmyth-stream/server/plugins/media/mencoder.py Mon Apr 09 16:22:37 2007 +0100 @@ -23,12 +23,17 @@ self.mplayer_pid = None signal.signal(signal.SIGABRT, self.kill_handler) + # __init__ + def kill_handler(self, sig, frame): try: - os.kill(self.mplayer_pid.pid + 1, signal.SIGKILL) + os.kill(self.mplayer_pid.pid, signal.SIGKILL) + log.debug("Killed Mplayer") sys.exit(0) except: - lib.log("Problems closing child") + log.error("Problems closing child") + + # kill_handler def set_args(self, options): @@ -41,58 +46,67 @@ try: self.language = opt.split("=")[1] except: - lib.log("Bad language option") + log.error("Bad language option") elif opt.find("format=") >= 0: try: self.mux += " -mpegopts format=%s" % opt.split("=")[1] except: - lib.log("Bad format option") + log.error("Bad format option") + # set_args def run_mplayer(self): - msg = "%s 1>/dev/null 2>/dev/null" % self.filename + msg = self.filename if self.kind == "dvd": msg = "dvd://" + msg - self.mplayer += " " + msg - self.mplayer_pid = Popen(self.mplayer, shell=True, close_fds=True) + self.mplayer_pid = Popen([self.mplayer, self.filename, "1> %s" % os.devnull,\ + "2> %s" % os.devnull], stdout=PIPE, close_fds=True) + + # run_mplayer + def setup_mencoder(self): self.path = self.config.get("Mencoder", "path") - a, b = os.popen2(self.path) - version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1] + mp = Popen([self.path], stdout=PIPE, close_fds=True) + + version = mp.stdout.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1] if version > "4.1.1": self.mencoder_old = False else: self.mencoder_old = True - lib.log("Mencoder version: %s" % version) - - a.close() - b.close() + os.kill(mp.pid, signal.SIGKILL) + log.info("Mencoder version: %s" % version) if self.mencoder_old: self.fifo = self.config.get("Mencoder", "fifo_path") else: self.fifo = "-" + # setup_mencoder + + def setup_audio(self, acodec): + + if acodec == "mp3lame": + return "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate + else: + return = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ + self.acodec, self.abitrate) + def setup_filename(self, filename): try: self.kind, self.filename = filename.split("://") except: return (False, "Wrong filename protocol") - if self.acodec == "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) + audio = setup_audio(self.acodec) if self.kind == "file": if not os.path.exists(self.filename): msg = "File requested does not exist. SETUP failed." - lib.log(msg) + log.error(msg) return (False, msg) self.args += " %s -mf fps=%s -of %s %s"\ @@ -110,6 +124,24 @@ return (True, "") + # setup_filename + + def setup_socket(self, socket): + if socket != None: + del(socket) + + socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + try: + socket.bind( ('', self.port) ) + socket.listen(1) + except Exception, e: + log.error("Could not create socket: %s" % e) + return (False, e) + + return (True, "") + ''' MENCODER SETUP DESCRIPTION =========================== @@ -146,16 +178,14 @@ # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file # /tmp/dvb.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 format=mpeg1 file #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd - if self.socket != None: - del(self.socket) + ret_val = setup_socket(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) + if not ret_val[0]: + return ret_val[1] - return 0 + return True + # setup def play(self):