From a37dede09ce2ce5109322d325e0a48082effbc5f Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 27 Feb 2004 18:01:52 +0000 Subject: [PATCH] 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. --- ChangeLog | 23 ++ common | 2 +- examples/gst/filesrc.py | 54 ++++ examples/gst/identity.py | 10 +- examples/gst/player.py | 41 +++ examples/gstreamer/filesrc.py | 54 ++++ examples/gstreamer/identity.py | 10 +- examples/gstreamer/player.py | 41 +++ gst/0.6.c | 30 --- gst/0.6.defs | 42 --- gst/0.6.h | 24 -- gst/0.6.override | 188 ------------- gst/0.7.c | 25 -- gst/0.7.defs | 15 -- gst/0.7.h | 20 -- gst/0.7.override | 245 ----------------- gst/Makefile.am | 53 ++-- gst/arg-types.py | 6 +- gst/common.c | 64 ----- gst/common.defs | 71 ----- gst/common.h | 34 --- gst/common.override | 414 ----------------------------- gst/gst-types.c | 9 +- gst/gst-types.defs | 6 +- gst/gst.defs | 19 +- gst/gstmodule.c | 2 +- gst/gstpad-handlers.override | 258 ++++++++++++++++++ gst/gstpad.override | 258 ++++++++++++++++++ gst/gstreamer.defs | 19 +- gst/gstreamermodule.c | 2 +- gstreamer/0.6.c | 30 --- gstreamer/0.6.defs | 42 --- gstreamer/0.6.h | 24 -- gstreamer/0.6.override | 188 ------------- gstreamer/0.7.c | 25 -- gstreamer/0.7.defs | 15 -- gstreamer/0.7.h | 20 -- gstreamer/0.7.override | 245 ----------------- gstreamer/Makefile.am | 53 ++-- gstreamer/arg-types.py | 6 +- gstreamer/common.c | 64 ----- gstreamer/common.defs | 71 ----- gstreamer/common.h | 34 --- gstreamer/common.override | 414 ----------------------------- gstreamer/gst-types.c | 9 +- gstreamer/gst-types.defs | 6 +- gstreamer/gst.defs | 19 +- gstreamer/gstmodule.c | 2 +- gstreamer/gstpad-handlers.override | 258 ++++++++++++++++++ gstreamer/gstreamer.defs | 19 +- gstreamer/gstreamermodule.c | 2 +- 51 files changed, 1130 insertions(+), 2455 deletions(-) create mode 100755 examples/gst/filesrc.py create mode 100755 examples/gst/player.py create mode 100644 examples/gstreamer/filesrc.py create mode 100644 examples/gstreamer/player.py delete mode 100644 gst/0.6.c delete mode 100644 gst/0.6.defs delete mode 100644 gst/0.6.h delete mode 100644 gst/0.6.override delete mode 100644 gst/0.7.c delete mode 100644 gst/0.7.defs delete mode 100644 gst/0.7.h delete mode 100644 gst/0.7.override delete mode 100644 gst/common.c delete mode 100644 gst/common.defs delete mode 100644 gst/common.h delete mode 100644 gst/common.override create mode 100644 gst/gstpad-handlers.override create mode 100644 gst/gstpad.override delete mode 100644 gstreamer/0.6.c delete mode 100644 gstreamer/0.6.defs delete mode 100644 gstreamer/0.6.h delete mode 100644 gstreamer/0.6.override delete mode 100644 gstreamer/0.7.c delete mode 100644 gstreamer/0.7.defs delete mode 100644 gstreamer/0.7.h delete mode 100644 gstreamer/0.7.override delete mode 100644 gstreamer/common.c delete mode 100644 gstreamer/common.defs delete mode 100644 gstreamer/common.h delete mode 100644 gstreamer/common.override create mode 100644 gstreamer/gstpad-handlers.override diff --git a/ChangeLog b/ChangeLog index dfa2f4e292..f6ed49fd16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2004-02-27 Johan Dahlin + + * 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-25 Johan Dahlin * gstreamer/gstreamer.override: diff --git a/common b/common index 0945c85c4c..874dab5c34 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 0945c85c4c9139e2e5b8e04d0fc841b8aa1e6e9b +Subproject commit 874dab5c3461ad7487f1ae029256b6da82dddf6d diff --git a/examples/gst/filesrc.py b/examples/gst/filesrc.py new file mode 100755 index 0000000000..f6e06e597b --- /dev/null +++ b/examples/gst/filesrc.py @@ -0,0 +1,54 @@ +import sys +import gobject +import gst + +class FileSource(gst.Element): + blocksize = 4096 + fd = None + def __init__(self, name): + self.__gobject_init__() + 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): + if name == 'location': + self.fd = open(value, 'r') + + def srcpad_get(self, pad): + data = self.fd.read(self.blocksize) + if data: + return gst.Buffer(data) + else: + self.set_eos() + return gst.Event(gst.EVENT_EOS) +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') + #filesrc = gst.Element('filesrc', 'src') + filesrc.set_property('location', args[1]) + + filesink = gst.Element('filesink', 'sink') + filesink.set_property('location', args[2]) + + bin.add_many(filesrc, filesink) + gst.element_link_many(filesrc, filesink) + + bin.set_state(gst.STATE_PLAYING); + + while bin.iterate(): + pass + + bin.set_state(gst.STATE_NULL) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/examples/gst/identity.py b/examples/gst/identity.py index 8f037a8dd4..ac84bb02c7 100755 --- a/examples/gst/identity.py +++ b/examples/gst/identity.py @@ -2,6 +2,7 @@ # # gst-python # Copyright (C) 2002 David I. Lehn +# 2004 Johan Dahlin # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -57,8 +58,13 @@ def filter(element): filesrc = gst.Element('sinesrc', 'source'); filesink = gst.Element('fakesink', 'sink') - bin.add_many(filesrc, element, filesink) - gst.element_link_many(filesrc, element, filesink) + stats = gst.Element('statistics', 'stats'); + stats.set_property('silent', False) + stats.set_property('buffer_update_freq', True) + stats.set_property('update_on_eos', True) + + bin.add_many(filesrc, element, stats, filesink) + gst.element_link_many(filesrc, element, stats, filesink) # start playing bin.set_state(gst.STATE_PLAYING); diff --git a/examples/gst/player.py b/examples/gst/player.py new file mode 100755 index 0000000000..ebd3db0cc8 --- /dev/null +++ b/examples/gst/player.py @@ -0,0 +1,41 @@ +import os +import sys + +import gst + +def found_tags(element, source, tags): + print 'Artist:', tags.get('artist') + print 'Title: ', tags.get('title') + print 'Album: ', tags.get('album') + +def playfile(filename): + bin = gst.Pipeline('player') + + source = gst.Element('filesrc', 'src') + source.set_property('location', filename) + + spider = gst.Element('spider', 'spider') + spider.connect('found-tag', found_tags) + + sink = gst.Element('osssink', 'sink') + + bin.add_many(source, spider, sink) + gst.element_link_many(source, spider, sink) + + print 'Playing:', os.path.basename(filename) + bin.set_state(gst.STATE_PLAYING) + + try: + while bin.iterate(): + pass + except KeyboardInterrupt: + pass + + bin.set_state(gst.STATE_NULL) + +def main(args): + map(playfile, args[1:]) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/examples/gstreamer/filesrc.py b/examples/gstreamer/filesrc.py new file mode 100644 index 0000000000..f6e06e597b --- /dev/null +++ b/examples/gstreamer/filesrc.py @@ -0,0 +1,54 @@ +import sys +import gobject +import gst + +class FileSource(gst.Element): + blocksize = 4096 + fd = None + def __init__(self, name): + self.__gobject_init__() + 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): + if name == 'location': + self.fd = open(value, 'r') + + def srcpad_get(self, pad): + data = self.fd.read(self.blocksize) + if data: + return gst.Buffer(data) + else: + self.set_eos() + return gst.Event(gst.EVENT_EOS) +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') + #filesrc = gst.Element('filesrc', 'src') + filesrc.set_property('location', args[1]) + + filesink = gst.Element('filesink', 'sink') + filesink.set_property('location', args[2]) + + bin.add_many(filesrc, filesink) + gst.element_link_many(filesrc, filesink) + + bin.set_state(gst.STATE_PLAYING); + + while bin.iterate(): + pass + + bin.set_state(gst.STATE_NULL) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/examples/gstreamer/identity.py b/examples/gstreamer/identity.py index 8f037a8dd4..ac84bb02c7 100755 --- a/examples/gstreamer/identity.py +++ b/examples/gstreamer/identity.py @@ -2,6 +2,7 @@ # # gst-python # Copyright (C) 2002 David I. Lehn +# 2004 Johan Dahlin # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -57,8 +58,13 @@ def filter(element): filesrc = gst.Element('sinesrc', 'source'); filesink = gst.Element('fakesink', 'sink') - bin.add_many(filesrc, element, filesink) - gst.element_link_many(filesrc, element, filesink) + stats = gst.Element('statistics', 'stats'); + stats.set_property('silent', False) + stats.set_property('buffer_update_freq', True) + stats.set_property('update_on_eos', True) + + bin.add_many(filesrc, element, stats, filesink) + gst.element_link_many(filesrc, element, stats, filesink) # start playing bin.set_state(gst.STATE_PLAYING); diff --git a/examples/gstreamer/player.py b/examples/gstreamer/player.py new file mode 100644 index 0000000000..ebd3db0cc8 --- /dev/null +++ b/examples/gstreamer/player.py @@ -0,0 +1,41 @@ +import os +import sys + +import gst + +def found_tags(element, source, tags): + print 'Artist:', tags.get('artist') + print 'Title: ', tags.get('title') + print 'Album: ', tags.get('album') + +def playfile(filename): + bin = gst.Pipeline('player') + + source = gst.Element('filesrc', 'src') + source.set_property('location', filename) + + spider = gst.Element('spider', 'spider') + spider.connect('found-tag', found_tags) + + sink = gst.Element('osssink', 'sink') + + bin.add_many(source, spider, sink) + gst.element_link_many(source, spider, sink) + + print 'Playing:', os.path.basename(filename) + bin.set_state(gst.STATE_PLAYING) + + try: + while bin.iterate(): + pass + except KeyboardInterrupt: + pass + + bin.set_state(gst.STATE_NULL) + +def main(args): + map(playfile, args[1:]) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/gst/0.6.c b/gst/0.6.c deleted file mode 100644 index 6820f91827..0000000000 --- a/gst/0.6.c +++ /dev/null @@ -1,30 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "0.6.h" - -GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry) -{ - return gst_props_entry_get_type(entry); -} diff --git a/gst/0.6.defs b/gst/0.6.defs deleted file mode 100644 index d76da3c93b..0000000000 --- a/gst/0.6.defs +++ /dev/null @@ -1,42 +0,0 @@ -;; -;; Override normal *_get_type handling via rename -;; - -(define-method get_props_type - (of-object "GstPropsEntry") - (c-name "gst_props_entry_get_props_type") - (return-type "GstPropsType") -) - -;; -;; Access GstProps properties list -;; - -(define-method get_list - (of-object "GstProps") - (c-name "gst_props_get_list") - (return-type "const-GList*") -) - -;; -;; 0.6 Boxed types -;; - -(define-boxed BufferPool - (in-module "Gst") - (c-name "GstBufferPool") - (gtype-id "GST_TYPE_BUFFER_POOL") -) - -(define-boxed Props - (in-module "Gst") - (c-name "GstProps") - (gtype-id "GST_TYPE_PROPS") -) - -(define-boxed PropsEntry - (in-module "Gst") - (c-name "GstPropsEntry") - (gtype-id "GST_TYPE_PROPS_ENTRY") -) - diff --git a/gst/0.6.h b/gst/0.6.h deleted file mode 100644 index ff0bcac68b..0000000000 --- a/gst/0.6.h +++ /dev/null @@ -1,24 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include - -GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry); diff --git a/gst/0.6.override b/gst/0.6.override deleted file mode 100644 index 829b64c918..0000000000 --- a/gst/0.6.override +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "0.6.h" -%% -override gst_props_entry_get_int - -static PyObject * -_wrap_gst_props_entry_get_int(PyObject *self) -{ - gboolean ret; - gint val; - - val = 0; - ret = gst_props_entry_get_int(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bi)", ret, val); -} -%% -override gst_props_entry_get_float - -static PyObject * -_wrap_gst_props_entry_get_float(PyObject *self) -{ - gboolean ret; - gfloat val; - - val = 0.0f; - ret = gst_props_entry_get_float(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bf)", ret, val); -} -%% -override gst_props_entry_get_fourcc_int - -static PyObject * -_wrap_gst_props_entry_get_fourcc_int(PyObject *self) -{ - gboolean ret; - gint32 val; - - val = 0; - ret = gst_props_entry_get_fourcc_int(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bi)", ret, val); -} -%% -override gst_props_entry_get_boolean - -static PyObject * -_wrap_gst_props_entry_get_boolean(PyObject *self) -{ - gboolean ret; - gboolean val; - PyObject *py_val; - - val = FALSE; - ret = gst_props_entry_get_boolean(pyg_boxed_get(self, GstPropsEntry), &val); - - py_val = val ? Py_True : Py_False; - return Py_BuildValue("(bO)", ret, py_val); -} -%% -override gst_props_entry_get_string - -static PyObject * -_wrap_gst_props_entry_get_string(PyObject *self) -{ - gboolean ret; - const gchar *val; - - val = NULL; - ret = gst_props_entry_get_string(pyg_boxed_get(self, GstPropsEntry), &val); - if (ret) { - return Py_BuildValue("(bs)", ret, val); - } else { - return Py_BuildValue("(bO)", ret, Py_None); - } -} -%% -override gst_props_entry_get_int_range - -static PyObject * -_wrap_gst_props_entry_get_int_range(PyObject *self) -{ - gboolean ret; - gint min, max; - - min = max = 0; - ret = gst_props_entry_get_int_range(pyg_boxed_get(self, GstPropsEntry), &min, &max); - return Py_BuildValue("(bii)", ret, min, max); -} -%% -override gst_props_entry_get_float_range - -static PyObject * -_wrap_gst_props_entry_get_float_range(PyObject *self) -{ - gboolean ret; - gfloat min, max; - - min = max = 0.0f; - ret = gst_props_entry_get_float_range(pyg_boxed_get(self, GstPropsEntry), &min, &max); - return Py_BuildValue("(bff)", ret, min, max); -} -%% -override gst_props_entry_get_list - - - -static PyObject * -_wrap_gst_props_entry_get_list(PyObject *self) -{ - gboolean ret; - const GList *list; - PyObject *tuple, *obj; - int i; - - list = NULL; - ret = gst_props_entry_get_list(pyg_boxed_get(self, GstPropsEntry), &list); - if (ret == TRUE) { - tuple = PyTuple_New(g_list_length((GList *) list)); - for (i = 0; list != NULL; i++, list = g_list_next(list)) { - obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE); - PyTuple_SET_ITEM(tuple, i, obj); - } - } else { - tuple = Py_None; - Py_INCREF(tuple); - } - return Py_BuildValue("(bO)", ret, tuple); -} -%% -override gst_props_get_list - -static gboolean -gst_props_get_list(GstProps *props, GList **list) -{ - *list = GST_PROPS_PROPERTIES(props); - return TRUE; -} - -static PyObject * -_wrap_gst_props_get_list(PyObject *self) -{ - gboolean ret; - GList *list; - PyObject *tuple, *obj; - int i; - - list = NULL; - ret = gst_props_get_list(pyg_boxed_get(self, GstProps), &list); - if (ret == TRUE) { - tuple = PyTuple_New(g_list_length(list)); - for (i = 0; list != NULL; i++, list = g_list_next(list)) { - obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE); - PyTuple_SET_ITEM(tuple, i, obj); - } - } else { - tuple = Py_None; - Py_INCREF(tuple); - } - return Py_BuildValue("(bO)", ret, tuple); -} - - diff --git a/gst/0.7.c b/gst/0.7.c deleted file mode 100644 index b8eb17723e..0000000000 --- a/gst/0.7.c +++ /dev/null @@ -1,25 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "0.7.h" diff --git a/gst/0.7.defs b/gst/0.7.defs deleted file mode 100644 index 0dee3720d6..0000000000 --- a/gst/0.7.defs +++ /dev/null @@ -1,15 +0,0 @@ -;; -;; 0.7 Boxed types -;; - -(define-boxed Structure - (in-module "Gst") - (c-name "GstStructure") - (gtype-id "GST_TYPE_STRUCTURE") -) - -(define-boxed TagList - (in-module "Gst") - (c-name "GstTagList") - (gtype-id "GST_TYPE_TAG_LIST") -) diff --git a/gst/0.7.h b/gst/0.7.h deleted file mode 100644 index 66d2bf1897..0000000000 --- a/gst/0.7.h +++ /dev/null @@ -1,20 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ diff --git a/gst/0.7.override b/gst/0.7.override deleted file mode 100644 index 4f9350f55d..0000000000 --- a/gst/0.7.override +++ /dev/null @@ -1,245 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "0.7.h" -%% -override gst_structure_new kwargs - -static int -_wrap_gst_structure_new(PyGBoxed *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "name", NULL }; - char *name; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:GstStructure.__init__", kwlist, &name)) - return -1; - self->gtype = GST_TYPE_STRUCTURE; - self->free_on_dealloc = FALSE; - self->boxed = gst_structure_new(name, NULL); - - if (!self->boxed) { - PyErr_SetString(PyExc_RuntimeError, "could not create GstStructure object"); - return -1; - } - self->free_on_dealloc = TRUE; - return 0; -} -%% -override gst_structure_set_value kwargs - -static PyObject * -_wrap_gst_structure_set_value(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "field", "value", NULL }; - char *field; - PyObject *py_value = NULL; - GValue value = { 0 }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:GstStructure.set_value", kwlist, &field, &py_value)) - return NULL; - g_value_init(&value, G_TYPE_STRING); - if (pyg_value_from_pyobject(&value, py_value) != 0) { - return NULL; - } - gst_structure_set_value(pyg_boxed_get(self, GstStructure), field, &value); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_structure_foreach kwargs - -static gboolean -pygst_structure_foreach_marshal(GQuark field_id, - GValue *value, - gpointer user_data) -{ - PyGstCustomNotify *cunote = user_data; - PyObject *py_field, *py_value, *retobj; - gboolean retval = TRUE; - - g_assert(cunote->func); - - pyg_block_threads(); - - //py_model = pygobject_new((GObject *)model); - //py_path = pygtk_tree_path_to_pyobject(path); - //py_iter = pyg_boxed_new(GTK_TYPE_TREE_ITER, iter, TRUE, TRUE); - py_field = Py_BuildValue("s", g_quark_to_string(field_id)); - py_value = pyg_value_as_pyobject(value, FALSE); - if (cunote->data) - retobj = PyEval_CallFunction(cunote->func, "(NNO)", - py_field, py_value, - cunote->data); - else - retobj = PyEval_CallFunction(cunote->func, "(NN)", - py_field, py_value); - - if (PyErr_Occurred () || (retobj == NULL) || (retobj == Py_None)) { - PyErr_Print (); - retval = FALSE; - } else if (retobj != Py_None) { - retval = PyInt_AsLong(retobj); - } - - Py_XDECREF(retobj); - - pyg_unblock_threads(); - - return retval; -} - -static PyObject * -_wrap_gst_structure_foreach (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "foreach_function", "args", NULL }; - PyObject *pyfunc, *pyarg = NULL; - PyGstCustomNotify cunote; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|O:GstStructure.foreach", - kwlist, - &pyfunc, &pyarg)) { - return NULL; - } - - if (!PyCallable_Check(pyfunc)) { - PyErr_SetString(PyExc_TypeError, "foreach_function not callable"); - return NULL; - } - - cunote.func = pyfunc; - cunote.data = pyarg; - gst_structure_foreach(pyg_boxed_get(self, GstStructure), - pygst_structure_foreach_marshal, - &cunote); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_tag_list_foreach kwargs - -static gboolean -pygst_tag_list_foreach_marshal(GstTagList *list, - const gchar *tag, - gpointer user_data) -{ - PyGstCustomNotify *cunote = user_data; - PyGObject *py_list; - PyObject *py_key, *retobj; - gboolean retval = TRUE; - - g_assert(cunote->func); - - pyg_block_threads(); - - py_list = pyg_boxed_new(GST_TYPE_TAG_LIST, list, TRUE, TRUE); - py_key = Py_BuildValue("s", tag); - if (cunote->data) - retobj = PyEval_CallFunction(cunote->func, "(NNO)", - py_list, - py_key, - cunote->data); - else - retobj = PyEval_CallFunction(cunote->func, "(NN)", - py_list, - py_key); - - if (PyErr_Occurred () || (retobj == NULL) || (retobj == Py_None)) { - PyErr_Print (); - retval = FALSE; - } else if (retobj != Py_None) { - retval = PyInt_AsLong(retobj); - } - - Py_XDECREF(retobj); - - pyg_unblock_threads(); - - return retval; -} - -static PyObject * -_wrap_gst_tag_list_foreach (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "foreach_function", "args", NULL }; - PyObject *pyfunc, *pyarg = NULL; - PyGstCustomNotify cunote; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|O:GstTagList.foreach", - kwlist, - &pyfunc, &pyarg)) { - return NULL; - } - - if (!PyCallable_Check(pyfunc)) { - PyErr_SetString(PyExc_TypeError, "foreach_function not callable"); - return NULL; - } - - cunote.func = pyfunc; - cunote.data = pyarg; - gst_tag_list_foreach(pyg_boxed_get(self, GstTagList), - pygst_tag_list_foreach_marshal, - &cunote); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_tag_list_get_value_index kwargs - -static PyObject * -_wrap_gst_tag_list_get_value_index (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "tag", "index", NULL }; - char *tag; - int index; - GValue *gvalue; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "si:GstTagList.get_value_index", - kwlist, - &tag, &index)) { - return NULL; - } - - gvalue = gst_tag_list_get_value_index(pyg_boxed_get(self, GstTagList), - tag, - index); - - return pyg_value_as_pyobject(gvalue, FALSE); -} diff --git a/gst/Makefile.am b/gst/Makefile.am index f7a3938320..3c736cfd0b 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -1,5 +1,3 @@ -MODULE = gstreamer - INCLUDES = $(PYTHON_INCLUDES) $(PYGTK_CFLAGS) PYGTK_DEFSDIR = @PYGTK_DEFSDIR@ @@ -15,50 +13,31 @@ pygstreamer_PYTHON = gstreamer.py pygstexecdir = $(pkgpyexecdir) -GST_OVERRIDES = common.override \ - 0.6.override \ - 0.7.override -GST_DEFS = common.defs \ - 0.6.defs \ - 0.7.defs -GST_CODE = common.c common.h \ - 0.6.c 0.6.h \ - 0.7.c 0.7.h - -# Ugly hack to pick the proper version code. -# Just setting to $(GST_MAJORMINOR).{ch} will not work -if GST_0_6 -VERSOURCES = 0.6.c 0.6.h -endif -if GST_0_7 -VERSOURCES = 0.7.c 0.7.h -endif +GST_OVERRIDES = \ + gstreamer.override \ + gstpad-handlers.override pygstexec_LTLIBRARIES = _gstmodule.la _gstmodule_la_SOURCES = \ - gstreamermodule.c \ - gst-types.c \ - common.c \ - common.h \ + gstreamermodule.c \ + gst-types.c \ $(VERSOURCES) + _gstmodule_la_CFLAGS = $(GST_CFLAGS) -fno-strict-aliasing _gstmodule_la_LIBADD = $(GST_LIBS) _gstmodule_la_LDFLAGS = -module -avoid-version -export-symbols-regex init_gst -nodist__gstmodule_la_SOURCES = $(MODULE).c +nodist__gstmodule_la_SOURCES = gstreamer.c -CLEANFILES = $(MODULE).c -EXTRA_DIST = $(MODULE).defs $(GST_OVERRIDES) $(GST_DEFS) $(GST_CODE) arg-types.py +CLEANFILES = gstreamer.c +EXTRA_DIST = gstreamer.defs $(GST_OVERRIDES) arg-types.py -GST_EXCLUDE_INCLUDES=\ - $(GST_INCLUDEDIR)/gst/gstatomic_impl.h \ - $(GST_INCLUDEDIR)/gst/gstcompat.h -GST_INCLUDES=$(filter-out $(GST_EXCLUDE_INCLUDES),$(wildcard $(GST_INCLUDEDIR)/gst/*.h)) - -gstreamer.c: $(srcdir)/$(MODULE).defs $(srcdir)/arg-types.py $(srcdir)/$(MODULE).override +gstreamer.c: $(srcdir)/gstreamer.defs $(srcdir)/arg-types.py $(GST_OVERRIDES) $(PYGTK_CODEGEN) \ --load-types $(srcdir)/arg-types.py \ --register $(srcdir)/gst-types.defs \ - --override $(srcdir)/$(MODULE).override \ - --prefix pygst $(MODULE).defs > gen-$(MODULE).c \ - && cp gen-$(MODULE).c $(MODULE).c \ - && rm -f gen-$(MODULE).c + --override $(srcdir)/gstreamer.override \ + --prefix pygst gstreamer.defs > gen-gstreamer.c \ + && rm -fr gtreamer.c \ + && echo '/* GENERATED FILE - DO NOT EDIT */' >> gstreamer.c \ + && cat gen-gstreamer.c >> gstreamer.c \ + && rm -f gen-gstreamer.c diff --git a/gst/arg-types.py b/gst/arg-types.py index 189d178b54..3fc393b32d 100644 --- a/gst/arg-types.py +++ b/gst/arg-types.py @@ -28,7 +28,7 @@ class GstDataPtrArg(ArgType): ' return NULL;\n') null = (' if (py_%(name)s == Py_None)\n' ' %(name)s = NULL;\n' - ' else if (pyst_data_from_pyobject(py_%(name)s, &%(name)s_rect))\n' + ' else if (pyst_data_from_pyobject(py_%(name)s, %(name)s_rect))\n' ' %(name)s = &%(name)s_rect;\n' ' else\n' ' return NULL;\n') @@ -41,10 +41,10 @@ class GstDataPtrArg(ArgType): info.arglist.append(pname) info.codebefore.append(self.null % {'name': pname}) else: - info.varlist.add('GstData', pname) + info.varlist.add('GstData*', pname) info.varlist.add('PyObject', '*py_' + pname) info.add_parselist('O', ['&py_' + pname], [pname]) - info.arglist.append('&' + pname) + info.arglist.append(pname) info.codebefore.append(self.normal % {'name': pname}) arg = GstDataPtrArg() diff --git a/gst/common.c b/gst/common.c deleted file mode 100644 index 841283b16b..0000000000 --- a/gst/common.c +++ /dev/null @@ -1,64 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "common.h" - -void iterate_bin_all(GstBin *bin) { - g_return_if_fail(bin != NULL); - g_return_if_fail(GST_IS_BIN(bin)); - - pyg_unblock_threads(); - while (gst_bin_iterate(bin)); - pyg_block_threads(); -} - -static gboolean iterate_bin(gpointer data) { - GstBin *bin; - - bin = GST_BIN(data); - return gst_bin_iterate(bin); -} - -static void iterate_bin_destroy(gpointer data) { - GstBin *bin; - - bin = GST_BIN(data); - gst_object_unref(GST_OBJECT(bin)); -} - -guint add_iterate_bin(GstBin *bin) { - g_return_val_if_fail(bin != NULL, FALSE); - g_return_val_if_fail(GST_IS_BIN(bin), FALSE); - - gst_object_ref(GST_OBJECT(bin)); - return g_idle_add_full( - G_PRIORITY_DEFAULT_IDLE, - iterate_bin, - bin, - iterate_bin_destroy); -} - -void remove_iterate_bin(guint id) { - g_source_remove(id); -} diff --git a/gst/common.defs b/gst/common.defs deleted file mode 100644 index 8215a6a158..0000000000 --- a/gst/common.defs +++ /dev/null @@ -1,71 +0,0 @@ -;; -*- scheme -*- -;; -;; Boxed types -;; - -(define-boxed Buffer - (in-module "Gst") - (c-name "GstBuffer") - (gtype-id "GST_TYPE_BUFFER") -) - -(define-boxed Caps - (in-module "Gst") - (c-name "GstCaps") - (gtype-id "GST_TYPE_CAPS") -) - -(define-boxed Event - (in-module "Gst") - (c-name "GstEvent") - (gtype-id "GST_TYPE_EVENT") -) - -;; -;; Accelerate common GstBin iterate loop -;; - -(define-function iterate_bin_all - (c-name "iterate_bin_all") - (return-type "none") - (parameters - '("GstBin*" "bin") - ) -) - -(define-function add_iterate_bin - (c-name "add_iterate_bin") - (return-type "guint") - (parameters - '("GstBin*" "bin") - ) -) - -(define-function remove_iterate_bin - (c-name "remove_iterate_bin") - (return-type "none") - (parameters - '("guint" "id") - ) -) - -;; -;; HACK -;; - -(define-method get_data - (of-object "GstBuffer") - (c-name "gst_buffer_get_data") - (return-type "char*") -) - -(define-method set_data - (of-object "GstBuffer") - (c-name "gst_buffer_set_data") - (return-type "none") - (parameters - '("char*" "data") - ) -) - - diff --git a/gst/common.h b/gst/common.h deleted file mode 100644 index c271193185..0000000000 --- a/gst/common.h +++ /dev/null @@ -1,34 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include -#include - -#include -#include - -typedef struct { - PyObject *func, *data; -} PyGstCustomNotify; - -void iterate_bin_all(GstBin *bin); -guint add_iterate_bin(GstBin *bin); -void remove_iterate_bin(guint id); diff --git a/gst/common.override b/gst/common.override deleted file mode 100644 index f93b430c60..0000000000 --- a/gst/common.override +++ /dev/null @@ -1,414 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "common.h" - -typedef struct { - PyGObject *pad; - PyObject *link_function; - PyObject *chain_function; -} PyGstPadPrivate; - -static PyGstPadPrivate* -pad_private(GstPad *pad) -{ - return (PyGstPadPrivate*)gst_pad_get_element_private(pad); -} - -static PyGstPadPrivate* -py_pad_private(PyGObject *pad) -{ - PyGstPadPrivate *private; - GstPad *gpad; - - gpad = (GstPad*)pygobject_get(pad); - private = (PyGstPadPrivate*)gst_pad_get_element_private(gpad); - if (private == NULL) { - /* FIXME need to free this somewhere */ - private = g_new0(PyGstPadPrivate, 1); - Py_INCREF(pad); - private->pad = pad; - gst_pad_set_element_private(gpad, private); - } - return private; -} - -%% -modulename gstreamer -%% -import gobject.GObject as PyGObject_Type -%% -ignore-glob - _* - gstreamer_*init - *_get_type -%% -override gst_pad_set_link_function kwargs - -static GstPadLinkReturn -call_link_function (GstPad *pad, GstCaps *caps) -{ - PyObject *function; - PyObject *retval; - GstPadLinkReturn ret; - - function = pad_private(pad)->link_function; - - pyg_block_threads(); - - retval = (PyObject*)PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_CAPS, caps, TRUE, TRUE)); - - if (PyErr_Occurred ()) { - PyErr_Print (); - pyg_unblock_threads(); - return GST_PAD_LINK_REFUSED; - } - - ret = PyInt_AsLong(retval); - - pyg_unblock_threads(); - - return ret; -} - -static PyObject* -_wrap_gst_pad_set_link_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "link_function", NULL }; - PyObject *link_function; - GstPad *pad; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GstPad.set_link_funcion", - kwlist, - &link_function)) { - return NULL; - } - - if (!PyCallable_Check(link_function)) { - PyErr_SetString(PyExc_TypeError, "link_function not callable"); - return NULL; - } - - Py_INCREF(link_function); - py_pad_private(self)->link_function = link_function; - pad = (GstPad*)pygobject_get(self); - gst_pad_set_link_function(pad, call_link_function); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_pad_set_chain_function kwargs - -static void -call_chain_function(GstPad *pad, GstData *data) -{ - PyObject *function; - - function = pad_private(pad)->chain_function; - - pyg_block_threads(); - - if (GST_IS_BUFFER(data)) { - PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_BUFFER, data, TRUE, TRUE)); - } else if (GST_IS_EVENT(data)) { - PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_EVENT, data, TRUE, TRUE)); - } - - if (PyErr_Occurred ()) { - PyErr_Print (); - pyg_unblock_threads(); - return; - } - - pyg_unblock_threads(); -} - -static PyObject* -_wrap_gst_pad_set_chain_function(PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "chain_function", NULL }; - PyObject *chain_function; - GstPad *pad; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GstPad.set_chain_funcion", - kwlist, - &chain_function)) { - return NULL; - } - - if (!PyCallable_Check(chain_function)) { - PyErr_SetString(PyExc_TypeError, "chain_function not callable"); - return NULL; - } - - Py_INCREF(chain_function); - py_pad_private(self)->chain_function = chain_function; - pad = (GstPad*)pygobject_get(self); - gst_pad_set_chain_function(pad, call_chain_function); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_buffer_get_data - -static PyObject* -_wrap_gst_buffer_get_data(PyObject *self) -{ - GstBuffer *buf; - - buf = pyg_boxed_get(self, GstBuffer); - - return PyString_FromStringAndSize( - GST_BUFFER_DATA(buf), - GST_BUFFER_SIZE(buf)); -} -%% -override gst_buffer_set_data kwargs - -static PyObject* -_wrap_gst_buffer_set_data(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = {"data", NULL}; - PyObject *data; - GstBuffer *buf; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstBuffer:set_data", kwlist, &data)) { - return NULL; - } - if (!PyString_Check(data)) { - PyErr_SetString(PyExc_TypeError, "data should be a string"); - return NULL; - } - buf = pyg_boxed_get(self, GstBuffer); - if (GST_BUFFER_FLAGS(buf) & GST_BUFFER_READONLY) { - PyErr_SetString(PyExc_TypeError, "set_data can't use a READONLY buffer"); - return NULL; - } - GST_BUFFER_SIZE(buf) = PyString_Size(data); - GST_BUFFER_DATA(buf) = g_new0(char, GST_BUFFER_SIZE(buf)); - - memcpy(GST_BUFFER_DATA(buf), - PyString_AsString(data), - PyString_Size(data)); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_bin_iterate - -static PyObject * -_wrap_gst_bin_iterate(PyGObject *self) -{ - int ret; - - pyg_unblock_threads(); - ret = gst_bin_iterate(GST_BIN(self->obj)); - pyg_block_threads(); - return PyInt_FromLong(ret); -} -%% -override gst_element_set_state kwargs - -static PyObject * -_wrap_gst_element_set_state(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "state", NULL }; - PyObject *py_state = NULL; - GstElementState state; - gint ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.set_state", kwlist, &py_state)) - return NULL; - if (pyg_flags_get_value(GST_TYPE_ELEMENT_STATE, py_state, (gint *)&state)) - return NULL; - pyg_unblock_threads(); - ret = gst_element_set_state(GST_ELEMENT(self->obj), state); - pyg_block_threads(); - return PyInt_FromLong(ret); -} -%% -override gst_pad_query kwargs - -static PyObject * -_wrap_gst_pad_query(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "type", "format", NULL }; - GstQueryType type; - GstFormat format; - gint64 value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GstPad.query", kwlist, &type, &format)) - return NULL; - value = 0; - ret = gst_pad_query(GST_PAD(self->obj), type, &format, &value); - return Py_BuildValue("(bL)", ret, value); -} -%% -override gst_element_query kwargs - -static PyObject * -_wrap_gst_element_query(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "type", "format", NULL }; - GstQueryType type; - GstFormat format; - gint64 value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GstElement.query", kwlist, &type, &format)) - return NULL; - value = 0; - ret = gst_element_query(GST_ELEMENT(self->obj), type, &format, &value); - return Py_BuildValue("(bL)", ret, value); -} -%% -override gst_pad_convert kwargs - -static PyObject * -_wrap_gst_pad_convert(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "src_format", "src_value", "dest_format", NULL }; - GstFormat src_format, dest_format; - PyObject *src_value_obj; - gint64 src_value, dest_value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iOi:GstPad.convert", kwlist, &src_format, &src_value_obj, &dest_format)) - return NULL; - src_value = PyLong_AsLongLong(src_value_obj); - dest_value = 0; - ret = gst_pad_convert(GST_PAD(self->obj), src_format, src_value, &dest_format, &dest_value); - return Py_BuildValue("(bL)", ret, dest_value); -} -%% -override gst_element_convert kwargs - -static PyObject * -_wrap_gst_element_convert(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "src_format", "src_value", "dest_format", NULL }; - GstFormat src_format, dest_format; - PyObject *src_value_obj; - gint64 src_value, dest_value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iOi:GstElement.convert", kwlist, &src_format, &src_value_obj, &dest_format)) - return NULL; - src_value = PyLong_AsLongLong(src_value_obj); - dest_value = 0; - ret = gst_element_convert(GST_ELEMENT(self->obj), src_format, src_value, &dest_format, &dest_value); - return Py_BuildValue("(bL)", ret, dest_value); -} -%% -override gst_element_factory_make_element - -/* we create this function to serve as a constructor for Element */ -static int -_wrap_gst_element_factory_make_element(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "factoryname", "name", NULL }; - char *factoryname, *name = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s:GstElement.__init__", kwlist, &factoryname, &name)) - return -1; - self->obj = (GObject *)gst_element_factory_make(factoryname, name); - - if (!self->obj) { - PyErr_SetString(PyExc_RuntimeError, "could not create GstElement object"); - return -1; - } - pygobject_register_wrapper((PyObject *)self); - return 0; -} -%% -override gst_version noargs - -static PyObject * -_wrap_gst_version(void) -{ - guint major, minor, micro; - - gst_version(&major, &minor, µ); - - return Py_BuildValue("(iii)", major, minor, micro); -} -%% -override gst_bin_add_many args -static PyObject * -_wrap_gst_bin_add_many(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - PyGObject *element; - int i; - int len; - - len = PyList_Size(args); - if (len == 0) - { - PyErr_SetString(PyExc_TypeError, "GstBin.add requires at least one argument"); - return NULL; - } - - - for (i = 0; i < len; i++) - { - element = (PyGObject*)PyList_GetItem(args, i); - if (!pygobject_check(element, &PyGstElement_Type)) - { - PyErr_SetString(PyExc_TypeError, "argument must be a GstElement"); - return NULL; - } - } - - for (i = 0; i < len; i++) - { - element = (PyGObject*)PyList_GetItem(args, i); - gst_bin_add(GST_BIN(self->obj), GST_ELEMENT(element->obj)); - } - - Py_INCREF(Py_None); - return Py_None; -} diff --git a/gst/gst-types.c b/gst/gst-types.c index aea315fb9b..2559cc2e3f 100644 --- a/gst/gst-types.c +++ b/gst/gst-types.c @@ -26,7 +26,7 @@ gboolean pygst_data_from_pyobject(PyObject *object, GstData **data) { g_return_val_if_fail(*data != NULL, FALSE); - + if (pyg_boxed_check(object, GST_TYPE_DATA)) { *data = pyg_boxed_get(object, GstData); return TRUE; @@ -58,14 +58,11 @@ PyGstData_to_value(GValue *value, PyObject *object) if (!pygst_data_from_pyobject(object, &data)) return -1; - - g_value_set_boxed(value, &data); + + g_value_set_boxed(value, data); return 0; } -/* We have to set ob_type here because stupid win32 does not allow you - * to use variables from another dll in a global variable initialisation. - */ void _pygst_register_boxed_types(PyObject *moddict) { diff --git a/gst/gst-types.defs b/gst/gst-types.defs index 74ec95bcb4..08c2e3f1ca 100644 --- a/gst/gst-types.defs +++ b/gst/gst-types.defs @@ -156,8 +156,8 @@ (in-module "Gst") (c-name "GstBuffer") (gtype-id "GST_TYPE_BUFFER") - (copy-func "gst_buffer_copy") - (release-func "gst_buffer_free") + (copy-func "gst_data_copy") + (release-func "gst_data_unref") ) (define-boxed Caps @@ -179,7 +179,7 @@ (c-name "GstEvent") (gtype-id "GST_TYPE_EVENT") (copy-func "gst_event_copy") - (release-func "gst_event_free") + (release-func "gst_data_unref") ) diff --git a/gst/gst.defs b/gst/gst.defs index 647528ca3e..9827fdab3f 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -1,6 +1,7 @@ ;; -*- scheme -*- (include "gst-types.defs") +;;(include "0.7.defs") ;; From /opt/gnome/include/gstreamer-0.7/gst/gstatomic.h @@ -1559,7 +1560,7 @@ (return-type "GstElement*") (parameters '("const-gchar*" "factoryname") - '("const-gchar*" "name") + '("const-gchar*" "name" (null-ok) (default "NULL")) ) ) @@ -5265,7 +5266,23 @@ (return-type "GstTagList*") ) +;; Added python method +(define-method keys + (of-object "GstTagList") + (c-name "pygst_tag_list_keys") +) +(define-method has_key + (of-object "GstTagList") + (c-name "pygst_tag_list_has_key") + (parameters '("gchar*" "key")) +) + +(define-method get + (of-object "GstTagList") + (c-name "pygst_tag_list_get") + (parameters '("gchar*" "key")) +) ;; From /opt/gnome/include/gstreamer-0.7/gst/gsttaginterface.h diff --git a/gst/gstmodule.c b/gst/gstmodule.c index ce1dce58bf..30508fa545 100644 --- a/gst/gstmodule.c +++ b/gst/gstmodule.c @@ -42,7 +42,7 @@ init_gst (void) char **argv; init_pygobject (); - + /* pull in arguments */ av = PySys_GetObject ("argv"); if (av != NULL) { diff --git a/gst/gstpad-handlers.override b/gst/gstpad-handlers.override new file mode 100644 index 0000000000..d00e8bea0e --- /dev/null +++ b/gst/gstpad-handlers.override @@ -0,0 +1,258 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2004 Johan Dahlin + * + * 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. + * + * Author: Johan Dahlin link_function; + + pyg_block_threads(); + + retval = (PyObject*)PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_CAPS, caps, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return GST_PAD_LINK_REFUSED; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_link_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "link_function", NULL }; + PyObject *link_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_link_funcion", + kwlist, + &link_function)) { + return NULL; + } + + if (!PyCallable_Check(link_function)) { + PyErr_SetString(PyExc_TypeError, "link_function not callable"); + return NULL; + } + + Py_INCREF(link_function); + py_pad_private(self)->link_function = link_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_link_function(pad, (GstPadLinkFunction)call_link_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_chain_function kwargs + +static void +call_chain_function(GstPad *pad, GstBuffer *buf) +{ + PyObject *function; + + function = pad_private(pad)->chain_function; + + pyg_block_threads(); + + PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_BUFFER, buf, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return; + } + + pyg_unblock_threads(); +} + +static PyObject* +_wrap_gst_pad_set_chain_function(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "chain_function", NULL }; + PyObject *chain_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_chain_funcion", + kwlist, + &chain_function)) { + return NULL; + } + + if (!PyCallable_Check(chain_function)) { + PyErr_SetString(PyExc_TypeError, "chain_function not callable"); + return NULL; + } + + Py_INCREF(chain_function); + py_pad_private(self)->chain_function = chain_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_chain_function(pad, (GstPadChainFunction)call_chain_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_event_function kwargs + +static gboolean +call_event_function (GstPad *pad, GstEvent *event) +{ + PyObject *function; + PyObject *retval; + gboolean ret; + + function = pad_private(pad)->event_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_EVENT, event, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return FALSE; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_event_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "event_function", NULL }; + PyObject *event_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_event_funcion", + kwlist, + &event_function)) { + return NULL; + } + + if (!PyCallable_Check(event_function)) { + PyErr_SetString(PyExc_TypeError, "event_function not callable"); + return NULL; + } + + Py_INCREF(event_function); + py_pad_private(self)->event_function = event_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_event_function(pad, (GstPadEventFunction)call_event_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_get_function kwargs + +static GstData* +call_get_function (GstPad *pad) +{ + PyObject *function; + PyObject *retval; + GstData *data = NULL; + + function = pad_private(pad)->get_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction(function, "O", pad_private(pad)->pad); + + if (PyErr_Occurred()) { + PyErr_Print(); + goto bail; + } else if (retval == Py_None) { + goto bail; + } + + pygst_data_from_pyobject(retval, &data); + +bail: + pyg_unblock_threads(); + return data; +} + +static PyObject* +_wrap_gst_pad_set_get_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "get_function", NULL }; + PyObject *get_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_get_funcion", + kwlist, + &get_function)) { + return NULL; + } + + if (!PyCallable_Check(get_function)) { + PyErr_SetString(PyExc_TypeError, "get_function not callable"); + return NULL; + } + + Py_INCREF(get_function); + py_pad_private(self)->get_function = get_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_get_function(pad, (GstPadGetFunction)call_get_function); + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/gst/gstpad.override b/gst/gstpad.override new file mode 100644 index 0000000000..d00e8bea0e --- /dev/null +++ b/gst/gstpad.override @@ -0,0 +1,258 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2004 Johan Dahlin + * + * 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. + * + * Author: Johan Dahlin link_function; + + pyg_block_threads(); + + retval = (PyObject*)PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_CAPS, caps, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return GST_PAD_LINK_REFUSED; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_link_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "link_function", NULL }; + PyObject *link_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_link_funcion", + kwlist, + &link_function)) { + return NULL; + } + + if (!PyCallable_Check(link_function)) { + PyErr_SetString(PyExc_TypeError, "link_function not callable"); + return NULL; + } + + Py_INCREF(link_function); + py_pad_private(self)->link_function = link_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_link_function(pad, (GstPadLinkFunction)call_link_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_chain_function kwargs + +static void +call_chain_function(GstPad *pad, GstBuffer *buf) +{ + PyObject *function; + + function = pad_private(pad)->chain_function; + + pyg_block_threads(); + + PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_BUFFER, buf, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return; + } + + pyg_unblock_threads(); +} + +static PyObject* +_wrap_gst_pad_set_chain_function(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "chain_function", NULL }; + PyObject *chain_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_chain_funcion", + kwlist, + &chain_function)) { + return NULL; + } + + if (!PyCallable_Check(chain_function)) { + PyErr_SetString(PyExc_TypeError, "chain_function not callable"); + return NULL; + } + + Py_INCREF(chain_function); + py_pad_private(self)->chain_function = chain_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_chain_function(pad, (GstPadChainFunction)call_chain_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_event_function kwargs + +static gboolean +call_event_function (GstPad *pad, GstEvent *event) +{ + PyObject *function; + PyObject *retval; + gboolean ret; + + function = pad_private(pad)->event_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_EVENT, event, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return FALSE; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_event_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "event_function", NULL }; + PyObject *event_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_event_funcion", + kwlist, + &event_function)) { + return NULL; + } + + if (!PyCallable_Check(event_function)) { + PyErr_SetString(PyExc_TypeError, "event_function not callable"); + return NULL; + } + + Py_INCREF(event_function); + py_pad_private(self)->event_function = event_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_event_function(pad, (GstPadEventFunction)call_event_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_get_function kwargs + +static GstData* +call_get_function (GstPad *pad) +{ + PyObject *function; + PyObject *retval; + GstData *data = NULL; + + function = pad_private(pad)->get_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction(function, "O", pad_private(pad)->pad); + + if (PyErr_Occurred()) { + PyErr_Print(); + goto bail; + } else if (retval == Py_None) { + goto bail; + } + + pygst_data_from_pyobject(retval, &data); + +bail: + pyg_unblock_threads(); + return data; +} + +static PyObject* +_wrap_gst_pad_set_get_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "get_function", NULL }; + PyObject *get_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_get_funcion", + kwlist, + &get_function)) { + return NULL; + } + + if (!PyCallable_Check(get_function)) { + PyErr_SetString(PyExc_TypeError, "get_function not callable"); + return NULL; + } + + Py_INCREF(get_function); + py_pad_private(self)->get_function = get_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_get_function(pad, (GstPadGetFunction)call_get_function); + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/gst/gstreamer.defs b/gst/gstreamer.defs index 647528ca3e..9827fdab3f 100644 --- a/gst/gstreamer.defs +++ b/gst/gstreamer.defs @@ -1,6 +1,7 @@ ;; -*- scheme -*- (include "gst-types.defs") +;;(include "0.7.defs") ;; From /opt/gnome/include/gstreamer-0.7/gst/gstatomic.h @@ -1559,7 +1560,7 @@ (return-type "GstElement*") (parameters '("const-gchar*" "factoryname") - '("const-gchar*" "name") + '("const-gchar*" "name" (null-ok) (default "NULL")) ) ) @@ -5265,7 +5266,23 @@ (return-type "GstTagList*") ) +;; Added python method +(define-method keys + (of-object "GstTagList") + (c-name "pygst_tag_list_keys") +) +(define-method has_key + (of-object "GstTagList") + (c-name "pygst_tag_list_has_key") + (parameters '("gchar*" "key")) +) + +(define-method get + (of-object "GstTagList") + (c-name "pygst_tag_list_get") + (parameters '("gchar*" "key")) +) ;; From /opt/gnome/include/gstreamer-0.7/gst/gsttaginterface.h diff --git a/gst/gstreamermodule.c b/gst/gstreamermodule.c index ce1dce58bf..30508fa545 100644 --- a/gst/gstreamermodule.c +++ b/gst/gstreamermodule.c @@ -42,7 +42,7 @@ init_gst (void) char **argv; init_pygobject (); - + /* pull in arguments */ av = PySys_GetObject ("argv"); if (av != NULL) { diff --git a/gstreamer/0.6.c b/gstreamer/0.6.c deleted file mode 100644 index 6820f91827..0000000000 --- a/gstreamer/0.6.c +++ /dev/null @@ -1,30 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "0.6.h" - -GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry) -{ - return gst_props_entry_get_type(entry); -} diff --git a/gstreamer/0.6.defs b/gstreamer/0.6.defs deleted file mode 100644 index d76da3c93b..0000000000 --- a/gstreamer/0.6.defs +++ /dev/null @@ -1,42 +0,0 @@ -;; -;; Override normal *_get_type handling via rename -;; - -(define-method get_props_type - (of-object "GstPropsEntry") - (c-name "gst_props_entry_get_props_type") - (return-type "GstPropsType") -) - -;; -;; Access GstProps properties list -;; - -(define-method get_list - (of-object "GstProps") - (c-name "gst_props_get_list") - (return-type "const-GList*") -) - -;; -;; 0.6 Boxed types -;; - -(define-boxed BufferPool - (in-module "Gst") - (c-name "GstBufferPool") - (gtype-id "GST_TYPE_BUFFER_POOL") -) - -(define-boxed Props - (in-module "Gst") - (c-name "GstProps") - (gtype-id "GST_TYPE_PROPS") -) - -(define-boxed PropsEntry - (in-module "Gst") - (c-name "GstPropsEntry") - (gtype-id "GST_TYPE_PROPS_ENTRY") -) - diff --git a/gstreamer/0.6.h b/gstreamer/0.6.h deleted file mode 100644 index ff0bcac68b..0000000000 --- a/gstreamer/0.6.h +++ /dev/null @@ -1,24 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include - -GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry); diff --git a/gstreamer/0.6.override b/gstreamer/0.6.override deleted file mode 100644 index 829b64c918..0000000000 --- a/gstreamer/0.6.override +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "0.6.h" -%% -override gst_props_entry_get_int - -static PyObject * -_wrap_gst_props_entry_get_int(PyObject *self) -{ - gboolean ret; - gint val; - - val = 0; - ret = gst_props_entry_get_int(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bi)", ret, val); -} -%% -override gst_props_entry_get_float - -static PyObject * -_wrap_gst_props_entry_get_float(PyObject *self) -{ - gboolean ret; - gfloat val; - - val = 0.0f; - ret = gst_props_entry_get_float(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bf)", ret, val); -} -%% -override gst_props_entry_get_fourcc_int - -static PyObject * -_wrap_gst_props_entry_get_fourcc_int(PyObject *self) -{ - gboolean ret; - gint32 val; - - val = 0; - ret = gst_props_entry_get_fourcc_int(pyg_boxed_get(self, GstPropsEntry), &val); - return Py_BuildValue("(bi)", ret, val); -} -%% -override gst_props_entry_get_boolean - -static PyObject * -_wrap_gst_props_entry_get_boolean(PyObject *self) -{ - gboolean ret; - gboolean val; - PyObject *py_val; - - val = FALSE; - ret = gst_props_entry_get_boolean(pyg_boxed_get(self, GstPropsEntry), &val); - - py_val = val ? Py_True : Py_False; - return Py_BuildValue("(bO)", ret, py_val); -} -%% -override gst_props_entry_get_string - -static PyObject * -_wrap_gst_props_entry_get_string(PyObject *self) -{ - gboolean ret; - const gchar *val; - - val = NULL; - ret = gst_props_entry_get_string(pyg_boxed_get(self, GstPropsEntry), &val); - if (ret) { - return Py_BuildValue("(bs)", ret, val); - } else { - return Py_BuildValue("(bO)", ret, Py_None); - } -} -%% -override gst_props_entry_get_int_range - -static PyObject * -_wrap_gst_props_entry_get_int_range(PyObject *self) -{ - gboolean ret; - gint min, max; - - min = max = 0; - ret = gst_props_entry_get_int_range(pyg_boxed_get(self, GstPropsEntry), &min, &max); - return Py_BuildValue("(bii)", ret, min, max); -} -%% -override gst_props_entry_get_float_range - -static PyObject * -_wrap_gst_props_entry_get_float_range(PyObject *self) -{ - gboolean ret; - gfloat min, max; - - min = max = 0.0f; - ret = gst_props_entry_get_float_range(pyg_boxed_get(self, GstPropsEntry), &min, &max); - return Py_BuildValue("(bff)", ret, min, max); -} -%% -override gst_props_entry_get_list - - - -static PyObject * -_wrap_gst_props_entry_get_list(PyObject *self) -{ - gboolean ret; - const GList *list; - PyObject *tuple, *obj; - int i; - - list = NULL; - ret = gst_props_entry_get_list(pyg_boxed_get(self, GstPropsEntry), &list); - if (ret == TRUE) { - tuple = PyTuple_New(g_list_length((GList *) list)); - for (i = 0; list != NULL; i++, list = g_list_next(list)) { - obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE); - PyTuple_SET_ITEM(tuple, i, obj); - } - } else { - tuple = Py_None; - Py_INCREF(tuple); - } - return Py_BuildValue("(bO)", ret, tuple); -} -%% -override gst_props_get_list - -static gboolean -gst_props_get_list(GstProps *props, GList **list) -{ - *list = GST_PROPS_PROPERTIES(props); - return TRUE; -} - -static PyObject * -_wrap_gst_props_get_list(PyObject *self) -{ - gboolean ret; - GList *list; - PyObject *tuple, *obj; - int i; - - list = NULL; - ret = gst_props_get_list(pyg_boxed_get(self, GstProps), &list); - if (ret == TRUE) { - tuple = PyTuple_New(g_list_length(list)); - for (i = 0; list != NULL; i++, list = g_list_next(list)) { - obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE); - PyTuple_SET_ITEM(tuple, i, obj); - } - } else { - tuple = Py_None; - Py_INCREF(tuple); - } - return Py_BuildValue("(bO)", ret, tuple); -} - - diff --git a/gstreamer/0.7.c b/gstreamer/0.7.c deleted file mode 100644 index b8eb17723e..0000000000 --- a/gstreamer/0.7.c +++ /dev/null @@ -1,25 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "0.7.h" diff --git a/gstreamer/0.7.defs b/gstreamer/0.7.defs deleted file mode 100644 index 0dee3720d6..0000000000 --- a/gstreamer/0.7.defs +++ /dev/null @@ -1,15 +0,0 @@ -;; -;; 0.7 Boxed types -;; - -(define-boxed Structure - (in-module "Gst") - (c-name "GstStructure") - (gtype-id "GST_TYPE_STRUCTURE") -) - -(define-boxed TagList - (in-module "Gst") - (c-name "GstTagList") - (gtype-id "GST_TYPE_TAG_LIST") -) diff --git a/gstreamer/0.7.h b/gstreamer/0.7.h deleted file mode 100644 index 66d2bf1897..0000000000 --- a/gstreamer/0.7.h +++ /dev/null @@ -1,20 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ diff --git a/gstreamer/0.7.override b/gstreamer/0.7.override deleted file mode 100644 index 4f9350f55d..0000000000 --- a/gstreamer/0.7.override +++ /dev/null @@ -1,245 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "0.7.h" -%% -override gst_structure_new kwargs - -static int -_wrap_gst_structure_new(PyGBoxed *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "name", NULL }; - char *name; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:GstStructure.__init__", kwlist, &name)) - return -1; - self->gtype = GST_TYPE_STRUCTURE; - self->free_on_dealloc = FALSE; - self->boxed = gst_structure_new(name, NULL); - - if (!self->boxed) { - PyErr_SetString(PyExc_RuntimeError, "could not create GstStructure object"); - return -1; - } - self->free_on_dealloc = TRUE; - return 0; -} -%% -override gst_structure_set_value kwargs - -static PyObject * -_wrap_gst_structure_set_value(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "field", "value", NULL }; - char *field; - PyObject *py_value = NULL; - GValue value = { 0 }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:GstStructure.set_value", kwlist, &field, &py_value)) - return NULL; - g_value_init(&value, G_TYPE_STRING); - if (pyg_value_from_pyobject(&value, py_value) != 0) { - return NULL; - } - gst_structure_set_value(pyg_boxed_get(self, GstStructure), field, &value); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_structure_foreach kwargs - -static gboolean -pygst_structure_foreach_marshal(GQuark field_id, - GValue *value, - gpointer user_data) -{ - PyGstCustomNotify *cunote = user_data; - PyObject *py_field, *py_value, *retobj; - gboolean retval = TRUE; - - g_assert(cunote->func); - - pyg_block_threads(); - - //py_model = pygobject_new((GObject *)model); - //py_path = pygtk_tree_path_to_pyobject(path); - //py_iter = pyg_boxed_new(GTK_TYPE_TREE_ITER, iter, TRUE, TRUE); - py_field = Py_BuildValue("s", g_quark_to_string(field_id)); - py_value = pyg_value_as_pyobject(value, FALSE); - if (cunote->data) - retobj = PyEval_CallFunction(cunote->func, "(NNO)", - py_field, py_value, - cunote->data); - else - retobj = PyEval_CallFunction(cunote->func, "(NN)", - py_field, py_value); - - if (PyErr_Occurred () || (retobj == NULL) || (retobj == Py_None)) { - PyErr_Print (); - retval = FALSE; - } else if (retobj != Py_None) { - retval = PyInt_AsLong(retobj); - } - - Py_XDECREF(retobj); - - pyg_unblock_threads(); - - return retval; -} - -static PyObject * -_wrap_gst_structure_foreach (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "foreach_function", "args", NULL }; - PyObject *pyfunc, *pyarg = NULL; - PyGstCustomNotify cunote; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|O:GstStructure.foreach", - kwlist, - &pyfunc, &pyarg)) { - return NULL; - } - - if (!PyCallable_Check(pyfunc)) { - PyErr_SetString(PyExc_TypeError, "foreach_function not callable"); - return NULL; - } - - cunote.func = pyfunc; - cunote.data = pyarg; - gst_structure_foreach(pyg_boxed_get(self, GstStructure), - pygst_structure_foreach_marshal, - &cunote); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_tag_list_foreach kwargs - -static gboolean -pygst_tag_list_foreach_marshal(GstTagList *list, - const gchar *tag, - gpointer user_data) -{ - PyGstCustomNotify *cunote = user_data; - PyGObject *py_list; - PyObject *py_key, *retobj; - gboolean retval = TRUE; - - g_assert(cunote->func); - - pyg_block_threads(); - - py_list = pyg_boxed_new(GST_TYPE_TAG_LIST, list, TRUE, TRUE); - py_key = Py_BuildValue("s", tag); - if (cunote->data) - retobj = PyEval_CallFunction(cunote->func, "(NNO)", - py_list, - py_key, - cunote->data); - else - retobj = PyEval_CallFunction(cunote->func, "(NN)", - py_list, - py_key); - - if (PyErr_Occurred () || (retobj == NULL) || (retobj == Py_None)) { - PyErr_Print (); - retval = FALSE; - } else if (retobj != Py_None) { - retval = PyInt_AsLong(retobj); - } - - Py_XDECREF(retobj); - - pyg_unblock_threads(); - - return retval; -} - -static PyObject * -_wrap_gst_tag_list_foreach (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "foreach_function", "args", NULL }; - PyObject *pyfunc, *pyarg = NULL; - PyGstCustomNotify cunote; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O|O:GstTagList.foreach", - kwlist, - &pyfunc, &pyarg)) { - return NULL; - } - - if (!PyCallable_Check(pyfunc)) { - PyErr_SetString(PyExc_TypeError, "foreach_function not callable"); - return NULL; - } - - cunote.func = pyfunc; - cunote.data = pyarg; - gst_tag_list_foreach(pyg_boxed_get(self, GstTagList), - pygst_tag_list_foreach_marshal, - &cunote); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_tag_list_get_value_index kwargs - -static PyObject * -_wrap_gst_tag_list_get_value_index (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "tag", "index", NULL }; - char *tag; - int index; - GValue *gvalue; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "si:GstTagList.get_value_index", - kwlist, - &tag, &index)) { - return NULL; - } - - gvalue = gst_tag_list_get_value_index(pyg_boxed_get(self, GstTagList), - tag, - index); - - return pyg_value_as_pyobject(gvalue, FALSE); -} diff --git a/gstreamer/Makefile.am b/gstreamer/Makefile.am index f7a3938320..3c736cfd0b 100644 --- a/gstreamer/Makefile.am +++ b/gstreamer/Makefile.am @@ -1,5 +1,3 @@ -MODULE = gstreamer - INCLUDES = $(PYTHON_INCLUDES) $(PYGTK_CFLAGS) PYGTK_DEFSDIR = @PYGTK_DEFSDIR@ @@ -15,50 +13,31 @@ pygstreamer_PYTHON = gstreamer.py pygstexecdir = $(pkgpyexecdir) -GST_OVERRIDES = common.override \ - 0.6.override \ - 0.7.override -GST_DEFS = common.defs \ - 0.6.defs \ - 0.7.defs -GST_CODE = common.c common.h \ - 0.6.c 0.6.h \ - 0.7.c 0.7.h - -# Ugly hack to pick the proper version code. -# Just setting to $(GST_MAJORMINOR).{ch} will not work -if GST_0_6 -VERSOURCES = 0.6.c 0.6.h -endif -if GST_0_7 -VERSOURCES = 0.7.c 0.7.h -endif +GST_OVERRIDES = \ + gstreamer.override \ + gstpad-handlers.override pygstexec_LTLIBRARIES = _gstmodule.la _gstmodule_la_SOURCES = \ - gstreamermodule.c \ - gst-types.c \ - common.c \ - common.h \ + gstreamermodule.c \ + gst-types.c \ $(VERSOURCES) + _gstmodule_la_CFLAGS = $(GST_CFLAGS) -fno-strict-aliasing _gstmodule_la_LIBADD = $(GST_LIBS) _gstmodule_la_LDFLAGS = -module -avoid-version -export-symbols-regex init_gst -nodist__gstmodule_la_SOURCES = $(MODULE).c +nodist__gstmodule_la_SOURCES = gstreamer.c -CLEANFILES = $(MODULE).c -EXTRA_DIST = $(MODULE).defs $(GST_OVERRIDES) $(GST_DEFS) $(GST_CODE) arg-types.py +CLEANFILES = gstreamer.c +EXTRA_DIST = gstreamer.defs $(GST_OVERRIDES) arg-types.py -GST_EXCLUDE_INCLUDES=\ - $(GST_INCLUDEDIR)/gst/gstatomic_impl.h \ - $(GST_INCLUDEDIR)/gst/gstcompat.h -GST_INCLUDES=$(filter-out $(GST_EXCLUDE_INCLUDES),$(wildcard $(GST_INCLUDEDIR)/gst/*.h)) - -gstreamer.c: $(srcdir)/$(MODULE).defs $(srcdir)/arg-types.py $(srcdir)/$(MODULE).override +gstreamer.c: $(srcdir)/gstreamer.defs $(srcdir)/arg-types.py $(GST_OVERRIDES) $(PYGTK_CODEGEN) \ --load-types $(srcdir)/arg-types.py \ --register $(srcdir)/gst-types.defs \ - --override $(srcdir)/$(MODULE).override \ - --prefix pygst $(MODULE).defs > gen-$(MODULE).c \ - && cp gen-$(MODULE).c $(MODULE).c \ - && rm -f gen-$(MODULE).c + --override $(srcdir)/gstreamer.override \ + --prefix pygst gstreamer.defs > gen-gstreamer.c \ + && rm -fr gtreamer.c \ + && echo '/* GENERATED FILE - DO NOT EDIT */' >> gstreamer.c \ + && cat gen-gstreamer.c >> gstreamer.c \ + && rm -f gen-gstreamer.c diff --git a/gstreamer/arg-types.py b/gstreamer/arg-types.py index 189d178b54..3fc393b32d 100644 --- a/gstreamer/arg-types.py +++ b/gstreamer/arg-types.py @@ -28,7 +28,7 @@ class GstDataPtrArg(ArgType): ' return NULL;\n') null = (' if (py_%(name)s == Py_None)\n' ' %(name)s = NULL;\n' - ' else if (pyst_data_from_pyobject(py_%(name)s, &%(name)s_rect))\n' + ' else if (pyst_data_from_pyobject(py_%(name)s, %(name)s_rect))\n' ' %(name)s = &%(name)s_rect;\n' ' else\n' ' return NULL;\n') @@ -41,10 +41,10 @@ class GstDataPtrArg(ArgType): info.arglist.append(pname) info.codebefore.append(self.null % {'name': pname}) else: - info.varlist.add('GstData', pname) + info.varlist.add('GstData*', pname) info.varlist.add('PyObject', '*py_' + pname) info.add_parselist('O', ['&py_' + pname], [pname]) - info.arglist.append('&' + pname) + info.arglist.append(pname) info.codebefore.append(self.normal % {'name': pname}) arg = GstDataPtrArg() diff --git a/gstreamer/common.c b/gstreamer/common.c deleted file mode 100644 index 841283b16b..0000000000 --- a/gstreamer/common.c +++ /dev/null @@ -1,64 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include "pygobject.h" -#include - -#include "common.h" - -void iterate_bin_all(GstBin *bin) { - g_return_if_fail(bin != NULL); - g_return_if_fail(GST_IS_BIN(bin)); - - pyg_unblock_threads(); - while (gst_bin_iterate(bin)); - pyg_block_threads(); -} - -static gboolean iterate_bin(gpointer data) { - GstBin *bin; - - bin = GST_BIN(data); - return gst_bin_iterate(bin); -} - -static void iterate_bin_destroy(gpointer data) { - GstBin *bin; - - bin = GST_BIN(data); - gst_object_unref(GST_OBJECT(bin)); -} - -guint add_iterate_bin(GstBin *bin) { - g_return_val_if_fail(bin != NULL, FALSE); - g_return_val_if_fail(GST_IS_BIN(bin), FALSE); - - gst_object_ref(GST_OBJECT(bin)); - return g_idle_add_full( - G_PRIORITY_DEFAULT_IDLE, - iterate_bin, - bin, - iterate_bin_destroy); -} - -void remove_iterate_bin(guint id) { - g_source_remove(id); -} diff --git a/gstreamer/common.defs b/gstreamer/common.defs deleted file mode 100644 index 8215a6a158..0000000000 --- a/gstreamer/common.defs +++ /dev/null @@ -1,71 +0,0 @@ -;; -*- scheme -*- -;; -;; Boxed types -;; - -(define-boxed Buffer - (in-module "Gst") - (c-name "GstBuffer") - (gtype-id "GST_TYPE_BUFFER") -) - -(define-boxed Caps - (in-module "Gst") - (c-name "GstCaps") - (gtype-id "GST_TYPE_CAPS") -) - -(define-boxed Event - (in-module "Gst") - (c-name "GstEvent") - (gtype-id "GST_TYPE_EVENT") -) - -;; -;; Accelerate common GstBin iterate loop -;; - -(define-function iterate_bin_all - (c-name "iterate_bin_all") - (return-type "none") - (parameters - '("GstBin*" "bin") - ) -) - -(define-function add_iterate_bin - (c-name "add_iterate_bin") - (return-type "guint") - (parameters - '("GstBin*" "bin") - ) -) - -(define-function remove_iterate_bin - (c-name "remove_iterate_bin") - (return-type "none") - (parameters - '("guint" "id") - ) -) - -;; -;; HACK -;; - -(define-method get_data - (of-object "GstBuffer") - (c-name "gst_buffer_get_data") - (return-type "char*") -) - -(define-method set_data - (of-object "GstBuffer") - (c-name "gst_buffer_set_data") - (return-type "none") - (parameters - '("char*" "data") - ) -) - - diff --git a/gstreamer/common.h b/gstreamer/common.h deleted file mode 100644 index c271193185..0000000000 --- a/gstreamer/common.h +++ /dev/null @@ -1,34 +0,0 @@ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ - -#include -#include - -#include -#include - -typedef struct { - PyObject *func, *data; -} PyGstCustomNotify; - -void iterate_bin_all(GstBin *bin); -guint add_iterate_bin(GstBin *bin); -void remove_iterate_bin(guint id); diff --git a/gstreamer/common.override b/gstreamer/common.override deleted file mode 100644 index f93b430c60..0000000000 --- a/gstreamer/common.override +++ /dev/null @@ -1,414 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python - * Copyright (C) 2002 David I. Lehn - * - * 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. - * - * Author: David I. Lehn - */ -%% -headers -#include - -#include "pygobject.h" -#include - -#include "common.h" - -typedef struct { - PyGObject *pad; - PyObject *link_function; - PyObject *chain_function; -} PyGstPadPrivate; - -static PyGstPadPrivate* -pad_private(GstPad *pad) -{ - return (PyGstPadPrivate*)gst_pad_get_element_private(pad); -} - -static PyGstPadPrivate* -py_pad_private(PyGObject *pad) -{ - PyGstPadPrivate *private; - GstPad *gpad; - - gpad = (GstPad*)pygobject_get(pad); - private = (PyGstPadPrivate*)gst_pad_get_element_private(gpad); - if (private == NULL) { - /* FIXME need to free this somewhere */ - private = g_new0(PyGstPadPrivate, 1); - Py_INCREF(pad); - private->pad = pad; - gst_pad_set_element_private(gpad, private); - } - return private; -} - -%% -modulename gstreamer -%% -import gobject.GObject as PyGObject_Type -%% -ignore-glob - _* - gstreamer_*init - *_get_type -%% -override gst_pad_set_link_function kwargs - -static GstPadLinkReturn -call_link_function (GstPad *pad, GstCaps *caps) -{ - PyObject *function; - PyObject *retval; - GstPadLinkReturn ret; - - function = pad_private(pad)->link_function; - - pyg_block_threads(); - - retval = (PyObject*)PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_CAPS, caps, TRUE, TRUE)); - - if (PyErr_Occurred ()) { - PyErr_Print (); - pyg_unblock_threads(); - return GST_PAD_LINK_REFUSED; - } - - ret = PyInt_AsLong(retval); - - pyg_unblock_threads(); - - return ret; -} - -static PyObject* -_wrap_gst_pad_set_link_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "link_function", NULL }; - PyObject *link_function; - GstPad *pad; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GstPad.set_link_funcion", - kwlist, - &link_function)) { - return NULL; - } - - if (!PyCallable_Check(link_function)) { - PyErr_SetString(PyExc_TypeError, "link_function not callable"); - return NULL; - } - - Py_INCREF(link_function); - py_pad_private(self)->link_function = link_function; - pad = (GstPad*)pygobject_get(self); - gst_pad_set_link_function(pad, call_link_function); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_pad_set_chain_function kwargs - -static void -call_chain_function(GstPad *pad, GstData *data) -{ - PyObject *function; - - function = pad_private(pad)->chain_function; - - pyg_block_threads(); - - if (GST_IS_BUFFER(data)) { - PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_BUFFER, data, TRUE, TRUE)); - } else if (GST_IS_EVENT(data)) { - PyObject_CallFunction (function, - "OO", - pad_private(pad)->pad, - pyg_boxed_new(GST_TYPE_EVENT, data, TRUE, TRUE)); - } - - if (PyErr_Occurred ()) { - PyErr_Print (); - pyg_unblock_threads(); - return; - } - - pyg_unblock_threads(); -} - -static PyObject* -_wrap_gst_pad_set_chain_function(PyGObject *self, - PyObject *args, - PyObject *kwargs) -{ - static char *kwlist[] = { "chain_function", NULL }; - PyObject *chain_function; - GstPad *pad; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O:GstPad.set_chain_funcion", - kwlist, - &chain_function)) { - return NULL; - } - - if (!PyCallable_Check(chain_function)) { - PyErr_SetString(PyExc_TypeError, "chain_function not callable"); - return NULL; - } - - Py_INCREF(chain_function); - py_pad_private(self)->chain_function = chain_function; - pad = (GstPad*)pygobject_get(self); - gst_pad_set_chain_function(pad, call_chain_function); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_buffer_get_data - -static PyObject* -_wrap_gst_buffer_get_data(PyObject *self) -{ - GstBuffer *buf; - - buf = pyg_boxed_get(self, GstBuffer); - - return PyString_FromStringAndSize( - GST_BUFFER_DATA(buf), - GST_BUFFER_SIZE(buf)); -} -%% -override gst_buffer_set_data kwargs - -static PyObject* -_wrap_gst_buffer_set_data(PyObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = {"data", NULL}; - PyObject *data; - GstBuffer *buf; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstBuffer:set_data", kwlist, &data)) { - return NULL; - } - if (!PyString_Check(data)) { - PyErr_SetString(PyExc_TypeError, "data should be a string"); - return NULL; - } - buf = pyg_boxed_get(self, GstBuffer); - if (GST_BUFFER_FLAGS(buf) & GST_BUFFER_READONLY) { - PyErr_SetString(PyExc_TypeError, "set_data can't use a READONLY buffer"); - return NULL; - } - GST_BUFFER_SIZE(buf) = PyString_Size(data); - GST_BUFFER_DATA(buf) = g_new0(char, GST_BUFFER_SIZE(buf)); - - memcpy(GST_BUFFER_DATA(buf), - PyString_AsString(data), - PyString_Size(data)); - - Py_INCREF(Py_None); - return Py_None; -} -%% -override gst_bin_iterate - -static PyObject * -_wrap_gst_bin_iterate(PyGObject *self) -{ - int ret; - - pyg_unblock_threads(); - ret = gst_bin_iterate(GST_BIN(self->obj)); - pyg_block_threads(); - return PyInt_FromLong(ret); -} -%% -override gst_element_set_state kwargs - -static PyObject * -_wrap_gst_element_set_state(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "state", NULL }; - PyObject *py_state = NULL; - GstElementState state; - gint ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.set_state", kwlist, &py_state)) - return NULL; - if (pyg_flags_get_value(GST_TYPE_ELEMENT_STATE, py_state, (gint *)&state)) - return NULL; - pyg_unblock_threads(); - ret = gst_element_set_state(GST_ELEMENT(self->obj), state); - pyg_block_threads(); - return PyInt_FromLong(ret); -} -%% -override gst_pad_query kwargs - -static PyObject * -_wrap_gst_pad_query(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "type", "format", NULL }; - GstQueryType type; - GstFormat format; - gint64 value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GstPad.query", kwlist, &type, &format)) - return NULL; - value = 0; - ret = gst_pad_query(GST_PAD(self->obj), type, &format, &value); - return Py_BuildValue("(bL)", ret, value); -} -%% -override gst_element_query kwargs - -static PyObject * -_wrap_gst_element_query(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "type", "format", NULL }; - GstQueryType type; - GstFormat format; - gint64 value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:GstElement.query", kwlist, &type, &format)) - return NULL; - value = 0; - ret = gst_element_query(GST_ELEMENT(self->obj), type, &format, &value); - return Py_BuildValue("(bL)", ret, value); -} -%% -override gst_pad_convert kwargs - -static PyObject * -_wrap_gst_pad_convert(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "src_format", "src_value", "dest_format", NULL }; - GstFormat src_format, dest_format; - PyObject *src_value_obj; - gint64 src_value, dest_value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iOi:GstPad.convert", kwlist, &src_format, &src_value_obj, &dest_format)) - return NULL; - src_value = PyLong_AsLongLong(src_value_obj); - dest_value = 0; - ret = gst_pad_convert(GST_PAD(self->obj), src_format, src_value, &dest_format, &dest_value); - return Py_BuildValue("(bL)", ret, dest_value); -} -%% -override gst_element_convert kwargs - -static PyObject * -_wrap_gst_element_convert(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "src_format", "src_value", "dest_format", NULL }; - GstFormat src_format, dest_format; - PyObject *src_value_obj; - gint64 src_value, dest_value; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iOi:GstElement.convert", kwlist, &src_format, &src_value_obj, &dest_format)) - return NULL; - src_value = PyLong_AsLongLong(src_value_obj); - dest_value = 0; - ret = gst_element_convert(GST_ELEMENT(self->obj), src_format, src_value, &dest_format, &dest_value); - return Py_BuildValue("(bL)", ret, dest_value); -} -%% -override gst_element_factory_make_element - -/* we create this function to serve as a constructor for Element */ -static int -_wrap_gst_element_factory_make_element(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - static char *kwlist[] = { "factoryname", "name", NULL }; - char *factoryname, *name = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s:GstElement.__init__", kwlist, &factoryname, &name)) - return -1; - self->obj = (GObject *)gst_element_factory_make(factoryname, name); - - if (!self->obj) { - PyErr_SetString(PyExc_RuntimeError, "could not create GstElement object"); - return -1; - } - pygobject_register_wrapper((PyObject *)self); - return 0; -} -%% -override gst_version noargs - -static PyObject * -_wrap_gst_version(void) -{ - guint major, minor, micro; - - gst_version(&major, &minor, µ); - - return Py_BuildValue("(iii)", major, minor, micro); -} -%% -override gst_bin_add_many args -static PyObject * -_wrap_gst_bin_add_many(PyGObject *self, PyObject *args, PyObject *kwargs) -{ - PyGObject *element; - int i; - int len; - - len = PyList_Size(args); - if (len == 0) - { - PyErr_SetString(PyExc_TypeError, "GstBin.add requires at least one argument"); - return NULL; - } - - - for (i = 0; i < len; i++) - { - element = (PyGObject*)PyList_GetItem(args, i); - if (!pygobject_check(element, &PyGstElement_Type)) - { - PyErr_SetString(PyExc_TypeError, "argument must be a GstElement"); - return NULL; - } - } - - for (i = 0; i < len; i++) - { - element = (PyGObject*)PyList_GetItem(args, i); - gst_bin_add(GST_BIN(self->obj), GST_ELEMENT(element->obj)); - } - - Py_INCREF(Py_None); - return Py_None; -} diff --git a/gstreamer/gst-types.c b/gstreamer/gst-types.c index aea315fb9b..2559cc2e3f 100644 --- a/gstreamer/gst-types.c +++ b/gstreamer/gst-types.c @@ -26,7 +26,7 @@ gboolean pygst_data_from_pyobject(PyObject *object, GstData **data) { g_return_val_if_fail(*data != NULL, FALSE); - + if (pyg_boxed_check(object, GST_TYPE_DATA)) { *data = pyg_boxed_get(object, GstData); return TRUE; @@ -58,14 +58,11 @@ PyGstData_to_value(GValue *value, PyObject *object) if (!pygst_data_from_pyobject(object, &data)) return -1; - - g_value_set_boxed(value, &data); + + g_value_set_boxed(value, data); return 0; } -/* We have to set ob_type here because stupid win32 does not allow you - * to use variables from another dll in a global variable initialisation. - */ void _pygst_register_boxed_types(PyObject *moddict) { diff --git a/gstreamer/gst-types.defs b/gstreamer/gst-types.defs index 74ec95bcb4..08c2e3f1ca 100644 --- a/gstreamer/gst-types.defs +++ b/gstreamer/gst-types.defs @@ -156,8 +156,8 @@ (in-module "Gst") (c-name "GstBuffer") (gtype-id "GST_TYPE_BUFFER") - (copy-func "gst_buffer_copy") - (release-func "gst_buffer_free") + (copy-func "gst_data_copy") + (release-func "gst_data_unref") ) (define-boxed Caps @@ -179,7 +179,7 @@ (c-name "GstEvent") (gtype-id "GST_TYPE_EVENT") (copy-func "gst_event_copy") - (release-func "gst_event_free") + (release-func "gst_data_unref") ) diff --git a/gstreamer/gst.defs b/gstreamer/gst.defs index 647528ca3e..9827fdab3f 100644 --- a/gstreamer/gst.defs +++ b/gstreamer/gst.defs @@ -1,6 +1,7 @@ ;; -*- scheme -*- (include "gst-types.defs") +;;(include "0.7.defs") ;; From /opt/gnome/include/gstreamer-0.7/gst/gstatomic.h @@ -1559,7 +1560,7 @@ (return-type "GstElement*") (parameters '("const-gchar*" "factoryname") - '("const-gchar*" "name") + '("const-gchar*" "name" (null-ok) (default "NULL")) ) ) @@ -5265,7 +5266,23 @@ (return-type "GstTagList*") ) +;; Added python method +(define-method keys + (of-object "GstTagList") + (c-name "pygst_tag_list_keys") +) +(define-method has_key + (of-object "GstTagList") + (c-name "pygst_tag_list_has_key") + (parameters '("gchar*" "key")) +) + +(define-method get + (of-object "GstTagList") + (c-name "pygst_tag_list_get") + (parameters '("gchar*" "key")) +) ;; From /opt/gnome/include/gstreamer-0.7/gst/gsttaginterface.h diff --git a/gstreamer/gstmodule.c b/gstreamer/gstmodule.c index ce1dce58bf..30508fa545 100644 --- a/gstreamer/gstmodule.c +++ b/gstreamer/gstmodule.c @@ -42,7 +42,7 @@ init_gst (void) char **argv; init_pygobject (); - + /* pull in arguments */ av = PySys_GetObject ("argv"); if (av != NULL) { diff --git a/gstreamer/gstpad-handlers.override b/gstreamer/gstpad-handlers.override new file mode 100644 index 0000000000..d00e8bea0e --- /dev/null +++ b/gstreamer/gstpad-handlers.override @@ -0,0 +1,258 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2004 Johan Dahlin + * + * 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. + * + * Author: Johan Dahlin link_function; + + pyg_block_threads(); + + retval = (PyObject*)PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_CAPS, caps, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return GST_PAD_LINK_REFUSED; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_link_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "link_function", NULL }; + PyObject *link_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_link_funcion", + kwlist, + &link_function)) { + return NULL; + } + + if (!PyCallable_Check(link_function)) { + PyErr_SetString(PyExc_TypeError, "link_function not callable"); + return NULL; + } + + Py_INCREF(link_function); + py_pad_private(self)->link_function = link_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_link_function(pad, (GstPadLinkFunction)call_link_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_chain_function kwargs + +static void +call_chain_function(GstPad *pad, GstBuffer *buf) +{ + PyObject *function; + + function = pad_private(pad)->chain_function; + + pyg_block_threads(); + + PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_BUFFER, buf, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return; + } + + pyg_unblock_threads(); +} + +static PyObject* +_wrap_gst_pad_set_chain_function(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "chain_function", NULL }; + PyObject *chain_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_chain_funcion", + kwlist, + &chain_function)) { + return NULL; + } + + if (!PyCallable_Check(chain_function)) { + PyErr_SetString(PyExc_TypeError, "chain_function not callable"); + return NULL; + } + + Py_INCREF(chain_function); + py_pad_private(self)->chain_function = chain_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_chain_function(pad, (GstPadChainFunction)call_chain_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_event_function kwargs + +static gboolean +call_event_function (GstPad *pad, GstEvent *event) +{ + PyObject *function; + PyObject *retval; + gboolean ret; + + function = pad_private(pad)->event_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction (function, + "OO", + pad_private(pad)->pad, + pyg_boxed_new(GST_TYPE_EVENT, event, TRUE, TRUE)); + + if (PyErr_Occurred ()) { + PyErr_Print (); + pyg_unblock_threads(); + return FALSE; + } + + ret = PyInt_AsLong(retval); + + pyg_unblock_threads(); + + return ret; +} + +static PyObject* +_wrap_gst_pad_set_event_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "event_function", NULL }; + PyObject *event_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_event_funcion", + kwlist, + &event_function)) { + return NULL; + } + + if (!PyCallable_Check(event_function)) { + PyErr_SetString(PyExc_TypeError, "event_function not callable"); + return NULL; + } + + Py_INCREF(event_function); + py_pad_private(self)->event_function = event_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_event_function(pad, (GstPadEventFunction)call_event_function); + + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_pad_set_get_function kwargs + +static GstData* +call_get_function (GstPad *pad) +{ + PyObject *function; + PyObject *retval; + GstData *data = NULL; + + function = pad_private(pad)->get_function; + + pyg_block_threads(); + + retval = PyObject_CallFunction(function, "O", pad_private(pad)->pad); + + if (PyErr_Occurred()) { + PyErr_Print(); + goto bail; + } else if (retval == Py_None) { + goto bail; + } + + pygst_data_from_pyobject(retval, &data); + +bail: + pyg_unblock_threads(); + return data; +} + +static PyObject* +_wrap_gst_pad_set_get_function (PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "get_function", NULL }; + PyObject *get_function; + GstPad *pad; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstPad.set_get_funcion", + kwlist, + &get_function)) { + return NULL; + } + + if (!PyCallable_Check(get_function)) { + PyErr_SetString(PyExc_TypeError, "get_function not callable"); + return NULL; + } + + Py_INCREF(get_function); + py_pad_private(self)->get_function = get_function; + pad = (GstPad*)pygobject_get(self); + gst_pad_set_get_function(pad, (GstPadGetFunction)call_get_function); + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/gstreamer/gstreamer.defs b/gstreamer/gstreamer.defs index 647528ca3e..9827fdab3f 100644 --- a/gstreamer/gstreamer.defs +++ b/gstreamer/gstreamer.defs @@ -1,6 +1,7 @@ ;; -*- scheme -*- (include "gst-types.defs") +;;(include "0.7.defs") ;; From /opt/gnome/include/gstreamer-0.7/gst/gstatomic.h @@ -1559,7 +1560,7 @@ (return-type "GstElement*") (parameters '("const-gchar*" "factoryname") - '("const-gchar*" "name") + '("const-gchar*" "name" (null-ok) (default "NULL")) ) ) @@ -5265,7 +5266,23 @@ (return-type "GstTagList*") ) +;; Added python method +(define-method keys + (of-object "GstTagList") + (c-name "pygst_tag_list_keys") +) +(define-method has_key + (of-object "GstTagList") + (c-name "pygst_tag_list_has_key") + (parameters '("gchar*" "key")) +) + +(define-method get + (of-object "GstTagList") + (c-name "pygst_tag_list_get") + (parameters '("gchar*" "key")) +) ;; From /opt/gnome/include/gstreamer-0.7/gst/gsttaginterface.h diff --git a/gstreamer/gstreamermodule.c b/gstreamer/gstreamermodule.c index ce1dce58bf..30508fa545 100644 --- a/gstreamer/gstreamermodule.c +++ b/gstreamer/gstreamermodule.c @@ -42,7 +42,7 @@ init_gst (void) char **argv; init_pygobject (); - + /* pull in arguments */ av = PySys_GetObject ("argv"); if (av != NULL) {