Commit ee8974cc authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Started clip workflow refactoring.

Pool is now "MemoryPool" and a new pool has been created.
It comes with a StackedBuffer class to release buffer that will be
filled by new clipworkflows
parent a9ffce54
/*****************************************************************************
* MemoryPool.hpp: Generic memory pool, that will reinstantiate
* a new object each time
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef MEMORYPOOL_HPP
#define MEMORYPOOL_HPP
#include <QMutex>
#include <QQueue>
#include "Singleton.hpp"
template <typename T, size_t NB_ELEM = 5>
class MemoryPool : public Singleton< MemoryPool<T, NB_ELEM> >
{
public:
T* get()
{
QMutexLocker lock( m_mutex );
if ( m_pool.size() == 0 )
{
qCritical() << "Pool is empty !!";
return new T;
}
uint8_t* ptr = m_pool.dequeue();
T* ret = new (ptr) T;
return ret;
}
void release( T* toRelease )
{
QMutexLocker lock( m_mutex );
toRelease->~T();
m_pool.enqueue( reinterpret_cast<uint8_t*>( toRelease ) );
}
private:
MemoryPool()
{
for ( size_t i = 0; i < NB_ELEM; ++i )
m_pool.enqueue( new uint8_t[ sizeof(T) ] );
m_mutex = new QMutex;
}
~MemoryPool()
{
while ( m_pool.size() != 0 )
{
uint8_t* ptr = m_pool.dequeue();
delete ptr;
}
delete m_mutex;
}
QQueue<uint8_t*> m_pool;
QMutex* m_mutex;
friend class Singleton< MemoryPool<T> >;
};
#endif // MEMORYPOOL_HPP
/*****************************************************************************
* Pool.hpp: Generic object pool
* Pool.hpp: Generic pool
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -28,47 +28,39 @@
#include "Singleton.hpp"
template <typename T, size_t NB_ELEM = 5>
class Pool : public Singleton< Pool<T, NB_ELEM> >
template <typename T>
class Pool
{
public:
T* get()
T get()
{
QMutexLocker lock( m_mutex );
if ( m_pool.size() == 0 )
{
return new T;
qCritical() << "Pool is empty !!";
return NULL;
}
uint8_t* ptr = m_pool.dequeue();
T* ret = new (ptr) T;
T ret = m_pool.dequeue();
return ret;
}
void release( T* toRelease )
void release( T toRelease )
{
QMutexLocker lock( m_mutex );
toRelease->~T();
m_pool.enqueue( reinterpret_cast<uint8_t*>( toRelease ) );
m_pool.enqueue( toRelease );
}
private:
Pool()
{
for ( size_t i = 0; i < NB_ELEM; ++i )
m_pool.enqueue( new uint8_t[ sizeof(T) ] );
m_mutex = new QMutex;
}
~Pool()
{
while ( m_pool.size() != 0 )
{
uint8_t* ptr = m_pool.dequeue();
delete ptr;
}
Q_ASSERT( m_pool.empty() == true );
delete m_mutex;
}
QQueue<uint8_t*> m_pool;
QMutex* m_mutex;
friend class Singleton< Pool<T> >;
};
#endif // POOL_HPP
#endif // MEMORYPOOL_HPP
HEADERS += Pool.hpp \
HEADERS += MemoryPool.hpp \
QSingleton.hpp \
Singleton.hpp \
Toggleable.hpp \
WaitCondition.hpp \
VlmcDebug.h
VlmcDebug.h \
Pool.hpp
SOURCES += VlmcDebug.cpp
......@@ -70,12 +70,7 @@ void AudioClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
m_vlcMedia->addOption( ":sout-transcode-samplerate=48000" );
m_vlcMedia->addOption( ":sout-transcode-channels=2" );
if ( m_fullSpeedRender == true )
{
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
else
m_vlcMedia->addOption( ":sout-smem-time-sync" );
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer , unsigned int size )
......
......@@ -24,7 +24,7 @@
#include "vlmc.h"
#include "ClipWorkflow.h"
#include "Pool.hpp"
#include "MemoryPool.hpp"
#include "LightVideoFrame.h"
ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
......@@ -83,7 +83,7 @@ void ClipWorkflow::initialize( bool preloading /*= false*/ )
m_currentPts = -1;
m_previousPts = -1;
initVlcOutput();
m_mediaPlayer = Pool<LibVLCpp::MediaPlayer>::getInstance()->get();
m_mediaPlayer = MemoryPool<LibVLCpp::MediaPlayer>::getInstance()->get();
m_mediaPlayer->setMedia( m_vlcMedia );
if ( preloading == true )
......@@ -187,7 +187,7 @@ void ClipWorkflow::stop()
{
m_mediaPlayer->stop();
disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( clipEndReached() ) );
Pool<LibVLCpp::MediaPlayer>::getInstance()->release( m_mediaPlayer );
MemoryPool<LibVLCpp::MediaPlayer>::getInstance()->release( m_mediaPlayer );
// qDebug() << "Setting media player to NULL";
m_mediaPlayer = NULL;
setState( Stopped );
......
......@@ -52,6 +52,17 @@ class ClipWorkflow : public QObject
EndReached, //8
};
/**
* \brief Used to know which way you want to get a computed output.
* Pop: the buffer is popped and returned
* Get: the buffer is just returned (for paused mode for instance)
*/
enum GetMode
{
Pop,
Get,
};
ClipWorkflow( Clip* clip );
virtual ~ClipWorkflow();
......
/*****************************************************************************
* StackedBuffer.hpp: A buffer that's must can be released and pushed back on a Pool.
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef STACKEDBUFFER_HPP
#define STACKEDBUFFER_HPP
#include "Pool.hpp"
/**
* This class is to be used closely with the templated Pool.
* When release, the buffer will automatically pushed itself back into the appropriate pool.
*/
template <typename T>
class StackedBuffer
{
public:
StackedBuffer( T buff, Pool<T>* pool, bool mustBeReleased = true ) :
m_buff( buff ),
m_pool( pool ),
m_released( false ),
m_mustRelease( mustBeReleased )
{
}
void release()
{
Q_ASSERT( m_released == false );
Q_ASSERT( m_mustRelease == true );
m_released = true;
m_pool->release( m_buff );
}
const T& get() const
{
return m_buff;
}
T get()
{
return m_buff;
}
operator const T&() const
{
return get();
}
operator T()
{
return get();
}
private:
T m_buff;
Pool<T>* m_pool;
bool m_released;
bool m_mustRelease;
};
#endif // STACKEDBUFFER_HPP
......@@ -49,12 +49,7 @@ void VideoClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
// m_vlcMedia->addOption( ":no-sout-keep" );
if ( m_fullSpeedRender == true )
{
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
else
m_vlcMedia->addOption( ":sout-smem-time-sync" );
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
sprintf( buffer, ":sout-transcode-width=%i", MainWorkflow::getInstance()->getWidth() );
m_vlcMedia->addOption( buffer );
......
......@@ -25,6 +25,8 @@
#include "ClipWorkflow.h"
#include "Clip.h"
#include "StackedBuffer.hpp"
#include "Pool.hpp"
class VideoClipWorkflow : public ClipWorkflow
{
......@@ -35,6 +37,8 @@ class VideoClipWorkflow : public ClipWorkflow
void* getUnlockCallback();
virtual void* getOutput();
static const uint32_t nbBuffers = 3 * 30; //3 seconds with an average fps of 30
protected:
virtual void initVlcOutput();
......
......@@ -4,7 +4,8 @@ HEADERS += AudioClipWorkflow.h \
TrackHandler.h \
TrackWorkflow.h \
VideoClipWorkflow.h \
ImageClipWorkflow.h
ImageClipWorkflow.h \
StackedBuffer.hpp
SOURCES += AudioClipWorkflow.cpp \
ClipWorkflow.cpp \
MainWorkflow.cpp \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment