Commit graph

83 commits

Author SHA1 Message Date
Thibault Saunier d365954fc0 Subclass Exception for mapping and unmapping errors
And minor cleanup in the way errors are handled
2019-12-10 12:05:19 -03:00
Daniel Klamt fecfe451a7 Changes the mapinfo so that the mapped data is writable
The Problem is, that in the current state it is not easily possible to
edit the buffer data in a gstreamer python element since you get a copy
of the real buffer.

This patch overrides the mapinfo and the function generating it in a way
so that mapinfo.data is now a memoryview pointing to the real buffer.
Depending on the flags given for this buffer the memoryview is r/w.
2019-12-09 09:23:55 +01:00
Thibault Saunier 91d05de9b9 python: Fix type type qualifiers issues 2019-11-28 10:47:07 -03:00
Thibault Saunier 95b2f64394 Remove python2 support
We have notified application developers this would happen a long time
ago and python2 is going to be deprecated very soon now, before 1.18
is going to be released.
2019-11-19 11:18:59 -03:00
Tim-Philipp Müller acb2da66f5 Remove autotools build 2019-10-14 19:08:47 +01:00
Mathieu Duponchelle c04bb945b0 overrides: fix callback setter overrides (bis)
The previous commit broke those by trying to pass weak refs
through pygobject, but we should probably have tested the elements
beyond instantiation: weakref.WeakMethod returns a callable, but
that callable when called only returns the ephemeral bound method,
which is the object we want to call, but pygobject has no support
for that.

Instead, fix the memory leaks we were going after by decoupling the
lifecycle of the callback and that of the pad, by passing functors
to pygobject.
2019-09-02 18:42:39 +02:00
Mathieu Duponchelle 34e0e3ce11 overrides: fix callback setter overrides
Use weakref to avoid leaks, and remove refcount hack as the actual
issue has been fixed in pygobject
2019-08-08 23:35:16 +00:00
Thibault Saunier 6fcd2c835f override Element before Bin so we can access element fields of bins
And add a test

See https://gitlab.gnome.org/GNOME/pygobject/issues/325
2019-05-06 11:30:47 -04:00
Mathieu Duponchelle 2e91b713f1 Gst.py: add high-level helpers 2019-05-03 15:12:02 +00:00
Thibault Saunier 96ecb22468 Gst.init() has to be called before GstPbutils is imported
This makes sure that we do not try to use GstPbutils before Gst is init
and in case GstPbutils is imported while Gst is not imported, use the
`GstPbutils.pb_utils_init()` function to have the oportunity to
initialize the overrides.

Not that we also introduce a `GstPbutils.init()` variant because
`GstPbutils.pb_utils_init()` is an ugly name.
2019-01-30 15:46:35 -03:00
Antonio Ospite 1cece5bde5 overrides: add a set_caps() method to the Pad override
The C API provides the gst_pad_set_caps() helper which makes it easier
to set caps on pads (see gst/gstcompat.h in gstreamer core).

Add such handy helper to the python bindings too.

The implementation follows as close as possible the one in gstcompat.h
with two changes:
  1. the type check on the pad has been removed because self is
     guaranteed to be a Gst.Pad in python.
  2. the null check on the caps has been extended to be a type check.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-python/issues/19
2019-01-09 12:32:37 +01:00
Mathieu Duponchelle d64bbc1e0c Tests: refactor testing approach
Instead of fiddling with sys.path, we instead use a custom
sys.meta_path importer
2018-10-31 00:41:31 +01:00
Havard Graff af4ade3743 meson: use new python module
This patch makes the tests pass running uninstalled and installed, with
python2 and python3 on linux, windows and osx.

The main gist is to use the new python-module to do the lifting done
by pythondetector, and with that add support for python2 and windows.
2018-10-28 17:53:44 +01:00
Mathieu Duponchelle a15ed715f0 automake: remove __init__.py's 2018-10-28 17:53:08 +01:00
Mathieu Duponchelle 055e2e17ec Remove __init__.py files
They were not installed, and were simply used for our
uninstalled setup, which we now implement differently.
2018-10-28 14:14:09 +01:00
Havard Graff e9d615bf53 gstmodule: fix warning when building against python2
PyMapping_GetItemString’ discards ‘const’ qualifier from pointer target type

https://bugzilla.gnome.org/show_bug.cgi?id=796093
2018-05-14 07:51:43 -04:00
Emilio Pozuelo Monfort e84b9b05f2 overrides: use get_introspection_module
https://bugzilla.gnome.org/show_bug.cgi?id=795555
2018-04-25 15:10:28 -03:00
Thibault Saunier 861a67bde6 overrides: Fix mixup between query function and chain one 2018-04-07 21:47:29 -03:00
Nicolas Dufresne 146b8cca43 makefiles: Add missing dist files
https://bugzilla.gnome.org/show_bug.cgi?id=793560
2018-02-22 17:05:35 -05:00
Thibault Saunier 693005716e bitmask: Do not use long() directly with python3
It doesn't exist anymore there
2018-02-22 08:05:54 -03:00
Thibault Saunier fb9401d6e9 gi: Check Gst has not been initialized before loading bindings
It can have been initialized by some C code (in a C app with plugins
for example).

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=788088
2018-02-22 07:52:24 -03:00
Sebastian Dröge 063562c986 Allow Bitmask to be created from ints and longs but always store as long
We need a 64 bit integer, and previously the test failed because it was
already created from longs in various cases (e.g. when reading from a
GstStructure).
2018-02-22 10:58:48 +01:00
Mathieu Duponchelle 8a807cc1be overrides: accept Gst.Structure in Caps.__new__
Also rename misleading parameter (*kwargs -> *args)

https://bugzilla.gnome.org/show_bug.cgi?id=793493
2018-02-15 20:23:34 +01:00
Sebastian Dröge 2dd3bb0cb7 Ship meson build system in autotools generated tarballs 2018-01-23 19:32:18 +02:00
Thibault Saunier a8aaada019 meson: Fix detection of overrides path in some cases 2017-08-03 14:38:36 -04:00
Thibault Saunier fcbca025e3 Fix simply running testsuite in meson
- Make sure to never have root folder in sys.path when running meson,
  as pythondetector won't be able to access gi._overridesdir

- Generate a mesonconfig.py file that will be used by the testsuite to
  know where meson generated files, making `python -m unittest` working.
2017-07-26 15:27:21 -04:00
Thibault Saunier cb0dd804f7 Add support for Gst.Bitmask 2017-07-26 15:27:21 -04:00
Thibault Saunier dd943155a1 structure: Add a .keys() method and implement __str__
We are making it behave like a dict, so we should provide the
same kind of utilities.
2017-07-26 15:27:21 -04:00
Thibault Saunier 31dfe42b37 Return a Gst.*Range instead of a python range converting from GValue to python
Otherwise we lose the information about what type of range it is, which
is mandatory, especially when dealing with Structure and Caps.
2017-07-26 15:27:21 -04:00
Thibault Saunier 02ddaf29f9 structures: Override __new__ to make it more pythonic 2017-07-26 15:27:19 -04:00
Olivier Crête 24156b0b0d overrides: Remove IntRange And Int64Range on Python2
They use the range() built-in type which is a Python 3 change.

https://bugzilla.gnome.org/show_bug.cgi?id=782927
2017-05-21 18:08:36 +02:00
Nicolas Dufresne d44975a1fe array/list: Make gvalue conversion symmetric
This is needed to support matrix. Otherwise, getting
a matrix would remove the rows envelopess, which would
make the "cast" fails, since it would not know if the
internal rows are ValueArray or ValueList. I think reading,
modifying and setting back the matrix is an important use
case.
2017-03-27 15:02:41 -04:00
Nicolas Dufresne c6dee2c26b gstmodule: Factor out gst type creation
This reduces a lot the boiler plate all over. At the same
time, use N instead of O when passing PyObject to fix
the objects leaks.
2017-03-27 14:52:24 -04:00
Nicolas Dufresne a4566ffbc8 overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:

  structure["range"] = Gst.IntRange(range(0,10,2)))

Same for the 64 bit variant. And when you do:

  r = structure.get_value("range")

A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:

  structure["range"] = Gst.DoubleRange(0,10.0)
  structure["range"] =
      Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)

When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.

For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.

  structure["list"] = Gst.ValueList([1,2,3,4])
  structure["array"] = Gst.ValueArray([1,2,3,4)

Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:

  list = Gst.ValueList([1,2,3,4])
  array = Gst.ValueArray (list)

https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-24 13:26:21 -04:00
Thibault Saunier 16f971226d Add support for Meson as alternative/parallel build system
https://github.com/mesonbuild/meson
2016-09-05 12:13:03 -03:00
Hanno Boeck 58c324e0cc NULL-terminate PyMethodDef array
PyMethodDef arrays are supposed to end with an entry full of NULL/0 values.
This is missing in gst-python in the file gstmodule.c.

This causes out of bounds memory reads which can be seen / tested by compiling
gst-python with address sanitizer (-fsanitize=address in CFLAGS/LDFLAGS).

https://bugzilla.gnome.org/show_bug.cgi?id=762766
2016-02-27 13:52:07 +02:00
Thibault Saunier eb043251ee Fix bug when checking template object type 2016-02-20 21:47:09 +01:00
Thibault Saunier 7b627c499d gst: Fix a crash when passing wrong type as __templates__ 2016-02-15 23:28:47 +01:00
Thibault Saunier 8b94b967a0 Avoid warning about gi.require_version not being called 2016-02-08 11:30:08 +01:00
Mark Nauwelaerts 9352c54ced overrides: also provide wrapper for trace level debug logging 2015-11-08 11:56:41 +01:00
Mark Nauwelaerts 664c153a5f overrides: fix a few typos in exception messages 2015-11-08 11:56:20 +01:00
Mark Nauwelaerts 1f26b4ad2b overrides: chain up to base __init__ in Pad override
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=757108
2015-10-26 14:36:00 +01:00
Thibault Saunier ed1f9eccba tests: Fix tests in python2
Python2 core checks that the first argument of a method is of the type
of the object if it does not have any info about the method, so when
using Gst not initialized it raiser a TypeError and not a
Gst.NotInitialized as expected.

+ And fix a typo
2015-04-24 11:25:38 +02:00
Thibault Saunier 74f7ffbb24 overrides: Do not use inspect.signature as it is not avalaible in python2
Fix regression from https://bugzilla.gnome.org/show_bug.cgi?id=746329
2015-04-24 11:15:09 +02:00
Thibault Saunier 6b32ccbbb2 overrides: Disable all GStreamer APIs until Gst has been initialized
Summary:
And throw an exception if the user tries to call any Gst API without
initializing gst.

https://bugzilla.gnome.org/show_bug.cgi?id=747555

Reviewers: Mathieu_Du

Differential Revision: http://phabricator.freedesktop.org/D87
2015-04-24 09:16:53 +02:00
Thibault Saunier 3d19875eb7 overrides: Try hard to make the query writable in the pad query function
Summary:
We know that the bindings will get an extra ref but we know that
it is not actually needed, so we are safe to decrease the refcount
by one in that particular context making sure we give PyGI its
ref back when we are done.

Reviewers: Mathieu_Du

Differential Revision: http://phabricator.freedesktop.org/D41

https://bugzilla.gnome.org/show_bug.cgi?id=746329
2015-03-19 10:27:51 +01:00
Thibault Saunier ed1c9866a2 Add an example sink element and override the chain and event functions of pads
Otherwize we will get 2 time acces to the element in it, which does
not make much sense. The _full variant can still be used.
2014-06-06 10:35:09 +02:00
Christoph Reiter 4c08c3396c overrides: Don't pass arguments to Boxed base class __init__() in Gst.Caps override.
This is needed since: https://git.gnome.org/browse/pygobject/commit/?id=3a2bfc8bf01fcae3863

https://bugzilla.gnome.org/show_bug.cgi?id=730596
2014-05-22 23:09:27 +02:00
Lubosz Sarnecki 16979ed48b python3: apply pep 238 for division overload
Python 3 needs an __truediv__ operator method, used in GstFraction.

see: http://legacy.python.org/dev/peps/pep-0238/

https://bugzilla.gnome.org/show_bug.cgi?id=726920
2014-04-01 09:56:13 +02:00
Thibault Saunier edd21362f6 overrides: Import the _gi_gst module relative
We always expect it to be in the same directory and it fixes its import
with python3

https://bugzilla.gnome.org/show_bug.cgi?id=726921
2014-04-01 09:56:13 +02:00