~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/AudioToolbox/AudioFileGlobalInfo.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// AudioFileGlobalInfo.cs:
 
3
//
 
4
// Authors:
 
5
//    Marek Safar (marek.safar@gmail.com)
 
6
//     
 
7
// Copyright 2012 Xamarin Inc.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.IO;
 
31
using System.Collections.Generic;
 
32
using System.Runtime.InteropServices;
 
33
using MonoMac.CoreFoundation;
 
34
using MonoMac.Foundation;
 
35
 
 
36
namespace MonoMac.AudioToolbox {
 
37
 
 
38
        public unsafe static class AudioFileGlobalInfo
 
39
        {
 
40
                public static AudioFileType[] ReadableTypes {
 
41
                        get {
 
42
                                uint size;
 
43
                                if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.ReadableTypes, 0, IntPtr.Zero, out size) != 0)
 
44
                                        return null;
 
45
 
 
46
                                var data = new AudioFileType[size / sizeof (AudioFileType)];
 
47
                                fixed (AudioFileType* ptr = data) {
 
48
                                        var res = AudioFileGetGlobalInfo (AudioFileGlobalProperty.ReadableTypes, 0, IntPtr.Zero, ref size, ptr);
 
49
                                        if (res != 0)
 
50
                                                return null;
 
51
 
 
52
                                        return data;
 
53
                                }
 
54
                        }
 
55
                }
 
56
 
 
57
                public static AudioFileType[] WritableTypes {
 
58
                        get {
 
59
                                uint size;
 
60
                                if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.WritableTypes, 0, IntPtr.Zero, out size) != 0)
 
61
                                        return null;
 
62
 
 
63
                                var data = new AudioFileType[size / sizeof (AudioFileType)];
 
64
                                fixed (AudioFileType* ptr = data) {
 
65
                                        var res = AudioFileGetGlobalInfo (AudioFileGlobalProperty.WritableTypes, 0, IntPtr.Zero, ref size, ptr);
 
66
                                        if (res != 0)
 
67
                                                return null;
 
68
 
 
69
                                        return data;
 
70
                                }
 
71
                        }
 
72
                }
 
73
 
 
74
                public static string GetFileTypeName (AudioFileType fileType)
 
75
                {
 
76
                        IntPtr ptr;
 
77
                        var size = (uint) sizeof (IntPtr);
 
78
                        if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.FileTypeName, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0)
 
79
                                return null;
 
80
 
 
81
                        return CFString.FetchString (ptr);
 
82
                }
 
83
 
 
84
                public static AudioFormatType[] GetAvailableFormats (AudioFileType fileType)
 
85
                {
 
86
                        uint size;
 
87
                        if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.AvailableFormatIDs, sizeof (AudioFileType), ref fileType, out size) != 0)
 
88
                                return null;
 
89
 
 
90
                        var data = new AudioFormatType[size / sizeof (AudioFormatType)];
 
91
                        fixed (AudioFormatType* ptr = data) {
 
92
                                var res = AudioFileGetGlobalInfo (AudioFileGlobalProperty.AvailableFormatIDs, sizeof (AudioFormatType), ref fileType, ref size, ptr);
 
93
                                if (res != 0)
 
94
                                        return null;
 
95
 
 
96
                                return data;
 
97
                        }
 
98
                }
 
99
 
 
100
                public static AudioStreamBasicDescription[] GetAvailableStreamDescriptions (AudioFileType fileType, AudioFormatType formatType)
 
101
                {
 
102
                        AudioFileTypeAndFormatID input;
 
103
                        input.FileType = fileType;
 
104
                        input.FormatType = formatType;
 
105
 
 
106
                        uint size;
 
107
                        if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.AvailableStreamDescriptionsForFormat, (uint)sizeof (AudioFileTypeAndFormatID), ref input, out size) != 0)
 
108
                                return null;
 
109
 
 
110
                        var data = new AudioStreamBasicDescription[size / sizeof (AudioStreamBasicDescription)];
 
111
                        fixed (AudioStreamBasicDescription* ptr = data) {
 
112
                                var res = AudioFileGetGlobalInfo (AudioFileGlobalProperty.AvailableStreamDescriptionsForFormat, (uint)sizeof (AudioFileTypeAndFormatID), ref input, ref size, ptr);
 
113
                                if (res != 0)
 
114
                                        return null;
 
115
 
 
116
                                return data;
 
117
                        }
 
118
                }
 
119
 
 
120
                public static string[] AllExtensions {
 
121
                        get {
 
122
                                IntPtr ptr;
 
123
                                var size = (uint) sizeof (IntPtr);
 
124
                                if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllExtensions, 0, IntPtr.Zero, ref size, out ptr) != 0)
 
125
                                        return null;
 
126
                                
 
127
                                return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
128
                        }
 
129
                }
 
130
 
 
131
                public static string[] AllUTIs {
 
132
                        get {
 
133
                                IntPtr ptr;
 
134
                                var size = (uint) sizeof (IntPtr);
 
135
                                if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllUTIs, 0, IntPtr.Zero, ref size, out ptr) != 0)
 
136
                                        return null;
 
137
                                
 
138
                                return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
139
                        }
 
140
                }
 
141
 
 
142
                public static string[] AllMIMETypes {
 
143
                        get {
 
144
                                IntPtr ptr;
 
145
                                var size = (uint) sizeof (IntPtr);
 
146
                                if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllMIMETypes, 0, IntPtr.Zero, ref size, out ptr) != 0)
 
147
                                        return null;
 
148
                                
 
149
                                return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
150
                        }
 
151
                }
 
152
 
 
153
                /*
 
154
                // TODO: Don't have HFSTypeCode 
 
155
                public static HFSTypeCode[] AllHFSTypeCodes {
 
156
                        get {
 
157
                                uint size;
 
158
                                if (AudioFileGetGlobalInfoSize (AudioFileGlobalProperty.AllHFSTypeCodes, 0, IntPtr.Zero, out size) != 0)
 
159
                                        return null;
 
160
 
 
161
                                var data = new HFSTypeCode[size / sizeof (HFSTypeCode)];
 
162
                                fixed (AudioFileType* ptr = data) {
 
163
                                        var res = AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllHFSTypeCodes, 0, IntPtr.Zero, ref size, ptr);
 
164
                                        if (res != 0)
 
165
                                                return null;
 
166
 
 
167
                                        return data;
 
168
                                }
 
169
                        }
 
170
                }
 
171
                */
 
172
 
 
173
                public static string[] GetExtensions (AudioFileType fileType)
 
174
                {
 
175
                        IntPtr ptr;
 
176
                        var size = (uint) sizeof (IntPtr);
 
177
                        if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.ExtensionsForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0)
 
178
                                return null;
 
179
                                
 
180
                        return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
181
                }
 
182
 
 
183
                public static string[] GetUTIs (AudioFileType fileType)
 
184
                {
 
185
                        IntPtr ptr;
 
186
                        var size = (uint) sizeof (IntPtr);
 
187
                        if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.UTIsForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0)
 
188
                                return null;
 
189
                                
 
190
                        return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
191
                }
 
192
 
 
193
                public static string[] GetMIMETypes (AudioFileType fileType)
 
194
                {
 
195
                        IntPtr ptr;
 
196
                        var size = (uint) sizeof (IntPtr);
 
197
                        if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.MIMETypesForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0)
 
198
                                return null;
 
199
                                
 
200
                        return NSArray.ArrayFromHandleFunc (ptr, l => CFString.FetchString (l));
 
201
                }
 
202
 
 
203
/*
 
204
                // TODO: Always returns 0
 
205
                public static AudioFileType? GetTypesForExtension (string extension)
 
206
                {
 
207
                        using (var cfs = new CFString (extension)) {
 
208
                                uint value;
 
209
                                uint size = sizeof (AudioFileType);
 
210
                                if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.TypesForExtension, (uint) Marshal.SizeOf (typeof (IntPtr)), cfs.Handle, ref size, out value) != 0)
 
211
                                        return null;
 
212
 
 
213
                                return (AudioFileType) value;
 
214
                        }
 
215
                }
 
216
*/
 
217
                [DllImport (Constants.AudioToolboxLibrary)]
 
218
                extern static int AudioFileGetGlobalInfoSize (AudioFileGlobalProperty propertyID, uint size, IntPtr inSpecifier, out uint outDataSize);
 
219
 
 
220
                [DllImport (Constants.AudioToolboxLibrary)]
 
221
                extern static int AudioFileGetGlobalInfoSize (AudioFileGlobalProperty propertyID, uint size, ref AudioFileType inSpecifier, out uint outDataSize);
 
222
 
 
223
                [DllImport (Constants.AudioToolboxLibrary)]
 
224
                extern static int AudioFileGetGlobalInfoSize (AudioFileGlobalProperty propertyID, uint size, ref AudioFileTypeAndFormatID inSpecifier, out uint outDataSize);
 
225
 
 
226
                [DllImport (Constants.AudioToolboxLibrary)]
 
227
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, IntPtr inSpecifier, ref uint ioDataSize, AudioFileType* outPropertyData);
 
228
 
 
229
                [DllImport (Constants.AudioToolboxLibrary)]
 
230
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, ref AudioFileType inSpecifier, ref uint ioDataSize, AudioFormatType* outPropertyData);
 
231
 
 
232
                [DllImport (Constants.AudioToolboxLibrary)]
 
233
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, ref AudioFileTypeAndFormatID inSpecifier, ref uint ioDataSize, AudioStreamBasicDescription* outPropertyData);
 
234
 
 
235
                [DllImport (Constants.AudioToolboxLibrary)]
 
236
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, ref AudioFileType inSpecifier, ref uint ioDataSize, out IntPtr outPropertyData);
 
237
 
 
238
                [DllImport (Constants.AudioToolboxLibrary)]
 
239
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, IntPtr inSpecifier, ref uint ioDataSize, out IntPtr outPropertyData);
 
240
 
 
241
                [DllImport (Constants.AudioToolboxLibrary)]
 
242
                extern static int AudioFileGetGlobalInfo (AudioFileGlobalProperty propertyID, uint size, IntPtr inSpecifier, ref uint ioDataSize, out uint outPropertyData);
 
243
        }
 
244
 
 
245
        struct AudioFileTypeAndFormatID
 
246
        {
 
247
                public AudioFileType FileType;
 
248
                public AudioFormatType FormatType;
 
249
        }
 
250
 
 
251
        enum AudioFileGlobalProperty : uint
 
252
        {
 
253
                ReadableTypes           = 0x61667266,   // 'afrf'
 
254
                WritableTypes           = 0x61667766,   // 'afwf'
 
255
                FileTypeName            = 0x66746e6d,   // 'ftnm'
 
256
                AvailableStreamDescriptionsForFormat    = 0x73646964,   // 'sdid'
 
257
                AvailableFormatIDs      = 0x666d6964,   // 'fmid'
 
258
 
 
259
                AllExtensions           = 0x616c7874,   // 'alxt'
 
260
                AllHFSTypeCodes         = 0x61686673,   // 'ahfs'
 
261
                AllUTIs                         = 0x61757469,   // 'auti'
 
262
                AllMIMETypes            = 0x616d696d,   // 'amim'
 
263
 
 
264
                ExtensionsForType       = 0x66657874,   // 'fext'
 
265
//              HFSTypeCodesForType                                     = 'fhfs',
 
266
                UTIsForType                     = 0x66757469,   // 'futi'
 
267
                MIMETypesForType        = 0x666d696d,   // 'fmim'
 
268
        
 
269
                TypesForMIMEType        = 0x746d696d,   // 'tmim'
 
270
                TypesForUTI                     = 0x74757469,   // 'tuti'
 
271
//              TypesForHFSTypeCode                                     = 'thfs',
 
272
                TypesForExtension       = 0x74657874,   // 'text'
 
273
        }
 
274
}