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