Commit 09a34dc0 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

ClipWorkflow: Release preallocated buffers when stopping.

parent 9397a6ad
...@@ -27,6 +27,18 @@ ...@@ -27,6 +27,18 @@
AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) : AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
ClipWorkflow( clip ) ClipWorkflow( clip )
{
debugType = 1;
m_ptsOffset = 0;
}
AudioClipWorkflow::~AudioClipWorkflow()
{
releasePrealocated();
}
void
AudioClipWorkflow::preallocate()
{ {
for ( quint32 i = 0; i < AudioClipWorkflow::nbBuffers; ++i ) for ( quint32 i = 0; i < AudioClipWorkflow::nbBuffers; ++i )
{ {
...@@ -35,16 +47,23 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) : ...@@ -35,16 +47,23 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
m_availableBuffers.push_back( as ); m_availableBuffers.push_back( as );
as->debugId = i; as->debugId = i;
} }
debugType = 1;
m_ptsOffset = 0;
} }
AudioClipWorkflow::~AudioClipWorkflow() void
AudioClipWorkflow::releasePrealocated()
{ {
while ( m_availableBuffers.isEmpty() == false ) while ( m_availableBuffers.isEmpty() == false )
delete m_availableBuffers.dequeue(); {
AudioSample *as = m_availableBuffers.takeFirst();
delete as->buff;
delete as;
}
while ( m_computedBuffers.isEmpty() == false ) while ( m_computedBuffers.isEmpty() == false )
delete m_computedBuffers.dequeue(); {
AudioSample *as = m_computedBuffers.takeFirst();
delete as->buff;
delete as;
}
} }
void* void*
...@@ -90,6 +109,7 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode ) ...@@ -90,6 +109,7 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void void
AudioClipWorkflow::initVlcOutput() AudioClipWorkflow::initVlcOutput()
{ {
preallocate();
m_vlcMedia->addOption( ":no-sout-video" ); m_vlcMedia->addOption( ":no-sout-video" );
m_vlcMedia->addOption( ":no-video" ); m_vlcMedia->addOption( ":no-video" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" ); m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
......
...@@ -63,6 +63,8 @@ class AudioClipWorkflow : public ClipWorkflow ...@@ -63,6 +63,8 @@ class AudioClipWorkflow : public ClipWorkflow
virtual quint32 getNbComputedBuffers() const; virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const; virtual quint32 getMaxComputedBuffers() const;
void flushComputedBuffers(); void flushComputedBuffers();
void preallocate();
void releasePrealocated();
private: private:
void releaseBuffer( AudioSample *sample ); void releaseBuffer( AudioSample *sample );
......
...@@ -135,6 +135,7 @@ void ClipWorkflow::stop() ...@@ -135,6 +135,7 @@ void ClipWorkflow::stop()
setState( Stopped ); setState( Stopped );
delete m_vlcMedia; delete m_vlcMedia;
flushComputedBuffers(); flushComputedBuffers();
releasePrealocated();
} }
else else
qDebug() << "ClipWorkflow has already been stopped"; qDebug() << "ClipWorkflow has already been stopped";
......
...@@ -204,6 +204,11 @@ class ClipWorkflow : public QObject ...@@ -204,6 +204,11 @@ class ClipWorkflow : public QObject
*/ */
virtual void flushComputedBuffers() = 0; virtual void flushComputedBuffers() = 0;
/**
* \brief Release the preallocated buffers
*/
virtual void releasePrealocated() = 0;
private: private:
WaitCondition* m_initWaitCond; WaitCondition* m_initWaitCond;
WaitCondition* m_pausingStateWaitCond; WaitCondition* m_pausingStateWaitCond;
......
...@@ -47,6 +47,7 @@ class ImageClipWorkflow : public ClipWorkflow ...@@ -47,6 +47,7 @@ class ImageClipWorkflow : public ClipWorkflow
virtual quint32 getNbComputedBuffers() const; virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const; virtual quint32 getMaxComputedBuffers() const;
virtual void flushComputedBuffers(); virtual void flushComputedBuffers();
virtual void releasePrealocated(){}
private: private:
static void lock( ImageClipWorkflow* clipWorkflow, void** pp_ret, static void lock( ImageClipWorkflow* clipWorkflow, void** pp_ret,
int size ); int size );
......
...@@ -39,6 +39,12 @@ VideoClipWorkflow::VideoClipWorkflow( Clip *clip ) : ...@@ -39,6 +39,12 @@ VideoClipWorkflow::VideoClipWorkflow( Clip *clip ) :
} }
VideoClipWorkflow::~VideoClipWorkflow() VideoClipWorkflow::~VideoClipWorkflow()
{
releasePrealocated();
}
void
VideoClipWorkflow::releasePrealocated()
{ {
while ( m_availableBuffers.isEmpty() == false ) while ( m_availableBuffers.isEmpty() == false )
delete m_availableBuffers.dequeue(); delete m_availableBuffers.dequeue();
......
...@@ -64,6 +64,7 @@ class VideoClipWorkflow : public ClipWorkflow ...@@ -64,6 +64,7 @@ class VideoClipWorkflow : public ClipWorkflow
* \brief Pre-allocate some image buffers. * \brief Pre-allocate some image buffers.
*/ */
void preallocate(); void preallocate();
void releasePrealocated();
private: private:
QQueue<LightVideoFrame*> m_computedBuffers; QQueue<LightVideoFrame*> m_computedBuffers;
......
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