gint i = 0;
gint num = 0;
GList *buffers = NULL;
- tbm_surface_h buffer[MAX_INPUT_BUFFER];
+ tbm_surface_h *surfaces = NULL;
GstOMXComponent *comp;
OMX_ERRORTYPE err = OMX_ErrorNone;
OMX_CONFIG_RECTTYPE rect;
rect.nHeight = port->port_def.format.video.nFrameHeight;
}
- g_mutex_lock (&port->comp->lock);
+ g_mutex_lock (&comp->lock);
/* deallocate previous allocated buffers... */
if (port->buffers)
gst_omx_port_deallocate_buffers (port);
if (port->use_buffer) {
+ surfaces = g_new0(tbm_surface_h, port->port_def.nBufferCountActual);
+ if (!surfaces) {
+ GST_ERROR_OBJECT (comp->parent, "tbm surface array failed");
+ goto error;
+ }
+
for (i = 0; i < port->port_def.nBufferCountActual; i++) {
- buffer[i] = tbm_surface_internal_create_with_flags (rect.nWidth, rect.nHeight, TBM_FORMAT_NV12, TBM_BO_WC);
- if (!buffer[i]) {
- g_mutex_unlock (&port->comp->lock);
+ surfaces[i] = tbm_surface_internal_create_with_flags (rect.nWidth, rect.nHeight, TBM_FORMAT_NV12, TBM_BO_WC);
+ if (!surfaces[i]) {
+ GST_ERROR_OBJECT (comp->parent, "tbm surface create failed [i:%d]", i);
goto error;
}
- buffers = g_list_append (buffers, (gpointer) buffer[i]);
+ buffers = g_list_append (buffers, (gpointer) surfaces[i]);
GST_INFO_OBJECT (comp->parent,
"Allocating %d buffer surface : %p for %s port %u",
- i, buffer[i], comp->name, (guint) port->index);
+ i, surfaces[i], comp->name, (guint) port->index);
}
}
num = port->use_buffer ? g_list_length ((GList *) buffers) : -1;
err = gst_omx_port_allocate_buffers_unlocked (port, buffers, NULL, num);
+ g_free(surfaces);
g_list_free (buffers);
- g_mutex_unlock (&port->comp->lock);
+ g_mutex_unlock (&comp->lock);
return err;
error:
- for (i = 0; i < port->port_def.nBufferCountActual; i++) {
- if (buffer[i]) {
- tbm_surface_internal_destroy (buffer[i]);
- buffer[i] = NULL;
+ if (surfaces) {
+ for (i = 0; i < port->port_def.nBufferCountActual; i++) {
+ if (surfaces[i])
+ tbm_surface_internal_destroy (surfaces[i]);
+ else
+ break;
}
+ g_free(surfaces);
}
+
g_list_free (buffers);
+ g_mutex_unlock (&comp->lock);
+
return OMX_ErrorInsufficientResources;
}
gint i = 0;
gint num = 0;
GList *buffers = NULL;
- tbm_surface_h buffer[MAX_INPUT_BUFFER];
+ tbm_surface_h *surfaces = NULL;
+ GstOMXComponent *comp;
g_return_val_if_fail (port != NULL, OMX_ErrorUndefined);
- g_mutex_lock (&port->comp->lock);
+ comp = port->comp;
+
+ g_mutex_lock (&comp->lock);
/* deallocate previous allocated buffers... */
if (port->buffers)
gst_omx_port_deallocate_buffers (port);
if (port->use_buffer) {
+ surfaces = g_new0(tbm_surface_h, port->port_def.nBufferCountActual);
+ if (!surfaces) {
+ GST_ERROR_OBJECT (comp->parent, "tbm surface array failed");
+ goto error;
+ }
+
for (i = 0; i < port->port_def.nBufferCountActual; i++) {
/* Since the input buffer is queued via OMX_EmptyThisBuffer(),
* a minimum amount of memory is sufficient.
*/
- buffer[i] = tbm_surface_internal_create_with_flags (128, 128, TBM_FORMAT_NV12, TBM_BO_WC);
-
- if (!buffer[i]) {
- g_mutex_unlock (&port->comp->lock);
+ surfaces[i] = tbm_surface_internal_create_with_flags (128, 128, TBM_FORMAT_NV12, TBM_BO_WC);
+ if (!surfaces[i]) {
+ GST_ERROR_OBJECT (comp->parent, "tbm surface create failed [i:%d]", i);
goto error;
}
- buffers = g_list_append (buffers, (gpointer) buffer[i]);
+ buffers = g_list_append (buffers, (gpointer) surfaces[i]);
}
}
num = port->use_buffer ? g_list_length ((GList *) buffers) : -1;
err = gst_omx_port_allocate_buffers_unlocked (port, buffers, NULL, num);
+ g_free(surfaces);
g_list_free (buffers);
- g_mutex_unlock (&port->comp->lock);
+ g_mutex_unlock (&comp->lock);
return err;
error:
- for (i = 0; i < port->port_def.nBufferCountActual; i++) {
- if (buffer[i]) {
- tbm_surface_internal_destroy (buffer[i]);
- buffer[i] = NULL;
+ if (surfaces) {
+ for (i = 0; i < port->port_def.nBufferCountActual; i++) {
+ if (surfaces[i])
+ tbm_surface_internal_destroy (surfaces[i]);
+ else
+ break;
}
+ g_free(surfaces);
}
+
g_list_free (buffers);
+ g_mutex_unlock (&comp->lock);
+
return OMX_ErrorInsufficientResources;
}
#endif