| 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 |
ACBaseCodec.cpp |
|---|
| 40 |
|
|---|
| 41 |
=============================================================================*/ |
|---|
| 42 |
|
|---|
| 43 |
//============================================================================= |
|---|
| 44 |
// Includes |
|---|
| 45 |
//============================================================================= |
|---|
| 46 |
|
|---|
| 47 |
#include "ACBaseCodec.h" |
|---|
| 48 |
#include <algorithm> |
|---|
| 49 |
#include "CABundleLocker.h" |
|---|
| 50 |
|
|---|
| 51 |
#if TARGET_OS_WIN32 |
|---|
| 52 |
#include "CAWin32StringResources.h" |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
//============================================================================= |
|---|
| 56 |
// ACBaseCodec |
|---|
| 57 |
//============================================================================= |
|---|
| 58 |
|
|---|
| 59 |
ACBaseCodec::ACBaseCodec() |
|---|
| 60 |
: |
|---|
| 61 |
ACCodec(), |
|---|
| 62 |
mIsInitialized(false), |
|---|
| 63 |
mInputFormatList(), |
|---|
| 64 |
mInputFormat(), |
|---|
| 65 |
mOutputFormatList(), |
|---|
| 66 |
mOutputFormat() |
|---|
| 67 |
{ |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
ACBaseCodec::~ACBaseCodec() |
|---|
| 71 |
{ |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
void ACBaseCodec::GetPropertyInfo(AudioCodecPropertyID inPropertyID, UInt32& outPropertyDataSize, bool& outWritable) |
|---|
| 75 |
{ |
|---|
| 76 |
switch(inPropertyID) |
|---|
| 77 |
{ |
|---|
| 78 |
case kAudioCodecPropertyNameCFString: |
|---|
| 79 |
outPropertyDataSize = sizeof(CFStringRef); |
|---|
| 80 |
outWritable = false; |
|---|
| 81 |
break; |
|---|
| 82 |
case kAudioCodecPropertyManufacturerCFString: |
|---|
| 83 |
outPropertyDataSize = sizeof(CFStringRef); |
|---|
| 84 |
outWritable = false; |
|---|
| 85 |
break; |
|---|
| 86 |
case kAudioCodecPropertyFormatCFString: |
|---|
| 87 |
outPropertyDataSize = sizeof(CFStringRef); |
|---|
| 88 |
outWritable = false; |
|---|
| 89 |
break; |
|---|
| 90 |
case kAudioCodecPropertyRequiresPacketDescription: |
|---|
| 91 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 92 |
outWritable = false; |
|---|
| 93 |
break; |
|---|
| 94 |
case kAudioCodecPropertyMinimumNumberInputPackets : |
|---|
| 95 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 96 |
outWritable = false; |
|---|
| 97 |
break; |
|---|
| 98 |
case kAudioCodecPropertyMinimumNumberOutputPackets : |
|---|
| 99 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 100 |
outWritable = false; |
|---|
| 101 |
break; |
|---|
| 102 |
case kAudioCodecPropertyInputChannelLayout : |
|---|
| 103 |
case kAudioCodecPropertyOutputChannelLayout : |
|---|
| 104 |
// by default a codec doesn't support channel layouts. |
|---|
| 105 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 106 |
break; |
|---|
| 107 |
case kAudioCodecPropertyAvailableInputChannelLayouts : |
|---|
| 108 |
case kAudioCodecPropertyAvailableOutputChannelLayouts : |
|---|
| 109 |
// by default a codec doesn't support channel layouts. |
|---|
| 110 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 111 |
break; |
|---|
| 112 |
|
|---|
| 113 |
case kAudioCodecPropertyCurrentInputFormat: |
|---|
| 114 |
outPropertyDataSize = sizeof(AudioStreamBasicDescription); |
|---|
| 115 |
outWritable = true; |
|---|
| 116 |
break; |
|---|
| 117 |
|
|---|
| 118 |
case kAudioCodecPropertySupportedInputFormats: |
|---|
| 119 |
case kAudioCodecInputFormatsForOutputFormat: |
|---|
| 120 |
outPropertyDataSize = GetNumberSupportedInputFormats() * sizeof(AudioStreamBasicDescription); |
|---|
| 121 |
outWritable = false; |
|---|
| 122 |
break; |
|---|
| 123 |
|
|---|
| 124 |
case kAudioCodecPropertyCurrentOutputFormat: |
|---|
| 125 |
outPropertyDataSize = sizeof(AudioStreamBasicDescription); |
|---|
| 126 |
outWritable = true; |
|---|
| 127 |
break; |
|---|
| 128 |
|
|---|
| 129 |
case kAudioCodecPropertySupportedOutputFormats: |
|---|
| 130 |
case kAudioCodecOutputFormatsForInputFormat: |
|---|
| 131 |
outPropertyDataSize = GetNumberSupportedOutputFormats() * sizeof(AudioStreamBasicDescription); |
|---|
| 132 |
outWritable = false; |
|---|
| 133 |
break; |
|---|
| 134 |
|
|---|
| 135 |
case kAudioCodecPropertyMagicCookie: |
|---|
| 136 |
outPropertyDataSize = GetMagicCookieByteSize(); |
|---|
| 137 |
outWritable = true; |
|---|
| 138 |
break; |
|---|
| 139 |
|
|---|
| 140 |
case kAudioCodecPropertyInputBufferSize: |
|---|
| 141 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 142 |
outWritable = false; |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
case kAudioCodecPropertyUsedInputBufferSize: |
|---|
| 146 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 147 |
outWritable = false; |
|---|
| 148 |
break; |
|---|
| 149 |
|
|---|
| 150 |
case kAudioCodecPropertyIsInitialized: |
|---|
| 151 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 152 |
outWritable = false; |
|---|
| 153 |
break; |
|---|
| 154 |
|
|---|
| 155 |
case kAudioCodecPropertyAvailableNumberChannels: |
|---|
| 156 |
outPropertyDataSize = sizeof(UInt32) * 2; // Mono, stereo |
|---|
| 157 |
outWritable = false; |
|---|
| 158 |
break; |
|---|
| 159 |
|
|---|
| 160 |
case kAudioCodecPropertyPrimeMethod: |
|---|
| 161 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 162 |
outWritable = false; |
|---|
| 163 |
break; |
|---|
| 164 |
|
|---|
| 165 |
case kAudioCodecPropertyPrimeInfo: |
|---|
| 166 |
outPropertyDataSize = sizeof(AudioCodecPrimeInfo); |
|---|
| 167 |
outWritable = false; |
|---|
| 168 |
break; |
|---|
| 169 |
|
|---|
| 170 |
case kAudioCodecUseRecommendedSampleRate: |
|---|
| 171 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 172 |
outWritable = false; |
|---|
| 173 |
break; |
|---|
| 174 |
|
|---|
| 175 |
case kAudioCodecOutputPrecedence: |
|---|
| 176 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 177 |
outWritable = false; |
|---|
| 178 |
break; |
|---|
| 179 |
|
|---|
| 180 |
case kAudioCodecDoesSampleRateConversion: |
|---|
| 181 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 182 |
outWritable = false; |
|---|
| 183 |
break; |
|---|
| 184 |
#ifdef kAudioCodecRequiresMagicCookie |
|---|
| 185 |
case kAudioCodecRequiresMagicCookie: |
|---|
| 186 |
outPropertyDataSize = sizeof(UInt32); |
|---|
| 187 |
outWritable = false; |
|---|
| 188 |
break; |
|---|
| 189 |
#endif |
|---|
| 190 |
|
|---|
| 191 |
default: |
|---|
| 192 |
CODEC_THROW(kAudioCodecUnknownPropertyError); |
|---|
| 193 |
break; |
|---|
| 194 |
|
|---|
| 195 |
}; |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
void ACBaseCodec::GetProperty(AudioCodecPropertyID inPropertyID, UInt32& ioPropertyDataSize, void* outPropertyData) |
|---|
| 199 |
{ |
|---|
| 200 |
UInt32 thePacketsToGet; |
|---|
| 201 |
|
|---|
| 202 |
switch(inPropertyID) |
|---|
| 203 |
{ |
|---|
| 204 |
case kAudioCodecPropertyNameCFString: |
|---|
| 205 |
{ |
|---|
| 206 |
if (ioPropertyDataSize != sizeof(CFStringRef)) CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 207 |
|
|---|
| 208 |
CABundleLocker lock; |
|---|
| 209 |
CFStringRef name = CFCopyLocalizedStringFromTableInBundle(CFSTR("unknown codec"), CFSTR("CodecNames"), GetCodecBundle(), CFSTR("")); |
|---|
| 210 |
*(CFStringRef*)outPropertyData = name; |
|---|
| 211 |
break; |
|---|
| 212 |
} |
|---|
| 213 |
case kAudioCodecPropertyManufacturerCFString: |
|---|
| 214 |
{ |
|---|
| 215 |
if (ioPropertyDataSize != sizeof(CFStringRef)) CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 216 |
|
|---|
| 217 |
CABundleLocker lock; |
|---|
| 218 |
CFStringRef name = CFCopyLocalizedStringFromTableInBundle(CFSTR("Apple Computer, Inc."), CFSTR("CodecNames"), GetCodecBundle(), CFSTR("")); |
|---|
| 219 |
*(CFStringRef*)outPropertyData = name; |
|---|
| 220 |
break; |
|---|
| 221 |
} |
|---|
| 222 |
case kAudioCodecPropertyRequiresPacketDescription: |
|---|
| 223 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 224 |
{ |
|---|
| 225 |
*reinterpret_cast<UInt32*>(outPropertyData) = 0; |
|---|
| 226 |
} |
|---|
| 227 |
else |
|---|
| 228 |
{ |
|---|
| 229 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 230 |
} |
|---|
| 231 |
break; |
|---|
| 232 |
case kAudioCodecPropertyMinimumNumberInputPackets : |
|---|
| 233 |
if(ioPropertyDataSize != sizeof(UInt32)) CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 234 |
*(UInt32*)outPropertyData = 1; |
|---|
| 235 |
break; |
|---|
| 236 |
case kAudioCodecPropertyMinimumNumberOutputPackets : |
|---|
| 237 |
if(ioPropertyDataSize != sizeof(UInt32)) CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 238 |
*(UInt32*)outPropertyData = 1; |
|---|
| 239 |
break; |
|---|
| 240 |
|
|---|
| 241 |
case kAudioCodecPropertyInputChannelLayout : |
|---|
| 242 |
case kAudioCodecPropertyOutputChannelLayout : |
|---|
| 243 |
// by default a codec doesn't support channel layouts. |
|---|
| 244 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 245 |
break; |
|---|
| 246 |
case kAudioCodecPropertyAvailableInputChannelLayouts : |
|---|
| 247 |
case kAudioCodecPropertyAvailableOutputChannelLayouts : |
|---|
| 248 |
// by default a codec doesn't support channel layouts. |
|---|
| 249 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 250 |
break; |
|---|
| 251 |
|
|---|
| 252 |
case kAudioCodecPropertyCurrentInputFormat: |
|---|
| 253 |
if(ioPropertyDataSize == sizeof(AudioStreamBasicDescription)) |
|---|
| 254 |
{ |
|---|
| 255 |
GetCurrentInputFormat(*reinterpret_cast<AudioStreamBasicDescription*>(outPropertyData)); |
|---|
| 256 |
} |
|---|
| 257 |
else |
|---|
| 258 |
{ |
|---|
| 259 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 260 |
} |
|---|
| 261 |
break; |
|---|
| 262 |
|
|---|
| 263 |
case kAudioCodecPropertySupportedInputFormats: |
|---|
| 264 |
case kAudioCodecInputFormatsForOutputFormat: |
|---|
| 265 |
thePacketsToGet = ioPropertyDataSize / sizeof(AudioStreamBasicDescription); |
|---|
| 266 |
GetSupportedInputFormats(reinterpret_cast<AudioStreamBasicDescription*>(outPropertyData), thePacketsToGet); |
|---|
| 267 |
ioPropertyDataSize = thePacketsToGet * sizeof(AudioStreamBasicDescription); |
|---|
| 268 |
break; |
|---|
| 269 |
|
|---|
| 270 |
case kAudioCodecPropertyCurrentOutputFormat: |
|---|
| 271 |
if(ioPropertyDataSize == sizeof(AudioStreamBasicDescription)) |
|---|
| 272 |
{ |
|---|
| 273 |
GetCurrentOutputFormat(*reinterpret_cast<AudioStreamBasicDescription*>(outPropertyData)); |
|---|
| 274 |
} |
|---|
| 275 |
else |
|---|
| 276 |
{ |
|---|
| 277 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 278 |
} |
|---|
| 279 |
break; |
|---|
| 280 |
|
|---|
| 281 |
case kAudioCodecPropertySupportedOutputFormats: |
|---|
| 282 |
case kAudioCodecOutputFormatsForInputFormat: |
|---|
| 283 |
thePacketsToGet = ioPropertyDataSize / sizeof(AudioStreamBasicDescription); |
|---|
| 284 |
GetSupportedOutputFormats(reinterpret_cast<AudioStreamBasicDescription*>(outPropertyData), thePacketsToGet); |
|---|
| 285 |
ioPropertyDataSize = thePacketsToGet * sizeof(AudioStreamBasicDescription); |
|---|
| 286 |
break; |
|---|
| 287 |
|
|---|
| 288 |
case kAudioCodecPropertyMagicCookie: |
|---|
| 289 |
if(ioPropertyDataSize >= GetMagicCookieByteSize()) |
|---|
| 290 |
{ |
|---|
| 291 |
GetMagicCookie(outPropertyData, ioPropertyDataSize); |
|---|
| 292 |
} |
|---|
| 293 |
else |
|---|
| 294 |
{ |
|---|
| 295 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 296 |
} |
|---|
| 297 |
break; |
|---|
| 298 |
|
|---|
| 299 |
case kAudioCodecPropertyInputBufferSize: |
|---|
| 300 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 301 |
{ |
|---|
| 302 |
*reinterpret_cast<UInt32*>(outPropertyData) = GetInputBufferByteSize(); |
|---|
| 303 |
} |
|---|
| 304 |
else |
|---|
| 305 |
{ |
|---|
| 306 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 307 |
} |
|---|
| 308 |
break; |
|---|
| 309 |
|
|---|
| 310 |
case kAudioCodecPropertyUsedInputBufferSize: |
|---|
| 311 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 312 |
{ |
|---|
| 313 |
*reinterpret_cast<UInt32*>(outPropertyData) = GetUsedInputBufferByteSize(); |
|---|
| 314 |
} |
|---|
| 315 |
else |
|---|
| 316 |
{ |
|---|
| 317 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 318 |
} |
|---|
| 319 |
break; |
|---|
| 320 |
|
|---|
| 321 |
case kAudioCodecPropertyIsInitialized: |
|---|
| 322 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 323 |
{ |
|---|
| 324 |
*reinterpret_cast<UInt32*>(outPropertyData) = IsInitialized() ? 1 : 0; |
|---|
| 325 |
} |
|---|
| 326 |
else |
|---|
| 327 |
{ |
|---|
| 328 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 329 |
} |
|---|
| 330 |
break; |
|---|
| 331 |
|
|---|
| 332 |
case kAudioCodecPropertyAvailableNumberChannels: |
|---|
| 333 |
if(ioPropertyDataSize == sizeof(UInt32) * 2) |
|---|
| 334 |
{ |
|---|
| 335 |
(reinterpret_cast<UInt32*>(outPropertyData))[0] = 1; |
|---|
| 336 |
(reinterpret_cast<UInt32*>(outPropertyData))[1] = 2; |
|---|
| 337 |
} |
|---|
| 338 |
else |
|---|
| 339 |
{ |
|---|
| 340 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 341 |
} |
|---|
| 342 |
break; |
|---|
| 343 |
|
|---|
| 344 |
case kAudioCodecPropertyPrimeMethod: |
|---|
| 345 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 346 |
{ |
|---|
| 347 |
*reinterpret_cast<UInt32*>(outPropertyData) = (UInt32)kAudioCodecPrimeMethod_None; |
|---|
| 348 |
} |
|---|
| 349 |
else |
|---|
| 350 |
{ |
|---|
| 351 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 352 |
} |
|---|
| 353 |
break; |
|---|
| 354 |
|
|---|
| 355 |
case kAudioCodecPropertyPrimeInfo: |
|---|
| 356 |
if(ioPropertyDataSize == sizeof(AudioCodecPrimeInfo) ) |
|---|
| 357 |
{ |
|---|
| 358 |
(reinterpret_cast<AudioCodecPrimeInfo*>(outPropertyData))->leadingFrames = 0; |
|---|
| 359 |
(reinterpret_cast<AudioCodecPrimeInfo*>(outPropertyData))->trailingFrames = 0; |
|---|
| 360 |
} |
|---|
| 361 |
else |
|---|
| 362 |
{ |
|---|
| 363 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 364 |
} |
|---|
| 365 |
break; |
|---|
| 366 |
|
|---|
| 367 |
case kAudioCodecUseRecommendedSampleRate: |
|---|
| 368 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 369 |
{ |
|---|
| 370 |
*reinterpret_cast<UInt32*>(outPropertyData) = 0; |
|---|
| 371 |
} |
|---|
| 372 |
else |
|---|
| 373 |
{ |
|---|
| 374 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 375 |
} |
|---|
| 376 |
break; |
|---|
| 377 |
|
|---|
| 378 |
case kAudioCodecOutputPrecedence: |
|---|
| 379 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 380 |
{ |
|---|
| 381 |
*reinterpret_cast<UInt32*>(outPropertyData) = kAudioCodecOutputPrecedenceNone; |
|---|
| 382 |
} |
|---|
| 383 |
else |
|---|
| 384 |
{ |
|---|
| 385 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 386 |
} |
|---|
| 387 |
break; |
|---|
| 388 |
|
|---|
| 389 |
case kAudioCodecDoesSampleRateConversion: |
|---|
| 390 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 391 |
{ |
|---|
| 392 |
*reinterpret_cast<UInt32*>(outPropertyData) = 0; |
|---|
| 393 |
} |
|---|
| 394 |
else |
|---|
| 395 |
{ |
|---|
| 396 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 397 |
} |
|---|
| 398 |
break; |
|---|
| 399 |
|
|---|
| 400 |
#ifdef kAudioCodecRequiresMagicCookie |
|---|
| 401 |
case kAudioCodecRequiresMagicCookie: |
|---|
| 402 |
if(ioPropertyDataSize == sizeof(UInt32)) |
|---|
| 403 |
{ |
|---|
| 404 |
*reinterpret_cast<UInt32*>(outPropertyData) = 0; |
|---|
| 405 |
} |
|---|
| 406 |
else |
|---|
| 407 |
{ |
|---|
| 408 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 409 |
} |
|---|
| 410 |
break; |
|---|
| 411 |
#endif |
|---|
| 412 |
default: |
|---|
| 413 |
CODEC_THROW(kAudioCodecUnknownPropertyError); |
|---|
| 414 |
break; |
|---|
| 415 |
|
|---|
| 416 |
}; |
|---|
| 417 |
} |
|---|
| 418 |
|
|---|
| 419 |
void ACBaseCodec::SetProperty(AudioCodecPropertyID inPropertyID, UInt32 inPropertyDataSize, const void* inPropertyData) |
|---|
| 420 |
{ |
|---|
| 421 |
switch(inPropertyID) |
|---|
| 422 |
{ |
|---|
| 423 |
case kAudioCodecPropertyMinimumNumberInputPackets : |
|---|
| 424 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 425 |
break; |
|---|
| 426 |
case kAudioCodecPropertyMinimumNumberOutputPackets : |
|---|
| 427 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 428 |
break; |
|---|
| 429 |
|
|---|
| 430 |
case kAudioCodecPropertyInputChannelLayout : |
|---|
| 431 |
case kAudioCodecPropertyOutputChannelLayout : |
|---|
| 432 |
// by default a codec doesn't support channel layouts. |
|---|
| 433 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 434 |
break; |
|---|
| 435 |
|
|---|
| 436 |
case kAudioCodecPropertyAvailableInputChannelLayouts : |
|---|
| 437 |
case kAudioCodecPropertyAvailableOutputChannelLayouts : |
|---|
| 438 |
// by default a codec doesn't support channel layouts. |
|---|
| 439 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 440 |
break; |
|---|
| 441 |
|
|---|
| 442 |
case kAudioCodecPropertyCurrentInputFormat: |
|---|
| 443 |
if(inPropertyDataSize == sizeof(AudioStreamBasicDescription)) |
|---|
| 444 |
{ |
|---|
| 445 |
SetCurrentInputFormat(*reinterpret_cast<const AudioStreamBasicDescription*>(inPropertyData)); |
|---|
| 446 |
} |
|---|
| 447 |
else |
|---|
| 448 |
{ |
|---|
| 449 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 450 |
} |
|---|
| 451 |
break; |
|---|
| 452 |
|
|---|
| 453 |
case kAudioCodecPropertyCurrentOutputFormat: |
|---|
| 454 |
if(inPropertyDataSize == sizeof(AudioStreamBasicDescription)) |
|---|
| 455 |
{ |
|---|
| 456 |
SetCurrentOutputFormat(*reinterpret_cast<const AudioStreamBasicDescription*>(inPropertyData)); |
|---|
| 457 |
} |
|---|
| 458 |
else |
|---|
| 459 |
{ |
|---|
| 460 |
CODEC_THROW(kAudioCodecBadPropertySizeError); |
|---|
| 461 |
} |
|---|
| 462 |
break; |
|---|
| 463 |
|
|---|
| 464 |
case kAudioCodecPropertyMagicCookie: |
|---|
| 465 |
SetMagicCookie(inPropertyData, inPropertyDataSize); |
|---|
| 466 |
break; |
|---|
| 467 |
|
|---|
| 468 |
case kAudioCodecPropertyHasVariablePacketByteSizes: |
|---|
| 469 |
case kAudioCodecPropertyInputBufferSize: |
|---|
| 470 |
case kAudioCodecPropertyNameCFString: |
|---|
| 471 |
case kAudioCodecPropertyManufacturerCFString: |
|---|
| 472 |
case kAudioCodecPropertyFormatCFString: |
|---|
| 473 |
case kAudioCodecPropertySupportedInputFormats: |
|---|
| 474 |
case kAudioCodecPropertySupportedOutputFormats: |
|---|
| 475 |
case kAudioCodecPropertyUsedInputBufferSize: |
|---|
| 476 |
case kAudioCodecPropertyIsInitialized: |
|---|
| 477 |
case kAudioCodecPropertyAvailableNumberChannels: |
|---|
| 478 |
case kAudioCodecPropertyPrimeMethod: |
|---|
| 479 |
case kAudioCodecPropertyPrimeInfo: |
|---|
| 480 |
case kAudioCodecOutputFormatsForInputFormat: |
|---|
| 481 |
case kAudioCodecInputFormatsForOutputFormat: |
|---|
| 482 |
case kAudioCodecUseRecommendedSampleRate: |
|---|
| 483 |
case kAudioCodecOutputPrecedence: |
|---|
| 484 |
case kAudioCodecDoesSampleRateConversion: |
|---|
| 485 |
#ifdef kAudioCodecRequiresMagicCookie |
|---|
| 486 |
case kAudioCodecRequiresMagicCookie: |
|---|
| 487 |
#endif |
|---|
| 488 |
case kAudioCodecPropertyRequiresPacketDescription: |
|---|
| 489 |
CODEC_THROW(kAudioCodecIllegalOperationError); |
|---|
| 490 |
break; |
|---|
| 491 |
|
|---|
| 492 |
default: |
|---|
| 493 |
CODEC_THROW(kAudioCodecUnknownPropertyError); |
|---|
| 494 |
break; |
|---|
| 495 |
|
|---|
| 496 |
}; |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
void ACBaseCodec::Initialize(const AudioStreamBasicDescription* inInputFormat, const AudioStreamBasicDescription* inOutputFormat, const void* inMagicCookie, UInt32 inMagicCookieByteSize) |
|---|
| 500 |
{ |
|---|
| 501 |
mIsInitialized = true; |
|---|
| 502 |
} |
|---|
| 503 |
|
|---|
| 504 |
void ACBaseCodec::Uninitialize() |
|---|
| 505 |
{ |
|---|
| 506 |
mIsInitialized = false; |
|---|
| 507 |
} |
|---|
| 508 |
|
|---|
| 509 |
void ACBaseCodec::Reset() |
|---|
| 510 |
{ |
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
UInt32 ACBaseCodec::GetNumberSupportedInputFormats() const |
|---|
| 514 |
{ |
|---|
| 515 |
return mInputFormatList.size(); |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
void ACBaseCodec::GetSupportedInputFormats(AudioStreamBasicDescription* outInputFormats, UInt32& ioNumberInputFormats) const |
|---|
| 519 |
{ |
|---|
| 520 |
UInt32 theNumberFormats = mInputFormatList.size(); |
|---|
| 521 |
ioNumberInputFormats = (theNumberFormats < ioNumberInputFormats) ? theNumberFormats : ioNumberInputFormats; |
|---|
| 522 |
|
|---|
| 523 |
FormatList::const_iterator theIterator = mInputFormatList.begin(); |
|---|
| 524 |
theNumberFormats = ioNumberInputFormats; |
|---|
| 525 |
while((theNumberFormats > 0) && (theIterator != mInputFormatList.end())) |
|---|
| 526 |
{ |
|---|
| 527 |
*outInputFormats = *theIterator; |
|---|
| 528 |
|
|---|
| 529 |
++outInputFormats; |
|---|
| 530 |
--theNumberFormats; |
|---|
| 531 |
std::advance(theIterator, 1); |
|---|
| 532 |
} |
|---|
| 533 |
} |
|---|
| 534 |
|
|---|
| 535 |
void ACBaseCodec::GetCurrentInputFormat(AudioStreamBasicDescription& outInputFormat) |
|---|
| 536 |
{ |
|---|
| 537 |
outInputFormat = mInputFormat; |
|---|
| 538 |
} |
|---|
| 539 |
|
|---|
| 540 |
void ACBaseCodec::SetCurrentInputFormat(const AudioStreamBasicDescription& inInputFormat) |
|---|
| 541 |
{ |
|---|
| 542 |
if(!mIsInitialized) |
|---|
| 543 |
{ |
|---|
| 544 |
mInputFormat = inInputFormat; |
|---|
| 545 |
} |
|---|
| 546 |
else |
|---|
| 547 |
{ |
|---|
| 548 |
CODEC_THROW(kAudioCodecStateError); |
|---|
| 549 |
} |
|---|
| 550 |
} |
|---|
| 551 |
|
|---|
| 552 |
UInt32 ACBaseCodec::GetNumberSupportedOutputFormats() const |
|---|
| 553 |
{ |
|---|
| 554 |
return mOutputFormatList.size(); |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
void ACBaseCodec::GetSupportedOutputFormats(AudioStreamBasicDescription* outOutputFormats, UInt32& ioNumberOutputFormats) const |
|---|
| 558 |
{ |
|---|
| 559 |
UInt32 theNumberFormats = mOutputFormatList.size(); |
|---|
| 560 |
ioNumberOutputFormats = (theNumberFormats < ioNumberOutputFormats) ? theNumberFormats : ioNumberOutputFormats; |
|---|
| 561 |
|
|---|
| 562 |
FormatList::const_iterator theIterator = mOutputFormatList.begin(); |
|---|
| 563 |
theNumberFormats = ioNumberOutputFormats; |
|---|
| 564 |
while((theNumberFormats > 0) && (theIterator != mOutputFormatList.end())) |
|---|
| 565 |
{ |
|---|
| 566 |
*outOutputFormats = *theIterator; |
|---|
| 567 |
|
|---|
| 568 |
++outOutputFormats; |
|---|
| 569 |
--theNumberFormats; |
|---|
| 570 |
std::advance(theIterator, 1); |
|---|
| 571 |
} |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
void ACBaseCodec::GetCurrentOutputFormat(AudioStreamBasicDescription& outOutputFormat) |
|---|
| 575 |
{ |
|---|
| 576 |
outOutputFormat = mOutputFormat; |
|---|
| 577 |
} |
|---|
| 578 |
|
|---|
| 579 |
void ACBaseCodec::SetCurrentOutputFormat(const AudioStreamBasicDescription& inOutputFormat) |
|---|
| 580 |
{ |
|---|
| 581 |
if(!mIsInitialized) |
|---|
| 582 |
{ |
|---|
| 583 |
mOutputFormat = inOutputFormat; |
|---|
| 584 |
} |
|---|
| 585 |
else |
|---|
| 586 |
{ |
|---|
| 587 |
CODEC_THROW(kAudioCodecStateError); |
|---|
| 588 |
} |
|---|
| 589 |
} |
|---|
| 590 |
|
|---|
| 591 |
UInt32 ACBaseCodec::GetMagicCookieByteSize() const |
|---|
| 592 |
{ |
|---|
| 593 |
return 0; |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
void ACBaseCodec::GetMagicCookie(void* outMagicCookieData, UInt32& ioMagicCookieDataByteSize) const |
|---|
| 597 |
{ |
|---|
| 598 |
ioMagicCookieDataByteSize = 0; |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
void ACBaseCodec::SetMagicCookie(const void* outMagicCookieData, UInt32 inMagicCookieDataByteSize) |
|---|
| 602 |
{ |
|---|
| 603 |
if(mIsInitialized) |
|---|
| 604 |
{ |
|---|
| 605 |
CODEC_THROW(kAudioCodecStateError); |
|---|
| 606 |
} |
|---|
| 607 |
} |
|---|
| 608 |
|
|---|
| 609 |
void ACBaseCodec::AddInputFormat(const AudioStreamBasicDescription& inInputFormat) |
|---|
| 610 |
{ |
|---|
| 611 |
FormatList::iterator theIterator = std::find(mInputFormatList.begin(), mInputFormatList.end(), inInputFormat); |
|---|
| 612 |
if(theIterator == mInputFormatList.end()) |
|---|
| 613 |
{ |
|---|
| 614 |
theIterator = std::lower_bound(mInputFormatList.begin(), mInputFormatList.end(), inInputFormat); |
|---|
| 615 |
mInputFormatList.insert(theIterator, inInputFormat); |
|---|
| 616 |
} |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
void ACBaseCodec::AddOutputFormat(const AudioStreamBasicDescription& inOutputFormat) |
|---|
| 620 |
{ |
|---|
| 621 |
FormatList::iterator theIterator = std::find(mOutputFormatList.begin(), mOutputFormatList.end(), inOutputFormat); |
|---|
| 622 |
if(theIterator == mOutputFormatList.end()) |
|---|
| 623 |
{ |
|---|
| 624 |
theIterator = std::lower_bound(mOutputFormatList.begin(), mOutputFormatList.end(), inOutputFormat); |
|---|
| 625 |
mOutputFormatList.insert(theIterator, inOutputFormat); |
|---|
| 626 |
} |
|---|
| 627 |
} |
|---|