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