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

IMediaLibrary: Allow an external thumbnailer to be used

parent 96a76276
......@@ -95,6 +95,7 @@ libmedialibrary_la_SOURCES = \
src/logging/IostreamLogger.cpp \
src/logging/Logger.cpp \
src/metadata_services/MetadataParser.cpp \
src/metadata_services/ThumbnailerWorker.cpp \
src/parser/Parser.cpp \
src/parser/ParserWorker.cpp \
src/parser/Task.cpp \
......@@ -147,6 +148,7 @@ noinst_HEADERS = \
src/Media.h \
src/MediaLibrary.h \
src/metadata_services/MetadataParser.h \
src/metadata_services/ThumbnailerWorker.h \
src/Movie.h \
src/parser/Parser.h \
src/parser/ParserWorker.h \
......@@ -237,7 +239,6 @@ endif
libmedialibrary_la_SOURCES += \
src/metadata_services/vlc/VLCMetadataService.cpp \
src/metadata_services/ThumbnailerWorker.cpp \
src/metadata_services/vlc/Common.cpp \
src/utils/VLCInstance.cpp \
src/factory/NetworkFileSystemFactory.cpp \
......@@ -250,7 +251,6 @@ noinst_HEADERS += \
src/utils/VLCInstance.h \
src/metadata_services/vlc/Common.hpp \
src/metadata_services/vlc/VLCMetadataService.h \
src/metadata_services/ThumbnailerWorker.h \
src/metadata_services/vlc/imagecompressors/IImageCompressor.h \
src/factory/NetworkFileSystemFactory.h \
src/filesystem/network/Device.h \
......
......@@ -492,6 +492,8 @@ class IMediaLibrary
virtual void addParserService( std::shared_ptr<parser::IParserService> service ) = 0;
virtual void addThumbnailer( std::shared_ptr<IThumbnailer> thumbnailer ) = 0;
/**
* @brief addNetworkFileSystemFactory Provides a network filesystem factory implementation
*
......
......@@ -47,6 +47,7 @@ class IDeviceLister;
class IDeviceListerCb;
class IFolder;
class ISubtitleTrack;
class IThumbnailer;
namespace parser
{
......
......@@ -68,9 +68,9 @@
// Metadata services:
#ifdef HAVE_LIBVLC
#include "metadata_services/vlc/VLCMetadataService.h"
#include "metadata_services/ThumbnailerWorker.h"
#endif
#include "metadata_services/MetadataParser.h"
#include "metadata_services/ThumbnailerWorker.h"
// FileSystem
#include "factory/DeviceListerFactory.h"
......@@ -78,6 +78,15 @@
#ifdef HAVE_LIBVLC
#include "factory/NetworkFileSystemFactory.h"
#include <vlcpp/vlc.hpp>
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
#include "metadata_services/vlc/CoreThumbnailer.h"
using ThumbnailerType = medialibrary::CoreThumbnailer;
#else
#include "metadata_services/vlc/VmemThumbnailer.h"
using ThumbnailerType = medialibrary::VmemThumbnailer;
#endif
#endif
#include "medialibrary/filesystem/IDevice.h"
......@@ -798,8 +807,17 @@ void MediaLibrary::startDeletionNotifier()
void MediaLibrary::startThumbnailer()
{
#ifdef HAVE_LIBVLC
m_thumbnailer = std::unique_ptr<ThumbnailerWorker>( new ThumbnailerWorker( this ) );
if ( m_thumbnailers.empty() == true )
m_thumbnailers.push_back( std::make_shared<ThumbnailerType>( this ) );
#endif
for ( const auto& thumbnailer : m_thumbnailers )
{
// For now this make little sense (as we are instantiating the same
// object in a loop, but at some point we will have multiple thumbnailer,
// or the thumbnailer worker will handle multiple IThumbnailer implementations
m_thumbnailer = std::unique_ptr<ThumbnailerWorker>(
new ThumbnailerWorker( this, thumbnailer ) );
}
}
void MediaLibrary::populateNetworkFsFactories()
......@@ -1501,12 +1519,10 @@ void MediaLibrary::forceRescan()
bool MediaLibrary::requestThumbnail( MediaPtr media )
{
#ifdef HAVE_LIBVLC
if ( m_thumbnailer == nullptr )
return false;
m_thumbnailer->requestThumbnail( media );
return true;
#else
return false;
#endif
}
void MediaLibrary::addParserService( std::shared_ptr<parser::IParserService> service )
......@@ -1519,6 +1535,17 @@ void MediaLibrary::addParserService( std::shared_ptr<parser::IParserService> ser
m_services.emplace_back( std::move( service ) );
}
void MediaLibrary::addThumbnailer( std::shared_ptr<IThumbnailer> thumbnailer )
{
if ( m_thumbnailers.size() != 0 )
{
// We only support a single thumbnailer for videos for now.
LOG_WARN( "Discarding thumbnailer since one has already been provided" );
return;
}
m_thumbnailers.push_back( std::move( thumbnailer ) );
}
bool MediaLibrary::onDevicePlugged( const std::string& uuid, const std::string& mountpoint )
{
auto currentDevice = Device::fromUuid( this, uuid );
......
......@@ -180,6 +180,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual void addParserService( std::shared_ptr<parser::IParserService> service ) override;
virtual void addThumbnailer( std::shared_ptr<IThumbnailer> thumbnailer ) override;
virtual void addNetworkFileSystemFactory( std::shared_ptr<fs::IFileSystemFactory> fsFactory ) override;
static bool isExtensionSupported( const char* ext );
......@@ -236,6 +238,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
// User provided parser services
std::vector<std::shared_ptr<parser::IParserService>> m_services;
std::vector<std::shared_ptr<IThumbnailer>> m_thumbnailers;
// Keep the parser as last field.
// The parser holds a (raw) pointer to the media library. When MediaLibrary's destructor gets called
// it might still finish a few operations before exiting the parser thread. Those operations are
......@@ -251,9 +254,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
bool m_initialized;
std::atomic_bool m_discovererIdle;
std::atomic_bool m_parserIdle;
#ifdef HAVE_LIBVLC
std::unique_ptr<ThumbnailerWorker> m_thumbnailer;
#endif
};
}
......
......@@ -32,26 +32,16 @@
#include "MediaLibrary.h"
#include "utils/ModificationsNotifier.h"
#include <vlcpp/vlc.hpp>
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
#include "vlc/CoreThumbnailer.h"
#else
#include "vlc/VmemThumbnailer.h"
#endif
namespace medialibrary
{
ThumbnailerWorker::ThumbnailerWorker( MediaLibraryPtr ml )
ThumbnailerWorker::ThumbnailerWorker( MediaLibraryPtr ml,
std::shared_ptr<IThumbnailer> thumbnailer )
: m_ml( ml )
, m_run( false )
, m_generator( std::move( thumbnailer ) )
, m_paused( false )
{
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(4, 0, 0, 0)
m_generator.reset( new CoreThumbnailer( m_ml ) );
#else
m_generator.reset( new VmemThumbnailer( m_ml ) );
#endif
}
ThumbnailerWorker::~ThumbnailerWorker()
......
......@@ -37,7 +37,8 @@ namespace medialibrary
class ThumbnailerWorker
{
public:
explicit ThumbnailerWorker( MediaLibraryPtr ml );
explicit ThumbnailerWorker( MediaLibraryPtr ml,
std::shared_ptr<IThumbnailer> thumbnailer );
virtual ~ThumbnailerWorker();
void requestThumbnail( MediaPtr media );
void pause();
......@@ -58,7 +59,7 @@ private:
compat::ConditionVariable m_cond;
std::queue<MediaPtr> m_tasks;
std::atomic_bool m_run;
std::unique_ptr<IThumbnailer> m_generator;
std::shared_ptr<IThumbnailer> m_generator;
compat::Thread m_thread;
bool m_paused;
};
......
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