1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gmyth-stream/plugins/media/vlc.py Tue Mar 27 20:27:51 2007 +0100
1.3 @@ -0,0 +1,99 @@
1.4 +'''
1.5 + # GMyth-Stream
1.6 + #
1.7 + # @file main.py
1.8 + #
1.9 + # @brief <p> Plugin for GMyth-Stream
1.10 + #
1.11 + # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
1.12 + # @author Artur Duque de Souza <artur.souza@indt.org.br>
1.13 + #
1.14 + #
1.15 + # This program is free software; you can redistribute it and/or modify
1.16 + # it under the terms of the GNU Lesser General Public License as published by
1.17 + # the Free Software Foundation; either version 2 of the License, or
1.18 + # (at your option) any later version.
1.19 + #
1.20 + # This program is distributed in the hope that it will be useful,
1.21 + # but WITHOUT ANY WARRANTY; without even the implied warranty of
1.22 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.23 + # GNU General Public License for more details.
1.24 + #
1.25 + # You should have received a copy of the GNU Lesser General Public License
1.26 + # along with this program; if not, write to the Free Software
1.27 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.28 + #
1.29 + '''
1.30 +
1.31 +import os
1.32 +import sys
1.33 +import time
1.34 +import socket
1.35 +import ConfigParser
1.36 +
1.37 +class Media:
1.38 +
1.39 + def __init__(self, config):
1.40 +
1.41 + self.config = config
1.42 + self.pipe = ""
1.43 + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1.44 +
1.45 + self.path = config.get("Vlc", "path")
1.46 + self.host = config.get("Vlc", "host")
1.47 + self.port = int(config.get("Vlc", "port"))
1.48 + self.pwd = config.get("Vlc", "pwd")
1.49 +
1.50 + # exec VLC
1.51 + pid = os.fork()
1.52 + if (pid == 0):
1.53 + #child
1.54 + print "ESTOU EM CHILD"
1.55 + self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
1.56 + os.system(self.path)
1.57 + sys.exit(0)
1.58 +
1.59 + print "ESTOU EM PARENT 1"
1.60 + time.sleep(3)
1.61 + print "ESTOU EM PARENT 2"
1.62 + self.sock.connect( (self.host, self.port) )
1.63 + self.sock.send("%s\n" % self.pwd)
1.64 +
1.65 +
1.66 + def insert_file(self, filename):
1.67 +
1.68 + self.sock.send("setup output0 input %s\n" % filename)
1.69 +
1.70 +
1.71 + def setup(self, filename, codec, bitrate, width, height, port):
1.72 +
1.73 + self.filename = filename
1.74 + self.codec = codec
1.75 + self.bitrate = int(bitrate)
1.76 + self.width = int(width)
1.77 + self.height = int(height)
1.78 + self.port = int(port)
1.79 +
1.80 + self.pipe = "#transcode{vcodec=%s,vb=%d,"\
1.81 + "fps=25.0,scale=1,acodec=mpga,"\
1.82 + "ab=64,channels=1,width=%d,height=%d}"\
1.83 + ":duplicate{dst=std{access=http,"\
1.84 + "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
1.85 + self.widht, self.height,\
1.86 + self.port)
1.87 +
1.88 + self.sock.send("setup output0 broadcast %s\n" % self.pipe)
1.89 + self.insert_file(self.filename)
1.90 +
1.91 + def play(self):
1.92 +
1.93 + print "Trying to play: %s" % self.pipe
1.94 + self.sock.send("control output0 play\n")
1.95 +
1.96 +
1.97 + def stop(self):
1.98 +
1.99 + print "Trying to stop: %s" % self.pipe
1.100 + self.sock.send("control output0 stop\n")
1.101 +
1.102 +