Skip to content

Commit

Permalink
gst: Add non-inline methods for bindings to able to use core APIs
Browse files Browse the repository at this point in the history
Provide non-inline version of refcounting APIs so that it can be
consumed by bindings

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer-sharp/-/issues/46
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/728>
  • Loading branch information
seungha-yang committed Jan 11, 2021
1 parent e02902a commit 84a3f04
Show file tree
Hide file tree
Showing 25 changed files with 1,230 additions and 622 deletions.
94 changes: 94 additions & 0 deletions gst/gstbuffer.c
Expand Up @@ -116,6 +116,7 @@
* for re-use. (Since: 1.6)
*
*/
#define GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
#include "gst_private.h"

#ifdef HAVE_UNISTD_H
Expand Down Expand Up @@ -2933,3 +2934,96 @@ gst_buffer_get_custom_meta (GstBuffer * buffer, const gchar * name)

return (GstCustomMeta *) gst_buffer_get_meta (buffer, info->api);
}

/**
* gst_buffer_ref: (skip)
* @buf: a #GstBuffer.
*
* Increases the refcount of the given buffer by one.
*
* Note that the refcount affects the writability
* of @buf and its metadata, see gst_buffer_is_writable().
* It is important to note that keeping additional references to
* GstBuffer instances can potentially increase the number
* of memcpy operations in a pipeline.
*
* Returns: (transfer full): @buf
*/
GstBuffer *
gst_buffer_ref (GstBuffer * buf)
{
return (GstBuffer *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (buf));
}

/**
* gst_buffer_unref: (skip)
* @buf: (transfer full): a #GstBuffer.
*
* Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
* with the associated metadata and memory will be freed.
*/
void
gst_buffer_unref (GstBuffer * buf)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (buf));
}

/**
* gst_clear_buffer: (skip)
* @buf_ptr: a pointer to a #GstBuffer reference
*
* Clears a reference to a #GstBuffer.
*
* @buf_ptr must not be %NULL.
*
* If the reference is %NULL then this function does nothing. Otherwise, the
* reference count of the buffer is decreased and the pointer is set to %NULL.
*
* Since: 1.16
*/
void
gst_clear_buffer (GstBuffer ** buf_ptr)
{
gst_clear_mini_object ((GstMiniObject **) buf_ptr);
}

/**
* gst_buffer_copy: (skip)
* @buf: a #GstBuffer.
*
* Create a copy of the given buffer. 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.
* Check gst_buffer_copy_deep() if you want to force the data
* to be copied to newly allocated memory.
*
* Returns: (transfer full): a new copy of @buf.
*/
GstBuffer *
gst_buffer_copy (const GstBuffer * buf)
{
return GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (buf)));
}

/**
* gst_buffer_replace: (skip)
* @obuf: (inout) (transfer full) (nullable): pointer to a pointer to
* a #GstBuffer to be replaced.
* @nbuf: (transfer none) (allow-none): pointer to a #GstBuffer that will
* replace the buffer pointed to by @obuf.
*
* Modifies a pointer to a #GstBuffer to point to a different #GstBuffer. The
* modification is done atomically (so this is useful for ensuring thread safety
* in some cases), and the reference counts are updated appropriately (the old
* buffer is unreffed, the new is reffed).
*
* Either @nbuf or the #GstBuffer pointed to by @obuf may be %NULL.
*
* Returns: %TRUE when @obuf was different from @nbuf.
*/
gboolean
gst_buffer_replace (GstBuffer ** obuf, GstBuffer * nbuf)
{
return gst_mini_object_replace ((GstMiniObject **) obuf,
(GstMiniObject *) nbuf);
}
87 changes: 20 additions & 67 deletions gst/gstbuffer.h
Expand Up @@ -409,81 +409,45 @@ GST_API
gboolean gst_buffer_unset_flags (GstBuffer * buffer, GstBufferFlags flags);



#ifndef GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
/* refcounting */
/**
* gst_buffer_ref: (skip)
* @buf: a #GstBuffer.
*
* Increases the refcount of the given buffer by one.
*
* Note that the refcount affects the writability
* of @buf and its metadata, see gst_buffer_is_writable().
* It is important to note that keeping additional references to
* GstBuffer instances can potentially increase the number
* of memcpy operations in a pipeline.
*
* Returns: (transfer full): @buf
*/
static inline GstBuffer* gst_buffer_ref(GstBuffer* buf);
static inline GstBuffer *
gst_buffer_ref (GstBuffer * buf)
{
return (GstBuffer *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (buf));
}

/**
* gst_buffer_unref: (skip)
* @buf: (transfer full): a #GstBuffer.
*
* Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
* with the associated metadata and memory will be freed.
*/
static inline void gst_buffer_unref(GstBuffer* buf);
static inline void
gst_buffer_unref (GstBuffer * buf)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (buf));
}

/**
* gst_clear_buffer: (skip)
* @buf_ptr: a pointer to a #GstBuffer reference
*
* Clears a reference to a #GstBuffer.
*
* @buf_ptr must not be %NULL.
*
* If the reference is %NULL then this function does nothing. Otherwise, the
* reference count of the buffer is decreased and the pointer is set to %NULL.
*
* Since: 1.16
*/
static inline void
gst_clear_buffer (GstBuffer ** buf_ptr)
{
gst_clear_mini_object ((GstMiniObject **) buf_ptr);
}

/* copy buffer */
/**
* gst_buffer_copy: (skip)
* @buf: a #GstBuffer.
*
* Create a copy of the given buffer. 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.
* Check gst_buffer_copy_deep() if you want to force the data
* to be copied to newly allocated memory.
*
* Returns: (transfer full): a new copy of @buf.
*/
static inline GstBuffer* gst_buffer_copy(const GstBuffer* buf);
static inline GstBuffer *
gst_buffer_copy (const GstBuffer * buf)
{
return GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (buf)));
}
#else /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
GST_API
GstBuffer * gst_buffer_ref (GstBuffer * buf);

GST_API
void gst_buffer_unref (GstBuffer * buf);

GST_API
void gst_clear_buffer (GstBuffer ** buf_ptr);

GST_API
GstBuffer * gst_buffer_copy (const GstBuffer * buf);
#endif /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */

GST_API
GstBuffer * gst_buffer_copy_deep (const GstBuffer * buf);
Expand Down Expand Up @@ -579,28 +543,17 @@ gboolean gst_buffer_copy_into (GstBuffer *dest, GstBuffer *src
*/
#define gst_buffer_make_writable(buf) GST_BUFFER_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (buf)))

/**
* gst_buffer_replace: (skip)
* @obuf: (inout) (transfer full) (nullable): pointer to a pointer to
* a #GstBuffer to be replaced.
* @nbuf: (transfer none) (allow-none): pointer to a #GstBuffer that will
* replace the buffer pointed to by @obuf.
*
* Modifies a pointer to a #GstBuffer to point to a different #GstBuffer. The
* modification is done atomically (so this is useful for ensuring thread safety
* in some cases), and the reference counts are updated appropriately (the old
* buffer is unreffed, the new is reffed).
*
* Either @nbuf or the #GstBuffer pointed to by @obuf may be %NULL.
*
* Returns: %TRUE when @obuf was different from @nbuf.
*/
static inline gboolean gst_buffer_replace(GstBuffer** obuf, GstBuffer* nbuf);
#ifndef GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
static inline gboolean
gst_buffer_replace (GstBuffer **obuf, GstBuffer *nbuf)
{
return gst_mini_object_replace ((GstMiniObject **) obuf, (GstMiniObject *) nbuf);
}
#else /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
GST_API
gboolean gst_buffer_replace (GstBuffer ** obuf,
GstBuffer * nbuf);
#endif /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */

/* creating a region */

Expand Down
118 changes: 118 additions & 0 deletions gst/gstbufferlist.c
Expand Up @@ -36,6 +36,7 @@
* interesting when multiple buffers need to be pushed in one go because it
* can reduce the amount of overhead for pushing each buffer individually.
*/
#define GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
#include "gst_private.h"

#include "gstbuffer.h"
Expand Down Expand Up @@ -553,3 +554,120 @@ gst_buffer_list_calculate_size (GstBufferList * list)

return size;
}

/**
* gst_buffer_list_ref: (skip)
* @list: a #GstBufferList
*
* Increases the refcount of the given buffer list by one.
*
* Note that the refcount affects the writability of @list and its data, see
* gst_buffer_list_make_writable(). It is important to note that keeping
* additional references to GstBufferList instances can potentially increase
* the number of memcpy operations in a pipeline.
*
* Returns: (transfer full): @list
*/
GstBufferList *
gst_buffer_list_ref (GstBufferList * list)
{
return
GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (list)));
}

/**
* gst_buffer_list_unref: (skip)
* @list: (transfer full): a #GstBufferList
*
* Decreases the refcount of the buffer list. If the refcount reaches 0, the
* buffer list will be freed.
*/
void
gst_buffer_list_unref (GstBufferList * list)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (list));
}

/**
* gst_clear_buffer_list: (skip)
* @list_ptr: a pointer to a #GstBufferList reference
*
* Clears a reference to a #GstBufferList.
*
* @list_ptr must not be %NULL.
*
* If the reference is %NULL then this function does nothing. Otherwise, the
* reference count of the list is decreased and the pointer is set to %NULL.
*
* Since: 1.16
*/
void
gst_clear_buffer_list (GstBufferList ** list_ptr)
{
gst_clear_mini_object ((GstMiniObject **) list_ptr);
}

/**
* gst_buffer_list_copy: (skip)
* @list: a #GstBufferList
*
* Create a shallow copy of the given buffer list. This will make a newly
* allocated copy of the source list with copies of buffer pointers. The
* refcount of buffers pointed to will be increased by one.
*
* Returns: (transfer full): a new copy of @list.
*/
GstBufferList *
gst_buffer_list_copy (const GstBufferList * list)
{
return
GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST
(list)));
}

/**
* gst_buffer_list_replace:
* @old_list: (inout) (transfer full) (nullable): pointer to a pointer to a
* #GstBufferList to be replaced.
* @new_list: (transfer none) (allow-none): pointer to a #GstBufferList that
* will replace the buffer list pointed to by @old_list.
*
* Modifies a pointer to a #GstBufferList to point to a different
* #GstBufferList. The modification is done atomically (so this is useful for
* ensuring thread safety in some cases), and the reference counts are updated
* appropriately (the old buffer list is unreffed, the new is reffed).
*
* Either @new_list or the #GstBufferList pointed to by @old_list may be %NULL.
*
* Returns: %TRUE if @new_list was different from @old_list
*
* Since: 1.16
*/
gboolean
gst_buffer_list_replace (GstBufferList ** old_list, GstBufferList * new_list)
{
return gst_mini_object_replace ((GstMiniObject **) old_list,
(GstMiniObject *) new_list);
}

/**
* gst_buffer_list_take:
* @old_list: (inout) (transfer full): pointer to a pointer to a #GstBufferList
* to be replaced.
* @new_list: (transfer full) (allow-none): pointer to a #GstBufferList
* that will replace the bufferlist pointed to by @old_list.
*
* Modifies a pointer to a #GstBufferList to point to a different
* #GstBufferList. This function is similar to gst_buffer_list_replace() except
* that it takes ownership of @new_list.
*
* Returns: %TRUE if @new_list was different from @old_list
*
* Since: 1.16
*/
gboolean
gst_buffer_list_take (GstBufferList ** old_list, GstBufferList * new_list)
{
return gst_mini_object_take ((GstMiniObject **) old_list,
(GstMiniObject *) new_list);
}

0 comments on commit 84a3f04

Please sign in to comment.