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

Removing old effects engine files.

parent 5d8d60b4
/*****************************************************************************
* EffectNode.cpp: Node of the patch
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Vincent Carrubba <cyberbouba@gmail.com>
*
* 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 "EffectNode.h"
#include "IEffectNode.h"
#include "IEffectPlugin.h"
#include <QObject>
#include <QReadLocker>
#include <QReadWriteLock>
#include <QString>
#include <QWriteLocker>
EffectNodeFactory EffectNode::s_renf;
QReadWriteLock EffectNode::s_srwl( QReadWriteLock::Recursive );
template class SemanticObjectManager< InSlot<LightVideoFrame> >;
template class SemanticObjectManager< OutSlot<LightVideoFrame> >;
// template class SemanticObjectManager<InSlot<AudioSoundSample> >;
// template class SemanticObjectManager<OutSlot<AudioSoundSample> >;
// template class SemanticObjectManager<InSlot<qreal> >;
// template class SemanticObjectManager<OutSlot<qreal> >;
//============================================================================================//
// CTORS & DTOR //
//============================================================================================//
EffectNode::EffectNode( IEffectPlugin* plugin ) : m_rwl( QReadWriteLock::Recursive ),
m_father( NULL ), m_plugin( plugin ),
m_visited( false )
{
m_staticVideosInputs.setFather( this );
m_staticVideosOutputs.setFather( this );
m_staticVideosInputs.setScope( false );
m_staticVideosOutputs.setScope( false );
m_internalsStaticVideosInputs.setFather( this );
m_internalsStaticVideosOutputs.setFather( this );
m_internalsStaticVideosInputs.setScope( true );
m_internalsStaticVideosOutputs.setScope( true );
m_enf.setFather( this );
m_plugin->init( this );
}
EffectNode::EffectNode() : m_father( NULL ),
m_plugin( NULL ),
m_visited( false )
{
m_staticVideosInputs.setFather( this );
m_staticVideosOutputs.setFather( this );
m_staticVideosInputs.setScope( false );
m_staticVideosOutputs.setScope( false );
m_internalsStaticVideosInputs.setFather( this );
m_internalsStaticVideosOutputs.setFather( this );
m_internalsStaticVideosInputs.setScope( true );
m_internalsStaticVideosOutputs.setScope( true );
m_enf.setFather( this );
}
EffectNode::~EffectNode()
{
delete m_plugin;
}
//============================================================================================//
// RENDER & CO //
//============================================================================================//
void
EffectNode::render( void )
{
if ( m_plugin != NULL )
m_plugin->render();
else
{
if ( m_father != NULL)
{
QWriteLocker wl( &m_rwl );
transmitDatasFromInputsToInternalsOutputs();
renderSubNodes();
transmitDatasFromInternalsInputsToOutputs();
resetAllChildsNodesVisitState();
}
else
{
QWriteLocker wl( &m_rwl );
renderSubNodes();
resetAllChildsNodesVisitState();
}
}
}
void
EffectNode::renderSubNodes( void )
{
QList<EffectNode*> effectsNodes = m_enf.getEffectNodeInstancesList();
QList<EffectNode*>::iterator effectsNodesIt = effectsNodes.begin();
QList<EffectNode*>::iterator effectsNodesEnd = effectsNodes.end();
QList<OutSlot<LightVideoFrame>*> intOuts = m_connectedInternalsStaticVideosOutputs.getObjectsReferencesList() ;
QList<OutSlot<LightVideoFrame>*>::iterator intOutsIt = intOuts.begin();
QList<OutSlot<LightVideoFrame>*>::iterator intOutsEnd = intOuts.end();
QQueue<EffectNode*> nodeQueue;
EffectNode* toQueueNode;
EffectNode* currentNode;
InSlot<LightVideoFrame>* currentIn;
for ( ; effectsNodesIt != effectsNodesEnd; ++effectsNodesIt )
{
if (
( (*effectsNodesIt)->getNBConnectedStaticsVideosInputs() == 0 ) &&
( (*effectsNodesIt)->getNBConnectedStaticsVideosOutputs() > 0 )
)
{
(*effectsNodesIt)->setVisited();
nodeQueue.enqueue( (*effectsNodesIt) );
}
}
for ( ; intOutsIt != intOutsEnd; ++intOutsIt )
{
currentIn = (*intOutsIt)->getInSlotPtr();
toQueueNode = currentIn->getPrivateFather();
if ((toQueueNode != this) && ( toQueueNode->wasItVisited() == false ))
{
toQueueNode->setVisited();
nodeQueue.enqueue( toQueueNode );
}
}
while ( nodeQueue.empty() == false )
{
currentNode = nodeQueue.dequeue();
QList<OutSlot<LightVideoFrame>*> outs = currentNode->getConnectedStaticsVideosOutputsList();
QList<OutSlot<LightVideoFrame>*>::iterator outsIt = outs.begin();
QList<OutSlot<LightVideoFrame>*>::iterator outsEnd = outs.end();
currentNode->render();
for ( ; outsIt != outsEnd; ++outsIt )
{
currentIn = (*outsIt)->getInSlotPtr();
toQueueNode = currentIn->getPrivateFather();
if ((toQueueNode != this) && ( toQueueNode->wasItVisited() == false ))
{
toQueueNode->setVisited();
nodeQueue.enqueue( toQueueNode );
}
}
}
}
void
EffectNode::transmitDatasFromInputsToInternalsOutputs( void )
{
if ( m_staticVideosInputs.getNBObjects() != 0 )
{
QList<InSlot<LightVideoFrame>*> ins = m_staticVideosInputs.getObjectsList();
QList<OutSlot<LightVideoFrame>*> intOuts = m_internalsStaticVideosOutputs.getObjectsList();
QList<InSlot<LightVideoFrame>*>::iterator insIt = ins.begin();
QList<InSlot<LightVideoFrame>*>::iterator insEnd = ins.end();
QList<OutSlot<LightVideoFrame>*>::iterator intOutsIt = intOuts.begin();
QList<OutSlot<LightVideoFrame>*>::iterator intOutsEnd = intOuts.end();
for ( ; ( insIt != insEnd ) && ( intOutsIt != intOutsEnd ); ++insIt, ++intOutsIt )
*(*intOutsIt) << *(*insIt);
}
}
void
EffectNode::transmitDatasFromInternalsInputsToOutputs( void )
{
if ( m_staticVideosOutputs.getNBObjects() != 0 )
{
QList<InSlot<LightVideoFrame>*> intIns = m_internalsStaticVideosInputs.getObjectsList();
QList<OutSlot<LightVideoFrame>*> outs = m_staticVideosOutputs.getObjectsList();
QList<InSlot<LightVideoFrame>*>::iterator intInsIt = intIns.begin();
QList<InSlot<LightVideoFrame>*>::iterator intInsEnd = intIns.end();
QList<OutSlot<LightVideoFrame>*>::iterator outsIt = outs.begin();
QList<OutSlot<LightVideoFrame>*>::iterator outsEnd = outs.end();
for ( ; ( intInsIt != intInsEnd ) && ( outsIt != outsEnd ); ++intInsIt, ++outsIt )
*(*outsIt) << *(*intInsIt);
}
}
void
EffectNode::resetAllChildsNodesVisitState( void )
{
QList<EffectNode*> childs = m_enf.getEffectNodeInstancesList();
if ( childs.empty() == false )
{
QList<EffectNode*>::iterator it = childs.begin();
QList<EffectNode*>::iterator end = childs.end();
for ( ; it != end; ++it)
(*it)->resetVisitState();
}
}
void
EffectNode::setVisited( void )
{
QWriteLocker wl( &m_rwl );
m_visited = true;
}
void
EffectNode::resetVisitState( void )
{
QWriteLocker wl( &m_rwl );
m_visited = false;
}
bool
EffectNode::wasItVisited( void ) const
{
QReadLocker rl( &m_rwl );
return m_visited;
}
//============================================================================================//
// CONNECTIONS MANAGEMENT //
//============================================================================================//
bool
EffectNode::primitiveConnection( quint32 outId,
const QString &outName,
bool outInternal,
quint32 inId,
const QString &inName,
bool inInternal,
quint32 nodeId,
const QString &nodeName )
{
OutSlot<LightVideoFrame>* out;
EffectNode* dest;
InSlot<LightVideoFrame>* in;
/**
* Get output, destination node and input
*/
if ( outInternal == true )
{
if ( outId == 0 && outName.isEmpty() == false )
{
if ( ( out = m_internalsStaticVideosOutputs.getObject( outName ) ) == NULL )
return false;
}
else if ( outId != 0 && outName.isEmpty() == true )
{
if ( ( out = m_internalsStaticVideosOutputs.getObject( outId ) ) == NULL )
return false;
}
else
return false;
if ( inInternal == true )
{
/**
* Connection internal to internal
*/
dest = this;
if ( nodeId != 0 || nodeName.size() != 0 )
return false;
if ( inId == 0 && inName.size() != 0 )
{
if ( ( in = m_internalsStaticVideosInputs.getObject( inName ) ) == NULL )
return false;
}
else if ( inId != 0 && inName.size() == 0 )
{
if ( ( in = m_internalsStaticVideosInputs.getObject( inId ) ) == NULL )
return false;
}
else
return false;
}
else
{
/**
* Connection internal to external ( so parent to child )
*/
if ( nodeId == 0 && nodeName.size() != 0 )
{
if ( ( dest = m_enf.getEffectNodeInstance( nodeName ) ) == NULL )
return false;
}
else if ( nodeId != 0 && nodeName.size() == 0 )
{
if ( ( dest = m_enf.getEffectNodeInstance( nodeId ) ) == NULL )
return false;
}
else
return false;
if ( inId == 0 && inName.size() != 0 )
{
if ( ( in = dest->getStaticVideoInput( inName ) ) == NULL )
return false;
}
else if ( inId != 0 && inName.size() == 0 )
{
if ( ( in = dest->getStaticVideoInput( inId ) ) == NULL )
return false;
}
else
return false;
}
}
else
{
if ( outId == 0 && outName.isEmpty() == false )
{
if ( ( out = m_staticVideosOutputs.getObject( outName ) ) == NULL )
return false;
}
else if ( outId != 0 && outName.isEmpty() == true )
{
if ( ( out = m_staticVideosOutputs.getObject( outId ) ) == NULL )
return false;
}
else
return false;
if ( m_father == NULL )
return false;
if ( inInternal == true )
{
/**
* Connection external to internal ( so child to parent )
*/
dest = m_father;
if ( nodeId != 0 || nodeName.size() != 0 )
return false;
if ( inId == 0 && inName.size() != 0 )
{
if ( ( in = m_father->getInternalStaticVideoInput( inName ) ) == NULL )
return false;
}
else if ( inId != 0 && inName.size() == 0 )
{
if ( ( in = m_father->getInternalStaticVideoInput( inId ) ) == NULL )
return false;
}
else
return false;
}
else
{
/**
* Connection external to external ( so brother to brother )
*/
if ( nodeId == 0 && nodeName.size() != 0 )
{
if ( ( dest = m_father->getChild( nodeName ) ) == NULL )
return false;
}
else if ( nodeId != 0 && nodeName.size() == 0 )
{
if ( ( dest = m_father->getChild( nodeId ) ) == NULL )
return false;
}
else
return false;
if ( inId == 0 && inName.size() != 0 )
{
if ( dest != this )
{
if ( ( in = dest->getStaticVideoInput( inName ) ) == NULL )
return false;
}
else
{
if ( ( in = m_staticVideosInputs.getObject( inName ) ) == NULL )
return false;
}
}
else if ( inId != 0 && inName.size() == 0 )
{
if ( dest != this )
{
if ( ( in = dest->getStaticVideoInput( inId ) ) == NULL )
return false;
}
else
{
if ( ( in = m_staticVideosInputs.getObject( inId ) ) == NULL )
return false;
}
}
else
return false;
}
}
/**
* Connect the output on the input
*/
if ( out->connect( *in ) == false )
return false;
/**
* Reference the output and the input as connected
*/
if ( outInternal == true )
{
if ( m_connectedInternalsStaticVideosOutputs.addObjectReference( out ) == false )
return false;
}
else
{
if ( m_connectedStaticVideosOutputs.addObjectReference( out ) == false )
return false;
}
if ( inInternal == true )
{
if ( dest != this )
{
if ( dest->referenceInternalStaticVideoInputAsConnected( in ) == false )
return false;
}
else
{
if ( m_connectedInternalsStaticVideosInputs.addObjectReference( in ) == false )
return false;
}
}
else
{
if ( dest != this )
{
if ( dest->referenceStaticVideoInputAsConnected( in ) == false )
return false;
}
else
{
if ( m_connectedStaticVideosInputs.addObjectReference( in ) == false )
return false;
}
}
return true;
}
/**
* Brother to brother connection
*/
bool
EffectNode::connectBrotherToBrother( const QString &outName, const QString &nodeName, const QString &inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
false,
0,
inName,
false,
0,
nodeName );
}
bool
EffectNode::connectBrotherToBrother( const QString &outName, const QString &nodeName, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
false,
inId,
"",
false,
0,
nodeName );
}
bool
EffectNode::connectBrotherToBrother( const QString &outName, quint32 nodeId, const QString &inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
false,
0,
inName,
false,
nodeId,
"" );
}
bool
EffectNode::connectBrotherToBrother( const QString &outName, quint32 nodeId, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
false,
inId,
"",
false,
nodeId,
"" );
}
bool
EffectNode::connectBrotherToBrother( quint32 outId, const QString &nodeName, const QString &inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
false,
0,
inName,
false,
0,
nodeName );
}
bool
EffectNode::connectBrotherToBrother( quint32 outId, const QString &nodeName, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
false,
inId,
"",
false,
0,
nodeName );
}
bool
EffectNode::connectBrotherToBrother( quint32 outId, quint32 nodeId, const QString &inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
false,
0,
inName,
false,
nodeId,
"" );
}
bool
EffectNode::connectBrotherToBrother( quint32 outId, quint32 nodeId, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
false,
inId,
"",
false,
nodeId,
"" );
}
/**
* Parent to child connection
*/
bool
EffectNode::connectParentToChild( const QString & outName, const QString & nodeName, const QString & inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
true,
0,
inName,
false,
0,
nodeName );
}
bool
EffectNode::connectParentToChild( const QString & outName, const QString & nodeName, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
true,
inId,
"",
false,
0,
nodeName );
}
bool
EffectNode::connectParentToChild( quint32 outId, const QString & nodeName, const QString & inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
true,
0,
inName,
false,
0,
nodeName );
}
bool
EffectNode::connectParentToChild( quint32 outId, const QString & nodeName, quint32 inId )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( outId,
"",
true,
inId,
"",
false,
0,
nodeName );
}
bool
EffectNode::connectParentToChild( const QString & outName, quint32 nodeId, const QString & inName )
{
QWriteLocker wl( &m_rwl );
return primitiveConnection( 0,
outName,
true,
0,
inName,
false,
nodeId,
"" );
}
bool
EffectNode::connectParentToChild( const QString & outName, quint32 nodeId, quint32 inId )
{