1 /*
2 File: ACPlugInDispatch.cpp
3 Abstract: ACPlugInDispatch.h
4 Version: 1.1
5
6 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
7 Inc. ("Apple") in consideration of your agreement to the following
8 terms, and your use, installation, modification or redistribution of
9 this Apple software constitutes acceptance of these terms. If you do
10 not agree with these terms, please do not use, install, modify or
11 redistribute this Apple software.
12
13 In consideration of your agreement to abide by the following terms, and
14 subject to these terms, Apple grants you a personal, non-exclusive
15 license, under Apple's copyrights in this original Apple software (the
16 "Apple Software"), to use, reproduce, modify and redistribute the Apple
17 Software, with or without modifications, in source and/or binary forms;
18 provided that if you redistribute the Apple Software in its entirety and
19 without modifications, you must retain this notice and the following
20 text and disclaimers in all such redistributions of the Apple Software.
21 Neither the name, trademarks, service marks or logos of Apple Inc. may
22 be used to endorse or promote products derived from the Apple Software
23 without specific prior written permission from Apple. Except as
24 expressly stated in this notice, no other rights or licenses, express or
25 implied, are granted by Apple herein, including but not limited to any
26 patent rights that may be infringed by your derivative works or by other
27 works in which the Apple Software may be incorporated.
28
29 The Apple Software is provided by Apple on an "AS IS" basis. APPLE
30 MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31 THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32 FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33 OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34
35 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39 MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40 AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41 STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42 POSSIBILITY OF SUCH DAMAGE.
43
44 Copyright (C) 2014 Apple Inc. All Rights Reserved.
45
46 */
47 #if AUDIOCODECS_SUPPORT_PLUGINS
48 #include "ACPlugInDispatch.h"
49 #include "CAXException.h"
50 #include "ACCodec.h"
51 #include <new>
52
53 #define ACPI ((AudioComponentPlugInInstance *)self)
54 #define ACC ((ACCodec *)&ACPI->mInstanceStorage)
55
GetPropertyInfo(void * self,AudioCodecPropertyID inPropertyID,UInt32 * outSize,Boolean * outWritable)56 static OSStatus GetPropertyInfo(void *self, AudioCodecPropertyID inPropertyID, UInt32 *outSize, Boolean *outWritable)
57 {
58 OSStatus result = noErr;
59 try {
60 UInt32 size;
61 Boolean writable;
62 ACC->GetPropertyInfo(inPropertyID, size, writable);
63 if (outSize) *outSize = size;
64 if (outWritable) *outWritable = writable;
65 }
66 COMPONENT_CATCH
67 return result;
68 }
69
GetProperty(void * self,AudioCodecPropertyID inPropertyID,UInt32 * ioPropertyDataSize,void * outPropertyData)70 static OSStatus GetProperty(void *self, AudioCodecPropertyID inPropertyID, UInt32 *ioPropertyDataSize, void *outPropertyData)
71 {
72 OSStatus result = noErr;
73 try {
74 ACC->GetProperty(inPropertyID, *ioPropertyDataSize, outPropertyData);
75 }
76 COMPONENT_CATCH
77 return result;
78 }
79
SetProperty(void * self,AudioCodecPropertyID inPropertyID,UInt32 inPropertyDataSize,const void * inPropertyData)80 static OSStatus SetProperty(void *self, AudioCodecPropertyID inPropertyID, UInt32 inPropertyDataSize, const void *inPropertyData)
81 {
82 OSStatus result = noErr;
83 try {
84 ACC->SetProperty(inPropertyID, inPropertyDataSize, inPropertyData);
85 }
86 COMPONENT_CATCH
87 return result;
88 }
89
90
Initialize(void * self,const AudioStreamBasicDescription * inInputFormat,const AudioStreamBasicDescription * inOutputFormat,const void * inMagicCookie,UInt32 inMagicCookieByteSize)91 static OSStatus Initialize(void *self, const AudioStreamBasicDescription *inInputFormat, const AudioStreamBasicDescription *inOutputFormat, const void *inMagicCookie, UInt32 inMagicCookieByteSize)
92 {
93 OSStatus result = noErr;
94 try {
95 ACC->Initialize(inInputFormat, inOutputFormat, inMagicCookie, inMagicCookieByteSize);
96 }
97 COMPONENT_CATCH
98 return result;
99 }
100
Uninitialize(void * self)101 static OSStatus Uninitialize(void *self)
102 {
103 OSStatus result = noErr;
104 try {
105 ACC->Uninitialize();
106 }
107 COMPONENT_CATCH
108 return result;
109 }
110
AppendInputData(void * self,const void * inInputData,UInt32 * ioInputDataByteSize,UInt32 * ioNumberPackets,const AudioStreamPacketDescription * inPacketDescription)111 static OSStatus AppendInputData(void *self, const void *inInputData, UInt32 *ioInputDataByteSize, UInt32 *ioNumberPackets, const AudioStreamPacketDescription *inPacketDescription)
112 {
113 OSStatus result = noErr;
114 try {
115 UInt32 npackets = (ioNumberPackets != NULL) ? *ioNumberPackets : 0;
116 ACC->AppendInputData(inInputData, *ioInputDataByteSize, npackets, inPacketDescription);
117 if(ioNumberPackets != NULL)
118 *ioNumberPackets = npackets;
119 }
120 COMPONENT_CATCH
121 return result;
122 }
123
ProduceOutputPackets(void * self,void * outOutputData,UInt32 * ioOutputDataByteSize,UInt32 * ioNumberPackets,AudioStreamPacketDescription * outPacketDescription,UInt32 * outStatus)124 static OSStatus ProduceOutputPackets(void *self, void *outOutputData, UInt32 *ioOutputDataByteSize, UInt32 *ioNumberPackets, AudioStreamPacketDescription *outPacketDescription, UInt32 *outStatus)
125 {
126 OSStatus result = noErr;
127 try {
128 *outStatus = ACC->ProduceOutputPackets(outOutputData, *ioOutputDataByteSize, *ioNumberPackets, outPacketDescription);
129 if (*outStatus == kAudioCodecProduceOutputPacketFailure)
130 result = kAudio_ParamError;
131 }
132 COMPONENT_CATCH
133 return result;
134 }
135
Reset(void * self)136 static OSStatus Reset(void *self)
137 {
138 OSStatus result = noErr;
139 try {
140 ACC->Reset();
141 }
142 COMPONENT_CATCH
143 return result;
144 }
145
146 #if AC_NON_INTERLEAVED_SUPPORT
AppendInputBufferList(void * self,const AudioBufferList * ioBufferList,UInt32 * inNumberPackets,const AudioStreamPacketDescription * inPacketDescription,UInt32 * outBytesConsumed)147 static OSStatus AppendInputBufferList(void *self, const AudioBufferList *ioBufferList, UInt32 *inNumberPackets, const AudioStreamPacketDescription *inPacketDescription, UInt32 *outBytesConsumed)
148 {
149 OSStatus result = noErr;
150 try {
151 if((ioBufferList != NULL) && (outBytesConsumed != NULL))
152 {
153 if(inNumberPackets != NULL)
154 {
155 ACC->AppendInputBufferList(ioBufferList, *inNumberPackets, inPacketDescription, outBytesConsumed);
156 }
157 else
158 {
159 UInt32 theNumberPackets = 0;
160 ACC->AppendInputBufferList(ioBufferList, theNumberPackets, inPacketDescription, outBytesConsumed);
161 }
162 }
163 else
164 {
165 result = kAudio_ParamError;
166 }
167 }
168 COMPONENT_CATCH
169 return result;
170 }
171
ProduceOutputBufferList(void * self,AudioBufferList * ioBufferList,UInt32 * ioNumberPackets,AudioStreamPacketDescription * outPacketDescription,UInt32 * outStatus)172 static OSStatus ProduceOutputBufferList(void *self, AudioBufferList *ioBufferList, UInt32 *ioNumberPackets, AudioStreamPacketDescription *outPacketDescription, UInt32 *outStatus)
173 {
174 OSStatus result = noErr;
175 try {
176 if((ioBufferList != NULL) && (ioNumberPackets != NULL) && (outStatus != NULL))
177 {
178 *outStatus = ACC->ProduceOutputBufferList(ioBufferList, *ioNumberPackets, outPacketDescription);
179 if(kAudioCodecProduceOutputPacketFailure == *outStatus)
180 {
181 result = kAudio_ParamError;
182 }
183 }
184 else
185 {
186 result = kAudio_ParamError;
187 }
188 }
189 COMPONENT_CATCH
190 return result;
191 }
192 #endif
193
194 #if TARGET_OS_IPHONE && AUDIOCONV_HAVE_AMC
195 // The ACTransformerCodecBase class is the base for ALL hardware codecs.
196 // No need to check for ImplementFeature...
197 #include "ACTransformerManager.h"
198 #define ACTM ((ACTransformerCodecBase*)&ACPI->mInstanceStorage)
199
AcquireHardware(void * self)200 static OSStatus AcquireHardware(void *self)
201 {
202 OSStatus result = noErr;
203 try {
204 ACTM->AcquireHardware();
205 }
206 COMPONENT_CATCH
207 return result;
208 }
209
ReleaseHardware(void * self)210 static OSStatus ReleaseHardware(void *self)
211 {
212 OSStatus result = noErr;
213 try {
214 ACTM->ReleaseHardware();
215 }
216 COMPONENT_CATCH
217 return result;
218 }
219 #endif // TARGET_OS_IPHONE && AUDIOCONV_HAVE_AMC
220
221
Lookup(SInt16 selector)222 AudioComponentMethod AudioCodecLookup::Lookup (SInt16 selector)
223 {
224 switch (selector) {
225 case kAudioCodecGetPropertyInfoSelect: return (AudioComponentMethod)GetPropertyInfo;
226 case kAudioCodecGetPropertySelect: return (AudioComponentMethod)GetProperty;
227 case kAudioCodecSetPropertySelect: return (AudioComponentMethod)SetProperty;
228 case kAudioCodecInitializeSelect: return (AudioComponentMethod)Initialize;
229 case kAudioCodecUninitializeSelect: return (AudioComponentMethod)Uninitialize;
230 case kAudioCodecAppendInputDataSelect: return (AudioComponentMethod)AppendInputData;
231 case kAudioCodecProduceOutputDataSelect: return (AudioComponentMethod)ProduceOutputPackets;
232 case kAudioCodecResetSelect: return (AudioComponentMethod)Reset;
233 default:
234 break;
235 }
236 return NULL;
237 }
238
239 #if AC_NON_INTERLEAVED_SUPPORT
Lookup(SInt16 selector)240 AudioComponentMethod AudioCodecNonInterleavedEncoderLookup::Lookup (SInt16 selector)
241 {
242 AudioComponentMethod method = AudioCodecLookup::Lookup(selector);
243 if (method)
244 return method;
245
246 if (selector == kAudioCodecAppendInputBufferListSelect)
247 return (AudioComponentMethod)AppendInputBufferList;
248
249 return NULL;
250 }
251
Lookup(SInt16 selector)252 AudioComponentMethod AudioCodecNonInterleavedDecoderLookup::Lookup (SInt16 selector)
253 {
254 AudioComponentMethod method = AudioCodecLookup::Lookup(selector);
255 if (method)
256 return method;
257
258 if (selector == kAudioCodecProduceOutputBufferListSelect)
259 return (AudioComponentMethod)ProduceOutputBufferList;
260
261 return NULL;
262 }
263 #endif
264
265 #if TARGET_OS_IPHONE && AUDIOCONV_HAVE_AMC
266 #include "AudioCodecPriv.h"
267
Lookup(SInt16 selector)268 AudioComponentMethod AudioCodecHWCodecLookup::Lookup (SInt16 selector)
269 {
270 AudioComponentMethod method = AudioCodecLookup::Lookup(selector);
271 if (method) return method;
272
273 switch (selector) {
274 case kAudioCodecAcquireHardwareSelect: return (AudioComponentMethod)AcquireHardware;
275 case kAudioCodecReleaseHardwareSelect: return (AudioComponentMethod)ReleaseHardware;
276 default:
277 break;
278 }
279 return NULL;
280 }
281 #endif // TARGET_OS_IPHONE && AUDIOCONV_HAVE_AMC
282
283 #endif // AUDIOCODECS_SUPPORT_PLUGINS
284