int GSkipBaseDevice::OSClearMeasurementPacketQueue() { int nReturn = 0; if (LockDevice(1) && IsOKToUse()) { nReturn = local_ClearPacketQueue(this, kMeasurementPipe); UnlockDevice(); } else GSTD_ASSERT(0); return nReturn; }
int GSkipBaseDevice::OSClearCmdRespPacketQueue() { int nReturn = 0; if (LockDevice(1) && IsOKToUse()) { nReturn = local_ClearPacketQueue(this, kCommandPipe); UnlockDevice(); } else GSTD_ASSERT(0); return nReturn; }
int GSkipBaseDevice::OSReadCmdRespPackets(void * pBuffer, int * pIONumPackets, int nBufferSizeInPackets) { int nReturn = 0; if (LockDevice(1) && IsOKToUse()) { nReturn = local_ReadPackets(this, pBuffer, pIONumPackets, nBufferSizeInPackets, kCommandPipe); UnlockDevice(); } else GSTD_ASSERT(0); return nReturn; }
int GSkipBaseDevice::OSCmdRespPacketsAvailable(void) { int nReturn = 0; if (LockDevice(1) && IsOKToUse()) { nReturn = local_PacketsAvailable(this, kCommandPipe); UnlockDevice(); } else GSTD_ASSERT(0); return nReturn; }
int GSkipBaseDevice::OSClose(void) { if (LockDevice(1) && IsOKToUse()) { TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData()); if ((usbDevice != NULL) && IsOpen()) VST_CloseUSBPort((VST_USBBulkDevice *)usbDevice); UnlockDevice(); } else GSTD_ASSERT(0); return kResponse_OK; }
void GSkipBaseDevice::OSDestroy(void) { if (LockDevice(1) && IsOKToUse()) { TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData()); if (usbDevice != NULL) { VST_CloseUSBPort((VST_USBBulkDevice *)usbDevice); VST_ReleaseUSBBulkDevice((VST_USBBulkDevice *)usbDevice); } UnlockDevice(); } else GSTD_ASSERT(0); }
int GSkipBaseDevice::OSMeasurementPacketsAvailable(unsigned char *pNumMeasurementsInLastPacket) { int nReturn = 0; if (LockDevice(1) && IsOKToUse()) { nReturn = local_PacketsAvailable(this, kMeasurementPipe); if (pNumMeasurementsInLastPacket != NULL) *pNumMeasurementsInLastPacket = local_NumLastMeasurements(this); UnlockDevice(); } else GSTD_ASSERT(0); return nReturn; }
int GSkipBaseDevice::OSClearIO(void) { int nResult = kResponse_Error; if (LockDevice(1) && IsOKToUse()) { nResult = OSClearMeasurementPacketQueue(); if (nResult != kResponse_Error) nResult = GSkipBaseDevice::OSClearCmdRespPacketQueue(); UnlockDevice(); } else GSTD_ASSERT(0); return nResult; }
static void stream_buffer_attr_callback(pa_stream *stream, void *pdata) //{{{ { ALCdevice *Device = pdata; pulse_data *data = Device->ExtraData; LockDevice(Device); data->attr = *(pa_stream_get_buffer_attr(stream)); Device->UpdateSize = data->attr.minreq / data->frame_size; Device->NumUpdates = (data->attr.tlength/data->frame_size) / Device->UpdateSize; if(Device->NumUpdates <= 1) { Device->NumUpdates = 1; ERR("PulseAudio returned minreq > tlength/2; expect lag or break up\n"); } UnlockDevice(Device); }//}}}
int GSkipBaseDevice::OSOpen(GPortRef * /*pPortRef*/) { int nResult = kResponse_Error; if (LockDevice(1) && IsOKToUse()) { TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData()); // port may be NULL if initialization failed if (usbDevice == NULL) return kResponse_Error; int err = VST_OpenUSBPortForIO((VST_USBBulkDevice *)usbDevice); if (err == (int)kCFM_IOExclusiveAccess) { // If another app (including Classic) has the device we // can simply retry a few times. The driver should be able to get a lock // on the device at some point. int nTry = 0; while ((err == (int)kCFM_IOExclusiveAccess) && (nTry < 4)) { err = VST_OpenUSBPortForIO((VST_USBBulkDevice *)usbDevice); nTry++; } } if (err == 0) nResult = kResponse_OK; else { cppsstream ssErr; ssErr << "GUSBDirectTempDevice:OSOpen -- Error: " << err; GSTD_LOG(ssErr.str()); } UnlockDevice(); } else GSTD_ASSERT(0); return nResult; }
int GSkipBaseDevice::OSWriteCmdPackets(void * pBuffer, int nNumPackets) { int nResult = kResponse_Error; UInt32 nIONumBytes = nNumPackets * sizeof(GSkipPacket); if (LockDevice(1) && IsOKToUse()) { TUSBBulkDevice usbDevice = static_cast<TUSBBulkDevice>(GetOSData()); if (usbDevice != NULL) { int err = VST_WriteBytes((VST_USBBulkDevice *)usbDevice, pBuffer, nIONumBytes); if (err == 0) nResult = kResponse_OK; } UnlockDevice(); } else GSTD_ASSERT(0); return nResult; }
long GSkipDevice::SendInitCmdAndGetResponse( void *pParams, //[in] ptr to cmd specific parameter block, may be NULL. long nParamBytes, //[in] # of bytes in (*pParams). void *pRespBuf, //[out] ptr to destination buffer, may be NULL. long *pnRespBytes, //[in, out] size of of dest buffer on input, size of response on output, may be NULL if pRespBuf is NULL. long nTimeoutMs /* = 1000 */,//[in] # of milliseconds to wait before giving up. bool *pExitFlag /* = NULL */)//[in] ptr to flag that another thread can set to force early exit. // THIS FLAG MUST BE FALSE FOR THIS ROUTINE TO RUN. // Ignore this if NULL. { long nResult = kResponse_Error; unsigned char initStatus; long initStatusLength = sizeof(initStatus); if (LockDevice(1) && IsOKToUse()) { nResult = kResponse_OK; long maxNumRetries = (nTimeoutMs + SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS - 1)/SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS; if (maxNumRetries > 1) nTimeoutMs = SKIP_TIMEOUT_MS_CMD_ID_INIT_WITH_BUSY_STATUS; bool bSuccess = false; long numRetries; GSkipInitParams initParams; initParams.reportErrorWhilePoweringUpFlag = 1; if (pParams) GSTD_ASSERT(nParamBytes == sizeof(initParams)); else { pParams = &initParams; nParamBytes = sizeof(initParams); } //Send multiple init commands until the timeout is reached because Skip may ignore commands sent before it is done //powering up. for (numRetries = 0; (numRetries < maxNumRetries) && (kResponse_OK == nResult) && (!bSuccess); numRetries++) { nResult = SendCmd(SKIP_CMD_ID_INIT, pParams, nParamBytes); if (kResponse_OK == nResult) { unsigned int nTimeCmdSent = GUtils::OSGetTimeStamp(); initStatusLength = sizeof(initStatus); initStatus = SKIP_STATUS_CMD_NOT_SUPPORTED; if (kResponse_OK == GetInitCmdResponse(&initStatus, &initStatusLength, nTimeoutMs, pExitFlag)) bSuccess = true; else if ((sizeof(initStatus) == initStatusLength) && (SKIP_STATUS_ERROR_SLAVE_POWERUP_INIT == initStatus)) { unsigned int nTimeNow = GUtils::OSGetTimeStamp(); unsigned int nElapsedTimeMs = nTimeNow - nTimeCmdSent; if (nElapsedTimeMs < nTimeoutMs) GUtils::Sleep(nTimeoutMs - nElapsedTimeMs); } } else initStatusLength = 0; } if (!bSuccess) nResult = kResponse_Error; UnlockDevice(); } else GSTD_ASSERT(0); // Can't use this device -- some other thread has it open! if (pRespBuf && pnRespBytes) { if (((*pnRespBytes) >= initStatusLength) && (initStatusLength > 0)) { (*pnRespBytes) = initStatusLength; memcpy(pRespBuf, &initStatus, initStatusLength); } else (*pnRespBytes) = 0; } return nResult; }
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectState *State = NULL; ALenum err = AL_NO_ERROR; LockDevice(Device); if(newtype == AL_EFFECT_NULL && EffectSlot->effect.type != AL_EFFECT_NULL) { State = NoneCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_EAXREVERB || newtype == AL_EFFECT_REVERB) { if(EffectSlot->effect.type != AL_EFFECT_EAXREVERB && EffectSlot->effect.type != AL_EFFECT_REVERB) { State = ReverbCreate(); if(!State) err = AL_OUT_OF_MEMORY; } } else if(newtype == AL_EFFECT_ECHO && EffectSlot->effect.type != AL_EFFECT_ECHO) { State = EchoCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_RING_MODULATOR && EffectSlot->effect.type != AL_EFFECT_RING_MODULATOR) { State = ModulatorCreate(); if(!State) err = AL_OUT_OF_MEMORY; } else if(newtype == AL_EFFECT_DEDICATED_DIALOGUE || newtype == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) { if(EffectSlot->effect.type != AL_EFFECT_DEDICATED_DIALOGUE && EffectSlot->effect.type != AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) { State = DedicatedCreate(); if(!State) err = AL_OUT_OF_MEMORY; } } if(err != AL_NO_ERROR) { UnlockDevice(Device); return err; } if(State) { int oldMode; oldMode = SetMixerFPUMode(); if(ALeffectState_DeviceUpdate(State, Device) == AL_FALSE) { RestoreFPUMode(oldMode); UnlockDevice(Device); ALeffectState_Destroy(State); return AL_OUT_OF_MEMORY; } State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); if(!effect) memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); else memcpy(&EffectSlot->effect, effect, sizeof(*effect)); /* FIXME: This should be done asynchronously, but since the EffectState * object was changed, it needs an update before its Process method can * be called. */ EffectSlot->NeedsUpdate = AL_FALSE; ALeffectState_Update(EffectSlot->EffectState, Device, EffectSlot); UnlockDevice(Device); RestoreFPUMode(oldMode); ALeffectState_Destroy(State); State = NULL; } else { if(!effect) memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); else memcpy(&EffectSlot->effect, effect, sizeof(*effect)); UnlockDevice(Device); EffectSlot->NeedsUpdate = AL_TRUE; } return AL_NO_ERROR; }