# HG changeset patch # User morphbr # Date 1175725844 -3600 # Node ID 2b5355061b667ece2711683c0654a1957ac0a100 # Parent b0e8a532e88240e743c494d5fe2d2dfa8d47f1b7 [svn r509] - GMyth-Streamer: * default port changed to 50000 * increase port used for streaming when SETUP * changed SETUP protocol * switch command CLOSE to QUIT diff -r b0e8a532e882 -r 2b5355061b66 gmyth-stream/server/main.py --- a/gmyth-stream/server/main.py Wed Apr 04 22:11:50 2007 +0100 +++ b/gmyth-stream/server/main.py Wed Apr 04 23:30:44 2007 +0100 @@ -21,8 +21,42 @@ lib.log("Starting GMyth-Stream server") + +''' +PROTOCOL DESCRIPTION +===================== + +COMMAND OPTIONS + +-> SETUP DESCRIPTION +|-> used to setup transcoding and streaming parameters +|-> must be used before any "PLAY" command +|-> e.g: + +file://file_name mux vcodec vbitrate fps acodec abitrate width height options +dvd://title_number mux vcodec vbitrate fps acodec abitrate width height options + +-> PLAY DESCRIPTION + |-> used to start transcoding and streaming of file + |-> must be used just if SETUP was used before + |-> after it, _must_ send STOP + +-> STOP DESCRIPTION + |-> used to stop transcoding and streaming process + |-> must be used just if PLAY was used before + |-> must be used after PLAY + +-> QUIT DESCRIPTION + |-> used to quit the main loop (quit program) + +''' +nextport = 0 + while (server.finish == 0): - con, client = server.getRequest() + conn, client, port = server.getRequest() + server.sendMsg("Welcome to GMyth-Streamer Master") + if nextport == 0: + nextport = port while True: msg = server.getMsg(1024).strip() @@ -47,10 +81,11 @@ options.append(setup[i]) i += 1 + nextport += 1 ret = media.setup(setup[0], setup[1], setup[2], \ setup[3], setup[4], setup[5], setup[6], setup[7], setup[8], - setup[9], options) + nextport, options) if ret == 0: server.Ack("SETUP") @@ -61,19 +96,20 @@ elif msg == "PLAY": media.play() server.Ack("PLAY") + server.sendMsg("STREAM PORT=%d" % nextport) elif msg == "STOP": media.stop() server.Ack("STOP") - elif msg == "CLOSE": + elif msg == "QUIT": server.finish = 1 media.stop() - server.Ack("CLOSE") + server.Ack("QUIT") break lib.log("Closing connection with %s" % client[0]) - server.disconnect_client(con) + server.disconnect_client(conn) server.stop() del(server) diff -r b0e8a532e882 -r 2b5355061b66 gmyth-stream/server/plugins/comm/tcp.py --- a/gmyth-stream/server/plugins/comm/tcp.py Wed Apr 04 22:11:50 2007 +0100 +++ b/gmyth-stream/server/plugins/comm/tcp.py Wed Apr 04 23:30:44 2007 +0100 @@ -27,7 +27,7 @@ def getRequest(self): self.con, self.client = self.tcp.accept() print "[%s] Received request from ip=%s" % (lib.now(), self.client ) - return (self.con, self.client) + return (self.con, self.client, self.port) def disconnect_client(self, connection): connection.close() diff -r b0e8a532e882 -r 2b5355061b66 gmyth-stream/server/plugins/media/mencoder.py --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 22:11:50 2007 +0100 +++ b/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 23:30:44 2007 +0100 @@ -14,6 +14,7 @@ def __init__(self, config): self.config = config + self.args = "" self.language = "en" self.socket = None self.child_pid = None @@ -33,32 +34,7 @@ for opt in options: - if opt == "file" or opt == "dvd": - - if self.acodec == "mp3lame": - audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate - else: - audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ - self.acodec, self.abitrate) - - - if opt == "file": - self.kind = "file" - self.args += " %s -mf fps=%s -of %s %s"\ - " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\ - " -really-quiet -o %s" % ( - self.filename, self.fps, self.mux, audio, self.vcodec, - self.vbitrate, self.width, self.height, self.fifo) - - elif opt == "dvd": - self.kind = "dvd" - self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\ - " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\ - " -ofps %s -really-quiet -o %s" % ( - self.filename, self.language, self.width, self.height, audio, - self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo) - - elif opt == "local": + if opt == "local": self.mplayer = os.popen("which mplayer").read().strip() elif opt.find("language=") >= 0: @@ -83,21 +59,7 @@ self.mplayer += " " + msg self.mplayer_pid = Popen(self.mplayer, shell=True) - def setup(self, filename, mux, vcodec, vbitrate,\ - fps, acodec, abitrate, width, height, port, options): - - self.filename = filename - self.mux = mux - self.vcodec = vcodec - self.vbitrate = vbitrate - self.fps = fps - self.acodec = acodec - self.abitrate = abitrate - self.width = width - self.height = height - - self.port = int(port) - + def setup_mencoder(self): self.path = self.config.get("Mencoder", "path") a, b = os.popen2(self.path) version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1] @@ -105,6 +67,8 @@ if version > "4.1.1": self.mencoder_old = False else: self.mencoder_old = True + lib.log("Mencoder version: %s" % version) + a.close() b.close() @@ -113,16 +77,74 @@ else: self.fifo = "-" - self.args = "" - self.kind = "" + def setup_filename(self, filename): + try: + self.kind, self.filename = filename.split("://") + except: + return (False, "Wrong filename protocol") + + if self.acodec == "mp3lame": + audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate + else: + audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ + self.acodec, self.abitrate) + + if self.kind == "file": + if not os.path.exists(self.filename): + msg = "File requested does not exist. SETUP failed." + lib.log(msg) + return (False, msg) + + self.args += " %s -mf fps=%s -of %s %s"\ + " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\ + " -really-quiet -o %s 2>/dev/null" % ( + self.filename, self.fps, self.mux, audio, self.vcodec, + self.vbitrate, self.width, self.height, self.fifo) + + elif self.kind == "dvd": + self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\ + " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\ + " -ofps %s -really-quiet -o %s 2>/dev/null" % ( + self.filename, self.language, self.width, self.height, audio, + self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo) + + return (True, "") + + ''' + MENCODER SETUP DESCRIPTION + =========================== + + -> mux, vcodecs and acodecs + |-> mencoder (-of | -ovc | -oac) help + + -> if used mpeg as mux: + |-> to setup format: format=%s as an option at the end + + ''' + + def setup(self, filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port, options): + + self.mux = mux + self.vcodec = vcodec + self.vbitrate = vbitrate + self.fps = fps + self.acodec = acodec + self.abitrate = abitrate + self.width = width + self.height = height + self.port = int(port) + + self.setup_mencoder() + ret_val = self.setup_filename(filename) + + if not ret_val[0]: + return ret_val[1] + self.set_args(options) - if self.kind == "file" and not os.path.exists(self.filename): - msg = "File requested does not exist. SETUP failed." - lib.log(msg) - return msg - # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file + # /tmp/dvb.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 format=mpeg1 file #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd if self.socket != None: del(self.socket) @@ -148,7 +170,7 @@ # exec Mencoder if self.mencoder_old: self.mencoder_pid = Popen(self.path + self.args, shell=True) - fifo = open(self.fifo) + self.pout = open(self.fifo) else: self.path += self.args pin, self.pout = os.popen2(self.path) diff -r b0e8a532e882 -r 2b5355061b66 gmyth-stream/server/stream.conf --- a/gmyth-stream/server/stream.conf Wed Apr 04 22:11:50 2007 +0100 +++ b/gmyth-stream/server/stream.conf Wed Apr 04 23:30:44 2007 +0100 @@ -1,6 +1,6 @@ [Comm] engine = tcp -port = 12345 +port = 50000 [Media]