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

It works a bit better for the audio.

parent 06f52598
......@@ -83,21 +83,35 @@ void AudioClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
AudioClipWorkflow::AudioSample* AudioClipWorkflow::createBuffer( size_t size )
{
AudioSample* as = new AudioSample;
as->buff = new uchar[size];
as->size = size;
return as;
}
void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer , unsigned int size )
{
cw->m_renderLock->lock();
//If there's no buffer at all, it must be the first render
if ( cw->m_availableBuffers.count() == 0 && cw->m_computedBuffers.count() == 0 )
{
for ( unsigned int i = 0; i < AudioClipWorkflow::nbBuffers; ++i )
{
AudioSample* as = new AudioSample;
as->buff = new uchar[size];
as->size = size;
AudioSample* as = cw->createBuffer( size );
cw->m_availableBuffers.push_back( as );
}
}
cw->m_renderLock->lock();
AudioSample* as = cw->m_availableBuffers.pop();
qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
AudioSample* as = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
{
qCritical() << cw << "Late buffer generation ! Spawning new buffer.";
as = cw->createBuffer( size );
}
else
as = cw->m_availableBuffers.pop();
cw->m_computedBuffers.push_back( as );
*pcm_buffer = as->buff;
}
......@@ -122,9 +136,8 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
as->nbChannels = channels;
as->ptsDiff = cw->m_currentPts - cw->m_previousPts;
}
cw->m_renderLock->unlock();
cw->commonUnlock();
cw->m_renderLock->unlock();
}
uint32_t AudioClipWorkflow::getAvailableBuffers() const
......
......@@ -54,6 +54,7 @@ class AudioClipWorkflow : public ClipWorkflow
QReadWriteLock* m_availableBuffersLock;
Pool<AudioSample*> m_availableBuffers;
void initVlcOutput();
AudioSample* createBuffer( size_t size );
static void lock( AudioClipWorkflow* clipWorkflow, uint8_t** pcm_buffer , unsigned int size );
static void unlock( AudioClipWorkflow* clipWorkflow, uint8_t* pcm_buffer,
unsigned int channels, unsigned int rate,
......@@ -61,7 +62,7 @@ class AudioClipWorkflow : public ClipWorkflow
unsigned int size, qint64 pts );
//FIXME: this is totally random powered ! Please adjust with a value that does make sense...
static const uint32_t nbBuffers = 128;
static const uint32_t nbBuffers = 1024;
};
#endif // AUDIOCLIPWORKFLOW_H
......@@ -227,13 +227,11 @@ void ClipWorkflow::commonUnlock()
}
if ( getComputedBuffers() == 1 )
{
qDebug() << "trying to inform of first buffer";
QMutexLocker lock( m_feedingCondWait->getMutex() );
qWarning() << "Just rendered the first buffer.";
m_feedingCondWait->wake();
}
checkStateChange();
qDebug() << "exited from common unlock";
}
void ClipWorkflow::computePtsDiff( qint64 pts )
......
......@@ -89,7 +89,7 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
QMutexLocker lock( m_renderLock );
preGetOutput();
qWarning() << "Video. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
// qWarning() << "Video. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
return NULL;
StackedBuffer<LightVideoFrame*>* buff;
......@@ -97,19 +97,17 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.pop(), &m_availableBuffers, true );
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.head(), NULL, false );
ClipWorkflow::postGetOutput();
postGetOutput();
return buff;
}
void VideoClipWorkflow::lock( VideoClipWorkflow* cw, void** pp_ret, int size )
{
Q_UNUSED( size );
qDebug() << "trying to lock renderlock";
cw->m_renderLock->lock();
qDebug() << "trying to pop available buffer";
LightVideoFrame* lvf = cw->m_availableBuffers.pop();
cw->m_computedBuffers.push_back( lvf );
qWarning() << ">>>VideoGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
// qWarning() << ">>>VideoGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
// qWarning() << "feeding video buffer";
*pp_ret = (*(lvf))->frame.octets;
}
......@@ -123,13 +121,10 @@ void VideoClipWorkflow::unlock( VideoClipWorkflow* cw, void* buffer, int widt
Q_UNUSED( size );
cw->computePtsDiff( pts );
qDebug() << "getting computed buffers head";
LightVideoFrame* lvf = cw->m_computedBuffers.head();
(*(lvf))->ptsDiff = cw->m_currentPts - cw->m_previousPts;
//If this is the first buffer that has been rendered, there may be a waiting TrackWorkflow.
qDebug() << "calling commonUnlock";
cw->commonUnlock();
qDebug() << "unlocking render lock";
cw->m_renderLock->unlock();
}
......
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