[vlmc-devel] ClipRenderer: Use shared pointer

Yikai Lu git at videolan.org
Fri Jun 30 08:14:38 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Fri Jun 30 15:06:05 2017 +0900| [43c86b11fb551559f77b0a968fb46a17862eb46c] | committer: Yikai Lu

ClipRenderer: Use shared pointer

> https://code.videolan.org/videolan/vlmc/commit/43c86b11fb551559f77b0a968fb46a17862eb46c
---

 src/Gui/MainWindow.cpp            |  4 ++--
 src/Gui/preview/PreviewWidget.cpp |  2 +-
 src/Renderer/ClipRenderer.cpp     | 15 ++++-----------
 src/Renderer/ClipRenderer.h       |  8 ++++----
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 21c69f06..73cc657c 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -528,11 +528,11 @@ MainWindow::setupClipPreview()
              renderer, &ClipRenderer::clipUnloaded );
     connect( m_clipLibrary, &ClipLibraryView::clipSelected, renderer, [renderer]( const QString& uuid )
     {
-        renderer->setClip( Core::instance()->library()->clip( uuid ).data() );
+        renderer->setClip( Core::instance()->library()->clip( uuid ) );
     } );
     connect( m_mediaLibrary, &MediaLibraryView::baseClipSelected, renderer, [renderer]( const QString& uuid )
     {
-        renderer->setClip( Core::instance()->library()->clip( uuid ).data() );
+        renderer->setClip( Core::instance()->library()->clip( uuid ) );
     } );
 
 
diff --git a/src/Gui/preview/PreviewWidget.cpp b/src/Gui/preview/PreviewWidget.cpp
index 34f20821..b1a5c4f9 100644
--- a/src/Gui/preview/PreviewWidget.cpp
+++ b/src/Gui/preview/PreviewWidget.cpp
@@ -239,7 +239,7 @@ PreviewWidget::createNewClipFromMarkers()
     ClipRenderer* clipRenderer = qobject_cast<ClipRenderer*>( m_renderer );
     Q_ASSERT( clipRenderer != nullptr );
 
-    Clip* clip = clipRenderer->getClip();
+    auto clip = clipRenderer->getClip();
     if ( clip == nullptr )
         return ;
     auto media = clip->media();
diff --git a/src/Renderer/ClipRenderer.cpp b/src/Renderer/ClipRenderer.cpp
index 5c86a3a9..68fada7d 100644
--- a/src/Renderer/ClipRenderer.cpp
+++ b/src/Renderer/ClipRenderer.cpp
@@ -54,7 +54,7 @@ ClipRenderer::~ClipRenderer()
 }
 
 void
-ClipRenderer::setClip( Clip* clip )
+ClipRenderer::setClip( QSharedPointer<Clip> clip )
 {
     // if the clip is different (or nullptr) we have to stop playback.
     if ( m_selectedClip != nullptr &&
@@ -64,7 +64,7 @@ ClipRenderer::setClip( Clip* clip )
     }
     if ( clip == nullptr )
     {
-        m_selectedClip = nullptr;
+        m_selectedClip.clear();
         m_clipLoaded = false;
         m_input = nullptr;
         return ;
@@ -72,12 +72,6 @@ ClipRenderer::setClip( Clip* clip )
     m_selectedClip = clip;
     if ( clip->length() == 0 )
         return ;
-    updateInfos( clip );
-}
-
-void
-ClipRenderer::updateInfos( Clip* clip )
-{
     if ( m_output->isStopped() == true )
         m_clipLoaded = false;
     else
@@ -89,7 +83,6 @@ ClipRenderer::startPreview()
 {
     if ( m_selectedClip == nullptr || m_selectedClip->length() == 0 )
         return ;
-    updateInfos( m_selectedClip );
     setInput( m_selectedClip->input() );
 
     m_input->setPosition( 0 );
@@ -154,11 +147,11 @@ ClipRenderer::clipUnloaded( const QUuid& uuid )
     {
         stop();
         m_clipLoaded = false;
-        m_selectedClip = nullptr;
+        m_selectedClip.clear();
     }
 }
 
-Clip*
+QSharedPointer<Clip>
 ClipRenderer::getClip()
 {
     return m_selectedClip;
diff --git a/src/Renderer/ClipRenderer.h b/src/Renderer/ClipRenderer.h
index 998b2ea7..43ede34f 100644
--- a/src/Renderer/ClipRenderer.h
+++ b/src/Renderer/ClipRenderer.h
@@ -27,6 +27,7 @@
 #include "AbstractRenderer.h"
 
 #include <QObject>
+#include <QSharedPointer>
 
 class   Clip;
 class   Media;
@@ -44,14 +45,14 @@ public:
     virtual void            stop();
     virtual qint64          length() const;
     virtual qint64          getLengthMs() const;
-    virtual Clip            *getClip();
+    virtual QSharedPointer<Clip> getClip();
 
 private:
     void                    startPreview();
 
 private:
     bool                    m_clipLoaded;
-    Clip*                   m_selectedClip;
+    QSharedPointer<Clip>    m_selectedClip;
     /**
      *  \brief  This flags is used to know if a new media has been selected in the
      * library. If so, we must relaunch the render if the play button is clicked again.
@@ -63,9 +64,8 @@ public slots:
      *  \brief      Set the Clip to render
      *  \param      clip    The clip to render
      */
-    void                    setClip( Clip* clip );
+    void                    setClip( QSharedPointer<Clip> clip );
     void                    clipUnloaded( const QUuid& uuid );
-    void                    updateInfos( Clip* clip );
 
     /**
      *  \brief      Triggered at every libvlc_MediaPlayerTimeChanged event.



More information about the Vlmc-devel mailing list