Commit 25734f97 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Adding failsafe for empty video buffer pool.

parent cec85438
......@@ -103,16 +103,17 @@ int WorkflowRenderer::lock( void *datas, int64_t *dts, int64_t *pts, unsigne
if ( handler->type == Video )
{
ret = lockVideo( handler->self, pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::VideoTrack );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::VideoTrack );
}
else if ( handler->type == Audio )
{
qWarning() << "got audio type <<<<<<<<<<<<<<<<<<<<<<<<<<<<";
ret = lockAudio( handler->self, pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::AudioTrack );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::AudioTrack );
}
else
qWarning() << "Invalid ES type";
// qDebug() << "ES Type:" << handler->type << "pts:" << *pts;
qDebug() << "ES Type:" << handler->type << "pts:" << *pts;
return ret;
}
......@@ -139,8 +140,7 @@ int WorkflowRenderer::lockVideo( WorkflowRenderer* self, int64_t *pts, size_
int WorkflowRenderer::lockAudio( WorkflowRenderer* self, int64_t *pts, size_t *bufferSize, void **buffer )
{
qint64 ptsDiff;
if ( self->m_paused == true )
return 1;
if ( self->m_stopping == false )
{
MainWorkflow::OutputBuffers* ret = self->m_mainWorkflow->getOutput( MainWorkflow::AudioTrack );
......@@ -153,6 +153,7 @@ int WorkflowRenderer::lockAudio( WorkflowRenderer* self, int64_t *pts, size
*buffer = self->m_renderAudioSample->buff;
*bufferSize = self->m_renderAudioSample->size;
ptsDiff = self->m_renderAudioSample->ptsDiff;
qWarning() << "injecting audio sample";
}
else
{
......@@ -166,6 +167,7 @@ int WorkflowRenderer::lockAudio( WorkflowRenderer* self, int64_t *pts, size
*buffer = WorkflowRenderer::silencedAudioBuffer;
*bufferSize = buffSize;
ptsDiff = self->m_pts - self->m_audioPts;
qWarning() << "injecting silence buffer";
}
self->m_audioPts = *pts = self->m_audioPts + ptsDiff;
//qDebug() << "Audio pts" << self->m_audioPts << "diff" << ptsDiff;
......
......@@ -103,11 +103,11 @@ void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer
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 )
{
qCritical() << cw << "Late buffer generation ! Spawning new buffer.";
qCritical() << cw << "Late buffer generation. Spawning new audio buffer.";
as = cw->createBuffer( size );
}
else
......
......@@ -220,15 +220,16 @@ void ClipWorkflow::preGetOutput()
void ClipWorkflow::commonUnlock()
{
if ( getAvailableBuffers() == 0 )
//Don't test using availableBuffer, as it may evolve if a buffer is required while
//no one is available : we would spawn a new buffer, thus modifying the number of available buffers
if ( getComputedBuffers() == getMaxComputedBuffers() )
{
qDebug() << "No more available buffers : pausing";
qWarning() << "Pausing media player";
m_mediaPlayer->pause();
}
if ( getComputedBuffers() == 1 )
{
QMutexLocker lock( m_feedingCondWait->getMutex() );
qWarning() << "Just rendered the first buffer.";
m_feedingCondWait->wake();
}
checkStateChange();
......
......@@ -103,9 +103,19 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void VideoClipWorkflow::lock( VideoClipWorkflow* cw, void** pp_ret, int size )
{
qDebug() << "video lock";
Q_UNUSED( size );
cw->m_renderLock->lock();
LightVideoFrame* lvf = cw->m_availableBuffers.pop();
LightVideoFrame* lvf = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
{
qCritical() << "Late buffer generation. Spawning new video buffer";
lvf = new LightVideoFrame( MainWorkflow::getInstance()->getWidth()
* MainWorkflow::getInstance()->getHeight()
* Pixel::NbComposantes );
}
else
lvf = cw->m_availableBuffers.pop();
cw->m_computedBuffers.push_back( lvf );
// qWarning() << ">>>VideoGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
// qWarning() << "feeding video buffer";
......@@ -114,6 +124,7 @@ void VideoClipWorkflow::lock( VideoClipWorkflow* cw, void** pp_ret, int size
void VideoClipWorkflow::unlock( VideoClipWorkflow* cw, void* buffer, int width, int height, int bpp, int size, qint64 pts )
{
qDebug() << "video unlock";
Q_UNUSED( buffer );
Q_UNUSED( width );
Q_UNUSED( height );
......
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