[svn r518] Newly added GMythFileLocal, to deal with local stream files.
10 log.basicConfig(level=log.DEBUG,
11 format="%(asctime)s %(levelname)-8s %(message)s",
12 datefmt='%Y-%m-%d %H:%M:%S')
14 config = ConfigParser.ConfigParser()
15 config.read("stream.conf")
17 def load_module(pathlist, name):
18 fp, path, desc = imp.find_module(name, pathlist)
20 module = imp.load_module(name, fp, path, desc)
27 media_plugin = config.get("Media", "engine")
28 media_plugin_module = load_module(["./plugins/media"], media_plugin)
29 media = media_plugin_module.Media(config)
31 comm_plugin = config.get("Comm", "engine")
32 comm_plugin_module = load_module(["./plugins/comm"], comm_plugin)
33 server = comm_plugin_module.Server(config)
35 log.info("Starting GMyth-Stream server")
45 |-> used to setup transcoding and streaming parameters
46 |-> must be used before any "PLAY" command
49 file://file_name mux vcodec vbitrate fps acodec abitrate width height options
50 dvd://title_number mux vcodec vbitrate fps acodec abitrate width height options
53 |-> used to start transcoding and streaming of file
54 |-> must be used just if SETUP was used before
55 |-> after it, _must_ send STOP
58 |-> used to stop transcoding and streaming process
59 |-> must be used just if PLAY was used before
60 |-> must be used after PLAY
63 |-> used to quit the main loop (quit program)
68 def do_setup(server, filename, mux, vcodec, vbitrate, fps, acodec, abitrate,
69 width, height, *options):
72 ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec,
73 abitrate, width, height, nextport, options)
82 server.sendOk("%d" % nextport)
105 def dispatch(server, msg):
108 log.error("Invalid client command format: %r" % msg)
109 server.sendNotOk("Invalid Format")
113 f = mapping.get(cmd, None)
115 log.error("Unknow command: %r" % msg)
116 server.sendNotOk("Unknow Command")
120 return f(server, *pieces[1:])
122 log.error("Could not execute %r: %s" % (msg, e))
123 server.sendNotOk(str(e))
128 while not server.finish:
129 conn, client, port = server.getRequest()
133 while not server.finish:
134 msg = server.getMsg()
138 log.info("Client %s sent command: %r" % (client, msg))
139 dispatch(server, msg)
142 log.info("Closing connection with %s" % (client,))
143 server.disconnect_client(conn)
146 log.info("Server stopped. Closing...")