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