Index: xbmc/OggTag.cpp =================================================================== --- xbmc/OggTag.cpp (revision 23333) +++ xbmc/OggTag.cpp (working copy) @@ -24,13 +24,54 @@ #endif #include "OggTag.h" #include "Util.h" +#include "File.h" +size_t OGGReadCB(void* ptr, size_t size, size_t nmemb, void *datasource) +{ + if (ptr && datasource) + { + XFILE::CFile* file = (XFILE::CFile*)datasource; + return file->Read(ptr, size*nmemb); + } + return -1; +} +int OGGSeekCB(void* datasource, ogg_int64_t offset, int whence) +{ + if (datasource) + { + int nseek; + XFILE::CFile* file = (XFILE::CFile*)datasource; + if ((nseek = file->Seek(offset, whence)) == offset) + return nseek; + } + return -1; +} + +int OGGCloseCB(void* datasource) +{ + if (datasource) + { + XFILE::CFile* file = (XFILE::CFile*)datasource; + file->Close(); + return 0; + } + return -1; +} + +long OGGTellCB(void* datasource) +{ + if (datasource) + { + XFILE::CFile* file = (XFILE::CFile*)datasource; + return (int)file->GetPosition(); + } + return -1; +} + + using namespace MUSIC_INFO; -// From EMUmsvcrt.cpp to open a file for a dll -extern "C" FILE * dll_fopen (const char * filename, const char * mode); - COggTag::COggTag() { @@ -64,44 +105,41 @@ CUtil::RemoveSlashAtEnd(strFile); // we want the filename } - #if (defined USE_EXTERNAL_LIBVORBIS) - // Call fopen() directly if we're using external libraries - FILE* file=fopen(strFile.c_str(), "r"); - #else - //Use the emulated fopen() as its only used inside the dll - FILE* file=dll_fopen (strFile.c_str(), "r"); - #endif - if (!file) - return false; - - OggVorbis_File vf; - // open ogg file with decoder - if (m_dll.ov_open(file, &vf, NULL, 0)!=0) - return false; - - int iStreams=m_dll.ov_streams(&vf); - if (iStreams>1) + bool ret = false; + XFILE::CFile file; + if (file.Open(strFile)) { - if (currentStream > iStreams) + OggVorbis_File vf; + ov_callbacks cb = {}; + cb.read_func = OGGReadCB; + cb.seek_func = OGGSeekCB; + cb.close_func = OGGCloseCB; + cb.tell_func = OGGTellCB; + // open ogg file with decoder + if (m_dll.ov_open_callbacks((void*)&file, &vf, NULL, 0, cb) == 0) { - m_dll.ov_clear(&vf); - return false; - } - } - m_musicInfoTag.SetDuration((int)m_dll.ov_time_total(&vf, currentStream)); + int iStreams=m_dll.ov_streams(&vf); + if (!((iStreams > 1) && (currentStream > iStreams))) + { + m_musicInfoTag.SetDuration((int)m_dll.ov_time_total(&vf, currentStream)); - vorbis_comment* pComments=m_dll.ov_comment(&vf, currentStream); - if (pComments) - { - for (int i=0; icomments; ++i) - { - CStdString strEntry=pComments->user_comments[i]; - ParseTagEntry(strEntry); + vorbis_comment* pComments=m_dll.ov_comment(&vf, currentStream); + if (pComments) + { + for (int i=0; icomments; ++i) + { + CStdString strEntry=pComments->user_comments[i]; + ParseTagEntry(strEntry); + } + } + } + ret = true; } + m_dll.ov_clear(&vf); + file.Close(); } - m_dll.ov_clear(&vf); - return true; + return ret; } int COggTag::GetStreamCount(const CStdString& strFile) @@ -109,24 +147,27 @@ if (!m_dll.Load()) return 0; - #if (defined USE_EXTERNAL_LIBVORBIS) - // Call fopen() directly if we're using external libraries - FILE* file=fopen(strFile.c_str(), "r"); - #else - FILE* file=dll_fopen (strFile.c_str(), "r"); - #endif - if (!file) - return 0; - - OggVorbis_File vf; - // open ogg file with decoder - if (m_dll.ov_open(file, &vf, NULL, 0)!=0) - return 0; - - int iStreams=m_dll.ov_streams(&vf); - - m_dll.ov_clear(&vf); - - return iStreams; + int ret = 0; + XFILE::CFile file; + if (file.Open(strFile)) + { + OggVorbis_File vf; + ov_callbacks cb = {}; + cb.read_func = OGGReadCB; + cb.seek_func = OGGSeekCB; + cb.close_func = OGGCloseCB; + cb.tell_func = OGGTellCB; + + // open ogg file with decoder + if (m_dll.ov_open_callbacks((void*)&file, &vf, NULL, 0, cb)!=0) + { + int iStreams=m_dll.ov_streams(&vf); + m_dll.ov_clear(&vf); + file.Close(); + ret = iStreams; + } + file.Close(); + } + return ret; }