Commit 081d44af authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored WorkflowFileRenderer

This class isn't a QDialog anymore, and inherits WorkflowRender
parent f5a42a36
#include "WorkflowFileRenderer.h"
WorkflowFileRenderer::WorkflowFileRenderer( QWidget* parent, const QString& outputFileName ) :
QDialog( parent ), m_outputFileName( outputFileName )
WorkflowFileRenderer::WorkflowFileRenderer( const QString& outputFileName ) :
m_outputFileName( outputFileName )
{
m_ui.setupUi( this );
m_ui.nameLabel->setText( outputFileName );
m_dialog = new WorkflowFileRendererDialog;
m_dialog->setOutputFileName( outputFileName );
m_mediaPlayer = new LibVLCpp::MediaPlayer;
m_mainWorkflow = MainWorkflow::getInstance();
}
WorkflowFileRenderer::~WorkflowFileRenderer()
{
delete m_mediaPlayer;
}
void* WorkflowFileRenderer::lock( void* datas )
{
WorkflowFileRenderer* self = reinterpret_cast<WorkflowFileRenderer*>( datas );
return self->m_mainWorkflow->getSynchroneOutput();
}
void WorkflowFileRenderer::unlock( void* )
{
}
void WorkflowFileRenderer::run()
{
m_media = new LibVLCpp::Media( "fake://" );
char buffer[256];
sprintf( buffer, ":invmem-width=%i", VIDEOWIDTH );
m_media->addOption( ":codec=invmem" );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-height=%i", VIDEOHEIGHT );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-lock=%lld", (qint64)WorkflowFileRenderer::lock );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-unlock=%lld", (qint64)WorkflowFileRenderer::unlock );
m_media->addOption( buffer );
sprintf( buffer, ":invmem-data=%lld", (qint64)this );
m_media->addOption( buffer );
//Media as already been created an mainly initialized by the WorkflowRenderer
m_media->addOption( ":no-audio" );
m_media->addOption( ":fake" );
sprintf(buffer, ":fake-duration=%lli", m_mainWorkflow->getLength() );
// m_media->addOption( buffer );
QString transcodeStr = "sout=#transcode{vcodec=mp4v,vb=800,acodec=mpga,ab=128}"
QString transcodeStr = "sout=#transcode{vcodec=mp4v,vb=800,acodec=mpga,ab=128" +
QString::number( FPS ) + "}"
":standard{access=file,mux=ps,dst=\""
+ m_outputFileName + "\"}";
m_media->addOption( transcodeStr.toStdString().c_str() );
sprintf( buffer, ":fake-duration=%lli", m_mainWorkflow->getLength() / FPS * 1000 );
m_media->addOption( buffer );
m_mediaPlayer->setMedia( m_media );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( stop() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( stop() ) );
connect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( positionChanged( float ) ) );
show();
m_dialog->show();
m_mainWorkflow->startRender();
m_mediaPlayer->play();
......@@ -64,17 +44,14 @@ void WorkflowFileRenderer::run()
void WorkflowFileRenderer::stop()
{
disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( stop() ) );
disconnect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( stop() ) );
m_mainWorkflow->stop();
m_mediaPlayer->stop();
done( 0 );
qDebug() << "Stopping file renderer";
WorkflowRenderer::stop();
m_dialog->done( 0 );
}
void WorkflowFileRenderer::positionChanged( float newPos )
{
m_ui.progressBar->setValue( static_cast<int>( newPos * 100 ) );
m_dialog->setProgressBarValue( static_cast<int>( newPos * 100 ) );
}
void WorkflowFileRenderer::on_cancelButton_clicked()
......
......@@ -23,19 +23,18 @@
#ifndef WORKFLOWFILERENDERER_H
#define WORKFLOWFILERENDERER_H
#include <QDialog>
#include "VLCMediaPlayer.h"
#include "Workflow/MainWorkflow.h"
#include "ui_WorkflowFileRenderer.h"
#include "WorkflowRenderer.h"
#include "WorkflowFileRendererDialog.h"
class WorkflowFileRenderer : public QDialog
class WorkflowFileRenderer : public WorkflowRenderer
{
Q_OBJECT
Q_DISABLE_COPY( WorkflowFileRenderer )
public:
WorkflowFileRenderer( QWidget* parent, const QString& outputFileName );
WorkflowFileRenderer( const QString& outputFileName );
virtual ~WorkflowFileRenderer();
static void* lock( void* datas );
......@@ -43,11 +42,8 @@ public:
void run();
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
LibVLCpp::Media* m_media;
MainWorkflow* m_mainWorkflow;
const QString m_outputFileName;
Ui::WorkflowFileRenderer m_ui;
WorkflowFileRendererDialog* m_dialog;
private slots:
void stop();
......
......@@ -161,7 +161,7 @@ void MainWindow::initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea );
m_projectPreview = new PreviewWidget( new WorkflowRenderer( m_timeline->getMainWorkflow() ), this );
m_projectPreview = new PreviewWidget( new WorkflowRenderer(), this );
dockManager->addDockedWidget( m_projectPreview,
tr( "Project Preview" ),
Qt::AllDockWidgetAreas,
......@@ -215,7 +215,7 @@ void MainWindow::on_actionRender_triggered()
{
if ( m_renderer )
delete m_renderer;
m_renderer = new WorkflowFileRenderer( this, outputFileName );
m_renderer = new WorkflowFileRenderer( outputFileName );
m_renderer->run();
}
}
......
......@@ -40,7 +40,6 @@ public:
TracksView* tracksView() { return m_tracksView; }
TracksScene* tracksScene() { return m_tracksScene; }
TracksRuler* tracksRuler() { return m_tracksRuler; }
MainWorkflow* getMainWorkflow() { return m_mainWorkflow; }
static Timeline* getInstance() { return m_instance; }
public slots:
......
#include "WorkflowFileRendererDialog.h"
WorkflowFileRendererDialog::WorkflowFileRendererDialog()
{
m_ui.setupUi( this );
}
void WorkflowFileRendererDialog::setOutputFileName( const QString& outputFileName )
{
m_ui.nameLabel->setText( outputFileName );
setWindowTitle( "Rendering to " + outputFileName );
}
void WorkflowFileRendererDialog::setProgressBarValue( int val )
{
m_ui.progressBar->setValue( val );
}
/*****************************************************************************
* WorkflowFileRenderer.h: Output the workflow to a file
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef WORKFLOWFILERENDERERDIALOG_H
#define WORKFLOWFILERENDERERDIALOG_H
#include <QDialog>
#include "ui_WorkflowFileRendererDialog.h"
class WorkflowFileRendererDialog : public QDialog
{
Q_OBJECT
Q_DISABLE_COPY( WorkflowFileRendererDialog );
public:
WorkflowFileRendererDialog();
void setOutputFileName( const QString& filename );
void setProgressBarValue( int val );
private:
Ui::WorkflowFileRendererDialog m_ui;
};
#endif // WORKFLOWFILERENDERERDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WorkflowFileRenderer</class>
<widget class="QDialog" name="WorkflowFileRenderer">
<class>WorkflowFileRendererDialog</class>
<widget class="QDialog" name="WorkflowFileRendererDialog">
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -27,8 +27,8 @@
#include "WorkflowRenderer.h"
#include "Timeline.h"
WorkflowRenderer::WorkflowRenderer( MainWorkflow* mainWorkflow ) :
m_mainWorkflow( mainWorkflow ),
WorkflowRenderer::WorkflowRenderer() :
m_mainWorkflow( MainWorkflow::getInstance() ),
m_pauseAsked( false ),
m_unpauseAsked( false ),
m_stopping( false )
......@@ -54,14 +54,6 @@ WorkflowRenderer::WorkflowRenderer( MainWorkflow* mainWorkflow ) :
sprintf( buffer, ":height=%i", VIDEOHEIGHT );
m_media->addOption( buffer );
m_mediaPlayer->setMedia( m_media );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( __positionChanged( float ) ) );
m_condMutex = new QMutex;
m_waitCond = new QWaitCondition;
}
......@@ -71,6 +63,7 @@ WorkflowRenderer::~WorkflowRenderer()
{
stop();
//FIXME this is probably useless...
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ) );
disconnect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ) );
disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
......@@ -140,6 +133,9 @@ void WorkflowRenderer::startPreview()
{
char buff[128];
m_mediaPlayer->setMedia( m_media );
//Workflow part
connect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
Timeline::getInstance()->tracksView()->tracksCursor(), SLOT( updateCursorPos( qint64 ) ) );
connect( Timeline::getInstance()->tracksView()->tracksCursor(), SIGNAL( cursorPositionChanged( qint64 ) ),
......@@ -147,6 +143,13 @@ void WorkflowRenderer::startPreview()
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowUnpaused() ), this, SLOT( mainWorkflowUnpaused() ) );
//Media player part: to update PreviewWidget
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoStopped() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( __positionChanged( float ) ) );
m_mainWorkflow->startRender();
sprintf( buff, ":fake-duration=%lli", m_mainWorkflow->getLength() / FPS * 1000 );
m_media->addOption( buff );
......
......@@ -42,7 +42,7 @@ class WorkflowRenderer : public GenericRenderer
Pause,
//Unpause,
};
WorkflowRenderer( MainWorkflow* mainWorkflow );
WorkflowRenderer();
~WorkflowRenderer();
void stopPreview();
......@@ -69,9 +69,10 @@ class WorkflowRenderer : public GenericRenderer
virtual void startPreview();
void checkActions();
private:
protected:
MainWorkflow* m_mainWorkflow;
LibVLCpp::Media* m_media;
private:
unsigned char* m_lastFrame;
QStack<Actions> m_actions;
QReadWriteLock* m_actionsLock;
......
......@@ -48,7 +48,8 @@ SOURCES += src/main.cpp \
src/WorkflowFileRenderer.cpp \
src/UndoStack.cpp \
src/metadata/MetaDataManager.cpp \
src/gui/ClipProperty.cpp
src/gui/ClipProperty.cpp \
src/gui/WorkflowFileRendererDialog.cpp
HEADERS += src/gui/MainWindow.h \
src/gui/DockWidgetManager.h \
src/gui/LibraryWidget.h \
......@@ -97,7 +98,8 @@ HEADERS += src/gui/MainWindow.h \
src/metadata/MetaDataManager.h \
src/commands/Commands.hpp \
src/tools/QSingleton.hpp \
src/gui/ClipProperty.h
src/gui/ClipProperty.h \
src/gui/WorkflowFileRendererDialog.h
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
......@@ -106,9 +108,8 @@ FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/About.ui \
src/gui/ui/Transcode.ui \
src/gui/ui/FileBrowser.ui \
src/gui/ui/WorkflowFileRenderer.ui \
src/gui/ui/WorkflowFileRendererDialog.ui \
src/gui/ui/ClipProperty.ui
TRANSLATIONS = ts/vlmc_es.ts \
ts/vlmc_fr.ts \
ts/vlmc_sv.ts
......
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