Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions omx/gstomx_base_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ change_state (GstElement * element, GstStateChange transition)

switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
g_mutex_lock (self->ready_lock);
g_mutex_lock (&self->ready_lock);
if (self->ready) {
/* unlock */
g_omx_port_finish (self->in_port);
Expand All @@ -131,7 +131,7 @@ change_state (GstElement * element, GstStateChange transition)
g_omx_core_unload (core);
self->ready = FALSE;
}
g_mutex_unlock (self->ready_lock);
g_mutex_unlock (&self->ready_lock);
if (core->omx_state != OMX_StateLoaded &&
core->omx_state != OMX_StateInvalid) {
ret = GST_STATE_CHANGE_FAILURE;
Expand Down Expand Up @@ -163,7 +163,7 @@ finalize (GObject * obj)

g_omx_core_free (self->gomx);

g_mutex_free (self->ready_lock);
g_mutex_clear (&self->ready_lock);

G_OBJECT_CLASS (parent_class)->finalize (obj);
}
Expand Down Expand Up @@ -576,7 +576,7 @@ pad_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (self, "state: %d", gomx->omx_state);

if (G_UNLIKELY (gomx->omx_state == OMX_StateLoaded)) {
g_mutex_lock (self->ready_lock);
g_mutex_lock (&self->ready_lock);

GST_INFO_OBJECT (self, "omx: prepare");

Expand All @@ -594,7 +594,7 @@ pad_chain (GstPad * pad, GstBuffer * buf)
gst_pad_start_task (self->srcpad, output_loop, self->srcpad);
}

g_mutex_unlock (self->ready_lock);
g_mutex_unlock (&self->ready_lock);

if (gomx->omx_state != OMX_StateIdle)
goto out_flushing;
Expand Down Expand Up @@ -890,7 +890,7 @@ type_instance_init (GTypeInstance * instance, gpointer g_class)
self->in_port = g_omx_core_new_port (self->gomx, 0);
self->out_port = g_omx_core_new_port (self->gomx, 1);

self->ready_lock = g_mutex_new ();
g_mutex_int (&self->ready_lock);

self->sinkpad =
gst_pad_new_from_template (gst_element_class_get_pad_template
Expand Down
2 changes: 1 addition & 1 deletion omx/gstomx_base_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct GstOmxBaseFilter

gboolean use_timestamps; /** @todo remove; timestamps should always be used */
gboolean ready;
GMutex *ready_lock;
GMutex ready_lock;

GstOmxBaseFilterCb omx_setup;
GstFlowReturn last_pad_push_return;
Expand Down
62 changes: 33 additions & 29 deletions omx/gstomx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static OMX_CALLBACKTYPE callbacks =
{ EventHandler, EmptyBufferDone, FillBufferDone };

/* protect implementations hash_table */
static GMutex *imp_mutex;
static GMutex imp_mutex;
static GHashTable *implementations;
static gboolean initialized;

Expand Down Expand Up @@ -151,7 +151,7 @@ imp_new (const gchar * name)
return NULL;
}

imp->mutex = g_mutex_new ();
g_mutex_init(&imp->mutex);
imp->sym_table.init = dlsym (handle, "OMX_Init");
imp->sym_table.deinit = dlsym (handle, "OMX_Deinit");
imp->sym_table.get_handle = dlsym (handle, "OMX_GetHandle");
Expand All @@ -167,7 +167,7 @@ imp_free (GOmxImp * imp)
if (imp->dl_handle) {
dlclose (imp->dl_handle);
}
g_mutex_free (imp->mutex);
g_mutex_clear(&imp->mutex);
g_free (imp);
}

Expand All @@ -177,19 +177,19 @@ request_imp (const gchar * name, gboolean disable_postproc)
GOmxImp *imp = NULL;
int retry = 1;

g_mutex_lock (imp_mutex);
g_mutex_lock (&imp_mutex);
imp = g_hash_table_lookup (implementations, name);
if (!imp) {
imp = imp_new (name);
if (imp)
g_hash_table_insert (implementations, g_strdup (name), imp);
}
g_mutex_unlock (imp_mutex);
g_mutex_unlock (&imp_mutex);

if (!imp)
return NULL;

g_mutex_lock (imp->mutex);
g_mutex_lock (&imp->mutex);
reinit:
if (imp->client_count == 0) {
OMX_ERRORTYPE (*r_config) (OMX_STRING path);
Expand All @@ -200,7 +200,7 @@ request_imp (const gchar * name, gboolean disable_postproc)
if (r_config)
omx_error = r_config (FILE_OMXR_CFG_NO_IPC);
if ((r_config == NULL) || (omx_error != OMX_ErrorNone)) {
g_mutex_unlock (imp->mutex);
g_mutex_unlock (&imp->mutex);
return NULL;
}
}
Expand All @@ -211,33 +211,33 @@ request_imp (const gchar * name, gboolean disable_postproc)
imp->sym_table.deinit ();
goto reinit;
}
g_mutex_unlock (imp->mutex);
g_mutex_unlock (&imp->mutex);
return NULL;
}
}
imp->client_count++;
g_mutex_unlock (imp->mutex);
g_mutex_unlock (&imp->mutex);

return imp;
}

static inline void
release_imp (GOmxImp * imp)
{
g_mutex_lock (imp->mutex);
g_mutex_lock (&imp->mutex);
imp->client_count--;
if (imp->client_count == 0) {
imp->sym_table.deinit ();
}
g_mutex_unlock (imp->mutex);
g_mutex_unlock (&imp->mutex);
}

void
g_omx_init (void)
{
if (!initialized) {
/* safe as plugin_init is safe */
imp_mutex = g_mutex_new ();
g_mutex_init(&imp_mutex);
implementations = g_hash_table_new_full (g_str_hash,
g_str_equal, g_free, (GDestroyNotify) imp_free);
initialized = TRUE;
Expand All @@ -249,7 +249,7 @@ g_omx_deinit (void)
{
if (initialized) {
g_hash_table_destroy (implementations);
g_mutex_free (imp_mutex);
g_mutex_clear (&imp_mutex);
initialized = FALSE;
}
}
Expand All @@ -268,8 +268,8 @@ g_omx_core_new (void *object)
core->object = object;
core->ports = g_ptr_array_new ();

core->omx_state_condition = g_cond_new ();
core->omx_state_mutex = g_mutex_new ();
g_cond_init(&core->omx_state_condition);
g_mutex_init(&core->omx_state_mutex);

core->done_sem = g_sem_new ();
core->flush_sem = g_sem_new ();
Expand All @@ -289,8 +289,8 @@ g_omx_core_free (GOmxCore * core)
g_sem_free (core->flush_sem);
g_sem_free (core->done_sem);

g_mutex_free (core->omx_state_mutex);
g_cond_free (core->omx_state_condition);
g_mutex_clear (&core->omx_state_mutex);
g_cond_clear (&core->omx_state_condition);

g_ptr_array_free (core->ports, TRUE);

Expand Down Expand Up @@ -501,15 +501,15 @@ g_omx_port_new (GOmxCore * core, guint index)

port->enabled = TRUE;
port->queue = async_queue_new ();
port->mutex = g_mutex_new ();
g_mutex_init (&port->mutex);

return port;
}

void
g_omx_port_free (GOmxPort * port)
{
g_mutex_free (port->mutex);
g_mutex_clear (&port->mutex);
async_queue_free (port->queue);

g_free (port->buffers);
Expand Down Expand Up @@ -726,7 +726,7 @@ g_omx_port_finish (GOmxPort * port)
static inline void
change_state (GOmxCore * core, OMX_STATETYPE state)
{
g_mutex_lock (core->omx_state_mutex);
g_mutex_lock (&core->omx_state_mutex);

GST_DEBUG_OBJECT (core->object, "state=%d", state);
OMX_SendCommand (core->omx_handle, OMX_CommandStateSet, state, NULL);
Expand All @@ -735,13 +735,13 @@ change_state (GOmxCore * core, OMX_STATETYPE state)
static inline void
complete_change_state (GOmxCore * core, OMX_STATETYPE state)
{
g_mutex_lock (core->omx_state_mutex);
g_mutex_lock (&core->omx_state_mutex);

core->omx_state = state;
g_cond_signal (core->omx_state_condition);
g_cond_signal (&core->omx_state_condition);
GST_DEBUG_OBJECT (core->object, "state=%d", state);

g_mutex_unlock (core->omx_state_mutex);
g_mutex_unlock (&core->omx_state_mutex);
}

static inline void
Expand All @@ -755,9 +755,13 @@ wait_for_state (GOmxCore * core, OMX_STATETYPE state)

/* try once */
if (core->omx_state != state) {
gint64 t = g_get_monotonic_time () +
((gint64)tv.tv_sec * G_USEC_PER_SEC + tv.tv_usec -
g_get_real_time ());

signaled =
g_cond_timed_wait (core->omx_state_condition, core->omx_state_mutex,
&tv);
g_cond_wait_until (&core->omx_state_condition, &core->omx_state_mutex,
t);

if (!signaled) {
GST_ERROR_OBJECT (core->object, "timed out switching from '%s' to '%s'",
Expand All @@ -774,7 +778,7 @@ wait_for_state (GOmxCore * core, OMX_STATETYPE state)
}

leave:
g_mutex_unlock (core->omx_state_mutex);
g_mutex_unlock (&core->omx_state_mutex);
}

/*
Expand Down Expand Up @@ -926,9 +930,9 @@ EventHandler (OMX_HANDLETYPE omx_handle,
*/
if (is_err_type_state_change (core->omx_error)) {
/* unlock wait_for_state */
g_mutex_lock (core->omx_state_mutex);
g_cond_signal (core->omx_state_condition);
g_mutex_unlock (core->omx_state_mutex);
g_mutex_lock (&core->omx_state_mutex);
g_cond_signal (&core->omx_state_condition);
g_mutex_unlock (&core->omx_state_mutex);
}

GST_ELEMENT_ERROR (core->object, STREAM, FAILED, (NULL),
Expand Down
8 changes: 4 additions & 4 deletions omx/gstomx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct GOmxImp
guint client_count;
void *dl_handle;
GOmxSymbolTable sym_table;
GMutex *mutex;
GMutex mutex;
};

struct GOmxCore
Expand All @@ -76,8 +76,8 @@ struct GOmxCore
OMX_ERRORTYPE omx_error;

OMX_STATETYPE omx_state;
GCond *omx_state_condition;
GMutex *omx_state_mutex;
GCond omx_state_condition;
GMutex omx_state_mutex;

GPtrArray *ports;

Expand Down Expand Up @@ -107,7 +107,7 @@ struct GOmxPort
guint port_index;
OMX_BUFFERHEADERTYPE **buffers;

GMutex *mutex;
GMutex mutex;
gboolean enabled;
gboolean omx_allocate; /**< Setup with OMX_AllocateBuffer rather than OMX_UseBuffer */
AsyncQueue *queue;
Expand Down