g_mutex_unlock (&comp->messages_lock);
}
+/* NOTE: Call with comp->lock, comp->messages_lock will be used */
+static gboolean
+gst_omx_component_wait_message (GstOMXComponent * comp, GstClockTime timeout)
+{
+ gboolean signalled;
+ gint64 wait_until = -1;
+
+ if (timeout != GST_CLOCK_TIME_NONE) {
+ gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
+
+ if (add == 0)
+ return FALSE;
+
+ wait_until = g_get_monotonic_time () + add;
+ GST_DEBUG_OBJECT (comp->parent, "%s waiting for %" G_GINT64_FORMAT "us",
+ comp->name, add);
+ } else {
+ GST_DEBUG_OBJECT (comp->parent, "%s waiting for signal", comp->name);
+ }
+
+ g_mutex_lock (&comp->messages_lock);
+ g_mutex_unlock (&comp->lock);
+
+ if (!g_queue_is_empty (&comp->messages)) {
+ signalled = TRUE;
+ } else if (timeout == GST_CLOCK_TIME_NONE) {
+ g_cond_wait (&comp->messages_cond, &comp->messages_lock);
+ signalled = TRUE;
+ } else {
+ signalled =
+ g_cond_wait_until (&comp->messages_cond, &comp->messages_lock,
+ wait_until);
+ }
+
+ g_mutex_unlock (&comp->messages_lock);
+ g_mutex_lock (&comp->lock);
+
+ return signalled;
+}
+
static OMX_ERRORTYPE
EventHandler (OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout)
{
OMX_STATETYPE ret;
- gint64 wait_until = -1;
gboolean signalled = TRUE;
g_return_val_if_fail (comp != NULL, OMX_StateInvalid);
goto done;
}
- if (timeout != GST_CLOCK_TIME_NONE) {
- gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
-
- if (add == 0)
- goto done;
-
- wait_until = g_get_monotonic_time () + add;
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for %" G_GINT64_FORMAT "us",
- comp->name, add);
- } else {
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for signal", comp->name);
- }
-
- gst_omx_component_handle_messages (comp);
while (signalled && comp->last_error == OMX_ErrorNone
&& comp->pending_state != OMX_StateInvalid) {
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
- if (!g_queue_is_empty (&comp->messages)) {
- signalled = TRUE;
- } else if (timeout == GST_CLOCK_TIME_NONE) {
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- signalled = TRUE;
- } else {
- signalled =
- g_cond_wait_until (&comp->messages_cond, &comp->messages_lock,
- wait_until);
- }
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
+
+ signalled = gst_omx_component_wait_message (comp, timeout);
if (signalled)
gst_omx_component_handle_messages (comp);
};
(err = comp->last_error) == OMX_ErrorNone && !port->flushing) {
GST_DEBUG_OBJECT (comp->parent,
"Waiting for %s output ports to reconfigure", comp->name);
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
- if (g_queue_is_empty (&comp->messages))
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
+ gst_omx_component_wait_message (comp, GST_CLOCK_TIME_NONE);
gst_omx_component_handle_messages (comp);
}
goto retry;
if (g_queue_is_empty (&port->pending_buffers)) {
GST_DEBUG_OBJECT (comp->parent, "Queue of %s port %u is empty",
comp->name, port->index);
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
- if (g_queue_is_empty (&comp->messages))
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
+ gst_omx_component_wait_message (comp, GST_CLOCK_TIME_NONE);
gst_omx_component_handle_messages (comp);
/* And now check everything again and maybe get a buffer */
port->flushing = flush;
if (flush) {
- gint64 wait_until = -1;
gboolean signalled;
OMX_ERRORTYPE last_error;
goto done;
}
- if (timeout != GST_CLOCK_TIME_NONE) {
- gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
-
- if (add == 0) {
- if (!port->flushed || (port->buffers
- && port->buffers->len >
- g_queue_get_length (&port->pending_buffers)))
- err = OMX_ErrorTimeout;
- goto done;
- }
-
- wait_until = g_get_monotonic_time () + add;
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for %" G_GINT64_FORMAT "us",
- comp->name, add);
- } else {
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for signal", comp->name);
+ if (timeout == 0) {
+ if (!port->flushed || (port->buffers
+ && port->buffers->len >
+ g_queue_get_length (&port->pending_buffers)))
+ err = OMX_ErrorTimeout;
+ goto done;
}
/* Retry until timeout or until an error happend or
while (signalled && last_error == OMX_ErrorNone && !port->flushed
&& port->buffers
&& port->buffers->len > g_queue_get_length (&port->pending_buffers)) {
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
-
- if (!g_queue_is_empty (&comp->messages)) {
- signalled = TRUE;
- } else if (timeout == GST_CLOCK_TIME_NONE) {
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- signalled = TRUE;
- } else {
- signalled =
- g_cond_wait_until (&comp->messages_cond, &comp->messages_lock,
- wait_until);
- }
-
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
-
+ signalled = gst_omx_component_wait_message (comp, timeout);
if (signalled)
gst_omx_component_handle_messages (comp);
GstOMXComponent *comp;
OMX_ERRORTYPE err = OMX_ErrorNone;
OMX_ERRORTYPE last_error;
- gint64 wait_until = -1;
gboolean signalled;
comp = port->comp;
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to release all "
"buffers", comp->name, port->index);
- if (timeout != GST_CLOCK_TIME_NONE) {
- gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
-
- if (add == 0) {
- if (port->buffers
- && port->buffers->len > g_queue_get_length (&port->pending_buffers))
- err = OMX_ErrorTimeout;
- goto done;
- }
-
- wait_until = g_get_monotonic_time () + add;
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for %" G_GINT64_FORMAT "us",
- comp->name, add);
- } else {
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for signal", comp->name);
+ if (timeout == 0) {
+ if (!port->flushed || (port->buffers
+ && port->buffers->len >
+ g_queue_get_length (&port->pending_buffers)))
+ err = OMX_ErrorTimeout;
+ goto done;
}
/* Wait until all buffers are released by the port */
while (signalled && last_error == OMX_ErrorNone && (port->buffers
&& port->buffers->len >
g_queue_get_length (&port->pending_buffers))) {
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
- if (!g_queue_is_empty (&comp->messages)) {
- signalled = TRUE;
- } else if (timeout != GST_CLOCK_TIME_NONE) {
- signalled =
- g_cond_wait_until (&comp->messages_cond, &comp->messages_lock,
- wait_until);
- } else {
- signalled = TRUE;
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- }
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
+ signalled = gst_omx_component_wait_message (comp, timeout);
if (signalled)
gst_omx_component_handle_messages (comp);
last_error = comp->last_error;
{
GstOMXComponent *comp;
OMX_ERRORTYPE err = OMX_ErrorNone;
- gint64 wait_until = -1;
gboolean signalled;
OMX_ERRORTYPE last_error;
gboolean enabled;
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to be %s",
comp->name, port->index, (enabled ? "enabled" : "disabled"));
- if (timeout != GST_CLOCK_TIME_NONE) {
- gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
-
- if (add == 0) {
- if (port->enabled_pending || port->disabled_pending)
- err = OMX_ErrorTimeout;
- goto done;
- }
-
- wait_until = g_get_monotonic_time () + add;
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for %" G_GINT64_FORMAT "us",
- comp->name, add);
- } else {
- GST_DEBUG_OBJECT (comp->parent, "%s waiting for signal", comp->name);
+ if (timeout == 0) {
+ if (port->enabled_pending || port->disabled_pending)
+ err = OMX_ErrorTimeout;
+ goto done;
}
/* And now wait until the enable/disable command is finished */
while (signalled && last_error == OMX_ErrorNone &&
(! !port->port_def.bEnabled != ! !enabled || port->enabled_pending
|| port->disabled_pending)) {
- g_mutex_lock (&comp->messages_lock);
- g_mutex_unlock (&comp->lock);
- if (!g_queue_is_empty (&comp->messages)) {
- signalled = TRUE;
- } else if (timeout != GST_CLOCK_TIME_NONE) {
- signalled =
- g_cond_wait_until (&comp->messages_cond, &comp->messages_lock,
- wait_until);
- } else {
- signalled = TRUE;
- g_cond_wait (&comp->messages_cond, &comp->messages_lock);
- }
- g_mutex_unlock (&comp->messages_lock);
- g_mutex_lock (&comp->lock);
+ signalled = gst_omx_component_wait_message (comp, timeout);
if (signalled)
gst_omx_component_handle_messages (comp);
last_error = comp->last_error;