[vlmc-devel] commit: ClipWorkflow: Release preallocated buffers when stopping. ( Hugo Beauzee-Luyssen )
git at videolan.org
git at videolan.org
Wed Mar 17 17:30:22 CET 2010
vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Wed Mar 17 11:51:55 2010 +0100| [09a34dc0c9b2392daf423a56888958daa18c46b8] | committer: Hugo Beauzee-Luyssen
ClipWorkflow: Release preallocated buffers when stopping.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=09a34dc0c9b2392daf423a56888958daa18c46b8
---
src/Workflow/AudioClipWorkflow.cpp | 30 +++++++++++++++++++++++++-----
src/Workflow/AudioClipWorkflow.h | 2 ++
src/Workflow/ClipWorkflow.cpp | 1 +
src/Workflow/ClipWorkflow.h | 5 +++++
src/Workflow/ImageClipWorkflow.h | 1 +
src/Workflow/VideoClipWorkflow.cpp | 6 ++++++
src/Workflow/VideoClipWorkflow.h | 1 +
7 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/src/Workflow/AudioClipWorkflow.cpp b/src/Workflow/AudioClipWorkflow.cpp
index e9240c9..f79a253 100644
--- a/src/Workflow/AudioClipWorkflow.cpp
+++ b/src/Workflow/AudioClipWorkflow.cpp
@@ -28,6 +28,18 @@
AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
ClipWorkflow( clip )
{
+ debugType = 1;
+ m_ptsOffset = 0;
+}
+
+AudioClipWorkflow::~AudioClipWorkflow()
+{
+ releasePrealocated();
+}
+
+void
+AudioClipWorkflow::preallocate()
+{
for ( quint32 i = 0; i < AudioClipWorkflow::nbBuffers; ++i )
{
AudioSample *as = new AudioSample;
@@ -35,16 +47,23 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
m_availableBuffers.push_back( as );
as->debugId = i;
}
- debugType = 1;
- m_ptsOffset = 0;
}
-AudioClipWorkflow::~AudioClipWorkflow()
+void
+AudioClipWorkflow::releasePrealocated()
{
while ( m_availableBuffers.isEmpty() == false )
- delete m_availableBuffers.dequeue();
+ {
+ AudioSample *as = m_availableBuffers.takeFirst();
+ delete as->buff;
+ delete as;
+ }
while ( m_computedBuffers.isEmpty() == false )
- delete m_computedBuffers.dequeue();
+ {
+ AudioSample *as = m_computedBuffers.takeFirst();
+ delete as->buff;
+ delete as;
+ }
}
void*
@@ -90,6 +109,7 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void
AudioClipWorkflow::initVlcOutput()
{
+ preallocate();
m_vlcMedia->addOption( ":no-sout-video" );
m_vlcMedia->addOption( ":no-video" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
diff --git a/src/Workflow/AudioClipWorkflow.h b/src/Workflow/AudioClipWorkflow.h
index eb0c318..9e09cb9 100644
--- a/src/Workflow/AudioClipWorkflow.h
+++ b/src/Workflow/AudioClipWorkflow.h
@@ -63,6 +63,8 @@ class AudioClipWorkflow : public ClipWorkflow
virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const;
void flushComputedBuffers();
+ void preallocate();
+ void releasePrealocated();
private:
void releaseBuffer( AudioSample *sample );
diff --git a/src/Workflow/ClipWorkflow.cpp b/src/Workflow/ClipWorkflow.cpp
index 0a80e01..53e7555 100644
--- a/src/Workflow/ClipWorkflow.cpp
+++ b/src/Workflow/ClipWorkflow.cpp
@@ -135,6 +135,7 @@ void ClipWorkflow::stop()
setState( Stopped );
delete m_vlcMedia;
flushComputedBuffers();
+ releasePrealocated();
}
else
qDebug() << "ClipWorkflow has already been stopped";
diff --git a/src/Workflow/ClipWorkflow.h b/src/Workflow/ClipWorkflow.h
index ba77a3a..e85191f 100644
--- a/src/Workflow/ClipWorkflow.h
+++ b/src/Workflow/ClipWorkflow.h
@@ -204,6 +204,11 @@ class ClipWorkflow : public QObject
*/
virtual void flushComputedBuffers() = 0;
+ /**
+ * \brief Release the preallocated buffers
+ */
+ virtual void releasePrealocated() = 0;
+
private:
WaitCondition* m_initWaitCond;
WaitCondition* m_pausingStateWaitCond;
diff --git a/src/Workflow/ImageClipWorkflow.h b/src/Workflow/ImageClipWorkflow.h
index 4e9f65f..2f1ccc7 100644
--- a/src/Workflow/ImageClipWorkflow.h
+++ b/src/Workflow/ImageClipWorkflow.h
@@ -47,6 +47,7 @@ class ImageClipWorkflow : public ClipWorkflow
virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const;
virtual void flushComputedBuffers();
+ virtual void releasePrealocated(){}
private:
static void lock( ImageClipWorkflow* clipWorkflow, void** pp_ret,
int size );
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index 4e89f0f..1fd5796 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -40,6 +40,12 @@ VideoClipWorkflow::VideoClipWorkflow( Clip *clip ) :
VideoClipWorkflow::~VideoClipWorkflow()
{
+ releasePrealocated();
+}
+
+void
+VideoClipWorkflow::releasePrealocated()
+{
while ( m_availableBuffers.isEmpty() == false )
delete m_availableBuffers.dequeue();
while ( m_computedBuffers.isEmpty() == false )
diff --git a/src/Workflow/VideoClipWorkflow.h b/src/Workflow/VideoClipWorkflow.h
index 3302e00..c70b1dc 100644
--- a/src/Workflow/VideoClipWorkflow.h
+++ b/src/Workflow/VideoClipWorkflow.h
@@ -64,6 +64,7 @@ class VideoClipWorkflow : public ClipWorkflow
* \brief Pre-allocate some image buffers.
*/
void preallocate();
+ void releasePrealocated();
private:
QQueue<LightVideoFrame*> m_computedBuffers;
More information about the Vlmc-devel
mailing list