# HG changeset patch # User morphbr # Date 1175292474 -3600 # Node ID 2eef408853227196b3ed09dd764ae3c42c2e8376 # Parent 57833200a4150bdcd90b66635e5f8c0b603afcbe [svn r476] * GMyth-Stream: - Bug fixes - Improved error handling - Created Mencoder plugin diff -r 57833200a415 -r 2eef40885322 gmyth-stream/main.py --- a/gmyth-stream/main.py Fri Mar 30 04:12:52 2007 +0100 +++ b/gmyth-stream/main.py Fri Mar 30 23:07:54 2007 +0100 @@ -42,7 +42,7 @@ server.Ack("SETUP") else: - lib.log("Wrong SETUP command from: %s" % client) + lib.log("Wrong SETUP command from: %s" % client[0]) elif (msg == "PLAY"): media.play() diff -r 57833200a415 -r 2eef40885322 gmyth-stream/plugins/comm/tcp.py --- a/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 04:12:52 2007 +0100 +++ b/gmyth-stream/plugins/comm/tcp.py Fri Mar 30 23:07:54 2007 +0100 @@ -10,6 +10,7 @@ self.finish = 0 self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.tcp.bind( (self.host, self.port) ) self.tcp.listen(1) diff -r 57833200a415 -r 2eef40885322 gmyth-stream/plugins/media/ffmpeg.py --- a/gmyth-stream/plugins/media/ffmpeg.py Fri Mar 30 04:12:52 2007 +0100 +++ b/gmyth-stream/plugins/media/ffmpeg.py Fri Mar 30 23:07:54 2007 +0100 @@ -38,13 +38,13 @@ del(self.socket) self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.bind( ('', self.port) ) self.socket.settimeout(10) + self.socket.listen(1) def play(self): - self.socket.listen(1) - lib.log("Starting FFmpeg: %s" % self.path) # exec FFmpeg and get stdout @@ -82,8 +82,9 @@ def stop(self): - lib.log("Closing socket") - self.socket.close() + if (self.socket != None): + lib.log("Closing socket") + self.socket.close() lib.log("Trying to stop FFmpeg process") if (self.child_pid != None): diff -r 57833200a415 -r 2eef40885322 gmyth-stream/plugins/media/mencoder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/plugins/media/mencoder.py Fri Mar 30 23:07:54 2007 +0100 @@ -0,0 +1,97 @@ +import os +import sys +import lib +import time +import socket +import ConfigParser + +class Media: + + def __init__(self, config): + + self.config = config + self.socket = None + self.child_pid = None + + def setup(self, filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port): + + self.filename = filename + self.mux = mux + self.vcodec = vcodec + self.vbitrate = int(vbitrate) + self.fps = int(fps) + self.acodec = acodec + self.abitrate = int(abitrate) + self.width = int(width) + self.height = int(height) + + self.port = int(port) + self.fifo = self.config.get("Mencoder", "fifo_path") + + try: + os.mkfifo(self.fifo) + except: + lib.log("Fifo already exists") + + # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 + self.path = self.config.get("Mencoder", "path") + self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\ + " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\ + " -o %s 1> /dev/null 2> /dev/null" % ( + self.filename, self.fps, self.mux, self.acodec, self.abitrate, + self.vcodec, self.vbitrate, self.width, self.height, self.fifo) + + + if (self.socket != None): + del(self.socket) + + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.bind( ('', self.port) ) + self.socket.settimeout(10) + self.socket.listen(1) + + def play(self): + + lib.log("Starting Mencoder: %s" % self.path ) + # exec Mencoder + pin, pout = os.popen2(self.path) + pin.close() + + fifo = open(self.fifo) + + self.child_pid = os.fork() + if (self.child_pid == 0): + conn,addr= self.socket.accept() + lib.log("Sending Data to client: %s" % addr[0]) + + data = fifo.read(4096) + conn.settimeout(5) + retry = 0 + + while( data != "" and retry < 5): + try: + conn.send(data) + except socket.error: + lib.log("Socket error (maybe timeout ?)") + retry += 1 + + data = fifo.read(4096) + + if (retry < 5): + lib.log("Finished sending Data to client: %s" % addr[0]) + else: + lib.log("Client timed out") + + pout.close() + + def stop(self): + + if (self.socket != None): + lib.log("Closing socket") + self.socket.close() + + lib.log("Trying to stop Mencoder process") + if (self.child_pid != None): + os.kill(self.child_pid, 9) diff -r 57833200a415 -r 2eef40885322 gmyth-stream/stream.conf --- a/gmyth-stream/stream.conf Fri Mar 30 04:12:52 2007 +0100 +++ b/gmyth-stream/stream.conf Fri Mar 30 23:07:54 2007 +0100 @@ -4,7 +4,7 @@ [Media] -engine = ffmpeg +engine = mencoder [Vlc] @@ -16,3 +16,8 @@ [FFmpeg] path = /usr/bin/ffmpeg + + +[Mencoder] +path = /usr/local/bin/mencoder +fifo_path = /tmp/teste diff -r 57833200a415 -r 2eef40885322 gmyth-stream/tests/client_ffmpeg.py --- a/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 04:12:52 2007 +0100 +++ b/gmyth-stream/tests/client_ffmpeg.py Fri Mar 30 23:07:54 2007 +0100 @@ -35,7 +35,7 @@ pin.close() pout.close() - +socket.close() # from select import select # r, w, x = select([pout], []. [], 0)