[vlmc-devel] Library: Use medialibrary's ID to uniquely identify a media

Hugo Beauzée-Luyssen git at videolan.org
Thu Aug 18 22:57:07 CEST 2016


vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Aug 18 22:55:39 2016 +0200| [57db142dcdab0f636374365b42e51272b13df4fa] | committer: Hugo Beauzée-Luyssen

Library: Use medialibrary's ID to uniquely identify a media

MRL can't be assumed to be constant over time, while the media library
will recognize a media that changes location (in some conditions) and
keep the same ID assigned to it

> https://code.videolan.org/videolan/vlmc/commit/57db142dcdab0f636374365b42e51272b13df4fa
---

 src/Library/Library.cpp | 11 ++++-------
 src/Library/Library.h   |  4 ++--
 src/Media/Clip.cpp      |  6 +++---
 src/Media/Media.cpp     |  6 ++++++
 src/Media/Media.h       |  1 +
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp
index 71d145f..418b93d 100644
--- a/src/Library/Library.cpp
+++ b/src/Library/Library.cpp
@@ -94,11 +94,9 @@ void
 Library::addMedia( Media* media )
 {
     setCleanState( false );
-    if ( m_media.contains( media->mrl() ) )
+    if ( m_media.contains( media->id() ) )
         return;
-    //FIXME: This doesn't play well with a mountpoint change, we'd rather use the ML's media ID
-    // or an UUID that maps 1:1 to the ML media ID
-    m_media[media->mrl()] = media;
+    m_media[media->id()] = media;
 }
 
 bool
@@ -115,7 +113,6 @@ Library::addClip( Clip *clip )
         }
     }
     setCleanState( false );
-    m_media[clip->media()->mrl()] = clip->media();
     return true;
 }
 
@@ -126,9 +123,9 @@ Library::isInCleanState() const
 }
 
 Media*
-Library::media(const QString& mrl)
+Library::media( qint64 mediaId )
 {
-    return m_media.value( mrl );
+    return m_media.value( mediaId );
 }
 
 Clip*
diff --git a/src/Library/Library.h b/src/Library/Library.h
index 95dbbd1..4e90925 100644
--- a/src/Library/Library.h
+++ b/src/Library/Library.h
@@ -53,7 +53,7 @@ public:
     virtual void    addMedia( Media* media );
     virtual bool    addClip( Clip *clip );
     bool            isInCleanState() const;
-    Media*          media( const QString& mrl );
+    Media*          media( qint64 mediaId );
     /**
      * @brief clip returns an existing clip
      * @param uuid the clip's UUID
@@ -71,7 +71,7 @@ private:
     bool        m_cleanState;
 
     Settings*   m_settings;
-    QHash<QString, Media*>  m_media;
+    QHash<qint64, Media*>  m_media;
     /**
      * @brief m_clips   contains all the clips loaded in the library, without any
      *                  subclip hierarchy
diff --git a/src/Media/Clip.cpp b/src/Media/Clip.cpp
index e9f3ca9..796ba22 100644
--- a/src/Media/Clip.cpp
+++ b/src/Media/Clip.cpp
@@ -341,8 +341,8 @@ Clip::fromVariant( const QVariant& v )
         return nullptr;
     }
 
-    auto mediaMrl = m["media"].toString();
-    if ( mediaMrl.isEmpty() == true )
+    auto mediaId = m["media"].toLongLong();
+    if ( mediaId == 0 )
     {
         vlmcWarning() << "Refusing to load an invalid root clip with no base media";
         return nullptr;
@@ -355,7 +355,7 @@ Clip::fromVariant( const QVariant& v )
         return nullptr;
     }
 
-    auto media = Core::instance()->library()->media( mediaMrl );
+    auto media = Core::instance()->library()->media( mediaId );
     auto clip = new Clip( media, 0, -1, uuid );
 
     clip->loadVariant( m );
diff --git a/src/Media/Media.cpp b/src/Media/Media.cpp
index b7f02a3..45d8df2 100644
--- a/src/Media/Media.cpp
+++ b/src/Media/Media.cpp
@@ -109,6 +109,12 @@ Media::title() const
     return QString::fromStdString( m_mlMedia->title() );
 }
 
+qint64
+Media::id() const
+{
+    return m_mlMedia->id();
+}
+
 void
 Media::setBaseClip( Clip *clip )
 {
diff --git a/src/Media/Media.h b/src/Media/Media.h
index 041a0e3..7fd50d8 100644
--- a/src/Media/Media.h
+++ b/src/Media/Media.h
@@ -86,6 +86,7 @@ public:
     QString                     mrl() const;
     FileType                    fileType() const;
     QString                     title() const;
+    qint64                      id() const;
 
     Clip*                       baseClip() { return m_baseClip; }
     const Clip*                 baseClip() const { return m_baseClip; }



More information about the Vlmc-devel mailing list