diff -r f353f0da6f07 -r 3ddc53d45d68 gmyth-stream/server/main.py --- a/gmyth-stream/server/main.py Tue Apr 10 01:07:35 2007 +0100 +++ b/gmyth-stream/server/main.py Mon Apr 16 20:05:45 2007 +0100 @@ -64,40 +64,61 @@ ''' nextport = 0 +setup = (False, "STOPPED") def do_setup(server, filename, mux, vcodec, vbitrate, fps, acodec, abitrate, width, height, *options): global nextport - nextport += 1 - ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec, - abitrate, width, height, nextport, options) - if ret: - server.sendOk() - else: - server.sendNotOk(ret) + global setup + + if setup[1] != "PLAYING": + nextport += 1 + ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec, + abitrate, width, height, nextport, options) + if ret[0]: + server.sendOk() + else: + server.sendNotOk(ret[1]) + + setup = (True, setup[1]) + + else: server.sendNotOk("You must STOP before SETingUP again") return True def do_play(server): - ret = media.play() - if ret: - server.sendOk("%d" % nextport) + global setup + + if setup[0] and setup[1] == "STOPPED": + setup = (setup[0], "PLAYING") + ret = media.play() + if ret[0]: + server.sendOk("%d" % nextport) + else: + server.sendNotOk(ret[1]) + else: - server.sendNotOk(ret) + if setup[1] == "STOPPED": + server.sendNotOk("You must SETUP before PLAYing") + else: + server.sendNotOk("You must STOP before PLAYing again") return True def do_stop(server): + global setup + media.stop() + setup = (False, "STOPPED") server.sendOk() return True def do_list(server, *directory): file_list = [] for j in directory: - list_media_files(j, file_list) + lib.list_media_files(j, file_list) - server.sendOk() + server.sendOk(file_list) return True def do_quit(server): @@ -115,6 +136,7 @@ "QUIT": do_quit, } + def dispatch(server, msg): pieces = msg.split() if len(pieces) < 1: @@ -151,9 +173,12 @@ log.info("Client %s sent command: %r" % (client, msg)) dispatch(server, msg) - log.info("Closing connection with %s" % (client,)) server.disconnect_client(conn) + try: + os.wait() + except Exception, e: + log.error(e) server.stop() log.info("Server stopped. Closing...")