Skip to content

Commit

Permalink
added: basic ffmpeg based tag loader
Browse files Browse the repository at this point in the history
use this for .mka
  • Loading branch information
notspiff committed Nov 17, 2014
1 parent 4e6620d commit e414517
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions xbmc/music/tags/CMakeLists.txt
Expand Up @@ -2,6 +2,7 @@ set(SOURCES MusicInfoTag.cpp
MusicInfoTagLoaderCDDA.cpp
MusicInfoTagLoaderDatabase.cpp
MusicInfoTagLoaderFactory.cpp
MusicInfoTagLoaderFFmpeg.cpp
MusicInfoTagLoaderShn.cpp
TagLibVFSStream.cpp
TagLoaderTagLib.cpp)
Expand Down
109 changes: 109 additions & 0 deletions xbmc/music/tags/MusicInfoTagLoaderFFmpeg.cpp
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2014 Arne Morten Kvarving
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "MusicInfoTagLoaderFFmpeg.h"
#include "MusicInfoTag.h"
#include "filesystem/File.h"
#include "cores/FFmpeg.h"
#include "utils/URIUtils.h"

using namespace MUSIC_INFO;
using namespace XFILE;

static int vfs_file_read(void *h, uint8_t* buf, int size)
{
CFile* pFile = static_cast<CFile*>(h);
return pFile->Read(buf, size);
}

static off_t vfs_file_seek(void *h, off_t pos, int whence)
{
CFile* pFile = static_cast<CFile*>(h);
if(whence == AVSEEK_SIZE)
return pFile->GetLength();
else
return pFile->Seek(pos, whence & ~AVSEEK_FORCE);
}

CMusicInfoTagLoaderFFmpeg::CMusicInfoTagLoaderFFmpeg(void)
{
}

CMusicInfoTagLoaderFFmpeg::~CMusicInfoTagLoaderFFmpeg()
{
}

bool CMusicInfoTagLoaderFFmpeg::Load(const CStdString& strFileName, CMusicInfoTag& tag, EmbeddedArt *art)
{
tag.SetLoaded(false);

CFile file;
if (!file.Open(strFileName))
return false;

uint8_t* buffer = (uint8_t*)av_malloc(32768);
AVIOContext* ioctx = avio_alloc_context(buffer, 32768, 0, &file, vfs_file_read, NULL, vfs_file_seek);

AVFormatContext* fctx = avformat_alloc_context();
fctx->pb = ioctx;

if (file.IoControl(IOCTRL_SEEK_POSSIBLE, NULL) == 0)
ioctx->seekable = 0;

ioctx->max_packet_size = 32768;

AVInputFormat* iformat=NULL;
av_probe_input_buffer(ioctx, &iformat, strFileName.c_str(), NULL, 0, 0);

bool contains = false;
if (avformat_open_input(&fctx, strFileName.c_str(), iformat, NULL) < 0)
{
if (fctx)
avformat_close_input(&fctx);
av_free(ioctx->buffer);
av_free(ioctx);
return false;
}

AVDictionaryEntry* avtag=NULL;
while ((avtag = av_dict_get(fctx->metadata, "", avtag, AV_DICT_IGNORE_SUFFIX)))
{
if (URIUtils::GetExtension(strFileName).Equals(".mka"))
{
if (strcasecmp(avtag->key,"title") == 0)
tag.SetTitle(avtag->value);
if (strcasecmp(avtag->key,"artist") == 0)
tag.SetArtist(avtag->value);
if (strcasecmp(avtag->key,"album") == 0)
tag.SetAlbum(avtag->value);
if (strcasecmp(avtag->key,"part_number") == 0 ||
strcasecmp(avtag->key,"track") == 0)
tag.SetTrackNumber(strtol(avtag->value, NULL, 10));
}
}

if (!tag.GetTitle().empty())
tag.SetLoaded(true);

avformat_close_input(&fctx);
av_free(ioctx->buffer);
av_free(ioctx);

return true;
}
34 changes: 34 additions & 0 deletions xbmc/music/tags/MusicInfoTagLoaderFFmpeg.h
@@ -0,0 +1,34 @@
#pragma once
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "ImusicInfoTagLoader.h"

namespace MUSIC_INFO
{
class CMusicInfoTagLoaderFFmpeg: public IMusicInfoTagLoader
{
public:
CMusicInfoTagLoaderFFmpeg(void);
virtual ~CMusicInfoTagLoaderFFmpeg();

virtual bool Load(const CStdString& strFileName, CMusicInfoTag& tag, EmbeddedArt *art = NULL);
};
}
3 changes: 3 additions & 0 deletions xbmc/music/tags/MusicInfoTagLoaderFactory.cpp
Expand Up @@ -24,6 +24,7 @@
#include "MusicInfoTagLoaderCDDA.h"
#include "MusicInfoTagLoaderShn.h"
#include "MusicInfoTagLoaderDatabase.h"
#include "MusicInfoTagLoaderFFmpeg.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "FileItem.h"
Expand Down Expand Up @@ -100,6 +101,8 @@ IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CStdString&
CMusicInfoTagLoaderSHN *pTagLoader = new CMusicInfoTagLoaderSHN();
return (IMusicInfoTagLoader*)pTagLoader;
}
else if (strExtension == "mka")
return new CMusicInfoTagLoaderFFmpeg();

return NULL;
}

0 comments on commit e414517

Please sign in to comment.