[svn r582] * GMyth-Streamer (version 0.2): trunk
authormorphbr
Thu Apr 19 22:38:46 2007 +0100 (2007-04-19)
branchtrunk
changeset 5777dc357cbaa40
parent 576 6ee1dc7357e8
child 578 9e589622f097
[svn r582] * GMyth-Streamer (version 0.2):
- Mencoder plugin 100% working (without mythtv stuff)
- Debug messages updated
- Bug fixes inside server/utils
gmyth-stream/server/0.2/gms.py
gmyth-stream/server/0.2/lib/server.py
gmyth-stream/server/0.2/lib/utils.py
gmyth-stream/server/0.2/plugins/transcoders/mencoder.py
     1.1 --- a/gmyth-stream/server/0.2/gms.py	Thu Apr 19 21:22:26 2007 +0100
     1.2 +++ b/gmyth-stream/server/0.2/gms.py	Thu Apr 19 22:38:46 2007 +0100
     1.3 @@ -11,7 +11,7 @@
     1.4          log_level -= 10
     1.5  
     1.6  log.basicConfig(level=log_level,
     1.7 -                format=("### %(asctime)s %(name)-18s %(levelname)-8s "
     1.8 +                format=("### %(asctime)s %(name)-18s \t%(levelname)-8s "
     1.9                          "\t%(message)s"),
    1.10                  datefmt="%Y-%m-%d %H:%M:%S")
    1.11  
     2.1 --- a/gmyth-stream/server/0.2/lib/server.py	Thu Apr 19 21:22:26 2007 +0100
     2.2 +++ b/gmyth-stream/server/0.2/lib/server.py	Thu Apr 19 22:38:46 2007 +0100
     2.3 @@ -19,7 +19,7 @@
     2.4             "load_plugins_transcoders")
     2.5  
     2.6  class Transcoder(object):
     2.7 -    log = log.getLogger("gmyth-streamer.transcoder")
     2.8 +    log = log.getLogger("gms.transcoder")
     2.9      priority = 0   # negative values have higher priorities
    2.10      name = None # to be used in requests
    2.11  
    2.12 @@ -62,18 +62,19 @@
    2.13  
    2.14  
    2.15      def __str__(self):
    2.16 -        return '%s("%s", mux="%s", params=%s)' % \
    2.17 +        return '%s("%s", mux="%s", params=%s, addr=%s)' % \
    2.18                 (self.__class__.__name__,
    2.19                  self.params_first("uri", "None"),
    2.20                  self.params_first("mux", "mpg"),
    2.21 -                self.params)
    2.22 +                self.params,
    2.23 +                repr(self))
    2.24      # __str__()
    2.25  # Transcoder
    2.26  
    2.27  
    2.28  
    2.29  class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    2.30 -    log = log.getLogger("gmyth-streamer.request")
    2.31 +    log = log.getLogger("gms.request")
    2.32      def_transcoder = None
    2.33      transcoders = utils.PluginSet(Transcoder)
    2.34  
    2.35 @@ -370,7 +371,7 @@
    2.36  
    2.37  
    2.38  class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
    2.39 -    log = log.getLogger("gmyth-streamer.server")
    2.40 +    log = log.getLogger("gms.server")
    2.41      run = True
    2.42      _transcoders = {}
    2.43      _lock = threading.RLock()
     3.1 --- a/gmyth-stream/server/0.2/lib/utils.py	Thu Apr 19 21:22:26 2007 +0100
     3.2 +++ b/gmyth-stream/server/0.2/lib/utils.py	Thu Apr 19 22:38:46 2007 +0100
     3.3 @@ -13,7 +13,7 @@
     3.4  import gobject
     3.5  import imp
     3.6  
     3.7 -log = logging.getLogger("gmyth-stream.utils")
     3.8 +log = logging.getLogger("gms.utils")
     3.9  
    3.10  __all__ = ("which", "load_plugins", "PluginSet")
    3.11  
    3.12 @@ -74,7 +74,7 @@
    3.13  
    3.14  
    3.15      def get(self, name, default=None):
    3.16 -        self.map.get(name, default)
    3.17 +        return self.map.get(name, default)
    3.18      # get()
    3.19  
    3.20  
     4.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu Apr 19 21:22:26 2007 +0100
     4.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu Apr 19 22:38:46 2007 +0100
     4.3 @@ -1,8 +1,10 @@
     4.4 +import os
     4.5 +import shlex
     4.6 +import signal
     4.7 +import subprocess
     4.8 +
     4.9  import lib.utils as utils
    4.10  import lib.server as server
    4.11 -import os
    4.12 -import signal
    4.13 -import subprocess
    4.14  
    4.15  __all__ = ("TranscoderMencoder",)
    4.16  
    4.17 @@ -10,6 +12,8 @@
    4.18      mencoder_path = utils.which("mencoder")
    4.19      name = "mencoder"
    4.20      priority = -1
    4.21 +    args = {}
    4.22 +    proc = None
    4.23  
    4.24      def _setup_params(self):
    4.25          params_first = self.params_first
    4.26 @@ -22,8 +26,9 @@
    4.27          self.args["outfile"]  = params_first("outfile", "-")
    4.28  
    4.29          # input_opt
    4.30 -        self.args["type"]     = params_first("type", "file")
    4.31 -        self.args["input"]    = params_first("input", "-")
    4.32 +        uri = params_first("uri", "file://-").split("://")
    4.33 +        self.args["type"]     = uri[0]
    4.34 +        self.args["input"]    = uri[1]
    4.35  
    4.36          # audio_opts
    4.37          self.args["acodec"]   = params_first("acodec", "mp2")
    4.38 @@ -53,8 +58,8 @@
    4.39  
    4.40  
    4.41      def _setup_video(self):
    4.42 -        video = " -of %s" % self.mux
    4.43 -        video += " -ofps %s" % self.fps
    4.44 +        video = " -of %s" % self.args["mux"]
    4.45 +        video += " -ofps %s" % self.args["fps"]
    4.46  
    4.47          vcodec = self.args["vcodec"]
    4.48          if vcodec == "nuv" or vcodec == "xvid"\
    4.49 @@ -72,13 +77,13 @@
    4.50  
    4.51  
    4.52      def _arg_append(self, args, options):
    4.53 -        for arg in shlex.split(options)
    4.54 +        for arg in shlex.split(options):
    4.55              args.append(arg)
    4.56      # arg_append()
    4.57  
    4.58      def _setup_mencoder_opts(self, args):
    4.59          args.append(self.mencoder_path)
    4.60 -        args.append("-")
    4.61 +        args.append(self.args["input"])
    4.62  
    4.63          if self.args["language"]:
    4.64              self._arg_append(args, "-alang %s" % self.args["language"])
    4.65 @@ -88,8 +93,8 @@
    4.66              self._arg_append(args, "-subfps %s" % self.args["fps"])
    4.67  
    4.68          self._arg_append(args, "-idx")
    4.69 -        self._arg_append(args, self._setup_audio)
    4.70 -        self._arg_append(args, self._setup_video)
    4.71 +        self._arg_append(args, self._setup_audio())
    4.72 +        self._arg_append(args, self._setup_video())
    4.73  
    4.74          self._arg_append(args, "-really-quiet")
    4.75          self._arg_append(args, "-o %s" % self.args["outfile"])
    4.76 @@ -102,22 +107,17 @@
    4.77  
    4.78          if _type == "file":
    4.79              if not os.path.exists(self.args["input"]):
    4.80 -                raise IOError, "File requested does not exist."
    4.81 +                raise IOError,\
    4.82 +                      "File requested does not exist: %s." % self.args["input"]
    4.83  
    4.84          elif _type == "dvd":
    4.85              self.args["input"] = "dvd://".join(self.args["input"])
    4.86 -
    4.87 -        elif _type == "myth":
    4.88 -            self.args["input"] = "myth://".join(self.args["input"])
    4.89 -            self.gst_pipe = os.pipe()
    4.90      # _setup_filename()
    4.91  
    4.92  
    4.93      def __init__(self, params):
    4.94          server.Transcoder.__init__(self, params)
    4.95 -        self.proc = None
    4.96 -        self.args = None
    4.97 -        self.mencoder_opts = None
    4.98 +        self.mencoder_opts = []
    4.99  
   4.100          try:
   4.101              self._setup_params()
   4.102 @@ -125,34 +125,22 @@
   4.103              self._setup_mencoder_opts(self.mencoder_opts)
   4.104          except Exception, e:
   4.105              self.log.error(e)
   4.106 -            return False
   4.107 -
   4.108 -        return True
   4.109      # __init__()
   4.110  
   4.111  
   4.112      def start(self, outfd):
   4.113 -        cmd = " ".join(self.args)
   4.114 -        self.log.info("Mencoder: %s" % cmd)
   4.115 -
   4.116 -        if self.args["type"] == "file":
   4.117 -            _input = open(self.args["input"])
   4.118 +        cmd = " ".join(self.mencoder_opts)
   4.119 +        self.log.debug("Mencoder: %s" % cmd)
   4.120  
   4.121          try:
   4.122 -            self.proc = subprocess.Popen(self.args, close_fds=True)
   4.123 +            self.proc = subprocess.Popen(self.mencoder_opts, stdout=subprocess.PIPE, close_fds=True)
   4.124          except Exception, e:
   4.125 -            self.log.error("Error executing mencoder: %s" % cmd)
   4.126 -            return False
   4.127 -
   4.128 -        try:
   4.129 -            fifo_read = open(self.mencoder_outfile)
   4.130 -        except Exception, e:
   4.131 -            self.log.error("Error opening fifo: %s" % cmd)
   4.132 +            self.log.error("Error executing mencoder: %s" % e)
   4.133              return False
   4.134  
   4.135          try:
   4.136              while self.proc and self.proc.poll() == None:
   4.137 -                d = fifo_read.read(1024)
   4.138 +                d = self.proc.stdout.read(1024)
   4.139                  outfd.write(d)
   4.140          except Exception, e:
   4.141              self.log.error("Problems handling data: %s" % e)