python: Convert buffer metadata API to use @property decorators
Convert buffer metadata getter/setter methods to Python properties for more intuitive access. This makes the API more Pythonic by allowing direct property assignment (buf.pts = 42) instead of method calls (buf.set_pts(42)). Updated properties: flags, pts, dts, duration, offset, offset_end Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9134>
This commit is contained in:
parent
edca7f83d1
commit
e2f54cc405
@ -124,10 +124,12 @@ class MiniObject:
|
||||
def is_writable(self):
|
||||
return _gi_gst.mini_object_is_writable(self)
|
||||
|
||||
@property
|
||||
def flags(self):
|
||||
return _gi_gst.mini_object_flags(self)
|
||||
|
||||
def set_flags(self, flags):
|
||||
@flags.setter
|
||||
def flags(self, flags):
|
||||
_gi_gst.mini_object_set_flags(self, flags)
|
||||
|
||||
|
||||
@ -170,6 +172,7 @@ class Event(Gst.Event, MiniObject):
|
||||
Event = override(Event)
|
||||
__all__.append('Event')
|
||||
|
||||
|
||||
class NotWritableContext(Exception):
|
||||
pass
|
||||
|
||||
@ -891,40 +894,52 @@ __all__.append("MapInfo")
|
||||
|
||||
|
||||
class Buffer(Gst.Buffer, MiniObject):
|
||||
@property
|
||||
def flags(self):
|
||||
return MiniObject.flags(self)
|
||||
return _gi_gst.mini_object_flags(self)
|
||||
|
||||
def set_flags(self, flags):
|
||||
return MiniObject.set_flags(self, flags)
|
||||
@flags.setter
|
||||
def flags(self, flags):
|
||||
_gi_gst.mini_object_set_flags(self, flags)
|
||||
|
||||
@property
|
||||
def dts(self):
|
||||
return _gi_gst.buffer_get_dts(self)
|
||||
|
||||
def set_dts(self, dts):
|
||||
@dts.setter
|
||||
def dts(self, dts):
|
||||
_gi_gst.buffer_set_dts(self, dts)
|
||||
|
||||
@property
|
||||
def pts(self):
|
||||
return _gi_gst.buffer_get_pts(self)
|
||||
|
||||
def set_pts(self, pts):
|
||||
@pts.setter
|
||||
def pts(self, pts):
|
||||
_gi_gst.buffer_set_pts(self, pts)
|
||||
|
||||
def set_duration(self, duration):
|
||||
_gi_gst.buffer_set_duration(self, duration)
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
return _gi_gst.buffer_get_duration(self)
|
||||
|
||||
@duration.setter
|
||||
def duration(self, duration):
|
||||
_gi_gst.buffer_set_duration(self, duration)
|
||||
|
||||
@property
|
||||
def offset(self):
|
||||
return _gi_gst.buffer_get_offset(self)
|
||||
|
||||
def set_offset(self, offset):
|
||||
@offset.setter
|
||||
def offset(self, offset):
|
||||
_gi_gst.buffer_set_offset(self, offset)
|
||||
|
||||
@property
|
||||
def offset_end(self):
|
||||
return _gi_gst.buffer_get_offset_end(self)
|
||||
|
||||
def set_offset_end(self, offset_end):
|
||||
@offset_end.setter
|
||||
def offset_end(self, offset_end):
|
||||
_gi_gst.buffer_set_offset_end(self, offset_end)
|
||||
|
||||
def map_range(self, idx, length, flags):
|
||||
|
@ -16,16 +16,16 @@
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
import overrides_hack
|
||||
import sys
|
||||
from common import TestCase, unittest
|
||||
from gi.repository import Gst
|
||||
import gi
|
||||
|
||||
|
||||
gi.require_version('Gst', '1.0')
|
||||
|
||||
|
||||
from gi.repository import Gst
|
||||
from common import TestCase, unittest
|
||||
import sys
|
||||
import overrides_hack
|
||||
overrides_hack
|
||||
|
||||
|
||||
@ -220,6 +220,7 @@ class TestQuery(TestCase):
|
||||
self.assertEqual(s["rate"], 44100)
|
||||
self.assertEqual(s["channels"], 2)
|
||||
|
||||
|
||||
class TestContext(TestCase):
|
||||
def test_writable(self):
|
||||
Gst.init(None)
|
||||
@ -244,24 +245,24 @@ class TestBuffer(TestCase):
|
||||
def test_set_metas(self):
|
||||
Gst.init(None)
|
||||
buf = Gst.Buffer.new_wrapped([42])
|
||||
buf.set_pts(42)
|
||||
self.assertEqual(buf.pts(), 42)
|
||||
buf.pts = 42
|
||||
self.assertEqual(buf.pts, 42)
|
||||
|
||||
make_not_writable = buf.mini_object
|
||||
with self.assertRaises(Gst.NotWritableMiniObject):
|
||||
buf.set_pts(52)
|
||||
buf.pts = 52
|
||||
|
||||
buf.make_writable()
|
||||
buf.set_dts(62)
|
||||
self.assertEqual(buf.dts(), 62)
|
||||
self.assertTrue(buf.flags() & Gst.BufferFlags.DISCONT == 0)
|
||||
buf.set_flags(Gst.BufferFlags.DISCONT)
|
||||
buf.set_duration(72)
|
||||
self.assertEqual(buf.duration(), 72)
|
||||
buf.set_offset(82)
|
||||
self.assertEqual(buf.offset(), 82)
|
||||
buf.set_offset_end(92)
|
||||
self.assertEqual(buf.offset_end(), 92)
|
||||
buf.dts = 62
|
||||
self.assertEqual(buf.dts, 62)
|
||||
self.assertTrue(buf.flags & Gst.BufferFlags.DISCONT == 0)
|
||||
buf.flags = Gst.BufferFlags.DISCONT
|
||||
buf.duration = 72
|
||||
self.assertEqual(buf.duration, 72)
|
||||
buf.offset = 82
|
||||
self.assertEqual(buf.offset, 82)
|
||||
buf.offset_end = 92
|
||||
self.assertEqual(buf.offset_end, 92)
|
||||
del make_not_writable
|
||||
|
||||
meta = buf.add_reference_timestamp_meta(Gst.Caps("yes"), 10, 10)
|
||||
|
Loading…
x
Reference in New Issue
Block a user