[vlmc-devel] commit: VideoClipWorkflow: Adding Effects handling. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Wed Jul 28 00:22:07 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Tue Jul 27 00:02:20 2010 +0200| [3e71a81594ac8603e8f53a013c8414178a96f90c] | committer: Hugo Beauzée-Luyssen 

VideoClipWorkflow: Adding Effects handling.

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

 src/EffectsEngine/EffectsEngine.cpp |   10 ++++----
 src/EffectsEngine/EffectsEngine.h   |    2 +-
 src/Renderer/WorkflowRenderer.cpp   |    2 +-
 src/Workflow/ClipWorkflow.h         |    2 +-
 src/Workflow/VideoClipWorkflow.cpp  |   40 ++++++++++++++++++++++++++++++++++-
 src/Workflow/VideoClipWorkflow.h    |    7 ++++++
 6 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/src/EffectsEngine/EffectsEngine.cpp b/src/EffectsEngine/EffectsEngine.cpp
index b3e26b6..c1bb955 100644
--- a/src/EffectsEngine/EffectsEngine.cpp
+++ b/src/EffectsEngine/EffectsEngine.cpp
@@ -86,7 +86,7 @@ EffectsEngine::browseDirectory( const QString &path )
 }
 
 void
-EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuffers *ret,
+EffectsEngine::applyEffects( const EffectList &effects, Workflow::Frame* frame,
                              qint64 currentFrame  )
 {
     if ( effects.size() == 0 )
@@ -96,7 +96,7 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
 
     quint8      *buff1 = NULL;
     quint8      *buff2 = NULL;
-    quint8      *input = ret->video->buffer();
+    quint8      *input = frame->buffer();
     bool        firstBuff = true;
 
     while ( it != ite )
@@ -110,7 +110,7 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
             else
                 buff = &buff2;
             if ( *buff == NULL )
-                *buff = new quint8[ret->video->size()];
+                *buff = new quint8[frame->size()];
             Effect  *effect = (*it)->effect;
             effect->process( 0.0, (quint32*)input, (quint32*)*buff );
             input = *buff;
@@ -124,12 +124,12 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
         if ( firstBuff == true )
         {
             delete[] buff1;
-            ret->video->setBuffer( buff2 );
+            frame->setBuffer( buff2 );
         }
         else
         {
             delete[] buff2;
-            ret->video->setBuffer( buff1 );
+            frame->setBuffer( buff1 );
         }
     }
 }
diff --git a/src/EffectsEngine/EffectsEngine.h b/src/EffectsEngine/EffectsEngine.h
index 3304715..17debc3 100644
--- a/src/EffectsEngine/EffectsEngine.h
+++ b/src/EffectsEngine/EffectsEngine.h
@@ -51,7 +51,7 @@ class   EffectsEngine : public QObject, public Singleton<EffectsEngine>
         void        browseDirectory( const QString& path );
 
         static void applyEffects( const EffectList& effects,
-                                  MainWorkflow::OutputBuffers* ret, qint64 currentFrame );
+                                  Workflow::Frame *frame, qint64 currentFrame );
     private:
         EffectsEngine();
         ~EffectsEngine();
diff --git a/src/Renderer/WorkflowRenderer.cpp b/src/Renderer/WorkflowRenderer.cpp
index f63a3d8..b533f5d 100644
--- a/src/Renderer/WorkflowRenderer.cpp
+++ b/src/Renderer/WorkflowRenderer.cpp
@@ -171,7 +171,7 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
     }
     {
         QReadLocker lock( m_effectsLock );
-        EffectsEngine::applyEffects( m_effects, ret, m_mainWorkflow->getCurrentFrame() );
+        EffectsEngine::applyEffects( m_effects, ret->video, m_mainWorkflow->getCurrentFrame() );
     }
     m_pts = *pts = ptsDiff + m_pts;
     *buffer = ret->video->buffer();
diff --git a/src/Workflow/ClipWorkflow.h b/src/Workflow/ClipWorkflow.h
index 5af377a..08d8a91 100644
--- a/src/Workflow/ClipWorkflow.h
+++ b/src/Workflow/ClipWorkflow.h
@@ -147,7 +147,7 @@ class   ClipWorkflow : public QObject
          *  \brief  Set the rendering position
          *  \param  time    The position in millisecond
          */
-        void                    setTime( qint64 time );
+        virtual void            setTime( qint64 time );
 
         /**
          *  This method must be used to change the state of the ClipWorkflow
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index fe130c1..833cce6 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -33,13 +33,18 @@
 VideoClipWorkflow::VideoClipWorkflow( ClipHelper *ch ) :
         ClipWorkflow( ch ),
         m_width( 0 ),
-        m_height( 0 )
+        m_height( 0 ),
+        m_renderedFrame( 0 )
 {
+    m_effectsLock = new QReadWriteLock();
+    m_renderedFrameMutex = new QMutex();
 }
 
 VideoClipWorkflow::~VideoClipWorkflow()
 {
     stop();
+    delete m_renderedFrameMutex;
+    delete m_effectsLock;
 }
 
 void
@@ -157,6 +162,14 @@ VideoClipWorkflow::unlock( VideoClipWorkflow *cw, void *buffer, int width,
 
     cw->computePtsDiff( pts );
     Workflow::Frame     *frame = cw->m_computedBuffers.last();
+    {
+        QWriteLocker    lock( cw->m_effectsLock );
+        EffectsEngine::applyEffects( cw->m_effects, frame, cw->m_renderedFrame );
+    }
+    {
+        QMutexLocker    lock( cw->m_renderedFrameMutex );
+        cw->m_renderedFrame++;
+    }
     frame->ptsDiff = cw->m_currentPts - cw->m_previousPts;
     cw->commonUnlock();
     cw->m_renderWaitCond->wakeAll();
@@ -192,6 +205,31 @@ VideoClipWorkflow::flushComputedBuffers()
         m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
 }
 
+bool
+VideoClipWorkflow::appendEffect( Effect *effect, qint64 start, qint64 end )
+{
+    if ( effect->type() != Effect::Filter )
+    {
+        qWarning() << "VideoClipWorkflow does not handle non filter effects.";
+        return false;
+    }
+    effect->setUsed( true );
+    effect->init( m_width, m_height );
+    QWriteLocker    lock( m_effectsLock );
+    m_effects.push_back( new EffectsEngine::EffectHelper( effect, start, end ) );
+    return true;
+}
+
+void
+VideoClipWorkflow::setTime( qint64 time )
+{
+    {
+        QMutexLocker    lock( m_renderedFrameMutex );
+        m_renderedFrame = time / 1000 * Clip::DefaultFPS;
+    }
+    ClipWorkflow::setTime( time );
+}
+
 VideoClipWorkflow::StackedBuffer::StackedBuffer( Workflow::Frame *frame,
                                                     VideoClipWorkflow *poolHandler,
                                                     bool mustBeReleased) :
diff --git a/src/Workflow/VideoClipWorkflow.h b/src/Workflow/VideoClipWorkflow.h
index 9e1b84d..09d9079 100644
--- a/src/Workflow/VideoClipWorkflow.h
+++ b/src/Workflow/VideoClipWorkflow.h
@@ -24,6 +24,7 @@
 #define VIDEOCLIPWORKFLOW_H
 
 #include "ClipWorkflow.h"
+#include "EffectsEngine.h"
 #include "StackedBuffer.hpp"
 #include "Pool.hpp"
 
@@ -51,6 +52,8 @@ class   VideoClipWorkflow : public ClipWorkflow
         void                    *getLockCallback() const;
         void                    *getUnlockCallback() const;
         virtual void            *getOutput( ClipWorkflow::GetMode mode );
+        virtual bool            appendEffect( Effect *effect, qint64 start = 0, qint64 end = -1 );
+        virtual void            setTime( qint64 time );
 
         static const quint32    nbBuffers = 3 * 30; //3 seconds with an average fps of 30
 
@@ -76,6 +79,10 @@ class   VideoClipWorkflow : public ClipWorkflow
                                         qint64 pts );
         quint32                     m_width;
         quint32                     m_height;
+        QReadWriteLock              *m_effectsLock;
+        QMutex                      *m_renderedFrameMutex;
+        qint64                      m_renderedFrame;
+        QList<EffectsEngine::EffectHelper*>     m_effects;
 };
 
 #endif // VIDEOCLIPWORKFLOW_H



More information about the Vlmc-devel mailing list