gmyth-stream/plugins/media/gstreamer.py
author morphbr
Tue Mar 27 00:13:27 2007 +0100 (2007-03-27)
branchtrunk
changeset 453 a806d8ad0ff0
child 466 a7aba7d166fb
permissions -rw-r--r--
[svn r458]
     1  '''
     2  # GMyth-Stream
     3  #
     4  # @file main.py
     5  #
     6  # @brief <p> Plugin for GMyth-Stream
     7  #
     8  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  # @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  #
    11  #
    12  # This program is free software; you can redistribute it and/or modify
    13  # it under the terms of the GNU Lesser General Public License as published by
    14  # the Free Software Foundation; either version 2 of the License, or
    15  # (at your option) any later version.
    16  #
    17  # This program is distributed in the hope that it will be useful,
    18  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  # GNU General Public License for more details.
    21  #
    22  # You should have received a copy of the GNU Lesser General Public License
    23  # along with this program; if not, write to the Free Software
    24  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  #
    26  '''
    27 
    28 import pygst
    29 pygst.require("0.10")
    30 import gst
    31 import gobject
    32 
    33 class Media:
    34 
    35     def __init__(self, config):
    36 
    37         # set gstreamer basic options
    38         self.config = config
    39         self.pipe = ""
    40 
    41     def setup(self, filename, codec, bitrate, width, height, port):
    42 
    43         self.filename = filename
    44         self.codec = codec
    45         self.bitrate = int(bitrate)
    46         self.width = int(width)
    47         self.height = int(height)
    48         self.port = int(port)
    49 
    50         ## Pipelines
    51 
    52         #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\
    53         #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \
    54         #! rtph263ppay ! udpsink  host=224.0.0.1 port=5000
    55 
    56 
    57         #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\
    58         #!  udpsink name=upd_audio host=224.0.0.1 port=5002
    59 
    60         self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\
    61                     "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\
    62                     " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
    63                     "queue  ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
    64                     "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
    65                                                 self.bitrate, self.port, self.port+2)
    66 
    67         #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
    68 
    69         self.pipeline = gst.parse_launch(self.pipe)
    70 
    71 
    72     def play(self):
    73 
    74         print "Trying to play pipeline: %s" % self.pipe
    75         try:
    76             if (self.pipeline):
    77                 self.pipeline.set_state(gst.STATE_PLAYING)
    78         except gobject.GError, e:
    79             print "Error: " + str(e)
    80 
    81 
    82     def stop(self):
    83 
    84         print "Trying to stop pipeline: %s" % self.pipe
    85         try:
    86             if (self.pipeline):
    87                 self.pipeline.set_state(gst.STATE_NULL)
    88         except gobject.GError, e:
    89             print "Error: " + str(e)
    90