[vlc-devel] [PATCH 01/12] Update to medialibrary API changes

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Jul 31 11:20:30 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     |  6 +++++-
 modules/misc/medialibrary/medialibrary.h   |  1 +
 7 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/contrib/src/medialibrary/rules.mak b/contrib/src/medialibrary/rules.mak
index 711797fbb9..f0fa8301be 100644
--- a/contrib/src/medialibrary/rules.mak
+++ b/contrib/src/medialibrary/rules.mak
@@ -1,4 +1,4 @@
-MEDIALIBRARY_HASH := 00d30ec824749b73bb7c5be6e22fe441785ba971
+MEDIALIBRARY_HASH := 4a202da63bb2936bc56e8c445cd3f4d98ccae198
 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..a2620b7cea 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -302,6 +302,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 )
 {
@@ -936,7 +940,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