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

Refactored StackedBuffer to avoid multiple template parameters.

parent d144b005
......@@ -24,6 +24,8 @@
#include "ProjectSettingsDefault.h"
#include "ProjectManager.h"
#include <QtDebug>
void ProjectSettingsDefault::load( const QString& part )
{
SettingsManager::getInstance()->addNewSettingsPart( part );
......@@ -60,7 +62,7 @@ void ProjectSettingsDefault::loadVideoDefaults( const QString& part )
settingsMan->setValue( part,
"VideoProjectWidth",
defaultProjectWidth );
qDebug() << "Loaded defaults values";
return ;
}
......
......@@ -200,6 +200,7 @@ void SettingsManager::flush()
void SettingsManager::loadDefaultsSettings()
{
qDebug() << "Load default settings ?";
if ( !SettingsManager::m_defaultLoaded )
{
SettingsManager::m_defaultLoaded = true;
......
......@@ -65,7 +65,8 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
return NULL;
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
StackedBuffer<AudioSample*, AudioClipWorkflow>* buff = new StackedBuffer<AudioSample*, AudioClipWorkflow>( m_computedBuffers.dequeue(), this, true );
::StackedBuffer<AudioSample*>* buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true );
postGetOutput();
return buff;
}
......@@ -171,3 +172,18 @@ void AudioClipWorkflow::flushComputedBuffers()
m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
}
}
AudioClipWorkflow::StackedBuffer::StackedBuffer( AudioClipWorkflow::AudioSample *as,
AudioClipWorkflow *poolHandler,
bool mustBeReleased) :
::StackedBuffer<AudioClipWorkflow::AudioSample*>( as, mustBeReleased ),
m_poolHandler( poolHandler )
{
}
void AudioClipWorkflow::StackedBuffer::release()
{
if ( m_mustRelease == true )
m_poolHandler->releaseBuffer( m_buff );
delete this;
}
......@@ -38,6 +38,16 @@ class AudioClipWorkflow : public ClipWorkflow
qint64 ptsDiff;
uint32_t debugId;
};
class StackedBuffer : public ::StackedBuffer<AudioSample*>
{
public:
StackedBuffer( AudioSample* lvf, AudioClipWorkflow* poolHandler,
bool mustBeReleased = true);
virtual void release();
private:
AudioClipWorkflow* m_poolHandler;
};
AudioClipWorkflow( Clip* clip );
~AudioClipWorkflow();
void* getLockCallback();
......@@ -65,8 +75,6 @@ class AudioClipWorkflow : public ClipWorkflow
//FIXME: this is totally random powered ! Please adjust with a value that does make sense...
static const uint32_t nbBuffers = 256;
friend class StackedBuffer<AudioSample*, AudioClipWorkflow>;
};
#endif // AUDIOCLIPWORKFLOW_H
......@@ -26,24 +26,19 @@
#include <QtDebug>
#include "Pool.hpp"
template <typename T, typename U>
template <typename T>
class StackedBuffer
{
public:
StackedBuffer( T buff, U* poolHandler, bool mustBeReleased = true ) :
StackedBuffer( T buff, bool mustBeReleased = true ) :
m_buff( buff ),
m_poolHandler( poolHandler ),
m_mustRelease( mustBeReleased )
{
}
/// \warning Calling this method will definitely invalidate the pointer;
void release()
{
if ( m_mustRelease == true )
m_poolHandler->releaseBuffer( m_buff );
delete this;
}
virtual void release() = 0;
const T& get() const
{
return m_buff;
......@@ -61,9 +56,8 @@ class StackedBuffer
return get();
}
private:
protected:
T m_buff;
U* m_poolHandler;
bool m_mustRelease;
};
......
......@@ -114,8 +114,8 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
m_effectEngine->setVideoInput( i + 1, *TrackHandler::nullOutput );
else
{
StackedBuffer<LightVideoFrame*, VideoClipWorkflow>* stackedBuffer =
reinterpret_cast<StackedBuffer<LightVideoFrame*, VideoClipWorkflow>*>(
StackedBuffer<LightVideoFrame*>* stackedBuffer =
reinterpret_cast<StackedBuffer<LightVideoFrame*>*>(
m_tracks[i]->getOutput( currentFrame, subFrame ) );
m_effectEngine->setVideoInput( i + 1, *( stackedBuffer->get() ) );
......@@ -123,9 +123,9 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
}
else
{
StackedBuffer<AudioClipWorkflow::AudioSample*, AudioClipWorkflow>*
StackedBuffer<AudioClipWorkflow::AudioSample*>*
stackedBuffer =
reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*, AudioClipWorkflow>*> (
reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*> (
m_tracks[i]->getOutput( currentFrame, subFrame ) );
if ( stackedBuffer != NULL )
m_tmpAudioBuffer = stackedBuffer->get();
......
......@@ -276,9 +276,9 @@ void* TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFra
qCritical() << "There's more than one clip to render here. Undefined behaviour !";
ret = renderClip( cw, currentFrame, start, needRepositioning );
if ( m_trackType == MainWorkflow::VideoTrack )
m_videoStackedBuffer = reinterpret_cast<StackedBuffer<LightVideoFrame*, VideoClipWorkflow>*>( ret );
m_videoStackedBuffer = reinterpret_cast<StackedBuffer<LightVideoFrame*>*>( ret );
else
m_audioStackedBuffer = reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*, AudioClipWorkflow>*>( ret );
m_audioStackedBuffer = reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*>( ret );
}
//Is it about to be rendered ?
else if ( start > currentFrame &&
......
......@@ -28,10 +28,8 @@
#include <QObject>
class AudioClipWorkflow;
class ClipWorkflow;
class LightVideoFrame;
class VideoClipWorkflow;
class QDomElement;
class QDomElement;
......@@ -116,9 +114,8 @@ class TrackWorkflow : public QObject
MainWorkflow::TrackType m_trackType;
qint64 m_lastFrame;
//Damn i wish this could be a meta-if :D (ho wait... it could be ! once the code will be cleaned)
StackedBuffer<LightVideoFrame*, VideoClipWorkflow>* m_videoStackedBuffer;
StackedBuffer<AudioClipWorkflow::AudioSample*, AudioClipWorkflow>* m_audioStackedBuffer;
StackedBuffer<LightVideoFrame*>* m_videoStackedBuffer;
StackedBuffer<AudioClipWorkflow::AudioSample*>* m_audioStackedBuffer;
signals:
void trackEndReached( unsigned int );
......
......@@ -97,15 +97,13 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
"Computed:" << m_computedBuffers.count();*/
if ( isEndReached() == true )
return NULL;
StackedBuffer<LightVideoFrame*, VideoClipWorkflow>* buff;
::StackedBuffer<LightVideoFrame*>* buff;
if ( mode == ClipWorkflow::Pop )
{
buff = new StackedBuffer<LightVideoFrame*, VideoClipWorkflow>(
m_computedBuffers.dequeue(), this, true );
buff = new StackedBuffer( m_computedBuffers.dequeue(), this, true );
}
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer<LightVideoFrame*, VideoClipWorkflow>(
m_computedBuffers.head(), NULL, false );
buff = new StackedBuffer( m_computedBuffers.head(), NULL, false );
postGetOutput();
return buff;
}
......@@ -192,3 +190,18 @@ VideoClipWorkflow::flushComputedBuffers()
m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
}
}
VideoClipWorkflow::StackedBuffer::StackedBuffer( LightVideoFrame *lvf,
VideoClipWorkflow *poolHandler,
bool mustBeReleased) :
::StackedBuffer<LightVideoFrame*>( lvf, mustBeReleased ),
m_poolHandler( poolHandler )
{
}
void VideoClipWorkflow::StackedBuffer::release()
{
if ( m_mustRelease == true )
m_poolHandler->releaseBuffer( m_buff );
delete this;
}
......@@ -32,6 +32,16 @@ class Clip;
class VideoClipWorkflow : public ClipWorkflow
{
public:
class StackedBuffer : public ::StackedBuffer<LightVideoFrame*>
{
public:
StackedBuffer( LightVideoFrame* lvf, VideoClipWorkflow* poolHandler,
bool mustBeReleased = true);
virtual void release();
private:
VideoClipWorkflow* m_poolHandler;
};
VideoClipWorkflow( Clip* clip );
~VideoClipWorkflow();
void* getLockCallback();
......@@ -52,8 +62,6 @@ class VideoClipWorkflow : public ClipWorkflow
QQueue<LightVideoFrame*> m_availableBuffers;
static void lock( VideoClipWorkflow* clipWorkflow, void** pp_ret, int size );
static void unlock( VideoClipWorkflow* clipWorkflow, void* buffer, int width, int height, int bpp, int size, qint64 pts );
friend class StackedBuffer<LightVideoFrame*, VideoClipWorkflow>;
};
#endif // VIDEOCLIPWORKFLOW_H
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