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

Removing StackedBuffers.

parent c281d1f5
......@@ -43,7 +43,6 @@ SET(VLMC_SRCS
Workflow/ClipHelper.cpp
Workflow/ImageClipWorkflow.cpp
Workflow/MainWorkflow.cpp
Workflow/StackedBuffer.hpp
Workflow/TrackHandler.cpp
Workflow/TrackWorkflow.cpp
Workflow/Types.cpp
......
......@@ -82,25 +82,30 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
if ( m_lastReturnedBuffer != NULL )
{
m_availableBuffers.enqueue( m_lastReturnedBuffer );
m_lastReturnedBuffer = NULL;
}
if ( getNbComputedBuffers() == 0 )
return NULL;
if ( shouldRender() == false )
return NULL;
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
::StackedBuffer<Workflow::AudioSample*> *buff = new StackedBuffer(
m_computedBuffers.dequeue(), this, true );
Workflow::AudioSample *buff = m_computedBuffers.dequeue();
if ( m_previousPts == -1 )
{
buff->get()->ptsDiff = 0;
m_previousPts = buff->get()->pts;
buff->ptsDiff = 0;
m_previousPts = buff->pts;
}
else
{
buff->get()->ptsDiff = buff->get()->pts - m_previousPts;
m_previousPts = buff->get()->pts;
buff->ptsDiff = buff->pts - m_previousPts;
m_previousPts = buff->pts;
}
postGetOutput();
m_lastReturnedBuffer = buff;
return buff;
}
......@@ -221,13 +226,6 @@ AudioClipWorkflow::getMaxComputedBuffers() const
return AudioClipWorkflow::nbBuffers;
}
void
AudioClipWorkflow::releaseBuffer( Workflow::AudioSample *sample )
{
QMutexLocker lock( m_renderLock );
m_availableBuffers.enqueue( sample );
}
void
AudioClipWorkflow::flushComputedBuffers()
{
......@@ -238,19 +236,3 @@ AudioClipWorkflow::flushComputedBuffers()
m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
}
}
AudioClipWorkflow::StackedBuffer::StackedBuffer( Workflow::AudioSample *as,
AudioClipWorkflow *poolHandler,
bool mustBeReleased) :
::StackedBuffer<Workflow::AudioSample*>( as, mustBeReleased ),
m_poolHandler( poolHandler )
{
}
void
AudioClipWorkflow::StackedBuffer::release()
{
if ( m_mustRelease == true && m_poolHandler.isNull() == false )
m_poolHandler->releaseBuffer( m_buff );
delete this;
}
......@@ -24,9 +24,9 @@
#define AUDIOCLIPWORKFLOW_H
#include "ClipWorkflow.h"
#include "StackedBuffer.hpp"
#include <QPointer>
#include <QQueue>
namespace Workflow
{
......@@ -38,23 +38,13 @@ class AudioClipWorkflow : public ClipWorkflow
Q_OBJECT
public:
class StackedBuffer : public ::StackedBuffer<Workflow::AudioSample*>
{
public:
StackedBuffer( Workflow::AudioSample* lvf, AudioClipWorkflow* poolHandler,
bool mustBeReleased = true);
virtual void release();
private:
QPointer<AudioClipWorkflow> m_poolHandler;
};
AudioClipWorkflow( ClipHelper* ch );
~AudioClipWorkflow();
void *getLockCallback() const;
void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode );
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:
virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const;
......@@ -63,7 +53,6 @@ class AudioClipWorkflow : public ClipWorkflow
virtual void releasePrealocated();
private:
void releaseBuffer( Workflow::AudioSample *sample );
void initVlcOutput();
Workflow::AudioSample* createBuffer( size_t size );
void insertPastBlock( Workflow::AudioSample* as );
......@@ -78,8 +67,8 @@ class AudioClipWorkflow : public ClipWorkflow
private:
QQueue<Workflow::AudioSample*> m_computedBuffers;
QQueue<Workflow::AudioSample*> m_availableBuffers;
qint64 m_ptsOffset;
qint64 m_ptsOffset;
Workflow::AudioSample *m_lastReturnedBuffer;
static const quint32 nbBuffers = 256;
};
......
......@@ -31,8 +31,7 @@
ImageClipWorkflow::ImageClipWorkflow( ClipHelper *ch ) :
ClipWorkflow( ch ),
m_buffer( NULL ),
m_stackedBuffer( NULL )
m_buffer( NULL )
{
//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)
......@@ -90,7 +89,7 @@ ImageClipWorkflow::getOutput( ClipWorkflow::GetMode )
{
QMutexLocker lock( m_renderLock );
return m_stackedBuffer;
return m_buffer;
}
void
......@@ -101,7 +100,6 @@ ImageClipWorkflow::lock(ImageClipWorkflow *cw, void **pp_ret, int )
{
cw->m_buffer = new Workflow::Frame( MainWorkflow::getInstance()->getWidth(),
MainWorkflow::getInstance()->getHeight() );
cw->m_stackedBuffer = new StackedBuffer( cw->m_buffer );
}
*pp_ret = cw->m_buffer->buffer();
}
......@@ -139,14 +137,3 @@ void
ImageClipWorkflow::flushComputedBuffers()
{
}
ImageClipWorkflow::StackedBuffer::StackedBuffer( Workflow::Frame *frame ) :
::StackedBuffer<Workflow::Frame*>( frame, false )
{
}
void
ImageClipWorkflow::StackedBuffer::release()
{
return ;
}
......@@ -24,19 +24,12 @@
#define IMAGECLIPWORKFLOW_H
#include "ClipWorkflow.h"
#include "StackedBuffer.hpp"
class ImageClipWorkflow : public ClipWorkflow
{
Q_OBJECT
public:
class StackedBuffer : public ::StackedBuffer<Workflow::Frame*>
{
public:
StackedBuffer( Workflow::Frame* frame );
virtual void release();
};
ImageClipWorkflow( ClipHelper* ch );
~ImageClipWorkflow();
......@@ -44,7 +37,7 @@ class ImageClipWorkflow : public ClipWorkflow
void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode );
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:
virtual void initVlcOutput();
virtual quint32 getNbComputedBuffers() const;
......@@ -59,7 +52,6 @@ class ImageClipWorkflow : public ClipWorkflow
qint64 pts );
private:
Workflow::Frame *m_buffer;
StackedBuffer *m_stackedBuffer;
private slots:
void stopComputation();
......
......@@ -35,6 +35,7 @@
#include "Workflow/Types.h"
#include <QDomElement>
#include <QMutex>
Workflow::Frame *MainWorkflow::blackOutput = NULL;
......
/*****************************************************************************
* StackedBuffer.hpp: A buffer that must can be released and pushed back on a Pool.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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.
*****************************************************************************/
#ifndef STACKEDBUFFER_HPP
#define STACKEDBUFFER_HPP
#include <QtDebug>
#include "Pool.hpp"
template <typename T>
class StackedBuffer
{
public:
StackedBuffer( T buff, bool mustBeReleased = true ) :
m_buff( buff ),
m_mustRelease( mustBeReleased )
{
}
virtual ~StackedBuffer()
{
}
/// \warning Calling this method will definitely invalidate the pointer;
virtual void release() = 0;
const T& get() const
{
return m_buff;
}
T get()
{
return m_buff;
}
operator const T&() const
{
return get();
}
operator T()
{
return get();
}
protected:
T m_buff;
bool m_mustRelease;
};
#endif // STACKEDBUFFER_HPP
......@@ -33,18 +33,17 @@
#include "VideoClipWorkflow.h"
#include "vlmc.h"
#include <QReadWriteLock>
#include <QDomDocument>
#include <QDomElement>
#include <QMutex>
#include <QReadWriteLock>
#include <QtDebug>
TrackWorkflow::TrackWorkflow( MainWorkflow::TrackType type ) :
m_length( 0 ),
m_trackType( type ),
m_lastFrame( 0 ),
m_videoStackedBuffer( NULL ),
m_audioStackedBuffer( NULL )
m_lastFrame( 0 )
{
m_renderOneFrameMutex = new QMutex;
m_clipsLock = new QReadWriteLock;
......@@ -263,36 +262,19 @@ TrackWorkflow::stop()
stopClipWorkflow( it.value() );
++it;
}
releasePreviousRender();
m_lastFrame = 0;
}
void
TrackWorkflow::releasePreviousRender()
{
if ( m_audioStackedBuffer != NULL )
{
m_audioStackedBuffer->release();
m_audioStackedBuffer = NULL;
}
if ( m_videoStackedBuffer != NULL )
{
m_videoStackedBuffer->release();
m_videoStackedBuffer = NULL;
}
}
void*
TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{
releasePreviousRender();
QReadLocker lock( m_clipsLock );
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
bool needRepositioning;
void *ret = NULL;
StackedBuffer<Workflow::Frame*> *frames[EffectsEngine::MaxFramesForMixer];
Workflow::Frame *frames[EffectsEngine::MaxFramesForMixer];
quint32 frameId = 0;
bool renderOneFrame = false;
......@@ -330,11 +312,9 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
renderOneFrame, paused );
if ( m_trackType == MainWorkflow::VideoTrack )
{
frames[frameId] = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
frames[frameId] = reinterpret_cast<Workflow::Frame*>( ret );
++frameId;
}
else
m_audioStackedBuffer = reinterpret_cast<StackedBuffer<Workflow::AudioSample*>*>( ret );
}
//Is it about to be rendered?
else if ( start > currentFrame &&
......@@ -353,40 +333,22 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{
//FIXME: We don't handle mixer3 yet.
mixer->effect->process( currentFrame * 1000.0 / m_fps,
frames[0]->get()->buffer(),
frames[1] != NULL ? frames[1]->get()->buffer() : MainWorkflow::blackOutput->buffer(),
frames[0]->buffer(),
frames[1] != NULL ? frames[1]->buffer() : MainWorkflow::blackOutput->buffer(),
NULL, m_mixerBuffer->buffer() );
m_mixerBuffer->ptsDiff = frames[0]->get()->ptsDiff;
//The rest of the code uses stackedbuffer, m_mixerBuffer is just a Frame*
for ( quint32 i = 0; i < EffectsEngine::MaxFramesForMixer; ++i )
{
if ( frames[i] != NULL )
frames[i]->release();
else
break;
}
m_mixerBuffer->ptsDiff = frames[0]->ptsDiff;
m_lastFrame = subFrame;
return m_mixerBuffer;
}
else //If no mixer, clean the potentially rendered extra frames.
{
for ( quint32 i = 1; i < EffectsEngine::MaxFramesForMixer; ++i )
{
if ( frames[i] != NULL )
frames[i]->release();
else
break;
}
else //If there's no mixer, just use the first frame, ignore the rest. It will be cleaned by the responsible ClipWorkflow.
ret = frames[0];
m_videoStackedBuffer = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
}
}
m_lastFrame = subFrame;
if ( ret == NULL )
return NULL;
if ( m_trackType == MainWorkflow::VideoTrack )
return reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret )->get();
return reinterpret_cast<StackedBuffer<Workflow::AudioSample*>*>( ret )->get();
return reinterpret_cast<Workflow::Frame*>( ret );
return reinterpret_cast<Workflow::AudioSample*>( ret );
}
void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
......
......@@ -25,9 +25,9 @@
#include "EffectsEngine.h"
#include "MainWorkflow.h"
#include "StackedBuffer.hpp"
#include <QObject>
#include <QMap>
#include <QXmlStreamWriter>
class ClipWorkflow;
......@@ -36,8 +36,6 @@ class QDomElement;
class QDomElement;
template <typename T>
class QList;
template <typename T, typename U>
class QMap;
class QMutex;
class QReadWriteLock;
class QWaitCondition;
......@@ -101,7 +99,6 @@ class TrackWorkflow : public QObject
void preloadClip( ClipWorkflow* cw );
void stopClipWorkflow( ClipWorkflow* cw );
void adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw );
void releasePreviousRender();
private:
......@@ -120,8 +117,6 @@ class TrackWorkflow : public QObject
MainWorkflow::TrackType m_trackType;
qint64 m_lastFrame;
StackedBuffer<Workflow::Frame*>* m_videoStackedBuffer;
StackedBuffer<Workflow::AudioSample*>* m_audioStackedBuffer;
Workflow::Frame *m_mixerBuffer;
double m_fps;
};
......
......@@ -24,19 +24,20 @@
#include "FilterInstance.h"
#include "MainWorkflow.h"
#include "Media.h"
#include "StackedBuffer.hpp"
#include "VideoClipWorkflow.h"
#include "VLCMedia.h"
#include "WaitCondition.hpp"
#include "Workflow/Types.h"
#include <QReadWriteLock>
#include <QtDebug>
VideoClipWorkflow::VideoClipWorkflow( ClipHelper *ch ) :
ClipWorkflow( ch ),
m_width( 0 ),
m_height( 0 ),
m_renderedFrame( 0 )
m_renderedFrame( 0 ),
m_lastReturnedBuffer( NULL )
{
m_effectsLock = new QReadWriteLock();
m_renderedFrameMutex = new QMutex();
......@@ -122,6 +123,11 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
if ( m_lastReturnedBuffer != NULL )
{
m_availableBuffers.enqueue( m_lastReturnedBuffer );
m_lastReturnedBuffer = NULL;
}
if ( shouldRender() == false )
return NULL;
if ( getNbComputedBuffers() == 0 )
......@@ -129,11 +135,14 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
//Recheck again, as the WaitCondition may have been awaken when stopping.
if ( getNbComputedBuffers() == 0 )
return NULL;
::StackedBuffer<Workflow::Frame*>* buff;
Workflow::Frame *buff;
if ( mode == ClipWorkflow::Pop )
buff = new StackedBuffer( m_computedBuffers.dequeue(), this, true );
{
buff = m_computedBuffers.dequeue();
m_lastReturnedBuffer = buff;
}
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer( m_computedBuffers.head(), NULL, false );
buff = m_computedBuffers.head();
postGetOutput();
return buff;
}
......@@ -192,14 +201,6 @@ VideoClipWorkflow::getMaxComputedBuffers() const
return VideoClipWorkflow::nbBuffers;
}
void
VideoClipWorkflow::releaseBuffer( Workflow::Frame *frame )
{
QMutexLocker lock( m_renderLock );
m_availableBuffers.enqueue( frame );
}
void
VideoClipWorkflow::flushComputedBuffers()
{
......@@ -239,19 +240,3 @@ VideoClipWorkflow::setTime( qint64 time, qint64 frame )
}
ClipWorkflow::setTime( time, frame );
}
VideoClipWorkflow::StackedBuffer::StackedBuffer( Workflow::Frame *frame,
VideoClipWorkflow *poolHandler,
bool mustBeReleased) :
::StackedBuffer<Workflow::Frame*>( frame, mustBeReleased ),
m_poolHandler( poolHandler )
{
}
void
VideoClipWorkflow::StackedBuffer::release()
{
if ( m_mustRelease == true && m_poolHandler.isNull() == false )
m_poolHandler->releaseBuffer( m_buff );
delete this;
}
......@@ -25,10 +25,8 @@
#include "ClipWorkflow.h"
#include "EffectsEngine.h"
#include "StackedBuffer.hpp"
#include "Pool.hpp"
#include <QPointer>
#include <QQueue>
class Clip;
......@@ -37,16 +35,6 @@ class VideoClipWorkflow : public ClipWorkflow
Q_OBJECT
public:
class StackedBuffer : public ::StackedBuffer<Workflow::Frame*>
{
public:
StackedBuffer( Workflow::Frame* frame, VideoClipWorkflow* poolHandler,
bool mustBeReleased = true);
virtual void release();
private:
QPointer<VideoClipWorkflow> m_poolHandler;
};
VideoClipWorkflow( ClipHelper* ch );
~VideoClipWorkflow();
void *getLockCallback() const;
......@@ -62,7 +50,6 @@ class VideoClipWorkflow : public ClipWorkflow
virtual void initVlcOutput();
virtual quint32 getNbComputedBuffers() const;
virtual quint32 getMaxComputedBuffers() const;
void releaseBuffer( Workflow::Frame* frame );
virtual void flushComputedBuffers();
/**
* \brief Pre-allocate some image buffers.
......@@ -83,6 +70,7 @@ class VideoClipWorkflow : public ClipWorkflow
QReadWriteLock *m_effectsLock;
QMutex *m_renderedFrameMutex;
qint64 m_renderedFrame;
Workflow::Frame *m_lastReturnedBuffer;
QList<EffectsEngine::FilterHelper*> m_filters;
};
......
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