[vlmc-devel] commit: MainWorkflow: Make getOutput return a const OutputBuffer* ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Tue Aug 24 22:57:00 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Tue Aug 24 22:50:09 2010 +0200| [c900bc8d493d779556fb96a8aae7b608ef1762b7] | committer: Hugo Beauzée-Luyssen 

MainWorkflow: Make getOutput return a const OutputBuffer*

This (and the changes that it implies) fix some flickering when applying
effects on a black screen.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=c900bc8d493d779556fb96a8aae7b608ef1762b7
---

 src/EffectsEngine/EffectsEngine.cpp |   20 ++++++++++----------
 src/EffectsEngine/EffectsEngine.h   |    8 ++++----
 src/Renderer/WorkflowRenderer.cpp   |   23 +++++++++++++++--------
 src/Renderer/WorkflowRenderer.h     |    2 ++
 src/Workflow/MainWorkflow.cpp       |    2 +-
 src/Workflow/MainWorkflow.h         |    2 +-
 src/Workflow/VideoClipWorkflow.cpp  |    4 +++-
 7 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/src/EffectsEngine/EffectsEngine.cpp b/src/EffectsEngine/EffectsEngine.cpp
index 11a0e4f..531eae3 100644
--- a/src/EffectsEngine/EffectsEngine.cpp
+++ b/src/EffectsEngine/EffectsEngine.cpp
@@ -110,19 +110,19 @@ EffectsEngine::browseDirectory( const QString &path )
     }
 }
 
-void
-EffectsEngine::applyFilters( const FilterList &effects, Workflow::Frame* frame,
+quint32*
+EffectsEngine::applyFilters( const FilterList &effects, const Workflow::Frame* frame,
                              qint64 currentFrame, double time )
 {
     if ( effects.size() == 0 )
-        return ;
+        return NULL;
     FilterList::const_iterator     it = effects.constBegin();
     FilterList::const_iterator     ite = effects.constEnd();
 
-    quint32     *buff1 = NULL;
-    quint32     *buff2 = NULL;
-    quint32     *input = frame->buffer();
-    bool        firstBuff = true;
+    quint32         *buff1 = NULL;
+    quint32         *buff2 = NULL;
+    const quint32   *input = frame->buffer();
+    bool            firstBuff = true;
 
     while ( it != ite )
     {
@@ -145,18 +145,18 @@ EffectsEngine::applyFilters( const FilterList &effects, Workflow::Frame* frame,
     }
     if ( buff1 != NULL || buff2 != NULL )
     {
-        //The old input frame will automatically be deleted when setting the new buffer
         if ( firstBuff == true )
         {
             delete[] buff1;
-            frame->setBuffer( buff2 );
+            return buff2;
         }
         else
         {
             delete[] buff2;
-            frame->setBuffer( buff1 );
+            return buff1;
         }
     }
+    return NULL;
 }
 
 void
diff --git a/src/EffectsEngine/EffectsEngine.h b/src/EffectsEngine/EffectsEngine.h
index 923e8e5..248194a 100644
--- a/src/EffectsEngine/EffectsEngine.h
+++ b/src/EffectsEngine/EffectsEngine.h
@@ -80,10 +80,10 @@ class   EffectsEngine : public QObject, public Singleton<EffectsEngine>
         void        loadEffects();
 
         //Filters methods:
-        static void applyFilters( const FilterList &effects,
-                                  Workflow::Frame *frame, qint64 currentFrame, double time );
-        static void saveFilters( const FilterList &effects, QXmlStreamWriter &project );
-        static void initFilters( const FilterList &effects, quint32 width, quint32 height );
+        static quint32  *applyFilters( const FilterList &effects,
+                                  const Workflow::Frame *frame, qint64 currentFrame, double time );
+        static void     saveFilters( const FilterList &effects, QXmlStreamWriter &project );
+        static void     initFilters( const FilterList &effects, quint32 width, quint32 height );
 
         //Mixers methods:
         static MixerHelper*     getMixer( const MixerList& mixers, qint64 currentFrame );
diff --git a/src/Renderer/WorkflowRenderer.cpp b/src/Renderer/WorkflowRenderer.cpp
index 68c7781..ad1ae7d 100644
--- a/src/Renderer/WorkflowRenderer.cpp
+++ b/src/Renderer/WorkflowRenderer.cpp
@@ -50,7 +50,8 @@ WorkflowRenderer::WorkflowRenderer() :
             m_height( 0 ),
             m_silencedAudioBuffer( NULL ),
             m_esHandler( NULL ),
-            m_oldLength( 0 )
+            m_oldLength( 0 ),
+            m_effectFrame( NULL )
 {
     m_effectsLock = new QReadWriteLock;
 }
@@ -159,12 +160,12 @@ int
 WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize, const void **buffer )
 {
     qint64                          ptsDiff = 0;
-    Workflow::Frame                 *ret;
+    const Workflow::Frame           *ret;
 
     if ( m_stopping == true )
         return 1;
 
-    ret = static_cast<Workflow::Frame*>( m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ) );
+    ret = static_cast<const Workflow::Frame*>( m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ) );
     ptsDiff = ret->ptsDiff;
     if ( ptsDiff == 0 )
     {
@@ -175,12 +176,15 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
     }
     {
         QReadLocker lock( m_effectsLock );
-        EffectsEngine::applyFilters( m_filters, ret,
+        m_effectFrame = EffectsEngine::applyFilters( m_filters, ret,
                                      m_mainWorkflow->getCurrentFrame(),
                                      m_mainWorkflow->getCurrentFrame() * 1000.0 / handler->fps );
     }
     m_pts = *pts = ptsDiff + m_pts;
-    *buffer = ret->buffer();
+    if ( m_effectFrame != NULL )
+        *buffer = m_effectFrame;
+    else
+        *buffer = ret->buffer();
     *bufferSize = ret->size();
     return 0;
 }
@@ -190,11 +194,11 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
 {
     qint64                              ptsDiff;
     quint32                             nbSample;
-    Workflow::AudioSample               *renderAudioSample;
+    const Workflow::AudioSample         *renderAudioSample;
 
     if ( m_stopping == false && m_paused == false )
     {
-        renderAudioSample = static_cast<Workflow::AudioSample*>( m_mainWorkflow->getOutput( Workflow::AudioTrack,
+        renderAudioSample = static_cast<const Workflow::AudioSample*>( m_mainWorkflow->getOutput( Workflow::AudioTrack,
                                                                                            m_paused ) );
     }
     else
@@ -222,8 +226,11 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
     return 0;
 }
 
-void    WorkflowRenderer::unlock( void*, const char*, size_t, void* )
+void    WorkflowRenderer::unlock( void *datas, const char*, size_t, void* )
 {
+    EsHandler*      handler = reinterpret_cast<EsHandler*>( datas );
+    delete[] handler->self->m_effectFrame;
+    handler->self->m_effectFrame = NULL;
 }
 
 void        WorkflowRenderer::startPreview()
diff --git a/src/Renderer/WorkflowRenderer.h b/src/Renderer/WorkflowRenderer.h
index 1e2e8f1..1d7d917 100644
--- a/src/Renderer/WorkflowRenderer.h
+++ b/src/Renderer/WorkflowRenderer.h
@@ -286,6 +286,8 @@ class   WorkflowRenderer : public GenericRenderer
         QReadWriteLock      *m_effectsLock;
         EffectsEngine::FilterList     m_filters;
 
+        quint32             *m_effectFrame;
+
         static const quint8     VideoCookie = '0';
         static const quint8     AudioCookie = '1';
 
diff --git a/src/Workflow/MainWorkflow.cpp b/src/Workflow/MainWorkflow.cpp
index 306d95a..414ba29 100644
--- a/src/Workflow/MainWorkflow.cpp
+++ b/src/Workflow/MainWorkflow.cpp
@@ -124,7 +124,7 @@ MainWorkflow::startRender( quint32 width, quint32 height, double fps )
     computeLength();
 }
 
-Workflow::OutputBuffer*
+const Workflow::OutputBuffer*
 MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused )
 {
     QMutexLocker        lock( m_renderStartedMutex );
diff --git a/src/Workflow/MainWorkflow.h b/src/Workflow/MainWorkflow.h
index 7980c04..bd90fe2 100644
--- a/src/Workflow/MainWorkflow.h
+++ b/src/Workflow/MainWorkflow.h
@@ -96,7 +96,7 @@ class   MainWorkflow : public QObject, public Singleton<MainWorkflow>
          *  \param  trackType   The type of track you wish to get the render from.
          *  \param  paused      The paused state of the renderer
          */
-        Workflow::OutputBuffer  *getOutput( Workflow::TrackType trackType, bool paused );
+        const Workflow::OutputBuffer    *getOutput( Workflow::TrackType trackType, bool paused );
         /**
          *  \brief              Set the workflow position by the desired frame
          *  \param              currentFrame: The desired frame to render from
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index 3902eb2..2db420f 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -176,8 +176,10 @@ VideoClipWorkflow::unlock( VideoClipWorkflow *cw, void *buffer, int width,
     Workflow::Frame     *frame = cw->m_computedBuffers.last();
     {
         QWriteLocker    lock( cw->m_effectsLock );
-        EffectsEngine::applyFilters( cw->m_filters, frame, cw->m_renderedFrame,
+        quint32     *newFrame = EffectsEngine::applyFilters( cw->m_filters, frame, cw->m_renderedFrame,
                                      cw->m_renderedFrame * 1000.0 / cw->clip()->getMedia()->fps() );
+        if ( newFrame != NULL )
+            frame->setBuffer( newFrame );
     }
     {
         QMutexLocker    lock( cw->m_renderedFrameMutex );



More information about the Vlmc-devel mailing list