BRCMIMAGE_STATUS_T brcmimage_create(BRCMIMAGE_TYPE_T type, unsigned int encoding, BRCMIMAGE_T **ctx) { BRCMIMAGE_STATUS_T status = BRCMIMAGE_SUCCESS; BRCMIMAGE_T **comp; if (type == BRCMIMAGE_TYPE_ENCODER) comp = &brcmimage_encoder[getEncoderIndexFromType(encoding)]; else comp = &brcmimage_decoder[getEncoderIndexFromType(encoding)]; vcos_once(&once, brcmimage_init_once); LOCK(); if (!*comp) { int init1, init2, init3; *comp = (BRCMIMAGE_T*)calloc(sizeof(BRCMIMAGE_T), 1); if (!*comp) { UNLOCK(); return BRCMIMAGE_ERROR_NOMEM; } (*comp)->type = type; (*comp)->encoding = encoding; init1 = vcos_mutex_create(&(*comp)->lock, "brcmimage lock") != VCOS_SUCCESS; init2 = vcos_mutex_create(&(*comp)->process_lock, "brcmimage process lock") != VCOS_SUCCESS; init3 = vcos_semaphore_create(&(*comp)->sema, "brcmimage sema", 0) != VCOS_SUCCESS; if (init1 | init2 | init3) { if (init1) vcos_mutex_delete(&(*comp)->lock); if (init2) vcos_mutex_delete(&(*comp)->process_lock); if (init3) vcos_semaphore_delete(&(*comp)->sema); free(comp); UNLOCK(); return BRCMIMAGE_ERROR_NOMEM; } } (*comp)->ref_count++; UNLOCK(); LOCK_COMP(*comp); if (!(*comp)->init) { if (type == BRCMIMAGE_TYPE_ENCODER) status = brcmimage_init_encoder(*comp); else status = brcmimage_init_decoder(*comp); (*comp)->init = status == BRCMIMAGE_SUCCESS; } UNLOCK_COMP(*comp); if (status != BRCMIMAGE_SUCCESS) brcmimage_release(*comp); *ctx = *comp; return status; }
static void brcmimage_destroy(BRCMIMAGE_T *ctx) { if (ctx->mmal) mmal_wrapper_destroy(ctx->mmal); vcos_mutex_delete(&ctx->lock); vcos_mutex_delete(&ctx->process_lock); vcos_semaphore_delete(&ctx->sema); free(ctx); }
BRCMJPEG_STATUS_T brcmjpeg_create(BRCMJPEG_TYPE_T type, BRCMJPEG_T **ctx) { BRCMJPEG_STATUS_T status = BRCMJPEG_SUCCESS; BRCMJPEG_T **comp; if (type == BRCMJPEG_TYPE_ENCODER) comp = &brcmjpeg_encoder; else comp = &brcmjpeg_decoder; vcos_once(&once, brcmjpeg_init_once); LOCK(); if (!*comp) { int init1, init2, init3; *comp = (BRCMJPEG_T*)calloc(sizeof(BRCMJPEG_T), 1); if (!*comp) { UNLOCK(); return BRCMJPEG_ERROR_NOMEM; } (*comp)->type = type; init1 = vcos_mutex_create(&(*comp)->lock, "brcmjpeg lock") != VCOS_SUCCESS; init2 = vcos_mutex_create(&(*comp)->process_lock, "brcmjpeg process lock") != VCOS_SUCCESS; init3 = vcos_semaphore_create(&(*comp)->sema, "brcmjpeg sema", 0) != VCOS_SUCCESS; if (init1 | init2 | init3) { if (init1) vcos_mutex_delete(&(*comp)->lock); if (init2) vcos_mutex_delete(&(*comp)->process_lock); if (init3) vcos_semaphore_delete(&(*comp)->sema); free(comp); UNLOCK(); return BRCMJPEG_ERROR_NOMEM; } } (*comp)->ref_count++; UNLOCK(); LOCK_COMP(*comp); if (!(*comp)->init) { if (type == BRCMJPEG_TYPE_ENCODER) status = brcmjpeg_init_encoder(*comp); else status = brcmjpeg_init_decoder(*comp); (*comp)->init = status == BRCMJPEG_SUCCESS; } UNLOCK_COMP(*comp); if (status != BRCMJPEG_SUCCESS) brcmjpeg_release(*comp); *ctx = *comp; return status; }
/** Free a port structure */ void mmal_port_free(MMAL_PORT_T *port) { LOG_TRACE("%s at %p", port ? port->name : "<invalid>", port); if (!port) return; vcos_assert(port->format == port->priv->core->format_ptr_copy); mmal_format_free(port->priv->core->format_ptr_copy); vcos_semaphore_delete(&port->priv->core->transit_sema); vcos_mutex_delete(&port->priv->core->transit_lock); vcos_mutex_delete(&port->priv->core->send_lock); vcos_mutex_delete(&port->priv->core->lock); vcos_free(port); }
/* Destroy SVP instance. svp may be NULL. */ void svp_destroy(SVP_T *svp) { if (svp) { MMAL_COMPONENT_T *components[] = { svp->reader, svp->video_decode, svp->camera }; MMAL_COMPONENT_T **comp; /* Stop thread, disable connection and components */ svp_stop(svp); for (comp = components; comp < components + vcos_countof(components); comp++) { mmal_component_disable(*comp); } /* Destroy connection + components */ if (svp->connection) { mmal_connection_destroy(svp->connection); } for (comp = components; comp < components + vcos_countof(components); comp++) { mmal_component_destroy(*comp); } /* Free remaining resources */ if (svp->out_pool) { mmal_pool_destroy(svp->out_pool); } if (svp->queue) { mmal_queue_destroy(svp->queue); } if (svp->created & SVP_CREATED_WD_TIMER) { vcos_timer_delete(&svp->wd_timer); } if (svp->created & SVP_CREATED_TIMER) { vcos_timer_delete(&svp->timer); } if (svp->created & SVP_CREATED_MUTEX) { vcos_mutex_delete(&svp->mutex); } if (svp->created & SVP_CREATED_SEM) { vcos_semaphore_delete(&svp->sema); } vcos_free(svp); } }
/*********************************************************** * Name: vc_dispmanx_stop * * Arguments: * - * * Description: Stops the Host side part of dispmanx * * Returns: - * ***********************************************************/ VCHPRE_ void VCHPOST_ vc_dispmanx_stop( void ) { // Wait for the current lock-holder to finish before zapping dispmanx. //TODO: kill the notifier task void *dummy; uint32_t i; if (!dispmanx_client.initialised) return; lock_obtain(); for (i=0; i<dispmanx_client.num_connections; i++) { int32_t result; result = vchi_service_close(dispmanx_client.client_handle[i]); vcos_assert( result == 0 ); result = vchi_service_close(dispmanx_client.notify_handle[i]); vcos_assert( result == 0 ); } lock_release(); dispmanx_client.initialised = 0; vcos_event_signal(&dispmanx_notify_available_event); vcos_thread_join(&dispmanx_notify_task, &dummy); vcos_mutex_delete(&dispmanx_client.lock); vcos_event_delete(&dispmanx_message_available_event); vcos_event_delete(&dispmanx_notify_available_event); }
void vcos_generic_blockpool_delete(VCOS_BLOCKPOOL_T *pool) { vcos_log_trace("%s: pool %p", VCOS_FUNCTION, pool); if (pool) { VCOS_UNSIGNED i; ASSERT_POOL(pool); for (i = 0; i < pool->num_subpools; ++i) { VCOS_BLOCKPOOL_SUBPOOL_T *subpool = &pool->subpools[i]; ASSERT_SUBPOOL(subpool); if (subpool->mem) { /* For debugging */ memset(subpool->mem, 0xBE, VCOS_BLOCKPOOL_SIZE(subpool->num_blocks, pool->block_data_size, pool->align)); if (subpool->flags & VCOS_BLOCKPOOL_SUBPOOL_FLAG_OWNS_MEM) vcos_free(subpool->mem); subpool->mem = NULL; subpool->start = NULL; } } vcos_mutex_delete(&pool->mutex); memset(pool, 0xBE, sizeof(VCOS_BLOCKPOOL_T)); /* For debugging */ } }
void vc_gencmd_stop () { // Assume a "power down" gencmd has been sent and the lock is held. There will // be no response so this should be called instead. int32_t success,i; if (!gencmd_client.initialised) return; if(lock_obtain() == 0) { use_gencmd_service(); for(i = 0; i< (int32_t)gencmd_client.num_connections; i++) { success = vchi_service_close( gencmd_client.open_handle[i]); assert(success == 0); } gencmd_client.initialised = 0; lock_release(); vcos_mutex_delete(&gencmd_client.lock); vcos_event_delete(&gencmd_client.message_available_event); } }
/** Destroy a queue of MMAL_BUFFER_HEADER_T */ void mmal_queue_destroy(MMAL_QUEUE_T *queue) { if(!queue) return; vcos_mutex_delete(&queue->lock); vcos_semaphore_delete(&queue->semaphore); vcos_free(queue); }
/** Create a QUEUE of MMAL_BUFFER_HEADER_T */ MMAL_QUEUE_T *mmal_queue_create(void) { MMAL_QUEUE_T *queue; queue = vcos_malloc(sizeof(*queue), "MMAL queue"); if(!queue) return 0; if(vcos_mutex_create(&queue->lock, "MMAL queue lock") != VCOS_SUCCESS ) { vcos_free(queue); return 0; } if(vcos_semaphore_create(&queue->semaphore, "MMAL queue sema", 0) != VCOS_SUCCESS ) { vcos_mutex_delete(&queue->lock); vcos_free(queue); return 0; } /* gratuitous lock for coverity */ vcos_mutex_lock(&queue->lock); queue->length = 0; queue->first = 0; queue->last = &queue->first; mmal_queue_sanity_check(queue, NULL); /* gratuitous unlock for coverity */ vcos_mutex_unlock(&queue->lock); return queue; }
/** Destroy a vidtex instance */ static void vidtex_destroy(VIDTEX_T *vt) { vidtex_gl_term(vt); vcos_mutex_delete(&vt->mutex); vcos_semaphore_delete(&vt->sem_drawn); vcos_semaphore_delete(&vt->sem_decoded); vcos_free(vt); }
/** Create a new vidtex instance */ static VIDTEX_T *vidtex_create(EGLNativeWindowType win) { VIDTEX_T *vt; VCOS_STATUS_T st; vt = vcos_calloc(1, sizeof(*vt), "vidtex"); if (vt == NULL) { vcos_log_trace("Memory allocation failure"); return NULL; } st = vcos_semaphore_create(&vt->sem_decoded, "vidtex-dec", 0); if (st != VCOS_SUCCESS) { vcos_log_trace("Error creating semaphore"); goto error_ctx; } st = vcos_semaphore_create(&vt->sem_drawn, "vidtex-drw", 0); if (st != VCOS_SUCCESS) { vcos_log_trace("Error creating semaphore"); goto error_sem1; } st = vcos_mutex_create(&vt->mutex, "vidtex"); if (st != VCOS_SUCCESS) { vcos_log_trace("Error creating semaphore"); goto error_sem2; } if (vidtex_gl_init(vt, win) != 0) { vcos_log_trace("Error initialising EGL"); goto error_mutex; } vt->quit = false; vt->stop_reason = 0; return vt; error_mutex: vcos_mutex_delete(&vt->mutex); error_sem2: vcos_semaphore_delete(&vt->sem_drawn); error_sem1: vcos_semaphore_delete(&vt->sem_decoded); error_ctx: vcos_free(vt); return NULL; }
static void vcos_term(uint32_t flags) { if (flags & VCOS_INIT_MSGQ) vcos_msgq_deinit(); if (flags & VCOS_INIT_MAIN_SEM) vcos_semaphore_delete(&vcos_thread_main.suspend); #ifdef ANDROID if (flags & VCOS_INIT_PRINTF_LOCK) vcos_mutex_delete(&printf_lock); #endif if (flags & VCOS_INIT_NAMED_SEM) _vcos_named_semaphore_deinit(); }
VCOS_STATUS_T vcos_msgq_init(void) { VCOS_STATUS_T st = vcos_mutex_create(&lock,"msgq"); if (st != VCOS_SUCCESS) goto fail_mtx; st = vcos_tls_create(&tls_key); if (st != VCOS_SUCCESS) goto fail_tls; endpoints = NULL; return st; fail_tls: vcos_mutex_delete(&lock); fail_mtx: return st; }
void mmal_vc_deinit(void) { int count; vcos_mutex_lock(&client.lock); count = --client.refcount; if (count != 0) { /* Still in use so don't do anything */ vcos_mutex_unlock(&client.lock); return; } vcos_mutex_delete(&client.bulk_lock); destroy_waitpool(&client.waitpool); vchiq_close_service(client.service); vchiq_shutdown(mmal_vchiq_instance); vcos_log_unregister(VCOS_LOG_CATEGORY); client.service = VCHIQ_SERVICE_HANDLE_INVALID; client.inited = 0; vcos_mutex_unlock(&client.lock); }
void vcos_msgq_deinit(void) { vcos_mutex_delete(&lock); vcos_tls_delete(tls_key); }
/** Allocate a port structure */ MMAL_PORT_T *mmal_port_alloc(MMAL_COMPONENT_T *component, MMAL_PORT_TYPE_T type, unsigned int extra_size) { MMAL_PORT_T *port; MMAL_PORT_PRIVATE_CORE_T *core; unsigned int name_size = strlen(component->name) + sizeof(PORT_NAME_FORMAT); unsigned int size = sizeof(*port) + sizeof(MMAL_PORT_PRIVATE_T) + sizeof(MMAL_PORT_PRIVATE_CORE_T) + name_size + extra_size; MMAL_BOOL_T lock = 0, lock_send = 0, lock_transit = 0, sema_transit = 0; MMAL_BOOL_T lock_stats = 0, lock_connection = 0; LOG_TRACE("component:%s type:%u extra:%u", component->name, type, extra_size); port = vcos_calloc(1, size, "mmal port"); if (!port) { LOG_ERROR("failed to allocate port, size %u", size); return 0; } port->type = type; port->priv = (MMAL_PORT_PRIVATE_T *)(port+1); port->priv->core = core = (MMAL_PORT_PRIVATE_CORE_T *)(port->priv+1); if (extra_size) port->priv->module = (struct MMAL_PORT_MODULE_T *)(port->priv->core+1); port->component = component; port->name = core->name = ((char *)(port->priv->core+1)) + extra_size; core->name_size = name_size; mmal_port_name_update(port); core->queue_last = &core->queue_first; port->priv->pf_connect = mmal_port_connect_default; lock = vcos_mutex_create(&port->priv->core->lock, "mmal port lock") == VCOS_SUCCESS; lock_send = vcos_mutex_create(&port->priv->core->send_lock, "mmal port send lock") == VCOS_SUCCESS; lock_transit = vcos_mutex_create(&port->priv->core->transit_lock, "mmal port transit lock") == VCOS_SUCCESS; sema_transit = vcos_semaphore_create(&port->priv->core->transit_sema, "mmal port transit sema", 1) == VCOS_SUCCESS; lock_stats = vcos_mutex_create(&port->priv->core->stats_lock, "mmal stats lock") == VCOS_SUCCESS; lock_connection = vcos_mutex_create(&port->priv->core->connection_lock, "mmal connection lock") == VCOS_SUCCESS; if (!lock || !lock_send || !lock_transit || !sema_transit || !lock_stats || !lock_connection) { LOG_ERROR("%s: failed to create sync objects (%u,%u,%u,%u,%u,%u)", port->name, lock, lock_send, lock_transit, sema_transit, lock_stats, lock_connection); goto error; } port->format = mmal_format_alloc(); if (!port->format) { LOG_ERROR("%s: failed to allocate format object", port->name); goto error; } port->priv->core->format_ptr_copy = port->format; LOG_TRACE("%s: created at %p", port->name, port); return port; error: if (lock) vcos_mutex_delete(&port->priv->core->lock); if (lock_send) vcos_mutex_delete(&port->priv->core->send_lock); if (lock_transit) vcos_mutex_delete(&port->priv->core->transit_lock); if (sema_transit) vcos_semaphore_delete(&port->priv->core->transit_sema); if (lock_stats) vcos_mutex_delete(&port->priv->core->stats_lock); if (lock_connection) vcos_mutex_delete(&port->priv->core->connection_lock); if (port->format) mmal_format_free(port->format); vcos_free(port); return 0; }
void vcos_generic_event_flags_delete(VCOS_EVENT_FLAGS_T *flags) { vcos_mutex_delete(&flags->lock); }
void _vcos_named_semaphore_deinit(void) { vcos_mutex_delete(&lock); }
void vcos_generic_reentrant_mutex_delete(VCOS_REENTRANT_MUTEX_T *m) { vcos_assert(m->count == 0); vcos_mutex_delete(&m->mutex); }
static void __inline local_mutex_destroy(LOCAL_MUTEX_T *mutex) { vcos_mutex_delete(&mutex->mutex); }
static void vcos_msgq_delete(VCOS_MSGQUEUE_T *q) { vcos_semaphore_delete(&q->sem); vcos_mutex_delete(&q->lock); }