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

Pending
author Chris Cannam
date Mon, 09 Feb 2015 10:27:21 +0000
parents d03b3d956358
children
line wrap: on
line diff
--- a/data/fileio/CoreAudioFileReader.cpp	Mon Dec 08 15:37:12 2014 +0000
+++ b/data/fileio/CoreAudioFileReader.cpp	Mon Feb 09 10:27:21 2015 +0000
@@ -88,18 +88,7 @@
          (CFIndex)ba.length(),
          false);
 
-    //!!! how do we find out if the file open fails because of DRM protection?
-
-//#if (MACOSX_DEPLOYMENT_TARGET <= 1040 && MAC_OS_X_VERSION_MIN_REQUIRED <= 1040)
-//    FSRef fsref;
-//    if (!CFURLGetFSRef(url, &fsref)) { // returns Boolean, not error code
-//        m_error = "CoreAudioReadStream: Error looking up FS ref (file not found?)";
-//        return;
-//    }
-//    m_d->err = ExtAudioFileOpen(&fsref, &m_d->file);
-//#else
     m_d->err = ExtAudioFileOpenURL(url, &m_d->file);
-//#endif
 
     CFRelease(url);
 
@@ -154,6 +143,7 @@
 
     m_d->valid = true;
 
+    readMetadata();
     initialiseDecodeCache();
 
     if (m_reporter) {
@@ -189,7 +179,6 @@
     m_completion = 100;
 }
 
-
 CoreAudioFileReader::~CoreAudioFileReader()
 {
     cerr << "CoreAudioFileReader::~CoreAudioFileReader" << endl;
@@ -203,6 +192,45 @@
 }
 
 void
+CoreAudioFileReader::readMetadata()
+{
+    AudioFileID audiofile;
+    UInt32 propsize = sizeof(AudioFileID);
+
+    // err is local, failures here are only warnings
+    OSStatus err = noErr;
+    
+    err = ExtAudioFileGetProperty
+	(m_d->file, kExtAudioFileProperty_AudioFile, &propsize, &audiofile);
+
+    if (err) {
+        cerr << "WARNING: CoreAudioReadStream: Error in getting underlying audio file: code " << codestr(err) << endl;
+        return;
+    }
+
+    propsize = 0;
+    char *data = 0;
+    err = AudioFileGetPropertyInfo
+        (audiofile, kAudioFilePropertyID3Tag, &propsize, 0);
+    if (err) {
+        cerr << "WARNING: CoreAudioReadStream: Failed to get id3 tag size: code " << codestr(err) << endl;
+        return;
+    }
+
+    data = new char[propsize];
+    err = AudioFileGetProperty
+        (audiofile, kAudioFilePropertyID3Tag, &propsize, data);
+    if (err) {
+        cerr << "WARNING: CoreAudioReadStream: Failed to read id3 tag data: code " << codestr(err) << endl;
+        return;
+    }
+
+    
+    
+    delete[] data;
+}
+
+void
 CoreAudioFileReader::cancelled()
 {
   m_cancelled = true;