ImageClipWorkflow.cpp 4.71 KB
Newer Older
1 2 3
/*****************************************************************************
 * ImageClipWorkflow.cpp : Will extract a frame from an image
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

#include "ImageClipWorkflow.h"
24
#include "Clip.h"
25
#include "ClipHelper.h"
26
#include "MainWorkflow.h"
27
#include "Media.h"
28
#include "VLCMediaPlayer.h"
29
#include "VLCMedia.h"
30
#include "Workflow/Types.h"
31

32
#include <QReadWriteLock>
33
#include <QStringBuilder>
34

35 36
ImageClipWorkflow::ImageClipWorkflow( ClipHelper *ch ) :
        ClipWorkflow( ch ),
37
        m_buffer( NULL )
38
{
39 40 41 42
    //This is used to queue the media player stopping, as it can't be asked for
    //from vlc's input thread (well it can but it will deadlock)
    connect( this, SIGNAL( computedFinished() ),
             this, SLOT( stopComputation() ), Qt::QueuedConnection );
43
    m_effectFrame = new Workflow::Frame;
44 45
}

46 47 48
ImageClipWorkflow::~ImageClipWorkflow()
{
    stop();
49
    delete m_effectFrame;
50 51
}

52 53
QString
ImageClipWorkflow::createSoutChain() const
54
{
55
    QString chain = ":sout=#transcode{vcodec=RV32,width=";
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    chain += QString::number( MainWorkflow::getInstance()->getWidth() )
            % ",height="
            % QString::number( MainWorkflow::getInstance()->getHeight() )
            % ",fps="
            % QString::number((float)Clip::DefaultFPS)
            % "}:smem{";
    if ( m_fullSpeedRender == false )
        chain += "time-sync";
    else
        chain += "no-time-sync";
    chain += ",video-data=" % QString::number( reinterpret_cast<intptr_t>( this ) )
            % ",video-prerender-callback="
            % QString::number( reinterpret_cast<intptr_t>( getLockCallback() ) )
            % ",video-postrender-callback="
            % QString::number( reinterpret_cast<intptr_t>( getUnlockCallback() ) )
            % '}';
73
    return chain;
74
}
75

76 77 78 79 80
void ImageClipWorkflow::initializeVlcOutput()
{
    char    buffer[32];
    m_vlcMedia->addOption(":no-audio");
    m_vlcMedia->addOption(":no-sout-audio");
81
    sprintf( buffer, ":fake-duration=%d", 1000 );
82
    m_vlcMedia->addOption( buffer );
83
    sprintf( buffer, ":fake-fps=%f", m_clipHelper->clip()->getMedia()->fps() );
84
    m_vlcMedia->addOption( buffer );
85 86 87

    m_effectFrame->resize( MainWorkflow::getInstance()->getWidth(),
                            MainWorkflow::getInstance()->getHeight() );
88
    m_isRendering = true;
89
}
90 91

void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
92
ImageClipWorkflow::getLockCallback() const
93 94 95 96 97
{
    return reinterpret_cast<void*>( &ImageClipWorkflow::lock );
}

void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
98
ImageClipWorkflow::getUnlockCallback() const
99 100 101 102
{
    return reinterpret_cast<void*>( &ImageClipWorkflow::unlock );
}

103
Workflow::OutputBuffer*
104
ImageClipWorkflow::getOutput( ClipWorkflow::GetMode, qint64 currentFrame )
105 106 107
{
    QMutexLocker    lock( m_renderLock );

108 109
    quint32 *buff = applyFilters( m_buffer, currentFrame,
                                    currentFrame * 1000.0 / clip()->getMedia()->fps() );
110 111 112 113 114
    if ( buff != NULL )
    {
        m_effectFrame->setBuffer( buff );
        return m_effectFrame;
    }
115
    return m_buffer;
116 117 118
}

void
119
ImageClipWorkflow::lock(ImageClipWorkflow *cw, void **pp_ret, int )
120 121 122 123
{
    cw->m_renderLock->lock();
    if ( cw->m_buffer == NULL )
    {
124
        cw->m_buffer = new Workflow::Frame( MainWorkflow::getInstance()->getWidth(),
125
                                            MainWorkflow::getInstance()->getHeight() );
126
    }
127
    *pp_ret = cw->m_buffer->buffer();
128 129 130
}

void
131
ImageClipWorkflow::unlock(ImageClipWorkflow *cw, void*, int, int, int, int, qint64 )
132 133 134 135 136
{
    cw->m_renderLock->unlock();
    cw->emit computedFinished();
}

137
quint32
138 139 140 141 142 143 144 145 146
ImageClipWorkflow::getNbComputedBuffers() const
{
    QMutexLocker    lock( m_renderLock );

    if ( m_buffer != NULL )
        return 1;
    return 0;
}

147
quint32
148 149 150 151 152 153 154 155 156 157 158
ImageClipWorkflow::getMaxComputedBuffers() const
{
    return 1;
}

void
ImageClipWorkflow::stopComputation()
{
    m_mediaPlayer->stop();
}

159 160 161 162
void
ImageClipWorkflow::flushComputedBuffers()
{
}