[svn r550] A lot of GObject fixes (using the GType casting), added inheritance to the GMythFile* modules, locks all the the STOP_RECORDING messages.
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)
67 setup = (False, "STOPPED")
69 def do_setup(server, filename, mux, vcodec, vbitrate, fps, acodec, abitrate,
70 width, height, *options):
74 if setup[1] != "PLAYING":
76 ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec,
77 abitrate, width, height, nextport, options)
81 server.sendNotOk(ret[1])
83 setup = (True, setup[1])
85 else: server.sendNotOk("You must STOP before SETingUP again")
92 if setup[0] and setup[1] == "STOPPED":
93 setup = (setup[0], "PLAYING")
96 server.sendOk("%d" % nextport)
98 server.sendNotOk(ret[1])
101 if setup[1] == "STOPPED":
102 server.sendNotOk("You must SETUP before PLAYing")
104 server.sendNotOk("You must STOP before PLAYing again")
112 setup = (False, "STOPPED")
116 def do_list(server, *directory):
119 lib.list_media_files(j, file_list)
121 server.sendOk(file_list)
140 def dispatch(server, msg):
143 log.error("Invalid client command format: %r" % msg)
144 server.sendNotOk("Invalid Format")
148 f = mapping.get(cmd, None)
150 log.error("Unknow command: %r" % msg)
151 server.sendNotOk("Unknow Command")
155 return f(server, *pieces[1:])
157 log.error("Could not execute %r: %s" % (msg, e))
158 server.sendNotOk(str(e))
163 while not server.finish:
164 conn, client, port = server.getRequest()
168 while not server.finish:
169 msg = server.getMsg()
173 log.info("Client %s sent command: %r" % (client, msg))
174 dispatch(server, msg)
176 log.info("Closing connection with %s" % (client,))
177 server.disconnect_client(conn)
184 log.info("Server stopped. Closing...")