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

Changing audio buffers pre-allocation method.

Adding audio options, changed debug.
parent ae68e097
......@@ -30,7 +30,7 @@ Instance::Instance()
{
char const *argv[] =
{
// "-vvvvv",
"-vvvvv",
"--no-skip-frames",
// "--intf", "dummy",
"--text-renderer", "dummy",
......
......@@ -85,15 +85,15 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
switch ( event->type )
{
case libvlc_MediaPlayerPlaying:
// qDebug() << "Media player playing";
qDebug() << "Media player playing";
self->emit playing();
break;
case libvlc_MediaPlayerPaused:
// qDebug() << "Media player paused";
qDebug() << "Media player paused";
self->emit paused();
break;
case libvlc_MediaPlayerStopped:
// qDebug() << "Media player stopped";
qDebug() << "Media player stopped";
self->emit stopped();
break;
case libvlc_MediaPlayerEndReached:
......
......@@ -93,7 +93,7 @@ void MetaDataWorker::computeAudioMetaData()
m_media->getVLCMedia()->addOption( ":sout-transcode-acodec=s16l" );
m_media->getVLCMedia()->addOption( ":no-sout-smem-time-sync" );
m_media->getVLCMedia()->addOption( ":no-sout-keep" );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ), Qt::QueuedConnection );
// connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ), Qt::QueuedConnection );
}
void MetaDataWorker::getMetaData()
......
......@@ -27,6 +27,13 @@
AudioClipWorkflow::AudioClipWorkflow( Clip* clip ) :
ClipWorkflow( clip )
{
for ( unsigned int i = 0; i < AudioClipWorkflow::nbBuffers; ++i )
{
AudioSample* as = new AudioSample;
as->buff = NULL;
m_availableBuffers.push_back( as );
}
debugType = 1;
}
AudioClipWorkflow::~AudioClipWorkflow()
......@@ -53,7 +60,7 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
QMutexLocker lock2( m_computedBuffersMutex );
preGetOutput();
// qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
return NULL;
if ( mode == ClipWorkflow::Get )
......@@ -66,6 +73,7 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void AudioClipWorkflow::initVlcOutput()
{
m_vlcMedia->addOption( ":no-sout-video" );
m_vlcMedia->addOption( ":no-video" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
m_vlcMedia->setAudioDataCtx( this );
m_vlcMedia->setAudioLockCallback( reinterpret_cast<void*>( getLockCallback() ) );
......@@ -86,20 +94,12 @@ AudioClipWorkflow::AudioSample* AudioClipWorkflow::createBuffer( size_t size
void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer , unsigned int size )
{
cw->m_renderLock->lock();
cw->m_computedBuffersMutex->lock();
QMutexLocker lock( cw->m_availableBuffersMutex );
cw->m_computedBuffersMutex->lock();
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 = cw->createBuffer( size );
as->debugId = i;
cw->m_availableBuffers.push_back( as );
}
}
// qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
AudioSample* as = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
{
......@@ -107,8 +107,15 @@ void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer
as = cw->createBuffer( size );
}
else
{
as = cw->m_availableBuffers.dequeue();
cw->m_computedBuffers.push_back( as );
if ( as->buff == NULL )
{
as->buff = new uchar[size];
as->size = size;
}
}
cw->m_computedBuffers.enqueue( as );
*pcm_buffer = as->buff;
}
......
......@@ -64,7 +64,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 = 1024;
static const uint32_t nbBuffers = 256;
friend class StackedBuffer<AudioSample*, AudioClipWorkflow>;
};
......
......@@ -198,10 +198,10 @@ void ClipWorkflow::preGetOutput()
if ( getComputedBuffers() == 0 )
{
// qWarning() << "Waiting for buffer to be fed";
qWarning() << "Waiting for buffer to be fed";
m_renderLock->unlock();
m_computedBuffersMutex->unlock();
// qDebug() << "Unlocked render lock, entering cond wait";
qDebug() << "Unlocked render lock, entering cond wait";
m_feedingCondWait->waitLocked();
m_computedBuffersMutex->lock();
m_renderLock->lock();
......@@ -216,9 +216,9 @@ void ClipWorkflow::postGetOutput()
QWriteLocker lock( m_stateLock );
if ( m_state == ClipWorkflow::Paused )
{
// qWarning() << "Unpausing media player";
qWarning() << "Unpausing media player. type:" << debugType;
m_state = ClipWorkflow::UnpauseRequired;
//This will act like an "unpause";
// This will act like an "unpause";
m_mediaPlayer->pause();
}
// else
......@@ -232,17 +232,15 @@ void ClipWorkflow::commonUnlock()
//no one is available : we would spawn a new buffer, thus modifying the number of available buffers
if ( getComputedBuffers() == getMaxComputedBuffers() )
{
// qWarning() << "Pausing media player";
qWarning() << "Pausing clip workflow. Type:" << debugType;
setState( ClipWorkflow::PauseRequired );
// qDebug() << "State has been set...calling pause method.";
m_mediaPlayer->pause();
// qDebug() << "Pause method has been called";
}
if ( getComputedBuffers() == 1 )
{
// qDebug() << "Waking feeding cont wait... acquiring lock";
qDebug() << "Waking feeding cont wait... acquiring lock. Type:" << debugType;
QMutexLocker lock( m_feedingCondWait->getMutex() );
// qDebug() << "feeding cont wait mutex acquired";
qDebug() << "feeding cont wait mutex acquired. Type:" << debugType;
m_feedingCondWait->wake();
}
checkStateChange();
......@@ -266,7 +264,7 @@ void ClipWorkflow::computePtsDiff( qint64 pts )
void ClipWorkflow::mediaPlayerPaused()
{
// qWarning() << "\n\n\n\nMedia player paused, waiting for buffers to be consumed\n\n\n\n";
qWarning() << "\n\n\n\nMedia player paused, waiting for buffers to be consumed.Type:" << debugType << "\n\n\n\n";
setState( ClipWorkflow::Paused );
m_beginPausePts = mdate();
// qDebug() << "got pause pts:" << m_beginPausePts;
......@@ -274,7 +272,7 @@ void ClipWorkflow::mediaPlayerPaused()
void ClipWorkflow::mediaPlayerUnpaused()
{
// qWarning() << "Media player unpaused. Go back to rendering";
qWarning() << "Media player unpaused. Go back to rendering. Type:" << debugType;
setState( ClipWorkflow::Rendering );
m_pauseDuration = mdate() - m_beginPausePts;
}
......@@ -203,6 +203,7 @@ class ClipWorkflow : public QObject
QMutex* m_availableBuffersMutex;
qint64 m_beginPausePts;
qint64 m_pauseDuration;
int debugType;
protected:
......
......@@ -34,6 +34,7 @@ VideoClipWorkflow::VideoClipWorkflow( Clip* clip ) : ClipWorkflow( clip )
* MainWorkflow::getInstance()->getHeight()
* Pixel::NbComposantes ) );
}
debugType = 2;
}
VideoClipWorkflow::~VideoClipWorkflow()
......
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