1.1 --- a/gmyth-stream/main.py Fri Mar 30 04:12:52 2007 +0100
1.2 +++ b/gmyth-stream/main.py Fri Mar 30 23:07:54 2007 +0100
1.3 @@ -42,7 +42,7 @@
1.4 server.Ack("SETUP")
1.5
1.6 else:
1.7 - lib.log("Wrong SETUP command from: %s" % client)
1.8 + lib.log("Wrong SETUP command from: %s" % client[0])
1.9
1.10 elif (msg == "PLAY"):
1.11 media.play()
2.1 --- a/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 04:12:52 2007 +0100
2.2 +++ b/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 23:07:54 2007 +0100
2.3 @@ -10,6 +10,7 @@
2.4 self.finish = 0
2.5
2.6 self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2.7 + self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
2.8 self.tcp.bind( (self.host, self.port) )
2.9 self.tcp.listen(1)
2.10
3.1 --- a/gmyth-stream/plugins/media/ffmpeg.py Fri Mar 30 04:12:52 2007 +0100
3.2 +++ b/gmyth-stream/plugins/media/ffmpeg.py Fri Mar 30 23:07:54 2007 +0100
3.3 @@ -38,13 +38,13 @@
3.4 del(self.socket)
3.5
3.6 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
3.7 + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
3.8 self.socket.bind( ('', self.port) )
3.9 self.socket.settimeout(10)
3.10 + self.socket.listen(1)
3.11
3.12 def play(self):
3.13
3.14 - self.socket.listen(1)
3.15 -
3.16 lib.log("Starting FFmpeg: %s" % self.path)
3.17
3.18 # exec FFmpeg and get stdout
3.19 @@ -82,8 +82,9 @@
3.20
3.21 def stop(self):
3.22
3.23 - lib.log("Closing socket")
3.24 - self.socket.close()
3.25 + if (self.socket != None):
3.26 + lib.log("Closing socket")
3.27 + self.socket.close()
3.28
3.29 lib.log("Trying to stop FFmpeg process")
3.30 if (self.child_pid != None):
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/gmyth-stream/plugins/media/mencoder.py Fri Mar 30 23:07:54 2007 +0100
4.3 @@ -0,0 +1,97 @@
4.4 +import os
4.5 +import sys
4.6 +import lib
4.7 +import time
4.8 +import socket
4.9 +import ConfigParser
4.10 +
4.11 +class Media:
4.12 +
4.13 + def __init__(self, config):
4.14 +
4.15 + self.config = config
4.16 + self.socket = None
4.17 + self.child_pid = None
4.18 +
4.19 + def setup(self, filename, mux, vcodec, vbitrate,\
4.20 + fps, acodec, abitrate, width, height, port):
4.21 +
4.22 + self.filename = filename
4.23 + self.mux = mux
4.24 + self.vcodec = vcodec
4.25 + self.vbitrate = int(vbitrate)
4.26 + self.fps = int(fps)
4.27 + self.acodec = acodec
4.28 + self.abitrate = int(abitrate)
4.29 + self.width = int(width)
4.30 + self.height = int(height)
4.31 +
4.32 + self.port = int(port)
4.33 + self.fifo = self.config.get("Mencoder", "fifo_path")
4.34 +
4.35 + try:
4.36 + os.mkfifo(self.fifo)
4.37 + except:
4.38 + lib.log("Fifo already exists")
4.39 +
4.40 + # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
4.41 + self.path = self.config.get("Mencoder", "path")
4.42 + self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
4.43 + " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
4.44 + " -o %s 1> /dev/null 2> /dev/null" % (
4.45 + self.filename, self.fps, self.mux, self.acodec, self.abitrate,
4.46 + self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
4.47 +
4.48 +
4.49 + if (self.socket != None):
4.50 + del(self.socket)
4.51 +
4.52 + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
4.53 + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
4.54 + self.socket.bind( ('', self.port) )
4.55 + self.socket.settimeout(10)
4.56 + self.socket.listen(1)
4.57 +
4.58 + def play(self):
4.59 +
4.60 + lib.log("Starting Mencoder: %s" % self.path )
4.61 + # exec Mencoder
4.62 + pin, pout = os.popen2(self.path)
4.63 + pin.close()
4.64 +
4.65 + fifo = open(self.fifo)
4.66 +
4.67 + self.child_pid = os.fork()
4.68 + if (self.child_pid == 0):
4.69 + conn,addr= self.socket.accept()
4.70 + lib.log("Sending Data to client: %s" % addr[0])
4.71 +
4.72 + data = fifo.read(4096)
4.73 + conn.settimeout(5)
4.74 + retry = 0
4.75 +
4.76 + while( data != "" and retry < 5):
4.77 + try:
4.78 + conn.send(data)
4.79 + except socket.error:
4.80 + lib.log("Socket error (maybe timeout ?)")
4.81 + retry += 1
4.82 +
4.83 + data = fifo.read(4096)
4.84 +
4.85 + if (retry < 5):
4.86 + lib.log("Finished sending Data to client: %s" % addr[0])
4.87 + else:
4.88 + lib.log("Client timed out")
4.89 +
4.90 + pout.close()
4.91 +
4.92 + def stop(self):
4.93 +
4.94 + if (self.socket != None):
4.95 + lib.log("Closing socket")
4.96 + self.socket.close()
4.97 +
4.98 + lib.log("Trying to stop Mencoder process")
4.99 + if (self.child_pid != None):
4.100 + os.kill(self.child_pid, 9)
5.1 --- a/gmyth-stream/stream.conf Fri Mar 30 04:12:52 2007 +0100
5.2 +++ b/gmyth-stream/stream.conf Fri Mar 30 23:07:54 2007 +0100
5.3 @@ -4,7 +4,7 @@
5.4
5.5
5.6 [Media]
5.7 -engine = ffmpeg
5.8 +engine = mencoder
5.9
5.10
5.11 [Vlc]
5.12 @@ -16,3 +16,8 @@
5.13
5.14 [FFmpeg]
5.15 path = /usr/bin/ffmpeg
5.16 +
5.17 +
5.18 +[Mencoder]
5.19 +path = /usr/local/bin/mencoder
5.20 +fifo_path = /tmp/teste
6.1 --- a/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 04:12:52 2007 +0100
6.2 +++ b/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 23:07:54 2007 +0100
6.3 @@ -35,7 +35,7 @@
6.4
6.5 pin.close()
6.6 pout.close()
6.7 -
6.8 +socket.close()
6.9
6.10 # from select import select
6.11 # r, w, x = select([pout], []. [], 0)