~ubuntu-branches/ubuntu/precise/gst0.10-python/precise

« back to all changes in this revision

Viewing changes to examples/filesrc.py

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2006-06-25 19:37:45 UTC
  • Revision ID: james.westby@ubuntu.com-20060625193745-9yeg0wq56r24n57x
Tags: upstream-0.10.4
ImportĀ upstreamĀ versionĀ 0.10.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- Mode: Python -*-
 
3
# vi:si:et:sw=4:sts=4:ts=4
 
4
 
 
5
# GStreamer python bindings
 
6
# Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
 
7
#               2004 Johan Dahlin  <johan@gnome.org>
 
8
#
 
9
# filesrc.py: implements a file source element completely in python
 
10
#
 
11
# This library is free software; you can redistribute it and/or
 
12
# modify it under the terms of the GNU Library General Public
 
13
# License as published by the Free Software Foundation; either
 
14
# version 2 of the License, or (at your option) any later version.
 
15
#
 
16
# This library is distributed in the hope that it will be useful,
 
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
# Library General Public License for more details.
 
20
#
 
21
# You should have received a copy of the GNU Library General Public
 
22
# License along with this library; if not, write to the
 
23
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
24
# Boston, MA 02111-1307, USA.
 
25
 
 
26
import sys
 
27
import gobject
 
28
import gst
 
29
 
 
30
class FileSource(gst.Element):
 
31
    blocksize = 4096
 
32
    fd = None
 
33
    def __init__(self, name):
 
34
        self.__gobject_init__()
 
35
        self.set_name(name)
 
36
        self.srcpad = gst.Pad('src', gst.PAD_SRC)
 
37
        self.srcpad.set_get_function(self.srcpad_get)
 
38
        self.add_pad(self.srcpad)
 
39
            
 
40
    def set_property(self, name, value):
 
41
        if name == 'location':
 
42
            self.fd = open(value, 'r')
 
43
            
 
44
    def srcpad_get(self, pad):
 
45
        data = self.fd.read(self.blocksize)
 
46
        if data:
 
47
            return gst.Buffer(data)
 
48
        else:
 
49
            self.set_eos()
 
50
            return gst.Event(gst.EVENT_EOS)
 
51
gobject.type_register(FileSource)
 
52
 
 
53
def main(args):
 
54
    print 'This example is not finished yet.'
 
55
    return
 
56
 
 
57
    if len(args) != 3:
 
58
        print 'Usage: %s input output' % (args[0])
 
59
        return -1
 
60
    
 
61
    bin = gst.Pipeline('pipeline')
 
62
 
 
63
    filesrc = FileSource('filesource')
 
64
    #filesrc = gst.Element('filesrc', 'src')
 
65
    assert filesrc
 
66
    filesrc.set_property('location', args[1])
 
67
   
 
68
    filesink = gst.element_factory_make('filesink', 'sink')
 
69
    filesink.set_property('location', args[2])
 
70
 
 
71
    bin.add_many(filesrc, filesink)
 
72
    gst.element_link_many(filesrc, filesink)
 
73
    
 
74
    bin.set_state(gst.STATE_PLAYING);
 
75
 
 
76
    while bin.iterate():
 
77
        pass
 
78
 
 
79
    bin.set_state(gst.STATE_NULL)
 
80
 
 
81
if __name__ == '__main__':
 
82
   sys.exit(main(sys.argv))
 
83