[svn r504] Gmyth-Streamer: mencoder stdout bug fix (Chenca's bug) trunk
authormorphbr
Wed Apr 04 21:18:43 2007 +0100 (2007-04-04)
branchtrunk
changeset 4999900800a8dd6
parent 498 7a0c3906dce2
child 500 f92a59c9a9a5
[svn r504] Gmyth-Streamer: mencoder stdout bug fix (Chenca's bug)
gmyth-stream/server/plugins/comm/tcp.py
gmyth-stream/server/plugins/media/mencoder.py
gmyth-stream/server/stream.conf
     1.1 --- a/gmyth-stream/server/plugins/comm/tcp.py	Wed Apr 04 18:05:44 2007 +0100
     1.2 +++ b/gmyth-stream/server/plugins/comm/tcp.py	Wed Apr 04 21:18:43 2007 +0100
     1.3 @@ -2,7 +2,7 @@
     1.4  import time
     1.5  import socket
     1.6  
     1.7 -class Server:
     1.8 +class Server(object):
     1.9  
    1.10      def __init__(self, config):
    1.11          self.host = ''
     2.1 --- a/gmyth-stream/server/plugins/media/mencoder.py	Wed Apr 04 18:05:44 2007 +0100
     2.2 +++ b/gmyth-stream/server/plugins/media/mencoder.py	Wed Apr 04 21:18:43 2007 +0100
     2.3 @@ -46,17 +46,17 @@
     2.4                  self.kind = "file"
     2.5                  self.args += " %s -mf fps=%s -of %s %s"\
     2.6                               " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\
     2.7 -                             " -o %s 1> /dev/null 2> /dev/null" % (
     2.8 +                             " -really-quiet -o %s" % (
     2.9                      self.filename, self.fps, self.mux, audio, self.vcodec,
    2.10                      self.vbitrate, self.width, self.height, self.fifo)
    2.11  
    2.12              elif opt == "dvd":
    2.13                  self.kind = "dvd"
    2.14                  self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\
    2.15 -                             " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -o %s"\
    2.16 -                             " -ofps %s 1> /dev/null 2> /dev/null" % (
    2.17 +                             " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\
    2.18 +                             " -ofps %s -really-quiet -o %s" % (
    2.19                      self.filename, self.language, self.width, self.height, audio,
    2.20 -                    self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps)
    2.21 +                    self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo)
    2.22  
    2.23              elif opt == "local":
    2.24                  self.mplayer = os.popen("which mplayer").read().strip()
    2.25 @@ -97,7 +97,21 @@
    2.26          self.height = height
    2.27  
    2.28          self.port = int(port)
    2.29 -        self.fifo = self.config.get("Mencoder", "fifo_path")
    2.30 +
    2.31 +        self.path = self.config.get("Mencoder", "path")
    2.32 +        a, b = os.popen2(self.path)
    2.33 +        version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1]
    2.34 +
    2.35 +        if version > "4.1.1": self.mencoder_old = False
    2.36 +        else: self.mencoder_old = True
    2.37 +
    2.38 +        a.close()
    2.39 +        b.close()
    2.40 +
    2.41 +        if self.mencoder_old:
    2.42 +            self.fifo = self.config.get("Mencoder", "fifo_path")
    2.43 +        else:
    2.44 +            self.fifo = "-"
    2.45  
    2.46          self.args = ""
    2.47          self.kind = ""
    2.48 @@ -110,8 +124,6 @@
    2.49  
    2.50          # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file
    2.51          #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd
    2.52 -        self.path = self.config.get("Mencoder", "path")
    2.53 -
    2.54          if self.socket != None:
    2.55              del(self.socket)
    2.56  
    2.57 @@ -125,16 +137,21 @@
    2.58  
    2.59      def play(self):
    2.60  
    2.61 -        try:
    2.62 -            os.mkfifo(self.fifo)
    2.63 -        except:
    2.64 -            lib.log("Fifo already exists")
    2.65 +        if self.mencoder_old:
    2.66 +            try:
    2.67 +                os.mkfifo(self.fifo)
    2.68 +            except:
    2.69 +                lib.log("Fifo already exists")
    2.70 +
    2.71  
    2.72          lib.log("Starting Mencoder: %s %s" % (self.path, self.args) )
    2.73          # exec Mencoder
    2.74 -        self.mencoder_pid = Popen(self.path + self.args, shell=True)
    2.75 -
    2.76 -        fifo = open(self.fifo)
    2.77 +        if self.mencoder_old:
    2.78 +            self.mencoder_pid = Popen(self.path + self.args, shell=True)
    2.79 +            fifo = open(self.fifo)
    2.80 +        else:
    2.81 +            self.path += self.args
    2.82 +            pin, self.pout = os.popen2(self.path)
    2.83  
    2.84          self.child_pid = os.fork()
    2.85  
    2.86 @@ -142,7 +159,8 @@
    2.87              conn,addr= self.socket.accept()
    2.88              lib.log("Sending Data to client: %s" % addr[0])
    2.89  
    2.90 -            data = fifo.read(1024)
    2.91 +            data = self.pout.read(1024)
    2.92 +
    2.93              conn.settimeout(5)
    2.94              retry = 0
    2.95  
    2.96 @@ -159,7 +177,7 @@
    2.97                      lib.log("Socket error (maybe timeout ?)")
    2.98                      retry += 1
    2.99  
   2.100 -                data = fifo.read(1024)
   2.101 +                data = self.pout.read(1024)
   2.102  
   2.103              if retry < 5:
   2.104                  lib.log("Finished sending Data to client: %s" % addr[0])
   2.105 @@ -171,7 +189,10 @@
   2.106  
   2.107      def stop(self):
   2.108          try:
   2.109 -            os.kill(self.mencoder_pid.pid + 1, signal.SIGKILL)
   2.110 +            if self.mplayer_old:
   2.111 +                os.kill(self.mencoder_pid.pid + 1, signal.SIGKILL)
   2.112 +            else:
   2.113 +                self.pout.close()
   2.114              self.mplayer = None
   2.115          except:
   2.116              lib.log("Trying to stop before playing...")
     3.1 --- a/gmyth-stream/server/stream.conf	Wed Apr 04 18:05:44 2007 +0100
     3.2 +++ b/gmyth-stream/server/stream.conf	Wed Apr 04 21:18:43 2007 +0100
     3.3 @@ -19,5 +19,5 @@
     3.4  
     3.5  
     3.6  [Mencoder]
     3.7 -path = /usr/local/bin/mencoder
     3.8 +path = /usr/bin/mencoder
     3.9  fifo_path = /tmp/teste