41 #ifndef __CAAudioFileFormats_h__
42 #define __CAAudioFileFormats_h__
44 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
45 #include <AudioToolbox/AudioToolbox.h>
47 #include <AudioToolbox.h>
49 #include "CAStreamBasicDescription.h"
51 class CAAudioFileFormats {
55 struct DataFormatInfo {
56 DataFormatInfo() : mVariants(NULL) { }
57 ~DataFormatInfo() {
delete[] mVariants; }
61 AudioStreamBasicDescription * mVariants;
64 bool mEitherEndianPCM;
71 struct FileFormatInfo {
72 FileFormatInfo() : mFileTypeName(NULL), mExtensions(NULL), mDataFormats(NULL) { }
74 delete[] mDataFormats;
76 CFRelease(mFileTypeName);
78 CFRelease(mExtensions);
81 AudioFileTypeID mFileTypeID;
82 CFStringRef mFileTypeName;
83 CFArrayRef mExtensions;
85 DataFormatInfo * mDataFormats;
87 int NumberOfExtensions() {
return mExtensions ? CFArrayGetCount(mExtensions) : 0; }
88 char * GetExtension(
int index,
char *buf,
int buflen) {
89 CFStringRef cfext = (CFStringRef)CFArrayGetValueAtIndex(mExtensions, index);
90 CFStringGetCString(cfext, buf, buflen, kCFStringEncodingUTF8);
93 bool MatchExtension(CFStringRef testExt) {
94 CFIndex n = NumberOfExtensions();
95 for (CFIndex i = 0; i < n; ++i) {
96 CFStringRef ext = (CFStringRef)CFArrayGetValueAtIndex(mExtensions, i);
97 if (CFStringCompare(ext, testExt, kCFCompareCaseInsensitive) == kCFCompareEqualTo)
102 bool AnyWritableFormats();
103 void LoadDataFormats();
111 CAAudioFileFormats(
bool loadDataFormats);
112 ~CAAudioFileFormats();
115 bool InferDataFormatFromFileFormat(AudioFileTypeID filetype, CAStreamBasicDescription &fmt);
117 bool InferFileFormatFromFilename(
const char *filename, AudioFileTypeID &filetype);
119 bool InferFileFormatFromFilename(CFStringRef filename, AudioFileTypeID &filetype);
121 bool InferFileFormatFromDataFormat(
const CAStreamBasicDescription &fmt, AudioFileTypeID &filetype);
123 bool IsKnownDataFormat(UInt32 dataFormat);
130 FileFormatInfo * mFileFormats;
132 FileFormatInfo * FindFileFormat(UInt32 formatID);
134 static CAAudioFileFormats * Instance(
bool loadDataFormats=
true);
137 static CAAudioFileFormats * sInstance;
140 char * OSTypeToStr(
char *buf, UInt32 t);
141 int StrToOSType(
const char *str, UInt32 &t);
143 #endif // __CAAudioFileFormats_h__