morphbr@453: ''' morphbr@453: # GMyth-Stream morphbr@453: # morphbr@453: # @file main.py morphbr@453: # morphbr@453: # @brief

Plugin for GMyth-Stream morphbr@453: # morphbr@453: # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. morphbr@453: # @author Artur Duque de Souza morphbr@453: # morphbr@453: # morphbr@453: # This program is free software; you can redistribute it and/or modify morphbr@453: # it under the terms of the GNU Lesser General Public License as published by morphbr@453: # the Free Software Foundation; either version 2 of the License, or morphbr@453: # (at your option) any later version. morphbr@453: # morphbr@453: # This program is distributed in the hope that it will be useful, morphbr@453: # but WITHOUT ANY WARRANTY; without even the implied warranty of morphbr@453: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the morphbr@453: # GNU General Public License for more details. morphbr@453: # morphbr@453: # You should have received a copy of the GNU Lesser General Public License morphbr@453: # along with this program; if not, write to the Free Software morphbr@453: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA morphbr@453: # morphbr@453: ''' morphbr@453: morphbr@453: import pygst morphbr@453: pygst.require("0.10") morphbr@453: import gst morphbr@453: import gobject morphbr@453: morphbr@453: class Media: morphbr@453: morphbr@453: def __init__(self, config): morphbr@453: morphbr@453: # set gstreamer basic options morphbr@453: self.config = config morphbr@453: self.pipe = "" morphbr@453: morphbr@453: def setup(self, filename, codec, bitrate, width, height, port): morphbr@453: morphbr@453: self.filename = filename morphbr@453: self.codec = codec morphbr@453: self.bitrate = int(bitrate) morphbr@453: self.width = int(width) morphbr@453: self.height = int(height) morphbr@453: self.port = int(port) morphbr@453: morphbr@453: ## Pipelines morphbr@453: morphbr@453: #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\ morphbr@453: #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \ morphbr@453: #! rtph263ppay ! udpsink host=224.0.0.1 port=5000 morphbr@453: morphbr@453: morphbr@453: #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\ morphbr@453: #! udpsink name=upd_audio host=224.0.0.1 port=5002 morphbr@453: morphbr@453: self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\ morphbr@453: "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\ morphbr@453: " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\ morphbr@453: "queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\ morphbr@453: "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\ morphbr@453: self.bitrate, self.port, self.port+2) morphbr@453: morphbr@453: #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink" morphbr@453: morphbr@453: self.pipeline = gst.parse_launch(self.pipe) morphbr@453: morphbr@453: morphbr@453: def play(self): morphbr@453: morphbr@453: print "Trying to play pipeline: %s" % self.pipe morphbr@453: try: morphbr@453: if (self.pipeline): morphbr@453: self.pipeline.set_state(gst.STATE_PLAYING) morphbr@453: except gobject.GError, e: morphbr@453: print "Error: " + str(e) morphbr@453: morphbr@453: morphbr@453: def stop(self): morphbr@453: morphbr@453: print "Trying to stop pipeline: %s" % self.pipe morphbr@453: try: morphbr@453: if (self.pipeline): morphbr@453: self.pipeline.set_state(gst.STATE_NULL) morphbr@453: except gobject.GError, e: morphbr@453: print "Error: " + str(e) morphbr@453: