1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
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.
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.
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.
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.
41 /*=============================================================================
42 CAAudioChannelLayout.h
44 =============================================================================*/
45 #if !defined(__CAAudioChannelLayout_h__)
46 #define __CAAudioChannelLayout_h__
48 //=============================================================================
50 //=============================================================================
53 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
54 #include <CoreAudio/CoreAudioTypes.h>
55 #include <CoreFoundation/CoreFoundation.h>
57 #include <CoreAudioTypes.h>
58 #include <CoreFoundation.h>
65 #include "CAReferenceCounted.h"
68 //=============================================================================
69 // CAAudioChannelLayout
70 //=============================================================================
72 bool operator== (const AudioChannelLayout
&x
, const AudioChannelLayout
&y
);
74 extern "C" void CAShowAudioChannelLayout (FILE* file
, const AudioChannelLayout
*layout
);
76 class CAAudioChannelLayout
78 // static Construction/Destruction
80 static AudioChannelLayout
* Create(UInt32 inNumberChannelDescriptions
);
81 static void Destroy(AudioChannelLayout
* inChannelLayout
);
82 static UInt32
CalculateByteSize(UInt32 inNumberChannelDescriptions
) {
83 return offsetof(AudioChannelLayout
, mChannelDescriptions
) + inNumberChannelDescriptions
* sizeof(AudioChannelDescription
);
85 static void SetAllToUnknown(AudioChannelLayout
& outChannelLayout
, UInt32 inNumberChannelDescriptions
);
86 static UInt32
NumberChannels(const AudioChannelLayout
& inLayout
);
91 CAAudioChannelLayout ();
93 CAAudioChannelLayout (UInt32 inNumberChannels
, bool inChooseSurround
);
94 // if inChooseSurround is false, then symmetrical speaker arrangements
95 // are chosen in place of surround layouts if there is a choice
96 // This call chooses layouts based on the expected defaults in
98 CAAudioChannelLayout (AudioChannelLayoutTag inTag
);
99 CAAudioChannelLayout (const CAAudioChannelLayout
&c
);
100 CAAudioChannelLayout (const AudioChannelLayout
* inChannelLayout
);
101 ~CAAudioChannelLayout();
103 CAAudioChannelLayout
& operator= (const AudioChannelLayout
* inChannelLayout
);
104 CAAudioChannelLayout
& operator= (const CAAudioChannelLayout
& c
);
105 bool operator== (const CAAudioChannelLayout
&c
) const;
107 void SetWithTag(AudioChannelLayoutTag inTag
);
109 bool IsValid() const { return NumberChannels() > 0; }
110 UInt32
Size() const { return mLayoutHolder
? mLayoutHolder
->Size() : 0; }
112 UInt32
NumberChannels() const { return mLayoutHolder
->NumberChannels(); }
114 AudioChannelLayoutTag
Tag() const { return Layout().mChannelLayoutTag
; }
115 const AudioChannelLayout
& Layout() const { return mLayoutHolder
->Layout(); }
116 operator const AudioChannelLayout
*() const { return &Layout(); }
118 void Print () const { Print (stdout
); }
119 void Print (FILE* file
) const;
121 OSStatus
Save (CFPropertyListRef
*outData
) const;
122 OSStatus
Restore (CFPropertyListRef
&inData
);
125 class ACLRefCounter
: public CAReferenceCounted
{
127 ACLRefCounter (UInt32 inDataSize
)
129 if (inDataSize
< offsetof(AudioChannelLayout
, mChannelDescriptions
))
130 inDataSize
= offsetof(AudioChannelLayout
, mChannelDescriptions
);
132 mLayout
= static_cast<AudioChannelLayout
*>(malloc (inDataSize
));
133 memset (mLayout
, 0, inDataSize
);
134 mByteSize
= inDataSize
;
137 const AudioChannelLayout
& Layout() const { return *mLayout
; }
139 UInt32
Size () const { return mByteSize
; }
141 UInt32
NumberChannels() { return mLayout
? CAAudioChannelLayout::NumberChannels(Layout()) : 0; }
144 AudioChannelLayout
*mLayout
;
147 // only the constructors can change the actual state of the layout
148 friend CAAudioChannelLayout::CAAudioChannelLayout (UInt32 inNumberChannels
, bool inChooseSurround
);
149 friend OSStatus
CAAudioChannelLayout::Restore (CFPropertyListRef
&inData
);
150 friend CAAudioChannelLayout
& CAAudioChannelLayout::operator= (const AudioChannelLayout
* inChannelLayout
);
151 friend void CAAudioChannelLayout::SetWithTag(AudioChannelLayoutTag inTag
);
153 AudioChannelLayout
* GetLayout() { return mLayout
; }
154 ~ACLRefCounter() { if (mLayout
) { free(mLayout
); mLayout
= NULL
; } }
157 ACLRefCounter () : mLayout(NULL
) { }
158 ACLRefCounter(const ACLRefCounter
& c
) : mLayout(NULL
) { }
159 ACLRefCounter
& operator=(const ACLRefCounter
& c
) { return *this; }
162 ACLRefCounter
*mLayoutHolder
;