diff options
author | Thibault Saunier <tsaunier@igalia.com> | 2020-08-14 19:43:41 -0400 |
---|---|---|
committer | Thibault Saunier <tsaunier@igalia.com> | 2020-08-14 22:08:02 -0400 |
commit | 3c020d16f6fdb485354d96c14367d085a3ad7e19 (patch) | |
tree | ff4a170585a9148d0a125f8578f5e66c965ebfdd | |
parent | a034db560c1d51229e98af74bbf57ed42dd369da (diff) |
overrides: Fix buffer API break
When introducing zero copy buffers/memory mapping we broke the API,
this brings back the exact same API as before for all the previously
handled cases but still raises an exception when using a context
to map buffers.
Fixes https://gitlab.freedesktop.org/gstreamer/gst-python/-/issues/40
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-python/-/merge_requests/39>
-rw-r--r-- | gi/overrides/Gst.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py index edf347b..2e4244c 100644 --- a/gi/overrides/Gst.py +++ b/gi/overrides/Gst.py @@ -606,11 +606,21 @@ class MapInfo: self.user_data = None self.__parent__ = None + def __iter__(self): + # Make it behave like a tuple similar to the PyGObject generated API for + # the `Gst.Buffer.map()` and friends. + for i in (self.__parent__ is not None, self): + yield i + def __enter__(self): + if not self.__parent__: + raise MapError('MappingError', 'Mapping was not successful') + return self def __exit__(self, type, value, tb): - self.__parent__.unmap(self) + if not self.__parent__.unmap(self): + raise MapError('MappingError', 'Unmapping was not successful') __all__.append("MapInfo") @@ -620,20 +630,19 @@ class Buffer(Gst.Buffer): mapinfo = MapInfo() if (_gi_gst.buffer_override_map_range(self, mapinfo, idx, length, int(flags))): mapinfo.__parent__ = self - return (mapinfo) - raise MapError('MappingError','Buffer mapping was not successfull') + + return mapinfo def map(self, flags): mapinfo = MapInfo() if _gi_gst.buffer_override_map(self, mapinfo, int(flags)): mapinfo.__parent__ = self - return mapinfo - raise MapError('MappingError','Buffer mapping was not successfull') + + return mapinfo def unmap(self, mapinfo): mapinfo.__parent__ = None - if _gi_gst.buffer_override_unmap(self, mapinfo) is not True: - raise MapError('UnmappingError','Buffer unmapping was not successfull') + return _gi_gst.buffer_override_unmap(self, mapinfo) Buffer = override(Buffer) __all__.append('Buffer') @@ -644,13 +653,12 @@ class Memory(Gst.Memory): mapinfo = MapInfo() if (_gi_gst.memory_override_map(self, mapinfo, int(flags))): mapinfo.__parent__ = self - return (mapinfo) - raise MapError('MappingError','Memory mapping was not successfull') + + return mapinfo def unmap(self, mapinfo): mapinfo.__parent__ = None - if _gi_gst.memory_override_unmap(self, mapinfo) is not True: - raise MapError('UnmappingError','Memory unmapping was not successfull') + return _gi_gst.memory_override_unmap(self, mapinfo) Memory = override(Memory) __all__.append('Memory') |