mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
examples/filesrc.py: Port to 0.10.
Original commit message from CVS: reviewed by: Edward Hervey <edward@fluendo.com> * examples/filesrc.py: Port to 0.10.
This commit is contained in:
parent
b6866c55bf
commit
78e97adb23
2 changed files with 38 additions and 16 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2006-04-27 Johan Rydberg <jrydberg@gnu.org>
|
||||||
|
|
||||||
|
reviewed by: Edward Hervey <edward@fluendo.com>
|
||||||
|
|
||||||
|
* examples/filesrc.py: Port to 0.10.
|
||||||
|
|
||||||
2006-05-27 Edward Hervey <edward@fluendo.com>
|
2006-05-27 Edward Hervey <edward@fluendo.com>
|
||||||
|
|
||||||
* examples/audio-controller.py:
|
* examples/audio-controller.py:
|
||||||
|
|
|
@ -25,35 +25,42 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import gobject
|
import gobject
|
||||||
|
import pygst
|
||||||
|
pygst.require('0.10')
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
class FileSource(gst.Element):
|
class FileSource(gst.BaseSrc):
|
||||||
|
__gsttemplates__ = (
|
||||||
|
gst.PadTemplate("src",
|
||||||
|
gst.PAD_SRC,
|
||||||
|
gst.PAD_ALWAYS,
|
||||||
|
gst.caps_new_any()),
|
||||||
|
)
|
||||||
|
|
||||||
blocksize = 4096
|
blocksize = 4096
|
||||||
fd = None
|
fd = None
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.__gobject_init__()
|
self.__gobject_init__()
|
||||||
|
self.curoffset = 0
|
||||||
self.set_name(name)
|
self.set_name(name)
|
||||||
self.srcpad = gst.Pad('src', gst.PAD_SRC)
|
|
||||||
self.srcpad.set_get_function(self.srcpad_get)
|
|
||||||
self.add_pad(self.srcpad)
|
|
||||||
|
|
||||||
def set_property(self, name, value):
|
def set_property(self, name, value):
|
||||||
if name == 'location':
|
if name == 'location':
|
||||||
self.fd = open(value, 'r')
|
self.fd = open(value, 'r')
|
||||||
|
|
||||||
def srcpad_get(self, pad):
|
def do_create(self, offset, size):
|
||||||
|
if offset != self.curoffset:
|
||||||
|
self.fd.seek(offset, 0)
|
||||||
data = self.fd.read(self.blocksize)
|
data = self.fd.read(self.blocksize)
|
||||||
if data:
|
if data:
|
||||||
return gst.Buffer(data)
|
self.curoffset += len(data)
|
||||||
|
return gst.FLOW_OK, gst.Buffer(data)
|
||||||
else:
|
else:
|
||||||
self.set_eos()
|
return gst.FLOW_UNEXPECTED, None
|
||||||
return gst.Event(gst.EVENT_EOS)
|
|
||||||
gobject.type_register(FileSource)
|
gobject.type_register(FileSource)
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
print 'This example is not finished yet.'
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(args) != 3:
|
if len(args) != 3:
|
||||||
print 'Usage: %s input output' % (args[0])
|
print 'Usage: %s input output' % (args[0])
|
||||||
return -1
|
return -1
|
||||||
|
@ -61,21 +68,30 @@ def main(args):
|
||||||
bin = gst.Pipeline('pipeline')
|
bin = gst.Pipeline('pipeline')
|
||||||
|
|
||||||
filesrc = FileSource('filesource')
|
filesrc = FileSource('filesource')
|
||||||
#filesrc = gst.Element('filesrc', 'src')
|
|
||||||
assert filesrc
|
assert filesrc
|
||||||
filesrc.set_property('location', args[1])
|
filesrc.set_property('location', args[1])
|
||||||
|
|
||||||
filesink = gst.element_factory_make('filesink', 'sink')
|
filesink = gst.element_factory_make('filesink', 'sink')
|
||||||
filesink.set_property('location', args[2])
|
filesink.set_property('location', args[2])
|
||||||
|
|
||||||
bin.add_many(filesrc, filesink)
|
bin.add(filesrc, filesink)
|
||||||
gst.element_link_many(filesrc, filesink)
|
gst.element_link_many(filesrc, filesink)
|
||||||
|
|
||||||
bin.set_state(gst.STATE_PLAYING);
|
bin.set_state(gst.STATE_PLAYING);
|
||||||
|
mainloop = gobject.MainLoop()
|
||||||
|
|
||||||
while bin.iterate():
|
def bus_event(bus, message):
|
||||||
pass
|
t = message.type
|
||||||
|
if t == gst.MESSAGE_EOS:
|
||||||
|
mainloop.quit()
|
||||||
|
elif t == gst.MESSAGE_ERROR:
|
||||||
|
err, debug = message.parse_error()
|
||||||
|
print "Error: %s" % err, debug
|
||||||
|
mainloop.quit()
|
||||||
|
return True
|
||||||
|
bin.get_bus().add_watch(bus_event)
|
||||||
|
|
||||||
|
mainloop.run()
|
||||||
bin.set_state(gst.STATE_NULL)
|
bin.set_state(gst.STATE_NULL)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue