Пример #1
0
extern "C" OSStatus	AudioDriverPlugInStreamGetProperty(AudioDeviceID inDevice, io_object_t inIOAudioStream, UInt32 inChannel, AudioDevicePropertyID inPropertyID, UInt32* ioPropertyDataSize, void* outPropertyData)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//	sanity check the arguments
		ThrowIfNULL(ioPropertyDataSize, CAException(kAudioHardwareIllegalOperationError), "AudioDriverPlugInDeviceGetProperty: ioPropertyDataSize is NULL");
		
		//	find the plug-in object for the device
		HP_DriverPlugIn* thePlugIn = HP_DriverPlugIn::GetPlugIn(inDevice);
		ThrowIfNULL(thePlugIn, CAException(kAudioHardwareBadDeviceError), "AudioDriverPlugInDeviceGetProperty: couldn't find the plug-in for the device");

		//	figure out if the stream has the given property
		if(thePlugIn->StreamHasProperty(inIOAudioStream, inChannel, inPropertyID))
		{
			//	let the plug-in do the work
			thePlugIn->StreamGetPropertyData(inIOAudioStream, inChannel, inPropertyID, *ioPropertyDataSize, outPropertyData);
		}
		else
		{
			theError = kAudioHardwareUnknownPropertyError;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock(AudioHardwarePlugInRef inSelf, AudioDeviceIOProcID* outIOProcID, AudioDeviceID inDeviceID, dispatch_queue_t inDispatchQueue, AudioDeviceIOBlock inBlock)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no plug-in");
		ThrowIf(inBlock == 0, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no IOBlock to add");
		ThrowIfNULL(outIOProcID, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: nowhere to put the return value");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no device with given ID");
		
		//	do the work
		*outIOProcID = theDevice->Do_CreateIOProcIDWithBlock(inDispatchQueue, inBlock);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_DeviceStop(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, AudioDeviceIOProc inProc)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceStop: no plug-in");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceStop: no device with given ID");
		
		//	do the work
		theDevice->Do_StopIOProc(inProc);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_DeviceTranslateTime(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, const AudioTimeStamp* inTime, AudioTimeStamp* outTime)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceTranslateTime: no plug-in");
		ThrowIfNULL(inTime, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceTranslateTime: no input time stamp");
		ThrowIfNULL(outTime, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceTranslateTime: no place for the return data");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceTranslateTime: no device with given ID");
		
		//	do the work
		theDevice->TranslateTime(*inTime, *outTime);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_DeviceGetNearestStartTime(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, AudioTimeStamp* ioRequestedStartTime, UInt32 inFlags)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetNearestStartTime: no plug-in");
		ThrowIfNULL(ioRequestedStartTime, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetNearestStartTime: no time stamp");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceGetNearestStartTime: no device with given ID");
		
		//	do the work
		theDevice->GetNearestStartTime(*ioRequestedStartTime, inFlags);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_DeviceGetPropertyInfo(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, UInt32* outSize, Boolean* outWritable)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no plug-in");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no device with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inDeviceID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theDevice = HP_Object::GetDeviceByID(inDeviceID);
			ThrowIfNULL(theDevice, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no device with given ID after locking");
		}
		
		//  construct a property address
		CAPropertyAddress theAddress(inPropertyID, isInput == 0 ? kAudioDevicePropertyScopeOutput : kAudioDevicePropertyScopeInput, inChannel);
		
		//	do the work
		ThrowIf(!theDevice->HasProperty(theAddress), CAException(kAudioHardwareUnknownPropertyError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no such property");
		if(outSize != NULL)
		{
			*outSize = theDevice->GetPropertyDataSize(theAddress, 0, NULL);
		}
		if(outWritable != NULL)
		{
			*outWritable = theDevice->IsPropertySettable(theAddress) ? 1 : 0;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_StreamGetPropertyInfo(AudioHardwarePlugInRef inSelf, AudioStreamID inStreamID, UInt32 inChannel, AudioDevicePropertyID inPropertyID, UInt32* outSize, Boolean* outWritable)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_StreamGetPropertyInfo: no plug-in");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inStreamID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
		}
		
		//  find the stream for the given ID
		HP_Stream* theStream = HP_Object::GetStreamByID(inStreamID);
		ThrowIfNULL(theStream, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_StreamGetPropertyInfo: no device with given ID after locking");
		
		//  construct a property address
		CAPropertyAddress theAddress(inPropertyID, kAudioObjectPropertyScopeGlobal, inChannel);
		
		//	do the work
		ThrowIf(!theStream->HasProperty(theAddress), CAException(kAudioHardwareUnknownPropertyError), "HP_HardwarePlugIn_StreamGetPropertyInfo: no such property");
		if(outSize != NULL)
		{
			*outSize = theStream->GetPropertyDataSize(theAddress, 0, NULL);
		}
		if(outWritable != NULL)
		{
			*outWritable = theStream->IsPropertySettable(theAddress) ? 1 : 0;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
static OSStatus	HP_HardwarePlugIn_StreamGetProperty(AudioHardwarePlugInRef inSelf, AudioStreamID inStreamID, UInt32 inChannel, AudioDevicePropertyID inPropertyID, UInt32* ioPropertyDataSize, void* outPropertyData)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_StreamGetProperty: no plug-in");
		ThrowIfNULL(ioPropertyDataSize, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_StreamGetProperty: no data size");
		
		//  find the stream for the given ID
		HP_Stream* theStream = HP_Object::GetStreamByID(inStreamID);
		ThrowIfNULL(theStream, CAException(kAudioHardwareBadStreamError), "HP_HardwarePlugIn_StreamGetProperty: no stream with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inStreamID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theStream = HP_Object::GetStreamByID(inStreamID);
			ThrowIfNULL(theStream, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_StreamGetProperty: no device with given ID after locking");
		}
		
		//  construct a property address
		CAPropertyAddress theAddress(inPropertyID, kAudioObjectPropertyScopeGlobal, inChannel);
		
		//	do the work
		theStream->GetPropertyData(theAddress, 0, NULL, *ioPropertyDataSize, outPropertyData);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
static HRESULT	HP_HardwarePlugIn_QueryInterface(AudioHardwarePlugInRef inSelf, REFIID inUUID, LPVOID* outInterface)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_QueryInterface: no plug-in");
		ThrowIfNULL(outInterface, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_QueryInterface: no place to store the return value");

		//	set the returned interface to NULL
		*outInterface = NULL;
		
		//	get the object out of the interface reference
		HP_HardwarePlugIn* thePlugIn = HP_HardwarePlugIn::GetObject(inSelf);
		
		// create a CoreFoundation UUIDRef for the requested interface.
		CACFUUID theInterfaceUUID(CFUUIDCreateFromUUIDBytes(NULL, inUUID));

		// test the requested ID against the valid interfaces.
#if	defined(kAudioHardwarePlugInInterface5ID)
		if(theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface5ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface4ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface3ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface2ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterfaceID) || theInterfaceUUID.IsEqual(IUnknownUUID))
#else
		if(theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface4ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface3ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterface2ID) || theInterfaceUUID.IsEqual(kAudioHardwarePlugInInterfaceID) || theInterfaceUUID.IsEqual(IUnknownUUID))
#endif
		{
			//	 it's one of the interfaces we understand
			
			//	retain the object on behalf of the caller
			thePlugIn->Retain();
			
			//	return the interface;
			*outInterface = thePlugIn->GetInterface();
		}
		else
		{
			//	not anything we understand
			theError = E_NOINTERFACE;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
Пример #10
0
static OSStatus HP_HardwarePlugIn_ObjectIsPropertySettable(AudioHardwarePlugInRef inSelf, AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, Boolean* outIsSettable)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectIsPropertySettable: no plug-in");
		ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectIsPropertySettable: no address");
		ThrowIfNULL(outIsSettable, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectIsPropertySettable: no place to store return value");
		
		//  find the object for the given ID
		HP_Object* theObject = HP_Object::GetObjectByID(inObjectID);
		ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectIsPropertySettable: no object with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inObjectID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theObject = HP_Object::GetObjectByID(inObjectID);
			ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectIsPropertySettable: no object with given ID after locking");
		}
		
		//	do the work
		*outIsSettable = theObject->IsPropertySettable(*inAddress);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
Пример #11
0
static OSStatus HP_HardwarePlugIn_ObjectGetPropertyData(AudioHardwarePlugInRef inSelf, AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* ioDataSize, void* outData)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectGetPropertyData: no plug-in");
		ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectGetPropertyData: no address");
		ThrowIfNULL(ioDataSize, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectGetPropertyData: no info about the size of the property data");
		
		//  find the object for the given ID
		HP_Object* theObject = HP_Object::GetObjectByID(inObjectID);
		ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectGetPropertyData: no object with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inObjectID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theObject = HP_Object::GetObjectByID(inObjectID);
			ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectGetPropertyData: no object with given ID after locking");
		}
		
		//	do the work
		theObject->GetPropertyData(*inAddress, inQualifierDataSize, inQualifierData, *ioDataSize, outData);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
Пример #12
0
static Boolean  HP_HardwarePlugIn_ObjectHasProperty(AudioHardwarePlugInRef inSelf, AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress)
{
	Boolean		theAnswer = false;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectHasProperty: no plug-in");
		ThrowIfNULL(inAddress, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectHasProperty: no address");
		
		//  find the object for the given ID
		HP_Object* theObject = HP_Object::GetObjectByID(inObjectID);
		ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectHasProperty: no object with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inObjectID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theObject = HP_Object::GetObjectByID(inObjectID);
			ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectHasProperty: no object with given ID after locking");
		}
		
		//	do the work
		theAnswer = theObject->HasProperty(*inAddress);
	}
	catch(const CAException& inException)
	{
		theAnswer = false;
	}
	catch(...)
	{
		theAnswer = false;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theAnswer;
}
static OSStatus	HP_HardwarePlugIn_DeviceGetProperty(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, UInt32* ioPropertyDataSize, void* outPropertyData)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetProperty: no plug-in");
		ThrowIfNULL(ioPropertyDataSize, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetProperty: no data size");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inDeviceID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
		}
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_DeviceGetProperty: no device with given ID after locking");
		
		//  construct a property address
		CAPropertyAddress theAddress(inPropertyID, isInput == 0 ? kAudioDevicePropertyScopeOutput : kAudioDevicePropertyScopeInput, inChannel);
		
		//	do the work
		theDevice->GetPropertyData(theAddress, 0, NULL, *ioPropertyDataSize, outPropertyData);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
static ULONG	HP_HardwarePlugIn_Release(AudioHardwarePlugInRef inSelf)
{
	ULONG theAnswer = 0;
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_Release: no plug-in");

		//	get the object out of the interface reference
		HP_HardwarePlugIn* thePlugIn = HP_HardwarePlugIn::GetObject(inSelf);
		
		//	release it
		theAnswer = thePlugIn->Release();
		
		//	note that thePlugIn is invalid now, so don't use it!
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theAnswer;
}
static OSStatus	HP_HardwarePlugIn_Teardown(AudioHardwarePlugInRef inSelf)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_Teardown: no plug-in");

		//	get the object out of the interface reference
		HP_HardwarePlugIn* thePlugIn = HP_HardwarePlugIn::GetObject(inSelf);
		
		//	do the work
		thePlugIn->Teardown();
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
static void HP_HardwarePlugIn_ObjectShow(AudioHardwarePlugInRef inSelf, AudioObjectID inObjectID)
{
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_ObjectShow: no plug-in");

		//  find the object for the given ID
		HP_Object* theObject = HP_Object::GetObjectByID(inObjectID);
		ThrowIfNULL(theObject, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_ObjectShow: no object with given ID");
		
		//	do the work
		theObject->Show();
	}
	catch(...)
	{
	}
}
Пример #17
0
void	HP_PreferredChannels::Initialize()
{
	//	construct the name of the preferences
	CACFString theUID(mDevice->CopyDeviceUID());
	
	mInputStereoPrefsKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("com.apple.audio.CoreAudio.PreferredStereoChannels.%s.%@"), "Input", theUID.GetCFString());
	ThrowIfNULL(mInputStereoPrefsKey, CAException(kAudioHardwareIllegalOperationError), "HP_PreferredChannels::Initialize: couldn't create the input stereo prefs key");
	
	mOutputStereoPrefsKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("com.apple.audio.CoreAudio.PreferredStereoChannels.%s.%@"), "Output", theUID.GetCFString());
	ThrowIfNULL(mOutputStereoPrefsKey, CAException(kAudioHardwareIllegalOperationError), "HP_PreferredChannels::Initialize: couldn't create the output stereo prefs key");
	
	mInputChannelLayoutPrefsKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("com.apple.audio.CoreAudio.PreferredChannelLayout.%s.%@"), "Input", theUID.GetCFString());
	ThrowIfNULL(mInputChannelLayoutPrefsKey, CAException(kAudioHardwareIllegalOperationError), "HP_PreferredChannels::Initialize: couldn't create the input channel layout prefs key");
	
	mOutputChannelLayoutPrefsKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("com.apple.audio.CoreAudio.PreferredChannelLayout.%s.%@"), "Output", theUID.GetCFString());
	ThrowIfNULL(mOutputChannelLayoutPrefsKey, CAException(kAudioHardwareIllegalOperationError), "HP_PreferredChannels::Initialize: couldn't create the output channel layout prefs key");
	
	//	cache the prefs
	mPreferredInputStereoChannels = CACFPreferences::CopyArrayValue(mInputStereoPrefsKey, false, true);
	mPreferredOutputStereoChannels = CACFPreferences::CopyArrayValue(mOutputStereoPrefsKey, false, true);
	mPreferredInputChannelLayout = CACFPreferences::CopyDictionaryValue(mInputChannelLayoutPrefsKey, false, true);
	mPreferredOutputChannelLayout = CACFPreferences::CopyDictionaryValue(mOutputChannelLayoutPrefsKey, false, true);
	
	//	cache the actual CFArray values for the output preferred stereo pair
	CACFArray thePrefStereoChannels(mPreferredOutputStereoChannels, false);
	if(thePrefStereoChannels.IsValid())
	{
		thePrefStereoChannels.GetUInt32(0, mOutputStereoPair[0]);
		thePrefStereoChannels.GetUInt32(1, mOutputStereoPair[1]);
	}
	else
	{
		mOutputStereoPair[0] = 1;
		mOutputStereoPair[1] = 2;
	}
	
	//	sign up for notifications
	CACFDistributedNotification::AddObserver((const void*)mToken, (CFNotificationCallback)ChangeNotification, mInputStereoPrefsKey);
	CACFDistributedNotification::AddObserver((const void*)mToken, (CFNotificationCallback)ChangeNotification, mOutputStereoPrefsKey);
	CACFDistributedNotification::AddObserver((const void*)mToken, (CFNotificationCallback)ChangeNotification, mInputChannelLayoutPrefsKey);
	CACFDistributedNotification::AddObserver((const void*)mToken, (CFNotificationCallback)ChangeNotification, mOutputChannelLayoutPrefsKey);
}
Пример #18
0
//	This constructor is the general form:
//	-	If inMachPort is MACH_PORT_NULL, the CFMachPort will allocate the port and own the send and
//		receive rights. Otherwise, the caller owns the rights and is resposible for cleaning them
//		up.
//	-	If inCallBack is NULL, then received messages will just get swallowed by the CFMachPort.
//		This is useful if you are only using the CFMachPort to track port death (aka invalidation).
//	-	If inInvalidationCallBack is non-NULL, then it will be installed as the invalidation
//		callback on the CFMachPort.
CACFMachPort::CACFMachPort(mach_port_t inMachPort, CFMachPortCallBack inCallBack, CFMachPortInvalidationCallBack inInvalidationCallBack, void* inUserData)
:
	mMachPort(NULL),
	mRunLoopSource(NULL),
	mOwnsPort(false)
{
	CFMachPortContext theContext = { 1, inUserData, NULL, NULL, NULL };
	
	if(inMachPort == MACH_PORT_NULL)
	{
		mMachPort = CFMachPortCreate(NULL, inCallBack, &theContext, NULL);
		ThrowIfNULL(mMachPort, CAException('what'), "CACFMachPort::CACFMachPort: couldn't create the CFMachPort");
		mOwnsPort = true;
	}
	else
	{
		mMachPort = CFMachPortCreateWithPort(NULL, inMachPort, inCallBack, &theContext, NULL);
		ThrowIfNULL(mMachPort, CAException('what'), "CACFMachPort::CACFMachPort: couldn't create the CFMachPort with a port");
		mOwnsPort = false;
	}

	mRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mMachPort, 0);
	if(mRunLoopSource == NULL)
	{
		if(mOwnsPort)
		{
			CFMachPortInvalidate(mMachPort);
		}
		CFRelease(mMachPort);
		mMachPort = NULL;
		DebugMessage("CACFMachPort::CACFMachPort: couldn't create the CFRunLoopSource");
		throw CAException('what');
	}
	
	if(inInvalidationCallBack != NULL)
	{
		CFMachPortSetInvalidationCallBack(mMachPort, inInvalidationCallBack);
	}
}
Пример #19
0
CAGuard::CAGuard(const char* inName)
:
	CAMutex(inName)
#if	Log_Average_Latency
	,mAverageLatencyAccumulator(0.0),
	mAverageLatencyCount(0)
#endif
{
#if TARGET_OS_MAC
	OSStatus theError = pthread_cond_init(&mCondVar, NULL);
	ThrowIf(theError != 0, CAException(theError), "CAGuard::CAGuard: Could not init the cond var");
#elif TARGET_OS_WIN32
	mEvent = CreateEvent(NULL, true, false, NULL);
	ThrowIfNULL(mEvent, CAException(GetLastError()), "CAGuard::CAGuard: Could not create the event");
#endif
}
Пример #20
0
//	This constructor is the short form. The CFMachPort will own the send and receive rights.
CACFMachPort::CACFMachPort(CFMachPortCallBack inCallBack, void* inUserData)
:
	mMachPort(NULL),
	mRunLoopSource(NULL),
	mOwnsPort(true)
{
	CFMachPortContext theContext = { 1, inUserData, NULL, NULL, NULL };
	mMachPort = CFMachPortCreate(NULL, inCallBack, &theContext, NULL);
	ThrowIfNULL(mMachPort, CAException('what'), "CACFMachPort::CACFMachPort(s): couldn't create the CFMachPort");

	mRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mMachPort, 0);
	if(mRunLoopSource == NULL)
	{
		CFMachPortInvalidate(mMachPort);
		CFRelease(mMachPort);
		mMachPort = NULL;
		DebugMessage("CACFMachPort::CACFMachPort(s): couldn't create the CFRunLoopSource");
		throw CAException('what');
	}
}
Пример #21
0
CAMutex::CAMutex(const char* inName)
:
	mName(inName),
	mOwner(0)
{
#if TARGET_OS_MAC
	OSStatus theError = pthread_mutex_init(&mMutex, NULL);
	ThrowIf(theError != 0, CAException(theError), "CAMutex::CAMutex: Could not init the mutex");
	
	#if	Log_Ownership
		DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: CAMutex::CAMutex: creating %s, owner: %p\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
	#endif
#elif TARGET_OS_WIN32
	mMutex = CreateMutex(NULL, false, NULL);
	ThrowIfNULL(mMutex, CAException(GetLastError()), "CAMutex::CAMutex: could not create the mutex.");
	
	#if	Log_Ownership
		DebugPrintfRtn(DebugPrintfFileComma "%lu %.4f: CAMutex::CAMutex: creating %s, owner: %lu\n", GetCurrentThreadId(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), mName, mOwner);
	#endif
#endif
}
Пример #22
0
extern "C" OSStatus	AudioDriverPlugInStreamGetPropertyInfo(AudioDeviceID inDevice, io_object_t inIOAudioStream, UInt32 inChannel, AudioDevicePropertyID inPropertyID, UInt32* outSize, Boolean* outWritable)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//	find the plug-in object for the device
		HP_DriverPlugIn* thePlugIn = HP_DriverPlugIn::GetPlugIn(inDevice);
		ThrowIfNULL(thePlugIn, CAException(kAudioHardwareBadDeviceError), "AudioDriverPlugInDeviceGetPropertyInfo: couldn't find the plug-in for the device");

		//	figure out if the stream has the given property
		if(thePlugIn->StreamHasProperty(inIOAudioStream, inChannel, inPropertyID))
		{
			//	let the plug-in do the work
			if(outSize != NULL)
			{
				*outSize = thePlugIn->StreamGetPropertyDataSize(inIOAudioStream, inChannel, inPropertyID);
			}
			
			if(outWritable != NULL)
			{
				*outWritable = thePlugIn->StreamIsPropertyWritable(inIOAudioStream, inChannel, inPropertyID);
			}
		}
		else
		{
			theError = kAudioHardwareUnknownPropertyError;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
Пример #23
0
extern "C" OSStatus	AudioDriverPlugInStreamSetProperty(AudioDeviceID inDevice, io_object_t inIOAudioStream, const AudioTimeStamp* /*inWhen*/, UInt32 inChannel, AudioDevicePropertyID inPropertyID, UInt32 inPropertyDataSize, const void* inPropertyData)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//	find the plug-in object for the device
		HP_DriverPlugIn* thePlugIn = HP_DriverPlugIn::GetPlugIn(inDevice);
		ThrowIfNULL(thePlugIn, CAException(kAudioHardwareBadDeviceError), "AudioDriverPlugInDeviceSetProperty: couldn't find the plug-in for the device");

		//	figure out if the stream has the given property
		if(thePlugIn->StreamHasProperty(inIOAudioStream, inChannel, inPropertyID))
		{
			//	make sure the property is writable
			if(thePlugIn->StreamIsPropertyWritable(inIOAudioStream, inChannel, inPropertyID))
			{
				//	let the plug-in do the work
				thePlugIn->StreamSetPropertyData(inIOAudioStream, inChannel, inPropertyID, inPropertyDataSize, inPropertyData);
			}
			else
			{
				theError = kAudioHardwareIllegalOperationError;
			}
		}
		else
		{
			theError = kAudioHardwareUnknownPropertyError;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
Пример #24
0
HP_HogMode::HP_HogMode(HP_Device* inDevice)
    :
    mToken(0),
    mDevice(inDevice),
    mPrefName(NULL),
    mOwner(-2)
{
    pthread_once(&sStaticInitializer, StaticInitializer);

    //	get our token
    mToken = sTokenMap->MapObject(this);

    //	construct the name of the preference
    mPrefName = CFStringCreateMutable(NULL, 0);
    ThrowIfNULL(mPrefName, CAException(kAudioHardwareUnspecifiedError), "HP_HogMode::HP_HogMode: couldn't allocate the pref name string");
    CFStringAppendCString((CFMutableStringRef)mPrefName, "com.apple.audio.CoreAudio.HogMode.Owner-", kCFStringEncodingASCII);
    CACFString theUID(inDevice->CopyDeviceUID());
    CFStringAppend((CFMutableStringRef)mPrefName, theUID.GetCFString());

    //	sign up for notifications
    CACFDistributedNotification::AddObserver((const void*)mToken, (CFNotificationCallback)ChangeNotification, mPrefName, 0);
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// GetDeviceByGUID()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	Device&	PlugIn::GetDeviceByGUID(UInt64 guid) const
	{
		Device* device = 0;
		bool found = false;

		// Iterate over the plugIn's devices and find the one whose guid matches
		for (UInt32 i = 0 ; i < GetNumberDevices() ; ++i)
		{
			device = static_cast<Device*>(GetDeviceByIndex(i));
			ThrowIfNULL(device, CAException(kCMIOHardwareBadDeviceError), "CMIO::DP::Sample::PlugIn::GetDeviceByGUID: no device for index");
			if (guid == device->GetDeviceGUID())
			{
				found = true;
				break;
			}
		}
		
		// Make sure that a device was actually found
		if (not found)
			throw CAException(kCMIOHardwareBadDeviceError);
		
		return *device;
	}
Пример #26
0
HP_DriverPlugIn*	HP_DriverPlugIn::OpenPlugIn(const AudioDriverPlugInHostInfo& inHostInfo)
{
	//	check to see if we already have one
	HP_DriverPlugIn* theAnswer = GetPlugIn(inHostInfo.mDeviceID);
	
	if(theAnswer == NULL)
	{
		//	we don't, so make a new one
		theAnswer = HP_DriverPlugIn::CreatePlugIn(inHostInfo);
		ThrowIfNULL(theAnswer, CAException(kAudioHardwareIllegalOperationError), "HP_DriverPlugIn::OpenPlugIn: failed to create the plug-in instance");
		
		//	create the plug-in list if necessary
		if(sPlugInList == NULL)
		{
			sPlugInList = new PlugInList;
		}
		
		//	add the new plug-in to the list
		sPlugInList->push_back(theAnswer);
	}
	
	return theAnswer;
}