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 ...@@ -161,7 +161,7 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
//the theorical pts for one frame. //the theorical pts for one frame.
//this is a bit hackish though... (especially regarding the "no frame computed" detection) //this is a bit hackish though... (especially regarding the "no frame computed" detection)
ptsDiff = 1000000 / handler->fps; ptsDiff = 1000000 / handler->fps;
} }
m_pts = *pts = ptsDiff + m_pts; m_pts = *pts = ptsDiff + m_pts;
*buffer = m_renderVideoFrame; *buffer = m_renderVideoFrame;
*bufferSize = m_videoBuffSize; *bufferSize = m_videoBuffSize;
...@@ -185,6 +185,7 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize ...@@ -185,6 +185,7 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
renderAudioSample = NULL; renderAudioSample = NULL;
if ( renderAudioSample != NULL ) if ( renderAudioSample != NULL )
{ {
// qDebug() << "pts diff:" << renderAudioSample->ptsDiff;
nbSample = renderAudioSample->nbSample; nbSample = renderAudioSample->nbSample;
*buffer = renderAudioSample->buff; *buffer = renderAudioSample->buff;
*bufferSize = renderAudioSample->size; *bufferSize = renderAudioSample->size;
......
...@@ -36,6 +36,7 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) : ...@@ -36,6 +36,7 @@ AudioClipWorkflow::AudioClipWorkflow( Clip *clip ) :
as->debugId = i; as->debugId = i;
} }
debugType = 1; debugType = 1;
m_ptsOffset = 0;
} }
AudioClipWorkflow::~AudioClipWorkflow() AudioClipWorkflow::~AudioClipWorkflow()
...@@ -72,6 +73,16 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode ) ...@@ -72,6 +73,16 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
qCritical() << "A sound buffer should never be asked with 'Get' mode"; qCritical() << "A sound buffer should never be asked with 'Get' mode";
::StackedBuffer<AudioSample*> *buff = new StackedBuffer( ::StackedBuffer<AudioSample*> *buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true ); 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(); postGetOutput();
return buff; return buff;
} }
...@@ -88,6 +99,7 @@ AudioClipWorkflow::initVlcOutput() ...@@ -88,6 +99,7 @@ AudioClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=f32l" ); m_vlcMedia->addOption( ":sout-transcode-acodec=f32l" );
m_vlcMedia->addOption( ":sout-transcode-samplerate=48000" ); m_vlcMedia->addOption( ":sout-transcode-samplerate=48000" );
m_vlcMedia->addOption( ":sout-transcode-channels=2" ); m_vlcMedia->addOption( ":sout-transcode-channels=2" );
m_vlcMedia->addOption( ":no-sout-transcode-hurry-up" );
if ( m_fullSpeedRender == false ) if ( m_fullSpeedRender == false )
m_vlcMedia->addOption( ":sout-smem-time-sync" ); m_vlcMedia->addOption( ":sout-smem-time-sync" );
else else
...@@ -138,19 +150,51 @@ AudioClipWorkflow::unlock( AudioClipWorkflow *cw, quint8 *pcm_buffer, ...@@ -138,19 +150,51 @@ AudioClipWorkflow::unlock( AudioClipWorkflow *cw, quint8 *pcm_buffer,
Q_UNUSED( bits_per_sample ); Q_UNUSED( bits_per_sample );
Q_UNUSED( size ); Q_UNUSED( size );
cw->computePtsDiff( pts ); pts -= cw->m_ptsOffset;
AudioSample* as = cw->m_computedBuffers.last(); AudioSample* as = cw->m_computedBuffers.last();
if ( as->buff != NULL ) if ( as->buff != NULL )
{ {
as->nbSample = nb_samples; as->nbSample = nb_samples;
as->nbChannels = channels; 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->commonUnlock();
cw->m_renderLock->unlock(); cw->m_renderLock->unlock();
cw->m_computedBuffersMutex->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 quint32
AudioClipWorkflow::getNbComputedBuffers() const AudioClipWorkflow::getNbComputedBuffers() const
{ {
......
...@@ -40,6 +40,7 @@ class AudioClipWorkflow : public ClipWorkflow ...@@ -40,6 +40,7 @@ class AudioClipWorkflow : public ClipWorkflow
quint32 nbSample; quint32 nbSample;
quint32 nbChannels; quint32 nbChannels;
qint64 ptsDiff; qint64 ptsDiff;
qint64 pts;
quint32 debugId; quint32 debugId;
}; };
class StackedBuffer : public ::StackedBuffer<AudioSample*> class StackedBuffer : public ::StackedBuffer<AudioSample*>
...@@ -54,23 +55,20 @@ class AudioClipWorkflow : public ClipWorkflow ...@@ -54,23 +55,20 @@ class AudioClipWorkflow : public ClipWorkflow
AudioClipWorkflow( Clip* clip ); AudioClipWorkflow( Clip* clip );
~AudioClipWorkflow(); ~AudioClipWorkflow();
void *getLockCallback() const; void *getLockCallback() const;
void *getUnlockCallback() const; void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode ); virtual void *getOutput( ClipWorkflow::GetMode mode );
protected: protected:
virtual quint32 getNbComputedBuffers() const; virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const; virtual quint32 getMaxComputedBuffers() const;
void flushComputedBuffers(); void flushComputedBuffers();
private: private:
void releaseBuffer( AudioSample* sample ); void releaseBuffer( AudioSample *sample );
private:
QQueue<AudioSample*> m_computedBuffers;
QQueue<AudioSample*> m_availableBuffers;
void initVlcOutput(); void initVlcOutput();
AudioSample* createBuffer( size_t size ); AudioSample* createBuffer( size_t size );
void insertPastBlock( AudioSample* as );
static void lock( AudioClipWorkflow* clipWorkflow, static void lock( AudioClipWorkflow* clipWorkflow,
quint8** pcm_buffer , quint32 size ); quint8** pcm_buffer , quint32 size );
static void unlock( AudioClipWorkflow* clipWorkflow, static void unlock( AudioClipWorkflow* clipWorkflow,
...@@ -79,6 +77,11 @@ class AudioClipWorkflow : public ClipWorkflow ...@@ -79,6 +77,11 @@ class AudioClipWorkflow : public ClipWorkflow
quint32 bits_per_sample, quint32 bits_per_sample,
quint32 size, qint64 pts ); quint32 size, qint64 pts );
private:
QQueue<AudioSample*> m_computedBuffers;
QQueue<AudioSample*> m_availableBuffers;
qint64 m_ptsOffset;
static const quint32 nbBuffers = 256; static const quint32 nbBuffers = 256;
}; };
......
...@@ -226,6 +226,11 @@ void ClipWorkflow::commonUnlock() ...@@ -226,6 +226,11 @@ void ClipWorkflow::commonUnlock()
void ClipWorkflow::computePtsDiff( qint64 pts ) 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 ) if ( m_previousPts == -1 )
m_previousPts = pts; m_previousPts = pts;
if ( m_currentPts == -1 ) if ( m_currentPts == -1 )
...@@ -242,10 +247,6 @@ void ClipWorkflow::computePtsDiff( qint64 pts ) ...@@ -242,10 +247,6 @@ void ClipWorkflow::computePtsDiff( qint64 pts )
// { // {
// qDebug() << "in computePtsDiff, After >> : pts:" << pts << "previousPts:" << m_previousPts // qDebug() << "in computePtsDiff, After >> : pts:" << pts << "previousPts:" << m_previousPts
// << "currentPts:" << m_currentPts; // << "currentPts:" << m_currentPts;
// }
// if ( debugType == 1 && pts < m_previousPts )
// {
// qCritical() << "New PTS is lower than previous PTS !<<<<<<<<<<<<<<<<<<<<<<<<<<";
// } // }
m_currentPts = qMax( pts, m_previousPts ); 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