changeset 1026:01a90c025eaa coreaudio-metadata

Pending
author Chris Cannam
date Mon, 09 Feb 2015 10:27:21 +0000
parents 88b54a185a0a
children
files data/fileio/CoreAudioFileReader.cpp data/fileio/CoreAudioFileReader.h
diffstat 2 files changed, 44 insertions(+), 12 deletions(-) [+]
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;
--- a/data/fileio/CoreAudioFileReader.h	Mon Dec 08 15:37:12 2014 +0000
+++ b/data/fileio/CoreAudioFileReader.h	Mon Feb 09 10:27:21 2015 +0000
@@ -47,6 +47,7 @@
     virtual QString getError() const { return m_error; }
     virtual QString getLocation() const { return m_source.getLocation(); }
     virtual QString getTitle() const { return m_title; }
+    virtual QString getMaker() const { return m_maker; }
     
     static void getSupportedExtensions(std::set<QString> &extensions);
     static bool supportsExtension(QString ext);
@@ -67,6 +68,7 @@
     QString m_path;
     QString m_error;
     QString m_title;
+    QString m_maker;
 
     class D;
     D *m_d;
@@ -86,6 +88,8 @@
     };
 
     DecodeThread *m_decodeThread;
+
+    void readMetadata();
 };
 
 #endif