diff options
author | Rob Clark <rob@ti.com> | 2010-03-17 17:50:29 -0500 |
---|---|---|
committer | Felipe Contreras <felipe.contreras@nokia.com> | 2010-04-16 17:29:24 +0300 |
commit | 69d756373bc886d3ef49a743c13f126b1c0b6413 (patch) | |
tree | 48cd2b6fcafab4ac5b22e654ba57d5f154bb75c4 | |
parent | 30f3679d309b3ea91c9ca385a5d026abf97ec5a2 (diff) |
Construct GOmxPort objects in element constructor
The port objects are constructed up in element constructor (so they are
valid at any point in the element's lifecycle), and bound to a
port_index at construction time, rather than getting constructed in
setup_ports.
This will be useful later to enable properties that directly set port
params.
Signed-off-by: Felipe Contreras <felipe.contreras@nokia.com>
-rw-r--r-- | omx/gstomx_base_filter.c | 7 | ||||
-rw-r--r-- | omx/gstomx_base_sink.c | 3 | ||||
-rw-r--r-- | omx/gstomx_base_src.c | 3 | ||||
-rw-r--r-- | omx/gstomx_util.c | 56 | ||||
-rw-r--r-- | omx/gstomx_util.h | 4 |
5 files changed, 39 insertions, 34 deletions
diff --git a/omx/gstomx_base_filter.c b/omx/gstomx_base_filter.c index 9e9d31e..bc0a77d 100644 --- a/omx/gstomx_base_filter.c +++ b/omx/gstomx_base_filter.c @@ -67,16 +67,17 @@ 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); + /* @todo: read from config file: */ if (g_getenv ("OMX_ALLOCATE_ON")) { self->in_port->omx_allocate = TRUE; @@ -892,6 +893,8 @@ type_instance_init (GTypeInstance *instance, 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_new_port (self->gomx, 0); + self->out_port = g_omx_core_new_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 97200b0..f946874 100644 --- a/omx/gstomx_base_sink.c +++ b/omx/gstomx_base_sink.c @@ -59,7 +59,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); } @@ -436,6 +436,7 @@ type_instance_init (GTypeInstance *instance, 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_new_port (self->gomx, 0); { GstPad *sinkpad; diff --git a/omx/gstomx_base_src.c b/omx/gstomx_base_src.c index ee04e78..0741aab 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) { @@ -421,6 +421,7 @@ type_instance_init (GTypeInstance *instance, 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_new_port (self->gomx, 1); GST_LOG_OBJECT (self, "end"); } diff --git a/omx/gstomx_util.c b/omx/gstomx_util.c index b2a96c8..e1060da 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,33 @@ 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, +GOmxPort * +g_omx_core_new_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); + GST_WARNING_OBJECT (core->object, "port %d already exists", index); + return port; } - return NULL; + port = g_omx_port_new (core, index); + g_ptr_array_insert (core->ports, index, port); + + return port; } void @@ -458,13 +452,18 @@ g_omx_core_flush_stop (GOmxCore *core) * Port */ +/** + * note: this is not intended to be called directly by elements (which should + * instead use g_omx_core_new_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; @@ -492,6 +491,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 +509,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 +904,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 +921,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..f763618 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_new_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); |