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