# HG changeset patch # User morphbr # Date 1177512799 -3600 # Node ID 5c5cff842d57cc23d3549c40308f85a8d0d5700a # Parent f36075170a4e9f4afe52fa15f556562a06d91550 [svn r601] * GMyth-Streamer - Updated mencoder, gmencoder and server diff -r f36075170a4e -r 5c5cff842d57 gmyth-stream/server/0.2/lib/server.py --- a/gmyth-stream/server/0.2/lib/server.py Wed Apr 25 15:50:41 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/server.py Wed Apr 25 15:53:19 2007 +0100 @@ -22,6 +22,7 @@ log = log.getLogger("gms.transcoder") priority = 0 # negative values have higher priorities name = None # to be used in requests + status = None def __init__(self, params): self.params = params @@ -237,9 +238,10 @@ for transcoder, request in tl: stopone = self._create_html_item("%s: %s:%s" - "[STOP]" % ( + "[STOP] - Status: %s%%" % ( transcoder, request.client_address[0], request.client_address[1], - self.menu["Stop"], request.client_address[0], request.client_address[1]) ) + self.menu["Stop"], request.client_address[0], request.client_address[1], + transcoder.status) ) self.wfile.write(utils.getHTML("status", {"menu": self._nav_items(), diff -r f36075170a4e -r 5c5cff842d57 gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py Wed Apr 25 15:50:41 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py Wed Apr 25 15:53:19 2007 +0100 @@ -13,7 +13,6 @@ name = "gmencoder" priority = -1 proc = None - args = {} def __init__(self, params): server.Transcoder.__init__(self, params) @@ -28,6 +27,9 @@ def _parser_params (self): self._insert_param("-i", \ "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", ""))) + + #self._insert_param("-i", self.params_first("uri", "")) + self._insert_param("--video-encode", self.params_first("ve", "")) self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5") self._insert_param("--video-fps", self.params_first("fps", "")) @@ -35,8 +37,8 @@ self._insert_param("--video-height", self.params_first("height", "")) self._insert_param("--audio-encode", self.params_first("ae", "")) self._insert_param("--output-element", "fdsink") - # _parse_params - + # _parse_params + def start(self, outfd): self.opts.append (self.gmencoder_path) self._parser_params () @@ -44,17 +46,16 @@ self.opts.append ("fd=%d" % outfd.fileno()) cmd = " ".join(self.opts) - self.log.info ("Gmemconder: %s", cmd) + self.log.info ("GMencoder: %s", cmd) try: self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE) except Exception, e: - self.log.error("Error executing gmencoder: %s" % e) + self.log.error("Error executing GMencoder: %s" % e) return False try: self.proc.wait() - except Exception, e: self.log.error("Problems handling data: %s" % e) return False @@ -65,7 +66,7 @@ def stop(self): if self.proc: - self.log.info ("STOP") + self.log.info ("STOPed GMencoder plugin") try: self.proc.stdin.write ("QUIT\n") except Exception, e: diff -r f36075170a4e -r 5c5cff842d57 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Wed Apr 25 15:50:41 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Wed Apr 25 15:53:19 2007 +0100 @@ -2,10 +2,13 @@ import shlex import signal import subprocess +import time import lib.utils as utils import lib.server as server +from select import select + __all__ = ("TranscoderMencoder",) class TranscoderMencoder(server.Transcoder): @@ -16,6 +19,9 @@ args = {} proc = None + # only works with avi container + status = 0 + def _setup_params(self): params_first = self.params_first @@ -25,6 +31,11 @@ self.args["subtitle"] = params_first("subtitle", False) self.args["format"] = params_first("format", "") self.args["outfile"] = params_first("outfile", "-") + self.args["sendback"] = params_first("sendback", True) + + # handle sendback variable + if self.args["sendback"] == "False": + self.args["sendback"] = False # input_opt uri = params_first("uri", "file://-").split("://") @@ -84,7 +95,11 @@ def _setup_mencoder_opts(self, args): args.append(self.mencoder_path) - args.append(self.args["input"]) + + if self.args["outfile"] == "-" and self.args["type"]: + args.append(self.args["input"]) + else: + args.append("-") if self.args["language"]: self._arg_append(args, "-alang %s" % self.args["language"]) @@ -99,7 +114,7 @@ self._arg_append(args, "-really-quiet") self._arg_append(args, "-o %s" % self.args["outfile"]) - self._arg_append(args, "2> %s" % os.devnull) + self._arg_append(args, "2>%s" % os.devnull) # _setup_args() @@ -113,6 +128,12 @@ elif _type == "dvd": self.args["input"] = "dvd://".join(self.args["input"]) + + elif _type == "myth": + # gmyth-cat -h 192.168.1.124 -p 6543 -c 111 + # gmyth-cat -h 192.168.1.124 -p 6543 -f file.nuv + # myth://IP:PORT:type:file + self.args["gmyth-cat"] = self.args["input"].split(":") # _setup_filename() @@ -129,16 +150,79 @@ # __init__() - def start(self, outfd): - cmd = " ".join(self.mencoder_opts) - self.log.debug("Mencoder: %s" % cmd) + def _check_opened_file(self, stdw, _stdin): + loop = True + while loop: + try: + return open(self.args["outfile"]) + except: + os.write(stdw, _stdin.read(1024)) + # _check_opened_file + + + def _start_outfile(self, outfd): + finished = False + + # fix this (not necessary) + outfd.write("OK") + + # Configuring stdin + _stdin = open(self.args["input"]) + size = int(os.path.getsize(self.args["input"])) + self.status = 0 + total_read = 0 + + # Configuring pipes + stdr, stdw = os.pipe() try: - self.proc = subprocess.Popen(self.mencoder_opts, stdout=subprocess.PIPE, close_fds=True) + self.proc = subprocess.Popen(self.mencoder_opts, stdin=stdr, close_fds=True) except Exception, e: self.log.error("Error executing mencoder: %s" % e) return False + stdout = self._check_opened_file(stdw, _stdin) + + try: + while self.proc and self.proc.poll() == None: + if not finished: + data_in = _stdin.read(4096) + if data_in != "": + os.write(stdw, data_in) + total_read += 4096 + d = stdout.read(4096) + if self.args["sendback"]: + outfd.write(d) + self.status = total_read * 100 / size + else: + finished = True + os.close(stdw) + + else: + d = stdout.read(4096) + if self.args["sendback"] and d != "": + outfd.write(d) + + except Exception, e: + self.log.error("Problems handling data: %s" % e) + return False + + self.log.info("%s: Finished sending data to client" % repr(self)) + if not self.args["sendback"]: + outfd.write("DONE") + + return True + # _start_outfile() + + def _start(self, outfd): + try: + self.proc = subprocess.Popen(self.mencoder_opts, + stdout=subprocess.PIPE, close_fds=True) + except Exception, e: + self.log.error("Error executing mencoder: %s" % e) + return False + + try: while self.proc and self.proc.poll() == None: d = self.proc.stdout.read(1024) @@ -147,7 +231,19 @@ self.log.error("Problems handling data: %s" % e) return False + self.log.info("%s: Finished sending data to client" % repr(self)) return True + # _start() + + + def start(self, outfd): + cmd = " ".join(self.mencoder_opts) + self.log.debug("Mencoder: %s" % cmd) + + if self.args["outfile"] == "-": + return self._start(outfd) + else: + return self._start_outfile(outfd) # start()