# HG changeset patch
# User morphbr
# Date 1176992028 -3600
# Node ID 644a526d408672bdd398af42798bbf657a8390aa
# Parent  f5ef83bbe8b5aa009deb5b6b9af24f12b5a45762
[svn r574] * GMyth-Streamer
	- Updated mencoder plugin (0.2)
	- Updated core engine (0.2)

diff -r f5ef83bbe8b5 -r 644a526d4086 gmyth-stream/client/src/gmyth-stream-client.c
--- a/gmyth-stream/client/src/gmyth-stream-client.c	Wed Apr 18 23:13:26 2007 +0100
+++ b/gmyth-stream/client/src/gmyth-stream-client.c	Thu Apr 19 15:13:48 2007 +0100
@@ -171,7 +171,8 @@
 
     close (priv->sock->fd);
     //shutdown (priv->sock->fd, SHUT_RDWR);
-    priv->sock->fd = -1;
+    g_free(priv->sock);
+    priv->sock = NULL;
     priv->connected = FALSE;
 }
 
diff -r f5ef83bbe8b5 -r 644a526d4086 gmyth-stream/server/0.2/lib/server.py
--- a/gmyth-stream/server/0.2/lib/server.py	Wed Apr 18 23:13:26 2007 +0100
+++ b/gmyth-stream/server/0.2/lib/server.py	Thu Apr 19 15:13:48 2007 +0100
@@ -138,9 +138,9 @@
         if body:
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server</title></head>
+   <head><title>GMyth-Streamer Server</title></head>
    <body>
-<h1>Welcome to Catota Server</h1>
+<h1>Welcome to GMyth-Streamer Server</h1>
 <ul>
 """)
             self._nav_items()
@@ -160,7 +160,7 @@
         if body:
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server</title></head>
+   <head><title>GMyth-Streamer Server</title></head>
    <body>
    <h1>Play</h1>
    <form action="/stream.do" method="GET">
@@ -186,9 +186,9 @@
         if body:
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server Exited</title></head>
+   <head><title>GMyth-Streamer Server Exited</title></head>
    <body>
-      <h1>Catota is not running anymore</h1>
+      <h1>GMyth-Streamer is not running anymore</h1>
    </body>
 </html>
 """)
@@ -205,9 +205,9 @@
             self.server.stop_transcoders()
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server Stopped Transcoders</title></head>
+   <head><title>GMyth-Streamer Server Stopped Transcoders</title></head>
    <body>
-      <h1>Catota stopped running transcoders</h1>
+      <h1>GMyth-Streamer stopped running transcoders</h1>
       <ul>
 """)
             self._nav_items()
@@ -227,9 +227,9 @@
         if body:
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server Stopped Transcoders</title></head>
+   <head><title>GMyth-Streamer Server Stopped Transcoders</title></head>
    <body>
-      <h1>Catota stopped running transcoders:</h1>
+      <h1>GMyth-Streamer stopped running transcoders:</h1>
       <ul>
     """)
             transcoders = self.server.get_transcoders()
@@ -246,7 +246,6 @@
                 for t, r in transcoders:
                     if r.client_address == addr:
                         t.stop()
-                        self.server.del_transcoders(self, t)
                         self.wfile.write("""\
          <li>%s: %s:%s</li>
 """ % (t, addr[0], addr[1]))
@@ -284,9 +283,9 @@
         if body:
             self.wfile.write("""\
 <html>
-   <head><title>Catota Server Status</title></head>
+   <head><title>GMyth-Streamer Server Status</title></head>
    <body>
-      <h1>Catota Status</h1>
+      <h1>GMyth-Streamer Status</h1>
 """)
             tl = self.server.get_transcoders()
             if not tl:
diff -r f5ef83bbe8b5 -r 644a526d4086 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py
--- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Wed Apr 18 23:13:26 2007 +0100
+++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu Apr 19 15:13:48 2007 +0100
@@ -8,76 +8,136 @@
 
 class TranscoderMencoder(server.Transcoder):
     mencoder_path = utils.which("mencoder")
-    def_mencoder_outfile = os.path.join(os.path.sep, "tmp",
-                                        "mencoder-fifo-%(uid)s-%(pid)s")
     name = "mencoder"
     priority = -1
 
+    def _setup_params(self):
+        params_first = self.params_first
+
+        # general_opts
+        self.args["local"]    = params_first("local", False)
+        self.args["language"] = params_first("language", False)
+        self.args["subtitle"] = params_first("subtitle", False)
+        self.args["format"]   = params_first("format", "")
+        self.args["outfile"]  = params_first("outfile", "-")
+
+        # input_opt
+        self.args["type"]     = params_first("type", "file")
+        self.args["input"]    = params_first("input", "-")
+
+        # audio_opts
+        self.args["acodec"]   = params_first("acodec", "mp2")
+        self.args["abitrate"] = params_first("abitrate", 192)
+        self.args["volume"]   = params_first("volume", 5)
+
+        # video_opts
+        self.args["mux"]      = params_first("mux", "mpeg")
+        self.args["fps"]      = params_first("fps", 25)
+        self.args["vcodec"]   = params_first("vcodec", "mpeg1video")
+        self.args["vbitrate"] = params_first("vbitrate", 400)
+        self.args["width"]    = params_first("width", 320)
+        self.args["height"]   = params_first("height", 240)
+    # _setup_params()
+
+
+    def _setup_audio(self):
+        if self.args["acodec"] == "mp3lame":
+            audio = "-oac mp3lame -lameopts cbr:br=%s vol=%s" % (
+                self.args["abitrate"], self.args["volume"])
+        else:
+            audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (
+                self.args["acodec"], self.args["abitrate"])
+
+        return audio
+    # _setup_audio()
+
+
+    def _setup_video(self):
+        video = " -of %s" % self.mux
+        video += " -ofps %s" % self.fps
+
+        vcodec = self.args["vcodec"]
+        if vcodec == "nuv" or vcodec == "xvid"\
+               or vcodec == "qtvideo" or vcodec == "copy":
+            video += " -ovc %s" % vcodec
+        else:
+            video += " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s" % (
+                vcodec, self.args["vbitrate"])
+
+        video += " %s" % self.args["format"]
+        video += " -vf scale=%s:%s" % (self.args["width"], self.args["height"])
+
+        return video
+    # _setup_video()
+
+
+    def _arg_append(self, args, 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("-")
+
+        if self.args["language"]:
+            self._arg_append(args, "-alang %s" % self.args["language"])
+
+        if self.args["subtitle"]:
+            self._arg_append(args, "-slang %s" % self.args["subtitle"])
+            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, "-really-quiet")
+        self._arg_append(args, "-o %s" % self.args["outfile"])
+        self._arg_append(args, "2> %s" % os.devnull)
+    # _setup_args()
+
+
+    def _setup_filename(self):
+        _type = self.args["type"]
+
+        if _type == "file":
+            if not os.path.exists(self.args["input"]):
+                raise IOError, "File requested does not exist."
+
+        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
 
-        vars = {"uid": os.getuid(), "pid": os.getpid()}
-        mencoder_outfile_base = self.def_mencoder_outfile % vars
-        mencoder_outfile = mencoder_outfile_base
-        i = 0
-        while os.path.exists(mencoder_outfile):
-            i += 1
-            mencoder_outfile = mencoder_outfile_base + ".%s" % i
+        try:
+            self._setup_params()
+            self._setup_filename()
+            self._setup_mencoder_opts(self.mencoder_opts)
+        except Exception, e:
+            self.log.error(e)
+            return False
 
-        self.mencoder_outfile = mencoder_outfile
-        os.mkfifo(self.mencoder_outfile)
-
-        args = [self.mencoder_path, "-really-quiet",
-                "-o", self.mencoder_outfile]
-
-        params_first = self.params_first
-
-        type = params_first("type")
-        location = params_first("location")
-        args.append("%s://%s" % (type, location))
-
-        mux = params_first("mux", "avi")
-        args.extend(["-of", mux])
-
-        acodec = params_first("acodec", "mp3")
-        abitrate = params_first("abitrate", "128")
-        if acodec == "mp3lame":
-            args.extend(["-oac", "mp3lame", "-lameopts",
-                         "cbr:br=%s" % abitrate])
-        else:
-            args.extend(["-oac", "lavc", "-lavcopts",
-                         "acodec=%s:abitrate=%s" % (acodec, abitrate)])
-
-        vcodec = params_first("vcodec", "mpeg4")
-        vbitrate = params_first("vbitrate", "400")
-        args.extend(["-ovc", "lavc", "-lavcopts",
-                     "vcodec=%s:vbitrate=%s" % (vcodec, vbitrate)])
-
-        fps = params_first("fps", "24")
-        args.extend(["-ofps", fps])
-
-        width = params_first("width", "320")
-        height = params_first("height", "240")
-        args.extend(["-vf", "scale=%s:%s" % (width, height)])
-
-        self.args = args
+        return True
     # __init__()
 
 
-    def _unlink_fifo(self):
-        try:
-            os.unlink(self.mencoder_outfile)
-        except Exception, e:
-            pass
-    # _unlink_fifo()
-
-
     def start(self, outfd):
         cmd = " ".join(self.args)
         self.log.info("Mencoder: %s" % cmd)
 
+        if self.args["type"] == "file":
+            _input = open(self.args["input"])
+
         try:
             self.proc = subprocess.Popen(self.args, close_fds=True)
         except Exception, e:
@@ -96,10 +156,8 @@
                 outfd.write(d)
         except Exception, e:
             self.log.error("Problems handling data: %s" % e)
-            self._unlink_fifo()
             return False
 
-        self._unlink_fifo()
         return True
     # start()
 
@@ -117,7 +175,6 @@
                 pass
 
             self.proc = None
+    # stop()
 
-        self._unlink_fifo()
-    # stop()
 # TranscoderMencoder