# HG changeset patch # User morphbr # Date 1177018726 -3600 # Node ID 7dc357cbaa409eb3f6a1be542b2a2a38eb5926dd # Parent 6ee1dc7357e8bd1dcfa1bfd4100e6724a23a4b94 [svn r582] * GMyth-Streamer (version 0.2): - Mencoder plugin 100% working (without mythtv stuff) - Debug messages updated - Bug fixes inside server/utils diff -r 6ee1dc7357e8 -r 7dc357cbaa40 gmyth-stream/server/0.2/gms.py --- a/gmyth-stream/server/0.2/gms.py Thu Apr 19 21:22:26 2007 +0100 +++ b/gmyth-stream/server/0.2/gms.py Thu Apr 19 22:38:46 2007 +0100 @@ -11,7 +11,7 @@ log_level -= 10 log.basicConfig(level=log_level, - format=("### %(asctime)s %(name)-18s %(levelname)-8s " + format=("### %(asctime)s %(name)-18s \t%(levelname)-8s " "\t%(message)s"), datefmt="%Y-%m-%d %H:%M:%S") diff -r 6ee1dc7357e8 -r 7dc357cbaa40 gmyth-stream/server/0.2/lib/server.py --- a/gmyth-stream/server/0.2/lib/server.py Thu Apr 19 21:22:26 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/server.py Thu Apr 19 22:38:46 2007 +0100 @@ -19,7 +19,7 @@ "load_plugins_transcoders") class Transcoder(object): - log = log.getLogger("gmyth-streamer.transcoder") + log = log.getLogger("gms.transcoder") priority = 0 # negative values have higher priorities name = None # to be used in requests @@ -62,18 +62,19 @@ def __str__(self): - return '%s("%s", mux="%s", params=%s)' % \ + return '%s("%s", mux="%s", params=%s, addr=%s)' % \ (self.__class__.__name__, self.params_first("uri", "None"), self.params_first("mux", "mpg"), - self.params) + self.params, + repr(self)) # __str__() # Transcoder class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): - log = log.getLogger("gmyth-streamer.request") + log = log.getLogger("gms.request") def_transcoder = None transcoders = utils.PluginSet(Transcoder) @@ -370,7 +371,7 @@ class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): - log = log.getLogger("gmyth-streamer.server") + log = log.getLogger("gms.server") run = True _transcoders = {} _lock = threading.RLock() diff -r 6ee1dc7357e8 -r 7dc357cbaa40 gmyth-stream/server/0.2/lib/utils.py --- a/gmyth-stream/server/0.2/lib/utils.py Thu Apr 19 21:22:26 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/utils.py Thu Apr 19 22:38:46 2007 +0100 @@ -13,7 +13,7 @@ import gobject import imp -log = logging.getLogger("gmyth-stream.utils") +log = logging.getLogger("gms.utils") __all__ = ("which", "load_plugins", "PluginSet") @@ -74,7 +74,7 @@ def get(self, name, default=None): - self.map.get(name, default) + return self.map.get(name, default) # get() diff -r 6ee1dc7357e8 -r 7dc357cbaa40 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Thu Apr 19 21:22:26 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Thu Apr 19 22:38:46 2007 +0100 @@ -1,8 +1,10 @@ +import os +import shlex +import signal +import subprocess + import lib.utils as utils import lib.server as server -import os -import signal -import subprocess __all__ = ("TranscoderMencoder",) @@ -10,6 +12,8 @@ mencoder_path = utils.which("mencoder") name = "mencoder" priority = -1 + args = {} + proc = None def _setup_params(self): params_first = self.params_first @@ -22,8 +26,9 @@ self.args["outfile"] = params_first("outfile", "-") # input_opt - self.args["type"] = params_first("type", "file") - self.args["input"] = params_first("input", "-") + uri = params_first("uri", "file://-").split("://") + self.args["type"] = uri[0] + self.args["input"] = uri[1] # audio_opts self.args["acodec"] = params_first("acodec", "mp2") @@ -53,8 +58,8 @@ def _setup_video(self): - video = " -of %s" % self.mux - video += " -ofps %s" % self.fps + video = " -of %s" % self.args["mux"] + video += " -ofps %s" % self.args["fps"] vcodec = self.args["vcodec"] if vcodec == "nuv" or vcodec == "xvid"\ @@ -72,13 +77,13 @@ def _arg_append(self, args, options): - for arg in shlex.split(options) + for arg in shlex.split(options): args.append(arg) # arg_append() def _setup_mencoder_opts(self, args): args.append(self.mencoder_path) - args.append("-") + args.append(self.args["input"]) if self.args["language"]: self._arg_append(args, "-alang %s" % self.args["language"]) @@ -88,8 +93,8 @@ self._arg_append(args, "-subfps %s" % self.args["fps"]) self._arg_append(args, "-idx") - self._arg_append(args, self._setup_audio) - self._arg_append(args, self._setup_video) + self._arg_append(args, self._setup_audio()) + self._arg_append(args, self._setup_video()) self._arg_append(args, "-really-quiet") self._arg_append(args, "-o %s" % self.args["outfile"]) @@ -102,22 +107,17 @@ if _type == "file": if not os.path.exists(self.args["input"]): - raise IOError, "File requested does not exist." + raise IOError,\ + "File requested does not exist: %s." % self.args["input"] elif _type == "dvd": self.args["input"] = "dvd://".join(self.args["input"]) - - elif _type == "myth": - self.args["input"] = "myth://".join(self.args["input"]) - self.gst_pipe = os.pipe() # _setup_filename() def __init__(self, params): server.Transcoder.__init__(self, params) - self.proc = None - self.args = None - self.mencoder_opts = None + self.mencoder_opts = [] try: self._setup_params() @@ -125,34 +125,22 @@ self._setup_mencoder_opts(self.mencoder_opts) except Exception, e: self.log.error(e) - return False - - return True # __init__() def start(self, outfd): - cmd = " ".join(self.args) - self.log.info("Mencoder: %s" % cmd) - - if self.args["type"] == "file": - _input = open(self.args["input"]) + cmd = " ".join(self.mencoder_opts) + self.log.debug("Mencoder: %s" % cmd) try: - self.proc = subprocess.Popen(self.args, close_fds=True) + self.proc = subprocess.Popen(self.mencoder_opts, stdout=subprocess.PIPE, close_fds=True) except Exception, e: - self.log.error("Error executing mencoder: %s" % cmd) - return False - - try: - fifo_read = open(self.mencoder_outfile) - except Exception, e: - self.log.error("Error opening fifo: %s" % cmd) + self.log.error("Error executing mencoder: %s" % e) return False try: while self.proc and self.proc.poll() == None: - d = fifo_read.read(1024) + d = self.proc.stdout.read(1024) outfd.write(d) except Exception, e: self.log.error("Problems handling data: %s" % e)