From: Sebastian Dröge Date: Thu, 28 Feb 2013 10:19:07 +0000 (+0100) Subject: omx: Add API for allocating a specific number of buffers and using EGLImages or buffe... X-Git-Tag: 1.19.3~501^2~667 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a906da40922de0768fef8d1035bda3eaabcddae;p=platform%2Fupstream%2Fgstreamer.git omx: Add API for allocating a specific number of buffers and using EGLImages or buffers allocated elsewhere --- diff --git a/omx/gstomx.c b/omx/gstomx.c index 9cd6454..79c7c8f 100644 --- a/omx/gstomx.c +++ b/omx/gstomx.c @@ -1560,11 +1560,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); @@ -1586,12 +1588,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, @@ -1605,7 +1612,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); @@ -1613,6 +1619,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; @@ -1622,9 +1629,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, @@ -1640,6 +1657,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); @@ -1663,14 +1682,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 8b1badf..718a4c5 100644 --- a/omx/gstomx.h +++ b/omx/gstomx.h @@ -297,7 +297,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 db6d1f8..6b087cc 100644 --- a/omx/gstomxaudioenc.c +++ b/omx/gstomxaudioenc.c @@ -354,7 +354,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; @@ -731,7 +731,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) @@ -743,9 +743,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, @@ -892,7 +892,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 302bb41..332d0b3 100644 --- a/omx/gstomxvideodec.c +++ b/omx/gstomxvideodec.c @@ -650,7 +650,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; @@ -1197,7 +1197,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) @@ -1209,9 +1209,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, @@ -1379,7 +1379,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 21afda5..b370743 100644 --- a/omx/gstomxvideoenc.c +++ b/omx/gstomxvideoenc.c @@ -806,7 +806,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; @@ -1204,7 +1204,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) @@ -1216,9 +1216,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, @@ -1534,7 +1534,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;