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

Tracks: Removing the "hard deactivated" state, and using the deactivated one for muting tracks.

Aka code simplification before adding mixers.
parent b98ca6ef
......@@ -32,7 +32,7 @@ template <typename T>
class Toggleable
{
public:
Toggleable() : m_ptr( NULL ), m_activated( true ), m_hardDeactivated( false )
Toggleable() : m_ptr( NULL ), m_activated( true )
{
}
void setPtr( T ptr )
......@@ -51,15 +51,11 @@ class Toggleable
}
bool activated() const
{
return ( m_hardDeactivated == false && m_activated == true );
return m_activated;
}
bool deactivated() const
{
return ( m_hardDeactivated == true || m_activated == false );
}
bool hardDeactivated() const
{
return m_hardDeactivated;
return !m_activated;
}
void activate()
{
......@@ -69,15 +65,9 @@ class Toggleable
{
m_activated = false;
}
void setHardDeactivation( bool val )
{
m_hardDeactivated = val;
}
private:
T m_ptr;
bool m_activated;
bool m_hardDeactivated;
};
#endif // TOGGLEABLE_HPP
......@@ -267,13 +267,6 @@ MainWorkflow::setCurrentFrame( qint64 currentFrame, MainWorkflow::FrameChangedRe
{
QWriteLocker lock( m_currentFrameLock );
if ( m_renderStarted == true )
{
//Since any track can be reactivated, we reactivate all of them, and let them
//disable themself if required.
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i)
m_tracks[i]->activateAll();
}
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i)
m_currentFrame[i] = currentFrame;
emit frameChanged( currentFrame, reason );
......
......@@ -3,7 +3,7 @@
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -29,14 +29,15 @@
TrackHandler::TrackHandler( unsigned int nbTracks, MainWorkflow::TrackType trackType ) :
m_trackCount( nbTracks ),
m_nbRenderingTracks( 0 ),
m_trackType( trackType ),
m_length( 0 )
{
m_tracks = new Toggleable<TrackWorkflow*>[nbTracks];
for ( unsigned int i = 0; i < nbTracks; ++i )
{
m_tracks[i].setPtr( new TrackWorkflow( i, trackType ) );
connect( m_tracks[i], SIGNAL( trackEndReached( unsigned int ) ), this, SLOT( trackEndReached(unsigned int) ), Qt::DirectConnection );
m_tracks[i].setPtr( new TrackWorkflow( trackType ) );
connect( m_tracks[i], SIGNAL( trackEndReached() ), this, SLOT( trackEndReached() ), Qt::DirectConnection );
}
}
......@@ -58,10 +59,6 @@ TrackHandler::addClip( ClipHelper* ch, unsigned int trackId, qint64 start )
//Now check if this clip addition has changed something about the workflow's length
if ( m_tracks[trackId]->getLength() > m_length )
m_length = m_tracks[trackId]->getLength();
//if the track is deactivated, we need to reactivate it.
if ( m_tracks[trackId].deactivated() == true )
activateTrack( trackId );
}
void
......@@ -81,7 +78,7 @@ TrackHandler::startRender()
{
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
activateTrack( i );
m_nbRenderingTracks.fetchAndAddAcquire( 1 );
m_tracks[i]->preload();
}
}
......@@ -111,55 +108,33 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{
for ( int i = m_trackCount - 1; i >= 0; --i )
{
if ( m_tracks[i].activated() == false || m_tracks[i]->hasFrameToRender( currentFrame ) )
continue ;
if ( m_trackType == MainWorkflow::VideoTrack )
{
if ( m_tracks[i].activated() == false )
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
StackedBuffer<Workflow::Frame*> *buff = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
if ( ret == NULL )
continue ;
else
{
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
StackedBuffer<Workflow::Frame*> *buff = reinterpret_cast<StackedBuffer<Workflow::Frame*>*>( ret );
if ( ret == NULL )
continue ;
else
return buff->get();
}
return buff->get();
}
else
{
if ( m_tracks[i].activated() == true )
{
//If paused is false at this point, there's probably something wrong...
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
//m_tmpAudioBuffer is NULl by default, so it will remain NULL if we continue;
if ( ret == NULL )
continue ;
StackedBuffer<Workflow::AudioSample*>* stackedBuffer =
reinterpret_cast<StackedBuffer<Workflow::AudioSample*>*> ( ret );
if ( stackedBuffer != NULL )
return stackedBuffer->get();
}
//If paused is false at this point, there's probably something wrong...
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
//m_tmpAudioBuffer is NULl by default, so it will remain NULL if we continue;
if ( ret == NULL )
continue ;
StackedBuffer<Workflow::AudioSample*>* stackedBuffer =
reinterpret_cast<StackedBuffer<Workflow::AudioSample*>*> ( ret );
if ( stackedBuffer != NULL )
return stackedBuffer->get();
}
}
return NULL;
}
void
TrackHandler::activateAll()
{
for ( unsigned int i = 0; i < m_trackCount; ++i )
activateTrack( i );
}
void
TrackHandler::activateTrack( unsigned int trackId )
{
if ( m_tracks[trackId]->getLength() > 0 )
m_tracks[trackId].activate();
else
m_tracks[trackId].deactivate();
}
qint64
TrackHandler::getClipPosition( const QUuid &uuid, unsigned int trackId ) const
{
......@@ -172,10 +147,7 @@ void
TrackHandler::stop()
{
for (unsigned int i = 0; i < m_trackCount; ++i)
{
if ( m_tracks[i].activated() == true )
m_tracks[i]->stop();
}
m_tracks[i]->stop();
}
void
......@@ -188,14 +160,11 @@ TrackHandler::moveClip(const QUuid &clipUuid, unsigned int oldTrack,
{
//And now, just move the clip.
m_tracks[newTrack]->moveClip( clipUuid, startingFrame );
activateTrack( newTrack );
}
else
{
ClipWorkflow* cw = m_tracks[oldTrack]->removeClipWorkflow( clipUuid );
m_tracks[newTrack]->addClip( cw, startingFrame );
activateTrack( oldTrack );
activateTrack( newTrack );
}
computeLength();
}
......@@ -207,20 +176,19 @@ TrackHandler::removeClip( const QUuid& uuid, unsigned int trackId )
Clip* clip = m_tracks[trackId]->removeClip( uuid );
computeLength();
activateTrack( trackId );
return clip;
}
void
TrackHandler::muteTrack( unsigned int trackId )
{
m_tracks[trackId].setHardDeactivation( true );
m_tracks[trackId].deactivate();
}
void
TrackHandler::unmuteTrack( unsigned int trackId )
{
m_tracks[trackId].setHardDeactivation( false );
m_tracks[trackId].activate();
}
Clip*
......@@ -248,15 +216,11 @@ TrackHandler::endIsReached() const
}
void
TrackHandler::trackEndReached( unsigned int trackId )
TrackHandler::trackEndReached()
{
m_tracks[trackId].deactivate();
for ( unsigned int i = 0; i < m_trackCount; ++i)
{
if ( m_tracks[i].activated() == true )
return ;
}
qDebug() << "deactivated track. remaining:" << m_nbRenderingTracks - 1;
if ( m_nbRenderingTracks.fetchAndAddAcquire( -1 ) != 1 )
return ;
m_endReached = true;
emit tracksEndReached();
}
......
......@@ -3,7 +3,7 @@
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -64,7 +64,6 @@ class TrackHandler : public QObject
*/
void *getOutput( qint64 currentFrame, qint64 subFrame,
bool paused );
void activateAll();
qint64 getClipPosition( const QUuid& uuid, unsigned int trackId ) const;
void stop();
void moveClip( const QUuid& clipUuid, unsigned int oldTrack,
......@@ -106,11 +105,11 @@ class TrackHandler : public QObject
private:
void computeLength();
void activateTrack( unsigned int tracKId );
private:
Toggleable<TrackWorkflow*>* m_tracks;
unsigned int m_trackCount;
QAtomicInt m_nbRenderingTracks;
MainWorkflow::TrackType m_trackType;
qint64 m_length;
unsigned int m_highestTrackNumber;
......@@ -118,7 +117,7 @@ class TrackHandler : public QObject
private slots:
void trackEndReached( unsigned int trackId );
void trackEndReached();
signals:
void tracksEndReached();
......
......@@ -37,8 +37,7 @@
#include <QtDebug>
TrackWorkflow::TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type ) :
m_trackId( trackId ),
TrackWorkflow::TrackWorkflow( MainWorkflow::TrackType type ) :
m_length( 0 ),
m_trackType( type ),
m_lastFrame( 0 ),
......@@ -233,7 +232,7 @@ TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
}
bool
TrackWorkflow::checkEnd( qint64 currentFrame ) const
TrackWorkflow::hasFrameToRender( qint64 currentFrame ) const
{
if ( m_clips.size() == 0 )
return true;
......@@ -289,14 +288,14 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
bool needRepositioning;
void* ret = NULL;
void *ret = NULL;
bool renderOneFrame = false;
if ( m_lastFrame == -1 )
m_lastFrame = currentFrame;
if ( checkEnd( currentFrame ) == true )
if ( hasFrameToRender( currentFrame ) == true )
{
emit trackEndReached( m_trackId );
emit trackEndReached();
//We continue, as there can be ClipWorkflow that requires to be stopped.
}
{
......@@ -369,8 +368,6 @@ void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
}
++it;
}
qDebug() << "Track" << m_trackId << "was asked to move clip" << id << "to position" << startingFrame
<< "but this clip doesn't exist in this track";
}
Clip* TrackWorkflow::removeClip( const QUuid& id )
......@@ -392,7 +389,7 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
cw->disconnect();
delete cw;
if ( m_length == 0 )
emit trackEndReached( m_trackId );
emit trackEndReached();
return clip;
}
++it;
......
......@@ -46,7 +46,7 @@ class TrackWorkflow : public QObject
Q_OBJECT
public:
TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type );
TrackWorkflow( MainWorkflow::TrackType type );
~TrackWorkflow();
void* getOutput( qint64 currentFrame,
......@@ -89,6 +89,7 @@ class TrackWorkflow : public QObject
bool contains( const QUuid& uuid ) const;
void stopFrameComputing();
bool hasFrameToRender( qint64 currentFrame ) const;
private:
void computeLength();
......@@ -97,14 +98,11 @@ class TrackWorkflow : public QObject
bool renderOneFrame, bool paused );
void preloadClip( ClipWorkflow* cw );
void stopClipWorkflow( ClipWorkflow* cw );
bool checkEnd( qint64 currentFrame ) const;
void adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw );
void releasePreviousRender();
private:
unsigned int m_trackId;
QMap<qint64, ClipWorkflow*> m_clips;
/**
......@@ -123,7 +121,7 @@ class TrackWorkflow : public QObject
StackedBuffer<Workflow::AudioSample*>* m_audioStackedBuffer;
signals:
void trackEndReached( unsigned int );
void trackEndReached();
};
#endif // TRACKWORKFLOW_H
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