boolean nx_config_cache_get_string(const char *module, const char *key, const char **result) { nx_ctx_t *ctx; nx_cc_item_t *item; char ckey[NX_CONFIG_CACHE_MAX_KEYLEN]; ASSERT(module != NULL); ASSERT(key != NULL); ctx = nx_ctx_get(); if ( apr_snprintf(ckey, sizeof(ckey), "%s/%s", module, key) == sizeof(ckey) ) { nx_panic("config cache key too long, limit is %d bytes", NX_CONFIG_CACHE_MAX_KEYLEN); } CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex)); item = (nx_cc_item_t *) apr_hash_get(ctx->config_cache, ckey, APR_HASH_KEY_STRING); CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); if ( item == NULL ) { return ( FALSE ); } if ( (strcmp(item->key, ckey) == 0) && (item->value->type == NX_VALUE_TYPE_STRING) ) { ASSERT(item->value->string != NULL); *result = item->value->string->buf; item->used = TRUE; return ( TRUE ); } return ( FALSE ); }
void nx_config_cache_free() { nx_ctx_t *ctx; nx_cc_item_t *item = NULL; apr_hash_index_t *idx; const char *key; apr_ssize_t keylen; ctx = nx_ctx_get(); CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex)); for ( idx = apr_hash_first(NULL, ctx->config_cache); idx != NULL; idx = apr_hash_next(idx) ) { apr_hash_this(idx, (const void **) &key, &keylen, (void **) &item); apr_hash_set(ctx->config_cache, item->key, APR_HASH_KEY_STRING, NULL); _free_item(item); } if ( ctx->ccfile != NULL ) { apr_file_close(ctx->ccfile); ctx->ccfile = NULL; } CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); }
void MarcPostDB::node_vector(int indexN,int indexV,PyVector *pVec) { GETFUNC(m_pFile,"node_vector",Func_NodeVector,"**ERROR** Function node_vector() not found"); PyObject *pParam = Py_BuildValue("(i,i)",indexN,indexV); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_NodeVector],pParam); CHECKERR(); PyObject *val = PyObject_GetAttrString(ret,"id"); pVec->id = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"x"); *(pVec->val)= PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"y"); *(pVec->val+1)= PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"z"); *(pVec->val+2)= PyFloat_AsDouble(val); Py_DECREF(val); Py_DECREF(ret); Py_DECREF(pParam); }
int MarcPostDB::element_scalar(int indexE,int indexS,PyScalar **ppScalar) { GETFUNC(m_pFile,"element_scalar",Func_ElementScalar,"**ERROR** Function element_scalar() not found"); PyObject *pParam = Py_BuildValue("(i,i)",indexE,indexS); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_ElementScalar],pParam); CHECKERR(); int len = 0; if (PyList_Check(ret)) { len = PyList_Size(ret); PyObject *item = 0; for (int i = 0; i < len; i++) { item = PyList_GetItem(ret,i); PyObject *val = PyObject_GetAttrString(item,"id"); m_oScalar[i].nId = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(item,"value"); m_oScalar[i].val = PyFloat_AsDouble(val); Py_DECREF(val); //Py_DECREF(item); } } Py_DECREF(ret); Py_DECREF(pParam); *ppScalar = m_oScalar; return len; }
int main() { int i; int err = 0; emsuinput_context* ctx = NULL; int keybits[] = { BTN_LEFT, }; int relbits[] = { REL_X, REL_Y, }; ctx = emsuinput_new_context("fakemouse", keybits, 1, relbits, 2); if (ctx == NULL) { exit(-1); } for (i = 0; i < 100; i++) { err = emsuinput_send_rel_xy(ctx, 10, 10); CHECKERR(err); usleep(10 * 1000); } /* err = emsuinput_send_rel_xy(ctx, -3000, -3000); */ /* err = emsuinput_send_rel_xy(ctx, 640, 480); */ emsuinput_release_context(ctx); exit(0); }
void MarcPostDB::node(int index,PyNode *pNode) { GETFUNC(m_pFile,"node",Func_Node,"**ERROR** Function node() not found"); PyObject *pParam = Py_BuildValue("(i)",index); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_Node],pParam); CHECKERR(); PyObject *val = PyObject_GetAttrString(ret,"id"); pNode->id = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"x"); *(pNode->coord)= PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"y"); *(pNode->coord+1)= PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"z"); *(pNode->coord+2)= PyFloat_AsDouble(val); Py_DECREF(val); Py_DECREF(pParam); Py_DECREF(ret); }
CML_Error CML_NodeFindContainer(CML_Node * node, char * path, CML_Node ** result) { CHECKPTR(node ); CHECKPTR(result); char next[256]; char curr[256]; path_curr(path, curr); path_next(path, next); uint32_t index; CHECKERR(CML_NodeFindIndex(node, curr, &index)); if (next[0]) /* go deeper */ CHECKERR(CML_NodeFindContainer(node->nodes[index], next, result)) else /* stay here */ { if ((node->nodes[index]->type == CML_TYPE_ARRAY) || (node->nodes[index]->type == CML_TYPE_HASH)) *result = node->nodes[index]; else return CML_ERROR_USER_BADTYPE; } return CML_ERROR_SUCCESS; }
CML_Error CML_NodeFind(CML_Node * node, char * path, CML_Node ** result, CML_Type type) { CHECKPTR(node ); CHECKTYP(type ); CHECKPTR(result); char next[1024]; char curr[1024]; path_curr(path, curr); path_next(path, next); uint32_t index; CHECKERR(CML_NodeFindIndex(node, curr, &index)); if (next[0]) /* go deeper */ CHECKERR(CML_NodeFind(node->nodes[index], next, result, type)) else /* stay here */ { if (node->nodes[index]->type == type) *result = node->nodes[index]; else return CML_ERROR_USER_BADTYPE; } return CML_ERROR_SUCCESS; }
void MarcPostDB::moveto(int i) { GETFUNC(m_pFile,"moveto",Func_MoveTo,"**ERROR** Function moveto() not found"); PyObject *pParam = Py_BuildValue("(i)",i); PyEval_CallObject((PyObject *)m_pFunc[Func_MoveTo],pParam); CHECKERR(); Py_DECREF(pParam); }
int MarcPostDB::node_vectors() { GETFUNC(m_pFile,"node_vectors",Func_NodeVectors,"**ERROR** Function node_vectors() not found"); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_NodeVectors],NULL); CHECKERR(); int i = PyInt_AsLong(ret); Py_DECREF(ret); return i; }
int MarcPostDB::increments() { GETFUNC(m_pFile,"increments",Func_Increments,"**ERROR** Function increments() not found"); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_Increments],NULL); CHECKERR(); int i = PyInt_AsLong(ret); Py_DECREF(ret); return i; }
char* MarcPostDB::version() { GETFUNC(m_pMod,"version",Func_Version,"**ERROR** Function version() not found"); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_Version],NULL); CHECKERR(); strcpy_s(m_cStr,128,PyString_AsString(ret)); Py_DECREF(ret); return m_cStr; }
char* MarcPostDB::title() { GETFUNC(m_pFile,"title",Func_Title,"**ERROR** Function title() not found"); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_Title],NULL); CHECKERR(); strcpy_s(m_cStr,128,PyString_AsString(ret)); Py_DECREF(ret); return m_cStr; }
int CreateInitSockClient(HWND hwnd, SOCKET& sock, sockaddr_in sa, char *buf) { int i; char lineErr[256], buf2[128]; CHECKERR(sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP), FL_ERR_SOCKET); CHECKERR(i = WSAAsyncSelect (sock, hwnd, WM_FLY_TASKS, FD_CONNECT | FD_WRITE | FD_READ | FD_CLOSE ), FL_ERR_WSAAYNC); i=connect (sock, (SOCKADDR *)&sa, sizeof(sa)); if (i==-1) { if (WSAGetLastError()!=WSAEWOULDBLOCK) { sprintf(buf, "code=%d", i); MessageBox (NULL, buf, "Error in connect", MB_OK); } } _beginthreadex (NULL, 0, ConnectingThread, (void*)sock, 0, &connectThreadID); return i; }
int MarcPostDB::element_tensors() { GETFUNC(m_pFile,"element_tensors",Func_ElementTensors,"**ERROR** Function element_tensors() not found"); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_ElementTensors],NULL); CHECKERR(); int i = PyInt_AsLong(ret); Py_DECREF(ret); return i; }
void initCL() { FILE *kernelFile; char *kernelSource; size_t kernelLength; cl_int errcode; ocd_options opts = ocd_get_options(); platform_id = opts.platform_id; device_id = opts.device_id; clDevice = GetDevice(platform_id, device_id); size_t max_worksize[3]; errcode = clGetDeviceInfo(clDevice, CL_DEVICE_MAX_WORK_ITEM_SIZES,sizeof(size_t)*3, &max_worksize, NULL); CHECKERR(errcode); while(num_threads_perdim*num_threads_perdim>max_worksize[0]) num_threads_perdim = num_threads_perdim/2; num_threads = num_threads_perdim*num_threads_perdim; clContext = clCreateContext(NULL, 1, &clDevice, NULL, NULL, &errcode); CHECKERR(errcode); clCommands = clCreateCommandQueue(clContext, clDevice, CL_QUEUE_PROFILING_ENABLE, &errcode); CHECKERR(errcode); kernelFile = fopen("kmeans_opencl_kernel.cl", "r"); fseek(kernelFile, 0, SEEK_END); kernelLength = (size_t) ftell(kernelFile); kernelSource = (char *) malloc(sizeof(char)*kernelLength); rewind(kernelFile); fread((void *) kernelSource, kernelLength, 1, kernelFile); fclose(kernelFile); clProgram = clCreateProgramWithSource(clContext, 1, (const char **) &kernelSource, &kernelLength, &errcode); CHECKERR(errcode); free(kernelSource); errcode = clBuildProgram(clProgram, 1, &clDevice, NULL, NULL, NULL); if (errcode == CL_BUILD_PROGRAM_FAILURE) { char *log; size_t logLength; errcode = clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLength); log = (char *) malloc(sizeof(char)*logLength); errcode = clGetProgramBuildInfo(clProgram, clDevice, CL_PROGRAM_BUILD_LOG, logLength, (void *) log, NULL); fprintf(stderr, "Kernel build error! Log:\n%s", log); free(log); return; } CHECKERR(errcode); clKernel_invert_mapping = clCreateKernel(clProgram, "invert_mapping", &errcode); CHECKERR(errcode); clKernel_kmeansPoint = clCreateKernel(clProgram, "kmeansPoint", &errcode); CHECKERR(errcode); }
static void _update_item(nx_cc_item_t *item) { nx_ctx_t *ctx; apr_off_t offs; nx_exception_t e; ASSERT(item->value != NULL); ctx = nx_ctx_get(); CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex)); try { if ( ctx->ccfile == NULL ) { CHECKERR_MSG(apr_file_open(&(ctx->ccfile), ctx->ccfilename, APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE, APR_OS_DEFAULT, ctx->pool), "couldn't open config cache '%s' for writing", ctx->ccfilename); } // only integers are supported for now, string modifications trigger a whole rewrite if ( (item->offs > 0) && (item->value->type == NX_VALUE_TYPE_INTEGER) ) { offs = item->offs; CHECKERR_MSG(apr_file_seek(ctx->ccfile, APR_SET, &offs), "failed to seek in %s file", ctx->ccfilename); CHECKERR_MSG(nx_value_to_file(item->value, ctx->ccfile), "failed to update config cache item"); } else { // write the whole file, not very efficient nx_config_cache_write(); } item->needflush = FALSE; } catch(e) { CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); rethrow(e); } CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); }
void nx_config_cache_set_string(const char *module, const char *key, const char *value) { nx_ctx_t *ctx; nx_cc_item_t *item; char ckey[NX_CONFIG_CACHE_MAX_KEYLEN]; ASSERT(module != NULL); ASSERT(key != NULL); ASSERT(value != NULL); ctx = nx_ctx_get(); if ( apr_snprintf(ckey, sizeof(ckey), "%s/%s", module, key) == sizeof(ckey) ) { nx_panic("config cache key too long, limit is %d bytes", NX_CONFIG_CACHE_MAX_KEYLEN); } CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex)); item = (nx_cc_item_t *) apr_hash_get(ctx->config_cache, ckey, APR_HASH_KEY_STRING); CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); if ( item != NULL ) { ASSERT(item->value->type == NX_VALUE_TYPE_STRING); nx_value_free(item->value); item->value = nx_value_new_string(value); item->used = TRUE; item->needflush = TRUE; } else { item = malloc(sizeof(nx_cc_item_t)); memset(item, 0, sizeof(nx_cc_item_t)); item->key = strdup(ckey); item->value = nx_value_new_string(value); item->used = TRUE; item->needflush = TRUE; CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex)); apr_hash_set(ctx->config_cache, item->key, APR_HASH_KEY_STRING, (void *) item); CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex)); } }
int MarcPostDB::element_id(int index) { GETFUNC(m_pFile,"element_id",Func_ElementId,"**ERROR** Function element_id() not found"); PyObject *pParam = Py_BuildValue("(i)",index); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_ElementId],pParam); CHECKERR(); int i = PyInt_AsLong(ret); Py_DECREF(ret); Py_DECREF(pParam); return i; }
double MarcPostDB::node_scalar(int indexN,int indexS) { GETFUNC(m_pFile,"node_scalar",Func_NodeScalar,"**ERROR** Function node_scalar() not found"); PyObject *pParam = Py_BuildValue("(i,i)",indexN,indexS); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_NodeScalar],pParam); CHECKERR(); double d = PyFloat_AsDouble(ret); Py_DECREF(ret); Py_DECREF(pParam); return d; }
char* MarcPostDB::element_tensor_label(int index) { GETFUNC(m_pFile,"element_tensor_label",Func_ElementTensorLabel,"**ERROR** Function element_tensor_label() not found"); PyObject *pParam = Py_BuildValue("(i)",index); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_ElementTensorLabel],pParam); CHECKERR(); strcpy_s(m_cStr,128,PyString_AsString(ret)); Py_DECREF(ret); Py_DECREF(pParam); return m_cStr; }
void MarcPostDB::element(int index,PyElement *pElement) { GETFUNC(m_pFile,"element",Func_Element,"**ERROR** Function element() not found"); PyObject *pParam = Py_BuildValue("(i)",index); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_Element],pParam); CHECKERR(); PyObject *val = PyObject_GetAttrString(ret,"id"); pElement->id = PyInt_AsLong(val); Py_DECREF(val); CHECKERR(); val = PyObject_GetAttrString(ret,"type"); pElement->elemType = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"len"); pElement->nodeCnt = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(ret,"items"); if (PyList_Check(val)) { int len = PyList_Size(val); PyObject *item = 0; for (int i = 0; i < len; i++) { item = PyList_GetItem(val,i); pElement->nodeId[i] = PyInt_AsLong(item); //Py_DECREF(item); } } Py_DECREF(val); CHECKERR(); Py_DECREF(ret); Py_DECREF(pParam); }
bool MarcPostDB::open(char *fname) { GETFUNC(m_pMod,"post_open",Func_PostOpen,"**ERROR** Function post_open() not found"); PyObject *pParam = Py_BuildValue("(s)",fname); m_pFile = (void *)PyEval_CallObject((PyObject *)m_pFunc[Func_PostOpen],pParam); CHECKERR(); Py_DECREF(pParam); if (m_pFile == 0) { printf("%s\n","**ERROR** DB open failed"); return false; } return true; }
apr_pool_t *nx_pool_create_core() { apr_pool_t *pool; apr_allocator_t *allocator; apr_thread_mutex_t *mutex; CHECKERR(apr_allocator_create(&allocator)); #ifdef HAVE_APR_POOL_CREATE_UNMANAGED_EX // older apr does not have this CHECKERR(apr_pool_create_unmanaged_ex(&pool, &abort_func, allocator)); #else CHECKERR(apr_pool_create_ex(&pool, NULL, &abort_func, allocator)); #endif allocator = apr_pool_allocator_get(pool); apr_allocator_owner_set(allocator, pool); ASSERT(allocator != NULL); apr_allocator_max_free_set(allocator, NX_MAX_ALLOCATOR_SIZE); CHECKERR(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool)); apr_allocator_mutex_set(allocator, mutex); return ( pool ); }
char* get_pvars_name_list() { int num, i; char *name; char *class_name; int bind,vc,verbos,ro,ct,at; MPI_Datatype dt; MPI_T_enum et; int namelen, desclen; int total_length_of_pvar_names; char fname[105]; char fdesc[105]; int index; /* Get number of variables */ MPI_T_pvar_get_num(&num); /* Find string sizes */ total_length_of_pvar_names = 0; for (i = 0; i<num; i++) { int namelen = 0; int desclen = 0; MPI_T_pvar_get_info(i,fname,&namelen,&verbos,&vc,&dt,&et,fdesc,&desclen,&bind,&ro,&ct,&at); total_length_of_pvar_names += namelen; } /* Allocate string buffers */ name = (char*)malloc(sizeof(char)* (total_length_of_pvar_names + num * 8 /*strlen(:CLASS_NAME)*/ + num /*delimiter*/ + 1)); CHECKERR("Malloc Name",(name==NULL)); index = 0; for (i = 0; i < num; i++) { namelen = 0; desclen = 0; MPI_T_pvar_get_info(i,fname,&namelen,&verbos,&vc,&dt,&et,fdesc,&desclen,&bind,&ro,&ct,&at); memcpy((name + index), fname, namelen); index += namelen; memcpy((name + index), ":", 1); index += 1; class_name = get_pvar_class(vc); memcpy((name+index), class_name, strlen(class_name)); index += strlen(class_name); memcpy((name + index), ";", 1); index += 1; } name[index] = 0; return name; }
apr_pool_t *nx_pool_create_child(apr_pool_t *parent) { apr_pool_t *pool; apr_allocator_t *allocator; CHECKERR(apr_pool_create_ex(&pool, parent, &abort_func, NULL)); if ( parent == NULL ) { allocator = apr_pool_allocator_get(pool); ASSERT(allocator != NULL); apr_allocator_max_free_set(allocator, NX_MAX_ALLOCATOR_SIZE); } return ( pool ); }
MarcPostDB::MarcPostDB():m_pFile(0),m_pMod(0) { for(int i = 0; i < FuncCount; i++) { m_pFunc[i] = 0; } //Py_SetPythonHome(); Py_Initialize(); if (!Py_IsInitialized()) { printf("%s/n","**ERROR** Python initialize failed"); } m_pMod = (void *)PyImport_ImportModule("py_post"); CHECKERR(); if (m_pMod == 0) { printf("%s\n","**ERROR** Module import failed"); } }
int MarcPostDB::element_vector(int indexE,int indexV,PyVector **ppVector) { GETFUNC(m_pFile,"element_vector",Func_ElementVector,"**ERROR** Function element_vector() not found"); PyObject *pParam = Py_BuildValue("(i,i)",indexE,indexV); PyObject * ret = PyEval_CallObject((PyObject *)m_pFunc[Func_ElementVector],pParam); CHECKERR(); int len = 0; if (PyList_Check(ret)) { len = PyList_Size(ret); PyObject *item = 0; for (int i = 0; i < len; i++) { item = PyList_GetItem(ret,i); PyObject *val = PyObject_GetAttrString(item,"id"); m_oVector[i].id = PyInt_AsLong(val); Py_DECREF(val); val = PyObject_GetAttrString(item,"x"); m_oVector[i].val[0] = PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(item,"y"); m_oVector[i].val[1] = PyFloat_AsDouble(val); Py_DECREF(val); val = PyObject_GetAttrString(item,"z"); m_oVector[i].val[2] = PyFloat_AsDouble(val); Py_DECREF(val); //Py_DECREF(item); } } Py_DECREF(ret); Py_DECREF(pParam); *ppVector = m_oVector; return len; }
// MT : this is a compatibility routine to do stuff that used to be done in the cfm initialiser of rezlib static Handle LoadDITL() { //Load the dialog item list for our AskIfNewResolutionWorks() function dialog box static Handle s_ditl=NULL; if (!s_ditl) { //Load our DITL s_ditl = Get1Resource( 'DITL', 27398 ); if( s_ditl ) { DEBUGMESSAGE( "\"AskIfNewResolutionWorks\" DITL loaded." ); DetachResource( s_ditl ); } else DEBUGMESSAGE( "Error: Failed to load DITL." ); OSStatus err = ResError(); CHECKERR( err ); if( err ) DEBUGMESSAGE( "Found Resource Manager error # " << err << " after attempting to load the \"AskIfNewResolutionWorks\" DITL. " ); } return s_ditl; }
static ALCenum oss_open_capture(ALCdevice *device, const ALCchar *deviceName) { int numFragmentsLogSize; int log2FragmentSize; unsigned int periods; audio_buf_info info; ALuint frameSize; int numChannels; oss_data *data; int ossFormat; int ossSpeed; char *err; if(!deviceName) deviceName = oss_device; else if(strcmp(deviceName, oss_device) != 0) return ALC_INVALID_VALUE; data = (oss_data*)calloc(1, sizeof(oss_data)); data->killNow = 0; data->fd = open(oss_capture, O_RDONLY); if(data->fd == -1) { free(data); ERR("Could not open %s: %s\n", oss_capture, strerror(errno)); return ALC_INVALID_VALUE; } switch(device->FmtType) { case DevFmtByte: ossFormat = AFMT_S8; break; case DevFmtUByte: ossFormat = AFMT_U8; break; case DevFmtShort: ossFormat = AFMT_S16_NE; break; case DevFmtUShort: case DevFmtInt: case DevFmtUInt: case DevFmtFloat: free(data); ERR("%s capture samples not supported\n", DevFmtTypeString(device->FmtType)); return ALC_INVALID_VALUE; } periods = 4; numChannels = ChannelsFromDevFmt(device->FmtChans); frameSize = numChannels * BytesFromDevFmt(device->FmtType); ossSpeed = device->Frequency; log2FragmentSize = log2i(device->UpdateSize * device->NumUpdates * frameSize / periods); /* according to the OSS spec, 16 bytes are the minimum */ if (log2FragmentSize < 4) log2FragmentSize = 4; numFragmentsLogSize = (periods << 16) | log2FragmentSize; #define CHECKERR(func) if((func) < 0) { \ err = #func; \ goto err; \ } CHECKERR(ioctl(data->fd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize)); CHECKERR(ioctl(data->fd, SNDCTL_DSP_SETFMT, &ossFormat)); CHECKERR(ioctl(data->fd, SNDCTL_DSP_CHANNELS, &numChannels)); CHECKERR(ioctl(data->fd, SNDCTL_DSP_SPEED, &ossSpeed)); CHECKERR(ioctl(data->fd, SNDCTL_DSP_GETISPACE, &info)); if(0) { err: ERR("%s failed: %s\n", err, strerror(errno)); close(data->fd); free(data); return ALC_INVALID_VALUE; } #undef CHECKERR if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels) { ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(device->FmtChans), numChannels); close(data->fd); free(data); return ALC_INVALID_VALUE; } if(!((ossFormat == AFMT_S8 && device->FmtType == DevFmtByte) || (ossFormat == AFMT_U8 && device->FmtType == DevFmtUByte) || (ossFormat == AFMT_S16_NE && device->FmtType == DevFmtShort))) { ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(device->FmtType), ossFormat); close(data->fd); free(data); return ALC_INVALID_VALUE; } data->ring = CreateRingBuffer(frameSize, device->UpdateSize * device->NumUpdates); if(!data->ring) { ERR("Ring buffer create failed\n"); close(data->fd); free(data); return ALC_OUT_OF_MEMORY; } data->data_size = info.fragsize; data->mix_data = calloc(1, data->data_size); device->ExtraData = data; data->thread = StartThread(OSSCaptureProc, device); if(data->thread == NULL) { device->ExtraData = NULL; free(data->mix_data); free(data); return ALC_OUT_OF_MEMORY; } device->szDeviceName = strdup(deviceName); return ALC_NO_ERROR; }