WorkflowRenderer.h 6.6 KB
Newer Older
1
/*****************************************************************************
2
 * WorkflowRenderer.h: Render the main workflow
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *****************************************************************************
 * 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.
 *****************************************************************************/

23 24
#ifndef WORKFLOWRENDERER_H
#define WORKFLOWRENDERER_H
25

26

27 28
#include <QObject>
#include <QWidget>
29
#include <QStack>
30 31

#include "Workflow/MainWorkflow.h"
32
#include "GenericRenderer.h"
33
#include "StackedAction.hpp"
34
#include "ActionStack.h"
35
#include "AudioClipWorkflow.h"
36

37
class   WorkflowRenderer : public GenericRenderer
38 39
{
    Q_OBJECT
40
    Q_DISABLE_COPY( WorkflowRenderer )
41 42

    public:
43 44 45 46 47 48 49 50 51 52 53 54
        enum    EsType
        {
            Unknown,
            Audio,
            Video,
            Subtitle //This is clearly not used by VLMC, but it fits imem module's model
        };
        struct  EsHandler
        {
            WorkflowRenderer*   self;
            EsType              type;
        };
55

56
        WorkflowRenderer();
57
        ~WorkflowRenderer();
58

59
        void                initializeRenderer();
60
        virtual void        togglePlayPause( bool forcePause );
61
        virtual void        stop();
62 63
        virtual void        nextFrame();
        virtual void        previousFrame();
64
        virtual qint64      getLengthMs() const;
65
        virtual qint64      getCurrentFrame() const;
66
        virtual float       getFps() const;
67
        void                addClip( Clip* clip, uint32_t trackId, qint64 startingPos, MainWorkflow::TrackType trackType );
68
        void                removeClip( const QUuid& uuid, uint32_t trackId, MainWorkflow::TrackType trackType );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
69 70 71 72 73 74 75 76 77 78 79 80
        /**
         *  \brief                  Will split a clip and return the created clip, resulting of the split operation.
         *  \param  toSplit         The clip to split
         *  \param  newClip         If the "toSplit" clip already has been splitted, this is the clip resulting
         *                          from the previous split operation. This prevent creating and deleting clip that could be used elsewhere.
         *  \param  trackId         The track containing the clip
         *  \param  newClipPos      The position of the "newClip" on the timeline.
         *  \param  newClipBegin    The starting frame (from the beginning of the clip's parent media)
         *  \param  trackType       The track type (audio or video)
         *  \return                 The newly created clip if "newClip" was NULL; else, newClip is returned.
         */
        Clip*               split( Clip* toSplit, Clip* newClip, uint32_t trackId, qint64 newClipPos, qint64 newClipBegin, MainWorkflow::TrackType trackType );
81
        void                unsplit( Clip* origin, Clip* splitted, uint32_t trackId, MainWorkflow::TrackType trackType );
82 83 84 85 86 87
        /**
         *  \param  undoRedoAction: if true, the potential move resulting from the resize will be emmited to the GUI.
         *                          if this is not an undo redo action, the GUI is already aware of the move.
         */
        void                resizeClip( Clip* clip, qint64 newBegin, qint64 newEnd, qint64 newPos,
                                        uint32_t trackId, MainWorkflow::TrackType trackType, bool undoRedoAction = false );
88

89
        static int          lock( void *data, int64_t *dts, int64_t *pts, unsigned int *flags, size_t *bufferSize, void **buffer );
90 91
        static int          lockVideo( WorkflowRenderer* self, int64_t *pts, size_t *bufferSize, void **buffer );
        static int          lockAudio( WorkflowRenderer* self, int64_t *pts, size_t *bufferSize, void **buffer );
92
        static void         unlock( void *data, size_t buffSize, void *buffer );
93

94
    private:
95
        void                internalPlayPause( bool forcePause );
96
        virtual void        startPreview();
97
        void                checkActions();
98

99 100 101 102
    protected:
        virtual void*       getLockCallback();
        virtual void*       getUnlockCallback();

103
    protected:
104
        MainWorkflow*       m_mainWorkflow;
105
        LibVLCpp::Media*    m_media;
106
        bool                m_stopping;
107
        float               m_outputFps;
108

109
    private:
110
        unsigned char*	    m_renderVideoFrame;
111 112 113 114
        /**
         *  \brief          When there's no sound to play, this is the buffer that'll
         *                  be injected
         */
115
        static uint8_t*             silencedAudioBuffer;
116
        size_t              m_videoBuffSize;
117
        AudioClipWorkflow::AudioSample*     m_renderAudioSample;
118
        Action::Stack       m_actions;
119
        QMutex*             m_actionsMutex;
120
        QWaitCondition*     m_waitCond;
121 122
        EsHandler*          m_videoEsHandler;
        EsHandler*          m_audioEsHandler;
123 124 125 126 127
        /**
         *  \brief          This isn't exactly the current PTS.
         *                  It's the number of frame rendered since the render has started.
         */
        qint64              m_pts;
128
        qint64              m_audioPts;
129
        uint32_t            m_nbChannels;
130
        uint32_t            m_rate;
131

132

133
    public slots:
134 135
        virtual void        setClip( Clip* ){}
        virtual void        setMedia( Media* ) {}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
136
        void                mediaUnloaded( const QUuid& ) {}
137
        void                timelineCursorChanged( qint64 newFrame );
138
        void                rulerCursorChanged( qint64 newFrame );
139
        void                previewWidgetCursorChanged( qint64 newFrame );
140

141
        virtual void        __frameChanged( qint64 frame, MainWorkflow::FrameChangedReason );
142 143 144 145
        void                __videoPaused();
        void                __videoStopped();
        void                __videoPlaying();
        void                __endReached();
146 147 148 149 150

    private slots:
        void                mainWorkflowPaused();
        void                mainWorkflowUnpaused();

151 152
};

153
#endif // WORKFLOWRENDERER_H