|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 |
|
18 #include "backendinfo.h" |
|
19 #include "backendheader.h" |
|
20 |
|
21 #include <AudioToolbox/AudioToolbox.h> |
|
22 #include <AudioUnit/AudioUnit.h> |
|
23 #include <CoreServices/CoreServices.h> |
|
24 |
|
25 #include <QtGui/qmacdefines_mac.h> |
|
26 #import <QTKit/QTMovie.h> |
|
27 |
|
28 #ifdef QUICKTIME_C_API_AVAILABLE |
|
29 #include <QuickTime/QuickTime.h> |
|
30 #undef check // avoid name clash; |
|
31 #endif |
|
32 |
|
33 QT_BEGIN_NAMESPACE |
|
34 |
|
35 namespace Phonon |
|
36 { |
|
37 namespace QT7 |
|
38 { |
|
39 |
|
40 QString BackendInfo::quickTimeVersionString() |
|
41 { |
|
42 SInt32 version; |
|
43 OSStatus err = Gestalt(gestaltQuickTimeVersion, &version); |
|
44 if (err != noErr) |
|
45 return QString("00.0.0.0000"); |
|
46 QString versionString = QString("%1%2.%3.%4.%5%6%7%8") |
|
47 .arg((version >> (7*4)) & 0xF) |
|
48 .arg((version >> (6*4)) & 0xF) |
|
49 .arg((version >> (5*4)) & 0xF) |
|
50 .arg((version >> (4*4)) & 0xF) |
|
51 .arg((version >> (3*4)) & 0xF) |
|
52 .arg((version >> (2*4)) & 0xF) |
|
53 .arg((version >> (1*4)) & 0xF) |
|
54 .arg((version >> (0*4)) & 0xF); |
|
55 return versionString; |
|
56 } |
|
57 |
|
58 bool BackendInfo::isQuickTimeVersionAvailable(int minHexVersion) |
|
59 { |
|
60 // minHexVersion == 0x0741 means version 7.4.1 |
|
61 SInt32 qtHexVersion; |
|
62 OSStatus err = Gestalt(gestaltQuickTimeVersion, &qtHexVersion); |
|
63 return (err == noErr) ? ((qtHexVersion >> 16) >= minHexVersion) : 0; |
|
64 } |
|
65 |
|
66 #ifdef QUICKTIME_C_API_AVAILABLE |
|
67 static QString getMimeTypeTag(QTAtomContainer mimeList, int index, OSType type) |
|
68 { |
|
69 QTAtom mimeAtom = QTFindChildByIndex(mimeList, kParentAtomIsContainer, type, index, 0); |
|
70 char mimeCharArray[256]; |
|
71 long length; |
|
72 OSStatus err = QTCopyAtomDataToPtr(mimeList, mimeAtom, true, sizeof(mimeCharArray)-1, mimeCharArray, &length); |
|
73 if (err == noErr) |
|
74 return QString::fromAscii(mimeCharArray, length); |
|
75 return QString(); |
|
76 } |
|
77 #endif // QUICKTIME_C_API_AVAILABLE |
|
78 |
|
79 #ifdef QUICKTIME_C_API_AVAILABLE |
|
80 QStringList BackendInfo::quickTimeMimeTypes(Scope scope) |
|
81 { |
|
82 QStringList mimeTypes; |
|
83 ARGUMENT_UNSUPPORTED(scope, Out, NORMAL_ERROR, mimeTypes) |
|
84 |
|
85 ComponentDescription description; |
|
86 description.componentType = MovieImportType; |
|
87 description.componentSubType = 0; |
|
88 description.componentManufacturer = 0; |
|
89 description.componentFlags = hasMovieImportMIMEList | canMovieImportFiles; |
|
90 description.componentFlagsMask = canMovieImportFiles | movieImportSubTypeIsFileExtension | hasMovieImportMIMEList; |
|
91 Component component = FindNextComponent(0, &description); |
|
92 |
|
93 while (component) { |
|
94 QTAtomContainer mimeList = 0; |
|
95 OSStatus err = MovieImportGetMIMETypeList((MovieImportComponent)component, &mimeList); |
|
96 if (err == noErr){ |
|
97 int count = QTCountChildrenOfType(mimeList, kParentAtomIsContainer, 0); |
|
98 for (int i=1; i<=count; ++i){ |
|
99 QString mimeType = getMimeTypeTag(mimeList, i, kMimeInfoMimeTypeTag); |
|
100 if (mimeType.startsWith(QLatin1String("audio")) || mimeType.startsWith(QLatin1String("video"))){ |
|
101 if (err == noErr && !mimeType.isEmpty()) |
|
102 mimeTypes << mimeType; |
|
103 } |
|
104 } |
|
105 } |
|
106 QTDisposeAtomContainer(mimeList); |
|
107 component = FindNextComponent(component, &description); |
|
108 } |
|
109 mimeTypes.sort(); |
|
110 return mimeTypes; |
|
111 } |
|
112 |
|
113 #else // QUICKTIME_C_API_AVAILABLE == false |
|
114 |
|
115 QString mimeForExtensionAudio(const QString &ext) |
|
116 { |
|
117 if (ext == "3g2") return QLatin1String("audio/3g2"); |
|
118 if (ext == "3gp") return QLatin1String("audio/3gp"); |
|
119 if (ext == "aac") return QLatin1String("audio/aac"); |
|
120 if (ext == "ac3") return QLatin1String("audio/ac3"); |
|
121 if (ext == "aif") return QLatin1String("audio/aif"); |
|
122 if (ext == "aifc") return QLatin1String("audio/aifc"); |
|
123 if (ext == "aiff") return QLatin1String("audio/aiff"); |
|
124 if (ext == "amr") return QLatin1String("audio/amr"); |
|
125 if (ext == "au") return QLatin1String("audio/au"); |
|
126 if (ext == "bwf") return QLatin1String("audio/bwf"); |
|
127 if (ext == "caf") return QLatin1String("audio/caf"); |
|
128 if (ext == "cdda") return QLatin1String("audio/cdda"); |
|
129 if (ext == "gsm") return QLatin1String("audio/gsm"); |
|
130 if (ext == "kar") return QLatin1String("audio/kar"); |
|
131 if (ext == "m1a") return QLatin1String("audio/m1a"); |
|
132 if (ext == "m1s") return QLatin1String("audio/m1s"); |
|
133 if (ext == "m3u") return QLatin1String("audio/m3u"); |
|
134 if (ext == "m3url") return QLatin1String("audio/m3url"); |
|
135 if (ext == "mid") return QLatin1String("audio/mid"); |
|
136 if (ext == "midi") return QLatin1String("audio/midi"); |
|
137 if (ext == "mka") return QLatin1String("audio/mka"); |
|
138 if (ext == "mp3") return QLatin1String("audio/mp3"); |
|
139 if (ext == "mp4") return QLatin1String("audio/mp4"); |
|
140 if (ext == "mpa") return QLatin1String("audio/mpa"); |
|
141 if (ext == "mpeg") return QLatin1String("audio/mpeg"); |
|
142 if (ext == "mpg") return QLatin1String("audio/mpg"); |
|
143 if (ext == "mpg4") return QLatin1String("audio/mpg4"); |
|
144 if (ext == "mpm") return QLatin1String("audio/mpm"); |
|
145 if (ext == "qcp") return QLatin1String("audio/qcp"); |
|
146 if (ext == "sd2") return QLatin1String("audio/sd2"); |
|
147 if (ext == "smf") return QLatin1String("audio/smf"); |
|
148 if (ext == "snd") return QLatin1String("audio/snd"); |
|
149 if (ext == "ulw") return QLatin1String("audio/ulw"); |
|
150 if (ext == "wav") return QLatin1String("audio/wav"); |
|
151 if (ext == "wax") return QLatin1String("audio/wax"); |
|
152 if (ext == "wma") return QLatin1String("audio/wma"); |
|
153 return QString(); |
|
154 } |
|
155 |
|
156 QString mimeForExtensionVideo(const QString &ext) |
|
157 { |
|
158 if (ext == "3g2") return QLatin1String("video/3g2"); |
|
159 if (ext == "3gp") return QLatin1String("video/3gp"); |
|
160 if (ext == "asf") return QLatin1String("video/asf"); |
|
161 if (ext == "asx") return QLatin1String("video/asx"); |
|
162 if (ext == "avi") return QLatin1String("video/avi"); |
|
163 if (ext == "dif") return QLatin1String("video/dif"); |
|
164 if (ext == "dv") return QLatin1String("video/dv"); |
|
165 if (ext == "flc") return QLatin1String("video/flc"); |
|
166 if (ext == "fli") return QLatin1String("video/fli"); |
|
167 if (ext == "m15") return QLatin1String("video/m15"); |
|
168 if (ext == "m1a") return QLatin1String("video/m1a"); |
|
169 if (ext == "m1s") return QLatin1String("video/m1s"); |
|
170 if (ext == "m1v") return QLatin1String("video/m1v"); |
|
171 if (ext == "m75") return QLatin1String("video/m75"); |
|
172 if (ext == "mkv") return QLatin1String("video/mkv"); |
|
173 if (ext == "mp4") return QLatin1String("video/mp4"); |
|
174 if (ext == "mpa") return QLatin1String("video/mpa"); |
|
175 if (ext == "mpeg") return QLatin1String("video/mpeg"); |
|
176 if (ext == "mpg") return QLatin1String("video/mpg"); |
|
177 if (ext == "mpg4") return QLatin1String("video/mpg4"); |
|
178 if (ext == "mpm") return QLatin1String("video/mpm"); |
|
179 if (ext == "mpv") return QLatin1String("video/mpv"); |
|
180 if (ext == "vfw") return QLatin1String("video/vfw"); |
|
181 if (ext == "wm") return QLatin1String("video/wm"); |
|
182 if (ext == "wmv") return QLatin1String("video/wmv"); |
|
183 if (ext == "wmx") return QLatin1String("video/wmx"); |
|
184 if (ext == "wvx") return QLatin1String("video/wvx"); |
|
185 return QString(); |
|
186 } |
|
187 |
|
188 QStringList BackendInfo::quickTimeMimeTypes(Scope scope) |
|
189 { |
|
190 QStringList mimeTypes; |
|
191 QStringList fileExtensions; |
|
192 ARGUMENT_UNSUPPORTED(scope, Out, NORMAL_ERROR, mimeTypes) |
|
193 |
|
194 PhononAutoReleasePool pool; |
|
195 NSArray *fileTypes = [QTMovie movieFileTypes:QTIncludeAllTypes]; |
|
196 for (NSString *type in fileTypes){ |
|
197 QString formattedType = QString::fromUtf8([type UTF8String]); |
|
198 formattedType = formattedType.remove('\'').remove('.').toLower(); |
|
199 QString audioMime = mimeForExtensionAudio(formattedType); |
|
200 QString videoMime = mimeForExtensionVideo(formattedType); |
|
201 if (!audioMime.isEmpty()) |
|
202 mimeTypes << audioMime; |
|
203 if (!videoMime.isEmpty()) |
|
204 mimeTypes << videoMime; |
|
205 if (audioMime.isEmpty() && videoMime.isEmpty()) |
|
206 fileExtensions << QLatin1String("application/x-qt-") + formattedType; |
|
207 } |
|
208 mimeTypes.sort(); |
|
209 fileExtensions.sort(); |
|
210 return mimeTypes + fileExtensions; |
|
211 } |
|
212 #endif // QUICKTIME_C_API_AVAILABLE |
|
213 |
|
214 QStringList BackendInfo::quickTimeCompressionFormats() |
|
215 { |
|
216 QStringList result; |
|
217 |
|
218 #ifdef QUICKTIME_C_API_AVAILABLE |
|
219 |
|
220 ComponentInstance component = 0; |
|
221 OSStatus err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubTypeAudio, &component); |
|
222 BACKEND_ASSERT3(err == noErr, "Could not open component for retrieving awailable compression formats", NORMAL_ERROR, result) |
|
223 |
|
224 UInt32 size; |
|
225 err = QTGetComponentPropertyInfo(component, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_AvailableCompressionFormatNamesList, 0, &size,0); |
|
226 BACKEND_ASSERT3(err == noErr, "Could not get awailable compression formats", NORMAL_ERROR, result) |
|
227 |
|
228 CFArrayRef formats[size]; |
|
229 err = QTGetComponentProperty(component, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_AvailableCompressionFormatNamesList, size, &formats, &size); |
|
230 BACKEND_ASSERT3(err == noErr, "Could not get awailable compression formats", NORMAL_ERROR, result) |
|
231 |
|
232 CFIndex count = CFArrayGetCount(*formats); |
|
233 for (CFIndex i=0; i<count; ++i){ |
|
234 const CFStringRef name = (const struct __CFString *) CFArrayGetValueAtIndex(*formats, i); |
|
235 result << PhononCFString::toQString(name); |
|
236 } |
|
237 |
|
238 #endif // QUICKTIME_C_API_AVAILABLE |
|
239 return result; |
|
240 } |
|
241 |
|
242 |
|
243 QStringList BackendInfo::coreAudioCodecs(Scope scope) |
|
244 { |
|
245 QStringList result; |
|
246 UInt32 size; |
|
247 OSStatus err; |
|
248 OSType *formatIDs; |
|
249 |
|
250 OSType encodersOrDecoders = (scope == In) |
|
251 ? kAudioFormatProperty_EncodeFormatIDs : kAudioFormatProperty_DecodeFormatIDs; |
|
252 |
|
253 err = AudioFormatGetPropertyInfo(encodersOrDecoders, 0, NULL, &size); |
|
254 BACKEND_ASSERT3(err == noErr, "Could not get awailable decoders/encoders", NORMAL_ERROR, result) |
|
255 |
|
256 formatIDs = (OSType*)malloc(size); |
|
257 UInt32 numFormats = size / sizeof(OSType); |
|
258 err = AudioFormatGetProperty(encodersOrDecoders, 0, NULL, &size, formatIDs); |
|
259 BACKEND_ASSERT(err == noErr, "Could not get awailable decoders/encoders", NORMAL_ERROR){ |
|
260 free(formatIDs); |
|
261 return result; |
|
262 } |
|
263 |
|
264 for (UInt32 i=0; i<numFormats; ++i){ |
|
265 AudioStreamBasicDescription absd; |
|
266 memset(&absd, 0, sizeof(absd)); |
|
267 absd.mFormatID = formatIDs[i]; |
|
268 |
|
269 CFStringRef name; |
|
270 size = sizeof(CFStringRef); |
|
271 err = AudioFormatGetProperty(kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name); |
|
272 BACKEND_ASSERT(err == noErr, "Could not get awailable decoder/encoder names", NORMAL_ERROR){ |
|
273 free(formatIDs); |
|
274 return result; |
|
275 } |
|
276 result << PhononCFString::toQString(name); |
|
277 } |
|
278 free(formatIDs); |
|
279 return result; |
|
280 } |
|
281 |
|
282 QStringList BackendInfo::coreAudioFileTypes(Scope scope) |
|
283 { |
|
284 QStringList result; |
|
285 OSStatus err; |
|
286 UInt32 propertySize; |
|
287 |
|
288 OSType readOrwrite = (scope == In) |
|
289 ? kAudioFileGlobalInfo_ReadableTypes : kAudioFileGlobalInfo_WritableTypes; |
|
290 |
|
291 err = AudioFileGetGlobalInfoSize(readOrwrite, 0, NULL, &propertySize); |
|
292 BACKEND_ASSERT3(err == noErr, "Could not get core audio file types", NORMAL_ERROR, result) |
|
293 |
|
294 OSType *types = (OSType*)malloc(propertySize); |
|
295 err = AudioFileGetGlobalInfo(readOrwrite, 0, NULL, &propertySize, types); |
|
296 BACKEND_ASSERT3(err == noErr, "Could not get core audio file types", NORMAL_ERROR, result) |
|
297 |
|
298 UInt32 numTypes = propertySize / sizeof(OSType); |
|
299 for (UInt32 i=0; i<numTypes; ++i){ |
|
300 CFStringRef name; |
|
301 UInt32 outSize = sizeof(name); |
|
302 err = AudioFileGetGlobalInfo(kAudioFileGlobalInfo_FileTypeName, sizeof(OSType), types+i, &outSize, &name); |
|
303 BACKEND_ASSERT3(err == noErr, "Could not get core audio file type names", NORMAL_ERROR, result) |
|
304 result << PhononCFString::toQString(name); |
|
305 } |
|
306 return result; |
|
307 } |
|
308 |
|
309 }} |
|
310 |
|
311 QT_END_NAMESPACE |
|
312 |