[Gstreamer-openmax] [PATCH 01/10] construct GOmxPort objects in element constructor
Rob Clark
rob at ti.com
Sun Mar 7 15:14:48 PST 2010
The port objects are constructed up front (so they are valid at any point in the element's lifecycle), and bound to a port_index at construction time.
This will be useful later to enable properties that directly set port params.
---
omx/gstomx_base_filter.c | 13 +++++------
omx/gstomx_base_sink.c | 10 +++-----
omx/gstomx_base_src.c | 10 +++-----
omx/gstomx_util.c | 47 +++++++++++++++++++--------------------------
omx/gstomx_util.h | 4 +-
5 files changed, 36 insertions(+), 48 deletions(-)
diff --git a/omx/gstomx_base_filter.c b/omx/gstomx_base_filter.c
index 44841c3..ddb480f 100644
--- a/omx/gstomx_base_filter.c
+++ b/omx/gstomx_base_filter.c
@@ -64,14 +64,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"))
@@ -877,11 +877,10 @@ type_instance_init (GTypeInstance *instance,
self->use_timestamps = TRUE;
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new (self);
- gstomx_get_component_info (gomx, G_TYPE_FROM_CLASS (g_class));
- }
+ self->gomx = g_omx_core_new (self);
+ gstomx_get_component_info (self->gomx, G_TYPE_FROM_CLASS (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 ();
diff --git a/omx/gstomx_base_sink.c b/omx/gstomx_base_sink.c
index 6838f08..1c7888c 100644
--- a/omx/gstomx_base_sink.c
+++ b/omx/gstomx_base_sink.c
@@ -52,7 +52,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);
}
@@ -417,11 +417,9 @@ type_instance_init (GTypeInstance *instance,
GST_LOG_OBJECT (self, "begin");
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new (self);
- gstomx_get_component_info (gomx, G_TYPE_FROM_CLASS (g_class));
- }
+ self->gomx = g_omx_core_new (self);
+ gstomx_get_component_info (self->gomx, G_TYPE_FROM_CLASS (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 dd2be9e..a19c08f 100644
--- a/omx/gstomx_base_src.c
+++ b/omx/gstomx_base_src.c
@@ -43,7 +43,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)
{
@@ -402,11 +402,9 @@ type_instance_init (GTypeInstance *instance,
GST_LOG_OBJECT (self, "begin");
/* GOmx */
- {
- GOmxCore *gomx;
- self->gomx = gomx = g_omx_core_new (self);
- gstomx_get_component_info (gomx, G_TYPE_FROM_CLASS (g_class));
- }
+ self->gomx = g_omx_core_new (self);
+ gstomx_get_component_info (self->gomx, G_TYPE_FROM_CLASS (g_class));
+ self->out_port = g_omx_core_get_port (self->gomx, 1);
GST_LOG_OBJECT (self, "end");
}
diff --git a/omx/gstomx_util.c b/omx/gstomx_util.c
index b2a96c8..d8cc7f0 100644
--- a/omx/gstomx_util.c
+++ b/omx/gstomx_util.c
@@ -76,9 +76,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 +131,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);
@@ -396,37 +394,30 @@ 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 *
+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
@@ -459,12 +450,13 @@ g_omx_core_flush_stop (GOmxCore *core)
*/
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;
@@ -492,6 +484,8 @@ g_omx_port_setup (GOmxPort *port,
{
GOmxPortType type = -1;
+ g_assert (port->port_index == omx_port->nPortIndex);
+
switch (omx_port->eDir)
{
case OMX_DirInput:
@@ -508,7 +502,6 @@ g_omx_port_setup (GOmxPort *port,
/** @todo should it be nBufferCountMin? */
port->num_buffers = omx_port->nBufferCountActual;
port->buffer_size = omx_port->nBufferSize;
- port->port_index = omx_port->nPortIndex;
g_free (port->buffers);
port->buffers = g_new0 (OMX_BUFFERHEADERTYPE *, port->num_buffers);
@@ -904,7 +897,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);
@@ -921,7 +914,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 6450c0d..060b042 100644
--- a/omx/gstomx_util.h
+++ b/omx/gstomx_util.h
@@ -130,9 +130,9 @@ 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);
+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);
--
1.6.3.2
More information about the Gstreamer-openmax
mailing list