ImageClipWorkflow.cpp 4.14 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 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

#include "ImageClipWorkflow.h"
24
#include "Clip.h"
25
#include "LightVideoFrame.h"
26
#include "MainWorkflow.h"
27
#include "VLCMediaPlayer.h"
28

29
ImageClipWorkflow::ImageClipWorkflow( Clip *clip ) :
30
        ClipWorkflow( clip ),
31 32
        m_buffer( NULL ),
        m_stackedBuffer( NULL )
33
{
34 35 36 37
    //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 );
38 39
}

40 41
void
ImageClipWorkflow::initVlcOutput()
42 43 44
{
    char    buffer[32];

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    m_vlcMedia->addOption( ":no-audio" );
    m_vlcMedia->addOption( ":no-sout-audio" );
    m_vlcMedia->addOption( ":sout=#transcode{}:smem" );
    m_vlcMedia->setVideoDataCtx( this );
    m_vlcMedia->setVideoLockCallback( reinterpret_cast<void*>( getLockCallback() ) );
    m_vlcMedia->setVideoUnlockCallback( reinterpret_cast<void*>( getUnlockCallback() ) );
    m_vlcMedia->addOption( ":sout-transcode-vcodec=RV24" );
    m_vlcMedia->addOption( ":sout-smem-time-sync" );

    sprintf( buffer, ":sout-transcode-width=%i",
             MainWorkflow::getInstance()->getWidth() );
    m_vlcMedia->addOption( buffer );
    sprintf( buffer, ":sout-transcode-height=%i",
             MainWorkflow::getInstance()->getHeight() );
    m_vlcMedia->addOption( buffer );
    sprintf( buffer, ":sout-transcode-fps=%f", (float)Clip::DefaultFPS );
    m_vlcMedia->addOption( buffer );
62
    sprintf( buffer, ":fake-duration=%d", 1000 );
63 64 65 66
    m_vlcMedia->addOption( buffer );
    sprintf( buffer, ":fake-fps=%f", m_clip->getParent()->getFps() );
    m_vlcMedia->addOption( buffer );
}
67 68

void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
69
ImageClipWorkflow::getLockCallback() const
70 71 72 73 74
{
    return reinterpret_cast<void*>( &ImageClipWorkflow::lock );
}

void*
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
75
ImageClipWorkflow::getUnlockCallback() const
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
{
    return reinterpret_cast<void*>( &ImageClipWorkflow::unlock );
}

void*
ImageClipWorkflow::getOutput( ClipWorkflow::GetMode )
{
    QMutexLocker    lock( m_renderLock );

    return m_stackedBuffer;
}

void
ImageClipWorkflow::lock(ImageClipWorkflow *cw, void **pp_ret, int size )
{
    cw->m_renderLock->lock();
    if ( cw->m_buffer == NULL )
    {
        cw->m_buffer = new LightVideoFrame( size );
        cw->m_stackedBuffer = new StackedBuffer( cw->m_buffer );
    }
    *pp_ret = (*(cw->m_buffer))->frame.octets;
}

void
ImageClipWorkflow::unlock(ImageClipWorkflow *cw, void *buffer, int width, int height, int bpp, int size, qint64 pts)
{
    cw->m_renderLock->unlock();
    cw->emit computedFinished();
}

uint32_t
ImageClipWorkflow::getNbComputedBuffers() const
{
    QMutexLocker    lock( m_renderLock );

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

uint32_t
ImageClipWorkflow::getMaxComputedBuffers() const
{
    return 1;
}

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

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

134 135 136 137 138 139 140 141 142 143
ImageClipWorkflow::StackedBuffer::StackedBuffer( LightVideoFrame *lvf ) :
    ::StackedBuffer<LightVideoFrame*>( lvf, false )
{
}

void
ImageClipWorkflow::StackedBuffer::release()
{
    return ;
}