/** 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; }
/** Find a font in our cache, or create a new entry in the cache. * * Very primitive at present. */ static VGFT_FONT_T *find_font(const char *text, uint32_t text_size) { int ptsize, dpi_x = 0, dpi_y = 0; VCOS_STATUS_T status; gx_font_cache_entry_t *font; ptsize = text_size << 6; // freetype takes size in points, in 26.6 format. for (font = fonts; font; font = font->next) { if (font->ptsize == ptsize) return &font->font; } font = vcos_malloc(sizeof(*font), "font"); if (!font) return NULL; font->ptsize = ptsize; status = vgft_font_init(&font->font); if (status != VCOS_SUCCESS) { vcos_free(font); return NULL; } // load the font status = vgft_font_load_mem(&font->font, default_font.mem, default_font.len); if (status != VCOS_SUCCESS) { GX_LOG("Could not load font from memory: %d", status); vgft_font_term(&font->font); vcos_free(font); return NULL; } status = vgft_font_convert_glyphs(&font->font, ptsize, dpi_x, dpi_y); if (status != VCOS_SUCCESS) { GX_LOG("Could not convert font '%s' at size %d", fname, ptsize); vgft_font_term(&font->font); vcos_free(font); return NULL; } font->next = fonts; fonts = font; return &font->font; }
static OMX_ERRORTYPE vcil_out_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE* pBufferHdr) { OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *) hComponent; VC_PRIVATE_COMPONENT_T *comp; IL_FREE_BUFFER_EXECUTE_T exe; IL_RESPONSE_HEADER_T resp; VC_PRIVATE_PORT_T *port; ILCS_COMMON_T *st; int rlen = sizeof(resp); if (!(pComp && pBufferHdr)) return OMX_ErrorBadParameter; st = pComp->pApplicationPrivate; comp = (VC_PRIVATE_COMPONENT_T *) pComp->pComponentPrivate; port = find_port(comp, nPortIndex); if (!port) return OMX_ErrorBadPortIndex; if (port->numBuffers == 0) return OMX_ErrorIncorrectStateTransition; exe.reference = comp->reference; exe.port = nPortIndex; if (port->dir == OMX_DirOutput) exe.bufferReference = pBufferHdr->pOutputPortPrivate; else exe.bufferReference = pBufferHdr->pInputPortPrivate; exe.func = port->func; exe.inputPrivate = NULL; exe.outputPrivate = NULL; if(ilcs_execute_function(st->ilcs, IL_FREE_BUFFER, &exe, sizeof(exe), &resp, &rlen) < 0 || rlen != sizeof(resp)) return OMX_ErrorHardware; if (resp.err == OMX_ErrorNone) { if (port->func == IL_ALLOCATE_BUFFER) vcos_free(pBufferHdr->pBuffer); vcos_free(pBufferHdr); port->numBuffers--; } return resp.err; }
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 */ } }
VCOS_STATUS_T vcos_generic_blockpool_create_on_heap(VCOS_BLOCKPOOL_T *pool, VCOS_UNSIGNED num_blocks, VCOS_UNSIGNED block_size, VCOS_UNSIGNED align, VCOS_UNSIGNED flags, const char *name) { VCOS_STATUS_T status = VCOS_SUCCESS; size_t size = VCOS_BLOCKPOOL_SIZE(num_blocks, block_size, align); void* mem = vcos_malloc(size, name); vcos_log_trace("%s: num_blocks %d block_size %d name %s", VCOS_FUNCTION, num_blocks, block_size, name); if (! mem) return VCOS_ENOMEM; status = vcos_generic_blockpool_init(pool, num_blocks, block_size, mem, size, align, flags, name); if (status != VCOS_SUCCESS) goto fail; pool->subpools[0].flags |= VCOS_BLOCKPOOL_SUBPOOL_FLAG_OWNS_MEM; return status; fail: vcos_free(mem); return status; }
static int calloc_test() { int passed = 1; int num, size; for(num = 1; num < 10; num++) { for(size = 1; size < 512; size = (size*3)+7) { uint8_t *buf = vcos_calloc(num, size, "test4"); int i; if(!buf) passed = 0; else { for(i=0; i<size*num; i++) { if(buf[i]) passed = 0; buf[i] = i & 0xff; } vcos_free(buf); } } } return passed; }
static int malloc_aligned_test() { int passed = 1; uint32_t size, align; for(size = 1; size < 1024; size = (size*3)+7) { for(align = 1; align < 4096; align<<=1) { uint8_t *buf = vcos_malloc_aligned(size, align, "test5"); if(!buf) passed = 0; { if((unsigned long) buf & (align-1)) passed = 0; memset(buf,0,size); vcos_free(buf); } } } return passed; }
/** Free memory @param v Pointer to memory area to free **/ void khrn_platform_free(void *v) { if (v) { vcos_free(v); } }
VCOS_THREAD_T *vcos_dummy_thread_create(void) { VCOS_STATUS_T st; VCOS_THREAD_T *thread_hndl = NULL; int rc; thread_hndl = (VCOS_THREAD_T *)vcos_malloc(sizeof(VCOS_THREAD_T), NULL); vcos_assert(thread_hndl != NULL); memset(thread_hndl, 0, sizeof(VCOS_THREAD_T)); thread_hndl->dummy = 1; thread_hndl->thread = pthread_self(); st = vcos_semaphore_create(&thread_hndl->suspend, NULL, 0); if (st != VCOS_SUCCESS) { vcos_free(thread_hndl); return( thread_hndl ); } vcos_once(¤t_thread_key_once, current_thread_key_init); rc = pthread_setspecific(_vcos_thread_current_key, thread_hndl); (void)rc; return( thread_hndl ); }
/** 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); }
void vchiu_queue_delete(VCHIU_QUEUE_T *queue) { vcos_event_delete(&queue->pop); vcos_event_delete(&queue->push); if (queue->storage != NULL) vcos_free(queue->storage); }
static MMAL_STATUS_T mmal_connection_destroy_internal(MMAL_CONNECTION_T *connection) { MMAL_STATUS_T status; if (connection->is_enabled) { status = mmal_connection_disable(connection); if (status != MMAL_SUCCESS) return status; } /* Special case for tunnelling */ if (connection->flags & MMAL_CONNECTION_FLAG_TUNNELLING) { status = mmal_port_disconnect(connection->out); if (status != MMAL_SUCCESS) LOG_ERROR("connection %s could not be cleared", connection->name); } /* Cleanup resources */ if (connection->pool) mmal_pool_destroy(connection->pool); if (connection->queue) mmal_queue_destroy(connection->queue); vcos_free(connection); return MMAL_SUCCESS; }
int vchiq_wrapper_add_service(VCHIQ_STATE_T *state, void **vconnection, int fourcc, VCHIQ_CALLBACK_T callback, void *userdata) { VCHI_CONNECTION_T **connection = (VCHI_CONNECTION_T **) vconnection; VCHI_INSTANCE_T *instance_handle = (VCHI_INSTANCE_T *) state; SERVICE_CREATION_T parameters = { fourcc, // 4cc service code 0, // passed in fn ptrs 0, // tx fifo size (unused) 0, // tx fifo size (unused) vchiq_wrapper_callback, // service callback 0 }; // callback parameter VCHIQ_WRAPPER_T *st = vcos_malloc(sizeof(VCHIQ_WRAPPER_T), "vchiq wrapper"); if(st == NULL) return 0; parameters.connection = connection[0]; parameters.callback_param = st; st->state = state; st->fourcc = fourcc; st->callback = callback; st->userdata = userdata; st->slot_free = ((1<<SLOT_NUM)-1); if(vchi_service_create(*instance_handle, ¶meters, &st->vchi_handle) != 0) { vcos_free(st); return 0; } // add to the global list of wrappers st->next = wrapper_list; wrapper_list = st; return 1; }
void vcil_in_free_buffer(ILCS_COMMON_T *st, void *call, int clen, void *resp, int *rlen) { IL_FREE_BUFFER_EXECUTE_T *exe = call; IL_RESPONSE_HEADER_T *ret = resp; OMX_COMPONENTTYPE *pComp = exe->reference; OMX_BUFFERHEADERTYPE *pHeader; OMX_U8 *buffer; OMX_PARAM_PORTDEFINITIONTYPE def; OMX_ERRORTYPE error; def.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); def.nVersion.nVersion = OMX_VERSION; def.nPortIndex = exe->port; error = pComp->GetParameter(pComp, OMX_IndexParamPortDefinition, &def); vc_assert(error == OMX_ErrorNone); if (def.eDir == OMX_DirInput) pHeader = exe->inputPrivate; else pHeader = exe->outputPrivate; buffer = pHeader->pBuffer; *rlen = sizeof(IL_RESPONSE_HEADER_T); ret->func = IL_FREE_BUFFER; ret->err = pComp->FreeBuffer(pComp, exe->port, pHeader); if (ret->err == OMX_ErrorNone) vcos_free(buffer); }
/* 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); } }
VCOS_THREAD_T *vcos_dummy_thread_create(void) { VCOS_STATUS_T st; VCOS_THREAD_T *thread_hndl = NULL; int rc; thread_hndl = (VCOS_THREAD_T *)vcos_malloc(sizeof(VCOS_THREAD_T), NULL); vcos_assert(thread_hndl != NULL); memset(thread_hndl, 0, sizeof(VCOS_THREAD_T)); thread_hndl->dummy = 1; thread_hndl->thread = vcos_llthread_current(); st = vcos_semaphore_create(&thread_hndl->suspend, NULL, 0); if (st != VCOS_SUCCESS) { vcos_free(thread_hndl); return( thread_hndl ); } vcos_once(¤t_thread_key_once, current_thread_key_init); #ifdef WIN32_KERN // TODO : Implement kenel mode implementation #else TlsSetValue(_vcos_thread_current_key, thread_hndl); #endif (void)rc; return(thread_hndl); }
/** Free a payload buffer */ void mmal_port_payload_free(MMAL_PORT_T *port, uint8_t *payload) { if (!port || !port->priv) return; LOG_TRACE("%s(%i:%i) port %p, payload %p", port->component->name, (int)port->type, (int)port->index, port, payload); if (!port->priv->pf_payload_alloc) { /* Revert to using the heap */ #ifdef _VIDEOCORE mem_release((MEM_HANDLE_T)payload); #else vcos_free(payload); #endif mmal_port_release(port); return; } LOCK_PORT(port); port->priv->pf_payload_free(port, payload); UNLOCK_PORT(port); mmal_port_release(port); }
/** Free an array of ports */ void mmal_ports_free(MMAL_PORT_T **ports, unsigned int ports_num) { unsigned int i; for (i = 0; i < ports_num; i++) mmal_port_free(ports[i]); vcos_free(ports); }
/** 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); }
MMAL_PARAMETER_HEADER_T *mmal_port_parameter_alloc_get(MMAL_PORT_T *port, uint32_t id, uint32_t size, MMAL_STATUS_T *p_status) { MMAL_PARAMETER_HEADER_T *param = NULL; MMAL_STATUS_T status = MMAL_ENOSYS; if (size < sizeof(MMAL_PARAMETER_HEADER_T)) size = sizeof(MMAL_PARAMETER_HEADER_T); if ((param = vcos_calloc(1, size, "mmal_port_param_get")) == NULL) { status = MMAL_ENOMEM; goto error; } param->id = id; param->size = size; if ((status = mmal_port_parameter_get(port, param)) == MMAL_ENOSPC) { /* We need to reallocate to get enough space for all parameter data */ size = param->size; vcos_free(param); if ((param = vcos_calloc(1, size, "mmal_port_param_get")) == NULL) { status = MMAL_ENOMEM; goto error; } /* Now retrieve it again */ param->id = id; param->size = size; status = mmal_port_parameter_get(port, param); } if (status != MMAL_SUCCESS) goto error; end: if (p_status) *p_status = status; return param; error: if (param) vcos_free(param); param = NULL; goto end; }
void gx_font_cache_flush(void) { while (fonts != NULL) { struct gx_font_cache_entry_t *next = fonts->next; vgft_font_term(&fonts->font); vcos_free(fonts); fonts = next; } }
/** 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; }
void vcos_thread_exit(void *arg) { VCOS_THREAD_T *thread = vcos_thread_current(); if ( thread && thread->dummy ) { vcos_free ( (void*) thread ); thread = NULL; } pthread_exit(arg); }
void _vcos_thread_delete(VCOS_THREAD_T *thread) { vcos_assert(thread); vcos_assert(thread->magic == VCOS_THREAD_MAGIC); vcos_llthread_delete(&thread->thread); if (thread->stack) vcos_free(thread->stack); delete_base(thread); }
static OMX_ERRORTYPE vcil_out_ComponentDeInit(OMX_IN OMX_HANDLETYPE hComponent) { OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *) hComponent; VC_PRIVATE_COMPONENT_T *comp; IL_EXECUTE_HEADER_T exe; IL_RESPONSE_HEADER_T resp; ILCS_COMMON_T *st; int rlen = sizeof(resp); if(!pComp) return OMX_ErrorBadParameter; st = pComp->pApplicationPrivate; comp = (VC_PRIVATE_COMPONENT_T *) pComp->pComponentPrivate; exe.reference = comp->reference; if(ilcs_execute_function(st->ilcs, IL_COMPONENT_DEINIT, &exe, sizeof(exe), &resp, &rlen) < 0 || rlen != sizeof(resp) || resp.err == OMX_ErrorNone) { // remove from list, assuming that we successfully managed to deinit // this component, or that ilcs has returned an error. The assumption // here is that if the component has managed to correctly signal an // error, it still exists, but if the transport has failed then we might // as well try and cleanup VC_PRIVATE_COMPONENT_T *list, *prev; vcos_semaphore_wait(&st->component_lock); list = st->component_list; prev = NULL; while (list != NULL && list != comp) { prev = list; list = list->next; } // failing to find this component is not a good sign. if(vcos_verify(list)) { if (prev == NULL) st->component_list = list->next; else prev->next = list->next; } vcos_semaphore_post(&st->component_lock); vcos_free(comp); } return resp.err; }
void vcos_thread_exit(void *arg) { VCOS_THREAD_T *thread = vcos_thread_current(); if ( thread && thread->dummy ) { vcos_free ( (void*) thread ); thread = NULL; } // Do nothing UNREFERENCED_PARAMETER(arg); }
/** Destroy a previously created component */ static MMAL_STATUS_T sdl_component_destroy(MMAL_COMPONENT_T *component) { MMAL_COMPONENT_MODULE_T *module = component->priv->module; if (module->audio_opened) SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); if(component->input_num) mmal_ports_free(component->input, 1); if(module->queue) mmal_queue_destroy(module->queue); vcos_free(module); return MMAL_SUCCESS; }
static int malloc_test() { int passed = 1; int size; for(size = 1; size < 4096; size = (size*3)+7) { uint8_t *mem = vcos_malloc(size, "test"); if(!mem) passed = 0; else { int i; for(i=0; i<size; i++) mem[i] = i&0xff; vcos_free(mem); } } if(passed) { uint8_t *mem1, *mem2, *mem3; mem1 = vcos_malloc(1<<10, "test1"); mem2 = vcos_malloc(1<<11, "test2"); mem3 = vcos_malloc(1<<16, "test3"); if(!mem1 || !mem2 || !mem3 || mem1==mem2 || mem1==mem3 || mem2==mem3) passed = 0; if(mem1) vcos_free(mem1); if(mem2) vcos_free(mem2); if(mem3) vcos_free(mem3); } return passed; }
static void vcos_dummy_thread_cleanup(void *cxt) { VCOS_THREAD_T *thread = cxt; if (thread->dummy) { int i; /* call termination functions */ for (i=0; thread->at_exit[i].pfn != NULL; i++) { thread->at_exit[i].pfn(thread->at_exit[i].cxt); } vcos_thread_cleanup(thread); vcos_free(thread); } }
/** 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); }