AudioFakeHardware::~AudioFakeHardware() { if (mFd >=0) :: close(mFd); closeOutputStream((AudioStreamOut *)mOutput); closeInputStream((AudioStreamIn *)mInput); }
TinyAudioHardware::~TinyAudioHardware() { closeOutputStream((AudioStreamOut *)mOutput); closeInputStream((AudioStreamIn *)mInput); if (mMixer) mixer_close(mMixer); }
AudioHardware::~AudioHardware() { for (size_t index = 0; index < mInputs.size(); index++) { closeInputStream((AudioStreamIn*)mInputs[index]); } mInputs.clear(); closeOutputStream((AudioStreamOut*)mOutput); delete [] mSndEndpoints; mInit = false; }
void PlayAudioEngine::restartStream(){ LOGI("Restarting stream"); if (restartingLock_.try_lock()){ closeOutputStream(); createPlaybackStream(); restartingLock_.unlock(); } else { LOGW("Restart stream operation already in progress - ignoring this request"); // We were unable to obtain the restarting lock which means the restart operation is currently // active. This is probably because we received successive "stream disconnected" events. // Internal issue b/63087953 } }
AudioHardwareOutput::~AudioHardwareOutput() { closeOutputStream(mMainOutput); closeOutputStream(mMCOutput); }
PlayAudioEngine::~PlayAudioEngine(){ closeOutputStream(); delete sineOscLeft_; delete sineOscRight_; }
AudioHardwareGeneric::~AudioHardwareGeneric() { if (mFd >= 0) ::close(mFd); closeOutputStream((AudioStreamOut *)mOutput); closeInputStream((AudioStreamIn *)mInput); }
A2dpAudioInterface::~A2dpAudioInterface() { closeOutputStream((AudioStreamOut *)mOutput); delete mHardwareInterface; }
OsStatus MpAudioDriverManager::setCurrentOutputDevice(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 output device return closeOutputStream(); } else if (device.compareTo("Default", UtlString::ignoreCase) == 0) { MpAudioDeviceIndex defaultOutputDeviceIndex; // we want to set default output device OsStatus res = m_pAudioDriver->getDefaultOutputDevice(defaultOutputDeviceIndex); if (res != OS_SUCCESS) { return OS_FAILED; } if (defaultOutputDeviceIndex != m_outputDeviceIndex) { // we want to change active output device // first close current stream closeOutputStream(); MpAudioStreamParameters outputParameters; outputParameters.setChannelCount(1); outputParameters.setSampleFormat(MP_AUDIO_FORMAT_INT16); outputParameters.setSuggestedLatency(m_initialOutputStreamLatency); outputParameters.setDeviceIndex(defaultOutputDeviceIndex); // open output stream res = m_pAudioDriver->openStream(&m_outputAudioStream, NULL, &outputParameters, MpMisc.m_audioSamplesPerSec, MpMisc.m_audioSamplesPerFrame, MP_AUDIO_STREAM_DITHEROFF, TRUE); if (res != OS_SUCCESS) { return OS_FAILED; } res = m_pAudioDriver->startStream(m_outputAudioStream); if (res != OS_SUCCESS) { return OS_FAILED; } m_outputDeviceIndex = defaultOutputDeviceIndex; m_outputAudioMixer = m_pAudioDriver->getMixerForStream(m_outputAudioStream, OUTPUT_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.getMaxOutputChannels() > 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.getMaxOutputChannels() > 0) { // we found match, we will select this device bDeviceFound = TRUE; hostApiName = deviceInfo.getHostApiName(); break; } } } if (bDeviceFound && i != m_outputDeviceIndex) { // we found a matching device // first close current stream closeOutputStream(); MpAudioStreamParameters outputParameters; outputParameters.setChannelCount(1); outputParameters.setSampleFormat(MP_AUDIO_FORMAT_INT16); outputParameters.setSuggestedLatency(m_initialOutputStreamLatency); outputParameters.setDeviceIndex(i); // open output stream res = m_pAudioDriver->openStream(&m_outputAudioStream, NULL, &outputParameters, 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_outputAudioStream); if (res != OS_SUCCESS) { return OS_FAILED; } m_outputDeviceIndex = i; m_outputAudioMixer = m_pAudioDriver->getMixerForStream(m_outputAudioStream, OUTPUT_MIXER_INDEX); return OS_SUCCESS; } // Selecting a device that is already selected is not a failure if(bDeviceFound && i == m_outputDeviceIndex) { return OS_SUCCESS; } } } return OS_FAILED; }