mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
omx: consolidate message waiting code
Add a wait_message helper function and remove all those duplicated code. https://bugzilla.gnome.org/show_bug.cgi?id=725493
This commit is contained in:
parent
6b28cf0378
commit
0700d6875f
1 changed files with 63 additions and 134 deletions
197
omx/gstomx.c
197
omx/gstomx.c
|
@ -407,6 +407,46 @@ gst_omx_component_send_message (GstOMXComponent * comp, GstOMXMessage * msg)
|
||||||
g_mutex_unlock (&comp->messages_lock);
|
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
|
static OMX_ERRORTYPE
|
||||||
EventHandler (OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
|
EventHandler (OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
|
||||||
OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
|
OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
|
||||||
|
@ -799,7 +839,6 @@ OMX_STATETYPE
|
||||||
gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout)
|
gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout)
|
||||||
{
|
{
|
||||||
OMX_STATETYPE ret;
|
OMX_STATETYPE ret;
|
||||||
gint64 wait_until = -1;
|
|
||||||
gboolean signalled = TRUE;
|
gboolean signalled = TRUE;
|
||||||
|
|
||||||
g_return_val_if_fail (comp != NULL, OMX_StateInvalid);
|
g_return_val_if_fail (comp != NULL, OMX_StateInvalid);
|
||||||
|
@ -822,36 +861,10 @@ gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout)
|
||||||
goto done;
|
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
|
while (signalled && comp->last_error == OMX_ErrorNone
|
||||||
&& comp->pending_state != OMX_StateInvalid) {
|
&& comp->pending_state != OMX_StateInvalid) {
|
||||||
g_mutex_lock (&comp->messages_lock);
|
|
||||||
g_mutex_unlock (&comp->lock);
|
signalled = gst_omx_component_wait_message (comp, timeout);
|
||||||
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);
|
|
||||||
if (signalled)
|
if (signalled)
|
||||||
gst_omx_component_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
};
|
};
|
||||||
|
@ -1248,12 +1261,7 @@ retry:
|
||||||
(err = comp->last_error) == OMX_ErrorNone && !port->flushing) {
|
(err = comp->last_error) == OMX_ErrorNone && !port->flushing) {
|
||||||
GST_DEBUG_OBJECT (comp->parent,
|
GST_DEBUG_OBJECT (comp->parent,
|
||||||
"Waiting for %s output ports to reconfigure", comp->name);
|
"Waiting for %s output ports to reconfigure", comp->name);
|
||||||
g_mutex_lock (&comp->messages_lock);
|
gst_omx_component_wait_message (comp, GST_CLOCK_TIME_NONE);
|
||||||
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_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
}
|
}
|
||||||
goto retry;
|
goto retry;
|
||||||
|
@ -1316,12 +1324,7 @@ retry:
|
||||||
if (g_queue_is_empty (&port->pending_buffers)) {
|
if (g_queue_is_empty (&port->pending_buffers)) {
|
||||||
GST_DEBUG_OBJECT (comp->parent, "Queue of %s port %u is empty",
|
GST_DEBUG_OBJECT (comp->parent, "Queue of %s port %u is empty",
|
||||||
comp->name, port->index);
|
comp->name, port->index);
|
||||||
g_mutex_lock (&comp->messages_lock);
|
gst_omx_component_wait_message (comp, GST_CLOCK_TIME_NONE);
|
||||||
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_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
|
|
||||||
/* And now check everything again and maybe get a buffer */
|
/* And now check everything again and maybe get a buffer */
|
||||||
|
@ -1456,7 +1459,6 @@ gst_omx_port_set_flushing (GstOMXPort * port, GstClockTime timeout,
|
||||||
|
|
||||||
port->flushing = flush;
|
port->flushing = flush;
|
||||||
if (flush) {
|
if (flush) {
|
||||||
gint64 wait_until = -1;
|
|
||||||
gboolean signalled;
|
gboolean signalled;
|
||||||
OMX_ERRORTYPE last_error;
|
OMX_ERRORTYPE last_error;
|
||||||
|
|
||||||
|
@ -1487,22 +1489,12 @@ gst_omx_port_set_flushing (GstOMXPort * port, GstClockTime timeout,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout != GST_CLOCK_TIME_NONE) {
|
if (timeout == 0) {
|
||||||
gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
|
if (!port->flushed || (port->buffers
|
||||||
|
&& port->buffers->len >
|
||||||
if (add == 0) {
|
g_queue_get_length (&port->pending_buffers)))
|
||||||
if (!port->flushed || (port->buffers
|
err = OMX_ErrorTimeout;
|
||||||
&& port->buffers->len >
|
goto done;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retry until timeout or until an error happend or
|
/* Retry until timeout or until an error happend or
|
||||||
|
@ -1514,23 +1506,7 @@ gst_omx_port_set_flushing (GstOMXPort * port, GstClockTime timeout,
|
||||||
while (signalled && last_error == OMX_ErrorNone && !port->flushed
|
while (signalled && last_error == OMX_ErrorNone && !port->flushed
|
||||||
&& port->buffers
|
&& port->buffers
|
||||||
&& port->buffers->len > g_queue_get_length (&port->pending_buffers)) {
|
&& port->buffers->len > g_queue_get_length (&port->pending_buffers)) {
|
||||||
g_mutex_lock (&comp->messages_lock);
|
signalled = gst_omx_component_wait_message (comp, timeout);
|
||||||
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);
|
|
||||||
|
|
||||||
if (signalled)
|
if (signalled)
|
||||||
gst_omx_component_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
|
|
||||||
|
@ -1927,7 +1903,6 @@ gst_omx_port_wait_buffers_released_unlocked (GstOMXPort * port,
|
||||||
GstOMXComponent *comp;
|
GstOMXComponent *comp;
|
||||||
OMX_ERRORTYPE err = OMX_ErrorNone;
|
OMX_ERRORTYPE err = OMX_ErrorNone;
|
||||||
OMX_ERRORTYPE last_error;
|
OMX_ERRORTYPE last_error;
|
||||||
gint64 wait_until = -1;
|
|
||||||
gboolean signalled;
|
gboolean signalled;
|
||||||
|
|
||||||
comp = port->comp;
|
comp = port->comp;
|
||||||
|
@ -1943,21 +1918,12 @@ gst_omx_port_wait_buffers_released_unlocked (GstOMXPort * port,
|
||||||
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to release all "
|
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to release all "
|
||||||
"buffers", comp->name, port->index);
|
"buffers", comp->name, port->index);
|
||||||
|
|
||||||
if (timeout != GST_CLOCK_TIME_NONE) {
|
if (timeout == 0) {
|
||||||
gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
|
if (!port->flushed || (port->buffers
|
||||||
|
&& port->buffers->len >
|
||||||
if (add == 0) {
|
g_queue_get_length (&port->pending_buffers)))
|
||||||
if (port->buffers
|
err = OMX_ErrorTimeout;
|
||||||
&& port->buffers->len > g_queue_get_length (&port->pending_buffers))
|
goto done;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait until all buffers are released by the port */
|
/* Wait until all buffers are released by the port */
|
||||||
|
@ -1967,20 +1933,7 @@ gst_omx_port_wait_buffers_released_unlocked (GstOMXPort * port,
|
||||||
while (signalled && last_error == OMX_ErrorNone && (port->buffers
|
while (signalled && last_error == OMX_ErrorNone && (port->buffers
|
||||||
&& port->buffers->len >
|
&& port->buffers->len >
|
||||||
g_queue_get_length (&port->pending_buffers))) {
|
g_queue_get_length (&port->pending_buffers))) {
|
||||||
g_mutex_lock (&comp->messages_lock);
|
signalled = gst_omx_component_wait_message (comp, timeout);
|
||||||
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);
|
|
||||||
if (signalled)
|
if (signalled)
|
||||||
gst_omx_component_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
last_error = comp->last_error;
|
last_error = comp->last_error;
|
||||||
|
@ -2130,7 +2083,6 @@ gst_omx_port_wait_enabled_unlocked (GstOMXPort * port, GstClockTime timeout)
|
||||||
{
|
{
|
||||||
GstOMXComponent *comp;
|
GstOMXComponent *comp;
|
||||||
OMX_ERRORTYPE err = OMX_ErrorNone;
|
OMX_ERRORTYPE err = OMX_ErrorNone;
|
||||||
gint64 wait_until = -1;
|
|
||||||
gboolean signalled;
|
gboolean signalled;
|
||||||
OMX_ERRORTYPE last_error;
|
OMX_ERRORTYPE last_error;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
|
@ -2158,20 +2110,10 @@ gst_omx_port_wait_enabled_unlocked (GstOMXPort * port, GstClockTime timeout)
|
||||||
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to be %s",
|
GST_INFO_OBJECT (comp->parent, "Waiting for %s port %u to be %s",
|
||||||
comp->name, port->index, (enabled ? "enabled" : "disabled"));
|
comp->name, port->index, (enabled ? "enabled" : "disabled"));
|
||||||
|
|
||||||
if (timeout != GST_CLOCK_TIME_NONE) {
|
if (timeout == 0) {
|
||||||
gint64 add = timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
|
if (port->enabled_pending || port->disabled_pending)
|
||||||
|
err = OMX_ErrorTimeout;
|
||||||
if (add == 0) {
|
goto done;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And now wait until the enable/disable command is finished */
|
/* And now wait until the enable/disable command is finished */
|
||||||
|
@ -2182,20 +2124,7 @@ gst_omx_port_wait_enabled_unlocked (GstOMXPort * port, GstClockTime timeout)
|
||||||
while (signalled && last_error == OMX_ErrorNone &&
|
while (signalled && last_error == OMX_ErrorNone &&
|
||||||
(! !port->port_def.bEnabled != ! !enabled || port->enabled_pending
|
(! !port->port_def.bEnabled != ! !enabled || port->enabled_pending
|
||||||
|| port->disabled_pending)) {
|
|| port->disabled_pending)) {
|
||||||
g_mutex_lock (&comp->messages_lock);
|
signalled = gst_omx_component_wait_message (comp, timeout);
|
||||||
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);
|
|
||||||
if (signalled)
|
if (signalled)
|
||||||
gst_omx_component_handle_messages (comp);
|
gst_omx_component_handle_messages (comp);
|
||||||
last_error = comp->last_error;
|
last_error = comp->last_error;
|
||||||
|
|
Loading…
Reference in a new issue