Adding gst-python package
[platform/upstream/gst-python.git] / old_examples / f2f.py
1 #!/usr/bin/env python
2 # -*- Mode: Python -*-
3 # vi:si:et:sw=4:sts=4:ts=4
4
5 # gst-python
6 # Copyright (C) 2002 David I. Lehn
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Library General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Library General Public License for more details.
17 #
18 # You should have received a copy of the GNU Library General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
22
23 # Author: David I. Lehn <dlehn@users.sourceforge.net>
24 #
25
26 import sys
27
28 import pygst
29 pygst.require('0.10')
30
31 import gst
32
33 def handoff_cb(sender, *args):
34    print sender.get_name(), args
35
36 def main(args):
37    # create a new bin to hold the elements
38    #gst_debug_set_categories(-1)
39    bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 signal-handoffs=true ! ' +
40                           'fakesink name=sink silent=1 signal-handoffs=true')
41    source = bin.get_by_name('source')
42    source.connect('handoff', handoff_cb)
43    source.get_pad("src").connect("have-data", handoff_cb)
44    sink = bin.get_by_name('sink')
45    sink.connect('handoff', handoff_cb)
46    sink.get_pad("sink").connect('have-data', handoff_cb)
47
48    print source, sink
49
50    bus = bin.get_bus()
51    
52    res = bin.set_state(gst.STATE_PLAYING);
53    assert res
54
55    while 1:
56       msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)
57       if msg:
58          break
59
60    res = bin.set_state(gst.STATE_NULL)
61    assert res
62
63 if __name__ == '__main__':
64    sys.exit(main(sys.argv))