1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gmyth-stream/plugins/media/gstreamer.py Tue Mar 27 00:13:27 2007 +0100
1.3 @@ -0,0 +1,90 @@
1.4 + '''
1.5 + # GMyth-Stream
1.6 + #
1.7 + # @file main.py
1.8 + #
1.9 + # @brief <p> Plugin for GMyth-Stream
1.10 + #
1.11 + # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
1.12 + # @author Artur Duque de Souza <artur.souza@indt.org.br>
1.13 + #
1.14 + #
1.15 + # This program is free software; you can redistribute it and/or modify
1.16 + # it under the terms of the GNU Lesser General Public License as published by
1.17 + # the Free Software Foundation; either version 2 of the License, or
1.18 + # (at your option) any later version.
1.19 + #
1.20 + # This program is distributed in the hope that it will be useful,
1.21 + # but WITHOUT ANY WARRANTY; without even the implied warranty of
1.22 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.23 + # GNU General Public License for more details.
1.24 + #
1.25 + # You should have received a copy of the GNU Lesser General Public License
1.26 + # along with this program; if not, write to the Free Software
1.27 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.28 + #
1.29 + '''
1.30 +
1.31 +import pygst
1.32 +pygst.require("0.10")
1.33 +import gst
1.34 +import gobject
1.35 +
1.36 +class Media:
1.37 +
1.38 + def __init__(self, config):
1.39 +
1.40 + # set gstreamer basic options
1.41 + self.config = config
1.42 + self.pipe = ""
1.43 +
1.44 + def setup(self, filename, codec, bitrate, width, height, port):
1.45 +
1.46 + self.filename = filename
1.47 + self.codec = codec
1.48 + self.bitrate = int(bitrate)
1.49 + self.width = int(width)
1.50 + self.height = int(height)
1.51 + self.port = int(port)
1.52 +
1.53 + ## Pipelines
1.54 +
1.55 + #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\
1.56 + #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \
1.57 + #! rtph263ppay ! udpsink host=224.0.0.1 port=5000
1.58 +
1.59 +
1.60 + #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\
1.61 + #! udpsink name=upd_audio host=224.0.0.1 port=5002
1.62 +
1.63 + self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\
1.64 + "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\
1.65 + " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
1.66 + "queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
1.67 + "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
1.68 + self.bitrate, self.port, self.port+2)
1.69 +
1.70 + #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
1.71 +
1.72 + self.pipeline = gst.parse_launch(self.pipe)
1.73 +
1.74 +
1.75 + def play(self):
1.76 +
1.77 + print "Trying to play pipeline: %s" % self.pipe
1.78 + try:
1.79 + if (self.pipeline):
1.80 + self.pipeline.set_state(gst.STATE_PLAYING)
1.81 + except gobject.GError, e:
1.82 + print "Error: " + str(e)
1.83 +
1.84 +
1.85 + def stop(self):
1.86 +
1.87 + print "Trying to stop pipeline: %s" % self.pipe
1.88 + try:
1.89 + if (self.pipeline):
1.90 + self.pipeline.set_state(gst.STATE_NULL)
1.91 + except gobject.GError, e:
1.92 + print "Error: " + str(e)
1.93 +