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