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