replicate the remove-all-trailing whitespace commit(s) in master

This commit is contained in:
Paul Davis 2015-10-26 14:35:06 -04:00
parent 589f2a1ab8
commit bc487bb4b0
235 changed files with 5833 additions and 5840 deletions

View file

@ -2,14 +2,14 @@
File: CAStreamBasicDescription.cpp
Abstract: CAStreamBasicDescription.h
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
@ -25,13 +25,13 @@
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@ -40,9 +40,9 @@
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014 Apple Inc. All Rights Reserved.
*/
#include "CAStreamBasicDescription.h"
#include "CAMath.h"
@ -72,12 +72,12 @@ char *CAStringForOSType (OSType t, char *writeLocation, size_t bufsize)
q++;
}
q = u.str;
if (hasNonPrint)
p += snprintf (p, pend - p, "0x");
else if (p < pend)
*p++ = '\'';
for (int i = 0; i < 4 && p < pend; ++i) {
if (hasNonPrint) {
p += snprintf(p, pend - p, "%02X", *q++);
@ -96,11 +96,11 @@ char *CAStringForOSType (OSType t, char *writeLocation, size_t bufsize)
const AudioStreamBasicDescription CAStreamBasicDescription::sEmpty = { 0.0, 0, 0, 0, 0, 0, 0, 0, 0 };
CAStreamBasicDescription::CAStreamBasicDescription()
{
memset (this, 0, sizeof(AudioStreamBasicDescription));
CAStreamBasicDescription::CAStreamBasicDescription()
{
memset (this, 0, sizeof(AudioStreamBasicDescription));
}
CAStreamBasicDescription::CAStreamBasicDescription(const AudioStreamBasicDescription &desc)
{
SetFrom(desc);
@ -165,15 +165,15 @@ char *CAStreamBasicDescription::AsString(char *buf, size_t _bufsize, bool brief
return theBuffer;
}
}
nc = snprintf(buf, static_cast<size_t>(bufsize), "%2d ch, %6.0f Hz, %s (0x%08X) ", (int)NumberChannels(), mSampleRate, formatID, (int)mFormatFlags);
buf += nc; if ((bufsize -= nc) <= 0) goto exit;
if (mFormatID == kAudioFormatLinearPCM) {
bool isInt = !(mFormatFlags & kLinearPCMFormatFlagIsFloat);
int wordSize = static_cast<int>(SampleWordSize());
const char *endian = (wordSize > 1) ?
const char *endian = (wordSize > 1) ?
((mFormatFlags & kLinearPCMFormatFlagIsBigEndian) ? " big-endian" : " little-endian" ) : "";
const char *sign = isInt ?
const char *sign = isInt ?
((mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) ? " signed" : " unsigned") : "";
const char *floatInt = isInt ? "integer" : "float";
char packed[32];
@ -195,9 +195,9 @@ char *CAStreamBasicDescription::AsString(char *buf, size_t _bufsize, bool brief
snprintf(bitdepth, sizeof(bitdepth), "%d.%d", (int)mBitsPerChannel - fracbits, fracbits);
else
snprintf(bitdepth, sizeof(bitdepth), "%d", (int)mBitsPerChannel);
/*nc =*/ snprintf(buf, static_cast<size_t>(bufsize), "%s-bit%s%s %s%s%s%s%s",
bitdepth, endian, sign, floatInt,
bitdepth, endian, sign, floatInt,
commaSpace, packed, align, deinter);
// buf += nc; if ((bufsize -= nc) <= 0) goto exit;
} else if (mFormatID == kAudioFormatAppleLossless) {
@ -226,7 +226,7 @@ char *CAStreamBasicDescription::AsString(char *buf, size_t _bufsize, bool brief
// buf += nc; if ((bufsize -= nc) <= 0) goto exit;
}
else
/*nc =*/ snprintf(buf, static_cast<size_t>(bufsize), "%d bits/channel, %d bytes/packet, %d frames/packet, %d bytes/frame",
/*nc =*/ snprintf(buf, static_cast<size_t>(bufsize), "%d bits/channel, %d bytes/packet, %d frames/packet, %d bytes/frame",
(int)mBitsPerChannel, (int)mBytesPerPacket, (int)mFramesPerPacket, (int)mBytesPerFrame);
exit:
return theBuffer;
@ -328,7 +328,7 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
outName += theCharactersWritten;
inMaxNameLength -= static_cast<UInt32>(theCharactersWritten);
}
switch(inDescription.mFormatID)
{
case kAudioFormatLinearPCM:
@ -346,7 +346,7 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
theEndianString = "Little Endian";
#endif
}
const char* theKindString = NULL;
if((inDescription.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
{
@ -360,7 +360,7 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
{
theKindString = (inAbbreviate ? "UInt" : "Unsigned Integer");
}
const char* thePackingString = NULL;
if((inDescription.mFormatFlags & kAudioFormatFlagIsPacked) == 0)
{
@ -373,7 +373,7 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
thePackingString = "Low";
}
}
const char* theMixabilityString = NULL;
if((inDescription.mFormatFlags & kIsNonMixableFlag) == 0)
{
@ -383,7 +383,7 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
{
theMixabilityString = "Unmixable";
}
if(inAbbreviate)
{
if(theEndianString != NULL)
@ -436,15 +436,15 @@ void CAStreamBasicDescription::GetSimpleName(const AudioStreamBasicDescription&
}
}
break;
case kAudioFormatAC3:
strlcpy(outName, "AC-3", sizeof(outName));
break;
case kAudioFormat60958AC3:
strlcpy(outName, "AC-3 for SPDIF", sizeof(outName));
break;
default:
CACopy4CCToCString(outName, inDescription.mFormatID);
break;
@ -471,9 +471,9 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
{
bool theAnswer = false;
bool isDone = false;
// note that if either side is 0, that field is skipped
// format ID is the first order sort
if((!isDone) && ((x.mFormatID != 0) && (y.mFormatID != 0)))
{
@ -496,8 +496,8 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
isDone = true;
}
}
// mixable is always better than non-mixable for linear PCM and should be the second order sort item
if((!isDone) && ((x.mFormatID == kAudioFormatLinearPCM) && (y.mFormatID == kAudioFormatLinearPCM)))
{
@ -512,7 +512,7 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
isDone = true;
}
}
// floating point vs integer for linear PCM only
if((!isDone) && ((x.mFormatID == kAudioFormatLinearPCM) && (y.mFormatID == kAudioFormatLinearPCM)))
{
@ -523,7 +523,7 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
isDone = true;
}
}
// bit depth
if((!isDone) && ((x.mBitsPerChannel != 0) && (y.mBitsPerChannel != 0)))
{
@ -534,7 +534,7 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
isDone = true;
}
}
// sample rate
if((!isDone) && fnonzero(x.mSampleRate) && fnonzero(y.mSampleRate))
{
@ -545,7 +545,7 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
isDone = true;
}
}
// number of channels
if((!isDone) && ((x.mChannelsPerFrame != 0) && (y.mChannelsPerFrame != 0)))
{
@ -556,7 +556,7 @@ bool operator<(const AudioStreamBasicDescription& x, const AudioStreamBasicDescr
//isDone = true;
}
}
return theAnswer;
}
@ -569,24 +569,24 @@ void CAStreamBasicDescription::ModifyFormatFlagsForMatching(const AudioStreamBas
xFlags = yFlags = 0;
return;
}
if (x.mFormatID == kAudioFormatLinearPCM) {
// knock off the all clear flag
xFlags = xFlags & ~kAudioFormatFlagsAreAllClear;
yFlags = yFlags & ~kAudioFormatFlagsAreAllClear;
// if both kAudioFormatFlagIsPacked bits are set, then we don't care about the kAudioFormatFlagIsAlignedHigh bit.
if (xFlags & yFlags & kAudioFormatFlagIsPacked) {
xFlags = xFlags & ~static_cast<UInt32>(kAudioFormatFlagIsAlignedHigh);
yFlags = yFlags & ~static_cast<UInt32>(kAudioFormatFlagIsAlignedHigh);
}
// if both kAudioFormatFlagIsFloat bits are set, then we don't care about the kAudioFormatFlagIsSignedInteger bit.
if (xFlags & yFlags & kAudioFormatFlagIsFloat) {
xFlags = xFlags & ~static_cast<UInt32>(kAudioFormatFlagIsSignedInteger);
yFlags = yFlags & ~static_cast<UInt32>(kAudioFormatFlagIsSignedInteger);
}
// if the bit depth is 8 bits or less and the format is packed, we don't care about endianness
if((x.mBitsPerChannel <= 8) && ((xFlags & kAudioFormatFlagIsPacked) == kAudioFormatFlagIsPacked))
{
@ -596,13 +596,13 @@ void CAStreamBasicDescription::ModifyFormatFlagsForMatching(const AudioStreamBas
{
yFlags = yFlags & ~static_cast<UInt32>(kAudioFormatFlagIsBigEndian);
}
// if the number of channels is 1, we don't care about non-interleavedness
if (x.mChannelsPerFrame == 1 && y.mChannelsPerFrame == 1) {
xFlags &= ~static_cast<UInt32>(kLinearPCMFormatFlagIsNonInterleaved);
yFlags &= ~static_cast<UInt32>(kLinearPCMFormatFlagIsNonInterleaved);
}
if (converterOnly) {
CAStreamBasicDescription cas_x = CAStreamBasicDescription(x);
CAStreamBasicDescription cas_y = CAStreamBasicDescription(y);
@ -625,7 +625,7 @@ static bool MatchFormatFlags(const AudioStreamBasicDescription& x, const AudioSt
{
UInt32 xFlags = x.mFormatFlags;
UInt32 yFlags = y.mFormatFlags;
CAStreamBasicDescription::ModifyFormatFlagsForMatching(x, y, xFlags, yFlags, false);
return xFlags == yFlags;
}
@ -635,37 +635,37 @@ bool operator==(const AudioStreamBasicDescription& x, const AudioStreamBasicDesc
// the semantics for equality are:
// 1) Values must match exactly -- except for PCM format flags, see above.
// 2) wildcard's are ignored in the comparison
#define MATCH(name) ((x.name) == 0 || (y.name) == 0 || (x.name) == (y.name))
return
return
// check all but the format flags
CAStreamBasicDescription::FlagIndependentEquivalence(x, y)
// check the format flags
&& MatchFormatFlags(x, y);
&& MatchFormatFlags(x, y);
}
bool CAStreamBasicDescription::FlagIndependentEquivalence(const AudioStreamBasicDescription &x, const AudioStreamBasicDescription &y)
{
return
return
// check the sample rate
(fiszero(x.mSampleRate) || fiszero(y.mSampleRate) || fequal(x.mSampleRate, y.mSampleRate))
// check the format ids
&& MATCH(mFormatID)
// check the bytes per packet
&& MATCH(mBytesPerPacket)
&& MATCH(mBytesPerPacket)
// check the frames per packet
&& MATCH(mFramesPerPacket)
&& MATCH(mFramesPerPacket)
// check the bytes per frame
&& MATCH(mBytesPerFrame)
&& MATCH(mBytesPerFrame)
// check the channels per frame
&& MATCH(mChannelsPerFrame)
&& MATCH(mChannelsPerFrame)
// check the channels per frame
&& MATCH(mBitsPerChannel) ;
}
@ -679,15 +679,15 @@ bool CAStreamBasicDescription::IsEqual(const AudioStreamBasicDescription &other,
bool CAStreamBasicDescription::IsFunctionallyEquivalent(const AudioStreamBasicDescription &x, const AudioStreamBasicDescription &y)
{
UInt32 xFlags = x.mFormatFlags, yFlags = y.mFormatFlags;
UInt32 xFlags = x.mFormatFlags, yFlags = y.mFormatFlags;
CAStreamBasicDescription::ModifyFormatFlagsForMatching(x, y, xFlags, yFlags, true);
return
// check all but the format flags
CAStreamBasicDescription::FlagIndependentEquivalence(x, y)
// check the format flags with converter focus
&& (xFlags == yFlags);
}
bool SanityCheck(const AudioStreamBasicDescription& x)
@ -695,9 +695,9 @@ bool SanityCheck(const AudioStreamBasicDescription& x)
// This function returns false if there are sufficiently insane values in any field.
// It is very conservative so even some very unlikely values will pass.
// This is just meant to catch the case where the data from a file is corrupted.
return
(x.mSampleRate >= 0.)
return
(x.mSampleRate >= 0.)
&& (x.mSampleRate < 3e6) // SACD sample rate is 2.8224 MHz
&& (x.mBytesPerPacket < 1000000)
&& (x.mFramesPerPacket < 1000000)
@ -711,7 +711,7 @@ bool SanityCheck(const AudioStreamBasicDescription& x)
bool CAStreamBasicDescription::FromText(const char *inTextDesc, AudioStreamBasicDescription &fmt)
{
const char *p = inTextDesc;
memset(&fmt, 0, sizeof(fmt));
bool isPCM = true; // until proven otherwise
@ -764,18 +764,18 @@ bool CAStreamBasicDescription::FromText(const char *inTextDesc, AudioStreamBasic
p += 2;
}
}
if (strchr("-@/#", buf[3])) {
// further special-casing for 'aac'
buf[3] = ' ';
--p;
}
memcpy(&fmt.mFormatID, buf, 4);
fmt.mFormatID = CFSwapInt32BigToHost(fmt.mFormatID);
}
}
if (isPCM) {
fmt.mFormatID = kAudioFormatLinearPCM;
fmt.mFormatFlags = pcmFlags;
@ -874,6 +874,6 @@ Bail:
return false;
}
const char *CAStreamBasicDescription::sTextParsingUsageString =
const char *CAStreamBasicDescription::sTextParsingUsageString =
"format[@sample_rate_hz][/format_flags][#frames_per_packet][:LHbytesPerFrame][,channelsDI].\n"
"Format for PCM is [-][BE|LE]{F|I|UI}{bitdepth}; else a 4-char format code (e.g. aac, alac).\n";