Commit 998a6fd1 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Workflow: Adding a ClipHelper class

This class will hold specific per-clip informations, such as the begin,
end, length, to avoid cloning the entire clip.
parent b8b6dd0c
......@@ -43,6 +43,7 @@ SET(VLMC_SRCS
Tools/WaitCondition.hpp
Workflow/AudioClipWorkflow.cpp
Workflow/ClipWorkflow.cpp
Workflow/ClipHelper.cpp
Workflow/ImageClipWorkflow.cpp
Workflow/MainWorkflow.cpp
Workflow/StackedBuffer.hpp
......
/*****************************************************************************
* ClipHelper.cpp: Contains information about a Clip in the workflow
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-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 "ClipHelper.h"
#include "Clip.h"
ClipHelper::ClipHelper( Clip* clip, qint64 begin /*= -1*/, qint64 end /*= -1*/ ) :
m_clip( clip ),
m_begin( begin ),
m_end( end )
{
if ( begin == -1 )
m_begin = clip->begin();
if ( end == -1 )
m_end = clip->end();
}
void
ClipHelper::setBegin( qint64 begin )
{
if ( begin < m_clip->begin() )
return ;
m_begin = begin;
}
void
ClipHelper::setEnd( qint64 end )
{
if ( end > m_clip->end() )
return ;
m_end = end;
}
qint64
ClipHelper::length() const
{
return m_end - m_begin;
}
/*****************************************************************************
* ClipHelper.h: Contains information about a Clip in the workflow
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-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.
*****************************************************************************/
#ifndef CLIPHELPER_H
#define CLIPHELPER_H
class Clip;
#include <QtGlobal>
class ClipHelper
{
public:
ClipHelper( Clip* clip, qint64 begin = -1, qint64 end = -1 );
Clip* clip()
{
return m_clip;
}
qint64 begin() const
{
return m_begin;
}
void setBegin( qint64 begin );
qint64 end() const
{
return m_end;
}
void setEnd( qint64 end );
/**
* \return The length in frames
*/
qint64 length() const;
private:
Clip* m_clip;
qint64 m_begin;
qint64 m_end;
};
#endif // CLIPHELPER_H
......@@ -22,6 +22,7 @@
#include "vlmc.h"
#include "Clip.h"
#include "ClipHelper.h"
#include "ClipWorkflow.h"
#include "LightVideoFrame.h"
#include "Media.h"
......@@ -36,7 +37,6 @@
ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_mediaPlayer(NULL),
m_clip( clip ),
m_state( ClipWorkflow::Stopped )
{
m_stateLock = new QReadWriteLock;
......@@ -44,6 +44,7 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_renderLock = new QMutex;
m_renderWaitCond = new QWaitCondition;
m_uuid = QUuid::createUuid();
m_clipHelper = new ClipHelper( clip );
}
ClipWorkflow::~ClipWorkflow()
......@@ -58,7 +59,7 @@ void ClipWorkflow::initialize()
{
setState( ClipWorkflow::Initializing );
m_vlcMedia = new LibVLCpp::Media( m_clip->getMedia()->mrl() );
m_vlcMedia = new LibVLCpp::Media( m_clipHelper->clip()->getMedia()->mrl() );
m_currentPts = -1;
m_previousPts = -1;
m_pauseDuration = -1;
......@@ -84,11 +85,11 @@ void ClipWorkflow::loadingComplete()
void ClipWorkflow::adjustBegin()
{
if ( m_clip->getMedia()->fileType() == Media::Video ||
m_clip->getMedia()->fileType() == Media::Audio )
if ( m_clipHelper->clip()->getMedia()->fileType() == Media::Video ||
m_clipHelper->clip()->getMedia()->fileType() == Media::Audio )
{
m_mediaPlayer->setTime( m_clip->begin() /
m_clip->getMedia()->fps() * 1000 );
m_mediaPlayer->setTime( m_clipHelper->begin() /
m_clipHelper->clip()->getMedia()->fps() * 1000 );
}
}
......
......@@ -24,6 +24,7 @@
#define CLIPWORKFLOW_H
#include "mdate.h"
#include "ClipHelper.h"
#include <QObject>
#include <QUuid>
......@@ -129,13 +130,17 @@ class ClipWorkflow : public QObject
State getState() const;
/**
\brief Returns the Clip this workflow instance is based
\brief Returns the ClipHelper this workflow instance is based
uppon, so that you can query information on it.
\return A pointer to a constant clip instance.
\return A pointer to a ClipHelper instance.
*/
inline Clip* getClip()
inline ClipHelper* getClipHelper()
{
return m_clip;
return m_clipHelper;
}
inline Clip* clip()
{
return m_clipHelper->clip();
}
/**
......@@ -238,7 +243,7 @@ class ClipWorkflow : public QObject
protected:
LibVLCpp::MediaPlayer* m_mediaPlayer;
Clip* m_clip;
ClipHelper* m_clipHelper;
QMutex* m_renderLock;
QReadWriteLock* m_stateLock;
State m_state;
......
......@@ -22,6 +22,7 @@
#include "ImageClipWorkflow.h"
#include "Clip.h"
#include "ClipHelper.h"
#include "LightVideoFrame.h"
#include "MainWorkflow.h"
#include "VLCMediaPlayer.h"
......@@ -63,7 +64,7 @@ ImageClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":fake-duration=%d", 1000 );
m_vlcMedia->addOption( buffer );
sprintf( buffer, ":fake-fps=%f", m_clip->getMedia()->fps() );
sprintf( buffer, ":fake-fps=%f", m_clipHelper->clip()->getMedia()->fps() );
m_vlcMedia->addOption( buffer );
}
......
......@@ -20,21 +20,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QtDebug>
#include "vlmc.h"
#include "TrackWorkflow.h"
#include "VideoClipWorkflow.h"
#include "ImageClipWorkflow.h"
#include "AudioClipWorkflow.h"
#include "Clip.h"
#include "ClipHelper.h"
#include "ImageClipWorkflow.h"
#include "Media.h"
#include "VideoClipWorkflow.h"
#include "vlmc.h"
#include <QReadWriteLock>
#include <QDomDocument>
#include <QDomElement>
#include <QXmlStreamWriter>
#include <QtDebug>
TrackWorkflow::TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type ) :
m_trackId( trackId ),
m_length( 0 ),
......@@ -97,7 +100,7 @@ TrackWorkflow::computeLength()
return ;
}
QMap<qint64, ClipWorkflow*>::const_iterator it = m_clips.end() - 1;
m_length = (it.key() + it.value()->getClip()->length() );
m_length = (it.key() + it.value()->getClipHelper()->length() );
}
qint64 TrackWorkflow::getLength() const
......@@ -127,7 +130,7 @@ Clip* TrackWorkflow::getClip( const QUuid& uuid )
while ( it != end )
{
if ( it.value()->uuid() == uuid )
return it.value()->getClip();
return it.value()->clip();
++it;
}
return NULL;
......@@ -159,7 +162,7 @@ TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
cw->initialize();
cw->waitForCompleteInit();
//We check for a difference greater than one to avoid false positive when starting.
if ( ( qAbs(start - currentFrame) > 1 ) || cw->getClip()->begin() != 0 )
if ( ( qAbs(start - currentFrame) > 1 ) || cw->getClipHelper()->begin() != 0 )
{
//Clip was not started as its real begining: adjust the position
adjustClipTime( currentFrame, start, cw );
......@@ -215,7 +218,7 @@ bool TrackWorkflow::checkEnd( qint64 currentFrame ) const
//This is the last video by chronological order :
QMap<qint64, ClipWorkflow*>::const_iterator it = m_clips.end() - 1;
//If it ends before the current frame, we reached end.
return ( it.value()->getClip()->length() + it.key() < currentFrame );
return ( it.value()->getClipHelper()->length() + it.key() < currentFrame );
}
void
......@@ -292,7 +295,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
qint64 start = it.key();
ClipWorkflow* cw = it.value();
//Is the clip supposed to render now ?
if ( start <= currentFrame && currentFrame <= start + cw->getClip()->length() )
if ( start <= currentFrame && currentFrame <= start + cw->getClipHelper()->length() )
{
if ( ret != NULL )
qCritical() << "There's more than one clip to render here. Undefined behaviour !";
......@@ -353,7 +356,7 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
if ( it.value()->uuid() == id )
{
ClipWorkflow* cw = it.value();
Clip* clip = cw->getClip();
Clip* clip = cw->clip();
m_clips.erase( it );
stopClipWorkflow( cw );
computeLength();
......@@ -401,10 +404,10 @@ void TrackWorkflow::save( QXmlStreamWriter& project ) const
for ( ; it != end ; ++it )
{
project.writeStartElement( "clip" );
project.writeAttribute( "uuid", it.value()->getClip()->fullId() );
project.writeAttribute( "uuid", it.value()->clip()->fullId() );
project.writeAttribute( "startFrame", QString::number( it.key() ) );
project.writeAttribute( "begin", QString::number( it.value()->getClip()->begin() ) );
project.writeAttribute( "end", QString::number( it.value()->getClip()->end() ) );
project.writeAttribute( "begin", QString::number( it.value()->getClipHelper()->begin() ) );
project.writeAttribute( "end", QString::number( it.value()->getClipHelper()->end() ) );
project.writeEndElement();
}
}
......@@ -427,8 +430,8 @@ void TrackWorkflow::clear()
void TrackWorkflow::adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw )
{
qint64 nbMs = ( currentFrame - start ) / cw->getClip()->getMedia()->fps() * 1000;
qint64 beginInMs = cw->getClip()->begin() / cw->getClip()->getMedia()->fps() * 1000;
qint64 nbMs = ( currentFrame - start ) / cw->clip()->getMedia()->fps() * 1000;
qint64 beginInMs = cw->getClipHelper()->begin() / cw->clip()->getMedia()->fps() * 1000;
qint64 startFrame = beginInMs + nbMs;
cw->setTime( startFrame );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment