Commit 79d541b3 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Fixed bug when having a track that isn't starting at 0

parent db0683a3
......@@ -109,13 +109,17 @@ int WorkflowRenderer::lock( void *datas, int64_t *dts, int64_t *pts, unsigne
*flags = 0;
if ( handler->type == Video )
{
qDebug() << "entering lock video";
ret = handler->self->lockVideo( pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::VideoTrack );
qDebug() << "leaved lock video";
}
else if ( handler->type == Audio )
{
qDebug() << "entering lock audio";
ret = handler->self->lockAudio( pts, bufferSize, buffer );
handler->self->m_mainWorkflow->goToNextFrame( MainWorkflow::AudioTrack );
qDebug() << "leaved lock audio";
}
else
qCritical() << "Invalid ES type";
......@@ -134,8 +138,15 @@ int WorkflowRenderer::lockVideo( int64_t *pts, size_t *bufferSize, void **bu
m_videoBuffSize = (*(ret->video))->nboctets;
ptsDiff = (*(ret->video))->ptsDiff;
}
if ( ptsDiff == 0 )
{
//If no ptsDiff has been computed, we have to fake it, so we compute
//the theorical pts for one frame.
//this is a bit hackish though... (especially regarding the "no frame computed" detection)
ptsDiff = 1000000 / m_outputFps;
}
m_pts = *pts = ptsDiff + m_pts;
// qDebug() << "Video pts" << m_pts << "diff" << ptsDiff;
qDebug() << "Video pts" << m_pts << "diff" << ptsDiff;
//*pts = qRound64( (float)( m_pts * 1000000.0f ) / m_outputFps );
//++m_pts;
*buffer = m_renderVideoFrame;
......
......@@ -57,23 +57,30 @@ void* AudioClipWorkflow::getUnlockCallback()
void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
// qDebug() << "entering audio get output";
QMutexLocker lock( m_renderLock );
// qDebug() << "got audio render lock";
QMutexLocker lock2( m_computedBuffersMutex );
if ( preGetOutput() == false )
{
// qDebug() << "audio preGetOutput() returned false";
return NULL;
}
// qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
{
// qDebug() << "End is reached";
// qDebug() << "audio end is reached";
return NULL;
}
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
::StackedBuffer<AudioSample*>* buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true );
// qDebug() << "calling audio postGetOutput();";
postGetOutput();
// qDebug() << "returning audio buffer";
return buff;
}
......@@ -148,7 +155,7 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
as->nbChannels = channels;
as->ptsDiff = cw->m_currentPts - cw->m_previousPts;
}
qWarning() << "::::Computing audio PTS: debugId:" << as->debugId << "ptsdiff:" << as->ptsDiff;
// qWarning() << "::::Computing audio PTS: debugId:" << as->debugId << "ptsdiff:" << as->ptsDiff;
cw->commonUnlock();
cw->m_renderLock->unlock();
cw->m_computedBuffersMutex->unlock();
......
......@@ -134,13 +134,13 @@ void ClipWorkflow::stop()
void
ClipWorkflow::setTime( qint64 time )
{
qDebug() << "setting clipworkflow time:" << time;
// qDebug() << "setting clipworkflow time:" << time;
m_mediaPlayer->setTime( time );
flushComputedBuffers();
QWriteLocker lock( m_stateLock );
if ( m_state == ClipWorkflow::Paused )
{
qDebug() << "Unpausing media player after set time";
// qDebug() << "Unpausing media player after set time";
m_mediaPlayer->pause();
m_state = ClipWorkflow::PauseRequired;
}
......@@ -199,8 +199,8 @@ void ClipWorkflow::postGetOutput()
// This will act like an "unpause";
m_mediaPlayer->pause();
}
else
qCritical() << "Running out of computed buffers ! debugType:" << debugType;
// else
// qCritical() << "Running out of computed buffers ! debugType:" << debugType;
}
}
......
......@@ -89,15 +89,24 @@ VideoClipWorkflow::getUnlockCallback()
void*
VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
// qDebug() << "entering video get output";
QMutexLocker lock( m_renderLock );
// qDebug() << "got video render lock";
QMutexLocker lock2( m_computedBuffersMutex );
// qDebug() << "got video computer buffers lock";
if ( preGetOutput() == false )
{
// qDebug() << "video preGetOutput() returned false";
return NULL;
}
// qWarning() << "Video::getOutput(). Available:" << m_availableBuffers.count() <<
// "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
{
// qDebug() << "video end reached was true";
return NULL;
}
::StackedBuffer<LightVideoFrame*>* buff;
if ( mode == ClipWorkflow::Pop )
{
......@@ -105,7 +114,9 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
}
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer( m_computedBuffers.head(), NULL, false );
// qDebug() << "calling video postGetOutput();";
postGetOutput();
// qDebug() << "returning videobuff";
return buff;
}
......@@ -128,8 +139,8 @@ VideoClipWorkflow::lock( VideoClipWorkflow *cw, void **pp_ret, int size )
else
lvf = cw->m_availableBuffers.dequeue();
cw->m_computedBuffers.enqueue( 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;
}
......@@ -186,7 +197,6 @@ VideoClipWorkflow::flushComputedBuffers()
QMutexLocker lock( m_computedBuffersMutex );
QMutexLocker lock2( m_availableBuffersMutex );
qWarning() << "Flushing computed buffers. state:" << m_state;
while ( m_computedBuffers.isEmpty() == false )
{
m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
......
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