gmyth-stream/plugins/media/vlc.py
author rosfran
Tue Mar 27 20:27:51 2007 +0100 (2007-03-27)
branchtrunk
changeset 462 0e6de3b59f57
child 466 a7aba7d166fb
permissions -rw-r--r--
[svn r467] Addded functions to help stopping LiveTV recording.
     1 '''
     2  # GMyth-Stream
     3  #
     4  # @file main.py
     5  #
     6  # @brief <p> Plugin for GMyth-Stream
     7  #
     8  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  # @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  #
    11  #
    12  # This program is free software; you can redistribute it and/or modify
    13  # it under the terms of the GNU Lesser General Public License as published by
    14  # the Free Software Foundation; either version 2 of the License, or
    15  # (at your option) any later version.
    16  #
    17  # This program is distributed in the hope that it will be useful,
    18  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  # GNU General Public License for more details.
    21  #
    22  # You should have received a copy of the GNU Lesser General Public License
    23  # along with this program; if not, write to the Free Software
    24  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  #
    26  '''
    27 
    28 import os
    29 import sys
    30 import time
    31 import socket
    32 import ConfigParser
    33 
    34 class Media:
    35 
    36     def __init__(self, config):
    37 
    38         self.config = config
    39         self.pipe = ""
    40         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    41 
    42         self.path = config.get("Vlc", "path")
    43         self.host = config.get("Vlc", "host")
    44         self.port = int(config.get("Vlc", "port"))
    45         self.pwd = config.get("Vlc", "pwd")
    46 
    47         # exec VLC
    48         pid = os.fork()
    49         if (pid == 0):
    50             #child
    51             print "ESTOU EM CHILD"
    52             self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
    53             os.system(self.path)
    54             sys.exit(0)
    55 
    56         print "ESTOU EM PARENT 1"
    57         time.sleep(3)
    58         print "ESTOU EM PARENT 2"
    59         self.sock.connect( (self.host, self.port) )
    60         self.sock.send("%s\n" % self.pwd)
    61 
    62 
    63     def insert_file(self, filename):
    64 
    65         self.sock.send("setup output0 input %s\n" % filename)
    66 
    67 
    68     def setup(self, filename, codec, bitrate, width, height, port):
    69 
    70         self.filename = filename
    71         self.codec = codec
    72         self.bitrate = int(bitrate)
    73         self.width = int(width)
    74         self.height = int(height)
    75         self.port = int(port)
    76 
    77         self.pipe = "#transcode{vcodec=%s,vb=%d,"\
    78                     "fps=25.0,scale=1,acodec=mpga,"\
    79                     "ab=64,channels=1,width=%d,height=%d}"\
    80                     ":duplicate{dst=std{access=http,"\
    81                     "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
    82                                              self.widht, self.height,\
    83                                              self.port)
    84 
    85         self.sock.send("setup output0 broadcast %s\n" % self.pipe)
    86         self.insert_file(self.filename)
    87 
    88     def play(self):
    89 
    90         print "Trying to play: %s" % self.pipe
    91         self.sock.send("control output0 play\n")
    92 
    93 
    94     def stop(self):
    95 
    96         print "Trying to stop: %s" % self.pipe
    97         self.sock.send("control output0 stop\n")
    98 
    99