[vlmc-devel] Ensure Max Buffer Size after the unlock function in ClipWorkflow

Yikai Lu git at videolan.org
Mon Apr 4 11:09:25 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Apr  4 17:54:34 2016 +0900| [4c29446729214e630936f7c00caaddb1ceb784ed] | committer: Hugo Beauzée-Luyssen

Ensure Max Buffer Size after the unlock function in ClipWorkflow

Currently, we only check the buffer size in "getOutput" function; however, it is called by the source renderer in the WorkflowRenderer. So if the source renderer hangs for some reason, it's highly likely that m_computedBuffers will overflow.

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> https://code.videolan.org/videolan/vlmc/commit/4c29446729214e630936f7c00caaddb1ceb784ed
---

 src/Workflow/AudioClipWorkflow.cpp |  2 ++
 src/Workflow/ClipWorkflow.cpp      | 10 ++++++++++
 src/Workflow/ClipWorkflow.h        |  7 +++++++
 src/Workflow/VideoClipWorkflow.cpp |  2 ++
 4 files changed, 21 insertions(+)

diff --git a/src/Workflow/AudioClipWorkflow.cpp b/src/Workflow/AudioClipWorkflow.cpp
index a9c1632..5130bff 100644
--- a/src/Workflow/AudioClipWorkflow.cpp
+++ b/src/Workflow/AudioClipWorkflow.cpp
@@ -172,6 +172,8 @@ AudioClipWorkflow::unlock( void* data, uint8_t *pcm_buffer, unsigned int channel
         else
             cw->m_currentPts = pts;
     }
+    if ( cw->getMaxComputedBuffers() <= cw->getNbComputedBuffers() )
+        emit cw->bufferReachedMax();
     cw->m_renderLock->unlock();
 }
 
diff --git a/src/Workflow/ClipWorkflow.cpp b/src/Workflow/ClipWorkflow.cpp
index d5e5432..305069b 100644
--- a/src/Workflow/ClipWorkflow.cpp
+++ b/src/Workflow/ClipWorkflow.cpp
@@ -84,6 +84,7 @@ ClipWorkflow::initialize()
     connect( m_eventWatcher, SIGNAL( endReached() ), this, SLOT( clipEndReached() ), Qt::DirectConnection );
     connect( m_eventWatcher, SIGNAL( errorEncountered() ), this, SLOT( errorEncountered() ) );
     connect( m_eventWatcher, &RendererEventWatcher::stopped, this, &ClipWorkflow::mediaPlayerStopped );
+    connect( this, &ClipWorkflow::bufferReachedMax, this, &ClipWorkflow::pause, Qt::QueuedConnection );
     m_renderer->start();
 }
 
@@ -131,6 +132,15 @@ ClipWorkflow::stop()
 }
 
 void
+ClipWorkflow::pause()
+{
+    if ( m_renderer != nullptr ) {
+        m_renderer->setPause( true );
+        vlmcWarning() << "ClipWorkflow:" << m_clipHelper->uuid() << " was paused unexpectedly";
+    }
+}
+
+void
 ClipWorkflow::setTime( qint64 time )
 {
     vlmcDebug() << "Setting ClipWorkflow" << m_clipHelper->uuid() << "time:" << time;
diff --git a/src/Workflow/ClipWorkflow.h b/src/Workflow/ClipWorkflow.h
index cdac341..98658be 100644
--- a/src/Workflow/ClipWorkflow.h
+++ b/src/Workflow/ClipWorkflow.h
@@ -140,6 +140,12 @@ class   ClipWorkflow : public EffectUser
          *  \brief  Stop this workflow.
          */
         void                    stop();
+
+        /**
+         *  \brief  Pause this workflow.
+         */
+        void                    pause();
+
         /**
          *  \brief  Set the rendering position
          *  \param  time    The position in millisecond
@@ -243,6 +249,7 @@ class   ClipWorkflow : public EffectUser
 
     signals:
         void                    error( ClipWorkflow* );
+        void                    bufferReachedMax();
 };
 
 #endif // CLIPWORKFLOW_H
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index 1a443c5..b90f241 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -163,6 +163,8 @@ VideoClipWorkflow::unlock( void *data, uint8_t *buffer, int width,
     Workflow::Frame     *frame = cw->m_computedBuffers.last();
     frame->ptsDiff = cw->m_currentPts - cw->m_previousPts;
     cw->m_renderWaitCond->wakeAll();
+    if ( cw->getMaxComputedBuffers() <= cw->getNbComputedBuffers() )
+        emit cw->bufferReachedMax();
     cw->m_renderLock->unlock();
 }
 



More information about the Vlmc-devel mailing list