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

Audio is now working when seeking :)

parent ac381359
......@@ -103,6 +103,7 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
self->emit timeChanged( event->u.media_player_time_changed.new_time / 1000 );
break;
case libvlc_MediaPlayerPositionChanged:
// qDebug() << self << "position changed : " << event->u.media_player_position_changed.new_position;
self->emit positionChanged( event->u.media_player_position_changed.new_position );
break;
case libvlc_MediaPlayerLengthChanged:
......@@ -156,7 +157,6 @@ qint64 MediaPlayer::getTime()
void MediaPlayer::setTime( qint64 time )
{
qDebug() << this << "MediaPlayer::setTime: setting time to" << time;
libvlc_media_player_set_time( m_internalPtr, time, m_ex );
CheckVlcppException( m_ex );
}
......
......@@ -52,9 +52,7 @@ void MetaDataWorker::compute()
{
if ( m_type == Audio )
{
qDebug() << "Skipping metadata computing";
return ;
// computeAudioMetaData();
computeAudioMetaData();
}
else
computeVideoMetaData();
......@@ -254,7 +252,6 @@ 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 );
......
......@@ -98,7 +98,8 @@ void AudioClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
m_vlcMedia->addOption( ":sout-transcode-samplerate=48000" );
m_vlcMedia->addOption( ":sout-transcode-channels=2" );
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
m_vlcMedia->addOption( ":sout-smem-time-sync" );
// m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
AudioClipWorkflow::AudioSample* AudioClipWorkflow::createBuffer( size_t size )
......@@ -117,7 +118,7 @@ void AudioClipWorkflow::lock( AudioClipWorkflow* cw, uint8_t** pcm_buffer
cw->m_renderLock->lock();
cw->m_computedBuffersMutex->lock();
qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count() << "position" << cw->m_mediaPlayer->getPosition();
// qWarning() << ">>>AudioGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count() << "position" << cw->m_mediaPlayer->getPosition();
AudioSample* as = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
{
......@@ -157,10 +158,6 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
as->nbChannels = channels;
as->ptsDiff = cw->m_currentPts - cw->m_previousPts;
}
// if ( as->ptsDiff == 0 )
// {
// qCritical() << "PTS DIFF IS 0 !!!! ";
// }
// qWarning() << "::::Computing audio PTS: debugId:" << as->debugId << "ptsdiff:" << as->ptsDiff;
cw->commonUnlock();
cw->m_renderLock->unlock();
......@@ -185,7 +182,6 @@ void AudioClipWorkflow::releaseBuffer( AudioSample *sample )
void AudioClipWorkflow::flushComputedBuffers()
{
qDebug() << "Flushing computed buffers in audio";
QMutexLocker lock( m_availableBuffersMutex );
QMutexLocker lock2( m_computedBuffersMutex );
......
......@@ -127,6 +127,7 @@ void ClipWorkflow::stop()
m_mediaPlayer = NULL;
setState( Stopped );
delete m_vlcMedia;
flushComputedBuffers();
}
else
qDebug() << "ClipWorkflow has already been stopped";
......@@ -135,9 +136,12 @@ void ClipWorkflow::stop()
void
ClipWorkflow::setTime( qint64 time )
{
qDebug() << "setting clipworkflow time:" << time << "debugType:" << debugType;
flushComputedBuffers();
// qDebug() << m_mediaPlayer << "setting clipworkflow time:" << time << "debugType:" << debugType <<
// "theorical position:" << (double)time / (double)((double)m_clip->getLengthSecond() * 1000.0);
connect( m_mediaPlayer, SIGNAL( timeChanged(qint64) ),
this, SLOT( resyncClipWorkflow() ), Qt::DirectConnection );
m_mediaPlayer->setTime( time );
flushComputedBuffers();
QWriteLocker lock( m_stateLock );
if ( m_state == ClipWorkflow::Paused )
{
......@@ -219,11 +223,6 @@ void ClipWorkflow::commonUnlock()
void ClipWorkflow::computePtsDiff( qint64 pts )
{
// if ( debugType == 1 )
// {
// qDebug() << "in computePtsDiff, Before << : pts:" << pts << "previousPts:" << m_previousPts
// << "currentPts:" << m_currentPts;
// }
if ( m_previousPts == -1 )
m_previousPts = pts;
if ( m_currentPts == -1 )
......@@ -263,3 +262,12 @@ void ClipWorkflow::mediaPlayerUnpaused()
m_pauseDuration = mdate() - m_beginPausePts;
// qDebug() << "pause duration:" << m_pauseDuration;
}
void ClipWorkflow::resyncClipWorkflow()
{
disconnect( m_mediaPlayer, SIGNAL( timeChanged(qint64) ),
this, SLOT( resyncClipWorkflow() ) );
flushComputedBuffers();
m_previousPts = -1;
m_currentPts = -1;
}
......@@ -178,6 +178,8 @@ class ClipWorkflow : public QObject
* This has to be implemented in the underlying
* clipworkflow implementation.
*/
virtual void flushComputedBuffers() = 0;
private:
WaitCondition* m_initWaitCond;
WaitCondition* m_pausingStateWaitCond;
......@@ -210,7 +212,7 @@ class ClipWorkflow : public QObject
void clipEndReached();
void mediaPlayerPaused();
void mediaPlayerUnpaused();
virtual void flushComputedBuffers() = 0;
void resyncClipWorkflow();
};
#endif // CLIPWORKFLOW_H
......@@ -62,7 +62,8 @@ VideoClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
// m_vlcMedia->addOption( ":no-sout-keep" );
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
m_vlcMedia->addOption( ":sout-smem-time-sync" );
// m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
sprintf( buffer, ":sout-transcode-width=%i",
MainWorkflow::getInstance()->getWidth() );
......@@ -123,10 +124,12 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void
VideoClipWorkflow::lock( VideoClipWorkflow *cw, void **pp_ret, int size )
{
// qDebug() << "Entering VideoClipWorkflow::lock";
Q_UNUSED( size );
QMutexLocker lock( cw->m_availableBuffersMutex );
cw->m_renderLock->lock();
cw->m_computedBuffersMutex->lock();
// qDebug() << "Got all videoclipworkflow::lock mutexs acquired.";
LightVideoFrame* lvf = NULL;
if ( cw->m_availableBuffers.isEmpty() == true )
......@@ -139,8 +142,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() << "position" << cw->m_mediaPlayer->getPosition();
// qWarning() << ">>>VideoGeneration. Available:" <<
// cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count() << "position" << cw->m_mediaPlayer->getPosition();
// qWarning() << "feeding video buffer";
*pp_ret = (*(lvf))->frame.octets;
}
......@@ -194,7 +197,6 @@ VideoClipWorkflow::releaseBuffer( LightVideoFrame *lvf )
void
VideoClipWorkflow::flushComputedBuffers()
{
qDebug() << "Flushing computed buffers in video";
QMutexLocker lock( m_computedBuffersMutex );
QMutexLocker lock2( m_availableBuffersMutex );
......
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