[vlmc-devel] Media: Lazy load base clip

Hugo Beauzée-Luyssen git at videolan.org
Mon Aug 22 00:28:26 CEST 2016


vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Aug 20 22:05:45 2016 +0200| [518ed4cbcb720f1342eea5161cf376b774d694b9] | committer: Hugo Beauzée-Luyssen

Media: Lazy load base clip

Mostly because sharedFromThis cannot be called from a constructor

> https://code.videolan.org/videolan/vlmc/commit/518ed4cbcb720f1342eea5161cf376b774d694b9
---

 src/Media/Media.cpp | 11 ++++++++++-
 src/Media/Media.h   |  6 ++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/Media/Media.cpp b/src/Media/Media.cpp
index c2bd872..00a9d0e 100644
--- a/src/Media/Media.cpp
+++ b/src/Media/Media.cpp
@@ -62,6 +62,8 @@ const QString   Media::streamPrefix = "stream://";
 Media::Media( medialibrary::MediaPtr media, const QUuid& uuid /* = QUuid() */ )
     : m_input( nullptr )
     , m_mlMedia( media )
+    , m_baseClipUuid( uuid )
+    , m_baseClip( nullptr )
 {
     auto files = media->files();
     Q_ASSERT( files.size() > 0 );
@@ -77,7 +79,6 @@ Media::Media( medialibrary::MediaPtr media, const QUuid& uuid /* = QUuid() */ )
     if ( m_mlFile == nullptr )
         vlmcFatal( "No file representing media %s", media->title().c_str(), "was found" );
     m_input.reset( new Backend::MLT::MLTInput( m_mlFile->mrl().c_str() ) );
-    m_baseClip = new Clip( sharedFromThis(), 0, Backend::IInput::EndOfMedia, uuid );
 }
 
 QString
@@ -113,6 +114,14 @@ Media::id() const
     return m_mlMedia->id();
 }
 
+Clip*
+Media::baseClip()
+{
+    if ( m_baseClip == nullptr )
+        m_baseClip = new Clip( sharedFromThis(), 0, Backend::IInput::EndOfMedia, m_baseClipUuid );
+    return m_baseClip;
+}
+
 QSharedPointer<Clip>
 Media::cut( qint64 begin, qint64 end )
 {
diff --git a/src/Media/Media.h b/src/Media/Media.h
index f903e26..9172917 100644
--- a/src/Media/Media.h
+++ b/src/Media/Media.h
@@ -86,7 +86,8 @@ public:
     QString                     title() const;
     qint64                      id() const;
 
-    Clip*                       baseClip() { return m_baseClip; }
+    Clip*                       baseClip();
+
     /**
      * @brief cut   Creates a clip to represent a cut of a media
      * @param begin The first frame of the cut
@@ -112,7 +113,8 @@ protected:
     std::unique_ptr<Backend::IInput>         m_input;
     medialibrary::MediaPtr      m_mlMedia;
     medialibrary::FilePtr       m_mlFile;
-    Clip*                       m_baseClip;
+    QUuid                       m_baseClipUuid;
+    mutable Clip*               m_baseClip;
     QHash<QUuid, QSharedPointer<Clip>>      m_clips;
 
 signals:



More information about the Vlmc-devel mailing list