renatofilho@484: import os
renatofilho@484: import sys
renatofilho@484: import time
renatofilho@484: import socket
renatofilho@484: import ConfigParser
renatofilho@484: 
renatofilho@484: class Media:
renatofilho@484: 
renatofilho@484:     def __init__(self, config):
renatofilho@484: 
renatofilho@484:         self.config = config
renatofilho@484:         self.pipe = ""
renatofilho@484:         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
renatofilho@484: 
renatofilho@484:         self.path = config.get("Vlc", "path")
renatofilho@484:         self.host = config.get("Vlc", "host")
renatofilho@484:         self.port = int(config.get("Vlc", "port"))
renatofilho@484:         self.pwd = config.get("Vlc", "pwd")
renatofilho@484: 
renatofilho@484:         # exec VLC
renatofilho@484:         pid = os.fork()
renatofilho@484:         if (pid == 0):
renatofilho@484:             #child
renatofilho@484:             print "ESTOU EM CHILD"
renatofilho@484:             self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
renatofilho@484:             os.system(self.path)
renatofilho@484:             sys.exit(0)
renatofilho@484:         else:
renatofilho@484:             print "ESTOU EM PARENT 1"
renatofilho@484:             time.sleep(3)
renatofilho@484:             print "ESTOU EM PARENT 2"
renatofilho@484:             self.sock.connect( (self.host, self.port) )
renatofilho@484:             self.sock.send("%s\n" % self.pwd)
renatofilho@484: 
renatofilho@484: 
renatofilho@484:     def insert_file(self, filename):
renatofilho@484: 
renatofilho@484:         self.sock.send("setup output0 input %s\n" % filename)
renatofilho@484: 
renatofilho@484: 
renatofilho@484: 
renatofilho@484:     def setup(self, filename, mux, vcodec, vbitrate,\
renatofilho@484:               fps, acodec, abitrate, width, height, port):
renatofilho@484: 
renatofilho@484:         self.filename = filename
renatofilho@484:         self.mux = mux
renatofilho@484:         self.vcodec = vcodec
renatofilho@484:         self.vbitrate = int(vbitrate)
renatofilho@484:         self.fps = int(fps)
renatofilho@484:         self.acodec = acodec
renatofilho@484:         self.abitrate = int(abitrate)
renatofilho@484:         self.width = int(width)
renatofilho@484:         self.height = int(height)
renatofilho@484: 
renatofilho@484:         self.port = int(port)
renatofilho@484: 
renatofilho@484: 
renatofilho@484:         self.pipe = "#transcode{vcodec=%s,vb=%d,"\
renatofilho@484:                     "fps=25.0,scale=1,acodec=mpga,"\
renatofilho@484:                     "ab=64,channels=1,width=%d,height=%d}"\
renatofilho@484:                     ":duplicate{dst=std{access=http,"\
renatofilho@484:                     "mux=mpeg1,dst=:%d}}" % (self.vcodec, self.vbitrate,\
renatofilho@484:                                              self.widht, self.height,\
renatofilho@484:                                              self.port)
renatofilho@484: 
renatofilho@484:         self.sock.send("setup output0 broadcast %s\n" % self.pipe)
renatofilho@484:         self.insert_file(self.filename)
renatofilho@484: 
renatofilho@484:     def play(self):
renatofilho@484: 
renatofilho@484:         print "Trying to play: %s" % self.pipe
renatofilho@484:         self.sock.send("control output0 play\n")
renatofilho@484: 
renatofilho@484: 
renatofilho@484:     def stop(self):
renatofilho@484: 
renatofilho@484:         print "Trying to stop: %s" % self.pipe
renatofilho@484:         self.sock.send("control output0 stop\n")
renatofilho@484: 
renatofilho@484: