Commit graph

54 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Thibault Saunier
8cc4bda46a overrides: Checking an empty caps should return False 2014-03-15 16:27:44 +01:00
Simon Farnsworth
c889037e40 Fix zip code of new FSF address
I missed the zip code last time round - fix it. Thanks to Michael Schwendt
in https://bugzilla.redhat.com/show_bug.cgi?id=1034341#c11 for pointing this
out to me.

Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>

https://bugzilla.gnome.org/show_bug.cgi?id=720317
2013-12-12 11:35:41 +00:00
Olivier Crête
8542c4b219 Gst: Add python version of GST_TIME_ARGS 2013-12-03 18:00:38 -05:00
Simon Farnsworth
2ad767a74c Update FSF address
The FSF has moved since these files were created. Update the address, in
order to keep packaging tools such as rpmlint quiet.

Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>

https://bugzilla.gnome.org/show_bug.cgi?id=715182
2013-11-26 15:28:53 +00:00
Thibault Saunier
9d1666ad07 Gst: Do not initialize Gst at init
Letting the user choose when to initialize it himself
2013-08-26 17:35:48 -04:00
Thibault Saunier
827a137189 overrides: implement Gst.Structure.__setitem__ 2012-12-07 14:18:21 -03:00
Alessandro Decina
33d57f045a overrides: implement Gst.Structure.__getitem__ 2012-11-22 07:11:45 +01:00
Alessandro Decina
02ca5d3ad2 overrides: move add(*args) override from Gst.Pipeline to Gst.Bin 2012-11-04 17:02:24 +01:00
Alessandro Decina
d6c8df0352 overrides: move the Gst.Pad override before Gst.GhostPad
...else gi will screw up the type hierarchy and GhostPad will inherit from the
non-overridden Gst.Pad. Got it?
2012-11-04 17:00:14 +01:00
Alessandro Decina
aba84580b3 overrides: override GhostPad.__init__ 2012-10-24 20:47:37 +02:00
Alessandro Decina
33541f1cd8 overrides: make Gst.Pad.link still return Gst.PadLinkReturn when successful 2012-10-15 09:56:43 +02:00
Alessandro Decina
374a4b50da overrides: make filter arg in Gst.Pad.query_caps(filter) default to None 2012-10-15 09:29:06 +02:00
Alessandro Decina
64db9c4771 overrides: set default value for name arg in ElementFactory.make(factory, name)
So you can use Gst.ElementFactory.make('fakesrc') instead of
Gst.ElementFactory.make('fakesrc', None)
2012-10-15 09:29:06 +02:00
Alessandro Decina
ec51f6bfd7 overrides: make Gst.Pad.link raise Gst.LinkError 2012-10-15 09:29:06 +02:00
Alessandro Decina
73fd67f6d3 overrides: implement Gst.Pipeline.add(e1, e2, ...) 2012-10-15 09:29:06 +02:00
Alessandro Decina
501db56597 overrides: implement the python iterator protocol for Gst.Iterator
So that you can use: for value in gst_iterator: ...
2012-10-15 09:29:06 +02:00
Alessandro Decina
0b0202cfbe overrides: implement caps[i] and len(caps) 2012-10-15 09:29:06 +02:00