gmyth-stream/server/0.1/plugins/media/vlc.py
author melunko
Wed May 16 13:35:11 2007 +0100 (2007-05-16)
branchtrunk
changeset 663 338476853df3
permissions -rw-r--r--
[svn r669] If local hostname is not found, we consider it as a default string
morphbr@565
     1
import os
morphbr@565
     2
import sys
morphbr@565
     3
import time
morphbr@565
     4
import socket
morphbr@565
     5
import ConfigParser
morphbr@565
     6
morphbr@565
     7
class Media:
morphbr@565
     8
morphbr@565
     9
    def __init__(self, config):
morphbr@565
    10
morphbr@565
    11
        self.config = config
morphbr@565
    12
        self.pipe = ""
morphbr@565
    13
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
morphbr@565
    14
morphbr@565
    15
        self.path = config.get("Vlc", "path")
morphbr@565
    16
        self.host = config.get("Vlc", "host")
morphbr@565
    17
        self.port = int(config.get("Vlc", "port"))
morphbr@565
    18
        self.pwd = config.get("Vlc", "pwd")
morphbr@565
    19
morphbr@565
    20
        # exec VLC
morphbr@565
    21
        pid = os.fork()
morphbr@565
    22
        if (pid == 0):
morphbr@565
    23
            #child
morphbr@565
    24
            print "ESTOU EM CHILD"
morphbr@565
    25
            self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
morphbr@565
    26
            os.system(self.path)
morphbr@565
    27
            sys.exit(0)
morphbr@565
    28
        else:
morphbr@565
    29
            print "ESTOU EM PARENT 1"
morphbr@565
    30
            time.sleep(3)
morphbr@565
    31
            print "ESTOU EM PARENT 2"
morphbr@565
    32
            self.sock.connect( (self.host, self.port) )
morphbr@565
    33
            self.sock.send("%s\n" % self.pwd)
morphbr@565
    34
morphbr@565
    35
morphbr@565
    36
    def insert_file(self, filename):
morphbr@565
    37
morphbr@565
    38
        self.sock.send("setup output0 input %s\n" % filename)
morphbr@565
    39
morphbr@565
    40
morphbr@565
    41
morphbr@565
    42
    def setup(self, filename, mux, vcodec, vbitrate,\
morphbr@565
    43
              fps, acodec, abitrate, width, height, port):
morphbr@565
    44
morphbr@565
    45
        self.filename = filename
morphbr@565
    46
        self.mux = mux
morphbr@565
    47
        self.vcodec = vcodec
morphbr@565
    48
        self.vbitrate = int(vbitrate)
morphbr@565
    49
        self.fps = int(fps)
morphbr@565
    50
        self.acodec = acodec
morphbr@565
    51
        self.abitrate = int(abitrate)
morphbr@565
    52
        self.width = int(width)
morphbr@565
    53
        self.height = int(height)
morphbr@565
    54
morphbr@565
    55
        self.port = int(port)
morphbr@565
    56
morphbr@565
    57
morphbr@565
    58
        self.pipe = "#transcode{vcodec=%s,vb=%d,"\
morphbr@565
    59
                    "fps=25.0,scale=1,acodec=mpga,"\
morphbr@565
    60
                    "ab=64,channels=1,width=%d,height=%d}"\
morphbr@565
    61
                    ":duplicate{dst=std{access=http,"\
morphbr@565
    62
                    "mux=mpeg1,dst=:%d}}" % (self.vcodec, self.vbitrate,\
morphbr@565
    63
                                             self.widht, self.height,\
morphbr@565
    64
                                             self.port)
morphbr@565
    65
morphbr@565
    66
        self.sock.send("setup output0 broadcast %s\n" % self.pipe)
morphbr@565
    67
        self.insert_file(self.filename)
morphbr@565
    68
morphbr@565
    69
    def play(self):
morphbr@565
    70
morphbr@565
    71
        print "Trying to play: %s" % self.pipe
morphbr@565
    72
        self.sock.send("control output0 play\n")
morphbr@565
    73
morphbr@565
    74
morphbr@565
    75
    def stop(self):
morphbr@565
    76
morphbr@565
    77
        print "Trying to stop: %s" % self.pipe
morphbr@565
    78
        self.sock.send("control output0 stop\n")
morphbr@565
    79
morphbr@565
    80