Gst_buffer_copy() is missing in gir file

One of our customers tries to create an app based on

which uses gst_buffer_copy().

My default gstreamer-1.16.2 Gentoo gir files does not contain that function at all. For latest git sources it is listed as introspectable=“0”.

Do we have any idea?

salewski@nuc ~ $ grep gst_buffer_copy  /opt/gtk/share/gir-1.0/Gst-1.0.gir 
gst_buffer_copy_into().</doc>
gst_buffer_copy_into().</doc>
use gst_buffer_copy_region(). This method tries to share the memory objects
      <method name="copy" c:identifier="gst_buffer_copy" introspectable="0">
Check gst_buffer_copy_deep() if you want to force the data
              c:identifier="gst_buffer_copy_deep"
      <method name="copy_into" c:identifier="gst_buffer_copy_into">
      <method name="copy_region" c:identifier="gst_buffer_copy_region">
              glib:get-type="gst_buffer_copy_flags_get_type"
           line="491">A set of flags that can be provided to the gst_buffer_copy_into()
gst_buffer_copy(). The passed-in @buf will be unreffed in that case, and the
salewski@nuc ~ $ grep gst_buffer_copy  /usr/share/gir-1.0/Gst-1.0.gir 
gst_buffer_copy_into().</doc>
gst_buffer_copy_into().</doc>
use gst_buffer_copy_region(). This method tries to share the memory objects
              c:identifier="gst_buffer_copy_deep"
      <method name="copy_into" c:identifier="gst_buffer_copy_into">
      <method name="copy_region" c:identifier="gst_buffer_copy_region">
              glib:get-type="gst_buffer_copy_flags_get_type"
           line="488">A set of flags that can be provided to the gst_buffer_copy_into()
gst_buffer_copy(). The passed-in @buf will be unreffed in that case, and the
salewski@nuc ~ $ grep gst_buffer_copy  ~/.nimble/pkgs/gintro-0.8.5/gintro/gst.nim 
proc gst_buffer_copy_deep(self: ptr Buffer00): ptr Buffer00 {.
  result.impl = gst_buffer_copy_deep(cast[ptr Buffer00](self.impl))
proc gst_buffer_copy_into(self: ptr Buffer00; src: ptr Buffer00; flags: BufferCopyFlags;
  toBool(gst_buffer_copy_into(cast[ptr Buffer00](self.impl), cast[ptr Buffer00](src.impl), flags, offset, size))
proc gst_buffer_copy_region(self: ptr Buffer00; flags: BufferCopyFlags; offset: uint64;
  result.impl = gst_buffer_copy_region(cast[ptr Buffer00](self.impl), flags, offset, size)

Since 1.18 it is in the gir file

      <method name="copy" c:identifier="gst_buffer_copy" introspectable="0">
        <doc xml:space="preserve"
             filename="../gst/gstbuffer.h"

But as you can see it’s defined in the header and only as an inline function. This potentially breaks bindings (and does break the C# bindings for example).

gobject-introspection picking up inline function and handling them exactly like normal functions although their symbol is not available in the shared library is discussed in this issue.

On the GStreamer side this will be fixed by this MR by also providing non-inline functions inside the shared library for these, so we don’t have to wait for gobject-introspection to be fixed first.

For pre-1.18 (and generally), you would use gst_mini_object_copy() for copying any kind of miniobject, including GstBuffer. You can call any GstMiniObject function on GstBuffer and other miniobjects.

On the C side, gst_buffer_copy() was a macro until 1.18 that simply called `gst_mini_object_copy().

1 Like

Thanks for your detailed explanations.

I was going to replace gst_buffer_copy() by gst_buffer_copy_deep() which seems to be available by gobject-introspection?

From the C API docs for gst_buffer_copy() we have

This will only copy the buffer’s data to a newly allocated memory if needed (if the type of memory requires it), otherwise the underlying data is just referenced.

My fear is that gst_mini_object_copy() does not support this optimization.

That will do a deep copy and is definitely not equivalent. It will also copy all contained data.

It’s literally the same, just take a look at the code :slight_smile:

1 Like

Funny fact:

grep -C12 gst_mini_object_copy /opt/gtk/share/gir-1.0/Gst-1.0.gir

      <method name="copy"
              c:identifier="gst_mini_object_copy"
              introspectable="0">

But function gst_mini_object_copy() exists in the C file, so I will add that function manually to the Nim bindings.

What’s wrong with the gir file in your opinion? Looks correct to me

If a symbol is not introspectable, it usually means it cannot be called—and not every language binding considers this annotation “optional”.

That was added in this commit apparently. I think the reason here was that otherwise the Python bindings end up generating useless and dangerous bindings. Having them skipped doesn’t seem correct but also was not a problem for any other bindings in the last 5 years it seems.

Realistically you’ll need manual bindings for all the miniobject API anyway or otherwise it’s of rather limited use, will be inflexible and likely involve far more copies of data than needed.