[vlmc-devel] commit: AudioClipWorkflow: Reorder blocks in case VLC misorder them ( Hugo Beauzee-Luyssen )
git at videolan.org
git at videolan.org
Sat Mar 13 16:41:49 CET 2010
vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Sat Mar 13 16:22:09 2010 +0100| [a20a5f3f9ceaadf40c1fe76bcc4c2a8992c53280] | committer: Hugo Beauzee-Luyssen
AudioClipWorkflow: Reorder blocks in case VLC misorder them
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=a20a5f3f9ceaadf40c1fe76bcc4c2a8992c53280
---
src/Renderer/WorkflowRenderer.cpp | 3 +-
src/Workflow/AudioClipWorkflow.cpp | 48 ++++++++++++++++++++++++++++++++++-
src/Workflow/AudioClipWorkflow.h | 25 ++++++++++--------
src/Workflow/ClipWorkflow.cpp | 9 +++---
4 files changed, 67 insertions(+), 18 deletions(-)
diff --git a/src/Renderer/WorkflowRenderer.cpp b/src/Renderer/WorkflowRenderer.cpp
index 2c07f61..ba33aa4 100644
--- a/src/Renderer/WorkflowRenderer.cpp
+++ b/src/Renderer/WorkflowRenderer.cpp
@@ -161,7 +161,7 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
//the theorical pts for one frame.
//this is a bit hackish though... (especially regarding the "no frame computed" detection)
ptsDiff = 1000000 / handler->fps;
- }
+ }
m_pts = *pts = ptsDiff + m_pts;
*buffer = m_renderVideoFrame;
*bufferSize = m_videoBuffSize;
@@ -185,6 +185,7 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
renderAudioSample = NULL;
if ( renderAudioSample != NULL )
{
+// qDebug() << "pts diff:" << renderAudioSample->ptsDiff;
nbSample = renderAudioSample->nbSample;
*buffer = renderAudioSample->buff;
*bufferSize = renderAudioSample->size;
diff --git a/src/Workflow/AudioClipWorkflow.cpp b/src/Workflow/AudioClipWorkflow.cpp
index 14516ee..e9240c9 100644
--- a/src/Workflow/AudioClipWorkflow.cpp
+++ b/src/Workflow/AudioClipWorkflow.cpp
@@ -36,6 +36,7 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
as->debugId = i;
}
debugType = 1;
+ m_ptsOffset = 0;
}
AudioClipWorkflow::~AudioClipWorkflow()
@@ -72,6 +73,16 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
::StackedBuffer<AudioSample*> *buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true );
+ if ( m_previousPts == -1 )
+ {
+ buff->get()->ptsDiff = 0;
+ m_previousPts = buff->get()->pts;
+ }
+ else
+ {
+ buff->get()->ptsDiff = buff->get()->pts - m_previousPts;
+ m_previousPts = buff->get()->pts;
+ }
postGetOutput();
return buff;
}
@@ -88,6 +99,7 @@ AudioClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=f32l" );
m_vlcMedia->addOption( ":sout-transcode-samplerate=48000" );
m_vlcMedia->addOption( ":sout-transcode-channels=2" );
+ m_vlcMedia->addOption( ":no-sout-transcode-hurry-up" );
if ( m_fullSpeedRender == false )
m_vlcMedia->addOption( ":sout-smem-time-sync" );
else
@@ -138,19 +150,51 @@ AudioClipWorkflow::unlock( AudioClipWorkflow *cw, quint8 *pcm_buffer,
Q_UNUSED( bits_per_sample );
Q_UNUSED( size );
- cw->computePtsDiff( pts );
+ pts -= cw->m_ptsOffset;
AudioSample* as = cw->m_computedBuffers.last();
if ( as->buff != NULL )
{
as->nbSample = nb_samples;
as->nbChannels = channels;
- as->ptsDiff = cw->m_currentPts - cw->m_previousPts;
+ as->ptsDiff = 0;
+ as->pts = pts;
+ if ( cw->m_pauseDuration != -1 )
+ {
+ cw->m_ptsOffset += cw->m_pauseDuration;
+ cw->m_pauseDuration = -1;
+ }
+ if ( cw->m_currentPts > pts )
+ {
+ cw->m_computedBuffers.removeLast();
+ cw->insertPastBlock( as );
+ }
+ else
+ cw->m_currentPts = pts;
}
cw->commonUnlock();
cw->m_renderLock->unlock();
cw->m_computedBuffersMutex->unlock();
}
+void
+AudioClipWorkflow::insertPastBlock( AudioSample *as )
+{
+ QQueue<AudioSample*>::iterator it = m_computedBuffers.begin();
+ QQueue<AudioSample*>::iterator end = m_computedBuffers.end();
+
+ while ( it != end )
+ {
+ if ( (*it)->pts > as->pts )
+ {
+ m_computedBuffers.insert( it, as );
+ return ;
+ }
+ ++it;
+ }
+ //Fail safe: reinsert the block at the end.
+ m_computedBuffers.push_back( as );
+}
+
quint32
AudioClipWorkflow::getNbComputedBuffers() const
{
diff --git a/src/Workflow/AudioClipWorkflow.h b/src/Workflow/AudioClipWorkflow.h
index 7c62f92..eb0c318 100644
--- a/src/Workflow/AudioClipWorkflow.h
+++ b/src/Workflow/AudioClipWorkflow.h
@@ -40,6 +40,7 @@ class AudioClipWorkflow : public ClipWorkflow
quint32 nbSample;
quint32 nbChannels;
qint64 ptsDiff;
+ qint64 pts;
quint32 debugId;
};
class StackedBuffer : public ::StackedBuffer<AudioSample*>
@@ -54,23 +55,20 @@ class AudioClipWorkflow : public ClipWorkflow
AudioClipWorkflow( Clip* clip );
~AudioClipWorkflow();
- void *getLockCallback() const;
- void *getUnlockCallback() const;
- virtual void *getOutput( ClipWorkflow::GetMode mode );
+ void *getLockCallback() const;
+ void *getUnlockCallback() const;
+ virtual void *getOutput( ClipWorkflow::GetMode mode );
protected:
- virtual quint32 getNbComputedBuffers() const;
- virtual quint32 getMaxComputedBuffers() const;
- void flushComputedBuffers();
+ virtual quint32 getNbComputedBuffers() const;
+ virtual quint32 getMaxComputedBuffers() const;
+ void flushComputedBuffers();
private:
- void releaseBuffer( AudioSample* sample );
-
- private:
- QQueue<AudioSample*> m_computedBuffers;
- QQueue<AudioSample*> m_availableBuffers;
+ void releaseBuffer( AudioSample *sample );
void initVlcOutput();
AudioSample* createBuffer( size_t size );
+ void insertPastBlock( AudioSample* as );
static void lock( AudioClipWorkflow* clipWorkflow,
quint8** pcm_buffer , quint32 size );
static void unlock( AudioClipWorkflow* clipWorkflow,
@@ -79,6 +77,11 @@ class AudioClipWorkflow : public ClipWorkflow
quint32 bits_per_sample,
quint32 size, qint64 pts );
+ private:
+ QQueue<AudioSample*> m_computedBuffers;
+ QQueue<AudioSample*> m_availableBuffers;
+ qint64 m_ptsOffset;
+
static const quint32 nbBuffers = 256;
};
diff --git a/src/Workflow/ClipWorkflow.cpp b/src/Workflow/ClipWorkflow.cpp
index 71a3c76..0a80e01 100644
--- a/src/Workflow/ClipWorkflow.cpp
+++ b/src/Workflow/ClipWorkflow.cpp
@@ -226,6 +226,11 @@ void ClipWorkflow::commonUnlock()
void ClipWorkflow::computePtsDiff( qint64 pts )
{
+ if ( debugType == 1 && pts < m_previousPts )
+ {
+ qCritical() << "New PTS is lower than previous PTS !<<<<<<<<<<<<<<<<<<<<<<<<<<" << m_previousPts << pts;
+ }
+
if ( m_previousPts == -1 )
m_previousPts = pts;
if ( m_currentPts == -1 )
@@ -243,10 +248,6 @@ void ClipWorkflow::computePtsDiff( qint64 pts )
// qDebug() << "in computePtsDiff, After >> : pts:" << pts << "previousPts:" << m_previousPts
// << "currentPts:" << m_currentPts;
// }
-// if ( debugType == 1 && pts < m_previousPts )
-// {
-// qCritical() << "New PTS is lower than previous PTS !<<<<<<<<<<<<<<<<<<<<<<<<<<";
-// }
m_currentPts = qMax( pts, m_previousPts );
}
More information about the Vlmc-devel
mailing list