# HG changeset patch
# User morphbr
# Date 1178307938 -3600
# Node ID c6af9d7a88b5a2d9083b808ceeeea26e4b67baa3
# Parent  73df1c7e30ecd0dede5c20edfee02585e70cb336
[svn r634] * GMyth-Streamer
	- Updated mencoder plugin
	- Updated server code

diff -r 73df1c7e30ec -r c6af9d7a88b5 gmyth-stream/server/0.2/lib/server.py
--- a/gmyth-stream/server/0.2/lib/server.py	Thu May 03 16:07:54 2007 +0100
+++ b/gmyth-stream/server/0.2/lib/server.py	Fri May 04 20:45:38 2007 +0100
@@ -114,7 +114,11 @@
         elif self.path == "/stream.do":
             self.serve_stream(body)
         else:
-            self.send_error(404, "File not found")
+            action = self.query.get("action", None)
+            if action is not None:
+                self.serve_stream(body)
+            else:
+                self.send_error(404, "File not found")
     # do_dispatch()
 
 
diff -r 73df1c7e30ec -r c6af9d7a88b5 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py
--- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu May 03 16:07:54 2007 +0100
+++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Fri May 04 20:45:38 2007 +0100
@@ -30,7 +30,7 @@
         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["format"]   = params_first("format", "mpeg1")
         self.args["outfile"]  = params_first("outfile", "-")
         self.args["sendback"] = params_first("sendback", True)
 
@@ -82,7 +82,8 @@
             video += " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s" % (
                 vcodec, self.args["vbitrate"])
 
-        video += " %s" % self.args["format"]
+        if self.args["mux"] == "mpeg":
+            video += " -mpegopts format=%s" % self.args["format"]
         video += " -vf scale=%s:%s" % (self.args["width"], self.args["height"])
 
         return video
@@ -110,7 +111,7 @@
             self._arg_append(args, "-subfps %s" % self.args["fps"])
 
         self._arg_append(args, "-idx")
-        self._arg_append(args, "-cache 500")
+        self._arg_append(args, "-cache 1024")
         self._arg_append(args, self._setup_audio())
         self._arg_append(args, self._setup_video())
 
@@ -207,6 +208,7 @@
 
         except Exception, e:
             self.log.error("Problems handling data: %s" % e)
+            self.stop()
             return False
 
         self.log.info("%s: Finished sending data to client" % repr(self))
@@ -243,7 +245,6 @@
 
         gmyth_cat = utils.which("gmyth-cat")
         opts = [gmyth_cat, "-h", host, "-p", port, "-" + kind, fchan]
-        gr, gw = os.pipe()
 
         try:
             self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE, close_fds=True)
@@ -254,12 +255,33 @@
         if not self._run_mencoder(input=self.gmyth.stdout, output=subprocess.PIPE):
             return False
 
+        show_loading = 0
+        show = True
+
+        #n800 150000 and 1000
+
         try:
             while self.proc and self.proc.poll() == None:
-                r, w, x = select([self.proc.stdout], [], [], 0)
+                r, w, x = select([self.proc.stdout], [outfd], [], 0)
                 if self.proc.stdout in r:
                     d = self.proc.stdout.read(4096)
                     outfd.write(d)
+                    self.log.debug("Sending tv data: %d" % show_loading)
+                    if show_loading > 150000 and show:
+                        self.log.debug("Disabling loading video")
+                        show = False
+
+                elif show_loading % 10000 == 0 and show:
+                    show_loading += 1
+                    d = open("loading.mpg")
+                    outfd.write(d.read())
+                    self.log.debug("Sendind loading video: %d" % show_loading)
+
+                else:
+                    show_loading += 1
+
+                #self.log.debug("SHOW_LOADING: %d" % show_loading)
+
         except Exception, e:
             self.log.error("Problems handling data: %s" % e)
             return False