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

IMediaLibrary: Allow an external user to provide a parser service

parent 039905c1
......@@ -391,8 +391,7 @@ class IMediaLibrary
* @brief forceRescan Deletes all entities except Media and Playlist, and
* forces all media to be rescanned.
*
* This can be called anytime after the medialibrary has been initialized.
* It will make all held instances outdated. Those should be considered
* This can be called anytime after the medialibrary has been initialized. * It will make all held instances outdated. Those should be considered
* as invalid the moment this method returns.
*/
virtual void forceRescan() = 0;
......@@ -405,6 +404,8 @@ class IMediaLibrary
*/
virtual void requestThumbnail( MediaPtr media ) = 0;
virtual void addParserService( std::shared_ptr<parser::IParserService> service ) = 0;
};
}
......
......@@ -48,6 +48,11 @@ class IDeviceLister;
class IDeviceListerCb;
class IFolder;
namespace parser
{
class IParserService;
}
using AlbumPtr = std::shared_ptr<IAlbum>;
using AlbumTrackPtr = std::shared_ptr<IAlbumTrack>;
using ArtistPtr = std::shared_ptr<IArtist>;
......
......@@ -714,10 +714,16 @@ void MediaLibrary::startParser()
{
m_parser.reset( new parser::Parser( this ) );
auto vlcService = std::make_shared<parser::VLCMetadataService>();
auto metadataService = std::make_shared<parser::MetadataAnalyzer>();
m_parser->addService( std::move( vlcService ) );
m_parser->addService( std::move( metadataService ) );
if ( m_services.size() == 0 )
{
m_parser->addService( std::make_shared<parser::VLCMetadataService>() );
}
else
{
assert( m_services[0]->targetedStep() == parser::Step::MetadataExtraction );
m_parser->addService( m_services[0] );
}
m_parser->addService( std::make_shared<parser::MetadataAnalyzer>() );
m_parser->start();
}
......@@ -1310,6 +1316,16 @@ void MediaLibrary::requestThumbnail( MediaPtr media )
m_thumbnailer->requestThumbnail( media );
}
void MediaLibrary::addParserService( std::shared_ptr<parser::IParserService> service )
{
// For now we only support 1 external service of type MetadataExtraction
if ( service->targetedStep() != parser::Step::MetadataExtraction )
return;
if ( m_services.size() != 0 )
return;
m_services.emplace_back( std::move( service ) );
}
bool MediaLibrary::onDevicePlugged( const std::string& uuid, const std::string& mountpoint )
{
auto currentDevice = Device::fromUuid( this, uuid );
......
......@@ -168,6 +168,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual void requestThumbnail( MediaPtr media ) override;
virtual void addParserService( std::shared_ptr<parser::IParserService> service ) override;
static bool isExtensionSupported( const char* ext );
protected:
......@@ -217,6 +219,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
IMediaLibraryCb* m_callback;
DeviceListerPtr m_deviceLister;
// User provided parser services
std::vector<std::shared_ptr<parser::IParserService>> m_services;
// 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
......
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