WorkflowFileRenderer.cpp 4.47 KB
Newer Older
1 2 3
/*****************************************************************************
 * WorkflowFileRenderer.cpp: Output the workflow to a file
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *****************************************************************************/

Ludovic Fauvet's avatar
Ludovic Fauvet committed
23
#include "vlmc.h"
24
#include "WorkflowFileRenderer.h"
25
#include "SettingsManager.h"
26
#include "VLCMedia.h"
27
#include "VLCMediaPlayer.h"
28

29 30
#include <QTime>

31
#ifdef WITH_GUI
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
32
WorkflowFileRenderer::WorkflowFileRenderer() :
33
        WorkflowRenderer(),
34
        m_renderVideoFrame( NULL ),
35
        m_image( NULL )
36 37 38 39 40
{
}

WorkflowFileRenderer::~WorkflowFileRenderer()
{
41
    delete m_image;
42
}
43
#endif
44

45 46 47
void        WorkflowFileRenderer::run( const QString& outputFileName, quint32 width,
                                       quint32 height, double fps, quint32 vbitrate,
                                       quint32 abitrate )
48
{
49
    m_mainWorkflow->setCurrentFrame( 0, Vlmc::Renderer );
50

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
51
    setupRenderer( width, height, fps );
52 53

    //Media as already been created and mainly initialized by the WorkflowRenderer
54 55 56
    QString     transcodeStr = ":sout=#transcode{vcodec=h264,vb=" + QString::number( vbitrate ) +
                               ",acodec=a52,ab=" + QString::number( abitrate ) +
                               ",no-hurry-up}"
57
                               ":standard{access=file,mux=ps,dst=\""
58
                          + outputFileName + "\"}";
59
    m_media->addOption( transcodeStr.toUtf8().constData() );
60

61 62 63
    m_mediaPlayer->setMedia( m_media );

    connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( stop() ) );
64 65
    connect( m_mainWorkflow, SIGNAL( frameChanged( qint64, Vlmc::FrameChangedReason) ),
             this, SLOT( __frameChanged( qint64,Vlmc::FrameChangedReason ) ) );
66

67 68
    m_isRendering = true;
    m_stopping = false;
69 70 71
    m_paused = false;
    m_pts = 0;
    m_audioPts = 0;
72

73
    m_mainWorkflow->setFullSpeedRender( true );
74
    m_mainWorkflow->startRender( width, height, fps );
75
    //Waiting for renderers to preload some frames:
Ludovic Fauvet's avatar
Ludovic Fauvet committed
76
    SleepS( 1 );
77 78 79 80 81
    m_mediaPlayer->play();
}

void    WorkflowFileRenderer::stop()
{
82
    WorkflowRenderer::killRenderer();
83 84
}

85 86 87
void
WorkflowFileRenderer::__endReached()
{
88
    stop();
89
    emit renderComplete();
90
    disconnect();
91 92
}

93 94 95 96
float   WorkflowFileRenderer::getFps() const
{
    return m_outputFps;
}
97

98
int
99
WorkflowFileRenderer::lock( void *datas, const char* cookie, qint64 *dts, qint64 *pts,
100
                            quint32 *flags, size_t *bufferSize, const void **buffer )
101
{
102
    int         ret = WorkflowRenderer::lock( datas, cookie, dts, pts, flags, bufferSize, buffer );
103 104
    EsHandler*  handler = reinterpret_cast<EsHandler*>( datas );
    WorkflowFileRenderer* self = static_cast<WorkflowFileRenderer*>( handler->self );
105

106
#ifdef WITH_GUI
107 108
    if ( self->m_time.isValid() == false ||
        self->m_time.elapsed() >= 1000 )
109
    {
110 111 112 113
        if ( self->m_renderVideoFrame == NULL )
            self->m_renderVideoFrame = new quint8[*bufferSize];
        memcpy( self->m_renderVideoFrame, (uchar*)(*buffer), *bufferSize );
        self->emit imageUpdated( self->m_renderVideoFrame );
114
        self->m_time.restart();
115
    }
116
#endif
117 118 119
    return ret;
}

120
void
121
WorkflowFileRenderer::__frameChanged( qint64 frame, Vlmc::FrameChangedReason )
122
{
123
    emit frameChanged( frame );
124
}
125

126
void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
127
WorkflowFileRenderer::getLockCallback()
128 129 130 131
{
    return (void*)&WorkflowFileRenderer::lock;
}

132
void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
133
WorkflowFileRenderer::getUnlockCallback()
134
{
135
    return (void*)&WorkflowRenderer::unlock;
136
}
137 138 139 140

quint32
WorkflowFileRenderer::width() const
{
141
    return VLMC_PROJECT_GET_UINT( "video/VideoProjectWidth" );
142 143 144 145 146
}

quint32
WorkflowFileRenderer::height() const
{
147
    return VLMC_PROJECT_GET_UINT( "video/VideoProjectHeight" );
148
}