1.1 --- a/gmyth-stream/server/main.py Wed Apr 04 22:11:50 2007 +0100
1.2 +++ b/gmyth-stream/server/main.py Wed Apr 04 23:30:44 2007 +0100
1.3 @@ -21,8 +21,42 @@
1.4
1.5 lib.log("Starting GMyth-Stream server")
1.6
1.7 +
1.8 +'''
1.9 +PROTOCOL DESCRIPTION
1.10 +=====================
1.11 +
1.12 +COMMAND OPTIONS
1.13 +
1.14 +-> SETUP DESCRIPTION
1.15 +|-> used to setup transcoding and streaming parameters
1.16 +|-> must be used before any "PLAY" command
1.17 +|-> e.g:
1.18 +
1.19 +file://file_name mux vcodec vbitrate fps acodec abitrate width height options
1.20 +dvd://title_number mux vcodec vbitrate fps acodec abitrate width height options
1.21 +
1.22 +-> PLAY DESCRIPTION
1.23 + |-> used to start transcoding and streaming of file
1.24 + |-> must be used just if SETUP was used before
1.25 + |-> after it, _must_ send STOP
1.26 +
1.27 +-> STOP DESCRIPTION
1.28 + |-> used to stop transcoding and streaming process
1.29 + |-> must be used just if PLAY was used before
1.30 + |-> must be used after PLAY
1.31 +
1.32 +-> QUIT DESCRIPTION
1.33 + |-> used to quit the main loop (quit program)
1.34 +
1.35 +'''
1.36 +nextport = 0
1.37 +
1.38 while (server.finish == 0):
1.39 - con, client = server.getRequest()
1.40 + conn, client, port = server.getRequest()
1.41 + server.sendMsg("Welcome to GMyth-Streamer Master")
1.42 + if nextport == 0:
1.43 + nextport = port
1.44
1.45 while True:
1.46 msg = server.getMsg(1024).strip()
1.47 @@ -47,10 +81,11 @@
1.48 options.append(setup[i])
1.49 i += 1
1.50
1.51 + nextport += 1
1.52 ret = media.setup(setup[0], setup[1], setup[2], \
1.53 setup[3], setup[4], setup[5],
1.54 setup[6], setup[7], setup[8],
1.55 - setup[9], options)
1.56 + nextport, options)
1.57
1.58 if ret == 0:
1.59 server.Ack("SETUP")
1.60 @@ -61,19 +96,20 @@
1.61 elif msg == "PLAY":
1.62 media.play()
1.63 server.Ack("PLAY")
1.64 + server.sendMsg("STREAM PORT=%d" % nextport)
1.65
1.66 elif msg == "STOP":
1.67 media.stop()
1.68 server.Ack("STOP")
1.69
1.70 - elif msg == "CLOSE":
1.71 + elif msg == "QUIT":
1.72 server.finish = 1
1.73 media.stop()
1.74 - server.Ack("CLOSE")
1.75 + server.Ack("QUIT")
1.76 break
1.77
1.78 lib.log("Closing connection with %s" % client[0])
1.79 - server.disconnect_client(con)
1.80 + server.disconnect_client(conn)
1.81
1.82 server.stop()
1.83 del(server)
2.1 --- a/gmyth-stream/server/plugins/comm/tcp.py Wed Apr 04 22:11:50 2007 +0100
2.2 +++ b/gmyth-stream/server/plugins/comm/tcp.py Wed Apr 04 23:30:44 2007 +0100
2.3 @@ -27,7 +27,7 @@
2.4 def getRequest(self):
2.5 self.con, self.client = self.tcp.accept()
2.6 print "[%s] Received request from ip=%s" % (lib.now(), self.client )
2.7 - return (self.con, self.client)
2.8 + return (self.con, self.client, self.port)
2.9
2.10 def disconnect_client(self, connection):
2.11 connection.close()
3.1 --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 22:11:50 2007 +0100
3.2 +++ b/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 23:30:44 2007 +0100
3.3 @@ -14,6 +14,7 @@
3.4 def __init__(self, config):
3.5
3.6 self.config = config
3.7 + self.args = ""
3.8 self.language = "en"
3.9 self.socket = None
3.10 self.child_pid = None
3.11 @@ -33,32 +34,7 @@
3.12
3.13 for opt in options:
3.14
3.15 - if opt == "file" or opt == "dvd":
3.16 -
3.17 - if self.acodec == "mp3lame":
3.18 - audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate
3.19 - else:
3.20 - audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\
3.21 - self.acodec, self.abitrate)
3.22 -
3.23 -
3.24 - if opt == "file":
3.25 - self.kind = "file"
3.26 - self.args += " %s -mf fps=%s -of %s %s"\
3.27 - " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\
3.28 - " -really-quiet -o %s" % (
3.29 - self.filename, self.fps, self.mux, audio, self.vcodec,
3.30 - self.vbitrate, self.width, self.height, self.fifo)
3.31 -
3.32 - elif opt == "dvd":
3.33 - self.kind = "dvd"
3.34 - self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\
3.35 - " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\
3.36 - " -ofps %s -really-quiet -o %s" % (
3.37 - self.filename, self.language, self.width, self.height, audio,
3.38 - self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo)
3.39 -
3.40 - elif opt == "local":
3.41 + if opt == "local":
3.42 self.mplayer = os.popen("which mplayer").read().strip()
3.43
3.44 elif opt.find("language=") >= 0:
3.45 @@ -83,21 +59,7 @@
3.46 self.mplayer += " " + msg
3.47 self.mplayer_pid = Popen(self.mplayer, shell=True)
3.48
3.49 - def setup(self, filename, mux, vcodec, vbitrate,\
3.50 - fps, acodec, abitrate, width, height, port, options):
3.51 -
3.52 - self.filename = filename
3.53 - self.mux = mux
3.54 - self.vcodec = vcodec
3.55 - self.vbitrate = vbitrate
3.56 - self.fps = fps
3.57 - self.acodec = acodec
3.58 - self.abitrate = abitrate
3.59 - self.width = width
3.60 - self.height = height
3.61 -
3.62 - self.port = int(port)
3.63 -
3.64 + def setup_mencoder(self):
3.65 self.path = self.config.get("Mencoder", "path")
3.66 a, b = os.popen2(self.path)
3.67 version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1]
3.68 @@ -105,6 +67,8 @@
3.69 if version > "4.1.1": self.mencoder_old = False
3.70 else: self.mencoder_old = True
3.71
3.72 + lib.log("Mencoder version: %s" % version)
3.73 +
3.74 a.close()
3.75 b.close()
3.76
3.77 @@ -113,16 +77,74 @@
3.78 else:
3.79 self.fifo = "-"
3.80
3.81 - self.args = ""
3.82 - self.kind = ""
3.83 + def setup_filename(self, filename):
3.84 + try:
3.85 + self.kind, self.filename = filename.split("://")
3.86 + except:
3.87 + return (False, "Wrong filename protocol")
3.88 +
3.89 + if self.acodec == "mp3lame":
3.90 + audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate
3.91 + else:
3.92 + audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\
3.93 + self.acodec, self.abitrate)
3.94 +
3.95 + if self.kind == "file":
3.96 + if not os.path.exists(self.filename):
3.97 + msg = "File requested does not exist. SETUP failed."
3.98 + lib.log(msg)
3.99 + return (False, msg)
3.100 +
3.101 + self.args += " %s -mf fps=%s -of %s %s"\
3.102 + " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\
3.103 + " -really-quiet -o %s 2>/dev/null" % (
3.104 + self.filename, self.fps, self.mux, audio, self.vcodec,
3.105 + self.vbitrate, self.width, self.height, self.fifo)
3.106 +
3.107 + elif self.kind == "dvd":
3.108 + self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\
3.109 + " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\
3.110 + " -ofps %s -really-quiet -o %s 2>/dev/null" % (
3.111 + self.filename, self.language, self.width, self.height, audio,
3.112 + self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo)
3.113 +
3.114 + return (True, "")
3.115 +
3.116 + '''
3.117 + MENCODER SETUP DESCRIPTION
3.118 + ===========================
3.119 +
3.120 + -> mux, vcodecs and acodecs
3.121 + |-> mencoder (-of | -ovc | -oac) help
3.122 +
3.123 + -> if used mpeg as mux:
3.124 + |-> to setup format: format=%s as an option at the end
3.125 +
3.126 + '''
3.127 +
3.128 + def setup(self, filename, mux, vcodec, vbitrate,\
3.129 + fps, acodec, abitrate, width, height, port, options):
3.130 +
3.131 + self.mux = mux
3.132 + self.vcodec = vcodec
3.133 + self.vbitrate = vbitrate
3.134 + self.fps = fps
3.135 + self.acodec = acodec
3.136 + self.abitrate = abitrate
3.137 + self.width = width
3.138 + self.height = height
3.139 + self.port = int(port)
3.140 +
3.141 + self.setup_mencoder()
3.142 + ret_val = self.setup_filename(filename)
3.143 +
3.144 + if not ret_val[0]:
3.145 + return ret_val[1]
3.146 +
3.147 self.set_args(options)
3.148
3.149 - if self.kind == "file" and not os.path.exists(self.filename):
3.150 - msg = "File requested does not exist. SETUP failed."
3.151 - lib.log(msg)
3.152 - return msg
3.153 -
3.154 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file
3.155 + # /tmp/dvb.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 format=mpeg1 file
3.156 #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd
3.157 if self.socket != None:
3.158 del(self.socket)
3.159 @@ -148,7 +170,7 @@
3.160 # exec Mencoder
3.161 if self.mencoder_old:
3.162 self.mencoder_pid = Popen(self.path + self.args, shell=True)
3.163 - fifo = open(self.fifo)
3.164 + self.pout = open(self.fifo)
3.165 else:
3.166 self.path += self.args
3.167 pin, self.pout = os.popen2(self.path)
4.1 --- a/gmyth-stream/server/stream.conf Wed Apr 04 22:11:50 2007 +0100
4.2 +++ b/gmyth-stream/server/stream.conf Wed Apr 04 23:30:44 2007 +0100
4.3 @@ -1,6 +1,6 @@
4.4 [Comm]
4.5 engine = tcp
4.6 -port = 12345
4.7 +port = 50000
4.8
4.9
4.10 [Media]