1.1 --- a/gmyth-stream/server/main.py Tue Apr 10 01:07:35 2007 +0100
1.2 +++ b/gmyth-stream/server/main.py Tue Apr 17 15:13:48 2007 +0100
1.3 @@ -64,40 +64,61 @@
1.4
1.5 '''
1.6 nextport = 0
1.7 +setup = (False, "STOPPED")
1.8
1.9 def do_setup(server, filename, mux, vcodec, vbitrate, fps, acodec, abitrate,
1.10 width, height, *options):
1.11 global nextport
1.12 - nextport += 1
1.13 - ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec,
1.14 - abitrate, width, height, nextport, options)
1.15 - if ret:
1.16 - server.sendOk()
1.17 - else:
1.18 - server.sendNotOk(ret)
1.19 + global setup
1.20 +
1.21 + if setup[1] != "PLAYING":
1.22 + nextport += 1
1.23 + ret = media.setup(filename, mux, vcodec, vbitrate, fps, acodec,
1.24 + abitrate, width, height, nextport, options)
1.25 + if ret[0]:
1.26 + server.sendOk()
1.27 + else:
1.28 + server.sendNotOk(ret[1])
1.29 +
1.30 + setup = (True, setup[1])
1.31 +
1.32 + else: server.sendNotOk("You must STOP before SETingUP again")
1.33
1.34 return True
1.35
1.36 def do_play(server):
1.37 - ret = media.play()
1.38 - if ret:
1.39 - server.sendOk("%d" % nextport)
1.40 + global setup
1.41 +
1.42 + if setup[0] and setup[1] == "STOPPED":
1.43 + setup = (setup[0], "PLAYING")
1.44 + ret = media.play()
1.45 + if ret[0]:
1.46 + server.sendOk("%d" % nextport)
1.47 + else:
1.48 + server.sendNotOk(ret[1])
1.49 +
1.50 else:
1.51 - server.sendNotOk(ret)
1.52 + if setup[1] == "STOPPED":
1.53 + server.sendNotOk("You must SETUP before PLAYing")
1.54 + else:
1.55 + server.sendNotOk("You must STOP before PLAYing again")
1.56
1.57 return True
1.58
1.59 def do_stop(server):
1.60 + global setup
1.61 +
1.62 media.stop()
1.63 + setup = (False, "STOPPED")
1.64 server.sendOk()
1.65 return True
1.66
1.67 def do_list(server, *directory):
1.68 file_list = []
1.69 for j in directory:
1.70 - list_media_files(j, file_list)
1.71 + lib.list_media_files(j, file_list)
1.72
1.73 - server.sendOk()
1.74 + server.sendOk(file_list)
1.75 return True
1.76
1.77 def do_quit(server):
1.78 @@ -115,6 +136,7 @@
1.79 "QUIT": do_quit,
1.80 }
1.81
1.82 +
1.83 def dispatch(server, msg):
1.84 pieces = msg.split()
1.85 if len(pieces) < 1:
1.86 @@ -151,9 +173,12 @@
1.87 log.info("Client %s sent command: %r" % (client, msg))
1.88 dispatch(server, msg)
1.89
1.90 -
1.91 log.info("Closing connection with %s" % (client,))
1.92 server.disconnect_client(conn)
1.93 + try:
1.94 + os.wait()
1.95 + except Exception, e:
1.96 + log.error(e)
1.97
1.98 server.stop()
1.99 log.info("Server stopped. Closing...")