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

TrackWorkflow: Implement Mixeris handling.

Untested as it requires some additions to the effects classes.
parent 28017d7d
......@@ -180,3 +180,18 @@ EffectsEngine::initFilters( const FilterList &effects, quint32 width, quint32 he
++it;
}
}
EffectsEngine::MixerHelper*
EffectsEngine::getMixer( const MixerList &mixers, qint64 currentFrame )
{
MixerList::const_iterator it = mixers.constBegin();
MixerList::const_iterator ite = mixers.constEnd();
while ( it != ite )
{
if ( it.key() <= currentFrame && currentFrame <= it.value()->end )
return it.value();
++it;
}
return NULL;
}
......@@ -66,17 +66,22 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
typedef EffectHelper<FilterInstance> FilterHelper;
typedef QList<FilterHelper*> FilterList;
typedef EffectHelper<MixerInstance> MixerHelper;
typedef QList<MixerHelper*> MixerList;
typedef QHash<qint64, MixerHelper*> MixerList;
static const quint32 MaxFramesForMixer = 3;
Effect* effect( const QString& name );
bool loadEffect( const QString& fileName );
void browseDirectory( const QString& path );
//Filters methods:
static void applyFilters( const FilterList &effects,
Workflow::Frame *frame, qint64 currentFrame, double time );
static void saveFilters( const FilterList &effects, QXmlStreamWriter &project );
static void initFilters( const FilterList &effects, quint32 width, quint32 height );
//Mixers methods:
static MixerHelper* getMixer( const MixerList& mixers, qint64 currentFrame );
private:
EffectsEngine();
~EffectsEngine();
......
......@@ -120,7 +120,7 @@ MainWorkflow::startRender( quint32 width, quint32 height )
blackOutput = new Workflow::Frame( m_width, m_height );
memset( blackOutput->buffer(), 0, blackOutput->size() );
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->startRender();
m_tracks[i]->startRender( width, height );
computeLength();
}
......
......@@ -66,7 +66,7 @@ TrackHandler::addEffect( Effect *effect, quint32 trackId, const QUuid &uuid )
}
void
TrackHandler::startRender()
TrackHandler::startRender( quint32 width, quint32 height )
{
m_endReached = false;
computeLength();
......@@ -76,7 +76,7 @@ TrackHandler::startRender()
{
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
m_tracks[i]->preload();
m_tracks[i]->initRender( width, height );
}
}
}
......
......@@ -54,7 +54,7 @@ class TrackHandler : public QObject
*/
unsigned int getTrackCount() const;
qint64 getLength() const;
void startRender();
void startRender( quint32 width, quint32 height );
/**
* \param currentFrame The current rendering frame (ie the video frame, in all case)
* \param subFrame The type-dependent frame. IE, for a video track,
......
......@@ -28,6 +28,8 @@
#include "AudioClipWorkflow.h"
#include "ImageClipWorkflow.h"
#include "Media.h"
#include "MixerInstance.h"
#include "Types.h"
#include "VideoClipWorkflow.h"
#include "vlmc.h"
......@@ -46,6 +48,7 @@ TrackWorkflow::TrackWorkflow( MainWorkflow::TrackType type ) :
{
m_renderOneFrameMutex = new QMutex;
m_clipsLock = new QReadWriteLock;
m_mixerBuffer = new Workflow::Frame;
}
TrackWorkflow::~TrackWorkflow()
......@@ -289,6 +292,8 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
bool needRepositioning;
void *ret = NULL;
StackedBuffer<Workflow::Frame*> *frames[EffectsEngine::MaxFramesForMixer];
quint32 frameId = 0;
bool renderOneFrame = false;
if ( m_lastFrame == -1 )
......@@ -313,6 +318,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
else
needRepositioning = ( abs( subFrame - m_lastFrame ) > 1 ) ? true : false;
}
memset( frames, 0, sizeof(*frames) * EffectsEngine::MaxFramesForMixer );
while ( it != end )
{
qint64 start = it.key();
......@@ -325,7 +331,10 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
ret = renderClip( cw, currentFrame, start, needRepositioning,
renderOneFrame, paused );
if ( m_trackType == MainWorkflow::VideoTrack )
m_videoStackedBuffer = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
{
frames[frameId] = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
++frameId;
}
else
m_audioStackedBuffer = reinterpret_cast<StackedBuffer<Workflow::AudioSample*>*>( ret );
}
......@@ -338,6 +347,21 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
stopClipWorkflow( cw );
++it;
}
//Handle mixers:
if ( m_trackType == MainWorkflow::VideoTrack )
{
if ( frames[1] != NULL ) //More than one frame has been rendered, let's mix them !
{
EffectsEngine::MixerHelper* mixer = EffectsEngine::getMixer( m_mixers, currentFrame );
if ( mixer != NULL )
{
//FIXME: We don't handle mixer3 yet.
mixer->effect->process( 0.0, frames[0]->get()->buffer(),
frames[0]->get()->buffer(), NULL, m_mixerBuffer->buffer() );
ret = m_mixerBuffer;
}
}
}
m_lastFrame = subFrame;
if ( ret == NULL )
return NULL;
......@@ -515,10 +539,11 @@ TrackWorkflow::unmuteClip( const QUuid &uuid )
}
void
TrackWorkflow::preload()
TrackWorkflow::initRender( quint32 width, quint32 height )
{
QReadLocker lock( m_clipsLock );
m_mixerBuffer->resize( width, height );
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
while ( it != end )
......
......@@ -23,6 +23,7 @@
#ifndef TRACKWORKFLOW_H
#define TRACKWORKFLOW_H
#include "EffectsEngine.h"
#include "MainWorkflow.h"
#include "StackedBuffer.hpp"
......@@ -84,7 +85,7 @@ class TrackWorkflow : public QObject
void muteClip( const QUuid& uuid );
void unmuteClip( const QUuid& uuid );
void preload();
void initRender( quint32 width, quint32 height );
bool contains( const QUuid& uuid ) const;
......@@ -104,6 +105,7 @@ class TrackWorkflow : public QObject
private:
QMap<qint64, ClipWorkflow*> m_clips;
EffectsEngine::MixerList m_mixers;
/**
* \brief The track length in frames.
......@@ -119,6 +121,7 @@ class TrackWorkflow : public QObject
qint64 m_lastFrame;
StackedBuffer<Workflow::Frame*>* m_videoStackedBuffer;
StackedBuffer<Workflow::AudioSample*>* m_audioStackedBuffer;
Workflow::Frame *m_mixerBuffer;
};
#endif // TRACKWORKFLOW_H
......@@ -26,6 +26,16 @@ using namespace Workflow;
#include <cstring> //memcpy
Frame::Frame() :
ptsDiff( 0 ),
m_width( 0 ),
m_height( 0 ),
m_buffer( 0 ),
m_size( 0 ),
m_nbPixels( 0 )
{
}
Frame::Frame( quint32 width, quint32 height ) :
ptsDiff( 0 ),
m_width( width ),
......@@ -91,3 +101,17 @@ Frame::setBuffer( quint32 *buff )
delete[] m_buffer;
m_buffer = buff;
}
void
Frame::resize( quint32 width, quint32 height )
{
if ( width != m_width || height != height )
{
delete[] m_buffer;
m_width = width;
m_height = height;
m_nbPixels = width * height;
m_size = m_nbPixels * Depth;
m_buffer = new quint32[m_nbPixels];
}
}
......@@ -32,6 +32,7 @@ namespace Workflow
class Frame
{
public:
explicit Frame();
Frame( quint32 width, quint32 height );
~Frame();
quint32 width() const;
......@@ -40,6 +41,12 @@ namespace Workflow
const quint32 *buffer() const;
void setBuffer( quint32 *buff );
Frame *clone() const;
/**
* \brief Resize the buffer.
*
* \warning This will not resize what's in the frame !
*/
void resize( quint32 width, quint32 height );
/**
* \returns The frame size in octets
*
......
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