Commit 78e3258c authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactoring video resolution handling.

Width and height are now handled by the renderer.
parent 5980ad00
...@@ -84,7 +84,7 @@ void WorkflowFileRenderer::run() ...@@ -84,7 +84,7 @@ void WorkflowFileRenderer::run()
m_audioPts = 0; m_audioPts = 0;
m_mainWorkflow->setFullSpeedRender( true ); m_mainWorkflow->setFullSpeedRender( true );
m_mainWorkflow->startRender(); m_mainWorkflow->startRender( width(), height() );
m_mediaPlayer->play(); m_mediaPlayer->play();
} }
...@@ -147,3 +147,19 @@ void* WorkflowFileRenderer::getUnlockCallback() ...@@ -147,3 +147,19 @@ void* WorkflowFileRenderer::getUnlockCallback()
{ {
return (void*)&WorkflowFileRenderer::unlock; return (void*)&WorkflowFileRenderer::unlock;
} }
quint32
WorkflowFileRenderer::width() const
{
const SettingValue *width = SettingsManager::getInstance()->getValue( "project",
"VideoProjectWidth" );
return width->get().toUInt();
}
quint32
WorkflowFileRenderer::height() const
{
const SettingValue *height = SettingsManager::getInstance()->getValue( "project",
"VideoProjectHeight" );
return height->get().toUInt();
}
...@@ -53,7 +53,8 @@ private: ...@@ -53,7 +53,8 @@ private:
protected: protected:
virtual void* getLockCallback(); virtual void* getLockCallback();
virtual void* getUnlockCallback(); virtual void* getUnlockCallback();
virtual quint32 width() const;
virtual quint32 height() const;
private slots: private slots:
void stop(); void stop();
void cancelButtonClicked(); void cancelButtonClicked();
......
...@@ -40,20 +40,14 @@ quint8* WorkflowRenderer::silencedAudioBuffer = NULL; ...@@ -40,20 +40,14 @@ quint8* WorkflowRenderer::silencedAudioBuffer = NULL;
WorkflowRenderer::WorkflowRenderer() : WorkflowRenderer::WorkflowRenderer() :
m_mainWorkflow( MainWorkflow::getInstance() ), m_mainWorkflow( MainWorkflow::getInstance() ),
m_stopping( false ), m_stopping( false ),
m_oldLength( 0 ) m_oldLength( 0 ),
m_renderVideoFrame( NULL ),
m_media( NULL )
{ {
} }
void WorkflowRenderer::initializeRenderer() void WorkflowRenderer::initializeRenderer()
{ {
char videoString[512];
char inputSlave[256];
char audioParameters[256];
char callbacks[64];
m_renderVideoFrame = new unsigned char[m_mainWorkflow->getWidth()
* m_mainWorkflow->getHeight() * Pixel::NbComposantes];
m_videoEsHandler = new EsHandler; m_videoEsHandler = new EsHandler;
m_videoEsHandler->self = this; m_videoEsHandler->self = this;
m_videoEsHandler->type = Video; m_videoEsHandler->type = Video;
...@@ -64,23 +58,6 @@ void WorkflowRenderer::initializeRenderer() ...@@ -64,23 +58,6 @@ void WorkflowRenderer::initializeRenderer()
m_nbChannels = 2; m_nbChannels = 2;
m_rate = 48000; m_rate = 48000;
sprintf( videoString, "width=%i:height=%i:dar=%s:fps=%s:data=%lld:codec=%s:cat=2:caching=0",
m_mainWorkflow->getWidth(), m_mainWorkflow->getHeight(), "16/9", "30/1",
(qint64)m_videoEsHandler, "RV24" );
sprintf( audioParameters, "data=%lld:cat=1:codec=fl32:samplerate=%u:channels=%u:caching=0",
(qint64)m_audioEsHandler, m_rate, m_nbChannels );
strcpy( inputSlave, ":input-slave=imem://" );
strcat( inputSlave, audioParameters );
m_media = new LibVLCpp::Media( "imem://" + QString( videoString ) );
m_media->addOption( inputSlave );
sprintf( callbacks, "imem-get=%lld", (qint64)getLockCallback() );
m_media->addOption( callbacks );
sprintf( callbacks, ":imem-release=%lld", (qint64)getUnlockCallback() );
m_media->addOption( callbacks );
m_media->addOption( ":text-renderer dummy" );
//Workflow part //Workflow part
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) ); connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( frameChanged( qint64, MainWorkflow::FrameChangedReason ) ), connect( m_mainWorkflow, SIGNAL( frameChanged( qint64, MainWorkflow::FrameChangedReason ) ),
...@@ -98,6 +75,40 @@ WorkflowRenderer::~WorkflowRenderer() ...@@ -98,6 +75,40 @@ WorkflowRenderer::~WorkflowRenderer()
delete m_media; delete m_media;
} }
void
WorkflowRenderer::setupRenderer()
{
char videoString[512];
char inputSlave[256];
char audioParameters[256];
char callbacks[64];
quint32 width = this->width();
quint32 height = this->height();
if ( m_renderVideoFrame != NULL )
delete m_renderVideoFrame;
m_renderVideoFrame = new unsigned char[width * height * Pixel::NbComposantes];
sprintf( videoString, "width=%i:height=%i:dar=%s:fps=%s:data=%lld:codec=%s:cat=2:caching=0",
width, height, "16/9", "30/1",
(qint64)m_videoEsHandler, "RV24" );
sprintf( audioParameters, "data=%lld:cat=1:codec=fl32:samplerate=%u:channels=%u:caching=0",
(qint64)m_audioEsHandler, m_rate, m_nbChannels );
strcpy( inputSlave, ":input-slave=imem://" );
strcat( inputSlave, audioParameters );
if ( m_media != NULL )
delete m_media;
m_media = new LibVLCpp::Media( "imem://" + QString( videoString ) );
m_media->addOption( inputSlave );
sprintf( callbacks, "imem-get=%lld", (qint64)getLockCallback() );
m_media->addOption( callbacks );
sprintf( callbacks, ":imem-release=%lld", (qint64)getUnlockCallback() );
m_media->addOption( callbacks );
m_media->addOption( ":text-renderer dummy" );
}
int int
WorkflowRenderer::lock( void *datas, qint64 *dts, qint64 *pts, quint32 *flags, WorkflowRenderer::lock( void *datas, qint64 *dts, qint64 *pts, quint32 *flags,
size_t *bufferSize, void **buffer ) size_t *bufferSize, void **buffer )
...@@ -198,6 +209,7 @@ void WorkflowRenderer::startPreview() ...@@ -198,6 +209,7 @@ void WorkflowRenderer::startPreview()
{ {
if ( m_mainWorkflow->getLengthFrame() <= 0 ) if ( m_mainWorkflow->getLengthFrame() <= 0 )
return ; return ;
setupRenderer();
m_mediaPlayer->setMedia( m_media ); m_mediaPlayer->setMedia( m_media );
//Media player part: to update PreviewWidget //Media player part: to update PreviewWidget
...@@ -212,7 +224,7 @@ void WorkflowRenderer::startPreview() ...@@ -212,7 +224,7 @@ void WorkflowRenderer::startPreview()
(*MainWorkflow::blackOutput)->nboctets ); (*MainWorkflow::blackOutput)->nboctets );
m_mainWorkflow->setFullSpeedRender( false ); m_mainWorkflow->setFullSpeedRender( false );
m_mainWorkflow->startRender(); m_mainWorkflow->startRender( width(), height() );
m_isRendering = true; m_isRendering = true;
m_paused = false; m_paused = false;
m_stopping = false; m_stopping = false;
...@@ -327,6 +339,22 @@ void* WorkflowRenderer::getUnlockCallback() ...@@ -327,6 +339,22 @@ void* WorkflowRenderer::getUnlockCallback()
return (void*)&WorkflowRenderer::unlock; return (void*)&WorkflowRenderer::unlock;
} }
quint32
WorkflowRenderer::width() const
{
const SettingValue *width = SettingsManager::getInstance()->getValue( "project",
"VideoProjectWidth" );
return width->get().toUInt();
}
quint32
WorkflowRenderer::height() const
{
const SettingValue *height = SettingsManager::getInstance()->getValue( "project",
"VideoProjectHeight" );
return height->get().toUInt();
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
/////SLOTS : /////SLOTS :
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
......
...@@ -83,6 +83,8 @@ class WorkflowRenderer : public GenericRenderer ...@@ -83,6 +83,8 @@ class WorkflowRenderer : public GenericRenderer
* forcePause is false. * forcePause is false.
* \param forcePause Will force the pause if true. * \param forcePause Will force the pause if true.
* \sa stop() * \sa stop()
* \warning Do NOT call this method from a constructor as it calls some
* virtual methods.
*/ */
virtual void togglePlayPause( bool forcePause ); virtual void togglePlayPause( bool forcePause );
/** /**
...@@ -207,6 +209,28 @@ class WorkflowRenderer : public GenericRenderer ...@@ -207,6 +209,28 @@ class WorkflowRenderer : public GenericRenderer
* \param buffer The buffer to be released * \param buffer The buffer to be released
*/ */
static void unlock( void *data, size_t buffSize, void *buffer ); static void unlock( void *data, size_t buffSize, void *buffer );
/**
* \brief Return the renderer specific width
*
* The render width can changed depending on the render target.
* This getter will be used to initialized the MainWorkflow with the
* appropriate width.
* \return The video width for the underlying WorkflowRenderer
*/
virtual quint32 width() const;
/**
* \brief Return the renderer specific height
*
* The render width can changed depending on the render target.
* This getter will be used to initialized the MainWorkflow with the
* appropriate height.
* \return The video height for the underlying WorkflowRenderer
*/
virtual quint32 height() const;
/**
* \brief Configure the production chain.
*/
void setupRenderer();
protected: protected:
MainWorkflow* m_mainWorkflow; MainWorkflow* m_mainWorkflow;
......
...@@ -39,22 +39,13 @@ LightVideoFrame *MainWorkflow::blackOutput = NULL; ...@@ -39,22 +39,13 @@ LightVideoFrame *MainWorkflow::blackOutput = NULL;
MainWorkflow::MainWorkflow( int trackCount ) : MainWorkflow::MainWorkflow( int trackCount ) :
m_lengthFrame( 0 ), m_lengthFrame( 0 ),
m_renderStarted( false ) m_renderStarted( false ),
m_width( 0 ),
m_height( 0 )
{ {
m_currentFrameLock = new QReadWriteLock; m_currentFrameLock = new QReadWriteLock;
m_renderStartedMutex = new QMutex; m_renderStartedMutex = new QMutex;
const SettingValue *width = SettingsManager::getInstance()->getValue( "project",
"VideoProjectWidth" );
connect( width, SIGNAL( changed( QVariant ) ),
this, SLOT( widthChanged( QVariant ) ) );
m_width = width->get().toUInt();
const SettingValue *height = SettingsManager::getInstance()->getValue( "project",
"VideoProjectHeight" );
connect( height, SIGNAL( changed( QVariant ) ),
this, SLOT( widthChanged( QVariant ) ) );
m_height = height->get().toUInt();
m_effectEngine = new EffectsEngine; m_effectEngine = new EffectsEngine;
m_effectEngine->disable(); m_effectEngine->disable();
...@@ -125,9 +116,11 @@ MainWorkflow::computeLength() ...@@ -125,9 +116,11 @@ MainWorkflow::computeLength()
} }
void void
MainWorkflow::startRender() MainWorkflow::startRender( quint32 width, quint32 height )
{ {
m_renderStarted = true; m_renderStarted = true;
m_width = width;
m_height = height;
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i ) for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->startRender(); m_tracks[i]->startRender();
computeLength(); computeLength();
...@@ -433,27 +426,17 @@ MainWorkflow::getCurrentFrame() const ...@@ -433,27 +426,17 @@ MainWorkflow::getCurrentFrame() const
return m_currentFrame[MainWorkflow::VideoTrack]; return m_currentFrame[MainWorkflow::VideoTrack];
} }
void
MainWorkflow::widthChanged( const QVariant &width )
{
m_width = width.toUInt();
}
void
MainWorkflow::heightChanged( const QVariant &height )
{
m_height = height.toUInt();
}
quint32 quint32
MainWorkflow::getWidth() const MainWorkflow::getWidth() const
{ {
Q_ASSERT( m_width != 0 );
return m_width; return m_width;
} }
quint32 quint32
MainWorkflow::getHeight() const MainWorkflow::getHeight() const
{ {
Q_ASSERT( m_height != 0 );
return m_height; return m_height;
} }
......
...@@ -105,9 +105,11 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow> ...@@ -105,9 +105,11 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
/** /**
* \brief Initialize the workflow for the render. * \brief Initialize the workflow for the render.
* *
* \param width The width to use with this render session.
* \param height The height to use with this render session.
* This will basically activate all the tracks, so they can render. * This will basically activate all the tracks, so they can render.
*/ */
void startRender(); void startRender( quint32 width, quint32 height );
/** /**
* \brief Gets a frame from the workflow * \brief Gets a frame from the workflow
* *
...@@ -401,19 +403,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow> ...@@ -401,19 +403,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* \sa mainWorkflowEndReached() * \sa mainWorkflowEndReached()
*/ */
void tracksEndReached(); void tracksEndReached();
/**
* \brief Called when the width is changed in the preferences
* \todo The value is immediatly changed, which is wrong.
* See issue : http://vlmc.org/issues/show/118
*/
void widthChanged( const QVariant& );
/**
* \brief Called when the height is changed in the preferences
* \todo The value is immediatly changed, which is wrong.
* See issue : http://vlmc.org/issues/show/118
*/
void heightChanged( const QVariant& );
public slots: public slots:
/** /**
......
...@@ -33,11 +33,6 @@ VideoClipWorkflow::VideoClipWorkflow( Clip *clip ) : ...@@ -33,11 +33,6 @@ VideoClipWorkflow::VideoClipWorkflow( Clip *clip ) :
ClipWorkflow( clip ), ClipWorkflow( clip ),
m_lastRenderedFrame( NULL ) m_lastRenderedFrame( NULL )
{ {
for ( unsigned int i = 0; i < VideoClipWorkflow::nbBuffers; ++i )
{
m_availableBuffers.enqueue( new LightVideoFrame( MainWorkflow::getInstance()->getWidth(),
MainWorkflow::getInstance()->getHeight() ) );
}
debugType = 2; debugType = 2;
} }
...@@ -49,6 +44,16 @@ VideoClipWorkflow::~VideoClipWorkflow() ...@@ -49,6 +44,16 @@ VideoClipWorkflow::~VideoClipWorkflow()
delete m_computedBuffers.dequeue(); delete m_computedBuffers.dequeue();
} }
void
VideoClipWorkflow::preallocate()
{
for ( unsigned int i = 0; i < VideoClipWorkflow::nbBuffers; ++i )
{
m_availableBuffers.enqueue( new LightVideoFrame( MainWorkflow::getInstance()->getWidth(),
MainWorkflow::getInstance()->getHeight() ) );
}
}
void void
VideoClipWorkflow::initVlcOutput() VideoClipWorkflow::initVlcOutput()
{ {
...@@ -74,6 +79,7 @@ VideoClipWorkflow::initVlcOutput() ...@@ -74,6 +79,7 @@ VideoClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( buffer ); m_vlcMedia->addOption( buffer );
sprintf( buffer, ":sout-transcode-fps=%f", (float)Clip::DefaultFPS ); sprintf( buffer, ":sout-transcode-fps=%f", (float)Clip::DefaultFPS );
m_vlcMedia->addOption( buffer ); m_vlcMedia->addOption( buffer );
preallocate();
} }
void* void*
......
...@@ -60,16 +60,22 @@ class VideoClipWorkflow : public ClipWorkflow ...@@ -60,16 +60,22 @@ class VideoClipWorkflow : public ClipWorkflow
virtual quint32 getMaxComputedBuffers() const; virtual quint32 getMaxComputedBuffers() const;
void releaseBuffer( LightVideoFrame* lvf ); void releaseBuffer( LightVideoFrame* lvf );
void flushComputedBuffers(); void flushComputedBuffers();
/**
* \brief Pre-allocate some image buffers.
*/
void preallocate();
private: private:
QQueue<LightVideoFrame*> m_computedBuffers; QQueue<LightVideoFrame*> m_computedBuffers;
QQueue<LightVideoFrame*> m_availableBuffers; QQueue<LightVideoFrame*> m_availableBuffers;
LightVideoFrame *m_lastRenderedFrame; LightVideoFrame *m_lastRenderedFrame;
static void lock( VideoClipWorkflow* clipWorkflow, void** pp_ret, static void lock( VideoClipWorkflow* clipWorkflow, void** pp_ret,
int size ); int size );
static void unlock( VideoClipWorkflow* clipWorkflow, void* buffer, static void unlock( VideoClipWorkflow* clipWorkflow, void* buffer,
int width, int height, int bpp, int size, int width, int height, int bpp, int size,
qint64 pts ); qint64 pts );
quint32 m_width;
quint32 m_height;
}; };
#endif // VIDEOCLIPWORKFLOW_H #endif // VIDEOCLIPWORKFLOW_H
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