Commit ccd6a8b3 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Handle clip beginning at non zero dates

parent de2f7604
......@@ -26,7 +26,7 @@
#include "Clip.h"
Clip::Clip( Media* parent ) : m_parent( parent ), m_begin( 0.0f ), m_end( Clip::UntilEndOfMedia )
Clip::Clip( Media* parent ) : m_parent( parent ), m_begin( 0.5f ), m_end( Clip::UntilEndOfMedia )
{
init();
}
......
......@@ -38,7 +38,7 @@ class Clip : public QObject
Q_OBJECT
public:
static const float UntilEndOfMedia = -1.0;
static const float UntilEndOfMedia = -1;
Clip( Media* parent );
Clip( Clip* creator, qint64 begin, qint64 end );
......
......@@ -30,16 +30,19 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip, QMutex* condMutex, QWaitCondition*
m_buffer( NULL ),
m_condMutex( condMutex ),
m_waitCond( waitCond ),
m_mediaPlayer(NULL)
m_mediaPlayer(NULL),
m_isReady( false )
{
m_mutex = new QReadWriteLock();
m_buffer = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4];
m_initMutex = new QReadWriteLock();
}
ClipWorkflow::~ClipWorkflow()
{
delete[] m_buffer;
delete m_mutex;
delete m_initMutex;
}
bool ClipWorkflow::renderComplete() const
......@@ -58,20 +61,26 @@ void ClipWorkflow::lock( ClipWorkflow* clipWorkflow, void** pp_ret )
//It doesn't seems necessary to lock anything here, since the scheduler
//will wait until the frame is ready to use it, and doesn't use it after
//it has asked for a new one.
qDebug() << "Locking in ClipWorkflow::lock";
//In any case, we give vlc a buffer to render in...
//If we don't, segmentation fault will catch us and eat our brain !! ahem...
// qDebug() << "Locking in ClipWorkflow::lock";
*pp_ret = clipWorkflow->m_buffer;
}
void ClipWorkflow::unlock( ClipWorkflow* clipWorkflow )
{
// qDebug() << "Outputing debug image";
QMutexLocker lock( clipWorkflow->m_condMutex );
if ( clipWorkflow->m_isReady == true )
{
QWriteLocker lock2( clipWorkflow->m_mutex );
clipWorkflow->m_renderComplete = true;
// qDebug() << "Outputing debug image";
QMutexLocker lock( clipWorkflow->m_condMutex );
{
QWriteLocker lock2( clipWorkflow->m_mutex );
clipWorkflow->m_renderComplete = true;
}
// qDebug() << "Frame rendered, sleeping mode";
clipWorkflow->m_waitCond->wait( clipWorkflow->m_condMutex );
}
// qDebug() << "Frame rendered, sleeping mode";
clipWorkflow->m_waitCond->wait( clipWorkflow->m_condMutex );
}
void ClipWorkflow::initialize()
......@@ -101,9 +110,36 @@ void ClipWorkflow::startRender( LibVLCpp::MediaPlayer* mediaPlayer )
m_mediaPlayer = mediaPlayer;
m_mediaPlayer->setMedia( m_clip->getParent()->getVLCMedia() );
//If Clip starts at 0, we can play it directly.
if ( m_clip->getBegin() == 0.0f )
{
QWriteLocker lock( m_initMutex );
m_isReady = true;
}
else
{
//The last parameter is NOT here for decoration ;)
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( playbackStarted() ), Qt::DirectConnection );
}
m_mediaPlayer->play();
//else, we should set it position before.
//TODO...
}
void ClipWorkflow::playbackStarted()
{
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( playbackStarted() ) );
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( positionChanged() ), Qt::DirectConnection );
m_mediaPlayer->setPosition( m_clip->getBegin() );
}
void ClipWorkflow::positionChanged()
{
disconnect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( positionChanged() ) );
QWriteLocker lock( m_initMutex);
m_isReady = true;
}
bool ClipWorkflow::isReady()
{
QReadLocker lock( m_initMutex );
return m_isReady;
}
......@@ -48,6 +48,7 @@ class ClipWorkflow : public QObject
bool renderComplete() const;
unsigned char* getOutput();
void startRender( LibVLCpp::MediaPlayer* mediaPlayer );
bool isReady();
private:
static void lock( ClipWorkflow* clipWorkflow, void** pp_ret );
static void unlock( ClipWorkflow* clipWorkflow );
......@@ -61,6 +62,12 @@ class ClipWorkflow : public QObject
QMutex* m_condMutex;
QWaitCondition* m_waitCond;
LibVLCpp::MediaPlayer* m_mediaPlayer;
QReadWriteLock* m_initMutex;
bool m_isReady;
public slots:
void playbackStarted();
void positionChanged();
};
#endif // CLIPWORKFLOW_H
......@@ -39,6 +39,8 @@ void TrackWorkflow::addClip( Clip* clip )
void TrackWorkflow::startRender()
{
m_currentClipWorkflow->startRender( m_mediaPlayer );
while ( m_currentClipWorkflow->isReady() == false )
usleep( 150 );
}
unsigned char* TrackWorkflow::getOutput()
......
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