Commit 05c24916 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Moving down more ClipWorkflow methods to VideoClipWorkflow

parent a50130fe
......@@ -40,7 +40,7 @@ Media::~Media()
void Media::addOption( const char* opt )
{
libvlc_media_add_option_flag( m_internalPtr, opt, libvlc_media_option_trusted, m_ex);
libvlc_media_add_option_flag( m_internalPtr, opt, libvlc_media_option_trusted );
CheckVlcppException(m_ex);
}
......
......@@ -29,10 +29,10 @@
ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_clip( clip ),
m_mediaPlayer(NULL),
m_state( ClipWorkflow::Stopped ),
m_requiredState( ClipWorkflow::None ),
m_rendering( false ),
m_initFlag( false ),
m_state( ClipWorkflow::Stopped ),
m_fullSpeedRender( false )
{
m_stateLock = new QReadWriteLock;
......@@ -43,7 +43,6 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_renderWaitCond = new WaitCondition;
m_pausingStateWaitCond = new WaitCondition;
m_renderLock = new QMutex;
m_buffer = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4];
}
ClipWorkflow::~ClipWorkflow()
......@@ -55,16 +54,6 @@ ClipWorkflow::~ClipWorkflow()
delete m_waitCond;
delete m_requiredStateLock;
delete m_stateLock;
delete[] m_buffer;
}
unsigned char* ClipWorkflow::getOutput()
{
QMutexLocker lock( m_renderLock );
if ( isEndReached() == true )
return NULL;
return m_buffer;
}
void ClipWorkflow::checkStateChange()
......@@ -80,91 +69,11 @@ void ClipWorkflow::checkStateChange()
}
}
void ClipWorkflow::lock( ClipWorkflow* cw, void** pp_ret, int size )
{
Q_UNUSED( size );
cw->m_renderLock->lock();
*pp_ret = cw->m_buffer;
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::lock";
}
void ClipWorkflow::unlock( ClipWorkflow* cw, void* buffer, int width, int height, int bpp, int size )
{
Q_UNUSED( buffer );
Q_UNUSED( width );
Q_UNUSED( height );
Q_UNUSED( bpp );
Q_UNUSED( size );
cw->m_renderLock->unlock();
cw->m_stateLock->lockForWrite();
if ( cw->m_state == Rendering )
{
QMutexLocker lock( cw->m_condMutex );
cw->m_state = Sleeping;
cw->m_stateLock->unlock();
{
QMutexLocker lock2( cw->m_renderWaitCond->getMutex() );
cw->m_renderWaitCond->wake();
}
cw->emit renderComplete( cw );
// qDebug() << "Emmiting render completed";
// qDebug() << "Entering cond wait";
cw->m_waitCond->wait( cw->m_condMutex );
// qDebug() << "Leaving condwait";
cw->m_stateLock->lockForWrite();
if ( cw->m_state == Sleeping )
cw->m_state = Rendering;
cw->m_stateLock->unlock();
}
else
cw->m_stateLock->unlock();
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::unlock";
cw->checkStateChange();
}
void ClipWorkflow::setVmem()
{
char buffer[32];
m_vlcMedia->addOption( ":no-audio" );
m_vlcMedia->addOption( ":no-sout-audio" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
m_vlcMedia->setDataCtx( this );
m_vlcMedia->setLockCallback( reinterpret_cast<LibVLCpp::Media::lockCallback>( &ClipWorkflow::lock ) );
m_vlcMedia->setUnlockCallback( reinterpret_cast<LibVLCpp::Media::unlockCallback>( &ClipWorkflow::unlock ) );
m_vlcMedia->addOption( ":sout-transcode-vcodec=RV24" );
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
// m_vlcMedia->addOption( ":no-sout-keep" );
if ( m_fullSpeedRender == true )
{
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
else
m_vlcMedia->addOption( ":sout-smem-time-sync" );
sprintf( buffer, ":sout-transcode-width=%i", VIDEOWIDTH );
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":sout-transcode-height=%i", VIDEOHEIGHT );
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":sout-transcode-fps=%f", (float)FPS );
m_vlcMedia->addOption( buffer );
//sprintf( buffer, "sout-smem-video-pitch=%i", VIDEOWIDTH * 3 );
//m_vlcMedia->addOption( buffer );
}
void ClipWorkflow::initialize( bool preloading /*= false*/ )
{
setState( Initializing );
m_vlcMedia = new LibVLCpp::Media( "file://" + m_clip->getParent()->getFileInfo()->absoluteFilePath() );
setVmem();
initVlcOutput();
m_mediaPlayer = Pool<LibVLCpp::MediaPlayer>::getInstance()->get();
m_mediaPlayer->setMedia( m_vlcMedia );
......
......@@ -65,7 +65,8 @@ class ClipWorkflow : public QObject
* therefore, you can call this method blindly, without taking care
* of the rendering process advancement.
*/
unsigned char* getOutput();
virtual void* getOutput() = 0;
virtual void initVlcOutput() = 0;
void initialize( bool preloading = false );
/**
* Return true ONLY if the state is equal to Ready.
......@@ -153,44 +154,26 @@ class ClipWorkflow : public QObject
void waitForCompleteRender( bool dontCheckRenderStarted = false );
QMutex* getSleepMutex();
virtual void* getLockCallback() = 0;
virtual void* getUnlockCallback() = 0;
LibVLCpp::MediaPlayer* getMediaPlayer();
void setFullSpeedRender( bool value );
private:
static void lock( ClipWorkflow* clipWorkflow, void** pp_ret, int size );
static void unlock( ClipWorkflow* clipWorkflow, void* buffer, int width, int height, int bpp, int size );
void setVmem();
void setState( State state );
void checkSynchronisation( State newState );
/**
* Don't ever call this method from anywhere else than the unlock() method
*/
void checkStateChange();
private:
Clip* m_clip;
/**
* \brief The VLC media used to render
*/
LibVLCpp::Media* m_vlcMedia;
unsigned char* m_buffer;
QMutex* m_renderLock;
LibVLCpp::MediaPlayer* m_mediaPlayer;
QMutex* m_condMutex;
QWaitCondition* m_waitCond;
State m_state;
QReadWriteLock* m_stateLock;
State m_requiredState;
QMutex* m_requiredStateLock;
WaitCondition* m_initWaitCond;
WaitCondition* m_renderWaitCond;
WaitCondition* m_pausingStateWaitCond;
/**
......@@ -205,7 +188,24 @@ class ClipWorkflow : public QObject
*/
bool m_initFlag;
protected:
QMutex* m_renderLock;
QReadWriteLock* m_stateLock;
QMutex* m_condMutex;
State m_state;
WaitCondition* m_renderWaitCond;
QWaitCondition* m_waitCond;
bool m_fullSpeedRender;
/**
* \brief The VLC media used to render
*/
LibVLCpp::Media* m_vlcMedia;
protected:
/**
* Don't ever call this method from anywhere else than the unlock() method
*/
void checkStateChange();
private slots:
/**
......
......@@ -24,6 +24,7 @@
#include "vlmc.h"
#include "TrackWorkflow.h"
#include "VideoClipWorkflow.h"
TrackWorkflow::TrackWorkflow( unsigned int trackId ) :
m_trackId( trackId ),
......@@ -53,7 +54,7 @@ TrackWorkflow::~TrackWorkflow()
void TrackWorkflow::addClip( Clip* clip, qint64 start )
{
ClipWorkflow* cw = new ClipWorkflow( clip );
ClipWorkflow* cw = new VideoClipWorkflow( clip );
addClip( cw, start );
}
......@@ -452,7 +453,7 @@ void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
// qDebug() << "Clip [" << QObject::sender() << "] render is completed on track" << m_trackId;
if ( cw != NULL )
{
m_synchroneRenderBuffer = cw->getOutput();
m_synchroneRenderBuffer = reinterpret_cast<unsigned char*>( cw->getOutput() );
}
else
{
......
......@@ -24,6 +24,46 @@
VideoClipWorkflow::VideoClipWorkflow( Clip* clip ) : ClipWorkflow( clip )
{
m_buffer = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4];
}
VideoClipWorkflow::~VideoClipWorkflow()
{
delete[] m_buffer;
}
void VideoClipWorkflow::initVlcOutput()
{
char buffer[32];
m_vlcMedia->addOption( ":no-audio" );
m_vlcMedia->addOption( ":no-sout-audio" );
m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
m_vlcMedia->setDataCtx( this );
m_vlcMedia->setLockCallback( reinterpret_cast<LibVLCpp::Media::lockCallback>( getLockCallback() ) );
m_vlcMedia->setUnlockCallback( reinterpret_cast<LibVLCpp::Media::unlockCallback>( getUnlockCallback() ) );
m_vlcMedia->addOption( ":sout-transcode-vcodec=RV24" );
m_vlcMedia->addOption( ":sout-transcode-acodec=s16l" );
// m_vlcMedia->addOption( ":no-sout-keep" );
if ( m_fullSpeedRender == true )
{
m_vlcMedia->addOption( ":no-sout-smem-time-sync" );
}
else
m_vlcMedia->addOption( ":sout-smem-time-sync" );
sprintf( buffer, ":sout-transcode-width=%i", VIDEOWIDTH );
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":sout-transcode-height=%i", VIDEOHEIGHT );
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":sout-transcode-fps=%f", (float)FPS );
m_vlcMedia->addOption( buffer );
//sprintf( buffer, "sout-smem-video-pitch=%i", VIDEOWIDTH * 3 );
//m_vlcMedia->addOption( buffer );
}
void* VideoClipWorkflow::getLockCallback()
......@@ -36,6 +76,15 @@ void* VideoClipWorkflow::getUnlockCallback()
return reinterpret_cast<void*>( &VideoClipWorkflow::unlock );
}
void* VideoClipWorkflow::getOutput()
{
QMutexLocker lock( m_renderLock );
if ( isEndReached() == true )
return NULL;
return m_buffer;
}
void VideoClipWorkflow::lock( VideoClipWorkflow* cw, void** pp_ret, int size )
{
Q_UNUSED( size );
......
......@@ -30,10 +30,14 @@ class VideoClipWorkflow : public ClipWorkflow
{
public:
VideoClipWorkflow( Clip* clip );
~VideoClipWorkflow();
void* getLockCallback();
void* getUnlockCallback();
virtual void* getOutput();
private:
unsigned char* m_buffer;
void initVlcOutput();
static void lock( VideoClipWorkflow* clipWorkflow, void** pp_ret, int size );
static void unlock( VideoClipWorkflow* clipWorkflow, void* buffer, int width, int height, int bpp, int size );
};
......
......@@ -33,7 +33,6 @@ SOURCES += src/main.cpp \
src/GUI/MediaListWidget.cpp \
src/Media/Clip.cpp \
src/GUI/About.cpp \
# src/GUI/Transcode.cpp \
src/GUI/Slider.cpp \
src/Metadata/MetaDataWorker.cpp \
src/Library/Library.cpp \
......@@ -64,7 +63,8 @@ SOURCES += src/main.cpp \
src/GUI/VLMCPreferences.cpp \
src/GUI/VideoProjectPreferences.cpp \
src/Project/ProjectManager.cpp \
src/Configuration/SettingsManager.cpp
src/Configuration/SettingsManager.cpp \
src/Workflow/VideoClipWorkflow.cpp
HEADERS += src/GUI/MainWindow.h \
src/GUI/DockWidgetManager.h \
src/GUI/LibraryWidget.h \
......@@ -83,7 +83,6 @@ HEADERS += src/GUI/MainWindow.h \
src/Media/Clip.h \
src/GUI/MediaListWidget.h \
src/GUI/About.h \
# src/GUI/Transcode.h \
src/GUI/Slider.h \
src/Metadata/MetaDataWorker.h \
src/Tools/Singleton.hpp \
......@@ -121,14 +120,14 @@ HEADERS += src/GUI/MainWindow.h \
src/GUI/AudioProjectPreferences.h \
src/GUI/VideoProjectPreferences.h \
src/Project/ProjectManager.h \
src/Configuration/SettingsManager.h
src/Configuration/SettingsManager.h \
src/Workflow/VideoClipWorkflow.h
FORMS += src/GUI/ui/MainWindow.ui \
src/GUI/ui/PreviewWidget.ui \
src/GUI/ui/LanguagePreferences.ui \
src/GUI/ui/Timeline.ui \
src/GUI/ui/LibraryWidget.ui \
src/GUI/ui/About.ui \
# src/GUI/ui/Transcode.ui \
src/GUI/ui/FileBrowser.ui \
src/GUI/ui/WorkflowFileRendererDialog.ui \
src/GUI/ui/ClipProperty.ui \
......
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