Permalink
Browse files

[embedded art] read coverart data in tags into the MusicInfoTag rathe…

…r than caching directly
  • Loading branch information...
1 parent 268a0ab commit fd0f6264d32f6cd07348110bbedb694da5b71f59 Jonathan Marshall committed May 26, 2012
View
31 xbmc/music/tags/FlacTag.cpp
@@ -26,7 +26,6 @@
#include "filesystem/File.h"
#include "utils/log.h"
#include "utils/EndianSwap.h"
-#include "ThumbnailCache.h"
#define BYTES_TO_CHECK_FOR_BAD_TAGS 16384
@@ -112,13 +111,7 @@ bool CFlacTag::Read(const CStdString& strFile)
if (!cover)
cover = third_cover;
- CStdString strCoverArt;
- if (!m_musicInfoTag.GetAlbum().IsEmpty() && (!m_musicInfoTag.GetAlbumArtist().empty() || !m_musicInfoTag.GetArtist().empty()))
- strCoverArt = CThumbnailCache::GetAlbumThumb(&m_musicInfoTag);
- else
- strCoverArt = CThumbnailCache::GetMusicThumb(m_musicInfoTag.GetURL());
-
- if (cover && !CUtil::ThumbExists(strCoverArt))
+ if (cover)
{
char info[1024];
m_file->Seek(cover, SEEK_SET);
@@ -138,29 +131,21 @@ bool CFlacTag::Read(const CStdString& strFile)
if (size > 1023)
m_file->Seek(size - 1023, SEEK_CUR);
- int nPos = mimeType.Find('/');
- if (nPos > -1)
- mimeType.Delete(0, nPos + 1);
-
// and now our actual image info
unsigned int picInfo[4];
m_file->Read(picInfo, 16);
unsigned int picSize = ReadUnsigned();
- BYTE *picData = new BYTE[picSize];
- if (picData)
+ m_musicInfoTag.SetCoverArtInfo(picSize, mimeType);
+ if (m_art)
{
- m_file->Read(picData, picSize);
- if (CPicture::CreateThumbnailFromMemory(picData, picSize, mimeType, strCoverArt))
- {
- CUtil::ThumbCacheAdd(strCoverArt, true);
- }
- else
+ uint8_t *picData = new uint8_t[picSize];
+ if (picData)
{
- CUtil::ThumbCacheAdd(strCoverArt, false);
- CLog::Log(LOGERROR, "%s Unable to create album art for %s (extension=%s, size=%d)", __FUNCTION__, m_musicInfoTag.GetURL().c_str(), mimeType.c_str(), picSize);
+ m_file->Read(picData, picSize);
+ m_art->set(picData, picSize, mimeType);
+ delete[] picData;
}
- delete[] picData;
}
}
return foundTag;
View
29 xbmc/music/tags/Id3Tag.cpp
@@ -27,7 +27,6 @@
#include "guilib/LocalizeStrings.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
-#include "ThumbnailCache.h"
#include <set>
@@ -168,34 +167,16 @@ bool CID3Tag::Parse()
bFound = true;
}
- // if we don't have an album tag, cache with the full file path so that
- // other non-tagged files don't get this album image
- CStdString strCoverArt;
- if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
- strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
- else
- strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
- if (bFound && !CUtil::ThumbExists(strCoverArt))
+ if (bFound)
{
- CStdString strExtension=GetPictureMimeType(pictype);
-
- int nPos = strExtension.Find('/');
- if (nPos > -1)
- strExtension.Delete(0, nPos + 1);
-
id3_length_t nBufSize = 0;
const BYTE* pPic = GetPictureData(pictype, &nBufSize );
+ std::string mimeType = GetPictureMimeType(pictype);
if (pPic != NULL && nBufSize > 0)
{
- if (CPicture::CreateThumbnailFromMemory(pPic, nBufSize, strExtension, strCoverArt))
- {
- CUtil::ThumbCacheAdd(strCoverArt, true);
- }
- else
- {
- CUtil::ThumbCacheAdd(strCoverArt, false);
- CLog::Log(LOGERROR, "Tag loader mp3: Unable to create album art for %s (extension=%s, size=%lu)", tag.GetURL().c_str(), strExtension.c_str(), nBufSize);
- }
+ tag.SetCoverArtInfo(nBufSize, mimeType);
+ if (m_art)
+ m_art->set(pPic, nBufSize, mimeType);
}
}
View
45 xbmc/music/tags/MusicInfoTagLoaderMP4.cpp
@@ -27,7 +27,6 @@
#include "guilib/LocalizeStrings.h"
#include "utils/AutoPtrHandle.h"
#include "utils/log.h"
-#include "ThumbnailCache.h"
using namespace XFILE;
using namespace AUTOPTR;
@@ -229,12 +228,18 @@ void CMusicInfoTagLoaderMP4::ParseTag( unsigned int metaKey, const char* pMetaDa
// This cover-art handling is pretty much what was in the old MP4 tag processing code..
// note that according to http://atomicparsley.sourceforge.net/mpeg-4files.html the type
- // of image (PNG=14 or JPG=13) is contained in pMetadata[-5] but we currently don't use this.
- m_thumbSize = metaSize;
- delete[] m_thumbData;
- m_thumbData = new BYTE[m_thumbSize];
- if (m_thumbData)
- memcpy(m_thumbData, pMetaData, metaSize);
+ // of image (PNG=14 or JPG=13) is contained in pMetadata[-5]
+ std::string mimeType;
+ if (pMetaData[-5] == 13)
+ mimeType = "image/jpeg";
+ else if (pMetaData[-5] == 14)
+ mimeType = "image/png";
+ else
+ CLog::Log(LOGDEBUG, "Unknown art mimetype %d", pMetaData[-5]);
+
+ tag.SetCoverArtInfo(metaSize, mimeType);
+ if (art)
+ art->set((const uint8_t*)pMetaData, metaSize, mimeType);
break;
}
default:
@@ -386,35 +391,9 @@ bool CMusicInfoTagLoaderMP4::Load(const CStdString& strFileName, CMusicInfoTag&
tag.SetURL(strFileName);
// Now go parse our atom data
- m_thumbSize = false;
- m_thumbData = NULL;
m_isCompilation = false;
ParseAtom( 0, m_file.GetLength(), tag, art );
- if (m_thumbData)
- { // cache the thumb
- // if we don't have an album tag, cache with the full file path so that
- // other non-tagged files don't get this album image
- CStdString strCoverArt;
- if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
- strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
- else
- strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
- if (!CUtil::ThumbExists(strCoverArt))
- {
- if (CPicture::CreateThumbnailFromMemory( m_thumbData, m_thumbSize, "", strCoverArt ) )
- {
- CUtil::ThumbCacheAdd( strCoverArt, true );
- }
- else
- {
- CLog::Log(LOGDEBUG, "%s unable to cache thumb as %s", __FUNCTION__, strCoverArt.c_str());
- CUtil::ThumbCacheAdd( strCoverArt, false );
- }
- }
- delete[] m_thumbData;
- }
-
if (m_isCompilation)
{ // iTunes compilation flag is set - this could be a various artists file
if (tag.GetAlbumArtist().empty())
View
2 xbmc/music/tags/MusicInfoTagLoaderMP4.h
@@ -40,8 +40,6 @@ class CMusicInfoTagLoaderMP4: public IMusicInfoTagLoader
int GetILSTOffset( const char* pBuffer, int bufferSize );
int ParseAtom( int64_t startOffset, int64_t stopOffset, CMusicInfoTag& tag, EmbeddedArt *art );
- unsigned int m_thumbSize;
- BYTE *m_thumbData;
bool m_isCompilation;
XFILE::CFile m_file;
View
34 xbmc/music/tags/MusicInfoTagLoaderWMA.cpp
@@ -28,7 +28,6 @@
#include "utils/AutoPtrHandle.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
-#include "ThumbnailCache.h"
#include "utils/StringUtils.h"
using namespace AUTOPTR;
@@ -514,36 +513,11 @@ void CMusicInfoTagLoaderWMA::SetTagValueBinary(const CStdString& strFrameName, c
// Cover Front (3) or Other (0) as the cover.
if (picture.bPictureType == 3 || picture.bPictureType == 0) // Cover Front
{
- CStdString strExtension(picture.pwszMIMEType);
- // if we don't have an album tag, cache with the full file path so that
- // other non-tagged files don't get this album image
- CStdString strCoverArt;
- if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
- strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
- else
- strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
- if (!CUtil::ThumbExists(strCoverArt))
+ if (picture.pbData != NULL && picture.dwDataLen > 0)
{
- int nPos = strExtension.Find('/');
- if (nPos > -1)
- strExtension.Delete(0, nPos + 1);
-
- if (picture.pbData != NULL && picture.dwDataLen > 0)
- {
- if (CPicture::CreateThumbnailFromMemory(picture.pbData, picture.dwDataLen, strExtension, strCoverArt))
- {
- CUtil::ThumbCacheAdd(strCoverArt, true);
- }
- else
- {
- CUtil::ThumbCacheAdd(strCoverArt, false);
- CLog::Log(LOGERROR, "Tag loader wma: "
- "Unable to create album art for %s "
- "(extension=%s, size=%u)",
- tag.GetURL().c_str(), strExtension.c_str(),
- picture.dwDataLen);
- }
- }
+ tag.SetCoverArtInfo(picture.dwDataLen, picture.pwszMIMEType);
+ if (art)
+ art->set(picture.pbData, picture.dwDataLen, picture.pwszMIMEType);
}
}
}

0 comments on commit fd0f626

Please sign in to comment.