FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) ) : Control::Container() , m_pConfigRom( configRom ) , m_pDeviceManager( d ) { addOption(Util::OptionContainer::Option("id",std::string("dev?"))); std::ostringstream nodestr; nodestr << "node" << getConfigRom().getNodeId(); if (!addElement(&getConfigRom())) { debugWarning("failed to add ConfigRom to Control::Container\n"); } m_genericContainer = new Control::Container("Generic"); if(m_genericContainer == NULL) { debugError("Could not create Control::Container for generic controls\n"); } else { if (!addElement(m_genericContainer)) { debugWarning("failed to add generic container to Control::Container\n"); } // add a generic control for the clock source selection if(!m_genericContainer->addElement(new Control::ClockSelect(*this))) { debugWarning("failed to add clock source control to container\n"); } } }
bool CycleTimerHelper::Start() { debugOutput( DEBUG_LEVEL_VERBOSE, "Start %p...\n", this); if(!initValues()) { debugFatal("(%p) Could not init values\n", this); return false; } m_Thread = new Util::PosixThread(this, "CTRHLP", m_realtime, m_priority, PTHREAD_CANCEL_DEFERRED); if(!m_Thread) { debugFatal("No thread\n"); return false; } // register the thread with the RT watchdog Util::Watchdog *watchdog = m_Parent.getWatchdog(); if(watchdog) { if(!watchdog->registerThread(m_Thread)) { debugWarning("could not register update thread with watchdog\n"); } } else { debugWarning("could not find valid watchdog\n"); } if (m_Thread->Start() != 0) { debugFatal("Could not start update thread\n"); return false; } return true; }
bool AutoExposure::init(cl_context context, cl_device_id device, QSize computeSize, int updatePeriod) { assert(!_initialized); _updatePeriod= updatePeriod; _lumaSize= computeSize; // Compile kernel and set arguments CLUtils::KernelDefines downDefines; downDefines["GAMMA_CORRECT"]= "2.2f"; _downKernel= CLUtils::loadKernelPath(context, device, ":/kernels/lumaDownsample.cl", "lumaDownsample", downDefines, QStringList("../res/kernels/")); if(!_downKernel) { debugWarning("Could not compile kernel."); return false; } _lumaData= (uchar*)malloc(lumaDataBytes()); if(!_lumaData) { debugWarning("Could not allocate data."); return false; } cl_int error; // This image could be WRITE_ONLY _lumaImage= clCreateImage2D(context, CL_MEM_READ_WRITE, clFormatGL(GL_R), _lumaSize.width(), _lumaSize.height(), 0, 0, &error); if(clCheckError(error, "clCreateImage2D")) { free(_lumaData); return false; } _initialized= true; return true; }
bool Configuration::openFile(std::string filename, enum eFileMode mode) { // check if not already open if(findFileName(filename) >= 0) { debugError("file already open\n"); return false; } ConfigFile *c = new ConfigFile(*this, filename, mode); switch(mode) { case eFM_ReadOnly: case eFM_ReadWrite: try { c->readFile(); } catch (FileIOException& e) { debugOutput(DEBUG_LEVEL_VERBOSE, "Could not open file: %s\n", filename.c_str()); delete c; return false; } catch (ParseException& e) { debugWarning("Could not parse file: %s\n", filename.c_str()); delete c; return false; } catch (...) { debugWarning("Unknown exception when opening file: %s\n", filename.c_str()); delete c; return false; } break; default: break; } m_ConfigFiles.push_back(c); return true; }
bool RmeTransmitStreamProcessor::transmitSilenceBlock(char *data, unsigned int nevents, unsigned int offset) { // This is the same as the non-silence version, except that is // doesn't read from the port buffers. bool no_problem = true; for ( PortVectorIterator it = m_Ports.begin(); it != m_Ports.end(); ++it ) { Port *port=(*it); switch(port->getPortType()) { case Port::E_Audio: if (encodeSilencePortToRmeEvents(static_cast<RmeAudioPort *>(*it), (quadlet_t *)data, offset, nevents)) { debugWarning("Could not encode port %s to MBLA events\n",(*it)->getName().c_str()); no_problem = false; } break; case Port::E_Midi: if (encodeSilencePortToRmeMidiEvents(static_cast<RmeMidiPort *>(*it), (quadlet_t *)data, offset, nevents)) { debugWarning("Could not encode port %s to Midi events\n",(*it)->getName().c_str()); no_problem = false; } break; default: // ignore break; } } return no_problem; }
void PosixMutex::Lock() { int err; debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) lock\n", m_id.c_str(), this); #if DEBUG_LOCK_COLLISION_TRACING if(TryLock()) { // locking succeeded m_locked_by = debugBacktraceGet( DEBUG_LOCK_COLLISION_TRACING_INDEX ); char name[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ]; name[0] = 0; debugGetFunctionNameFromAddr(m_locked_by, name, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN); debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) %s obtained lock\n", m_id.c_str(), this, name); return; } else { void *lock_try_by = debugBacktraceGet( DEBUG_LOCK_COLLISION_TRACING_INDEX ); char name1[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ]; name1[0] = 0; debugGetFunctionNameFromAddr(lock_try_by, name1, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN); char name2[ DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN ]; name2[0] = 0; debugGetFunctionNameFromAddr(m_locked_by, name2, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN); debugWarning("(%s, %p) lock collision: %s wants lock, %s has lock\n", m_id.c_str(), this, name1, name2); if((err = pthread_mutex_lock(&m_mutex))) { if (err == EDEADLK) { debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this); debugPrintBacktrace(10); } else { debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err); } } else { debugWarning("(%s, %p) lock collision: %s got lock (from %s?)\n", m_id.c_str(), this, name1, name2); } } #else #ifdef DEBUG if((err = pthread_mutex_lock(&m_mutex))) { if (err == EDEADLK) { debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this); debugPrintBacktrace(10); } else { debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err); } } #else pthread_mutex_lock(&m_mutex); #endif #endif }
bool Device::addDirPorts(enum Streaming::Port::E_Direction direction) { const char *mode_str = direction==Streaming::Port::E_Capture?"cap":"pbk"; Streaming::StreamProcessor *s_processor; std::string id; char name[128]; // This method (in conjunction with addPort()) illustrates the port // creation process. if (direction == Streaming::Port::E_Capture) { s_processor = m_receiveProcessor; } else { s_processor = m_transmitProcessor; } id = std::string("dev?"); if (!getOption("id", id)) { debugWarning("Could not retrieve id parameter, defaulting to 'dev?'\n"); } // Add two ports for an example snprintf(name, sizeof(name), "%s_%s_%s", id.c_str(), mode_str, "port_0"); addPort(s_processor, name, direction, 0, 0); snprintf(name, sizeof(name), "%s_%s_%s", id.c_str(), mode_str, "port_1"); addPort(s_processor, name, direction, 4, 0); return true; }
// helpers bool SlaveDevice::waitForRegisterNotEqualTo(nodeaddr_t offset, fb_quadlet_t v) { debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for StreamProcessor streams to start running...\n"); // we have to wait until all streamprocessors indicate that they are running // i.e. that there is actually some data stream flowing int timeoutSecs=120; if(!getOption("isoTimeoutSecs", timeoutSecs)) { debugWarning("Could not retrieve isoTimeoutSecs parameter, defauling to 120secs\n"); } int wait_cycles=timeoutSecs*10; // two seconds fb_quadlet_t reg=v; while ((v == reg) && wait_cycles) { wait_cycles--; if (!readReg(offset,®)) { debugError("Could not read register\n"); return false; } SleepRelativeUsec(100000); } if(!wait_cycles) { // timout has occurred return false; } return true; }
libconfig::Setting * Configuration::getDeviceSetting( unsigned int vendor_id, unsigned model_id ) { for ( std::vector<ConfigFile *>::iterator it = m_ConfigFiles.begin(); it != m_ConfigFiles.end(); ++it ) { ConfigFile *c = *it; try { Setting &list = c->lookup("device_definitions"); unsigned int children = list.getLength(); for(unsigned int i = 0; i < children; i++) { Setting &s = list[i]; try { Setting &vendorid = s["vendorid"]; Setting &modelid = s["modelid"]; uint32_t vid = vendorid; uint32_t mid = modelid; if (vendor_id == vid && model_id == mid) { debugOutput(DEBUG_LEVEL_VERBOSE, " device VME for %X:%x found in %s\n", vendor_id, model_id, c->getName().c_str()); c->showSetting(s); return &s; } } catch (...) { debugWarning("Bogus format\n"); } } } catch (...) { debugOutput(DEBUG_LEVEL_VERBOSE, " %s has no device definitions\n", c->getName().c_str()); } } return NULL; }
bool Device::setFeatureFBLRBalanceCurrent(int id, int channel, int v) { FunctionBlockCmd fbCmd( get1394Service(), FunctionBlockCmd::eFBT_Feature, id, FunctionBlockCmd::eCA_Current ); fbCmd.setNodeId( getNodeId() ); fbCmd.setSubunitId( 0x00 ); fbCmd.setCommandType( AVCCommand::eCT_Control ); fbCmd.m_pFBFeature->m_audioChannelNumber = channel; fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_LRBalance; AVC::FunctionBlockFeatureLRBalance bl; fbCmd.m_pFBFeature->m_pLRBalance = bl.clone(); fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = v; fbCmd.setVerboseLevel( getDebugLevel() ); if ( !fbCmd.fire() ) { debugError( "cmd failed\n" ); return false; } // if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) { // Util::Cmd::CoutSerializer se; // fbCmd.serialize( se ); // } if((fbCmd.getResponse() != AVCCommand::eR_Accepted)) { debugWarning("fbCmd.getResponse() != AVCCommand::eR_Accepted\n"); } return (fbCmd.getResponse() == AVCCommand::eR_Accepted); }
bool Container::addElement(Element *e) { if (e==NULL) { debugWarning("Cannot add NULL element\n"); return false; } debugOutput( DEBUG_LEVEL_VERBOSE, "Adding Element %s to %s\n", e->getName().c_str(), getName().c_str()); // don't allow duplicates, only makes life hard for ( ElementVectorIterator it = m_Children.begin(); it != m_Children.end(); ++it ) { if(*it == e) { debugOutput( DEBUG_LEVEL_VERBOSE, "Not adding Element %s, already present\n", e->getName().c_str()); return false; } } m_Children.push_back(e); return true; }
int Device::getProcessingFBMixerSingleCurrent(int id, int iPlugNum, int iAChNum, int oAChNum) { AVC::FunctionBlockCmd fbCmd(get1394Service(), AVC::FunctionBlockCmd::eFBT_Processing, id, AVC::FunctionBlockCmd::eCA_Current); fbCmd.setNodeId(getNodeId()); fbCmd.setSubunitId(0x00); fbCmd.setCommandType(AVCCommand::eCT_Status); fbCmd.setVerboseLevel( getDebugLevel() ); AVC::FunctionBlockProcessing *fbp = fbCmd.m_pFBProcessing; fbp->m_selectorLength = 0x04; fbp->m_fbInputPlugNumber = iPlugNum; fbp->m_inputAudioChannelNumber = iAChNum; fbp->m_outputAudioChannelNumber = oAChNum; // mixer object is not generated automatically fbp->m_pMixer = new AVC::FunctionBlockProcessingMixer; if ( !fbCmd.fire() ) { debugError( "cmd failed\n" ); return 0; } if( (fbCmd.getResponse() != AVCCommand::eR_Implemented) ) { debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n"); } int16_t setting = (int16_t)(fbp->m_pMixer->m_mixerSetting); return setting; }
int Device::getFeatureFBLRBalanceValue(int id, int channel, FunctionBlockCmd::EControlAttribute controlAttribute) { FunctionBlockCmd fbCmd( get1394Service(), FunctionBlockCmd::eFBT_Feature, id, controlAttribute); fbCmd.setNodeId( getNodeId() ); fbCmd.setSubunitId( 0x00 ); fbCmd.setCommandType( AVCCommand::eCT_Status ); fbCmd.m_pFBFeature->m_audioChannelNumber = channel; fbCmd.m_pFBFeature->m_controlSelector = FunctionBlockFeature::eCSE_Feature_LRBalance; AVC::FunctionBlockFeatureLRBalance bl; fbCmd.m_pFBFeature->m_pLRBalance = bl.clone(); fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance = 0; fbCmd.setVerboseLevel( getDebugLevel() ); if ( !fbCmd.fire() ) { debugError( "cmd failed\n" ); return 0; } // if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) { // Util::Cmd::CoutSerializer se; // fbCmd.serialize( se ); // } if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) { debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n"); } int16_t balance=(int16_t)(fbCmd.m_pFBFeature->m_pLRBalance->m_lrBalance); return balance; }
int Device::getSelectorFBValue(int id) { FunctionBlockCmd fbCmd( get1394Service(), FunctionBlockCmd::eFBT_Selector, id, FunctionBlockCmd::eCA_Current ); fbCmd.setNodeId( getNodeId() ); fbCmd.setSubunitId( 0x00 ); fbCmd.setCommandType( AVCCommand::eCT_Status ); fbCmd.m_pFBSelector->m_inputFbPlugNumber = 0xFF; fbCmd.setVerboseLevel( getDebugLevel() ); if ( !fbCmd.fire() ) { debugError( "cmd failed\n" ); return -1; } // if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) { // Util::Cmd::CoutSerializer se; // fbCmd.serialize( se ); // } if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) { debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n"); } return fbCmd.m_pFBSelector->m_inputFbPlugNumber; }
/** * Verify a PIN code. * * @param buffer which contains the code to verify. */ int CHV_PIN_verify(CHV_PIN *pin, unsigned int length, unsigned char *buffer) { // Verify if the PIN has not been blocked if (pin->count == 0) { return CHV_BLOCKED; } // Check length of the provided data if (length > 0) { if (length != CHV_PIN_SIZE) { return CHV_WRONG_LENGTH; } else { // Compare the PIN with the stored code if (NotEqual(CHV_PIN_SIZE, buffer, pin->code)) { debugWarning("PIN verification failed"); debugInteger("Tries left", pin->count - 1); --(pin->count); CHV_flags &= (0xFF ^ pin->flag); } else { debugMessage("PIN verified"); pin->count = CHV_PIN_COUNT; CHV_flags |= pin->flag; } } } return CHV_PIN_query(pin); }
bool FocusriteDevice::getSpecificValue(uint32_t id, uint32_t *v) { bool retval; bool use_avc = false; if(!getOption("useAvcForParameters", use_avc)) { debugWarning("Could not retrieve useAvcForParameters parameter, defaulting to false\n"); } // rate control ffado_microsecs_t now = Util::SystemTimeSource::getCurrentTimeAsUsecs(); if(m_cmd_time_interval && (m_earliest_next_cmd_time > now)) { ffado_microsecs_t wait = m_earliest_next_cmd_time - now; debugOutput( DEBUG_LEVEL_VERBOSE, "Rate control... %"PRIu64"\n", wait ); Util::SystemTimeSource::SleepUsecRelative(wait); } m_earliest_next_cmd_time = now + m_cmd_time_interval; // execute if (use_avc) { retval = getSpecificValueAvc(id, v); } else { retval = getSpecificValueARM(id, v); } debugOutput(DEBUG_LEVEL_VERBOSE,"Read parameter address space id 0x%08X (%u): %08X\n", id, id, *v); return retval; }
bool Profire2626::Profire2626EAP::writeApplicationReg(unsigned offset, quadlet_t quadlet) { bool ret = writeReg(Dice::EAP::eRT_Application, offset, quadlet); if (!ret) { debugWarning("Couldn't write %i to register %x!\n", quadlet, offset); return false; } return ret; }
/* * call with lock held */ bool CycleTimerHelper::initDLL() { uint32_t cycle_timer; uint64_t local_time; double bw_rel = m_dll_coeff_b / (DLL_SQRT2 * DLL_2PI); double bw_abs = bw_rel / (m_usecs_per_update / 1e6); if (bw_rel > 0.5) { double bw_max = 0.5 / (m_usecs_per_update / 1e6); debugWarning("Specified DLL bandwidth too high (%f > %f), reducing to max." " Increase the DLL update rate to increase the max DLL bandwidth\n", bw_abs, bw_max); bw_rel = 0.49; bw_abs = bw_rel / (m_usecs_per_update / 1e6); m_dll_coeff_b = bw_rel * (DLL_SQRT2 * DLL_2PI); m_dll_coeff_c = bw_rel * bw_rel * DLL_2PI * DLL_2PI; } if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { debugError("Could not read cycle timer register\n"); return false; } #if DEBUG_EXTREME_ENABLE uint64_t cycle_timer_ticks = CYCLE_TIMER_TO_TICKS(cycle_timer); #endif debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " read : CTR: %11u, local: %17" PRIu64 "\n", cycle_timer, local_time); debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, " ctr : 0x%08X %11" PRIu64 " (%03us %04ucy %04uticks)\n", (uint32_t)cycle_timer, (uint64_t)cycle_timer_ticks, (unsigned int)TICKS_TO_SECS( (uint64_t)cycle_timer_ticks ), (unsigned int)TICKS_TO_CYCLES( (uint64_t)cycle_timer_ticks ), (unsigned int)TICKS_TO_OFFSET( (uint64_t)cycle_timer_ticks ) ); m_sleep_until = local_time + m_usecs_per_update; m_dll_e2 = m_ticks_per_update; m_current_time_usecs = local_time; m_next_time_usecs = m_current_time_usecs + m_usecs_per_update; m_current_time_ticks = CYCLE_TIMER_TO_TICKS( cycle_timer ); m_next_time_ticks = addTicks( (uint64_t)m_current_time_ticks, (uint64_t)m_dll_e2); debugOutput(DEBUG_LEVEL_VERBOSE, " (%p) First run\n", this); debugOutput(DEBUG_LEVEL_VERBOSE, " DLL bandwidth: %f Hz (rel: %f)\n", bw_abs, bw_rel); debugOutput(DEBUG_LEVEL_VERBOSE, " usecs/update: %u, ticks/update: %u, m_dll_e2: %f\n", m_usecs_per_update, m_ticks_per_update, m_dll_e2); debugOutput(DEBUG_LEVEL_VERBOSE, " usecs current: %f, next: %f\n", m_current_time_usecs, m_next_time_usecs); debugOutput(DEBUG_LEVEL_VERBOSE, " ticks current: %f, next: %f\n", m_current_time_ticks, m_next_time_ticks); return true; }
bool Watchdog::start() { debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Starting watchdog...\n", this); debugOutput( DEBUG_LEVEL_VERBOSE, "Create hartbeat task/thread for %p...\n", this); m_HartbeatTask = new WatchdogHartbeatTask( *this, m_check_interval/2 ); if(!m_HartbeatTask) { debugFatal("No hartbeat task\n"); return false; } m_HartbeatThread = new Util::PosixThread(m_HartbeatTask, "WDGHBT", false, 0, PTHREAD_CANCEL_ASYNCHRONOUS); if(!m_HartbeatThread) { debugFatal("No hartbeat thread\n"); return false; } debugOutput( DEBUG_LEVEL_VERBOSE, " hartbeat task: %p, thread %p...\n", m_HartbeatTask, m_HartbeatThread); debugOutput( DEBUG_LEVEL_VERBOSE, "Create check task/thread for %p...\n", this); m_CheckTask = new WatchdogCheckTask( *this, m_check_interval ); if(!m_CheckTask) { debugFatal("No check task\n"); return false; } m_CheckThread = new Util::PosixThread(m_CheckTask,"WDGCHK", false, 0, PTHREAD_CANCEL_ASYNCHRONOUS); if(!m_CheckThread) { debugFatal("No check thread\n"); return false; } debugOutput( DEBUG_LEVEL_VERBOSE, " check task: %p, thread %p...\n", m_CheckTask, m_CheckThread); // switch to realtime if necessary if(m_realtime) { if(!m_CheckThread->AcquireRealTime(m_priority)) { debugWarning("(%p) Could not aquire realtime priotiry for watchdog thread.\n", this); } } // start threads if (m_HartbeatThread->Start() != 0) { debugFatal("Could not start hartbeat thread\n"); return false; } if (m_CheckThread->Start() != 0) { debugFatal("Could not start check thread\n"); return false; } debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Watchdog running...\n", this); return true; }
bool Device::discover() { unsigned int vendorId = getConfigRom().getNodeVendorId(); unsigned int modelId = getConfigRom().getModelId(); Util::Configuration &c = getDeviceManager().getConfiguration(); Util::Configuration::VendorModelEntry vme = c.findDeviceVME( vendorId, modelId ); if (c.isValid(vme) && vme.driver == Util::Configuration::eD_BeBoB) { debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", vme.vendor_name.c_str(), vme.model_name.c_str()); } else { debugWarning("Using generic BeBoB support for unsupported device '%s %s'\n", getConfigRom().getVendorName().c_str(), getConfigRom().getModelName().c_str()); } if ( !Unit::discover() ) { debugError( "Could not discover unit\n" ); return false; } if((getAudioSubunit( 0 ) == NULL)) { debugError( "Unit doesn't have an Audio subunit.\n"); return false; } if((getMusicSubunit( 0 ) == NULL)) { debugError( "Unit doesn't have a Music subunit.\n"); return false; } if(!buildMixer()) { debugWarning("Could not build mixer\n"); } // keep track of the config id of this discovery m_last_discovery_config_id = getConfigurationId(); return true; }
Streaming::StreamProcessor * Device::getStreamProcessorByIndex(int i) { switch (i) { case 0: return m_receiveProcessor; case 1: return m_transmitProcessor; default: debugWarning("Invalid stream index %d\n", i); } return NULL; }
uint32_t CycleTimerHelper::getCycleTimer(uint64_t now) { uint32_t ticks = getCycleTimerTicks(now); uint32_t result = TICKS_TO_CYCLE_TIMER(ticks); #ifdef DEBUG if(CYCLE_TIMER_TO_TICKS(result) != ticks) { debugWarning("Bad ctr conversion"); } #endif return result; }
Streaming::StreamProcessor * Device::getStreamProcessorByIndex(int i) { // A housekeeping method. This should not need to be changed. switch (i) { case 0: return m_receiveProcessor; case 1: return m_transmitProcessor; default: debugWarning("Invalid stream index %d\n", i); } return NULL; }
int RmeTransmitStreamProcessor::encodePortToRmeMidiEvents( RmeMidiPort *p, quadlet_t *data, unsigned int offset, unsigned int nevents) { unsigned int j; quadlet_t *src = (quadlet_t *)p->getBufferAddress(); src += offset; unsigned char *target = (unsigned char *)data + p->getPosition(); // Send a MIDI byte if there is one to send. RME MIDI data is sent using // a 3-byte sequence within a frame starting at the port's position. // A non-zero MSB indicates there is MIDI data to send. for (j=0; j<nevents; j++, src++, target+=m_event_size) { if (midi_lock) midi_lock--; /* FFADO's MIDI subsystem dictates that at the most there will be one * MIDI byte every 8th's sample, making a MIDI byte "unlikely". */ if (unlikely(*src & 0xff000000)) { /* A MIDI byte is ready to send - buffer it */ midibuffer[mb_head++] = *src; mb_head &= MIDIBUFFER_SIZE-1; if (unlikely(mb_head == mb_tail)) { /* Buffer overflow - dump oldest byte. */ /* Ideally this would dump an entire MIDI message, but this is only * feasible if it's possible to determine the message size easily. */ mb_tail = (mb_tail+1) & (MIDIBUFFER_SIZE-1); debugWarning("RME MIDI buffer overflow\n"); } debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Buffered MIDI byte %d\n", *src & 0xff); } /* Send the MIDI byte at the tail of the buffer if enough time has elapsed * since the last MIDI byte was sent. For most iterations through the loop * this condition will be false. */ if (unlikely(mb_head!=mb_tail && !midi_lock)) { *(target) = 0x01; *(target+1) = 0x00; *(target+2) = midibuffer[mb_tail] & 0xff; debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Sent MIDI byte %d (j=%d)\n", midibuffer[mb_tail], j); mb_tail = (mb_tail+1) & (MIDIBUFFER_SIZE-1); midi_lock = midi_tx_period; } } return 0; }
/** * PKCS #1 PSS verification */ static int PSS_verify(unsigned int message_bytes, const unsigned char *message, unsigned int encoded_bytes, const unsigned char *encoded) { unsigned char M[8 + RSA_SHA_BYTES + RSA_SALT_BYTES]; unsigned char DB[RSA_MOD_BYTES - RSA_SHA_BYTES - 1]; debugValue("PSS verify: message", message, message_bytes); if (encoded_bytes != RSA_MOD_BYTES) { return RSA_ERROR_PSS_INCONSISTENT; } debugValue("PSS verify: encoded message", encoded, encoded_bytes); // Verification if (encoded[RSA_MOD_BYTES - 1] != 0xbc) { return RSA_ERROR_PSS_INCONSISTENT; } // Extract maskedDB and H debugValue("PSS verify: maskedDB", encoded, RSA_MOD_BYTES - RSA_SHA_BYTES - 1); Copy(RSA_SHA_BYTES, M + 8, encoded + RSA_MOD_BYTES - RSA_SHA_BYTES - 1); debugValue("PSS verify: H", encoded + RSA_MOD_BYTES - RSA_SHA_BYTES - 1, RSA_SHA_BYTES); // Compute DB MGF1(RSA_SHA_BYTES, M + 8, RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB); debugValue("PSS verify: dbMask", DB, RSA_MOD_BYTES - RSA_SHA_BYTES - 1); XorAssign(RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB, encoded); debugValue("PSS verify: DB", DB, RSA_MOD_BYTES - RSA_SHA_BYTES - 1); if (DB[RSA_MOD_BYTES - RSA_SALT_BYTES - RSA_SHA_BYTES - 2] != 0x01) { return RSA_ERROR_PSS_INCONSISTENT; } // Compute hash of m SHA(RSA_SHA_BYTES, M + 8, message_bytes, message); debugValue("PSS verify: hash of message", M + 8, RSA_SHA_BYTES); Copy(RSA_SALT_BYTES, M + 8 + RSA_SHA_BYTES, DB + RSA_MOD_BYTES - RSA_SALT_BYTES - RSA_SHA_BYTES - 1); debugValue("PSS verify: recovered message to be encoded", M, 8 + RSA_SHA_BYTES + RSA_SALT_BYTES); SHA(RSA_SHA_BYTES, DB, 8 + RSA_SHA_BYTES + RSA_SALT_BYTES, M); debugValue("PSS verify: hash of recovered message to be encoded", DB, RSA_SHA_BYTES); if (NotEqual(RSA_SHA_BYTES, encoded + RSA_MOD_BYTES - RSA_SHA_BYTES - 1, DB)) { debugWarning("PSS verify: verification failed"); return RSA_ERROR_PSS_INCONSISTENT; } debugMessage("PSS verify: verification succeeded"); return RSA_PSS_CONSISTENT; }
bool Device::discover() { unsigned int vendorId = getConfigRom().getNodeVendorId(); unsigned int modelId = getConfigRom().getModelId(); Util::Configuration &c = getDeviceManager().getConfiguration(); Util::Configuration::VendorModelEntry vme = c.findDeviceVME( vendorId, modelId ); if (c.isValid(vme) && vme.driver == Util::Configuration::eD_Digidesign) { debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", vme.vendor_name.c_str(), vme.model_name.c_str()); } else { debugWarning("Device '%s %s' unsupported by Digidesign driver (no generic Digidesign support)\n", getConfigRom().getVendorName().c_str(), getConfigRom().getModelName().c_str()); } // Here you work out what m_digidesign_model should be set to and // set it accordingly. This can then be used by the rest of the driver // whenever one needs to do different things for different interfaces. // // m_digidesign_model = DIGIDESIGN_MODEL_... // // This function should return true if the device is a supported device // or false if not. Presently only the 003 Rack is supported. if (m_digidesign_model != DIGIDESIGN_MODEL_003_RACK) { debugError("Unsupported model\n"); return false; } if (!buildMixer()) { debugWarning("Could not build mixer\n"); } return true; }
/* * compose the event streams for the packets from the port buffers */ bool RmeTransmitStreamProcessor::processWriteBlock(char *data, unsigned int nevents, unsigned int offset) { bool no_problem=true; for ( PortVectorIterator it = m_Ports.begin(); it != m_Ports.end(); ++it ) { // If this port is disabled, unconditionally send it silence. if((*it)->isDisabled()) { if (encodeSilencePortToRmeEvents(static_cast<RmeAudioPort *>(*it), (quadlet_t *)data, offset, nevents)) { debugWarning("Could not encode silence for disabled port %s to Rme events\n",(*it)->getName().c_str()); // Don't treat this as a fatal error at this point } continue; } Port *port=(*it); switch(port->getPortType()) { case Port::E_Audio: if (encodePortToRmeEvents(static_cast<RmeAudioPort *>(*it), (quadlet_t *)data, offset, nevents)) { debugWarning("Could not encode port %s to Rme events\n",(*it)->getName().c_str()); no_problem=false; } break; case Port::E_Midi: if (encodePortToRmeMidiEvents(static_cast<RmeMidiPort *>(*it), (quadlet_t *)data, offset, nevents)) { debugWarning("Could not encode port %s to Midi events\n",(*it)->getName().c_str()); no_problem=false; } break; default: // ignore break; } } return no_problem; }
int FocusriteDevice::convertDefToSr( uint32_t def ) { switch(def) { case FOCUSRITE_CMD_SAMPLERATE_44K1: return 44100; case FOCUSRITE_CMD_SAMPLERATE_48K: return 48000; case FOCUSRITE_CMD_SAMPLERATE_88K2: return 88200; case FOCUSRITE_CMD_SAMPLERATE_96K: return 96000; case FOCUSRITE_CMD_SAMPLERATE_176K4: return 176400; case FOCUSRITE_CMD_SAMPLERATE_192K: return 192000; default: debugWarning("Unsupported samplerate def: %08X\n", def); return 0; } }
uint32_t FocusriteDevice::convertSrToDef( int sr ) { switch(sr) { case 44100: return FOCUSRITE_CMD_SAMPLERATE_44K1; case 48000: return FOCUSRITE_CMD_SAMPLERATE_48K; case 88200: return FOCUSRITE_CMD_SAMPLERATE_88K2; case 96000: return FOCUSRITE_CMD_SAMPLERATE_96K; case 176400: return FOCUSRITE_CMD_SAMPLERATE_176K4; case 192000: return FOCUSRITE_CMD_SAMPLERATE_192K; default: debugWarning("Unsupported samplerate: %d\n", sr); return 0; } }
uint32_t CycleTimerHelper::getCycleTimerTicks(uint64_t now) { debugWarning("untested code\n"); #warning Untested code uint32_t cycle_timer; uint64_t local_time; readCycleTimerWithRetry(&cycle_timer, &local_time, 10); int64_t ticks = CYCLE_TIMER_TO_TICKS(cycle_timer); int delta_t = now - local_time; // how far ahead is the request? ticks += delta_t * getRate(); // add ticks if (ticks >= TICKS_PER_SECOND * 128) ticks -= TICKS_PER_SECOND * 128; else if (ticks < 0) ticks += TICKS_PER_SECOND * 128; return ticks; }