[vlmc-devel] MLTFilter: Try to get length from its connected producer if unlimited.

Yikai Lu git at videolan.org
Tue Jun 28 10:39:44 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Tue Jun 28 15:48:26 2016 +0900| [49a94373aed428c33d5f456d8d931faba7762560] | committer: Yikai Lu

MLTFilter: Try to get length from its connected producer if unlimited.

> https://code.videolan.org/videolan/vlmc/commit/49a94373aed428c33d5f456d8d931faba7762560
---

 src/Backend/MLT/MLTFilter.cpp  | 18 ++++++++++++++++--
 src/Backend/MLT/MLTFilter.h    |  4 +++-
 src/Backend/MLT/MLTService.cpp |  2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/Backend/MLT/MLTFilter.cpp b/src/Backend/MLT/MLTFilter.cpp
index 5c154ef..acdcaa5 100644
--- a/src/Backend/MLT/MLTFilter.cpp
+++ b/src/Backend/MLT/MLTFilter.cpp
@@ -22,6 +22,7 @@
 
 #include "MLTFilter.h"
 #include <mlt++/MltFilter.h>
+#include <mlt++/MltProducer.h>
 
 #include <cstring>
 #include "Backend/IBackend.h"
@@ -153,6 +154,7 @@ MLTFilterInfo::setProperties( Mlt::Properties* properties )
 }
 
 MLTFilter::MLTFilter( Backend::IProfile& profile, const char* id )
+    : m_connectedService( nullptr )
 {
     MLTProfile& mltProfile = static_cast<MLTProfile&>( profile );
     m_filter = new Mlt::Filter( *mltProfile.m_profile, id );
@@ -167,9 +169,10 @@ MLTFilter::MLTFilter( const char *id )
 
 }
 
-MLTFilter::MLTFilter( Mlt::Filter* filter )
+MLTFilter::MLTFilter( Mlt::Filter* filter, Mlt::Service* connectedService )
 {
     m_filter = filter;
+    m_connectedService = connectedService;
     m_service = filter;
 }
 
@@ -186,6 +189,8 @@ MLTFilter::connect( Backend::IService& service, int index )
     if ( mltService == nullptr )
         return true;
 
+    m_connectedService = mltService->m_service;
+
     return m_filter->connect( *mltService->m_service, index );
 }
 
@@ -210,7 +215,16 @@ MLTFilter::end() const
 int64_t
 MLTFilter::length() const
 {
-    return m_filter->get_length();
+    auto length = m_filter->get_length();
+
+    if ( length == 0 )
+    {
+        auto producer = dynamic_cast<Mlt::Producer*>( m_connectedService );
+        if ( producer != nullptr )
+            length = producer->get_playtime();
+    }
+
+    return length ? length : Unlimited;
 }
 
 const Backend::IFilterInfo&
diff --git a/src/Backend/MLT/MLTFilter.h b/src/Backend/MLT/MLTFilter.h
index a2bd118..3285680 100644
--- a/src/Backend/MLT/MLTFilter.h
+++ b/src/Backend/MLT/MLTFilter.h
@@ -30,6 +30,7 @@ namespace Mlt
 {
 class Filter;
 class Properties;
+class Producer;
 }
 
 namespace Backend
@@ -90,7 +91,7 @@ namespace MLT
     public:
         MLTFilter( IProfile& profile, const char* id );
         MLTFilter( const char* id );
-        MLTFilter( Mlt::Filter* filter );
+        MLTFilter( Mlt::Filter* filter, Mlt::Service* connectedService );
         virtual ~MLTFilter() override;
 
         virtual bool    connect( IService& service, int index = 0 ) override;
@@ -103,6 +104,7 @@ namespace MLT
 
     private:
         Mlt::Filter*        m_filter;
+        Mlt::Service*       m_connectedService;
 
     friend class MLTTractor;
     friend class MLTService;
diff --git a/src/Backend/MLT/MLTService.cpp b/src/Backend/MLT/MLTService.cpp
index 3800e56..8642da8 100644
--- a/src/Backend/MLT/MLTService.cpp
+++ b/src/Backend/MLT/MLTService.cpp
@@ -112,7 +112,7 @@ MLTService::moveFilter( int from, int to )
 std::shared_ptr<Backend::IFilter>
 MLTService::filter( int index ) const
 {
-    return std::shared_ptr<Backend::IFilter>( new MLTFilter( m_service->filter( index ) ) );
+    return std::shared_ptr<Backend::IFilter>( new MLTFilter( m_service->filter( index ), m_service ) );
 }
 
 void



More information about the Vlmc-devel mailing list