Improve support GstBuffer attributes, r/w support for timestamp.
authorJohan Dahlin <johan@gnome.org>
Tue, 14 Dec 2004 16:53:09 +0000 (16:53 +0000)
committerJohan Dahlin <johan@gnome.org>
Tue, 14 Dec 2004 16:53:09 +0000 (16:53 +0000)
Original commit message from CVS:
* gst/gst-types.defs:
* gst/gstbuffer.override:
* testsuite/test_buffer.py:

Improve support GstBuffer attributes, r/w support for timestamp.

ChangeLog
common
gst/gst-types.defs
gst/gstbuffer.override
testsuite/test_buffer.py

index 990d687..6d55e0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-12-14  Johan Dahlin  <johan@gnome.org>
+
+       * gst/gst-types.defs:
+       * gst/gstbuffer.override:
+       * testsuite/test_buffer.py:
+
+       Improve support GstBuffer attributes, r/w support for timestamp.
+
 2004-11-29  Johan Dahlin  <johan@gnome.org>
 
        * configure.ac: Post release version bump
diff --git a/common b/common
index ded6dc5..b2638c1 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit ded6dc5186cb7f8c64cb06a8591b9f787122c6f1
+Subproject commit b2638c100721f67b280c3b43b21f1ce1c9b5e316
index 44f4642..8ab504a 100644 (file)
   (copy-func "gst_buffer_copy")
   (release-func "gst_data_unref")
   (fields 
+     ;; GstData fields
+     '("GType" "data_type")
+     '("guint16" "flags")
+     
+     ;; GstBuffer fields
      '("guint" "size")
      '("guint" "maxsize")
      '("guint64" "offset")
      '("guint64" "offset_end")
+     '("GstClockTime" "timestamp")
   )
 )
 
index ee39462..129c137 100644 (file)
@@ -117,28 +117,18 @@ _wrap_gst_buffer_set_data(PyObject *self, PyObject *args, PyObject *kwargs)
        return Py_None;
 }
 %%
-override-slot GstBuffer.tp_getattr
-PyObject *
-_wrap_gst_buffer_tp_getattr(PyGObject *self, char *attr)
+override-attr GstBuffer.data_type
+static PyObject*
+_wrap_gst_buffer__get_data_type(PyGObject *self, void *closure)
 {
-       /* We have some GstData methods since it's not a subclass */
-       if (!strcmp(attr, "type"))
-               return pyg_type_wrapper_new(GST_DATA_TYPE(self->obj));
-       else if (!strcmp(attr, "flags"))
-               return PyInt_FromLong(GST_DATA_FLAGS(self->obj));
-#if 0  
-       else if (!strcmp(attr, "size"))
-               return PyInt_FromLong(GST_BUFFER_SIZE(self->obj));
-#endif 
-       else if (!strcmp(attr, "maxsize"))
-               return PyInt_FromLong(GST_BUFFER_MAXSIZE(self->obj));
-       /* XXX: timestamp and duration */
-       else if (!strcmp(attr, "offset"))
-               return PyInt_FromLong(GST_BUFFER_OFFSET(self->obj));
-       else if (!strcmp(attr, "offset_end"))
-               return PyInt_FromLong(GST_BUFFER_OFFSET_END(self->obj));
-
-       return Py_FindMethod(_PyGstBuffer_methods, (PyObject*)self, attr);
+       return pyg_type_wrapper_new(GST_DATA_TYPE(self->obj));
+}
+%%
+override-attr GstBuffer.flags
+static PyObject*
+_wrap_gst_buffer__get_flags(PyGObject *self, void *closure)
+{
+       return PyInt_FromLong(GST_DATA_FLAGS(self->obj));
 }
 %%
 override-attr GstBuffer.size
@@ -169,6 +159,25 @@ _wrap_gst_buffer__get_offset_end(PyGObject *self, void *closure)
        return PyInt_FromLong(GST_BUFFER_OFFSET_END(self->obj));
 }
 %%
+override-attr GstBuffer.timestamp
+static PyObject *
+_wrap_gst_buffer__get_timestamp(PyGObject *self, void *closure)
+{
+       return PyInt_FromLong(GST_BUFFER(self->obj)->timestamp);
+}
+static int
+_wrap_gst_buffer__set_timestamp(PyGBoxed *self, PyObject *value, void *closure)
+{
+    gint val;
+
+    val = PyInt_AsLong(value);
+    if (PyErr_Occurred())
+        return -1;
+    
+    pyg_boxed_get(self, GstBuffer)->timestamp = val;
+    return 0;
+}
+%%
 override-slot GstBuffer.tp_str
 static PyObject *
 _wrap_gst_buffer_tp_str(PyGObject *self)
index b798550..97178a8 100644 (file)
@@ -1,5 +1,5 @@
 import sys
-from common import gst, unittest
+from common import gobject, gst, unittest
 
 class BufferTest(unittest.TestCase):
     def testBufferBuffer(self):
@@ -80,5 +80,26 @@ class BufferTest(unittest.TestCase):
         buffer.flag_unset(gst.BUFFER_IN_CAPS)
         assert not buffer.flag_is_set(gst.BUFFER_IN_CAPS)
 
+    def testAttrType(self):
+        buffer = gst.Buffer()
+        assert hasattr(buffer, "data_type")
+        # XXX: Expose this in gobject
+        #assert isinstance(buffer.data_type, gobject.GType)
+        assert buffer.data_type == buffer.__gtype__
+        
+    def testAttrFlags(self):
+        buffer = gst.Buffer()
+        assert hasattr(buffer, "flags")
+        assert isinstance(buffer.flags, int)
+    def testAttrTimestamp(self):
+        buffer = gst.Buffer()
+        assert hasattr(buffer, "timestamp")
+        assert isinstance(buffer.timestamp, int)
+
+        assert buffer.timestamp == -1
+        buffer.timestamp = 0
+        assert buffer.timestamp == 0
+        
 if __name__ == "__main__":
     unittest.main()