[vlmc-devel] [PATCH 2/4] VmemRenderer: Use shared_ptr to manage m_snapshot
Yikai Lu
luyikei.qmltu at gmail.com
Tue Apr 12 13:10:40 CEST 2016
---
src/Backend/VLC/VLCVmemRenderer.cpp | 9 ++++-----
src/Backend/VLC/VLCVmemRenderer.h | 4 +++-
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/Backend/VLC/VLCVmemRenderer.cpp b/src/Backend/VLC/VLCVmemRenderer.cpp
index d062bbe..65c3430 100644
--- a/src/Backend/VLC/VLCVmemRenderer.cpp
+++ b/src/Backend/VLC/VLCVmemRenderer.cpp
@@ -59,7 +59,6 @@ VmemRenderer::~VmemRenderer()
* destroyed in a potentially locked state, while the vmem tries to lock/unlock.
*/
stop();
- delete[] m_snapshot;
}
::VLC::MediaPlayer&
@@ -75,16 +74,16 @@ VmemRenderer::waitSnapshot()
m_snapshotRequired = true;
if ( m_waitCond.wait( &m_mutex, 3000 ) == false )
return nullptr;
- return m_snapshot;
+ return m_snapshot.get();
}
void*
VmemRenderer::vmemLock( void **planes)
{
QMutexLocker lock( &m_mutex );
- m_snapshot = new uint8_t[320 * 180 * 4];
- *planes = m_snapshot;
- return m_snapshot;
+ m_snapshot = std::shared_ptr<uint8_t>( new uint8_t[320 * 180 * 4] );
+ *planes = m_snapshot.get();
+ return nullptr;
}
void
diff --git a/src/Backend/VLC/VLCVmemRenderer.h b/src/Backend/VLC/VLCVmemRenderer.h
index 89b105d..de79410 100644
--- a/src/Backend/VLC/VLCVmemRenderer.h
+++ b/src/Backend/VLC/VLCVmemRenderer.h
@@ -23,6 +23,7 @@
#ifndef VLCVMEMRENDERER_H
#define VLCVMEMRENDERER_H
+#include <memory>
#include <QMutex>
#include <QWaitCondition>
@@ -54,7 +55,8 @@ private:
void vmemUnlock( void* picture );
private:
- uint8_t* m_snapshot;
+ std::shared_ptr<uint8_t> m_snapshot;
+
bool m_snapshotRequired;
QMutex m_mutex;
QWaitCondition m_waitCond;
--
1.9.1
More information about the Vlmc-devel
mailing list