[svn r480] * GMyth-Stream: trunk
authormorphbr
Sun Apr 01 03:11:01 2007 +0100 (2007-04-01)
branchtrunk
changeset 4752521ec986005
parent 474 07c12d2ceddf
child 476 f9330272e09d
[svn r480] * GMyth-Stream:
- Support for dvds
- Support regarding playing the file locally
gmyth-stream/main.py
gmyth-stream/plugins/media/mencoder.py
     1.1 --- a/gmyth-stream/main.py	Sat Mar 31 00:55:28 2007 +0100
     1.2 +++ b/gmyth-stream/main.py	Sun Apr 01 03:11:01 2007 +0100
     1.3 @@ -33,19 +33,30 @@
     1.4  
     1.5          if (msg == "SETUP"):
     1.6              setup = server.getMsg(1024).strip().split(" ")
     1.7 -            if ( len(setup) == 10 ):
     1.8 +            size = len(setup)
     1.9 +            options = []
    1.10 +
    1.11 +            if ( size < 10 ):
    1.12 +                server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
    1.13 +
    1.14 +            else:
    1.15 +
    1.16 +                if ( size > 10 ):
    1.17 +                    i = 10
    1.18 +                    while (i < size):
    1.19 +                        options.append(setup[i])
    1.20 +                        i += 1
    1.21 +
    1.22                  ret = media.setup(setup[0], setup[1], setup[2], \
    1.23                                    setup[3], setup[4], setup[5],
    1.24                                    setup[6], setup[7], setup[8],
    1.25 -                                  setup[9])
    1.26 +                                  setup[9], options)
    1.27  
    1.28                  if (ret == 0):
    1.29                      server.Ack("SETUP")
    1.30                  else:
    1.31 -                    server.sendMsg(lib.log("File does not exist: %s" % setup[0]))
    1.32 +                    server.sendMsg(lib.log(ret))
    1.33  
    1.34 -            else:
    1.35 -                server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
    1.36  
    1.37          elif (msg == "PLAY"):
    1.38              media.play()
     2.1 --- a/gmyth-stream/plugins/media/mencoder.py	Sat Mar 31 00:55:28 2007 +0100
     2.2 +++ b/gmyth-stream/plugins/media/mencoder.py	Sun Apr 01 03:11:01 2007 +0100
     2.3 @@ -12,47 +12,71 @@
     2.4          self.config = config
     2.5          self.socket = None
     2.6          self.child_pid = None
     2.7 +        self.mplayer = None
     2.8 +
     2.9 +    def set_args(self, options):
    2.10 +
    2.11 +        for opt in options:
    2.12 +
    2.13 +            if (opt == "file"):
    2.14 +                self.kind = "file"
    2.15 +                self.args += " %s -mf fps=%d -of %s -oac %s -lameopts vol=5 cbr:br=%d"\
    2.16 +                             " -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
    2.17 +                             " -o %s 1> /dev/null 2> /dev/null" % (
    2.18 +                    self.filename, self.fps, self.mux, self.acodec, self.abitrate,
    2.19 +                    self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
    2.20 +
    2.21 +            elif (opt == "dvd"):
    2.22 +                self.kind = "dvd"
    2.23 +                self.args += " dvd://%s -vf scale=%d:%d -oac %s -lameopts vol=5 cbr:br=%d"\
    2.24 +                             " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -o %s"\
    2.25 +                             " -mf fps=%d 1> /dev/null 2> /dev/null" % (
    2.26 +                    self.filename, self.width, self.height, self.acodec, self.abitrate,
    2.27 +                    self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps)
    2.28 +
    2.29 +            elif (opt == "local"):
    2.30 +                self.mplayer = os.popen("which mplayer").read().strip()
    2.31  
    2.32      def setup(self, filename, mux, vcodec, vbitrate,\
    2.33 -              fps, acodec, abitrate, width, height, port):
    2.34 +              fps, acodec, abitrate, width, height, port, options):
    2.35  
    2.36 -        if (os.path.exists(filename)):
    2.37 +        self.filename = filename
    2.38 +        self.mux = mux
    2.39 +        self.vcodec = vcodec
    2.40 +        self.vbitrate = int(vbitrate)
    2.41 +        self.fps = int(fps)
    2.42 +        self.acodec = acodec
    2.43 +        self.abitrate = int(abitrate)
    2.44 +        self.width = int(width)
    2.45 +        self.height = int(height)
    2.46  
    2.47 -            self.filename = filename
    2.48 -            self.mux = mux
    2.49 -            self.vcodec = vcodec
    2.50 -            self.vbitrate = int(vbitrate)
    2.51 -            self.fps = int(fps)
    2.52 -            self.acodec = acodec
    2.53 -            self.abitrate = int(abitrate)
    2.54 -            self.width = int(width)
    2.55 -            self.height = int(height)
    2.56 +        self.port = int(port)
    2.57 +        self.fifo = self.config.get("Mencoder", "fifo_path")
    2.58  
    2.59 -            self.port = int(port)
    2.60 -            self.fifo = self.config.get("Mencoder", "fifo_path")
    2.61 +        self.args = ""
    2.62 +        self.kind = ""
    2.63 +        self.set_args(options)
    2.64  
    2.65 -            # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
    2.66 -            self.path = self.config.get("Mencoder", "path")
    2.67 -            self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
    2.68 -                         " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
    2.69 -                         " -o %s 1> /dev/null 2> /dev/null" % (
    2.70 -                self.filename, self.fps, self.mux, self.acodec, self.abitrate,
    2.71 -                self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
    2.72 +        if (self.kind == "file" and not os.path.exists(self.filename)):
    2.73 +            msg = "File requested does not exist. SETUP failed."
    2.74 +            lib.log(msg)
    2.75 +            return msg
    2.76  
    2.77 +        # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
    2.78 +        #mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
    2.79 +        self.path = self.config.get("Mencoder", "path")
    2.80 +        self.path += self.args
    2.81  
    2.82 -            if (self.socket != None):
    2.83 -                del(self.socket)
    2.84 +        if (self.socket != None):
    2.85 +            del(self.socket)
    2.86  
    2.87 -            self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    2.88 -            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    2.89 -            self.socket.bind( ('', self.port) )
    2.90 -            self.socket.listen(1)
    2.91 +        self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    2.92 +        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    2.93 +        self.socket.bind( ('', self.port) )
    2.94 +        self.socket.listen(1)
    2.95  
    2.96 -            return 0
    2.97 +        return 0
    2.98  
    2.99 -        else:
   2.100 -            lib.log("File requested does not exist. SETUP failed.")
   2.101 -            return -1
   2.102  
   2.103      def play(self):
   2.104  
   2.105 @@ -69,6 +93,7 @@
   2.106          fifo = open(self.fifo)
   2.107  
   2.108          self.child_pid = os.fork()
   2.109 +
   2.110          if (self.child_pid == 0):
   2.111              conn,addr= self.socket.accept()
   2.112              lib.log("Sending Data to client: %s" % addr[0])
   2.113 @@ -77,6 +102,14 @@
   2.114              conn.settimeout(5)
   2.115              retry = 0
   2.116  
   2.117 +            if (self.mplayer):
   2.118 +                msg = "%s 1>/dev/null 2>/dev/null" % self.filename
   2.119 +                if (self.kind == "dvd"):
   2.120 +                    msg = "dvd://" + msg
   2.121 +
   2.122 +                self.mplayer += " " + msg
   2.123 +                mplayer_in, self.mplayer_out = os.popen2(self.mplayer)
   2.124 +
   2.125              while( data != "" and retry < 5):
   2.126                  try:
   2.127                      conn.send(data)
   2.128 @@ -93,8 +126,13 @@
   2.129  
   2.130  
   2.131      def stop(self):
   2.132 +        try:
   2.133 +            self.pout.close()
   2.134 +            self.mplayer_out.close()
   2.135 +        except:
   2.136 +            lib.log("Trying to stop before playing...")
   2.137  
   2.138 -        self.pout.close()
   2.139 +        self.mplayer = None
   2.140  
   2.141          if (self.socket != None):
   2.142              lib.log("Closing socket")