changed: support the new libapetag file API - fixes ape tags on smb:// etc.
authorjmarshallnz <jmarshallnz@svn>
Wed, 29 Sep 2010 19:40:22 +0000 (19:40 +0000)
committerjmarshallnz <jmarshallnz@svn>
Wed, 29 Sep 2010 19:40:22 +0000 (19:40 +0000)
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@34301 568bbfeb-2a22-0410-94d2-cc84cf5bfa90

xbmc/APEv2Tag.cpp
xbmc/APEv2Tag.h
xbmc/DllLibapetag.h

index c6ddfa2..aa6422c 100644 (file)
  */
 
 #include "APEv2Tag.h"
+#include "FileSystem/File.h"
 
+using namespace XFILE;
+
+struct _ape_file_io
+{
+  size_t (*read_func)  (void *ptr, size_t size, size_t nmemb, void *datasource);
+  int    (*seek_func)  (void *datasource, long int offset, int whence);
+  long   (*tell_func)  (void *datasource);
+  void *data;
+};
 
 using namespace MUSIC_INFO;
 
+size_t CAPEv2Tag::fread_callback(void *ptr, size_t size, size_t nmemb, void *fp)
+{
+  CFile *file = (CFile *)fp;
+  return file->Read(ptr, size * nmemb) / size;
+}
+
+int CAPEv2Tag::fseek_callback(void *fp, long int offset, int whence)
+{
+  CFile *file = (CFile *)fp;
+  return (file->Seek(offset, whence) >= 0) ? 0 : -1;
+}
+
+long CAPEv2Tag::ftell_callback(void *fp)
+{
+  CFile *file = (CFile *)fp;
+  return file->GetPosition();
+}
+
 CAPEv2Tag::CAPEv2Tag()
 {
   m_nTrackNum = 0;
@@ -43,7 +71,20 @@ bool CAPEv2Tag::ReadTag(const char* filename)
 
   // Read in our tag using our dll
   apetag *tag = m_dll.apetag_init();
-  m_dll.apetag_read(tag, (char*)filename, 0);
+
+  CFile file;
+  if (!file.Open(filename))
+    return false;
+
+  // Create our file reading class
+  ape_file file_api;
+  memset(&file_api, 0, sizeof(ape_file));
+  file_api.read_func = fread_callback;
+  file_api.seek_func = fseek_callback;
+  file_api.tell_func = ftell_callback;
+  file_api.data = &file;
+
+  m_dll.apetag_read_fp(tag, &file_api, (char *)filename, 0);
   if (!tag)
     return false;
 
index 89e74d8..972435a 100644 (file)
@@ -54,6 +54,11 @@ public:
   char GetRating() { return m_rating; };
   void GetReplayGainFromTag(apetag *tag);
   const CReplayGain &GetReplayGain() { return m_replayGain; };
+
+  static size_t fread_callback(void *ptr, size_t size, size_t nmemb, void *fp);  
+  static int fseek_callback(void *fp, long int offset, int whence);
+  static long ftell_callback(void *fp);
+
 protected:
   CStdString m_strTitle;
   CStdString m_strArtist;
index 0ba40e2..658f006 100644 (file)
@@ -25,6 +25,7 @@
 #include "utils/log.h"
 extern "C" {
 #undef strcasecmp
+#include "lib/libapetag/file_io.h"
 #include "lib/libapetag/apetaglib.h"
 }
 
@@ -33,7 +34,7 @@ class DllLibApeTagInterface
 public:
     virtual ~DllLibApeTagInterface() {}
     virtual int apetag_read (apetag *mem_cnt, char *filename, int flag)=0;
-    virtual int apetag_read_fp (apetag *mem_cnt, FILE * fp, char *filename, int flag)=0;
+    virtual int apetag_read_fp (apetag *mem_cnt, ape_file * fp, char *filename, int flag)=0;
     virtual apetag *apetag_init (void)=0;
     virtual void apetag_free (apetag *mem_cnt)=0;
     virtual int apetag_save (char *filename, apetag *mem_cnt, int flag)=0;
@@ -45,7 +46,7 @@ public:
     virtual char *apefrm_getstr (apetag *mem_cnt, char *name)=0;
     virtual void apefrm_remove_real (apetag *mem_cnt, char *name)=0;
     virtual void apefrm_remove (apetag *mem_cnt, char *name)=0;
-    virtual int readtag_id3v1_fp (apetag *mem_cnt, FILE * fp)=0;
+    virtual int readtag_id3v1_fp (apetag *mem_cnt, ape_file * fp)=0;
     virtual void libapetag_print_mem_cnt (apetag *mem_cnt)=0;
 };
 
@@ -55,7 +56,7 @@ public:
     virtual ~DllLibApeTag() {}
     virtual int apetag_read (apetag *mem_cnt, char *filename, int flag)
         { return ::apetag_read(mem_cnt, filename, flag); }
-    virtual int apetag_read_fp (apetag *mem_cnt, FILE * fp, char *filename, int flag)
+    virtual int apetag_read_fp (apetag *mem_cnt, ape_file * fp, char *filename, int flag)
         { return ::apetag_read_fp (mem_cnt, fp, filename, flag); }
     virtual apetag *apetag_init (void)
         { return ::apetag_init (); }
@@ -78,7 +79,7 @@ public:
         { return ::apefrm_remove_real (mem_cnt, name); }
     virtual void apefrm_remove (apetag *mem_cnt, char *name)
         { return ::apefrm_remove (mem_cnt, name); }
-    virtual int readtag_id3v1_fp (apetag *mem_cnt, FILE * fp)
+    virtual int readtag_id3v1_fp (apetag *mem_cnt, ape_file * fp)
         { return ::readtag_id3v1_fp (mem_cnt, fp); }
     virtual void libapetag_print_mem_cnt (apetag *mem_cnt)
         { return ::libapetag_print_mem_cnt (mem_cnt); }