Commit 3ddbee6e authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Fixing a first set of bugs... much more remaining...

parent 46228b4d
......@@ -250,6 +250,7 @@ void MetaDataWorker::unlock( MetaDataWorker* metaDataWorker, uint8_t* pcm
void MetaDataWorker::generateAudioSpectrum()
{
qWarning() << "Generating audio spectrum";
disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( generateAudioSpectrum() ) );
m_mediaPlayer->stop();
emit mediaPlayerIdle( m_mediaPlayer );
......
......@@ -107,13 +107,12 @@ int WorkflowRenderer::lock( void *datas, int64_t *dts, int64_t *pts, unsigne
}
else if ( handler->type == Audio )
{
qWarning() << "got audio type <<<<<<<<<<<<<<<<<<<<<<<<<<<<";
ret = lockAudio( handler->self, pts, bufferSize, buffer );
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;
}
......@@ -153,7 +152,6 @@ 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 from sample #" << self->m_renderAudioSample->debugId;
}
else
{
......@@ -167,7 +165,6 @@ 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;
......
......@@ -131,7 +131,7 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
cw->computePtsDiff( pts );
AudioSample* as = cw->m_computedBuffers.head();
qWarning() << "Computing audio PTS: pts:" << pts << "m_currentPts:" << cw->m_currentPts << "m_previousPts:" << cw->m_previousPts << "for buffer#" << as->debugId;
// qWarning() << "Computing audio PTS: pts:" << pts << "m_currentPts:" << cw->m_currentPts << "m_previousPts:" << cw->m_previousPts << "for buffer#" << as->debugId;
if ( as->buff != NULL )
{
as->nbSample = nb_samples;
......
......@@ -86,7 +86,8 @@ void ClipWorkflow::loadingComplete()
{
adjustBegin();
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( loadingComplete() ) );
qDebug() << "Setting state to Rendering";
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( mediaPlayerUnpaused() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( pause() ), this, SLOT( mediaPlayerPaused() ), Qt::DirectConnection );
QMutexLocker lock( m_initWaitCond->getMutex() );
setState( Rendering );
qDebug() << "Waking init wait cond";
......@@ -190,14 +191,31 @@ LibVLCpp::MediaPlayer* ClipWorkflow::getMediaPlayer()
return m_mediaPlayer;
}
void ClipWorkflow::preGetOutput()
{
QMutexLocker lock( m_feedingCondWait->getMutex() );
if ( getComputedBuffers() == 0 )
{
qWarning() << "Waiting for buffer to be fed";
m_renderLock->unlock();
qDebug() << "Unlocked render lock, entering cond wait";
m_feedingCondWait->waitLocked();
m_renderLock->lock();
}
}
void ClipWorkflow::postGetOutput()
{
//If we're running out of computed buffers, refill our stack.
if ( getComputedBuffers() < getMaxComputedBuffers() / 3 )
{
if ( m_mediaPlayer->isPlaying() == false )
QWriteLocker lock( m_stateLock );
if ( m_state == ClipWorkflow::Paused )
{
qWarning() << "Unpausing media player";
m_state = ClipWorkflow::UnpauseRequired;
//This will act like an "unpause";
m_mediaPlayer->pause();
}
else
......@@ -205,19 +223,6 @@ void ClipWorkflow::postGetOutput()
}
}
void ClipWorkflow::preGetOutput()
{
QMutexLocker lock( m_feedingCondWait->getMutex() );
if ( getComputedBuffers() == 0 )
{
qWarning() << "Waiting for buffer to be fed";
m_renderLock->unlock();
m_feedingCondWait->waitLocked();
m_renderLock->lock();
}
}
void ClipWorkflow::commonUnlock()
{
//Don't test using availableBuffer, as it may evolve if a buffer is required while
......@@ -225,11 +230,14 @@ void ClipWorkflow::commonUnlock()
if ( getComputedBuffers() == getMaxComputedBuffers() )
{
qWarning() << "Pausing media player";
setState( ClipWorkflow::PauseRequired );
m_mediaPlayer->pause();
}
if ( getComputedBuffers() == 1 )
{
qDebug() << "Waking feeding cont wait... acquiring lock";
QMutexLocker lock( m_feedingCondWait->getMutex() );
qDebug() << "feeding cont wait mutex acquired";
m_feedingCondWait->wake();
}
checkStateChange();
......@@ -244,3 +252,15 @@ void ClipWorkflow::computePtsDiff( qint64 pts )
m_previousPts = m_currentPts;
m_currentPts = qMax( pts, m_previousPts );
}
void ClipWorkflow::mediaPlayerPaused()
{
qWarning() << "Media player paused, waiting for buffers to be consumed";
setState( ClipWorkflow::Paused );
}
void ClipWorkflow::mediaPlayerUnpaused()
{
qWarning() << "Media player unpaused. Go back to rendering";
setState( ClipWorkflow::Rendering );
}
......@@ -50,6 +50,16 @@ class ClipWorkflow : public QObject
/// \brief Used when end is reached, IE no more frame has to be rendered, but the trackworkflow
/// may eventually ask for some.
EndReached, //3
// Here starts internal states :
/// \brief This state will be used when an unpause
/// has been required
UnpauseRequired,
/// \brief This state will be used when a pause
/// has been required
PauseRequired,
/// \brief This state will be used when the media player is paused,
/// because of a sufficient number of computed buffers
Paused,
};
/**
......@@ -197,6 +207,8 @@ class ClipWorkflow : public QObject
private slots:
void loadingComplete();
void clipEndReached();
void mediaPlayerPaused();
void mediaPlayerUnpaused();
};
#endif // CLIPWORKFLOW_H
......@@ -123,7 +123,7 @@ MainWorkflow::OutputBuffers* MainWorkflow::getOutput( TrackType trackType )
{
QReadLocker lock3( m_currentFrameLock );
m_tracks[trackType]->getOutput( m_currentFrame[trackType] );
m_tracks[trackType]->getOutput( m_currentFrame[VideoTrack], m_currentFrame[trackType] );
if ( trackType == MainWorkflow::VideoTrack )
{
m_effectEngine->render();
......
......@@ -95,7 +95,7 @@ qint64 TrackHandler::getLength() const
return m_length;
}
void TrackHandler::getOutput( qint64 currentFrame )
void TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
{
m_tmpAudioBuffer = NULL;
for ( unsigned int i = 0; i < m_trackCount; ++i )
......@@ -107,14 +107,14 @@ void TrackHandler::getOutput( qint64 currentFrame )
else
{
StackedBuffer<LightVideoFrame*>* stackedBuffer =
reinterpret_cast<StackedBuffer<LightVideoFrame*>*>( m_tracks[i]->getOutput( currentFrame ) );
reinterpret_cast<StackedBuffer<LightVideoFrame*>*>( m_tracks[i]->getOutput( currentFrame, subFrame ) );
m_effectEngine->setInputFrame( *(stackedBuffer->get()), i );
}
}
else
{
StackedBuffer<AudioClipWorkflow::AudioSample*>* stackedBuffer =
reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*> (m_tracks[i]->getOutput( currentFrame ) );
reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*> ( m_tracks[i]->getOutput( currentFrame, subFrame ) );
if ( stackedBuffer != NULL )
m_tmpAudioBuffer = stackedBuffer->get();
//else if will remain NULL
......
......@@ -47,7 +47,15 @@ class TrackHandler : public QObject
unsigned int getTrackCount() const;
qint64 getLength() const;
void startRender();
void getOutput( qint64 currentFrame );
/**
* \param currentFrame The current rendering frame (ie the video frame, in all case)
* \param subFrame The underlying system frame. For video TrackWorkflow, it's the same
* as the currentFrame. For an Audio TrackWorkflow, it is the current
* "audio frame"
* \todo This should probably be partialy handled by the trackHandler, as the work
* is exactly the same for both audio and video trackWorkflow in most of the case... or not.
*/
void getOutput( qint64 currentFrame, qint64 subFrame );
void pause();
void unpause();
void activateAll();
......
......@@ -129,8 +129,11 @@ void* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
{
cw->getStateLock()->lockForRead();
// qDebug() << "Rendering clip" << cw << "state:" << cw->getState() << "Type:" << m_trackType;
if ( cw->getState() == ClipWorkflow::Rendering )
qDebug() << "Rendering clip" << cw << "state:" << cw->getState() << "Type:" << m_trackType;
if ( cw->getState() == ClipWorkflow::Rendering ||
cw->getState() == ClipWorkflow::Paused ||
cw->getState() == ClipWorkflow::PauseRequired ||
cw->getState() == ClipWorkflow::UnpauseRequired )
{
cw->getStateLock()->unlock();
if ( needRepositioning == true )
......@@ -150,11 +153,13 @@ void* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
}
else if ( cw->getState() == ClipWorkflow::EndReached )
{
qDebug() << "State is endreached";
cw->getStateLock()->unlock();
//The stopClipWorkflow() method will take care of that.
}
else
{
qCritical() << "Unexpected state:" << cw->getState();
cw->getStateLock()->unlock();
}
return NULL;
......@@ -227,7 +232,7 @@ void TrackWorkflow::releasePreviousRender()
m_videoStackedBuffer->release();
}
void* TrackWorkflow::getOutput( qint64 currentFrame )
void* TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame )
{
releasePreviousRender();
QReadLocker lock( m_clipsLock );
......@@ -249,10 +254,10 @@ void* TrackWorkflow::getOutput( qint64 currentFrame )
needRepositioning = true;
m_forceRepositionning = false;
}
else if ( m_paused == true && currentFrame != m_lastFrame )
else if ( m_paused == true && subFrame != m_lastFrame )
needRepositioning = true;
else
needRepositioning = ( abs( currentFrame - m_lastFrame ) > 1 ) ? true : false;
needRepositioning = ( abs( subFrame - m_lastFrame ) > 1 ) ? true : false;
}
while ( it != end )
......@@ -263,6 +268,7 @@ void* TrackWorkflow::getOutput( qint64 currentFrame )
// qDebug() << "Start:" << start << "Current Frame:" << currentFrame;
if ( start <= currentFrame && currentFrame <= start + cw->getClip()->getLength() )
{
qDebug() << "Rendering clip... type:" << m_trackType;
if ( ret != NULL )
qCritical() << "There's more than one clip to render here. Undefined behaviour !";
ret = renderClip( cw, currentFrame, start, needRepositioning );
......@@ -270,22 +276,24 @@ void* TrackWorkflow::getOutput( qint64 currentFrame )
m_videoStackedBuffer = reinterpret_cast<StackedBuffer<LightVideoFrame*>*>( ret );
else
m_audioStackedBuffer = reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*>( ret );
qDebug() << "Rendered buffer. Type:" << m_trackType << "ret:" << (void*)ret;
}
//Is it about to be rendered ?
else if ( start > currentFrame &&
start - currentFrame < TrackWorkflow::nbFrameBeforePreload )
{
qDebug() << "Preloading clip.";
preloadClip( cw );
}
//Is it supposed to be stopped ?
else
{
qDebug() << "Stopping clip";
stopClipWorkflow( cw );
}
++it;
}
m_lastFrame = currentFrame;
m_lastFrame = subFrame;
return ret;
}
......
......@@ -53,7 +53,7 @@ class TrackWorkflow : public QObject
TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type );
~TrackWorkflow();
void* getOutput( qint64 currentFrame );
void* getOutput( qint64 currentFrame, qint64 subFrame );
qint64 getLength() const;
void stop();
void pause();
......
......@@ -91,10 +91,16 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
preGetOutput();
// qWarning() << "Video. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
{
qWarning() << "End is reached. returning NULL";
return NULL;
}
StackedBuffer<LightVideoFrame*>* buff;
if ( mode == ClipWorkflow::Pop )
{
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.pop(), &m_availableBuffers, true );
qDebug() << "buff:" << (void*)buff;
}
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.head(), NULL, false );
postGetOutput();
......
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