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); }
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 ); }
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; }
int32_t vc_gpuserv_init( void ) { VCHIQ_SERVICE_PARAMS_T vchiq_params; VCOS_STATUS_T status = VCOS_ENXIO; VCHIQ_STATUS_T vchiq_status; vcos_once(&gpuserv_client_once, init_once); vcos_mutex_lock(&gpuserv_client.lock); if (gpuserv_client.refcount++ > 0) { /* Already initialised so nothing to do */ vcos_mutex_unlock(&gpuserv_client.lock); return VCOS_SUCCESS; } vcos_log_set_level(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE); vcos_log_register("gpuserv", VCOS_LOG_CATEGORY); vcos_log_trace("%s: starting initialisation", VCOS_FUNCTION); /* Initialise a VCHIQ instance */ vchiq_status = vchiq_initialise(&gpuserv_client_vchiq_instance); if (vchiq_status != VCHIQ_SUCCESS) { vcos_log_error("%s: failed to initialise vchiq: %d", VCOS_FUNCTION, vchiq_status); goto error; } vchiq_status = vchiq_connect(gpuserv_client_vchiq_instance); if (vchiq_status != VCHIQ_SUCCESS) { vcos_log_error("%s: failed to connect to vchiq: %d", VCOS_FUNCTION, vchiq_status); goto error; } memset(&vchiq_params, 0, sizeof(vchiq_params)); vchiq_params.fourcc = VCHIQ_MAKE_FOURCC('G','P','U','S'); vchiq_params.callback = gpuserv_callback; vchiq_params.userdata = NULL; vchiq_params.version = 1; vchiq_params.version_min = 1; vchiq_status = vchiq_open_service(gpuserv_client_vchiq_instance, &vchiq_params, &gpuserv_client.service); if (vchiq_status != VCHIQ_SUCCESS) { vcos_log_error("%s: could not open vchiq service: %d", VCOS_FUNCTION, vchiq_status); goto error; } vcos_mutex_unlock(&gpuserv_client.lock); return 0; error: vcos_mutex_unlock(&gpuserv_client.lock); return -1; }
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; }
VCOS_STATUS_T vcos_platform_init(void) { VCOS_STATUS_T st; uint32_t flags = 0; st = _vcos_named_semaphore_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_NAMED_SEM; st = vcos_once(¤t_thread_key_once, current_thread_key_init); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; /* Initialise a VCOS wrapper for the thread which called vcos_init. */ st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MAIN_SEM; #ifdef WIN32_KERN vcos_thread_main.thread = PsGetCurrentThreadId(); // TODO Implement thread context for kernel mode #else int pst; vcos_thread_main.thread = GetCurrentThread(); // For windows zero return value is failure pst = TlsSetValue(_vcos_thread_current_key, &vcos_thread_main); if (!vcos_verify(pst != 0)) { st = VCOS_EINVAL; goto end; } #endif st = vcos_msgq_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MSGQ; vcos_logging_init(); end: if (st != VCOS_SUCCESS) vcos_term(flags); return st; }
static OMX_ERRORTYPE vcil_out_UseEGLImage(OMX_IN OMX_HANDLETYPE hComponent, OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_PTR pAppPrivate, OMX_IN void* eglImage) { /* Load eglIntOpenMAXILDoneMarker() and libEGL here, it will be needed later */ vcos_once(&loaded_eglIntOpenMAXILDoneMarker, load_eglIntOpenMAXILDoneMarker); return vcil_out_addBuffer(hComponent, ppBufferHdr, nPortIndex, pAppPrivate, 0, NULL, eglImage, IL_USE_EGL_IMAGE); }
/* OMX_Init */ OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void) { VCOS_STATUS_T status; OMX_ERRORTYPE err = OMX_ErrorNone; status = vcos_once(&once, initOnce); vcos_demand(status == VCOS_SUCCESS); vcos_mutex_lock(&lock); if(coreInit == 0) { // we need to connect via an ILCS connection to VideoCore VCHI_INSTANCE_T initialise_instance; VCHI_CONNECTION_T *connection; ILCS_CONFIG_T config; vc_host_get_vchi_state(&initialise_instance, &connection); vcilcs_config(&config); ilcs_service = ilcs_init((VCHIQ_INSTANCE_T) initialise_instance, (void **) &connection, &config, 0); if(ilcs_service == NULL) { err = OMX_ErrorHardware; goto end; } coreInit = 1; } else coreInit++; end: vcos_mutex_unlock(&lock); return err; }
MMAL_STATUS_T mmal_vc_init(void) { VCHIQ_SERVICE_PARAMS_T vchiq_params; MMAL_BOOL_T vchiq_initialised = 0, waitpool_initialised = 0; MMAL_BOOL_T service_initialised = 0; MMAL_STATUS_T status = MMAL_EIO; VCHIQ_STATUS_T vchiq_status; int count; vcos_once(&once, init_once); vcos_mutex_lock(&client.lock); count = client.refcount++; if (count > 0) { /* Already initialised so nothing to do */ vcos_mutex_unlock(&client.lock); return MMAL_SUCCESS; } vcos_log_register("mmalipc", VCOS_LOG_CATEGORY); /* Initialise a VCHIQ instance */ vchiq_status = vchiq_initialise(&mmal_vchiq_instance); if (vchiq_status != VCHIQ_SUCCESS) { LOG_ERROR("failed to initialise vchiq"); status = MMAL_EIO; goto error; } vchiq_initialised = 1; vchiq_status = vchiq_connect(mmal_vchiq_instance); if (vchiq_status != VCHIQ_SUCCESS) { LOG_ERROR("failed to connect to vchiq"); status = MMAL_EIO; goto error; } memset(&vchiq_params,0,sizeof(vchiq_params)); vchiq_params.fourcc = MMAL_CONTROL_FOURCC(); vchiq_params.callback = mmal_vc_vchiq_callback; vchiq_params.userdata = &client; vchiq_params.version = WORKER_VER_MAJOR; vchiq_params.version_min = WORKER_VER_MINIMUM; vchiq_status = vchiq_open_service(mmal_vchiq_instance, &vchiq_params, &client.service); if (vchiq_status != VCHIQ_SUCCESS) { LOG_ERROR("could not open vchiq service"); status = MMAL_EIO; goto error; } client.usecount = 1; /* usecount set to 1 by the open call. */ service_initialised = 1; status = create_waitpool(&client.waitpool); if (status != MMAL_SUCCESS) { LOG_ERROR("could not create wait pool"); goto error; } waitpool_initialised = 1; if (vcos_mutex_create(&client.bulk_lock, "mmal client bulk lock") != VCOS_SUCCESS) { LOG_ERROR("could not create bulk lock"); status = MMAL_ENOSPC; goto error; } client.inited = 1; vcos_mutex_unlock(&client.lock); /* assume we're not using VC immediately. Do this outside the lock */ mmal_vc_release(); return MMAL_SUCCESS; error: if (waitpool_initialised) destroy_waitpool(&client.waitpool); if (service_initialised) { client.usecount = 0; vchiq_close_service(client.service); } if (vchiq_initialised) vchiq_shutdown(mmal_vchiq_instance); vcos_log_unregister(VCOS_LOG_CATEGORY); client.refcount--; vcos_mutex_unlock(&client.lock); return status; }
VCOS_STATUS_T vcos_platform_init(void) { VCOS_STATUS_T st; uint32_t flags = 0; int pst; st = _vcos_named_semaphore_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_NAMED_SEM; #ifdef HAVE_MTRACE /* enable glibc memory debugging, if the environment * variable MALLOC_TRACE names a valid file. */ mtrace(); #endif #ifdef ANDROID st = vcos_mutex_create(&printf_lock, "printf"); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_PRINTF_LOCK; #endif st = vcos_once(¤t_thread_key_once, current_thread_key_init); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; /* Initialise a VCOS wrapper for the thread which called vcos_init. */ st = vcos_semaphore_create(&vcos_thread_main.suspend, NULL, 0); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MAIN_SEM; vcos_thread_main.thread = pthread_self(); pst = pthread_setspecific(_vcos_thread_current_key, &vcos_thread_main); if (!vcos_verify(pst == 0)) { st = VCOS_EINVAL; goto end; } st = vcos_msgq_init(); if (!vcos_verify(st == VCOS_SUCCESS)) goto end; flags |= VCOS_INIT_MSGQ; vcos_logging_init(); end: if (st != VCOS_SUCCESS) vcos_term(flags); return st; }