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

Workflow: Getting rid of void*.

Buffers are now hard typed.
parent 219da3e0
...@@ -159,13 +159,13 @@ int ...@@ -159,13 +159,13 @@ int
WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize, const void **buffer ) WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize, const void **buffer )
{ {
qint64 ptsDiff = 0; qint64 ptsDiff = 0;
MainWorkflow::OutputBuffers* ret; Workflow::Frame *ret;
if ( m_stopping == true ) if ( m_stopping == true )
return 1; return 1;
ret = m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ); ret = static_cast<Workflow::Frame*>( m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ) );
ptsDiff = ret->video->ptsDiff; ptsDiff = ret->ptsDiff;
if ( ptsDiff == 0 ) if ( ptsDiff == 0 )
{ {
//If no ptsDiff has been computed, we have to fake it, so we compute //If no ptsDiff has been computed, we have to fake it, so we compute
...@@ -175,13 +175,13 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize ...@@ -175,13 +175,13 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
} }
{ {
QReadLocker lock( m_effectsLock ); QReadLocker lock( m_effectsLock );
EffectsEngine::applyFilters( m_filters, ret->video, EffectsEngine::applyFilters( m_filters, ret,
m_mainWorkflow->getCurrentFrame(), m_mainWorkflow->getCurrentFrame(),
m_mainWorkflow->getCurrentFrame() * 1000.0 / handler->fps ); m_mainWorkflow->getCurrentFrame() * 1000.0 / handler->fps );
} }
m_pts = *pts = ptsDiff + m_pts; m_pts = *pts = ptsDiff + m_pts;
*buffer = ret->video->buffer(); *buffer = ret->buffer();
*bufferSize = ret->video->size(); *bufferSize = ret->size();
return 0; return 0;
} }
...@@ -194,9 +194,8 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize ...@@ -194,9 +194,8 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
if ( m_stopping == false && m_paused == false ) if ( m_stopping == false && m_paused == false )
{ {
MainWorkflow::OutputBuffers* ret = m_mainWorkflow->getOutput( Workflow::AudioTrack, renderAudioSample = static_cast<Workflow::AudioSample*>( m_mainWorkflow->getOutput( Workflow::AudioTrack,
m_paused ); m_paused ) );
renderAudioSample = ret->audio;
} }
else else
renderAudioSample = NULL; renderAudioSample = NULL;
......
...@@ -77,7 +77,7 @@ AudioClipWorkflow::getUnlockCallback() const ...@@ -77,7 +77,7 @@ AudioClipWorkflow::getUnlockCallback() const
return reinterpret_cast<void*>( &AudioClipWorkflow::unlock ); return reinterpret_cast<void*>( &AudioClipWorkflow::unlock );
} }
void* Workflow::OutputBuffer*
AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode ) AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{ {
QMutexLocker lock( m_renderLock ); QMutexLocker lock( m_renderLock );
......
...@@ -42,7 +42,7 @@ class AudioClipWorkflow : public ClipWorkflow ...@@ -42,7 +42,7 @@ class AudioClipWorkflow : public ClipWorkflow
~AudioClipWorkflow(); ~AudioClipWorkflow();
void *getLockCallback() const; void *getLockCallback() const;
void *getUnlockCallback() const; void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode ); virtual Workflow::OutputBuffer *getOutput( ClipWorkflow::GetMode mode );
virtual void saveEffects( QXmlStreamWriter & ) const {} //Nothing to do here now. virtual void saveEffects( QXmlStreamWriter & ) const {} //Nothing to do here now.
virtual bool appendEffect( Effect *, qint64, qint64 ) { return false; } //Nothing to do here now. virtual bool appendEffect( Effect *, qint64, qint64 ) { return false; } //Nothing to do here now.
protected: protected:
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "mdate.h" #include "mdate.h"
#include "ClipHelper.h" #include "ClipHelper.h"
#include "Types.h"
#include <QObject> #include <QObject>
#include <QUuid> #include <QUuid>
...@@ -106,7 +107,7 @@ class ClipWorkflow : public QObject ...@@ -106,7 +107,7 @@ class ClipWorkflow : public QObject
* therefore, you can call this method blindly, without taking care * therefore, you can call this method blindly, without taking care
* of the rendering process advancement. * of the rendering process advancement.
*/ */
virtual void* getOutput( ClipWorkflow::GetMode mode ) = 0; virtual Workflow::OutputBuffer *getOutput( ClipWorkflow::GetMode mode ) = 0;
void postGetOutput(); void postGetOutput();
virtual void initVlcOutput() = 0; virtual void initVlcOutput() = 0;
void initialize(); void initialize();
......
...@@ -84,7 +84,7 @@ ImageClipWorkflow::getUnlockCallback() const ...@@ -84,7 +84,7 @@ ImageClipWorkflow::getUnlockCallback() const
return reinterpret_cast<void*>( &ImageClipWorkflow::unlock ); return reinterpret_cast<void*>( &ImageClipWorkflow::unlock );
} }
void* Workflow::OutputBuffer*
ImageClipWorkflow::getOutput( ClipWorkflow::GetMode ) ImageClipWorkflow::getOutput( ClipWorkflow::GetMode )
{ {
QMutexLocker lock( m_renderLock ); QMutexLocker lock( m_renderLock );
......
...@@ -35,7 +35,7 @@ class ImageClipWorkflow : public ClipWorkflow ...@@ -35,7 +35,7 @@ class ImageClipWorkflow : public ClipWorkflow
void *getLockCallback() const; void *getLockCallback() const;
void *getUnlockCallback() const; void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode ); virtual Workflow::OutputBuffer *getOutput( ClipWorkflow::GetMode mode );
virtual void saveEffects( QXmlStreamWriter & ) const {} //Nothing to do here now. virtual void saveEffects( QXmlStreamWriter & ) const {} //Nothing to do here now.
virtual bool appendEffect( Effect *, qint64, qint64 ) { return false; } //Nothing to do here now. virtual bool appendEffect( Effect *, qint64, qint64 ) { return false; } //Nothing to do here now.
protected: protected:
......
...@@ -59,7 +59,6 @@ MainWorkflow::MainWorkflow( int trackCount ) : ...@@ -59,7 +59,6 @@ MainWorkflow::MainWorkflow( int trackCount ) :
this, SLOT( tracksEndReached() ) ); this, SLOT( tracksEndReached() ) );
m_currentFrame[i] = 0; m_currentFrame[i] = 0;
} }
m_outputBuffers = new OutputBuffers;
} }
MainWorkflow::~MainWorkflow() MainWorkflow::~MainWorkflow()
...@@ -125,7 +124,7 @@ MainWorkflow::startRender( quint32 width, quint32 height, double fps ) ...@@ -125,7 +124,7 @@ MainWorkflow::startRender( quint32 width, quint32 height, double fps )
computeLength(); computeLength();
} }
MainWorkflow::OutputBuffers* Workflow::OutputBuffer*
MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused ) MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused )
{ {
QMutexLocker lock( m_renderStartedMutex ); QMutexLocker lock( m_renderStartedMutex );
...@@ -134,22 +133,16 @@ MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused ) ...@@ -134,22 +133,16 @@ MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused )
{ {
QReadLocker lock2( m_currentFrameLock ); QReadLocker lock2( m_currentFrameLock );
void* ret = m_tracks[trackType]->getOutput( m_currentFrame[Workflow::VideoTrack], Workflow::OutputBuffer *ret = m_tracks[trackType]->getOutput( m_currentFrame[Workflow::VideoTrack],
m_currentFrame[trackType], paused ); m_currentFrame[trackType], paused );
if ( trackType == Workflow::VideoTrack ) if ( trackType == Workflow::VideoTrack )
{ {
Workflow::Frame* frame = static_cast<Workflow::Frame*>( ret ); if ( ret == NULL )
if ( frame == NULL ) return MainWorkflow::blackOutput;
m_outputBuffers->video = MainWorkflow::blackOutput;
else
m_outputBuffers->video = frame;
}
else
{
m_outputBuffers->audio = static_cast<Workflow::AudioSample*>( ret );
} }
return ret;
} }
return m_outputBuffers; return NULL;
} }
void void
......
...@@ -56,16 +56,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow> ...@@ -56,16 +56,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
Q_OBJECT Q_OBJECT
public: public:
/**
* \struct Represents an output, with both audio and video buffers.
* Note that an OutputBuffers will not necessarly have its both
* fields filed out.
*/
struct OutputBuffers
{
Workflow::Frame *video;
Workflow::AudioSample *audio;
};
/** /**
* \enum Used to know which part required a change of rendered frame. * \enum Used to know which part required a change of rendered frame.
* The main use of this enum is to avoid infinite information propagation * The main use of this enum is to avoid infinite information propagation
...@@ -125,7 +115,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow> ...@@ -125,7 +115,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* \param trackType The type of track you wish to get the render from. * \param trackType The type of track you wish to get the render from.
* \param paused The paused state of the renderer * \param paused The paused state of the renderer
*/ */
OutputBuffers* getOutput( Workflow::TrackType trackType, bool paused ); Workflow::OutputBuffer *getOutput( Workflow::TrackType trackType, bool paused );
/** /**
* \brief Set the workflow position by the desired frame * \brief Set the workflow position by the desired frame
* \param currentFrame: The desired frame to render from * \param currentFrame: The desired frame to render from
...@@ -395,8 +385,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow> ...@@ -395,8 +385,6 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
/// Contains the trackhandler, indexed by Workflow::TrackType /// Contains the trackhandler, indexed by Workflow::TrackType
TrackHandler** m_tracks; TrackHandler** m_tracks;
/// Pre-allocated buffer, that will contain every computed outputs.
OutputBuffers* m_outputBuffers;
/// Width used for the render /// Width used for the render
quint32 m_width; quint32 m_width;
......
...@@ -100,7 +100,7 @@ TrackHandler::getLength() const ...@@ -100,7 +100,7 @@ TrackHandler::getLength() const
return m_length; return m_length;
} }
void* Workflow::OutputBuffer*
TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{ {
bool validTrack = false; bool validTrack = false;
...@@ -110,7 +110,7 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) ...@@ -110,7 +110,7 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
if ( m_tracks[i].activated() == false || m_tracks[i]->hasFrameToRender( currentFrame ) ) if ( m_tracks[i].activated() == false || m_tracks[i]->hasFrameToRender( currentFrame ) )
continue ; continue ;
validTrack = true; validTrack = true;
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused ); Workflow::OutputBuffer *ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
if ( ret == NULL ) if ( ret == NULL )
continue ; continue ;
else else
......
...@@ -62,7 +62,7 @@ class TrackHandler : public QObject ...@@ -62,7 +62,7 @@ class TrackHandler : public QObject
* track, it will be different. * track, it will be different.
* \param paused The renderer paused state * \param paused The renderer paused state
*/ */
void *getOutput( qint64 currentFrame, qint64 subFrame, Workflow::OutputBuffer *getOutput( qint64 currentFrame, qint64 subFrame,
bool paused ); bool paused );
qint64 getClipPosition( const QUuid& uuid, unsigned int trackId ) const; qint64 getClipPosition( const QUuid& uuid, unsigned int trackId ) const;
void stop(); void stop();
......
...@@ -152,7 +152,7 @@ TrackWorkflow::getClip( const QUuid& uuid ) ...@@ -152,7 +152,7 @@ TrackWorkflow::getClip( const QUuid& uuid )
return NULL; return NULL;
} }
void* Workflow::OutputBuffer*
TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame, TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
qint64 start , bool needRepositioning, qint64 start , bool needRepositioning,
bool renderOneFrame, bool paused ) bool renderOneFrame, bool paused )
...@@ -265,7 +265,7 @@ TrackWorkflow::stop() ...@@ -265,7 +265,7 @@ TrackWorkflow::stop()
m_lastFrame = 0; m_lastFrame = 0;
} }
void* Workflow::OutputBuffer*
TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{ {
QReadLocker lock( m_clipsLock ); QReadLocker lock( m_clipsLock );
...@@ -273,7 +273,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) ...@@ -273,7 +273,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin(); QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end(); QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
bool needRepositioning; bool needRepositioning;
void *ret = NULL; Workflow::OutputBuffer *ret = NULL;
Workflow::Frame *frames[EffectsEngine::MaxFramesForMixer]; Workflow::Frame *frames[EffectsEngine::MaxFramesForMixer];
quint32 frameId = 0; quint32 frameId = 0;
bool renderOneFrame = false; bool renderOneFrame = false;
...@@ -312,7 +312,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) ...@@ -312,7 +312,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
renderOneFrame, paused ); renderOneFrame, paused );
if ( m_trackType == Workflow::VideoTrack ) if ( m_trackType == Workflow::VideoTrack )
{ {
frames[frameId] = reinterpret_cast<Workflow::Frame*>( ret ); frames[frameId] = static_cast<Workflow::Frame*>( ret );
++frameId; ++frameId;
} }
} }
...@@ -344,11 +344,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused ) ...@@ -344,11 +344,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
ret = frames[0]; ret = frames[0];
} }
m_lastFrame = subFrame; m_lastFrame = subFrame;
if ( ret == NULL ) return ret;
return NULL;
if ( m_trackType == Workflow::VideoTrack )
return reinterpret_cast<Workflow::Frame*>( ret );
return reinterpret_cast<Workflow::AudioSample*>( ret );
} }
void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame ) void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
......
...@@ -49,7 +49,7 @@ class TrackWorkflow : public QObject ...@@ -49,7 +49,7 @@ class TrackWorkflow : public QObject
TrackWorkflow( Workflow::TrackType type ); TrackWorkflow( Workflow::TrackType type );
~TrackWorkflow(); ~TrackWorkflow();
void* getOutput( qint64 currentFrame, Workflow::OutputBuffer *getOutput( qint64 currentFrame,
qint64 subFrame, bool paused ); qint64 subFrame, bool paused );
qint64 getLength() const; qint64 getLength() const;
void stop(); void stop();
...@@ -94,7 +94,7 @@ class TrackWorkflow : public QObject ...@@ -94,7 +94,7 @@ class TrackWorkflow : public QObject
private: private:
void computeLength(); void computeLength();
void* renderClip( ClipWorkflow* cw, qint64 currentFrame, Workflow::OutputBuffer *renderClip( ClipWorkflow* cw, qint64 currentFrame,
qint64 start, bool needRepositioning, qint64 start, bool needRepositioning,
bool renderOneFrame, bool paused ); bool renderOneFrame, bool paused );
void preloadClip( ClipWorkflow* cw ); void preloadClip( ClipWorkflow* cw );
......
...@@ -27,6 +27,7 @@ using namespace Workflow; ...@@ -27,6 +27,7 @@ using namespace Workflow;
#include <cstring> //memcpy #include <cstring> //memcpy
Frame::Frame() : Frame::Frame() :
OutputBuffer( VideoTrack ),
ptsDiff( 0 ), ptsDiff( 0 ),
m_width( 0 ), m_width( 0 ),
m_height( 0 ), m_height( 0 ),
...@@ -37,6 +38,7 @@ Frame::Frame() : ...@@ -37,6 +38,7 @@ Frame::Frame() :
} }
Frame::Frame( quint32 width, quint32 height ) : Frame::Frame( quint32 width, quint32 height ) :
OutputBuffer( VideoTrack ),
ptsDiff( 0 ), ptsDiff( 0 ),
m_width( width ), m_width( width ),
m_height( height ) m_height( height )
......
...@@ -39,7 +39,14 @@ namespace Workflow ...@@ -39,7 +39,14 @@ namespace Workflow
NbTrackType, ///< Used to know how many types we have NbTrackType, ///< Used to know how many types we have
}; };
class Frame struct OutputBuffer
{
TrackType type;
protected:
OutputBuffer( TrackType _type ) : type( _type ) {}
};
class Frame : public OutputBuffer
{ {
public: public:
explicit Frame(); explicit Frame();
...@@ -83,8 +90,9 @@ namespace Workflow ...@@ -83,8 +90,9 @@ namespace Workflow
quint32 m_size; quint32 m_size;
quint32 m_nbPixels; quint32 m_nbPixels;
}; };
struct AudioSample struct AudioSample : public OutputBuffer
{ {
AudioSample() : OutputBuffer( AudioTrack ){}
unsigned char* buff; unsigned char* buff;
size_t size; size_t size;
quint32 nbSample; quint32 nbSample;
......
...@@ -118,7 +118,7 @@ VideoClipWorkflow::getUnlockCallback() const ...@@ -118,7 +118,7 @@ VideoClipWorkflow::getUnlockCallback() const
return reinterpret_cast<void*>( &VideoClipWorkflow::unlock ); return reinterpret_cast<void*>( &VideoClipWorkflow::unlock );
} }
void* Workflow::OutputBuffer*
VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode ) VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{ {
QMutexLocker lock( m_renderLock ); QMutexLocker lock( m_renderLock );
......
...@@ -39,7 +39,7 @@ class VideoClipWorkflow : public ClipWorkflow ...@@ -39,7 +39,7 @@ class VideoClipWorkflow : public ClipWorkflow
~VideoClipWorkflow(); ~VideoClipWorkflow();
void *getLockCallback() const; void *getLockCallback() const;
void *getUnlockCallback() const; void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode ); virtual Workflow::OutputBuffer *getOutput( ClipWorkflow::GetMode mode );
virtual bool appendEffect( Effect *effect, qint64 start = 0, qint64 end = -1 ); virtual bool appendEffect( Effect *effect, qint64 start = 0, qint64 end = -1 );
virtual void setTime( qint64 time, qint64 frame ); virtual void setTime( qint64 time, qint64 frame );
virtual void saveEffects( QXmlStreamWriter &project ) const; virtual void saveEffects( QXmlStreamWriter &project ) const;
......
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