comparison data/fileio/CoreAudioFileReader.cpp @ 1026:01a90c025eaa coreaudio-metadata

Pending
author Chris Cannam
date Mon, 09 Feb 2015 10:27:21 +0000
parents d03b3d956358
children
comparison
equal deleted inserted replaced
1025:88b54a185a0a 1026:01a90c025eaa
86 (kCFAllocatorDefault, 86 (kCFAllocatorDefault,
87 (const UInt8 *)ba.data(), 87 (const UInt8 *)ba.data(),
88 (CFIndex)ba.length(), 88 (CFIndex)ba.length(),
89 false); 89 false);
90 90
91 //!!! how do we find out if the file open fails because of DRM protection?
92
93 //#if (MACOSX_DEPLOYMENT_TARGET <= 1040 && MAC_OS_X_VERSION_MIN_REQUIRED <= 1040)
94 // FSRef fsref;
95 // if (!CFURLGetFSRef(url, &fsref)) { // returns Boolean, not error code
96 // m_error = "CoreAudioReadStream: Error looking up FS ref (file not found?)";
97 // return;
98 // }
99 // m_d->err = ExtAudioFileOpen(&fsref, &m_d->file);
100 //#else
101 m_d->err = ExtAudioFileOpenURL(url, &m_d->file); 91 m_d->err = ExtAudioFileOpenURL(url, &m_d->file);
102 //#endif
103 92
104 CFRelease(url); 93 CFRelease(url);
105 94
106 if (m_d->err) { 95 if (m_d->err) {
107 m_error = "CoreAudioReadStream: Error opening file: code " + codestr(m_d->err); 96 m_error = "CoreAudioReadStream: Error opening file: code " + codestr(m_d->err);
152 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; 141 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize;
153 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; 142 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize];
154 143
155 m_d->valid = true; 144 m_d->valid = true;
156 145
146 readMetadata();
157 initialiseDecodeCache(); 147 initialiseDecodeCache();
158 148
159 if (m_reporter) { 149 if (m_reporter) {
160 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled())); 150 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled()));
161 m_reporter->setMessage 151 m_reporter->setMessage
187 endSerialised(); 177 endSerialised();
188 178
189 m_completion = 100; 179 m_completion = 100;
190 } 180 }
191 181
192
193 CoreAudioFileReader::~CoreAudioFileReader() 182 CoreAudioFileReader::~CoreAudioFileReader()
194 { 183 {
195 cerr << "CoreAudioFileReader::~CoreAudioFileReader" << endl; 184 cerr << "CoreAudioFileReader::~CoreAudioFileReader" << endl;
196 185
197 if (m_d->valid) { 186 if (m_d->valid) {
198 ExtAudioFileDispose(m_d->file); 187 ExtAudioFileDispose(m_d->file);
199 delete[] m_d->buffer.mBuffers[0].mData; 188 delete[] m_d->buffer.mBuffers[0].mData;
200 } 189 }
201 190
202 delete m_d; 191 delete m_d;
192 }
193
194 void
195 CoreAudioFileReader::readMetadata()
196 {
197 AudioFileID audiofile;
198 UInt32 propsize = sizeof(AudioFileID);
199
200 // err is local, failures here are only warnings
201 OSStatus err = noErr;
202
203 err = ExtAudioFileGetProperty
204 (m_d->file, kExtAudioFileProperty_AudioFile, &propsize, &audiofile);
205
206 if (err) {
207 cerr << "WARNING: CoreAudioReadStream: Error in getting underlying audio file: code " << codestr(err) << endl;
208 return;
209 }
210
211 propsize = 0;
212 char *data = 0;
213 err = AudioFileGetPropertyInfo
214 (audiofile, kAudioFilePropertyID3Tag, &propsize, 0);
215 if (err) {
216 cerr << "WARNING: CoreAudioReadStream: Failed to get id3 tag size: code " << codestr(err) << endl;
217 return;
218 }
219
220 data = new char[propsize];
221 err = AudioFileGetProperty
222 (audiofile, kAudioFilePropertyID3Tag, &propsize, data);
223 if (err) {
224 cerr << "WARNING: CoreAudioReadStream: Failed to read id3 tag data: code " << codestr(err) << endl;
225 return;
226 }
227
228
229
230 delete[] data;
203 } 231 }
204 232
205 void 233 void
206 CoreAudioFileReader::cancelled() 234 CoreAudioFileReader::cancelled()
207 { 235 {