<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import os
import sys
import time
import socket
import ConfigParser

class Media:

    def __init__(self, config):

        self.config = config
        self.pipe = ""
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.path = config.get("Vlc", "path")
        self.host = config.get("Vlc", "host")
        self.port = int(config.get("Vlc", "port"))
        self.pwd = config.get("Vlc", "pwd")

        # exec VLC
        pid = os.fork()
        if (pid == 0):
            #child
            print "ESTOU EM CHILD"
            self.path += " -I telnet -d 1&gt; /dev/null 2&gt; /dev/null &amp;"
            os.system(self.path)
            sys.exit(0)
        else:
            print "ESTOU EM PARENT 1"
            time.sleep(3)
            print "ESTOU EM PARENT 2"
            self.sock.connect( (self.host, self.port) )
            self.sock.send("%s\n" % self.pwd)


    def insert_file(self, filename):

        self.sock.send("setup output0 input %s\n" % filename)



    def setup(self, filename, mux, vcodec, vbitrate,\
              fps, acodec, abitrate, width, height, port):

        self.filename = filename
        self.mux = mux
        self.vcodec = vcodec
        self.vbitrate = int(vbitrate)
        self.fps = int(fps)
        self.acodec = acodec
        self.abitrate = int(abitrate)
        self.width = int(width)
        self.height = int(height)

        self.port = int(port)


        self.pipe = "#transcode{vcodec=%s,vb=%d,"\
                    "fps=25.0,scale=1,acodec=mpga,"\
                    "ab=64,channels=1,width=%d,height=%d}"\
                    ":duplicate{dst=std{access=http,"\
                    "mux=mpeg1,dst=:%d}}" % (self.vcodec, self.vbitrate,\
                                             self.widht, self.height,\
                                             self.port)

        self.sock.send("setup output0 broadcast %s\n" % self.pipe)
        self.insert_file(self.filename)

    def play(self):

        print "Trying to play: %s" % self.pipe
        self.sock.send("control output0 play\n")


    def stop(self):

        print "Trying to stop: %s" % self.pipe
        self.sock.send("control output0 stop\n")


</pre></body></html>