summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2013-02-28 11:19:07 +0100
committerJosep Torra <n770galaxy@gmail.com>2013-03-01 11:58:40 +0100
commit52f364a1f71b57a25b2d7421e7c361452e1b8c53 (patch)
tree50d5edbbad1d6b40d04a9236b67e430c26aaf2ad
parentde5e69aedc2394e05fa07bbbd56889d1748897fa (diff)
omx: Add API for allocating a specific number of buffers and using EGLImages or buffers allocated elsewhere
Conflicts: omx/gstomx.c
-rw-r--r--omx/gstomx.c73
-rw-r--r--omx/gstomx.h4
-rw-r--r--omx/gstomxaudioenc.c10
-rw-r--r--omx/gstomxvideodec.c10
-rw-r--r--omx/gstomxvideoenc.c10
5 files changed, 81 insertions, 26 deletions
diff --git a/omx/gstomx.c b/omx/gstomx.c
index 0e521ae..87f0a32 100644
--- a/omx/gstomx.c
+++ b/omx/gstomx.c
@@ -1568,11 +1568,13 @@ gst_omx_port_is_flushing (GstOMXPort * port)
/* NOTE: Must be called while holding comp->lock, uses comp->messages_lock */
static OMX_ERRORTYPE
-gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
+gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port,
+ const GList * buffers, const GList * images, guint n)
{
GstOMXComponent *comp;
OMX_ERRORTYPE err = OMX_ErrorNone;
- gint i, n;
+ gint i;
+ const GList *l;
g_assert (!port->buffers || port->buffers->len == 0);
@@ -1594,12 +1596,17 @@ gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
gst_omx_component_get_parameter (comp, OMX_IndexParamPortDefinition,
&port->port_def);
+ g_return_val_if_fail (n != -1
+ && n < port->port_def.nBufferCountMin, OMX_ErrorBadParameter);
+ if (n == -1)
+ n = port->port_def.nBufferCountMin;
+
/* If the configured, actual number of buffers is less than
* the minimal number of buffers required, use the minimal
* number of buffers
*/
- if (port->port_def.nBufferCountActual < port->port_def.nBufferCountMin) {
- port->port_def.nBufferCountActual = port->port_def.nBufferCountMin;
+ if (port->port_def.nBufferCountActual < n) {
+ port->port_def.nBufferCountActual = n;
err = gst_omx_component_set_parameter (comp, OMX_IndexParamPortDefinition,
&port->port_def);
gst_omx_component_get_parameter (comp, OMX_IndexParamPortDefinition,
@@ -1613,7 +1620,6 @@ gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
goto error;
}
- n = port->port_def.nBufferCountActual;
GST_DEBUG_OBJECT (comp->parent,
"Allocating %d buffers of size %u for port %u", n,
port->port_def.nBufferSize, port->index);
@@ -1621,6 +1627,7 @@ gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
if (!port->buffers)
port->buffers = g_ptr_array_sized_new (n);
+ l = (buffers ? buffers : images);
for (i = 0; i < n; i++) {
GstOMXBuffer *buf;
@@ -1630,9 +1637,19 @@ gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
buf->settings_cookie = port->settings_cookie;
g_ptr_array_add (port->buffers, buf);
- err =
- OMX_AllocateBuffer (comp->handle, &buf->omx_buf, port->index, buf,
- port->port_def.nBufferSize);
+ if (buffers) {
+ err =
+ OMX_UseBuffer (comp->handle, &buf->omx_buf, port->index, buf,
+ port->port_def.nBufferSize, l->data);
+ } else if (images) {
+ err =
+ OMX_UseEGLImage (comp->handle, &buf->omx_buf, port->index, buf,
+ l->data);
+ } else {
+ err =
+ OMX_AllocateBuffer (comp->handle, &buf->omx_buf, port->index, buf,
+ port->port_def.nBufferSize);
+ }
if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (comp->parent,
@@ -1648,6 +1665,8 @@ gst_omx_port_allocate_buffers_unlocked (GstOMXPort * port)
/* In the beginning all buffers are not owned by the component */
g_queue_push_tail (&port->pending_buffers, buf);
+ if (buffers || images)
+ l = l->next;
}
gst_omx_component_handle_messages (comp);
@@ -1671,14 +1690,48 @@ error:
/* NOTE: Uses comp->lock and comp->messages_lock */
OMX_ERRORTYPE
-gst_omx_port_allocate_buffers (GstOMXPort * port)
+gst_omx_port_allocate_buffers (GstOMXPort * port, guint n)
+{
+ OMX_ERRORTYPE err;
+
+ g_return_val_if_fail (port != NULL, OMX_ErrorUndefined);
+
+ g_mutex_lock (port->comp->lock);
+ err = gst_omx_port_allocate_buffers_unlocked (port, NULL, NULL, n);
+ g_mutex_unlock (port->comp->lock);
+
+ return err;
+}
+
+/* NOTE: Uses comp->lock and comp->messages_lock */
+OMX_ERRORTYPE
+gst_omx_port_use_buffers (GstOMXPort * port, const GList * buffers)
+{
+ OMX_ERRORTYPE err;
+ guint n;
+
+ g_return_val_if_fail (port != NULL, OMX_ErrorUndefined);
+
+ g_mutex_lock (port->comp->lock);
+ n = g_list_length ((GList *) buffers);
+ err = gst_omx_port_allocate_buffers_unlocked (port, buffers, NULL, n);
+ g_mutex_unlock (port->comp->lock);
+
+ return err;
+}
+
+/* NOTE: Uses comp->lock and comp->messages_lock */
+OMX_ERRORTYPE
+gst_omx_port_use_eglimages (GstOMXPort * port, const GList * images)
{
OMX_ERRORTYPE err;
+ guint n;
g_return_val_if_fail (port != NULL, OMX_ErrorUndefined);
g_mutex_lock (port->comp->lock);
- err = gst_omx_port_allocate_buffers_unlocked (port);
+ n = g_list_length ((GList *) images);
+ err = gst_omx_port_allocate_buffers_unlocked (port, NULL, images, n);
g_mutex_unlock (port->comp->lock);
return err;
diff --git a/omx/gstomx.h b/omx/gstomx.h
index 7bc8915..1914e16 100644
--- a/omx/gstomx.h
+++ b/omx/gstomx.h
@@ -296,7 +296,9 @@ OMX_ERRORTYPE gst_omx_port_release_buffer (GstOMXPort *port, GstOMXBuffer *b
OMX_ERRORTYPE gst_omx_port_set_flushing (GstOMXPort *port, gboolean flush);
gboolean gst_omx_port_is_flushing (GstOMXPort *port);
-OMX_ERRORTYPE gst_omx_port_allocate_buffers (GstOMXPort *port);
+OMX_ERRORTYPE gst_omx_port_allocate_buffers (GstOMXPort *port, guint n);
+OMX_ERRORTYPE gst_omx_port_use_buffers (GstOMXPort *port, const GList *buffers);
+OMX_ERRORTYPE gst_omx_port_use_eglimages (GstOMXPort *port, const GList *images);
OMX_ERRORTYPE gst_omx_port_deallocate_buffers (GstOMXPort *port);
OMX_ERRORTYPE gst_omx_port_wait_buffers_released (GstOMXPort * port, GstClockTime timeout);
diff --git a/omx/gstomxaudioenc.c b/omx/gstomxaudioenc.c
index c7d7018..ce07e01 100644
--- a/omx/gstomxaudioenc.c
+++ b/omx/gstomxaudioenc.c
@@ -509,7 +509,7 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
if (err != OMX_ErrorNone)
goto reconfigure_error;
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone)
goto reconfigure_error;
@@ -878,7 +878,7 @@ gst_omx_audio_enc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
if (needs_disable) {
if (gst_omx_port_set_enabled (self->enc_in_port, TRUE) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_in_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_port_wait_enabled (self->enc_in_port,
5 * GST_SECOND) != OMX_ErrorNone)
@@ -890,9 +890,9 @@ gst_omx_audio_enc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
return FALSE;
/* Need to allocate buffers to reach Idle state */
- if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_in_port, -1) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->enc_out_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_out_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_component_get_state (self->enc,
@@ -1039,7 +1039,7 @@ gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
goto reconfigure_error;
}
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone) {
GST_AUDIO_ENCODER_STREAM_LOCK (self);
goto reconfigure_error;
diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c
index d389e82..b2d17d5 100644
--- a/omx/gstomxvideodec.c
+++ b/omx/gstomxvideodec.c
@@ -794,7 +794,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
if (err != OMX_ErrorNone)
goto reconfigure_error;
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone)
goto reconfigure_error;
@@ -1349,7 +1349,7 @@ gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
if (needs_disable) {
if (gst_omx_port_set_enabled (self->dec_in_port, TRUE) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->dec_in_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_port_wait_enabled (self->dec_in_port,
5 * GST_SECOND) != OMX_ErrorNone)
@@ -1361,9 +1361,9 @@ gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
return FALSE;
/* Need to allocate buffers to reach Idle state */
- if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->dec_in_port, -1) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->dec_out_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->dec_out_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_component_get_state (self->dec,
@@ -1531,7 +1531,7 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
goto reconfigure_error;
}
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone) {
GST_VIDEO_DECODER_STREAM_LOCK (self);
goto reconfigure_error;
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 441ca3f..a10cfef 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -933,7 +933,7 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
if (err != OMX_ErrorNone)
goto reconfigure_error;
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone)
goto reconfigure_error;
@@ -1331,7 +1331,7 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
if (needs_disable) {
if (gst_omx_port_set_enabled (self->enc_in_port, TRUE) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_in_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_port_wait_enabled (self->enc_in_port,
5 * GST_SECOND) != OMX_ErrorNone)
@@ -1343,9 +1343,9 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
return FALSE;
/* Need to allocate buffers to reach Idle state */
- if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_in_port, -1) != OMX_ErrorNone)
return FALSE;
- if (gst_omx_port_allocate_buffers (self->enc_out_port) != OMX_ErrorNone)
+ if (gst_omx_port_allocate_buffers (self->enc_out_port, -1) != OMX_ErrorNone)
return FALSE;
if (gst_omx_component_get_state (self->enc,
@@ -1680,7 +1680,7 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
goto reconfigure_error;
}
- err = gst_omx_port_allocate_buffers (port);
+ err = gst_omx_port_allocate_buffers (port, -1);
if (err != OMX_ErrorNone) {
GST_VIDEO_ENCODER_STREAM_LOCK (self);
goto reconfigure_error;