[svn r519] Gmyth-Streamer: Mencoder update trunk
authormorphbr
Mon Apr 09 16:22:37 2007 +0100 (2007-04-09)
branchtrunk
changeset 514b5352888e3c2
parent 513 12a61040588d
child 515 18f08fa8e216
[svn r519] Gmyth-Streamer: Mencoder update
gmyth-stream/server/main.py
gmyth-stream/server/plugins/media/mencoder.py
     1.1 --- a/gmyth-stream/server/main.py	Mon Apr 09 15:20:37 2007 +0100
     1.2 +++ b/gmyth-stream/server/main.py	Mon Apr 09 16:22:37 2007 +0100
     1.3 @@ -71,7 +71,7 @@
     1.4      nextport += 1
     1.5      ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec,
     1.6                        abitrate, width, height, nextport, options)
     1.7 -    if ret == 0:
     1.8 +    if ret == True:
     1.9          server.sendOk()
    1.10      else:
    1.11          server.sendNotOk(ret)
     2.1 --- a/gmyth-stream/server/plugins/media/mencoder.py	Mon Apr 09 15:20:37 2007 +0100
     2.2 +++ b/gmyth-stream/server/plugins/media/mencoder.py	Mon Apr 09 16:22:37 2007 +0100
     2.3 @@ -23,12 +23,17 @@
     2.4          self.mplayer_pid = None
     2.5          signal.signal(signal.SIGABRT, self.kill_handler)
     2.6  
     2.7 +    # __init__
     2.8 +
     2.9      def kill_handler(self, sig, frame):
    2.10          try:
    2.11 -            os.kill(self.mplayer_pid.pid + 1, signal.SIGKILL)
    2.12 +            os.kill(self.mplayer_pid.pid, signal.SIGKILL)
    2.13 +            log.debug("Killed Mplayer")
    2.14              sys.exit(0)
    2.15          except:
    2.16 -            lib.log("Problems closing child")
    2.17 +            log.error("Problems closing child")
    2.18 +
    2.19 +    # kill_handler
    2.20  
    2.21      def set_args(self, options):
    2.22  
    2.23 @@ -41,58 +46,67 @@
    2.24                  try:
    2.25                      self.language = opt.split("=")[1]
    2.26                  except:
    2.27 -                    lib.log("Bad language option")
    2.28 +                    log.error("Bad language option")
    2.29  
    2.30              elif opt.find("format=") >= 0:
    2.31                  try:
    2.32                      self.mux += " -mpegopts format=%s" % opt.split("=")[1]
    2.33                  except:
    2.34 -                    lib.log("Bad format option")
    2.35 +                    log.error("Bad format option")
    2.36  
    2.37 +    # set_args
    2.38  
    2.39      def run_mplayer(self):
    2.40 -        msg = "%s 1>/dev/null 2>/dev/null" % self.filename
    2.41 +        msg = self.filename
    2.42  
    2.43          if self.kind == "dvd":
    2.44              msg = "dvd://" + msg
    2.45  
    2.46 -        self.mplayer += " " + msg
    2.47 -        self.mplayer_pid = Popen(self.mplayer, shell=True, close_fds=True)
    2.48 +        self.mplayer_pid = Popen([self.mplayer, self.filename, "1> %s" % os.devnull,\
    2.49 +                                  "2> %s" % os.devnull], stdout=PIPE, close_fds=True)
    2.50 +
    2.51 +    # run_mplayer
    2.52 +
    2.53  
    2.54      def setup_mencoder(self):
    2.55          self.path = self.config.get("Mencoder", "path")
    2.56 -        a, b = os.popen2(self.path)
    2.57 -        version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1]
    2.58 +        mp = Popen([self.path], stdout=PIPE, close_fds=True)
    2.59 +
    2.60 +        version = mp.stdout.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1]
    2.61  
    2.62          if version > "4.1.1": self.mencoder_old = False
    2.63          else: self.mencoder_old = True
    2.64  
    2.65 -        lib.log("Mencoder version: %s" % version)
    2.66 -
    2.67 -        a.close()
    2.68 -        b.close()
    2.69 +        os.kill(mp.pid, signal.SIGKILL)
    2.70 +        log.info("Mencoder version: %s" % version)
    2.71  
    2.72          if self.mencoder_old:
    2.73              self.fifo = self.config.get("Mencoder", "fifo_path")
    2.74          else:
    2.75              self.fifo = "-"
    2.76  
    2.77 +    # setup_mencoder
    2.78 +
    2.79 +    def setup_audio(self, acodec):
    2.80 +
    2.81 +        if acodec == "mp3lame":
    2.82 +            return "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate
    2.83 +        else:
    2.84 +            return = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\
    2.85 +                self.acodec, self.abitrate)
    2.86 +
    2.87      def setup_filename(self, filename):
    2.88          try:
    2.89              self.kind, self.filename = filename.split("://")
    2.90          except:
    2.91              return (False, "Wrong filename protocol")
    2.92  
    2.93 -        if self.acodec == "mp3lame":
    2.94 -            audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate
    2.95 -        else:
    2.96 -            audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\
    2.97 -                    self.acodec, self.abitrate)
    2.98 +        audio = setup_audio(self.acodec)
    2.99  
   2.100          if self.kind == "file":
   2.101              if not os.path.exists(self.filename):
   2.102                  msg = "File requested does not exist. SETUP failed."
   2.103 -                lib.log(msg)
   2.104 +                log.error(msg)
   2.105                  return (False, msg)
   2.106  
   2.107              self.args += " %s -mf fps=%s -of %s %s"\
   2.108 @@ -110,6 +124,24 @@
   2.109  
   2.110          return (True, "")
   2.111  
   2.112 +    # setup_filename
   2.113 +
   2.114 +    def setup_socket(self, socket):
   2.115 +        if socket != None:
   2.116 +            del(socket)
   2.117 +
   2.118 +        socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   2.119 +        socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
   2.120 +
   2.121 +        try:
   2.122 +            socket.bind( ('', self.port) )
   2.123 +            socket.listen(1)
   2.124 +        except Exception, e:
   2.125 +            log.error("Could not create socket: %s" % e)
   2.126 +            return (False, e)
   2.127 +
   2.128 +        return (True, "")
   2.129 +
   2.130      '''
   2.131      MENCODER SETUP DESCRIPTION
   2.132      ===========================
   2.133 @@ -146,16 +178,14 @@
   2.134          # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file
   2.135          # /tmp/dvb.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 format=mpeg1 file
   2.136          #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd
   2.137 -        if self.socket != None:
   2.138 -            del(self.socket)
   2.139 +        ret_val = setup_socket(self.socket)
   2.140  
   2.141 -        self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   2.142 -        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
   2.143 -        self.socket.bind( ('', self.port) )
   2.144 -        self.socket.listen(1)
   2.145 +        if not ret_val[0]:
   2.146 +            return ret_val[1]
   2.147  
   2.148 -        return 0
   2.149 +        return True
   2.150  
   2.151 +    # setup
   2.152  
   2.153      def play(self):
   2.154