TrackWorkflow.h 5.59 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 26 27 28
/*****************************************************************************
 * 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

#include <QObject>
#include <QMutex>
#include <QWaitCondition>
29
#include <QMap>
30
#include <QList>
31
#include <QReadWriteLock>
32
#include <QDomElement>
33 34

#include "ClipWorkflow.h"
35
#include "LightVideoFrame.h"
36

37 38
//TODO: REMOVE THIS
#ifndef FPS
39
#define FPS     30
40
#endif
41

42 43 44 45
#ifndef MAX_TRACKS
#define MAX_TRACKS 64
#endif

46 47 48 49 50
class   TrackWorkflow : public QObject
{
    Q_OBJECT

    public:
51 52 53
        enum    TrackType
        {
            Video,
54
            Audio,
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
55
            NbType
56 57
        };
        TrackWorkflow( unsigned int trackId, TrackType type );
58
        ~TrackWorkflow();
59

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

73 74 75
        /**
         *  Returns the output that has been computed in synchrone mode.
         */
76
        void*                                   getSynchroneOutput();
77

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

81
        void                                    save( QDomDocument& doc, QDomElement& trackNode ) const;
82
        void                                    clear();
83

84
        void                                    setFullSpeedRender( bool value );
85
        void                                    forceRepositionning();
86

87
    private:
88
        void                                    computeLength();
89
        void                                    renderClip( ClipWorkflow* cw, qint64 currentFrame,
90
                                                            qint64 start, bool needRepositioning );
91
        void                                    preloadClip( ClipWorkflow* cw );
92
        void                                    stopClipWorkflow( ClipWorkflow* cw );
93
        bool                                    checkEnd( qint64 currentFrame ) const;
94
        void                                    adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw );
95
        void                                    disconnectClipWorkflow( ClipWorkflow* cw );
96

97

98
    private:
99 100
        unsigned int                            m_trackId;

101
        QMap<qint64, ClipWorkflow*>             m_clips;
102

103
        /**
104
         *  \brief      The track length in frames.
105 106
        */
        qint64                                  m_length;
107

108 109 110 111 112 113 114
        /**
         *  \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;

115
        QReadWriteLock*                         m_clipsLock;
116 117

        bool                                    m_paused;
118

119
        QAtomicInt                              m_nbClipToPause;
120
        QAtomicInt                              m_nbClipToUnpause;
121 122
        QAtomicInt                              m_nbClipToRender;

123
        void*                                   m_synchroneRenderBuffer;
124

125 126
        TrackType                               m_trackType;

127 128
    private slots:
        void                                    clipWorkflowPaused();
129
        void                                    clipWorkflowUnpaused();
130
        void                                    clipWorkflowRenderCompleted( ClipWorkflow* );
131

132
    signals:
133 134
        void                                    trackEndReached( unsigned int );
        void                                    trackPaused();
135
        void                                    trackUnpaused();
136
        void                                    renderCompleted( unsigned int );
137 138 139
};

#endif // TRACKWORKFLOW_H