[Gstreamer-openmax] [PATCH] a small bit of refactoring to gstomx_util, to allow for more flexibility of when the OMX component and port is instantiated
Rob Clark
rob at ti.com
Tue Nov 3 18:25:04 PST 2009
Signed-off-by: Rob Clark <rob at ti.com>
---
omx/gstomx_base_filter.c | 24 ++------
omx/gstomx_base_sink.c | 21 ++------
omx/gstomx_base_src.c | 22 ++------
omx/gstomx_util.c | 133 +++++++++++++++++++++++++++++++++++-----------
omx/gstomx_util.h | 12 +++--
5 files changed, 123 insertions(+), 89 deletions(-)
diff --git a/omx/gstomx_base_filter.c b/omx/gstomx_base_filter.c
index 287f50c..6b90673 100644
--- a/omx/gstomx_base_filter.c
+++ b/omx/gstomx_base_filter.c
@@ -66,14 +66,14 @@ setup_ports (GstOmxBaseFilter *self)
param.nPortIndex = 0;
OMX_GetParameter (core->omx_handle, OMX_IndexParamPortDefinition, ¶m);
- self->in_port = g_omx_core_setup_port (core, ¶m);
+ g_omx_port_setup (self->in_port, ¶m);
gst_pad_set_element_private (self->sinkpad, self->in_port);
/* Output port configuration. */
param.nPortIndex = 1;
OMX_GetParameter (core->omx_handle, OMX_IndexParamPortDefinition, ¶m);
- self->out_port = g_omx_core_setup_port (core, ¶m);
+ g_omx_port_setup (self->out_port, ¶m);
gst_pad_set_element_private (self->srcpad, self->out_port);
if (g_getenv ("OMX_ALLOCATE_ON"))
@@ -115,7 +115,7 @@ change_state (GstElement *element,
switch (transition)
{
case GST_STATE_CHANGE_NULL_TO_READY:
- g_omx_core_init (core, self->omx_library, self->omx_component);
+ g_omx_core_init (core);
if (core->omx_state != OMX_StateLoaded)
{
ret = GST_STATE_CHANGE_FAILURE;
@@ -898,11 +898,9 @@ type_instance_init (GTypeInstance *instance,
self->use_timestamps = TRUE;
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new ();
- gomx->object = self;
- }
+ self->gomx = g_omx_core_new (self, g_class);
+ self->in_port = g_omx_core_get_port (self->gomx, 0);
+ self->out_port = g_omx_core_get_port (self->gomx, 1);
self->ready_lock = g_mutex_new ();
@@ -922,16 +920,6 @@ type_instance_init (GTypeInstance *instance,
gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
- {
- const char *tmp;
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("library-name"));
- self->omx_library = g_strdup (tmp);
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("component-name"));
- self->omx_component = g_strdup (tmp);
- }
-
GST_LOG_OBJECT (self, "end");
}
diff --git a/omx/gstomx_base_sink.c b/omx/gstomx_base_sink.c
index b50564d..1f2e271 100644
--- a/omx/gstomx_base_sink.c
+++ b/omx/gstomx_base_sink.c
@@ -58,7 +58,7 @@ setup_ports (GstOmxBaseSink *self)
param.nPortIndex = 0;
OMX_GetParameter (core->omx_handle, OMX_IndexParamPortDefinition, ¶m);
- self->in_port = g_omx_core_setup_port (core, ¶m);
+ g_omx_port_setup (self->in_port, ¶m);
gst_pad_set_element_private (self->sinkpad, self->in_port);
}
@@ -420,7 +420,7 @@ activate_push (GstPad *pad,
static inline gboolean
omx_init (GstOmxBaseSink *self)
{
- g_omx_core_init (self->gomx, self->omx_library, self->omx_component);
+ g_omx_core_init (self->gomx);
if (self->gomx->omx_error)
return FALSE;
@@ -461,21 +461,8 @@ type_instance_init (GTypeInstance *instance,
GST_LOG_OBJECT (self, "begin");
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new ();
- gomx->object = self;
- }
-
- {
- const char *tmp;
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("library-name"));
- self->omx_library = g_strdup (tmp);
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("component-name"));
- self->omx_component = g_strdup (tmp);
- }
+ self->gomx = g_omx_core_new (self, g_class);
+ self->in_port = g_omx_core_get_port (self->gomx, 0);
{
GstPad *sinkpad;
diff --git a/omx/gstomx_base_src.c b/omx/gstomx_base_src.c
index 9b02b22..e8a1c95 100644
--- a/omx/gstomx_base_src.c
+++ b/omx/gstomx_base_src.c
@@ -50,7 +50,7 @@ setup_ports (GstOmxBaseSrc *self)
param.nPortIndex = 0;
OMX_GetParameter (core->omx_handle, OMX_IndexParamPortDefinition, ¶m);
- self->out_port = g_omx_core_setup_port (core, ¶m);
+ g_omx_port_setup (self->out_port, ¶m);
if (self->setup_ports)
{
@@ -67,7 +67,7 @@ start (GstBaseSrc *gst_base)
GST_LOG_OBJECT (self, "begin");
- g_omx_core_init (self->gomx, self->omx_library, self->omx_component);
+ g_omx_core_init (self->gomx);
if (self->gomx->omx_error)
return GST_STATE_CHANGE_FAILURE;
@@ -453,22 +453,8 @@ type_instance_init (GTypeInstance *instance,
GST_LOG_OBJECT (self, "begin");
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new ();
- gomx->object = self;
- }
-
- {
- const char *tmp;
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("library-name"));
- self->omx_library = g_strdup (tmp);
- tmp = g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
- g_quark_from_static_string ("component-name"));
- self->omx_component = g_strdup (tmp);
- }
-
+ self->gomx = g_omx_core_new (self, g_class);
+ self->out_port = g_omx_core_get_port (self->gomx, 0);
GST_LOG_OBJECT (self, "end");
}
diff --git a/omx/gstomx_util.c b/omx/gstomx_util.c
index 39d900b..1cd224f 100644
--- a/omx/gstomx_util.c
+++ b/omx/gstomx_util.c
@@ -22,6 +22,7 @@
#include "gstomx_util.h"
#include <dlfcn.h>
+#include <string.h>
#include "gstomx.h"
@@ -76,9 +77,7 @@ omx_state_to_str (OMX_STATETYPE omx_state);
static inline const char *
omx_error_to_str (OMX_ERRORTYPE omx_error);
-static inline GOmxPort *
-g_omx_core_get_port (GOmxCore *core,
- guint index);
+static inline GOmxPort *get_port (GOmxCore *core, guint index);
static inline void
port_free_buffers (GOmxPort *port);
@@ -133,7 +132,7 @@ core_for_each_port (GOmxCore *core,
{
GOmxPort *port;
- port = g_omx_core_get_port (core, index);
+ port = get_port (core, index);
if (port)
func (port);
@@ -159,6 +158,7 @@ imp_new (const gchar *name)
void *handle;
imp->dl_handle = handle = dlopen (name, RTLD_LAZY);
+ GST_DEBUG ("dlopen(%s) -> %p", name, handle);
if (!handle)
{
g_warning ("%s\n", dlerror ());
@@ -264,13 +264,22 @@ g_omx_deinit (void)
* Core
*/
+/**
+ * Construct new core
+ *
+ * @object: the GstOmx object (ie. GstOmxBaseFilter, GstOmxBaseSrc, or
+ * GstOmxBaseSink). The GstOmx object should have "component-name"
+ * and "library-name" properties.
+ */
GOmxCore *
-g_omx_core_new (void)
+g_omx_core_new (gpointer object, gpointer klass)
{
GOmxCore *core;
core = g_new0 (GOmxCore, 1);
+ core->object = object;
+
core->ports = g_ptr_array_new ();
core->omx_state_condition = g_cond_new ();
@@ -282,12 +291,33 @@ g_omx_core_new (void)
core->omx_state = OMX_StateInvalid;
+ {
+ gchar *library_name, *component_name, *component_role;
+
+ library_name = g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
+ g_quark_from_static_string ("library-name"));
+
+ component_name = g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
+ g_quark_from_static_string ("component-name"));
+
+ component_role = g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
+ g_quark_from_static_string ("component-role"));
+
+ g_object_set (core->object,
+ "component-role", component_role,
+ "component-name", component_name,
+ "library-name", library_name,
+ NULL);
+ }
+
return core;
}
void
g_omx_core_free (GOmxCore *core)
{
+ g_omx_core_deinit (core); /* just in case we didn't have a READY->NULL.. mainly for gst-inspect */
+
g_sem_free (core->port_sem);
g_sem_free (core->flush_sem);
g_sem_free (core->done_sem);
@@ -301,10 +331,23 @@ g_omx_core_free (GOmxCore *core)
}
void
-g_omx_core_init (GOmxCore *core,
- const gchar *library_name,
- const gchar *component_name)
+g_omx_core_init (GOmxCore *core)
{
+ gchar *library_name=NULL, *component_name=NULL;
+
+ if (core->omx_handle)
+ return;
+
+ GST_DEBUG_OBJECT (core->object, "loading: %s (%s)", component_name, library_name);
+
+ g_object_get (core->object,
+ "component-name", &component_name,
+ "library-name", &library_name,
+ NULL);
+
+ g_return_if_fail (component_name);
+ g_return_if_fail (library_name);
+
core->imp = request_imp (library_name);
if (!core->imp)
@@ -314,8 +357,15 @@ g_omx_core_init (GOmxCore *core,
(char *) component_name,
core,
&callbacks);
+
+ GST_DEBUG_OBJECT (core->object, "OMX_GetHandle(&%p) -> %d",
+ core->omx_handle, core->omx_error);
+
if (!core->omx_error)
core->omx_state = OMX_StateLoaded;
+
+ g_free (component_name);
+ g_free (library_name);
}
void
@@ -328,7 +378,12 @@ g_omx_core_deinit (GOmxCore *core)
core->omx_state == OMX_StateInvalid)
{
if (core->omx_handle)
+ {
core->omx_error = core->imp->sym_table.free_handle (core->omx_handle);
+ GST_DEBUG_OBJECT (core->object, "OMX_FreeHandle(%p) -> %d",
+ core->omx_handle, core->omx_error);
+ core->omx_handle = NULL;
+ }
}
release_imp (core->imp);
@@ -394,37 +449,29 @@ g_omx_core_unload (GOmxCore *core)
g_ptr_array_clear (core->ports);
}
-GOmxPort *
-g_omx_core_setup_port (GOmxCore *core,
- OMX_PARAM_PORTDEFINITIONTYPE *omx_port)
+static inline GOmxPort *
+get_port (GOmxCore *core, guint index)
{
- GOmxPort *port;
- guint index;
-
- index = omx_port->nPortIndex;
- port = g_omx_core_get_port (core, index);
-
- if (!port)
+ if (G_LIKELY (index < core->ports->len))
{
- port = g_omx_port_new (core);
- g_ptr_array_insert (core->ports, index, port);
+ return g_ptr_array_index (core->ports, index);
}
- g_omx_port_setup (port, omx_port);
-
- return port;
+ return NULL;
}
-static inline GOmxPort *
-g_omx_core_get_port (GOmxCore *core,
- guint index)
+GOmxPort *
+g_omx_core_get_port (GOmxCore *core, guint index)
{
- if (G_LIKELY (index < core->ports->len))
+ GOmxPort *port = get_port (core, index);
+
+ if (!port)
{
- return g_ptr_array_index (core->ports, index);
+ port = g_omx_port_new (core, index);
+ g_ptr_array_insert (core->ports, index, port);
}
- return NULL;
+ return port;
}
void
@@ -452,17 +499,31 @@ g_omx_core_flush_stop (GOmxCore *core)
core_for_each_port (core, g_omx_port_resume);
}
+/**
+ * Accessor for OMX component handle. If the OMX component is not constructed
+ * yet, this will trigger it to be constructed (OMX_GetHandle()). This should
+ * at least be used in places where g_omx_core_init() might not have been
+ * called yet (such as setting/getting properties)
+ */
+OMX_HANDLETYPE
+g_omx_core_get_handle (GOmxCore *core)
+{
+ if (!core->omx_handle) g_omx_core_init (core);
+ return core->omx_handle;
+}
+
/*
* Port
*/
GOmxPort *
-g_omx_port_new (GOmxCore *core)
+g_omx_port_new (GOmxCore *core, guint index)
{
GOmxPort *port;
port = g_new0 (GOmxPort, 1);
port->core = core;
+ port->port_index = index;
port->num_buffers = 0;
port->buffer_size = 0;
port->buffers = NULL;
@@ -508,6 +569,10 @@ g_omx_port_setup (GOmxPort *port,
port->buffer_size = omx_port->nBufferSize;
port->port_index = omx_port->nPortIndex;
+ GST_DEBUG_OBJECT (port->core->object,
+ "type=%d, num_buffers=%d, buffer_size=%d, port_index=%d",
+ port->type, port->num_buffers, port->buffer_size, port->port_index);
+
g_free (port->buffers);
port->buffers = g_new0 (OMX_BUFFERHEADERTYPE *, port->num_buffers);
}
@@ -840,6 +905,8 @@ EventHandler (OMX_HANDLETYPE omx_handle,
cmd = (OMX_COMMANDTYPE) data_1;
+ GST_DEBUG_OBJECT (core->object, "OMX_EventCmdComplete: %d", cmd);
+
switch (cmd)
{
case OMX_CommandStateSet:
@@ -858,6 +925,7 @@ EventHandler (OMX_HANDLETYPE omx_handle,
}
case OMX_EventBufferFlag:
{
+ GST_DEBUG_OBJECT (core->object, "OMX_EventBufferFlag");
if (data_2 & OMX_BUFFERFLAG_EOS)
{
g_omx_core_set_done (core);
@@ -866,6 +934,7 @@ EventHandler (OMX_HANDLETYPE omx_handle,
}
case OMX_EventPortSettingsChanged:
{
+ GST_DEBUG_OBJECT (core->object, "OMX_EventPortSettingsChanged");
/** @todo only on the relevant port. */
if (core->settings_changed_cb)
{
@@ -902,7 +971,7 @@ EmptyBufferDone (OMX_HANDLETYPE omx_handle,
GOmxPort *port;
core = (GOmxCore*) app_data;
- port = g_omx_core_get_port (core, omx_buffer->nInputPortIndex);
+ port = get_port (core, omx_buffer->nInputPortIndex);
GST_CAT_LOG_OBJECT (gstomx_util_debug, core->object, "omx_buffer=%p", omx_buffer);
got_buffer (core, port, omx_buffer);
@@ -919,7 +988,7 @@ FillBufferDone (OMX_HANDLETYPE omx_handle,
GOmxPort *port;
core = (GOmxCore *) app_data;
- port = g_omx_core_get_port (core, omx_buffer->nOutputPortIndex);
+ port = get_port (core, omx_buffer->nOutputPortIndex);
GST_CAT_LOG_OBJECT (gstomx_util_debug, core->object, "omx_buffer=%p", omx_buffer);
got_buffer (core, port, omx_buffer);
diff --git a/omx/gstomx_util.h b/omx/gstomx_util.h
index f0cf045..4857265 100644
--- a/omx/gstomx_util.h
+++ b/omx/gstomx_util.h
@@ -114,9 +114,9 @@ struct GOmxPort
void g_omx_init (void);
void g_omx_deinit (void);
-GOmxCore *g_omx_core_new (void);
+GOmxCore *g_omx_core_new (gpointer object, gpointer klass);
void g_omx_core_free (GOmxCore *core);
-void g_omx_core_init (GOmxCore *core, const gchar *library_name, const gchar *component_name);
+void g_omx_core_init (GOmxCore *core);
void g_omx_core_deinit (GOmxCore *core);
void g_omx_core_prepare (GOmxCore *core);
void g_omx_core_start (GOmxCore *core);
@@ -127,9 +127,11 @@ void g_omx_core_set_done (GOmxCore *core);
void g_omx_core_wait_for_done (GOmxCore *core);
void g_omx_core_flush_start (GOmxCore *core);
void g_omx_core_flush_stop (GOmxCore *core);
-GOmxPort *g_omx_core_setup_port (GOmxCore *core, OMX_PARAM_PORTDEFINITIONTYPE *omx_port);
+OMX_HANDLETYPE g_omx_core_get_handle (GOmxCore *core);
+GOmxPort *g_omx_core_get_port (GOmxCore *core, guint index);
-GOmxPort *g_omx_port_new (GOmxCore *core);
+
+GOmxPort *g_omx_port_new (GOmxCore *core, guint index);
void g_omx_port_free (GOmxPort *port);
void g_omx_port_setup (GOmxPort *port, OMX_PARAM_PORTDEFINITIONTYPE *omx_port);
void g_omx_port_push_buffer (GOmxPort *port, OMX_BUFFERHEADERTYPE *omx_buffer);
@@ -142,4 +144,6 @@ void g_omx_port_enable (GOmxPort *port);
void g_omx_port_disable (GOmxPort *port);
void g_omx_port_finish (GOmxPort *port);
+
+
#endif /* GSTOMX_UTIL_H */
--
1.6.3.2
More information about the Gstreamer-openmax
mailing list