[vlmc-devel] VmemRenderer, VLCSource: Don't use QImage to store a snapshot

Yikai Lu git at videolan.org
Tue Apr 12 14:55:28 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Tue Apr 12 20:10:39 2016 +0900| [4ca6417c3b075d5308d88d8c37366353e1dbf870] | committer: Hugo Beauzée-Luyssen

VmemRenderer, VLCSource: Don't use QImage to store a snapshot

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> https://code.videolan.org/videolan/vlmc/commit/4ca6417c3b075d5308d88d8c37366353e1dbf870
---

 src/Backend/VLC/VLCSource.cpp       |  2 +-
 src/Backend/VLC/VLCSource.h         |  4 ++--
 src/Backend/VLC/VLCVmemRenderer.cpp | 12 ++++++------
 src/Backend/VLC/VLCVmemRenderer.h   |  6 ++----
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/Backend/VLC/VLCSource.cpp b/src/Backend/VLC/VLCSource.cpp
index 39fa756..d38d12f 100644
--- a/src/Backend/VLC/VLCSource.cpp
+++ b/src/Backend/VLC/VLCSource.cpp
@@ -176,7 +176,7 @@ VLCSource::snapshot() const
 {
     if ( hasVideo() == false || m_snapshot == nullptr )
         return nullptr;
-    return m_snapshot->bits();
+    return m_snapshot;
 }
 
 int64_t
diff --git a/src/Backend/VLC/VLCSource.h b/src/Backend/VLC/VLCSource.h
index 60ecb11..10a7d08 100644
--- a/src/Backend/VLC/VLCSource.h
+++ b/src/Backend/VLC/VLCSource.h
@@ -23,7 +23,7 @@
 #ifndef VLCRSOURCE_H
 #define VLCRSOURCE_H
 
-#include <QImage>
+#include <QtGlobal>
 
 #include "Backend/ISource.h"
 #include "libvlcpp/vlcpp/vlc.hpp"
@@ -69,7 +69,7 @@ private:
     unsigned int                m_nbVideoTracks;
     unsigned int                m_nbAudioTracks;
     int64_t                     m_length; //in milliseconds.
-    QImage*                     m_snapshot;
+    uint8_t*                    m_snapshot;
     bool                        m_isParsed;
     int64_t                     m_nbFrames;
 };
diff --git a/src/Backend/VLC/VLCVmemRenderer.cpp b/src/Backend/VLC/VLCVmemRenderer.cpp
index d840e31..d062bbe 100644
--- a/src/Backend/VLC/VLCVmemRenderer.cpp
+++ b/src/Backend/VLC/VLCVmemRenderer.cpp
@@ -35,8 +35,7 @@ VmemRenderer::VmemRenderer( VLCBackend* backend, VLCSource *source , ISourceRend
 {
     m_media.parse();
     setName( "VmemRenderer" );
-    m_snapshot = new QImage( 320, 180, QImage::Format_RGB32 );
-    m_mediaPlayer.setVideoFormat( "RV32", m_snapshot->width(), m_snapshot->height(), m_snapshot->bytesPerLine() );
+    m_mediaPlayer.setVideoFormat( "RV32", 320, 180, 320 * 4 );
     m_mediaPlayer.setVideoCallbacks(
         // Lock:
         [this]( void** planes ) {
@@ -60,7 +59,7 @@ VmemRenderer::~VmemRenderer()
      * destroyed in a potentially locked state, while the vmem tries to lock/unlock.
      */
     stop();
-    delete m_snapshot;
+    delete[] m_snapshot;
 }
 
 ::VLC::MediaPlayer&
@@ -69,21 +68,22 @@ VmemRenderer::mediaPlayer()
     return m_mediaPlayer;
 }
 
-QImage*
+uint8_t*
 VmemRenderer::waitSnapshot()
 {
     QMutexLocker lock( &m_mutex );
     m_snapshotRequired = true;
     if ( m_waitCond.wait( &m_mutex, 3000 ) == false )
         return nullptr;
-    return new QImage( *m_snapshot );
+    return m_snapshot;
 }
 
 void*
 VmemRenderer::vmemLock( void **planes)
 {
     QMutexLocker lock( &m_mutex );
-    *planes = m_snapshot->bits();
+    m_snapshot = new uint8_t[320 * 180 * 4];
+    *planes = m_snapshot;
     return m_snapshot;
 }
 
diff --git a/src/Backend/VLC/VLCVmemRenderer.h b/src/Backend/VLC/VLCVmemRenderer.h
index 447d6bc..89b105d 100644
--- a/src/Backend/VLC/VLCVmemRenderer.h
+++ b/src/Backend/VLC/VLCVmemRenderer.h
@@ -28,8 +28,6 @@
 
 #include "VLCSourceRenderer.h"
 
-class QImage;
-
 namespace Backend
 {
 namespace VLC
@@ -49,14 +47,14 @@ public:
      *  the caller.
      * @return
      */
-    QImage *waitSnapshot();
+    uint8_t *waitSnapshot();
 
 private:
     void*    vmemLock( void **planes );
     void     vmemUnlock( void* picture );
 
 private:
-    QImage*         m_snapshot;
+    uint8_t*        m_snapshot;
     bool            m_snapshotRequired;
     QMutex          m_mutex;
     QWaitCondition  m_waitCond;



More information about the Vlmc-devel mailing list