morphbr@453: '''
morphbr@453:  # GMyth-Stream
morphbr@453:  #
morphbr@453:  # @file main.py
morphbr@453:  #
morphbr@453:  # @brief <p> Plugin for GMyth-Stream
morphbr@453:  #
morphbr@453:  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
morphbr@453:  # @author Artur Duque de Souza <artur.souza@indt.org.br>
morphbr@453:  #
morphbr@453:  #
morphbr@453:  # This program is free software; you can redistribute it and/or modify
morphbr@453:  # it under the terms of the GNU Lesser General Public License as published by
morphbr@453:  # the Free Software Foundation; either version 2 of the License, or
morphbr@453:  # (at your option) any later version.
morphbr@453:  #
morphbr@453:  # This program is distributed in the hope that it will be useful,
morphbr@453:  # but WITHOUT ANY WARRANTY; without even the implied warranty of
morphbr@453:  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
morphbr@453:  # GNU General Public License for more details.
morphbr@453:  #
morphbr@453:  # You should have received a copy of the GNU Lesser General Public License
morphbr@453:  # along with this program; if not, write to the Free Software
morphbr@453:  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
morphbr@453:  #
morphbr@453:  '''
morphbr@453: 
morphbr@453: import os
morphbr@453: import sys
morphbr@453: import time
morphbr@453: import socket
morphbr@453: import ConfigParser
morphbr@453: 
morphbr@453: class Media:
morphbr@453: 
morphbr@453:     def __init__(self, config):
morphbr@453: 
morphbr@453:         self.config = config
morphbr@453:         self.pipe = ""
morphbr@453:         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
morphbr@453: 
morphbr@453:         self.path = config.get("Vlc", "path")
morphbr@453:         self.host = config.get("Vlc", "host")
morphbr@453:         self.port = int(config.get("Vlc", "port"))
morphbr@453:         self.pwd = config.get("Vlc", "pwd")
morphbr@453: 
morphbr@453:         # exec VLC
morphbr@453:         pid = os.fork()
morphbr@453:         if (pid == 0):
morphbr@453:             #child
morphbr@453:             print "ESTOU EM CHILD"
morphbr@453:             self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
morphbr@453:             os.system(self.path)
morphbr@453:             sys.exit(0)
morphbr@453: 
morphbr@453:         print "ESTOU EM PARENT 1"
morphbr@453:         time.sleep(3)
morphbr@453:         print "ESTOU EM PARENT 2"
morphbr@453:         self.sock.connect( (self.host, self.port) )
morphbr@453:         self.sock.send("%s\n" % self.pwd)
morphbr@453: 
morphbr@453: 
morphbr@453:     def insert_file(self, filename):
morphbr@453: 
morphbr@453:         self.sock.send("setup output0 input %s\n" % filename)
morphbr@453: 
morphbr@453: 
morphbr@453:     def setup(self, filename, codec, bitrate, width, height, port):
morphbr@453: 
morphbr@453:         self.filename = filename
morphbr@453:         self.codec = codec
morphbr@453:         self.bitrate = int(bitrate)
morphbr@453:         self.width = int(width)
morphbr@453:         self.height = int(height)
morphbr@453:         self.port = int(port)
morphbr@453: 
morphbr@453:         self.pipe = "#transcode{vcodec=%s,vb=%d,"\
morphbr@453:                     "fps=25.0,scale=1,acodec=mpga,"\
morphbr@453:                     "ab=64,channels=1,width=%d,height=%d}"\
morphbr@453:                     ":duplicate{dst=std{access=http,"\
morphbr@453:                     "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
morphbr@453:                                              self.widht, self.height,\
morphbr@453:                                              self.port)
morphbr@453: 
morphbr@453:         self.sock.send("setup output0 broadcast %s\n" % self.pipe)
morphbr@453:         self.insert_file(self.filename)
morphbr@453: 
morphbr@453:     def play(self):
morphbr@453: 
morphbr@453:         print "Trying to play: %s" % self.pipe
morphbr@453:         self.sock.send("control output0 play\n")
morphbr@453: 
morphbr@453: 
morphbr@453:     def stop(self):
morphbr@453: 
morphbr@453:         print "Trying to stop: %s" % self.pipe
morphbr@453:         self.sock.send("control output0 stop\n")
morphbr@453: 
morphbr@453: