After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 698562 - rtpbuffer: broken language bindings for gst_rtp_buffer_get_payload
rtpbuffer: broken language bindings for gst_rtp_buffer_get_payload
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal enhancement
: 1.1.2
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-04-22 12:47 UTC by Branko Subasic
Modified: 2013-07-10 07:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
New function to use instead of gst_rtp_buffer_get_payload in language bindings. (3.58 KB, patch)
2013-04-22 12:49 UTC, Branko Subasic
none Details | Review
New patch, same approach as before but modified according to comments (4.60 KB, patch)
2013-05-14 07:17 UTC, Branko Subasic
needs-work Details | Review
New, compilable, patch. Same approach as before but modified according to comments (5.24 KB, patch)
2013-05-14 19:46 UTC, Branko Subasic
none Details | Review
New attmpt, this time using GBytes (5.32 KB, patch)
2013-06-13 21:58 UTC, Branko Subasic
needs-work Details | Review
New (last?) attempt using GBytes. Modified according to comments. (9.77 KB, patch)
2013-06-16 20:50 UTC, Branko Subasic
committed Details | Review
Add new functions to win32/common/libgstrtp.def (997 bytes, patch)
2013-07-09 21:22 UTC, Branko Subasic
committed Details | Review

Description Branko Subasic 2013-04-22 12:47:41 UTC
When calling the function gst_rtp_buffer_get_payload() from Python, i.e. GstRtp.RTPBuffer.get_payload() the program segfaults.

This is caused by the function returning a byte array, but it lacks a length parameter to store the returned array's length. This makes it impossible for the Python bindings to work.

Attached is a patch that remedies this issue.
Since the GstRtpBuffer API is already released we can not simply change the function. Instead I have added a new function gst_rtp_buffer_get_payload_data() with the proper parameters and annotation. Also added a 'Rename to:' annotation in order to replace the original gst_rtp_buffer_get_payload() function with the new gst_rtp_buffer_get_payload_data() when creating bindings.

There is also an error in the annotations for the function gst_rtp_buffer_get_extension_data(). This function does have an output parameter for the length of the array, but it's expressed in number of 32-bit words. Again, this is a released API and can not simply be changed. Thus I've added a a new function that basically wraps the this one, but returns the length in terms of bytes.
Comment 1 Branko Subasic 2013-04-22 12:49:24 UTC
Created attachment 242130 [details] [review]
New function to use instead of gst_rtp_buffer_get_payload in language bindings.
Comment 2 Tim-Philipp Müller 2013-04-23 22:37:26 UTC
Ok, some nitpicks, and some things I'm not sure about yet:

 - please add 'Since: 1.2' markers for new API

 - the old functions that we're replacing via
    Rename-to should probably be marked with
    (skip) or so

 - if these functions are for bindings, it might
   be better to just return const guint8 * or
   guint8 * directly instead of gpointer plus
    annotating the pointer

 - the out length argument should probably
    be gsize now instead of guint. We haven't
    changed it everywhere, but we may just
    as well do it right in new API even if it
    doesn't really make a difference.

 - this whole 'the returned memory is valid
    as long as the object is valid' thing does
    not work too well for bindings, I don't
    think we can express that. I believe
    bindings will work around that by just
    making a copy of the bytes in any case.
    The main implication here is that this
    works fine for reading, but will very likely
    not work for writing at all (since the
    bindings will modified the copied buffer
    and not the original one). I'm guessing
    you are only reading data here?
Comment 3 Olivier Crête 2013-04-23 23:05:32 UTC
Might be a use-case for GBytes ? Although you have the problem that there is no way to invalidate it after a unmap.. You may want to do a _extract() instead that does a memcpy
Comment 4 Tim-Philipp Müller 2013-04-24 07:58:38 UTC
I don't know if GBytes solves the problem with writing directly to the original memory for bindings - does it? (I'm sure the answer is somewhere in bug #678663, but I'm too lazy to check now).
Comment 5 Sebastian Dröge (slomo) 2013-04-24 10:52:43 UTC
GBytes is immutable, yes
Comment 6 Branko Subasic 2013-05-07 20:51:11 UTC
It seems as if using GBytes is not the way to go, right? Given the problem of invalidating it after the memory has been unmapped.

And if the bindings makes a copy of the original data anyway then it's not a big  difference compared to adding an _extract() function. But adding an extract function might make it clearer that it's an actual copy, and it would be similar to the gst_buffer_extract_dup() function.

So, which way to go?
Comment 7 Branko Subasic 2013-05-07 21:27:08 UTC
Tim: yes, we are only reading data.
Comment 8 Branko Subasic 2013-05-14 07:17:33 UTC
Created attachment 244133 [details] [review]
New patch, same approach as before but modified according to comments
Comment 9 Tim-Philipp Müller 2013-05-14 09:04:08 UTC
Comment on attachment 244133 [details] [review]
New patch, same approach as before but modified according to comments

This doesn't even compile...

Please also add the bug number or bug URL at the end of the commit message.
Comment 10 Branko Subasic 2013-05-14 19:46:13 UTC
Created attachment 244236 [details] [review]
New, compilable, patch. Same approach as before but modified according to comments

Tim: Truly sorry about the previous patch. Last minute change of a parameter name, without recompiling it. Unfortunately I missed one occurrence. No last minute changes without compiling and testing this time. 

While fixing it I rewrote the gst_rtp_buffer_get_extension_bytes() function a little.
Comment 11 Sebastian Dröge (slomo) 2013-05-23 15:16:53 UTC
I think GBytes should be used here, as that's apparently what the g-i people recommend to use in such cases.
Comment 12 Branko Subasic 2013-06-13 21:58:24 UTC
Created attachment 246771 [details] [review]
New attmpt, this time using GBytes
Comment 13 Sebastian Dröge (slomo) 2013-06-14 13:15:59 UTC
Review of attachment 246771 [details] [review]:

::: gst-libs/gst/rtp/gstrtpbuffer.c
@@ +713,3 @@
+gboolean
+gst_rtp_buffer_get_extension_bytes (GstRTPBuffer * rtp, guint16 * bits,
+    GBytes ** data)

I think this should just return a GBytes instead of having the out parameter

@@ +727,3 @@
+    *data = g_bytes_new (buf_data, 4 * buf_len);
+  } else {
+    *data = NULL;

And in the buf_len==0 case just return an empty GBytes
Comment 14 Branko Subasic 2013-06-16 20:50:15 UTC
Created attachment 246982 [details] [review]
New (last?) attempt using GBytes. Modified according to comments.
Comment 15 Sebastian Dröge (slomo) 2013-06-18 09:27:30 UTC
commit 4dd5c5b808d1618efbe0364b80c04fb2ca23d65a
Author: Branko Subasic <branko@axis.com>
Date:   Sun Jun 16 22:39:30 2013 +0200

    rtpbuffer: add gst_rtp_buffer_get_payload_bytes
    
    The function gst_rtp_buffer_get_payload can not be used in Python
    because it lacks necessary length parameter. This patch adds a new
    function, gst_rtp_buffer_get_payload_bytes, to use from Python
    bindings. The new function has the advisory "Rename to:" annotation
    so it can replace the gst_rtp_buffer_get_payload whan creating
    bindings.
    
    The function gst_rtp_buffer_get_extension_bytes is also added. It wraps
    gst_rtp_buffer_get_extension_data which doesn't work in Python due to
    incomplete annotation and because it returns the length as number of
    32-bit words.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698562
Comment 16 Branko Subasic 2013-07-09 21:21:38 UTC
Must add the functions to win32/common/libgstrtp.def.
Comment 17 Branko Subasic 2013-07-09 21:22:52 UTC
Created attachment 248775 [details] [review]
Add new functions to win32/common/libgstrtp.def
Comment 18 Sebastian Dröge (slomo) 2013-07-10 07:22:00 UTC
commit 71fa8f945bdabd6dbcf91886cdc0adebaa429ed4
Author: Branko Subasic <branko@axis.com>
Date:   Tue Jul 9 23:04:49 2013 +0200

    win32: add missing rtp buffer methods