morphbr@453: #!/usr/bin/python morphbr@453: morphbr@470: import os morphbr@470: import lib morphbr@453: import sys morphbr@453: import ConfigParser morphbr@453: morphbr@453: config = ConfigParser.ConfigParser() morphbr@453: config.read("stream.conf") morphbr@453: morphbr@453: media_plugin = config.get("Media", "engine") morphbr@453: exec("from plugins.media.%s import *" % media_plugin) morphbr@453: morphbr@453: media = Media(config) morphbr@453: morphbr@453: comm_plugin = config.get("Comm", "engine") morphbr@453: exec("from plugins.comm.%s import *" % comm_plugin) morphbr@453: morphbr@453: # Start Our Server: morphbr@453: server = Server(config) morphbr@453: morphbr@470: lib.log("Starting GMyth-Stream server") morphbr@453: morphbr@453: while (server.finish == 0): morphbr@453: con, client = server.getRequest() morphbr@453: morphbr@453: while True: morphbr@453: msg = server.getMsg(1024).strip() morphbr@453: morphbr@453: if not msg: break morphbr@453: morphbr@470: lib.log("Received %s from: %s" % (msg, client) ) morphbr@470: morphbr@470: if (msg == "SETUP"): morphbr@453: setup = server.getMsg(1024).strip().split(" ") morphbr@475: size = len(setup) morphbr@475: options = [] morphbr@475: morphbr@475: if ( size < 10 ): morphbr@475: server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0])) morphbr@475: morphbr@475: else: morphbr@475: morphbr@475: if ( size > 10 ): morphbr@475: i = 10 morphbr@475: while (i < size): morphbr@475: options.append(setup[i]) morphbr@475: i += 1 morphbr@475: morphbr@474: ret = media.setup(setup[0], setup[1], setup[2], \ morphbr@474: setup[3], setup[4], setup[5], morphbr@474: setup[6], setup[7], setup[8], morphbr@475: setup[9], options) morphbr@470: morphbr@474: if (ret == 0): morphbr@474: server.Ack("SETUP") morphbr@474: else: morphbr@475: server.sendMsg(lib.log(ret)) morphbr@470: morphbr@453: morphbr@453: elif (msg == "PLAY"): morphbr@453: media.play() morphbr@470: server.Ack("PLAY") morphbr@453: morphbr@453: elif (msg == "STOP"): morphbr@453: media.stop() morphbr@470: server.Ack("STOP") morphbr@453: morphbr@453: elif (msg == "CLOSE"): morphbr@453: server.finish = 1 morphbr@453: media.stop() morphbr@470: server.Ack("CLOSE") morphbr@453: break morphbr@453: morphbr@470: lib.log("Closing connection with %s" % client[0]) morphbr@453: server.disconnect_client(con) morphbr@453: morphbr@453: server.stop() morphbr@466: del(server) morphbr@470: lib.log("Server stopped. Closing...") morphbr@470: