int scan(char *fileName) { Token *token; if (openInputStream(fileName) == IO_ERROR) return IO_ERROR; token = getToken(); while (token->tokenType != TK_EOF) { printToken(token); free(token); token = getToken(); } free(token); closeInputStream(); return IO_SUCCESS; }
int compile(char *fileName) { if (openInputStream(fileName) == IO_ERROR) return IO_ERROR; currentToken = NULL; lookAhead = getValidToken(); initSymTab(); compileProgram(); cleanSymTab(); free(currentToken); free(lookAhead); closeInputStream(); return IO_SUCCESS; }
void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) { int ret; InputStream inStream; InputPlugin * plugin = NULL; char * path; if(isRemoteUrl(pc->utf8url)) { path = utf8StrToLatin1Dup(pc->utf8url); } else path = strdup(rmp2amp(utf8ToFsCharset(pc->utf8url))); if(!path) { dc->error = DECODE_ERROR_FILE; dc->state = DECODE_STATE_STOP; dc->start = 0; return; } copyMpdTagToOutputBuffer(cb, NULL); strncpy(dc->utf8url, pc->utf8url, MAXPATHLEN); dc->utf8url[MAXPATHLEN] = '\0'; if(openInputStream(&inStream, path) < 0) { dc->error = DECODE_ERROR_FILE; dc->state = DECODE_STATE_STOP; dc->start = 0; free(path); return; } dc->seekable = inStream.seekable; dc->state = DECODE_STATE_START; dc->start = 0; while(!inputStreamAtEOF(&inStream) && bufferInputStream(&inStream) < 0 && !dc->stop) { /* sleep so we don't consume 100% of the cpu */ // fprintf(stderr,"In decode.c decodeParent decode start func\r\n"); // my_usleep(1000); } if(dc->stop) { dc->state = DECODE_STATE_STOP; dc->stop = 0; free(path); return; } /*if(inStream.metaName) { MpdTag * tag = newMpdTag(); tag->name = strdup(inStream.metaName); copyMpdTagToOutputBuffer(cb, tag); freeMpdTag(tag); }*/ /* reset Metadata in OutputBuffer */ ret = DECODE_ERROR_UNKTYPE; if(isRemoteUrl(dc->utf8url)) { cb->acceptMetadata = 1; plugin = getInputPluginFromMimeType(inStream.mime); if(plugin == NULL) { plugin = getInputPluginFromSuffix( getSuffix(dc->utf8url)); } /* this is needed for bastard streams that don't have a suffix or set the mimeType */ if(plugin == NULL) { plugin = getInputPluginFromName("mp3"); } if(plugin && (plugin->streamTypes & INPUT_PLUGIN_STREAM_URL) && plugin->streamDecodeFunc) { ret = plugin->streamDecodeFunc(cb, dc, &inStream); } } else { cb->acceptMetadata = 0; plugin = getInputPluginFromSuffix(getSuffix(dc->utf8url)); if(plugin && (plugin->streamTypes && INPUT_PLUGIN_STREAM_FILE)) { if(plugin->streamDecodeFunc) { ret = plugin->streamDecodeFunc(cb, dc, &inStream); } else if(plugin->fileDecodeFunc) { closeInputStream(&inStream); ret = plugin->fileDecodeFunc(cb, dc, path); } } } if(ret<0 || ret == DECODE_ERROR_UNKTYPE) { strncpy(pc->erroredUrl, dc->utf8url, MAXPATHLEN); pc->erroredUrl[MAXPATHLEN] = '\0'; if(ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE; else { dc->error = DECODE_ERROR_UNKTYPE; closeInputStream(&inStream); } dc->stop = 0; dc->state = DECODE_STATE_STOP; } free(path); }
AudioHardwareGeneric::~AudioHardwareGeneric() { if (mFd >= 0) ::close(mFd); closeOutputStream((AudioStreamOut *)mOutput); closeInputStream((AudioStreamIn *)mInput); }
OsStatus MpAudioDriverManager::setCurrentInputDevice(const UtlString& device, const UtlString& driverName) { OsLock lock(ms_mutex); if (m_pAudioDriver) { if (device.compareTo("None", UtlString::ignoreCase) == 0) { // we want to disable current input device return closeInputStream(); } else if (device.compareTo("Default", UtlString::ignoreCase) == 0) { MpAudioDeviceIndex defaultInputDeviceIndex; // we want to set default input device OsStatus res = m_pAudioDriver->getDefaultInputDevice(defaultInputDeviceIndex); if (res != OS_SUCCESS) { return OS_FAILED; } if (defaultInputDeviceIndex != m_inputDeviceIndex) { // we want to change active input device // first close current stream closeInputStream(); MpAudioStreamParameters inputParameters; inputParameters.setChannelCount(1); inputParameters.setSampleFormat(MP_AUDIO_FORMAT_INT16); inputParameters.setSuggestedLatency(m_initialInputStreamLatency); inputParameters.setDeviceIndex(defaultInputDeviceIndex); // open asynchronous input stream res = m_pAudioDriver->openStream(&m_inputAudioStream, &inputParameters, NULL, MpMisc.m_audioSamplesPerSec, MpMisc.m_audioSamplesPerFrame, MP_AUDIO_STREAM_DITHEROFF, TRUE); if (res != OS_SUCCESS) { return OS_FAILED; } res = m_pAudioDriver->startStream(m_inputAudioStream); if (res != OS_SUCCESS) { return OS_FAILED; } m_inputDeviceIndex = defaultInputDeviceIndex; m_inputAudioMixer = m_pAudioDriver->getMixerForStream(m_inputAudioStream, INPUT_MIXER_INDEX); return OS_SUCCESS; } else { // new and old device are the same, no need to change return OS_SUCCESS; } } else { // user wants to select a particular device OsStatus res = OS_FAILED; UtlBoolean bDeviceFound = FALSE; UtlBoolean bDriverReq = !driverName.isNull(); MpAudioDeviceIndex deviceCount = 0; MpAudioDeviceIndex i = 0; UtlString hostApiName; m_pAudioDriver->getDeviceCount(deviceCount); // loop through all devices, and find matching one for (i = 0; i < deviceCount; i++) { MpAudioDeviceInfo deviceInfo; m_pAudioDriver->getDeviceInfo(i, deviceInfo); if (!bDriverReq) { // driver match is not required, match by name only if (deviceInfo.getName().compareTo(device.data(), UtlString::matchCase) == 0 && deviceInfo.getMaxInputChannels() > 0) { // we found match, we will select this device bDeviceFound = TRUE; hostApiName = deviceInfo.getHostApiName(); break; } } else { // now try to match by driver name, device name if (deviceInfo.getName().compareTo(device.data(), UtlString::matchCase) == 0 && deviceInfo.getHostApiName().compareTo(driverName.data(), UtlString::matchCase) == 0 && deviceInfo.getMaxInputChannels() > 0) { // we found match, we will select this device bDeviceFound = TRUE; hostApiName = deviceInfo.getHostApiName(); break; } } } if (bDeviceFound && i != m_inputDeviceIndex) { // we found a matching device // first close current stream closeInputStream(); MpAudioStreamParameters inputParameters; inputParameters.setChannelCount(1); inputParameters.setSampleFormat(MP_AUDIO_FORMAT_INT16); inputParameters.setSuggestedLatency(m_initialInputStreamLatency); inputParameters.setDeviceIndex(i); // open asynchronous input stream res = m_pAudioDriver->openStream(&m_inputAudioStream, &inputParameters, NULL, MpMisc.m_audioSamplesPerSec, MpMisc.m_audioSamplesPerFrame, MP_AUDIO_STREAM_DITHEROFF, MpAudioDriverManager::useSynchronousStream(hostApiName)); if (res != OS_SUCCESS) { return OS_FAILED; } res = m_pAudioDriver->startStream(m_inputAudioStream); if (res != OS_SUCCESS) { return OS_FAILED; } m_inputDeviceIndex = i; m_inputAudioMixer = m_pAudioDriver->getMixerForStream(m_inputAudioStream, INPUT_MIXER_INDEX); return OS_SUCCESS; } // Selecting a device that is already selected is not a failure if(bDeviceFound && i == m_inputDeviceIndex) { return OS_SUCCESS; } } } return OS_FAILED; }