2004-08-12 15:00:17 +00:00
|
|
|
#!/usr/bin/env python
|
2005-11-19 10:37:58 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
2004-08-12 15:00:17 +00:00
|
|
|
# GStreamer python bindings
|
|
|
|
# Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
|
|
|
|
# 2004 Johan Dahlin <johan@gnome.org>
|
|
|
|
#
|
|
|
|
# filesrc.py: implements a file source element completely in python
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
import sys
|
|
|
|
import gobject
|
2006-05-27 12:13:46 +00:00
|
|
|
import pygst
|
|
|
|
pygst.require('0.10')
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
import gst
|
|
|
|
|
2006-05-27 12:13:46 +00:00
|
|
|
class FileSource(gst.BaseSrc):
|
|
|
|
__gsttemplates__ = (
|
|
|
|
gst.PadTemplate("src",
|
|
|
|
gst.PAD_SRC,
|
|
|
|
gst.PAD_ALWAYS,
|
|
|
|
gst.caps_new_any()),
|
|
|
|
)
|
|
|
|
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
blocksize = 4096
|
|
|
|
fd = None
|
2006-05-27 12:13:46 +00:00
|
|
|
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
def __init__(self, name):
|
|
|
|
self.__gobject_init__()
|
2006-05-27 12:13:46 +00:00
|
|
|
self.curoffset = 0
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
self.set_name(name)
|
|
|
|
|
|
|
|
def set_property(self, name, value):
|
|
|
|
if name == 'location':
|
|
|
|
self.fd = open(value, 'r')
|
2006-05-27 12:13:46 +00:00
|
|
|
|
|
|
|
def do_create(self, offset, size):
|
|
|
|
if offset != self.curoffset:
|
|
|
|
self.fd.seek(offset, 0)
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
data = self.fd.read(self.blocksize)
|
|
|
|
if data:
|
2006-05-27 12:13:46 +00:00
|
|
|
self.curoffset += len(data)
|
|
|
|
return gst.FLOW_OK, gst.Buffer(data)
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
else:
|
2006-05-27 12:13:46 +00:00
|
|
|
return gst.FLOW_UNEXPECTED, None
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
gobject.type_register(FileSource)
|
|
|
|
|
|
|
|
def main(args):
|
|
|
|
if len(args) != 3:
|
|
|
|
print 'Usage: %s input output' % (args[0])
|
|
|
|
return -1
|
|
|
|
|
|
|
|
bin = gst.Pipeline('pipeline')
|
|
|
|
|
|
|
|
filesrc = FileSource('filesource')
|
2004-08-12 15:00:17 +00:00
|
|
|
assert filesrc
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
filesrc.set_property('location', args[1])
|
|
|
|
|
2004-10-11 09:55:44 +00:00
|
|
|
filesink = gst.element_factory_make('filesink', 'sink')
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
filesink.set_property('location', args[2])
|
|
|
|
|
2006-05-27 12:13:46 +00:00
|
|
|
bin.add(filesrc, filesink)
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
gst.element_link_many(filesrc, filesink)
|
|
|
|
|
|
|
|
bin.set_state(gst.STATE_PLAYING);
|
2006-05-27 12:13:46 +00:00
|
|
|
mainloop = gobject.MainLoop()
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
|
2006-05-27 12:13:46 +00:00
|
|
|
def bus_event(bus, message):
|
|
|
|
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)
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
|
2006-05-27 12:13:46 +00:00
|
|
|
mainloop.run()
|
examples/gstreamer/filesrc.py,player.py: New examples
Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-27 18:01:52 +00:00
|
|
|
bin.set_state(gst.STATE_NULL)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|
|
|
|
|