ImageClipWorkflow.cpp 3.83 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 25
#include <QMutex>
#include <QReadWriteLock>

26
#include "ImageClipWorkflow.h"
27
#include "Clip.h"
28
#include "ClipHelper.h"
29
#include "ISource.h"
30
#include "ISourceRenderer.h"
31
#include "MainWorkflow.h"
32
#include "Media.h"
33
#include "SettingsManager.h"
34
#include "Workflow/Types.h"
35

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

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

53
void ImageClipWorkflow::initializeInternals()
54
{
55 56 57 58 59
    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" );
60 61 62

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

66 67
void
ImageClipWorkflow::preallocate()
68 69 70 71
{

}

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

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

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

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

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

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

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

void
ImageClipWorkflow::stopComputation()
{
127
    m_renderer->stop();
128 129
}

130 131 132 133
void
ImageClipWorkflow::flushComputedBuffers()
{
}