Commit a20a5f3f authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

AudioClipWorkflow: Reorder blocks in case VLC misorder them

parent 6095df5a
......@@ -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;
......
......@@ -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
{
......
......@@ -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;
};
......
......@@ -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 )
......@@ -242,10 +247,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 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment