[vlmc-devel] [PATCH 5/5] VLCSource: Avoid deleting VmemRenderer too early
Yikai Lu
luyikei.qmltu at gmail.com
Tue Apr 12 15:09:34 CEST 2016
If we declare in a function like "VmemRenderer renderer( some values )" just as we did before, it will be removed as soon as the function ends. Since the renderer don't know how much time should be needed to render a snapshot, we should keep it alive as long as possible.
---
src/Backend/VLC/VLCSource.cpp | 16 +++++++++-------
src/Backend/VLC/VLCSource.h | 3 ++-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/Backend/VLC/VLCSource.cpp b/src/Backend/VLC/VLCSource.cpp
index eee870a..d96ca6e 100644
--- a/src/Backend/VLC/VLCSource.cpp
+++ b/src/Backend/VLC/VLCSource.cpp
@@ -39,6 +39,7 @@ VLCSource::VLCSource( VLCBackend* backend, const QString& path )
, m_snapshot( nullptr )
, m_isParsed( false )
, m_nbFrames( 0 )
+ , m_vmemRenderer( nullptr )
{
m_media = ::VLC::Media( backend->vlcInstance(), path.toStdString(), ::VLC::Media::FromPath );
}
@@ -47,6 +48,7 @@ VLCSource::~VLCSource()
{
if ( m_snapshot )
delete[] m_snapshot;
+ delete m_vmemRenderer;
}
::VLC::Media&
@@ -69,7 +71,6 @@ VLCSource::preparse()
Q_ASSERT( m_nbAudioTracks == 0 );
Q_ASSERT( m_nbVideoTracks == 0 );
- VmemRenderer renderer( m_backend, this, nullptr );
m_media.parse();
m_length = m_media.duration();
auto tracks = m_media.tracks();
@@ -91,7 +92,7 @@ VLCSource::preparse()
m_width = t.width();
m_height = t.height();
m_nbFrames = (int64_t)( (float)( m_length / 1000 ) * m_fps );
- computeSnapshot( renderer );
+ computeSnapshot();
}
}
else if ( t.type() == ::VLC::MediaTrack::Type::Audio )
@@ -108,25 +109,26 @@ VLCSource::isParsed() const
}
bool
-VLCSource::computeSnapshot( VmemRenderer& renderer )
+VLCSource::computeSnapshot()
{
Q_ASSERT( m_snapshot == nullptr );
- renderer.start();
+ m_vmemRenderer = new VmemRenderer( m_backend, this, nullptr );
+ m_vmemRenderer->start();
{
QMutex mutex;
QWaitCondition cond;
- auto em = renderer.mediaPlayer().eventManager();
+ auto em = m_vmemRenderer->mediaPlayer().eventManager();
em.onPositionChanged([&mutex, &cond](float pos) {
QMutexLocker lock( &mutex );
if ( pos > 0.2 )
cond.wakeAll();
});
QMutexLocker lock( &mutex );
- renderer.setPosition( 0.3 );
+ m_vmemRenderer->setPosition( 0.3 );
if ( cond.wait( &mutex, 2000 ) == false )
return false;
}
- m_snapshot = renderer.waitSnapshot();
+ m_snapshot = m_vmemRenderer->waitSnapshot();
return m_snapshot != nullptr;
}
diff --git a/src/Backend/VLC/VLCSource.h b/src/Backend/VLC/VLCSource.h
index 4fee4dc..745d7bd 100644
--- a/src/Backend/VLC/VLCSource.h
+++ b/src/Backend/VLC/VLCSource.h
@@ -59,7 +59,7 @@ public:
::VLC::Media& media();
private:
- bool computeSnapshot( VmemRenderer& renderer );
+ bool computeSnapshot();
private:
VLCBackend* m_backend;
@@ -73,6 +73,7 @@ private:
const uint8_t* m_snapshot;
bool m_isParsed;
int64_t m_nbFrames;
+ VmemRenderer* m_vmemRenderer;
};
--
1.9.1
More information about the Vlmc-devel
mailing list