Commit 536c901a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Some bugs are gone, some other stay...

Right now, it's blocked by a frameChanged // cursorPositionChanged signal problem
parent e885c11b
......@@ -28,7 +28,7 @@ Instance::Instance()
{
char const *argv[] =
{
"-vvvvv",
// "-vvvvv",
"--no-skip-frames",
// "--intf", "dummy",
"--text-renderer", "dummy",
......
......@@ -34,16 +34,7 @@ MediaPlayer::MediaPlayer() : m_media( NULL )
// Initialize the event manager
p_em = libvlc_media_player_event_manager( m_internalPtr, m_ex );
// Register the callback
libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerStopped, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerLengthChanged, callbacks,this,m_ex );
registerEvents();
}
MediaPlayer::MediaPlayer( Media* media ) : m_media( media )
......@@ -53,15 +44,7 @@ MediaPlayer::MediaPlayer( Media* media ) : m_media( media )
// Initialize the event manager
p_em = libvlc_media_player_event_manager( m_internalPtr, m_ex );
// Register the callback
libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerStopped, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
registerEvents();
}
MediaPlayer::~MediaPlayer()
......@@ -76,6 +59,23 @@ MediaPlayer::~MediaPlayer()
libvlc_media_player_release( m_internalPtr );
}
void
MediaPlayer::registerEvents()
{
// Register the callback
libvlc_event_attach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPlaying, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPaused, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerStopped, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerEndReached, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerLengthChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerEncounteredError,callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerPausableChanged, callbacks, this, m_ex );
libvlc_event_attach( p_em, libvlc_MediaPlayerSeekableChanged, callbacks, this, m_ex );
}
/**
* Event dispatcher.
*/
......@@ -111,6 +111,10 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
case libvlc_MediaPlayerSnapshotTaken:
self->emit snapshotTaken();
break;
case libvlc_MediaPlayerEncounteredError:
qDebug() << "libvlc_MediaPlayerEncounteredError received."
<< "This is not looking good...";
break ;
case libvlc_MediaPlayerSeekableChanged:
case libvlc_MediaPlayerPausableChanged:
case libvlc_MediaPlayerTitleChanged:
......@@ -119,9 +123,8 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
case libvlc_MediaPlayerBuffering:
case libvlc_MediaPlayerForward:
case libvlc_MediaPlayerBackward:
case libvlc_MediaPlayerEncounteredError:
default:
qDebug() << "Unknown mediaPlayerEvent: " << event->type;
// qDebug() << "Unknown mediaPlayerEvent: " << event->type;
break;
}
}
......@@ -153,6 +156,7 @@ 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 );
}
......
......@@ -65,6 +65,7 @@ namespace LibVLCpp
private:
static void callbacks( const libvlc_event_t* event, void* self );
void registerEvents();
Exception m_ex;
libvlc_event_manager_t* p_em;
......
......@@ -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()
......
......@@ -63,7 +63,7 @@ void WorkflowRenderer::initializeRenderer()
sprintf( videoString, "width=%i:height=%i:dar=%s:fps=%s:data=%lld:codec=%s:cat=2:caching=0",
m_mainWorkflow->getWidth(), m_mainWorkflow->getHeight(), "4/3", "30/1", (qint64)m_videoEsHandler, "RV24" );
sprintf( audioParameters, "data=%lld:cat=1:codec=s16l:samplerate=%u:channels=%u",
sprintf( audioParameters, "data=%lld:cat=1:codec=s16l:samplerate=%u:channels=%u:caching=0",
(qint64)m_audioEsHandler, m_rate, m_nbChannels );
strcpy( inputSlave, ":input-slave=imem://" );
strcat( inputSlave, audioParameters );
......@@ -130,7 +130,7 @@ int WorkflowRenderer::lockVideo( WorkflowRenderer* self, int64_t *pts, size_
ptsDiff = (*(ret->video))->ptsDiff;
}
self->m_pts = *pts = ptsDiff + self->m_pts;
//qDebug() << "Video pts" << self->m_pts << "diff" << ptsDiff;
// qDebug() << "Video pts" << self->m_pts << "diff" << ptsDiff;
//*pts = qRound64( (float)( self->m_pts * 1000000.0f ) / self->m_outputFps );
//++self->m_pts;
*buffer = self->m_renderVideoFrame;
......@@ -167,7 +167,7 @@ int WorkflowRenderer::lockAudio( WorkflowRenderer* self, int64_t *pts, size
ptsDiff = self->m_pts - self->m_audioPts;
}
self->m_audioPts = *pts = self->m_audioPts + ptsDiff;
//qDebug() << "Audio pts" << self->m_audioPts << "diff" << ptsDiff;
// qDebug() << "Audio pts" << self->m_audioPts << "diff" << ptsDiff;
//*pts = self->m_audioPts * 1000000.0f / self->m_rate;
//self->m_audioPts += nbSample * self->m_nbChannels;
return 0;
......
......@@ -32,6 +32,7 @@ AudioClipWorkflow::AudioClipWorkflow( Clip* clip ) :
AudioSample* as = new AudioSample;
as->buff = NULL;
m_availableBuffers.push_back( as );
as->debugId = i;
}
debugType = 1;
}
......@@ -60,9 +61,12 @@ 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 )
{
qDebug() << "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(
......@@ -73,7 +77,8 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void AudioClipWorkflow::initVlcOutput()
{
m_vlcMedia->addOption( ":verbose 3" );
// m_vlcMedia->addOption( ":verbose 3" );
// m_vlcMedia->addOption( ":vvv" );
m_vlcMedia->addOption( ":no-sout-video" );
m_vlcMedia->addOption( ":no-video" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
......@@ -91,6 +96,7 @@ AudioClipWorkflow::AudioSample* AudioClipWorkflow::createBuffer( size_t size
AudioSample* as = new AudioSample;
as->buff = new uchar[size];
as->size = size;
as->debugId = -1;
return as;
}
......
......@@ -74,7 +74,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 = 256;
static const uint32_t nbBuffers = 1024;
};
#endif // AUDIOCLIPWORKFLOW_H
......@@ -150,6 +150,7 @@ void ClipWorkflow::stop()
void ClipWorkflow::setTime( qint64 time )
{
qDebug() << "setting clipworkflow time to:" << time;
m_mediaPlayer->setTime( time );
flushComputedBuffers();
}
......@@ -199,10 +200,10 @@ void ClipWorkflow::preGetOutput()
//Computed buffer mutex is already locked by underlying clipworkflow getoutput method
if ( getNbComputedBuffers() == 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();
......@@ -212,6 +213,8 @@ void ClipWorkflow::preGetOutput()
void ClipWorkflow::postGetOutput()
{
//If we're running out of computed buffers, refill our stack.
if ( debugType == 1 )
qDebug() << "AudioClipWorkflow::postGetOutput";
if ( getNbComputedBuffers() < getMaxComputedBuffers() / 3 )
{
QWriteLocker lock( m_stateLock );
......@@ -222,8 +225,8 @@ void ClipWorkflow::postGetOutput()
// This will act like an "unpause";
m_mediaPlayer->pause();
}
// else
// qCritical() << "Running out of computed buffers !";
else
qCritical() << "Running out of computed buffers !";
}
}
......@@ -233,7 +236,7 @@ void ClipWorkflow::commonUnlock()
//no one is available : we would spawn a new buffer, thus modifying the number of available buffers
if ( getNbComputedBuffers() == getMaxComputedBuffers() )
{
qWarning() << "Pausing clip workflow. Type:" << debugType;
// qWarning() << "Pausing clip workflow. Type:" << debugType;
setState( ClipWorkflow::PauseRequired );
m_mediaPlayer->pause();
}
......@@ -249,23 +252,38 @@ 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 )
m_currentPts = pts;
if ( m_pauseDuration != -1 )
{
// qDebug() << "In pause mode";
m_previousPts = m_currentPts + m_pauseDuration;
m_pauseDuration = -1;
}
else
m_previousPts = m_currentPts;
// if ( debugType == 1 )
// {
// qDebug() << "in computePtsDiff, After >> : pts:" << pts << "previousPts:" << m_previousPts
// << "currentPts:" << m_currentPts;
// }
// if ( debugType == 1 && pts < m_previousPts )
// {
// qCritical() << "New PTS is lower than previous PTS !<<<<<<<<<<<<<<<<<<<<<<<<<<";
// }
m_currentPts = qMax( pts, m_previousPts );
}
void ClipWorkflow::mediaPlayerPaused()
{
qWarning() << "\n\n\n\nMedia player paused, waiting for buffers to be consumed.Type:" << debugType << "\n\n\n\n";
qWarning() << "\n\nMedia player paused, waiting for buffers to be consumed.Type:" << debugType << "\n\n";
setState( ClipWorkflow::Paused );
m_beginPausePts = mdate();
// qDebug() << "got pause pts:" << m_beginPausePts;
......
......@@ -136,8 +136,7 @@ MainWorkflow::getOutput( TrackType trackType )
{
QReadLocker lock2( m_currentFrameLock );
m_tracks[trackType]->getOutput( m_currentFrame[VideoTrack],
m_currentFrame[trackType] );
m_tracks[trackType]->getOutput( m_currentFrame[trackType] );
if ( trackType == MainWorkflow::VideoTrack )
{
m_effectEngine->render();
......@@ -264,11 +263,18 @@ MainWorkflow::unmuteTrack( unsigned int trackId, MainWorkflow::TrackType trackTy
m_tracks[trackType]->unmuteTrack( trackId );
}
void toggleBreakPoint()
{
}
void
MainWorkflow::setCurrentFrame( qint64 currentFrame, MainWorkflow::FrameChangedReason reason )
{
QWriteLocker lock( m_currentFrameLock );
// if ( m_currentFrame[VideoTrack] == currentFrame )
return ;
toggleBreakPoint();
if ( m_renderStarted == true )
{
//Since any track can be reactivated, we reactivate all of them, and let them
......
......@@ -103,7 +103,7 @@ TrackHandler::getLength() const
}
void
TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
TrackHandler::getOutput( qint64 currentFrame )
{
m_tmpAudioBuffer = NULL;
for ( unsigned int i = 0; i < m_trackCount; ++i )
......@@ -116,7 +116,7 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
{
StackedBuffer<LightVideoFrame*>* stackedBuffer =
reinterpret_cast<StackedBuffer<LightVideoFrame*>*>(
m_tracks[i]->getOutput( currentFrame, subFrame ) );
m_tracks[i]->getOutput( currentFrame ) );
m_effectEngine->setVideoInput( i + 1, *( stackedBuffer->get() ) );
}
......@@ -126,7 +126,7 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame )
StackedBuffer<AudioClipWorkflow::AudioSample*>*
stackedBuffer =
reinterpret_cast<StackedBuffer<AudioClipWorkflow::AudioSample*>*> (
m_tracks[i]->getOutput( currentFrame, subFrame ) );
m_tracks[i]->getOutput( currentFrame ) );
if ( stackedBuffer != NULL )
m_tmpAudioBuffer = stackedBuffer->get();
//else if will remain NULL
......
......@@ -49,13 +49,10 @@ class TrackHandler : public QObject
void startRender();
/**
* \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 getOutput( qint64 currentFrame );
void pause();
void unpause();
void activateAll();
......
......@@ -134,6 +134,7 @@ void* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
{
cw->getStateLock()->lockForRead();
qDebug() << "TrackWorkflow::renderClip. currentFrame:" << currentFrame << "trackType:" << m_trackType;
// qDebug() << "Rendering clip" << cw << "state:" << cw->getState() << "Type:" << m_trackType;
if ( cw->getState() == ClipWorkflow::Rendering ||
cw->getState() == ClipWorkflow::Paused ||
......@@ -142,7 +143,10 @@ void* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
{
cw->getStateLock()->unlock();
if ( needRepositioning == true )
{
qDebug() << "adjusting because of needRepositionning";
adjustClipTime( currentFrame, start, cw );
}
return cw->getOutput( ClipWorkflow::Pop );
}
else if ( cw->getState() == ClipWorkflow::Stopped )
......@@ -151,6 +155,8 @@ void* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
cw->initialize();
if ( start != currentFrame || cw->getClip()->getBegin() != 0 ) //Clip was not started as its real begining
{
qDebug() << "Adjusting clip start. start:" << start << "currentframe:" << currentFrame
<< "clip begin:" << cw->getClip()->getBegin();
adjustClipTime( currentFrame, start, cw );
}
cw->waitForCompleteInit();
......@@ -236,7 +242,7 @@ void TrackWorkflow::releasePreviousRender()
m_videoStackedBuffer->release();
}
void* TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame )
void* TrackWorkflow::getOutput( qint64 currentFrame )
{
releasePreviousRender();
QReadLocker lock( m_clipsLock );
......@@ -255,13 +261,24 @@ void* TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFra
QMutexLocker lock( m_forceRepositionningMutex );
if ( m_forceRepositionning == true )
{
qDebug() << "Force repositionning is required.";
needRepositioning = true;
m_forceRepositionning = false;
}
else if ( m_paused == true && subFrame != m_lastFrame )
needRepositioning = true;
else if ( m_paused == true && currentFrame != m_lastFrame )
{
needRepositioning = true;
qDebug() << "Paused is true, currentframe != lastframe -> repo";
}
else
needRepositioning = ( abs( subFrame - m_lastFrame ) > 1 ) ? true : false;
{
needRepositioning = ( abs( currentFrame - m_lastFrame ) > 1 ) ? true : false;
if ( needRepositioning == true )
{
qDebug() << "Need repo because more than 1 frame has passed. currentFrame:"
<< currentFrame << "m_lastFrame:" << m_lastFrame;
}
}
}
while ( it != end )
......@@ -289,7 +306,7 @@ void* TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFra
stopClipWorkflow( cw );
++it;
}
m_lastFrame = subFrame;
m_lastFrame = currentFrame;
return ret;
}
......@@ -447,6 +464,8 @@ void TrackWorkflow::clear()
void TrackWorkflow::adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw )
{
if ( m_trackType == MainWorkflow::AudioTrack )
qDebug() << "Adjusting clip time for audio:" << currentFrame;
qint64 nbMs = ( currentFrame - start ) / cw->getClip()->getParent()->getFps() * 1000;
qint64 beginInMs = cw->getClip()->getBegin() / cw->getClip()->getParent()->getFps() * 1000;
qint64 startFrame = beginInMs + nbMs;
......
......@@ -58,7 +58,7 @@ class TrackWorkflow : public QObject
TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type );
~TrackWorkflow();
void* getOutput( qint64 currentFrame, qint64 subFrame );
void* getOutput( qint64 currentFrame );
qint64 getLength() const;
void stop();
void pause();
......
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