ImageClipWorkflow.cpp 4 KB
Newer Older
1 2 3
/*****************************************************************************
 * ImageClipWorkflow.cpp : Will extract a frame from an image
 *****************************************************************************
4
 * Copyright (C) 2008-2014 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
 *
 * 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 "ImageClipWorkflow.h"
28
#include "Media/Clip.h"
29
#include "ClipHelper.h"
30 31
#include "Backend/ISource.h"
#include "Backend/ISourceRenderer.h"
32
#include "MainWorkflow.h"
33 34
#include "Media/Media.h"
#include "Settings/SettingsManager.h"
35
#include "Workflow/Types.h"
36

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

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

54
void ImageClipWorkflow::initializeInternals()
55
{
56
    m_renderer->setName( qPrintable( QString("ImageClipWorkflow " % m_clipHelper->uuid().toString() ) ) );
57 58 59 60 61
    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" );
62 63 64

    m_effectFrame->resize( MainWorkflow::getInstance()->getWidth(),
                            MainWorkflow::getInstance()->getHeight() );
65
    m_isRendering = true;
66
}
67

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

}

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

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

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

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

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

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

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

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

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