TrackWorkflow.h 5.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*****************************************************************************
 * TrackWorkflow.h : Will query the Clip workflow for each successive clip in the track
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * 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 TRACKWORKFLOW_H
#define TRACKWORKFLOW_H

26
#include "MainWorkflow.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
27
#include "StackedBuffer.hpp"
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <QObject>

class   ClipWorkflow;
class   LightVideoFrame;

class   QDomElement;
class   QDomElement;
template <typename T>
class   QList;
template <typename T, typename U>
class   QMap;
class   QMutex;
class   QReadWriteLock;
class   QWaitCondition;

44 45
//TODO: REMOVE THIS
#ifndef FPS
46
#define FPS     30
47
#endif
48

49 50 51 52
#ifndef MAX_TRACKS
#define MAX_TRACKS 64
#endif

53 54 55 56 57
class   TrackWorkflow : public QObject
{
    Q_OBJECT

    public:
58
        TrackWorkflow( unsigned int trackId, MainWorkflow::TrackType type );
59
        ~TrackWorkflow();
60

61 62
        void*                                   getOutput( qint64 currentFrame,
                                                           qint64 subFrame );
63
        qint64                                  getLength() const;
64
        void                                    stop();
65
        void                                    pause();
66
        void                                    unpause();
67 68
        void                                    moveClip( const QUuid& id, qint64 startingFrame );
        Clip*                                   removeClip( const QUuid& id );
69
        ClipWorkflow*                           removeClipWorkflow( const QUuid& id );
70
        void                                    addClip( Clip*, qint64 start );
71
        void                                    addClip( ClipWorkflow*, qint64 start );
72
        qint64                                  getClipPosition( const QUuid& uuid ) const;
73
        Clip*                                   getClip( const QUuid& uuid );
74

75
        //FIXME: this won't be reliable as soon as we change the fps from the configuration
76
        static const unsigned int               nbFrameBeforePreload = 60;
77

78
        void                                    save( QDomDocument& doc, QDomElement& trackNode ) const;
79
        void                                    clear();
80

81
        void                                    forceRepositionning();
82
        void                                    renderOneFrame();
83

84 85 86 87 88
        /**
         *  \sa     MainWorkflow::setFullSpeedRender();
         */
        void                                    setFullSpeedRender( bool val );

89
    private:
90
        void                                    computeLength();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
91
        void*                                   renderClip( ClipWorkflow* cw, qint64 currentFrame,
92 93
                                                            qint64 start, bool needRepositioning,
                                                            bool renderOneFrame );
94
        void                                    preloadClip( ClipWorkflow* cw );
95
        void                                    stopClipWorkflow( ClipWorkflow* cw );
96
        bool                                    checkEnd( qint64 currentFrame ) const;
97
        void                                    adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw );
98
        void                                    releasePreviousRender();
99

100

101
    private:
102 103
        unsigned int                            m_trackId;

104
        QMap<qint64, ClipWorkflow*>             m_clips;
105

106
        /**
107
         *  \brief      The track length in frames.
108 109
        */
        qint64                                  m_length;
110

111 112 113 114 115 116
        /**
         *  \brief      If a clip was moved, we may have to force repositionning.
         *              If this flag is set to true, we will force it anyway.
         */
        bool                                    m_forceRepositionning;
        QMutex*                                 m_forceRepositionningMutex;
117 118
        bool                                    m_renderOneFrame;
        QMutex                                  *m_renderOneFrameMutex;
119

120
        QReadWriteLock*                         m_clipsLock;
121 122

        bool                                    m_paused;
123

124
        MainWorkflow::TrackType                 m_trackType;
125
        qint64                                  m_lastFrame;
126 127
        StackedBuffer<LightVideoFrame*>*                    m_videoStackedBuffer;
        StackedBuffer<AudioClipWorkflow::AudioSample*>*     m_audioStackedBuffer;
128

129
    signals:
130
        void                                    trackEndReached( unsigned int );
131 132 133
};

#endif // TRACKWORKFLOW_H