omx: factor out gst_omx_buffer_get/set_omx_buf()

Move the qdata code to helper functions as I'm going to need them in
omxvideoenc to implement dmabuf export.

https://bugzilla.gnome.org/show_bug.cgi?id=796918
This commit is contained in:
Guillaume Desmottes 2018-05-15 16:21:26 +02:00
parent 092788a968
commit 457e1b9a5e
3 changed files with 25 additions and 14 deletions

View file

@ -70,6 +70,8 @@ static GHashTable *core_handles;
G_LOCK_DEFINE_STATIC (buffer_flags_str);
static GHashTable *buffer_flags_str;
static GQuark gst_omx_buffer_data_quark = 0;
GstOMXCore *
gst_omx_core_acquire (const gchar * filename)
{
@ -2960,6 +2962,20 @@ gst_omx_set_default_role (GstOMXClassData * class_data,
class_data->component_role = default_role;
}
void
gst_omx_buffer_set_omx_buf (GstBuffer * buffer, GstOMXBuffer * omx_buf)
{
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buffer),
gst_omx_buffer_data_quark, omx_buf, NULL);
}
GstOMXBuffer *
gst_omx_buffer_get_omx_buf (GstBuffer * buffer)
{
return gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buffer),
gst_omx_buffer_data_quark);
}
static void
_class_init (gpointer g_class, gpointer data)
{
@ -3130,6 +3146,8 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (OMX_PERFORMANCE, "OMX_PERFORMANCE", 0,
"gst-omx performace");
gst_omx_buffer_data_quark = g_quark_from_static_string ("GstOMXBufferData");
/* Read configuration file gstomx.conf from the preferred
* configuration directories */
env_config_dir = g_strdup (g_getenv (*env_config_name));

View file

@ -469,6 +469,9 @@ gboolean gst_omx_buffer_import_fd (GstOMXBuffer * buffer, GstBuffer * i
void gst_omx_set_default_role (GstOMXClassData *class_data, const gchar *default_role);
void gst_omx_buffer_set_omx_buf (GstBuffer * buffer, GstOMXBuffer * omx_buf);
GstOMXBuffer * gst_omx_buffer_get_omx_buf (GstBuffer * buffer);
/* refered by plugin_init */
GST_DEBUG_CATEGORY_EXTERN (gst_omx_video_debug_category);

View file

@ -203,8 +203,6 @@ gst_omx_memory_allocator_alloc (GstAllocator * allocator, GstMemoryFlags flags,
* back to the component (OMX_FillThisBuffer()) when it is released.
*/
static GQuark gst_omx_buffer_data_quark = 0;
#define DEBUG_INIT \
GST_DEBUG_CATEGORY_INIT (gst_omx_buffer_pool_debug_category, "omxbufferpool", 0, \
"debug category for gst-omx buffer pool base class");
@ -491,8 +489,7 @@ gst_omx_buffer_pool_alloc_buffer (GstBufferPool * bpool,
}
}
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buf),
gst_omx_buffer_data_quark, omx_buf, NULL);
gst_omx_buffer_set_omx_buf (buf, omx_buf);
*buffer = buf;
@ -514,8 +511,7 @@ gst_omx_buffer_pool_free_buffer (GstBufferPool * bpool, GstBuffer * buffer)
}
GST_OBJECT_UNLOCK (pool);
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buffer),
gst_omx_buffer_data_quark, NULL, NULL);
gst_omx_buffer_set_omx_buf (buffer, NULL);
GST_BUFFER_POOL_CLASS (gst_omx_buffer_pool_parent_class)->free_buffer (bpool,
buffer);
@ -544,9 +540,7 @@ gst_omx_buffer_pool_acquire_buffer (GstBufferPool * bpool,
GstOMXBuffer *omx_buf;
if (pool->output_mode == GST_OMX_BUFFER_MODE_DMABUF) {
omx_buf =
gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buf),
gst_omx_buffer_data_quark);
omx_buf = gst_omx_buffer_get_omx_buf (buf);
} else {
g_assert (mem
&& g_strcmp0 (mem->allocator->mem_type, GST_OMX_MEMORY_TYPE) == 0);
@ -578,9 +572,7 @@ gst_omx_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
g_assert (pool->component && pool->port);
if (!pool->allocating && !pool->deactivated) {
omx_buf =
gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buffer),
gst_omx_buffer_data_quark);
omx_buf = gst_omx_buffer_get_omx_buf (buffer);
if (pool->port->port_def.eDir == OMX_DirOutput && !omx_buf->used) {
/* Release back to the port, can be filled again */
err = gst_omx_port_release_buffer (pool->port, omx_buf);
@ -645,8 +637,6 @@ gst_omx_buffer_pool_class_init (GstOMXBufferPoolClass * klass)
GObjectClass *gobject_class = (GObjectClass *) klass;
GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
gst_omx_buffer_data_quark = g_quark_from_static_string ("GstOMXBufferData");
gobject_class->finalize = gst_omx_buffer_pool_finalize;
gstbufferpool_class->start = gst_omx_buffer_pool_start;
gstbufferpool_class->stop = gst_omx_buffer_pool_stop;