[Gstreamer-openmax] [PATCH 6/8] Add input-buffers/output-buffers properties to the base classes

Rob Clark rob at ti.com
Mon Mar 29 06:09:26 PDT 2010


---
v2: update with changes suggested by Felipe to reduce nesting

 omx/gstomx_base_filter.c |   68 +++++++++++++++++++++++++++++++++++++++
 omx/gstomx_base_sink.c   |   80 ++++++++++++++++++++++++++++++++++++++++++++++
 omx/gstomx_base_src.c    |   80 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+), 0 deletions(-)

diff --git a/omx/gstomx_base_filter.c b/omx/gstomx_base_filter.c
index 2dbf850..4821f3b 100644
--- a/omx/gstomx_base_filter.c
+++ b/omx/gstomx_base_filter.c
@@ -28,6 +28,8 @@
 enum
 {
     ARG_USE_TIMESTAMPS = GSTOMX_NUM_COMMON_PROP,
+    ARG_NUM_INPUT_BUFFERS,
+    ARG_NUM_OUTPUT_BUFFERS,
 };
 
 static void init_interfaces (GType type);
@@ -182,6 +184,40 @@ set_property (GObject *obj,
         case ARG_USE_TIMESTAMPS:
             self->use_timestamps = g_value_get_boolean (value);
             break;
+        case ARG_NUM_INPUT_BUFFERS:
+        case ARG_NUM_OUTPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+                OMX_U32 nBufferCountActual;
+                GOmxPort *port = (prop_id == ARG_NUM_INPUT_BUFFERS) ?
+                        self->in_port : self->out_port;
+
+                if (G_UNLIKELY (!omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    break;
+                }
+
+                nBufferCountActual = g_value_get_uint (value);
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                if (nBufferCountActual < param.nBufferCountMin)
+                {
+                    GST_ERROR_OBJECT (self, "buffer count %lu is less than minimum %lu",
+                            nBufferCountActual, param.nBufferCountMin);
+                    return;
+                }
+
+                param.nBufferCountActual = nBufferCountActual;
+
+                OMX_SetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+            }
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
             break;
@@ -206,6 +242,29 @@ get_property (GObject *obj,
         case ARG_USE_TIMESTAMPS:
             g_value_set_boolean (value, self->use_timestamps);
             break;
+        case ARG_NUM_INPUT_BUFFERS:
+        case ARG_NUM_OUTPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+                GOmxPort *port = (prop_id == ARG_NUM_INPUT_BUFFERS) ?
+                        self->in_port : self->out_port;
+
+                if (G_UNLIKELY (!omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    g_value_set_uint (value, 0);
+                    break;
+                }
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                g_value_set_uint (value, param.nBufferCountActual);
+            }
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
             break;
@@ -241,6 +300,15 @@ type_class_init (gpointer g_class,
                                          g_param_spec_boolean ("use-timestamps", "Use timestamps",
                                                                "Whether or not to use timestamps",
                                                                TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+        g_object_class_install_property (gobject_class, ARG_NUM_INPUT_BUFFERS,
+                                         g_param_spec_uint ("input-buffers", "Input buffers",
+                                                            "The number of OMX input buffers",
+                                                            1, 10, 4, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+        g_object_class_install_property (gobject_class, ARG_NUM_OUTPUT_BUFFERS,
+                                         g_param_spec_uint ("output-buffers", "Output buffers",
+                                                            "The number of OMX output buffers",
+                                                            1, 10, 4, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
     }
 }
 
diff --git a/omx/gstomx_base_sink.c b/omx/gstomx_base_sink.c
index 3cc5f99..66e32d6 100644
--- a/omx/gstomx_base_sink.c
+++ b/omx/gstomx_base_sink.c
@@ -28,6 +28,11 @@
 
 #include <string.h> /* for memcpy */
 
+enum
+{
+    ARG_NUM_INPUT_BUFFERS = GSTOMX_NUM_COMMON_PROP,
+};
+
 static gboolean share_input_buffer;
 
 static inline gboolean omx_init (GstOmxBaseSink *self);
@@ -265,6 +270,55 @@ handle_event (GstBaseSink *gst_base,
 }
 
 static void
+set_property (GObject *obj,
+              guint prop_id,
+              const GValue *value,
+              GParamSpec *pspec)
+{
+    GstOmxBaseSink *self;
+
+    self = GST_OMX_BASE_SINK (obj);
+
+    switch (prop_id)
+    {
+        case ARG_NUM_INPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+                OMX_U32 nBufferCountActual;
+
+                if (G_UNLIKELY (!omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    break;
+                }
+
+                nBufferCountActual = g_value_get_uint (value);
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = self->in_port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                if (nBufferCountActual < param.nBufferCountMin)
+                {
+                    GST_ERROR_OBJECT (self, "buffer count %lu is less than minimum %lu",
+                            nBufferCountActual, param.nBufferCountMin);
+                    return;
+                }
+
+                param.nBufferCountActual = nBufferCountActual;
+
+                OMX_SetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+            }
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
+            break;
+    }
+}
+
+static void
 get_property (GObject *obj,
               guint prop_id,
               GValue *value,
@@ -279,6 +333,26 @@ get_property (GObject *obj,
 
     switch (prop_id)
     {
+        case ARG_NUM_INPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+
+                if (G_UNLIKELY (!omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    g_value_set_uint (value, 0);
+                    break;
+                }
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = self->in_port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                g_value_set_uint (value, param.nBufferCountActual);
+            }
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
             break;
@@ -312,9 +386,15 @@ type_class_init (gpointer g_class,
 
     /* Properties stuff */
     {
+        gobject_class->set_property = set_property;
         gobject_class->get_property = get_property;
 
         gstomx_install_property_helper (gobject_class);
+
+        g_object_class_install_property (gobject_class, ARG_NUM_INPUT_BUFFERS,
+                                         g_param_spec_uint ("input-buffers", "Input buffers",
+                                                            "The number of OMX input buffers",
+                                                            1, 10, 4, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
     }
 }
 
diff --git a/omx/gstomx_base_src.c b/omx/gstomx_base_src.c
index af0bd01..37b29f9 100644
--- a/omx/gstomx_base_src.c
+++ b/omx/gstomx_base_src.c
@@ -24,6 +24,11 @@
 
 #include <string.h> /* for memcpy */
 
+enum
+{
+    ARG_NUM_OUTPUT_BUFFERS = GSTOMX_NUM_COMMON_PROP,
+};
+
 GSTOMX_BOILERPLATE (GstOmxBaseSrc, gst_omx_base_src, GstBaseSrc, GST_TYPE_BASE_SRC);
 
 static void
@@ -326,6 +331,55 @@ handle_event (GstBaseSrc *gst_base,
 }
 
 static void
+set_property (GObject *obj,
+              guint prop_id,
+              const GValue *value,
+              GParamSpec *pspec)
+{
+    GstOmxBaseSrc *self;
+
+    self = GST_OMX_BASE_SRC (obj);
+
+    switch (prop_id)
+    {
+        case ARG_NUM_OUTPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+                OMX_U32 nBufferCountActual;
+
+                if (G_UNLIKELY (omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    break;
+                }
+
+                nBufferCountActual = g_value_get_uint (value);
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = self->out_port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                if (nBufferCountActual < param.nBufferCountMin)
+                {
+                    GST_ERROR_OBJECT (self, "buffer count %lu is less than minimum %lu",
+                            nBufferCountActual, param.nBufferCountMin);
+                    return;
+                }
+
+                param.nBufferCountActual = nBufferCountActual;
+
+                OMX_SetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+            }
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
+            break;
+    }
+}
+
+static void
 get_property (GObject *obj,
               guint prop_id,
               GValue *value,
@@ -340,6 +394,26 @@ get_property (GObject *obj,
 
     switch (prop_id)
     {
+        case ARG_NUM_OUTPUT_BUFFERS:
+            {
+                OMX_PARAM_PORTDEFINITIONTYPE param;
+                OMX_HANDLETYPE omx_handle = self->gomx->omx_handle;
+
+                if (G_UNLIKELY (!omx_handle))
+                {
+                    GST_WARNING_OBJECT (self, "no component");
+                    g_value_set_uint (value, 0);
+                    break;
+                }
+
+                G_OMX_INIT_PARAM (param);
+
+                param.nPortIndex = self->out_port->port_index;
+                OMX_GetParameter (omx_handle, OMX_IndexParamPortDefinition, &param);
+
+                g_value_set_uint (value, param.nBufferCountActual);
+            }
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
             break;
@@ -370,9 +444,15 @@ type_class_init (gpointer g_class,
 
     /* Properties stuff */
     {
+        gobject_class->set_property = set_property;
         gobject_class->get_property = get_property;
 
         gstomx_install_property_helper (gobject_class);
+
+        g_object_class_install_property (gobject_class, ARG_NUM_OUTPUT_BUFFERS,
+                                         g_param_spec_uint ("output-buffers", "Output buffers",
+                                                            "The number of OMX output buffers",
+                                                            1, 10, 4, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
     }
 }
 
-- 
1.6.6





More information about the Gstreamer-openmax mailing list