# HG changeset patch
# User morphbr
# Date 1174950807 -3600
# Node ID a806d8ad0ff0b7cc4c33559a18f4e271255719bb
# Parent 8efecea98bd77b038cb3eb2a8fed649d68555167
[svn r458]
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/main.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/main.py Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,85 @@
+ '''
+ # GMyth-Stream
+ #
+ # @file main.py
+ #
+ # @brief
Plugin for GMyth-Stream
+ #
+ # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ # @author Artur Duque de Souza
+ #
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ '''
+
+#!/usr/bin/python
+
+import sys
+import os
+import ConfigParser
+
+def now():
+ return time.strftime("%Y-%m-%d %H:%M:%S");
+
+
+config = ConfigParser.ConfigParser()
+config.read("stream.conf")
+
+media_plugin = config.get("Media", "engine")
+exec("from plugins.media.%s import *" % media_plugin)
+
+media = Media(config)
+
+comm_plugin = config.get("Comm", "engine")
+exec("from plugins.comm.%s import *" % comm_plugin)
+
+# Start Our Server:
+server = Server(config)
+
+print "--> Starting the server..."
+
+while (server.finish == 0):
+ con, client = server.getRequest()
+
+ while True:
+ msg = server.getMsg(1024).strip()
+
+ if not msg: break
+
+ elif (msg == "SETUP"):
+ setup = server.getMsg(1024).strip().split(" ")
+ media.setup(setup[0], setup[1], setup[2], \
+ setup[3], setup[4], setup[5])
+
+ elif (msg == "PLAY"):
+ media.play()
+
+ elif (msg == "STOP"):
+ media.stop()
+
+ elif (msg == "CLOSE"):
+ server.finish = 1
+ media.stop()
+ break
+
+ print "[%s] %s: %s" % (now(), client, msg)
+
+ print "[%s] Closing connection with %s" % (now(), client)
+ server.disconnect_client(con)
+
+server.stop()
+
+print "--> Server stopped..."
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/plugins/comm/tcp.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/plugins/comm/tcp.py Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,58 @@
+ '''
+ # GMyth-Stream
+ #
+ # @file main.py
+ #
+ # @brief Plugin for GMyth-Stream
+ #
+ # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ # @author Artur Duque de Souza
+ #
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ '''
+
+import time
+import socket
+
+class Server:
+
+ def __init__(self, config):
+ self.host = ''
+ self.port = int(config.get("Comm", "port"))
+ self.finish = 0
+
+ self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.tcp.bind( (self.host, self.port) )
+ self.tcp.listen(1)
+
+ def now(self):
+ return time.strftime("%Y-%m-%d %H:%M:%S");
+
+ def getMsg(self, size):
+ con = self.data[0]
+ return con.recv(size)
+
+ def getRequest(self):
+ self.data = self.tcp.accept()
+ print "[%s] Received request from ip=%s" % (self.now(), self.data[1] )
+ return self.data
+
+ def disconnect_client(self, connection):
+ connection.close()
+
+ def stop(self):
+ self.tcp.close()
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/plugins/comm/xmlrpc.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/plugins/comm/xmlrpc.py Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,102 @@
+ '''
+ # GMyth-Stream
+ #
+ # @file plugins/comm/xmlrpc.py
+ #
+ # @brief Plugin for GMyth-Stream
+ #
+ # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ # @author Artur Duque de Souza
+ #
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ '''
+
+import SimpleXMLRPCServer
+
+
+class Handler:
+
+ def __init__(self, pool):
+ self.pool = pool
+
+ def _listMethods(self):
+ return ['Setup', 'Play', 'Stop', 'Close']
+
+ def _methodHelp(self, method):
+
+ if method == 'Setup':
+ return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)"
+ elif method == 'Play':
+ return "Play the Media: Play()"
+ elif method == 'Stop':
+ return "Stop the Media: Stop()"
+ elif method == 'Close':
+ return "Close the connection: Close()"
+ else:
+ # By convention, return empty
+ # string if no help is available
+ return ""
+
+
+ def Setup(self, filename, codec, bitrate, width, height, port):
+ self.pool.append("SETUP")
+ self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\
+ width, height, port))
+ return 0
+
+ def Play(self):
+ self.pool.append("PLAY")
+ return 0
+
+ def Stop(self):
+ self.pool.append("STOP")
+ return 0
+
+ def Close(self):
+ self.pool.append("CLOSE")
+ return 0
+
+
+class Server:
+
+ def __init__(self, config):
+ self.host = 'localhost'
+ self.port = int(config.get("Comm", "port"))
+ self.finish = 0
+ self.pool = []
+
+ self.handler = Handler(self.pool)
+
+ self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port))
+ self.xmlrpc.register_instance(self.handler)
+
+
+ def getMsg(self, size):
+ try:
+ return self.pool.pop(0)
+ except IndexError:
+ return ""
+
+ def getRequest(self):
+ self.xmlrpc.handle_request()
+ return (0, "RPC Client")
+
+ def disconnect_client(self, connection):
+ connection = 0
+
+ def stop(self):
+ self.xmlrpc.server_close()
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/plugins/media/gstreamer.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/plugins/media/gstreamer.py Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,90 @@
+ '''
+ # GMyth-Stream
+ #
+ # @file main.py
+ #
+ # @brief Plugin for GMyth-Stream
+ #
+ # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ # @author Artur Duque de Souza
+ #
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ '''
+
+import pygst
+pygst.require("0.10")
+import gst
+import gobject
+
+class Media:
+
+ def __init__(self, config):
+
+ # set gstreamer basic options
+ self.config = config
+ self.pipe = ""
+
+ def setup(self, filename, codec, bitrate, width, height, port):
+
+ self.filename = filename
+ self.codec = codec
+ self.bitrate = int(bitrate)
+ self.width = int(width)
+ self.height = int(height)
+ self.port = int(port)
+
+ ## Pipelines
+
+ #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\
+ #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \
+ #! rtph263ppay ! udpsink host=224.0.0.1 port=5000
+
+
+ #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\
+ #! udpsink name=upd_audio host=224.0.0.1 port=5002
+
+ self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\
+ "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\
+ " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
+ "queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
+ "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
+ self.bitrate, self.port, self.port+2)
+
+ #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
+
+ self.pipeline = gst.parse_launch(self.pipe)
+
+
+ def play(self):
+
+ print "Trying to play pipeline: %s" % self.pipe
+ try:
+ if (self.pipeline):
+ self.pipeline.set_state(gst.STATE_PLAYING)
+ except gobject.GError, e:
+ print "Error: " + str(e)
+
+
+ def stop(self):
+
+ print "Trying to stop pipeline: %s" % self.pipe
+ try:
+ if (self.pipeline):
+ self.pipeline.set_state(gst.STATE_NULL)
+ except gobject.GError, e:
+ print "Error: " + str(e)
+
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/plugins/media/vlc.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/plugins/media/vlc.py Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,99 @@
+'''
+ # GMyth-Stream
+ #
+ # @file main.py
+ #
+ # @brief Plugin for GMyth-Stream
+ #
+ # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ # @author Artur Duque de Souza
+ #
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU Lesser General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ '''
+
+import os
+import sys
+import time
+import socket
+import ConfigParser
+
+class Media:
+
+ def __init__(self, config):
+
+ self.config = config
+ self.pipe = ""
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ self.path = config.get("Vlc", "path")
+ self.host = config.get("Vlc", "host")
+ self.port = int(config.get("Vlc", "port"))
+ self.pwd = config.get("Vlc", "pwd")
+
+ # exec VLC
+ pid = os.fork()
+ if (pid == 0):
+ #child
+ print "ESTOU EM CHILD"
+ self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
+ os.system(self.path)
+ sys.exit(0)
+
+ print "ESTOU EM PARENT 1"
+ time.sleep(3)
+ print "ESTOU EM PARENT 2"
+ self.sock.connect( (self.host, self.port) )
+ self.sock.send("%s\n" % self.pwd)
+
+
+ def insert_file(self, filename):
+
+ self.sock.send("setup output0 input %s\n" % filename)
+
+
+ def setup(self, filename, codec, bitrate, width, height, port):
+
+ self.filename = filename
+ self.codec = codec
+ self.bitrate = int(bitrate)
+ self.width = int(width)
+ self.height = int(height)
+ self.port = int(port)
+
+ self.pipe = "#transcode{vcodec=%s,vb=%d,"\
+ "fps=25.0,scale=1,acodec=mpga,"\
+ "ab=64,channels=1,width=%d,height=%d}"\
+ ":duplicate{dst=std{access=http,"\
+ "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
+ self.widht, self.height,\
+ self.port)
+
+ self.sock.send("setup output0 broadcast %s\n" % self.pipe)
+ self.insert_file(self.filename)
+
+ def play(self):
+
+ print "Trying to play: %s" % self.pipe
+ self.sock.send("control output0 play\n")
+
+
+ def stop(self):
+
+ print "Trying to stop: %s" % self.pipe
+ self.sock.send("control output0 stop\n")
+
+
diff -r 8efecea98bd7 -r a806d8ad0ff0 gmyth-stream/stream.conf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/stream.conf Tue Mar 27 00:13:27 2007 +0100
@@ -0,0 +1,12 @@
+[Media]
+engine = gstreamer
+
+[Comm]
+engine = tcp
+port = 12344
+
+[Vlc]
+path = /usr/local/bin/vlc
+host = 127.0.0.1
+port = 4212
+pwd = admin