Commit b8cf9667 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add an emotion metadata module skeleton

parent 903260b0
......@@ -4,6 +4,12 @@ cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
EnableCpp11()
include(FindPkgConfig)
pkg_check_modules(EMOTION emotion)
pkg_check_modules(ECOREEVAS ecore-evas)
pkg_check_modules(EVAS evas)
add_definitions("-Wall -Wextra -pedantic")
if(UNIX)
......@@ -69,6 +75,12 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
Utils.cpp
)
if (${EMOTION_FOUND})
list(APPEND SRC_LIST
metadata_services/emotion/Emotion.cpp
)
endif()
find_package(Sqlite3 REQUIRED)
add_library(${PROJECT_NAME} ${SRC_LIST})
......@@ -80,3 +92,11 @@ include_directories(${LIBVLC_INCLUDE_DIR})
set(LIBVLCPP_DIR "" CACHE PATH "Path to libvlcpp's directory")
include_directories(${LIBVLCPP_DIR})
if (${EMOTION_FOUND})
include_directories(${EMOTION_INCLUDE_DIRS})
include_directories(${ECOREEVAS_INCLUDE_DIRS})
target_link_libraries( ${PROJECT_NAME} ${EMOTION_LIBRARIES} )
target_link_libraries( ${PROJECT_NAME} ${ECOREEVAS_LIBRARIES} )
target_link_libraries( ${PROJECT_NAME} ${EVAS_LIBRARIES} )
endif()
#include "Emotion.h"
#include <iostream>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Emotion.h>
#include "IFile.h"
EmotionMetadataService::EmotionMetadataService()
: m_initialized( false )
{
}
EmotionMetadataService::~EmotionMetadataService()
{
if ( m_initialized )
evas_shutdown();
}
bool EmotionMetadataService::initialize( IMetadataServiceCb *callback, IMediaLibrary *ml )
{
m_cb = callback;
m_ml = ml;
if ( ecore_evas_init() == 0 )
{
throw std::runtime_error( "Failed to initialize Evas" );
}
m_initialized = true;
return true;
}
unsigned int EmotionMetadataService::priority() const
{
return 1000;
}
bool EmotionMetadataService::run( FilePtr file, void *data )
{
auto evas = ecore_evas_new( nullptr, 0, 0, 10, 10, nullptr );
if ( evas == nullptr )
return false;
std::unique_ptr<Ecore_Evas, decltype(&ecore_evas_free)> evas_u( evas, &ecore_evas_free );
auto e = ecore_evas_get( evas );
auto em = emotion_object_add( e );
if ( emotion_object_init( em, "libvlc" ) != EINA_TRUE )
return false;
if ( emotion_object_file_set( em, file->mrl().c_str() ) != EINA_TRUE )
return false;
auto meta = emotion_object_meta_info_get( em, EMOTION_META_INFO_TRACK_ARTIST );
std::cout << "track album: " << meta << std::endl;
m_cb->done( file, StatusSuccess, data );
return true;
}
#pragma once
#include "IMetadataService.h"
class EmotionMetadataService : public IMetadataService
{
public:
EmotionMetadataService();
virtual ~EmotionMetadataService();
virtual bool initialize(IMetadataServiceCb *callback, IMediaLibrary *ml) override;
virtual unsigned int priority() const override;
virtual bool run(FilePtr file, void *data) override;
private:
//FIXME: This should be a shared_ptr
IMetadataServiceCb* m_cb;
IMediaLibrary* m_ml;
bool m_initialized;
};
......@@ -48,6 +48,12 @@ list(APPEND TEST_SRCS
mocks/FileSystem.h
)
if (${EMOTION_FOUND})
list (APPEND TEST_SRCS
EmotionMetadataService_Test.cpp
)
endif()
add_executable(unittest ${TEST_SRCS})
add_dependencies(unittest gtest-dependency)
......
#include "Tests.h"
#include <condition_variable>
#include <mutex>
#include "IFile.h"
#include "metadata_services/emotion/Emotion.h"
class EmotionMetadataServiceCb : public IParserCb
{
public:
bool failed;
std::condition_variable waitCond;
std::mutex mutex;
virtual void onServiceDone( FilePtr, ServiceStatus status ) override
{
std::unique_lock<std::mutex> lock( mutex );
if ( status == StatusSuccess )
failed = false;
waitCond.notify_all();
}
virtual void onFileDone( FilePtr ) override
{
}
};
class EmotionMetadataService_Tests : public Tests
{
protected:
static std::unique_ptr<EmotionMetadataServiceCb> cb;
public:
static void SetUpTestCase()
{
cb.reset( new EmotionMetadataServiceCb );
}
virtual void SetUp() override
{
Tests::SetUp();
cb->failed = true;
auto emotionService = std::unique_ptr<EmotionMetadataService>( new EmotionMetadataService );
ml->addMetadataService( std::move( emotionService ) );
}
};
std::unique_ptr<EmotionMetadataServiceCb> EmotionMetadataService_Tests::cb;
TEST_F( EmotionMetadataService_Tests, ParseAudio )
{
auto file = ml->addFile( "mr-zebra.mp3" );
std::unique_lock<std::mutex> lock( cb->mutex );
ml->parse( file, cb.get() );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return cb->failed == true || ( file->audioTracks().size() > 0 );
} );
ASSERT_TRUE( res );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment