| 1 |
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved. |
|---|
| 2 |
|
|---|
| 3 |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. |
|---|
| 4 |
("Apple") in consideration of your agreement to the following terms, and your |
|---|
| 5 |
use, installation, modification or redistribution of this Apple software |
|---|
| 6 |
constitutes acceptance of these terms. If you do not agree with these terms, |
|---|
| 7 |
please do not use, install, modify or redistribute this Apple software. |
|---|
| 8 |
|
|---|
| 9 |
In consideration of your agreement to abide by the following terms, and subject |
|---|
| 10 |
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs |
|---|
| 11 |
copyrights in this original Apple software (the "Apple Software"), to use, |
|---|
| 12 |
reproduce, modify and redistribute the Apple Software, with or without |
|---|
| 13 |
modifications, in source and/or binary forms; provided that if you redistribute |
|---|
| 14 |
the Apple Software in its entirety and without modifications, you must retain |
|---|
| 15 |
this notice and the following text and disclaimers in all such redistributions of |
|---|
| 16 |
the Apple Software. Neither the name, trademarks, service marks or logos of |
|---|
| 17 |
Apple Computer, Inc. may be used to endorse or promote products derived from the |
|---|
| 18 |
Apple Software without specific prior written permission from Apple. Except as |
|---|
| 19 |
expressly stated in this notice, no other rights or licenses, express or implied, |
|---|
| 20 |
are granted by Apple herein, including but not limited to any patent rights that |
|---|
| 21 |
may be infringed by your derivative works or by other works in which the Apple |
|---|
| 22 |
Software may be incorporated. |
|---|
| 23 |
|
|---|
| 24 |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
|---|
| 25 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|---|
| 26 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 27 |
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN |
|---|
| 28 |
COMBINATION WITH YOUR PRODUCTS. |
|---|
| 29 |
|
|---|
| 30 |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|---|
| 31 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 32 |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 33 |
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION |
|---|
| 34 |
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT |
|---|
| 35 |
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN |
|---|
| 36 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 37 |
*/ |
|---|
| 38 |
/*============================================================================= |
|---|
| 39 |
ACCodecDispatch.h |
|---|
| 40 |
|
|---|
| 41 |
=============================================================================*/ |
|---|
| 42 |
#if !defined(__ACCodecDispatch_h__) |
|---|
| 43 |
#define __ACCodecDispatch_h__ |
|---|
| 44 |
|
|---|
| 45 |
//============================================================================= |
|---|
| 46 |
// Includes |
|---|
| 47 |
//============================================================================= |
|---|
| 48 |
|
|---|
| 49 |
#include "ACCodec.h" |
|---|
| 50 |
#include "ACCodecDispatchTypes.h" |
|---|
| 51 |
|
|---|
| 52 |
//============================================================================= |
|---|
| 53 |
// ACCodecDispatch |
|---|
| 54 |
// |
|---|
| 55 |
// A function template that implements a component dispatch routine for an |
|---|
| 56 |
// AudioCodec in terms of an instance of a subclass of ACCodec. |
|---|
| 57 |
// It is best used when called from the primary codec dispatcher like so: |
|---|
| 58 |
// |
|---|
| 59 |
// extern "C" |
|---|
| 60 |
// ComponentResult FooCodecDispatch(ComponentParameters* inParameters, FooCodec* inThis) |
|---|
| 61 |
// { |
|---|
| 62 |
// return ACCodecDispatch(inParameters, inThis); |
|---|
| 63 |
// } |
|---|
| 64 |
// |
|---|
| 65 |
// The reason this exists is to better encapuslate all the necessary code |
|---|
| 66 |
// to do the dispatching without having to figure out what the C++ mangled |
|---|
| 67 |
// name for the entry point to put in the exported symbols file. |
|---|
| 68 |
//============================================================================= |
|---|
| 69 |
|
|---|
| 70 |
template <class CodecClass> |
|---|
| 71 |
ComponentResult ACCodecDispatch(ComponentParameters* inParameters, CodecClass* inThis) |
|---|
| 72 |
{ |
|---|
| 73 |
ComponentResult theError = kAudioCodecNoError; |
|---|
| 74 |
|
|---|
| 75 |
try |
|---|
| 76 |
{ |
|---|
| 77 |
switch (inParameters->what) |
|---|
| 78 |
{ |
|---|
| 79 |
// these selectors don't use the object pointer |
|---|
| 80 |
|
|---|
| 81 |
case kComponentOpenSelect: |
|---|
| 82 |
{ |
|---|
| 83 |
CodecClass* theCodec = new CodecClass(); |
|---|
| 84 |
SetComponentInstanceStorage(((AudioCodecOpenGluePB*)inParameters)->inCodec, (Handle)theCodec); |
|---|
| 85 |
} |
|---|
| 86 |
break; |
|---|
| 87 |
|
|---|
| 88 |
case kComponentCloseSelect: |
|---|
| 89 |
delete inThis; |
|---|
| 90 |
break; |
|---|
| 91 |
|
|---|
| 92 |
case kComponentCanDoSelect: |
|---|
| 93 |
switch (*((SInt16*)&inParameters->params[1])) |
|---|
| 94 |
{ |
|---|
| 95 |
case kComponentOpenSelect: |
|---|
| 96 |
case kComponentCloseSelect: |
|---|
| 97 |
case kComponentCanDoSelect: |
|---|
| 98 |
case kComponentRegisterSelect: |
|---|
| 99 |
case kComponentVersionSelect: |
|---|
| 100 |
case kAudioCodecGetPropertyInfoSelect: |
|---|
| 101 |
case kAudioCodecGetPropertySelect: |
|---|
| 102 |
case kAudioCodecSetPropertySelect: |
|---|
| 103 |
case kAudioCodecInitializeSelect: |
|---|
| 104 |
case kAudioCodecAppendInputDataSelect: |
|---|
| 105 |
case kAudioCodecProduceOutputDataSelect: |
|---|
| 106 |
case kAudioCodecResetSelect: |
|---|
| 107 |
theError = 1; |
|---|
| 108 |
break; |
|---|
| 109 |
}; |
|---|
| 110 |
break; |
|---|
| 111 |
|
|---|
| 112 |
default: |
|---|
| 113 |
// these selectors use the object pointer |
|---|
| 114 |
if(inThis != NULL) |
|---|
| 115 |
{ |
|---|
| 116 |
switch (inParameters->what) |
|---|
| 117 |
{ |
|---|
| 118 |
case kComponentRegisterSelect: |
|---|
| 119 |
if(!inThis->Register()) |
|---|
| 120 |
{ |
|---|
| 121 |
theError = componentDontRegister; |
|---|
| 122 |
} |
|---|
| 123 |
break; |
|---|
| 124 |
|
|---|
| 125 |
case kComponentVersionSelect: |
|---|
| 126 |
theError = inThis->GetVersion(); |
|---|
| 127 |
break; |
|---|
| 128 |
|
|---|
| 129 |
case kAudioCodecGetPropertyInfoSelect: |
|---|
| 130 |
{ |
|---|
| 131 |
AudioCodecGetPropertyInfoGluePB* thePB = (AudioCodecGetPropertyInfoGluePB*)inParameters; |
|---|
| 132 |
UInt32 theSize = 0; |
|---|
| 133 |
bool isWritable = false; |
|---|
| 134 |
|
|---|
| 135 |
inThis->GetPropertyInfo(thePB->inPropertyID, theSize, isWritable); |
|---|
| 136 |
if(thePB->outSize != NULL) |
|---|
| 137 |
{ |
|---|
| 138 |
*(thePB->outSize) = theSize; |
|---|
| 139 |
} |
|---|
| 140 |
if(thePB->outWritable != NULL) |
|---|
| 141 |
{ |
|---|
| 142 |
*(thePB->outWritable) = isWritable ? 1 : 0; |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
break; |
|---|
| 146 |
|
|---|
| 147 |
case kAudioCodecGetPropertySelect: |
|---|
| 148 |
{ |
|---|
| 149 |
AudioCodecGetPropertyGluePB* thePB = (AudioCodecGetPropertyGluePB*)inParameters; |
|---|
| 150 |
|
|---|
| 151 |
if((thePB->ioPropertyDataSize != NULL) && (thePB->outPropertyData != NULL)) |
|---|
| 152 |
{ |
|---|
| 153 |
inThis->GetProperty(thePB->inPropertyID, *(thePB->ioPropertyDataSize), thePB->outPropertyData); |
|---|
| 154 |
} |
|---|
| 155 |
else |
|---|
| 156 |
{ |
|---|
| 157 |
theError = paramErr; |
|---|
| 158 |
} |
|---|
| 159 |
} |
|---|
| 160 |
break; |
|---|
| 161 |
|
|---|
| 162 |
case kAudioCodecSetPropertySelect: |
|---|
| 163 |
{ |
|---|
| 164 |
AudioCodecSetPropertyGluePB* thePB = (AudioCodecSetPropertyGluePB*)inParameters; |
|---|
| 165 |
|
|---|
| 166 |
if(thePB->inPropertyData != NULL) |
|---|
| 167 |
{ |
|---|
| 168 |
inThis->SetProperty(thePB->inPropertyID, thePB->inPropertyDataSize, thePB->inPropertyData); |
|---|
| 169 |
} |
|---|
| 170 |
else |
|---|
| 171 |
{ |
|---|
| 172 |
theError = paramErr; |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
break; |
|---|
| 176 |
|
|---|
| 177 |
case kAudioCodecInitializeSelect: |
|---|
| 178 |
{ |
|---|
| 179 |
AudioCodecInitializeGluePB* thePB = (AudioCodecInitializeGluePB*)inParameters; |
|---|
| 180 |
|
|---|
| 181 |
inThis->Initialize(thePB->inInputFormat, thePB->inOutputFormat, thePB->inMagicCookie, thePB->inMagicCookieByteSize); |
|---|
| 182 |
} |
|---|
| 183 |
break; |
|---|
| 184 |
|
|---|
| 185 |
case kAudioCodecUninitializeSelect: |
|---|
| 186 |
{ |
|---|
| 187 |
//AudioCodecUninitializeGluePB* thePB = (AudioCodecUninitializeGluePB*)inParameters; |
|---|
| 188 |
|
|---|
| 189 |
inThis->Uninitialize(); |
|---|
| 190 |
} |
|---|
| 191 |
break; |
|---|
| 192 |
|
|---|
| 193 |
case kAudioCodecAppendInputDataSelect: |
|---|
| 194 |
{ |
|---|
| 195 |
AudioCodecAppendInputDataGluePB* thePB = (AudioCodecAppendInputDataGluePB*)inParameters; |
|---|
| 196 |
|
|---|
| 197 |
if((thePB->inInputData != NULL) && (thePB->ioInputDataByteSize != NULL)) |
|---|
| 198 |
{ |
|---|
| 199 |
if(thePB->ioNumberPackets != NULL) |
|---|
| 200 |
{ |
|---|
| 201 |
inThis->AppendInputData(thePB->inInputData, *(thePB->ioInputDataByteSize), *(thePB->ioNumberPackets), thePB->inPacketDescription); |
|---|
| 202 |
} |
|---|
| 203 |
else |
|---|
| 204 |
{ |
|---|
| 205 |
UInt32 theNumberPackets = 0; |
|---|
| 206 |
inThis->AppendInputData(thePB->inInputData, *(thePB->ioInputDataByteSize), theNumberPackets, thePB->inPacketDescription); |
|---|
| 207 |
} |
|---|
| 208 |
} |
|---|
| 209 |
else |
|---|
| 210 |
{ |
|---|
| 211 |
theError = paramErr; |
|---|
| 212 |
} |
|---|
| 213 |
} |
|---|
| 214 |
break; |
|---|
| 215 |
|
|---|
| 216 |
case kAudioCodecProduceOutputDataSelect: |
|---|
| 217 |
{ |
|---|
| 218 |
AudioCodecProduceOutputPacketsGluePB* thePB = (AudioCodecProduceOutputPacketsGluePB*)inParameters; |
|---|
| 219 |
|
|---|
| 220 |
if((thePB->outOutputData != NULL) && (thePB->ioOutputDataByteSize != NULL) && (thePB->ioNumberPackets != NULL) && (thePB->outStatus != NULL)) |
|---|
| 221 |
{ |
|---|
| 222 |
*(thePB->outStatus) = inThis->ProduceOutputPackets(thePB->outOutputData, *(thePB->ioOutputDataByteSize), *(thePB->ioNumberPackets), thePB->outPacketDescription); |
|---|
| 223 |
if(kAudioCodecProduceOutputPacketFailure == *(thePB->outStatus)) |
|---|
| 224 |
{ |
|---|
| 225 |
theError = paramErr; |
|---|
| 226 |
} |
|---|
| 227 |
} |
|---|
| 228 |
else |
|---|
| 229 |
{ |
|---|
| 230 |
theError = paramErr; |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
break; |
|---|
| 234 |
|
|---|
| 235 |
case kAudioCodecResetSelect: |
|---|
| 236 |
{ |
|---|
| 237 |
//AudioCodecResetGluePB* thePB = (AudioCodecResetGluePB*)inParameters; |
|---|
| 238 |
|
|---|
| 239 |
inThis->Reset(); |
|---|
| 240 |
} |
|---|
| 241 |
break; |
|---|
| 242 |
|
|---|
| 243 |
default: |
|---|
| 244 |
theError = badComponentSelector; |
|---|
| 245 |
break; |
|---|
| 246 |
}; |
|---|
| 247 |
} |
|---|
| 248 |
else |
|---|
| 249 |
{ |
|---|
| 250 |
theError = paramErr; |
|---|
| 251 |
} |
|---|
| 252 |
break; |
|---|
| 253 |
}; |
|---|
| 254 |
} |
|---|
| 255 |
catch(ComponentResult inErrorCode) |
|---|
| 256 |
{ |
|---|
| 257 |
theError = inErrorCode; |
|---|
| 258 |
} |
|---|
| 259 |
catch(...) |
|---|
| 260 |
{ |
|---|
| 261 |
theError = kAudioCodecUnspecifiedError; |
|---|
| 262 |
} |
|---|
| 263 |
|
|---|
| 264 |
return theError; |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
#endif |
|---|