void SHP_PlugIn::Teardown() { // first figure out if this is being done as part of the process being torn down UInt32 isInitingOrExiting = 0; UInt32 theSize = sizeof(UInt32); AudioHardwareGetProperty(kAudioHardwarePropertyIsInitingOrExiting, &theSize, &isInitingOrExiting); // next figure out if this is the master process UInt32 isMaster = 0; theSize = sizeof(UInt32); AudioHardwareGetProperty(kAudioHardwarePropertyProcessIsMaster, &theSize, &isMaster); // do the full teardown if this is outside of the process being torn down or this is the master process if((isInitingOrExiting == 0) || (isMaster != 0)) { // stop all IO on the device mDevice->Do_StopAllIOProcs(); // send the necessary IsAlive notifications CAPropertyAddress theIsAliveAddress(kAudioDevicePropertyDeviceIsAlive); mDevice->PropertiesChanged(1, &theIsAliveAddress); // save it's settings if necessary if(isMaster != 0) { HP_DeviceSettings::SaveToPrefs(*mDevice, HP_DeviceSettings::sStandardControlsToSave, HP_DeviceSettings::kStandardNumberControlsToSave); } // tell the HAL that the device has gone away AudioObjectID theObjectID = mDevice->GetObjectID(); #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) OSStatus theError = AudioHardwareDevicesDied(GetInterface(), 1, &theObjectID); #else OSStatus theError = AudioObjectsPublishedAndDied(GetInterface(), kAudioObjectSystemObject, 0, NULL, 1, &theObjectID); #endif AssertNoError(theError, "SHP_PlugIn::Teardown: got an error telling the HAL a device died"); // remove the object state mutex HP_Object::SetObjectStateMutexForID(theObjectID, NULL); // toss it mDevice->Teardown(); delete mDevice; mDevice = NULL; // teardown the super class HP_HardwarePlugIn::Teardown(); } else { // otherwise, only stop the IOProcs mDevice->Do_StopAllIOProcs(); // finalize (rather than tear down) the devices mDevice->Finalize(); // and leave the rest to die with the process } }
OSStatus PA_Stream::PublishObjects(Boolean active) { std::vector<AudioStreamID> controlIDs; controlIDs.clear(); ReportOwnedObjects(controlIDs); if (controlIDs.size() != 0) if (active) { return AudioObjectsPublishedAndDied(plugin->GetInterface(), GetObjectID(), controlIDs.size(), &(controlIDs.front()), 0, NULL); } else { return AudioObjectsPublishedAndDied(plugin->GetInterface(), GetObjectID(), 0, NULL, controlIDs.size(), &(controlIDs.front())); } return kAudioHardwareNoError; }
void SHP_PlugIn::InitializeWithObjectID(AudioObjectID inObjectID) { // initialize the super class HP_HardwarePlugIn::InitializeWithObjectID(inObjectID); // instantiate a new AudioDevice object in the HAL AudioDeviceID theNewDeviceID = 0; #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) OSStatus theError = AudioHardwareClaimAudioDeviceID(GetInterface(), &theNewDeviceID); #else OSStatus theError = AudioObjectCreate(GetInterface(), kAudioObjectSystemObject, kAudioDeviceClassID, &theNewDeviceID); #endif ThrowIfError(theError, CAException(theError), "SHP_PlugIn::InitializeWithObjectID: couldn't instantiate the AudioDevice object"); // make a device object mDevice = new SHP_Device(theNewDeviceID, this); mDevice->Initialize(); // restore it's settings if necessary UInt32 isMaster = 0; UInt32 theSize = sizeof(UInt32); AudioHardwareGetProperty(kAudioHardwarePropertyProcessIsMaster, &theSize, &isMaster); if(isMaster != 0) { HP_DeviceSettings::RestoreFromPrefs(*mDevice, HP_DeviceSettings::sStandardControlsToSave, HP_DeviceSettings::kStandardNumberControlsToSave); } // set the object state mutex HP_Object::SetObjectStateMutexForID(theNewDeviceID, mDevice->GetObjectStateMutex()); // tell the HAL about the device #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4) theError = AudioHardwareDevicesCreated(GetInterface(), 1, &theNewDeviceID); #else theError = AudioObjectsPublishedAndDied(GetInterface(), kAudioObjectSystemObject, 1, &theNewDeviceID, 0, NULL); #endif AssertNoError(theError, "SHP_PlugIn::InitializeWithObjectID: got an error telling the HAL a device died"); }