ImageClipWorkflow.cpp 4.05 KB
Newer Older
1 2 3
/*****************************************************************************
 * ImageClipWorkflow.cpp : Will extract a frame from an image
 *****************************************************************************
4
 * Copyright (C) 2008-2014 VideoLAN
5
 *
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
 *
 * 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.
 *****************************************************************************/

23 24
#include <QMutex>
#include <QReadWriteLock>
25
#include <QStringBuilder>
26

27
#include "Main/Project.h"
28
#include "ImageClipWorkflow.h"
29
#include "Media/Clip.h"
30
#include "ClipHelper.h"
31 32
#include "Backend/ISource.h"
#include "Backend/ISourceRenderer.h"
33
#include "MainWorkflow.h"
34
#include "Media/Media.h"
35
#include "Settings/Settings.h"
36
#include "Workflow/Types.h"
37

38 39
ImageClipWorkflow::ImageClipWorkflow( ClipHelper *ch ) :
        ClipWorkflow( ch ),
40
        m_buffer( NULL )
41
{
42 43 44 45
    //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 );
46
    m_effectFrame = new Workflow::Frame;
47 48
}

49 50 51
ImageClipWorkflow::~ImageClipWorkflow()
{
    stop();
52
    delete m_effectFrame;
53 54
}

55
void ImageClipWorkflow::initializeInternals()
56
{
57
    m_renderer->setName( qPrintable( QString("ImageClipWorkflow " % m_clipHelper->uuid().toString() ) ) );
58 59 60 61 62
    m_renderer->enableVideoOutputToMemory( this, &lock, &unlock, m_fullSpeedRender );
    m_renderer->setOutputWidth( m_width );
    m_renderer->setOutputHeight( m_height );
    m_renderer->setOutputFps( (float)VLMC_PROJECT_GET_DOUBLE( "video/VLMCOutputFPS" ) );
    m_renderer->setOutputVideoCodec( "RV32" );
63

64 65
    m_effectFrame->resize( Project::getInstance()->workflow()->getWidth(),
                            Project::getInstance()->workflow()->getHeight() );
66
    m_isRendering = true;
67
}
68

69 70
void
ImageClipWorkflow::preallocate()
71 72 73 74
{

}

75
Workflow::OutputBuffer*
76
ImageClipWorkflow::getOutput( ClipWorkflow::GetMode, qint64 currentFrame )
77 78 79
{
    QMutexLocker    lock( m_renderLock );

80
    quint32 *buff = applyFilters( m_buffer, currentFrame,
81
                                    currentFrame * 1000.0 / clip()->getMedia()->source()->fps() );
82 83 84 85 86
    if ( buff != NULL )
    {
        m_effectFrame->setBuffer( buff );
        return m_effectFrame;
    }
87
    return m_buffer;
88 89 90
}

void
91
ImageClipWorkflow::lock(void *data, uint8_t **pp_ret, size_t )
92
{
93
    ImageClipWorkflow* cw = reinterpret_cast<ImageClipWorkflow*>( data );
94 95 96
    cw->m_renderLock->lock();
    if ( cw->m_buffer == NULL )
    {
97 98
        cw->m_buffer = new Workflow::Frame( Project::getInstance()->workflow()->getWidth(),
                                            Project::getInstance()->workflow()->getHeight() );
99
    }
100
    *pp_ret = (uint8_t*)cw->m_buffer->buffer();
101 102 103
}

void
104
ImageClipWorkflow::unlock( void* data, uint8_t*, int, int, int, size_t, int64_t )
105
{
106
    ImageClipWorkflow* cw = reinterpret_cast<ImageClipWorkflow*>( data );
107 108 109 110
    cw->m_renderLock->unlock();
    cw->emit computedFinished();
}

111
quint32
112 113 114 115 116 117 118 119 120
ImageClipWorkflow::getNbComputedBuffers() const
{
    QMutexLocker    lock( m_renderLock );

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

121
quint32
122 123 124 125 126 127 128 129
ImageClipWorkflow::getMaxComputedBuffers() const
{
    return 1;
}

void
ImageClipWorkflow::stopComputation()
{
130
    m_renderer->stop();
131 132
}

133 134 135 136
void
ImageClipWorkflow::flushComputedBuffers()
{
}