[vlc-devel] [PATCH 01/14] Update to medialibrary API changes
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Mon Sep 23 11:44:44 CEST 2019
---
contrib/src/medialibrary/rules.mak | 2 +-
modules/misc/medialibrary/fs/directory.cpp | 17 ++++++++++++
modules/misc/medialibrary/fs/directory.h | 1 +
modules/misc/medialibrary/fs/fs.cpp | 8 ++++++
modules/misc/medialibrary/fs/fs.h | 3 +++
modules/misc/medialibrary/medialib.cpp | 31 +++++++++++++++++++---
modules/misc/medialibrary/medialibrary.h | 1 +
7 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/contrib/src/medialibrary/rules.mak b/contrib/src/medialibrary/rules.mak
index 711797fbb9..6c646f387d 100644
--- a/contrib/src/medialibrary/rules.mak
+++ b/contrib/src/medialibrary/rules.mak
@@ -1,4 +1,4 @@
-MEDIALIBRARY_HASH := 00d30ec824749b73bb7c5be6e22fe441785ba971
+MEDIALIBRARY_HASH := e65e46c8614aba502fc2885dff4bc1251a819a60
MEDIALIBRARY_VERSION := git-$(MEDIALIBRARY_HASH)
MEDIALIBRARY_GITURL := https://code.videolan.org/videolan/medialibrary.git
diff --git a/modules/misc/medialibrary/fs/directory.cpp b/modules/misc/medialibrary/fs/directory.cpp
index 2e66e8311e..f370ef147c 100644
--- a/modules/misc/medialibrary/fs/directory.cpp
+++ b/modules/misc/medialibrary/fs/directory.cpp
@@ -24,7 +24,9 @@
#include "directory.h"
#include "file.h"
+#include "util.h"
+#include <algorithm>
#include <assert.h>
#include <vector>
#include <system_error>
@@ -79,6 +81,21 @@ SDDirectory::device() const
return m_device;
}
+std::shared_ptr<IFile> SDDirectory::file(const std::string& mrl) const
+{
+ auto fs = files();
+ // Don't compare entire mrls, this might yield false negative when a
+ // device has multiple mountpoints.
+ auto fileName = utils::fileName( mrl );
+ auto it = std::find_if( cbegin( fs ), cend( fs ),
+ [&fileName]( const std::shared_ptr<fs::IFile> f ) {
+ return f->name() == fileName;
+ });
+ if ( it == cend( fs ) )
+ throw std::runtime_error( mrl + " wasn't found in the directory" );
+ return *it;
+}
+
struct metadata_request {
vlc::threads::mutex lock;
vlc::threads::condition_variable cond;
diff --git a/modules/misc/medialibrary/fs/directory.h b/modules/misc/medialibrary/fs/directory.h
index bc5395b396..948cd7eca2 100644
--- a/modules/misc/medialibrary/fs/directory.h
+++ b/modules/misc/medialibrary/fs/directory.h
@@ -39,6 +39,7 @@ public:
const std::vector<std::shared_ptr<IFile>> &files() const override;
const std::vector<std::shared_ptr<IDirectory>> &dirs() const override;
std::shared_ptr<IDevice> device() const override;
+ std::shared_ptr<IFile> file( const std::string& mrl ) const override;
private:
void read() const;
diff --git a/modules/misc/medialibrary/fs/fs.cpp b/modules/misc/medialibrary/fs/fs.cpp
index a133979cf5..ccc7c86e2d 100644
--- a/modules/misc/medialibrary/fs/fs.cpp
+++ b/modules/misc/medialibrary/fs/fs.cpp
@@ -80,6 +80,14 @@ SDFileSystemFactory::createDirectory(const std::string &mrl)
return std::make_shared<SDDirectory>(mrl, *this);
}
+std::shared_ptr<IFile>
+SDFileSystemFactory::createFile(const std::string& mrl)
+{
+ auto dir = createDirectory(mrl);
+ assert(dir != nullptr);
+ return dir->file(mrl);
+}
+
std::shared_ptr<IDevice>
SDFileSystemFactory::createDevice(const std::string &uuid)
{
diff --git a/modules/misc/medialibrary/fs/fs.h b/modules/misc/medialibrary/fs/fs.h
index 95e5956941..04c2e9e99f 100644
--- a/modules/misc/medialibrary/fs/fs.h
+++ b/modules/misc/medialibrary/fs/fs.h
@@ -53,6 +53,9 @@ public:
std::shared_ptr<IDirectory>
createDirectory(const std::string &mrl) override;
+ std::shared_ptr<fs::IFile>
+ createFile(const std::string& mrl) override;
+
std::shared_ptr<IDevice>
createDevice(const std::string &uuid) override;
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 1c7dc6ef08..f2d5063687 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -26,6 +26,7 @@
#include <vlc_plugin.h>
#include <vlc_url.h>
#include <vlc_media_library.h>
+#include <vlc_dialog.h>
#include "medialibrary.h"
#include "fs/fs.h"
@@ -302,6 +303,10 @@ void MediaLibrary::onMediaThumbnailReady( medialibrary::MediaPtr media,
m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
+void MediaLibrary::onHistoryChanged( medialibrary::HistoryType )
+{
+}
+
MediaLibrary::MediaLibrary( vlc_medialibrary_module_t* ml )
: m_vlc_ml( ml )
{
@@ -321,9 +326,8 @@ bool MediaLibrary::Start()
auto userDir = vlc::wrap_cptr( config_GetUserDir( VLC_USERDATA_DIR ) );
std::string mlDir = std::string{ userDir.get() } + "/ml/";
- auto thumbnailsDir = mlDir + "thumbnails/";
- auto initStatus = ml->initialize( mlDir + "ml.db", thumbnailsDir, this );
+ auto initStatus = ml->initialize( mlDir + "ml.db", mlDir + "/mlstorage/", this );
switch ( initStatus )
{
case medialibrary::InitializeResult::AlreadyInitialized:
@@ -338,6 +342,27 @@ bool MediaLibrary::Start()
case medialibrary::InitializeResult::Success:
msg_Dbg( m_vlc_ml, "MediaLibrary successfully initialized" );
break;
+ case medialibrary::InitializeResult::DbCorrupted:
+ {
+ auto res = vlc_dialog_wait_question(VLC_OBJECT( m_vlc_ml ),
+ VLC_DIALOG_QUESTION_NORMAL, _( "Ignore" ), _( "Recover" ),
+ _( "Recreate" ), _( "Media database corrupted" ),
+ "Your media database appears to be corrupted. You can try to "
+ "recover it, recreate it entirely, or ignore this error (the "
+ "mediacenter will be disabled)." );
+ switch ( res )
+ {
+ case 1:
+ ml->clearDatabase( true );
+ break;
+ case 2:
+ ml->clearDatabase( false );
+ break;
+ default:
+ return false;
+ }
+ break;
+ }
}
ml->addParserService( std::make_shared<MetadataExtractor>( VLC_OBJECT( m_vlc_ml ) ) );
@@ -936,7 +961,7 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media, int meta, char** r
*result = nullptr;
return VLC_SUCCESS;
}
- *result = strdup( md.str().c_str() );
+ *result = strdup( md.asStr().c_str() );
if ( *result == nullptr )
return VLC_ENOMEM;
return VLC_SUCCESS;
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 861a41c44a..1380d2f95a 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -193,6 +193,7 @@ public:
virtual void onMediaThumbnailReady(medialibrary::MediaPtr media,
medialibrary::ThumbnailSizeType sizeType,
bool success) override;
+ virtual void onHistoryChanged( medialibrary::HistoryType historyType ) override;
};
bool Convert( const medialibrary::IMedia* input, vlc_ml_media_t& output );
--
2.20.1
More information about the vlc-devel
mailing list