Jamoma API  0.6.0.a19
CAHALAudioSystemObject.cpp
1 /* Copyright 2007 Apple Inc. All Rights Reserved.
2 
3  Disclaimer: IMPORTANT: This Apple software is supplied to you by
4  Apple Inc. ("Apple") in consideration of your agreement to the
5  following terms, and your use, installation, modification or
6  redistribution of this Apple software constitutes acceptance of these
7  terms. If you do not agree with these terms, please do not use,
8  install, modify or redistribute this Apple software.
9 
10  In consideration of your agreement to abide by the following terms, and
11  subject to these terms, Apple grants you a personal, non-exclusive
12  license, under Apple's copyrights in this original Apple software (the
13  "Apple Software"), to use, reproduce, modify and redistribute the Apple
14  Software, with or without modifications, in source and/or binary forms;
15  provided that if you redistribute the Apple Software in its entirety and
16  without modifications, you must retain this notice and the following
17  text and disclaimers in all such redistributions of the Apple Software.
18  Neither the name, trademarks, service marks or logos of Apple Inc.
19  may be used to endorse or promote products derived from the Apple
20  Software without specific prior written permission from Apple. Except
21  as expressly stated in this notice, no other rights or licenses, express
22  or implied, are granted by Apple herein, including but not limited to
23  any patent rights that may be infringed by your derivative works or by
24  other works in which the Apple Software may be incorporated.
25 
26  The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31 
32  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 //==================================================================================================
42 // Includes
43 //==================================================================================================
44 
45 // Self Include
46 #include "CAHALAudioSystemObject.h"
47 
48 // PublicUtility Includes
49 #include "CAAutoDisposer.h"
50 #include "CAPropertyAddress.h"
51 
52 //==================================================================================================
53 // CAHALAudioSystemObject
54 //==================================================================================================
55 
56 CAHALAudioSystemObject::CAHALAudioSystemObject()
57 :
58  CAHALAudioObject(kAudioObjectSystemObject)
59 {
60 }
61 
62 CAHALAudioSystemObject::~CAHALAudioSystemObject()
63 {
64 }
65 
66 UInt32 CAHALAudioSystemObject::GetNumberAudioDevices() const
67 {
68  CAPropertyAddress theAddress(kAudioHardwarePropertyDevices);
69  UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL);
70  theAnswer /= sizeof(AudioObjectID);
71  return theAnswer;
72 }
73 
74 void CAHALAudioSystemObject::GetAudioDevices(UInt32& ioNumberAudioDevices, AudioObjectID* outAudioDevices) const
75 {
76  CAPropertyAddress theAddress(kAudioHardwarePropertyDevices);
77  UInt32 theSize = ioNumberAudioDevices * sizeof(AudioObjectID);
78  GetPropertyData(theAddress, 0, NULL, theSize, outAudioDevices);
79  ioNumberAudioDevices = theSize / sizeof(AudioObjectID);
80 }
81 
82 AudioObjectID CAHALAudioSystemObject::GetAudioDeviceAtIndex(UInt32 inIndex) const
83 {
84  AudioObjectID theAnswer = kAudioObjectUnknown;
85  UInt32 theNumberDevices = GetNumberAudioDevices();
86  if((theNumberDevices > 0) && (inIndex < theNumberDevices))
87  {
88  CAAutoArrayDelete<AudioObjectID> theDeviceList(theNumberDevices);
89  GetAudioDevices(theNumberDevices, theDeviceList);
90  if((theNumberDevices > 0) && (inIndex < theNumberDevices))
91  {
92  theAnswer = theDeviceList[inIndex];
93  }
94  }
95  return theAnswer;
96 }
97 
98 AudioObjectID CAHALAudioSystemObject::GetAudioDeviceForUID(CFStringRef inUID) const
99 {
100  AudioObjectID theAnswer = kAudioObjectUnknown;
101  AudioValueTranslation theValue = { &inUID, sizeof(CFStringRef), &theAnswer, sizeof(AudioObjectID) };
102  CAPropertyAddress theAddress(kAudioHardwarePropertyDeviceForUID);
103  UInt32 theSize = sizeof(AudioValueTranslation);
104  GetPropertyData(theAddress, 0, NULL, theSize, &theValue);
105  return theAnswer;
106 }
107 
108 static inline AudioObjectPropertySelector CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(bool inIsInput, bool inIsSystem)
109 {
110  AudioObjectPropertySelector theAnswer = kAudioHardwarePropertyDefaultOutputDevice;
111  if(inIsInput)
112  {
113  theAnswer = kAudioHardwarePropertyDefaultInputDevice;
114  }
115  else if(inIsSystem)
116  {
117  theAnswer = kAudioHardwarePropertyDefaultSystemOutputDevice;
118  }
119  return theAnswer;
120 }
121 
122 AudioObjectID CAHALAudioSystemObject::GetDefaultAudioDevice(bool inIsInput, bool inIsSystem) const
123 {
124  AudioObjectID theAnswer = kAudioObjectUnknown;
125  CAPropertyAddress theAddress(CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(inIsInput, inIsSystem));
126  UInt32 theSize = sizeof(AudioObjectID);
127  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
128  return theAnswer;
129 }
130 
131 void CAHALAudioSystemObject::SetDefaultAudioDevice(bool inIsInput, bool inIsSystem, AudioObjectID inNewDefaultDevice)
132 {
133  CAPropertyAddress theAddress(CAHALAudioSystemObject_CalculateDefaultDeviceProperySelector(inIsInput, inIsSystem));
134  UInt32 theSize = sizeof(AudioObjectID);
135  SetPropertyData(theAddress, 0, NULL, theSize, &inNewDefaultDevice);
136 }
137 
138 AudioObjectID CAHALAudioSystemObject::GetAudioPlugInForBundleID(CFStringRef inUID) const
139 {
140  AudioObjectID theAnswer = kAudioObjectUnknown;
141  AudioValueTranslation theValue = { &inUID, sizeof(CFStringRef), &theAnswer, sizeof(AudioObjectID) };
142  CAPropertyAddress theAddress(kAudioHardwarePropertyPlugInForBundleID);
143  UInt32 theSize = sizeof(AudioValueTranslation);
144  GetPropertyData(theAddress, 0, NULL, theSize, &theValue);
145  return theAnswer;
146 }