WorkflowRenderer.h 10.8 KB
Newer Older
1
/*****************************************************************************
2
 * WorkflowRenderer.h: Render the main workflow
3
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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
#include "AudioClipWorkflow.h"
27 28
#include "GenericRenderer.h"
#include "MainWorkflow.h"
29

30 31 32 33 34 35 36 37 38
#include <QObject>

class   Clip;

class   QWidget;
class   QWaitCondition;
class   QMutex;
class   QUuid;

39
class   WorkflowRenderer : public GenericRenderer
40 41
{
    Q_OBJECT
42
    Q_DISABLE_COPY( WorkflowRenderer )
43 44

    public:
45 46 47 48
        /**
         *  \brief      Describes the different types of elementary streams
         *              that can be handled by the imem.
         */
49 50
        enum    EsType
        {
51 52 53 54
            Unknown, ///< Unknown type. Should never happen
            Audio, ///< Audio type
            Video, ///< Video type
            Subtitle ///< This is clearly not used by VLMC, but it fits imem module's model
55
        };
56 57 58 59
        /**
         *  \brief  This struct will be the type of the callback parameter
         *          in the lock / unlock callbacks
         */
60 61
        struct  EsHandler
        {
62 63
            WorkflowRenderer*   self; ///< The 'this' pointer will be passed in this field
            EsType              type; ///< The elementary stream type
64
        };
65

66
        WorkflowRenderer();
67
        ~WorkflowRenderer();
68

69 70 71 72 73
        /**
         *  \brief      Initialize the renderer.
         *
         *  This will set the imem string, instantiate EsHandlers, connect signals.
         */
74
        void                initializeRenderer();
75 76 77 78 79 80 81 82 83 84 85 86
        /**
         *  \brief          Play or pause the media.
         *
         *  When this method is called :
         *      - if the render has not started and forcePause is false, the render is started
         *      - if the render has not started and forcePause is true, nothing happens.
         *      - if the render has started and is not paused, the render will pause
         *      - if the render has started, and is paused, the render will unpause if
         *          forcePause is false.
         *  \param  forcePause  Will force the pause if true.
         *  \sa     stop()
         */
87
        virtual void        togglePlayPause( bool forcePause );
88
        /**
89 90 91 92
         *  \brief Stop the mainworkflow, but not the renderer.
         *
         *  In order to provide premanent feedback (ie stay in paused mode when not
         *  playing, we have to never stop the renderer.
93
         *  \sa togglePlayPause( bool );
94
         *  \sa killRenderer();
95
         */
96
        virtual void        stop();
97 98 99 100
        /**
         *  \brief Render the next frame
         *  \sa     previousFrame()
         */
101
        virtual void        nextFrame();
102 103 104 105
        /**
         *  \brief  Render the previous frame
         *  \sa     nextFrame();
         */
106
        virtual void        previousFrame();
107 108 109 110 111
        /**
         * \brief   Return the length in milliseconds
         * \return  The length of the underlying rendered target in milliseconds
         *  \sa     getLength()
         */
112
        virtual qint64      getLengthMs() const;
113 114 115

        virtual qint64      getLength() const;

116 117 118 119
        /**
         *  \brief  Return the current frame number
         *  \return The current frame
         */
120
        virtual qint64      getCurrentFrame() const;
121 122 123 124
        /**
         *  \brief Return the number of frames per second
         *  \return     The current fps
         */
125
        virtual float       getFps() const;
126

127 128 129 130 131 132 133 134
        /**
         *  \brief          Completely kill the renderer.
         *
         *  This will stop both mainworkflow and renderer thread.
         *  This should only be used when destroying the renderer.
         *  \sa             stop();
         */
        void                killRenderer();
135

136
    private:
137 138 139 140
        /**
         *  \brief          This is a subpart of the togglePlayPause( bool ) method
         *  \sa             togglePlayPause( bool );
         */
141
        void                internalPlayPause( bool forcePause );
142 143 144 145 146 147 148 149
        /**
         *  \brief          This is a subpart of the togglePlayPause( bool ) method
         *
         *  It starts the render by launching the media player that will query the
         *  lock and unlock callbacks, thus querying the MainWorkflow for frames and
         *  audio samples
         *  \sa             togglePlayPause( bool );
         */
150 151
        virtual void        startPreview();

152
    protected:
153 154 155 156 157 158 159 160 161
        /**
         *  \brief          Will return a pointer to the function/static method to use
         *                  as the imem lock callback.
         *  This method is provided to allow renderers to inherit from this class,
         *  without having to reimplement the initializeRenderer() method, that uses
         *  both getLockCallback() and getUnlockCallback()
         *  \return         A pointer to the lock function.
         *  \sa             getUnlockCallback()
         */
162
        virtual void*       getLockCallback();
163 164 165 166 167 168 169 170 171
        /**
         *  \brief          Will return a pointer to the function/static method to use
         *                  as the imem unlock callback.
         *  This method is provided to allow renderers to inherit from this class,
         *  without having to reimplement the initializeRenderer() method, that uses
         *  both getLockCallback() and getUnlockCallback()
         *  \return         A pointer to the unlock function.
         *  \sa             getLockCallback()
         */
172
        virtual void*       getUnlockCallback();
173 174 175 176 177 178 179 180 181 182 183
        /**
         *  \brief              Lock callback for imem module
         *
         *  This callback will query the MainWorkflow for a frame or an audio sample
         *  \param  data        The callback data, this is most likely to be an EsHandler
         *  \param  dts         Unused, but provided by imem
         *  \param  pts         The pts for the buffer that will be provided
         *  \param  flags       Unused but provided by imem
         *  \param  bufferSize  The size of the buffer that will be provided
         *  \param  buffer      The buffer itself.
         */
184 185
        static int          lock( void *data, qint64 *dts, qint64 *pts,
                                quint32 *flags, size_t *bufferSize, void **buffer );
186 187 188 189 190 191 192
        /**
         *  \brief  "Subcallback", for video frame injection
         *
         *  \param  pts         The pts for the buffer that will be provided
         *  \param  bufferSize  The size of the buffer that will be provided
         *  \param  buffer      The buffer itself.
         */
193
        int                 lockVideo( qint64 *pts, size_t *bufferSize, void **buffer );
194 195 196 197 198 199 200
        /**
         *  \brief  "Subcallback", for audio sample injection
         *
         *  \param  pts         The pts for the buffer that will be provided
         *  \param  bufferSize  The size of the buffer that will be provided
         *  \param  buffer      The buffer itself.
         */
201
        int                 lockAudio( qint64 *pts, size_t *bufferSize, void **buffer );
202 203 204 205 206 207 208 209
        /**
         *  \brief  unlock callback for the imem module
         *
         *  \param  data        The callback data, this is most likely to be an EsHandler
         *  \param  buffSize    The size of the buffer
         *  \param  buffer      The buffer to be released
         */
        static void         unlock( void *data, size_t buffSize, void *buffer );
210

211
    protected:
212
        MainWorkflow*       m_mainWorkflow;
213
        LibVLCpp::Media*    m_media;
214
        bool                m_stopping;
215
        float               m_outputFps;
216
        unsigned char*	    m_renderVideoFrame;
217

218
    private:
219 220 221 222
        /**
         *  \brief          When there's no sound to play, this is the buffer that'll
         *                  be injected
         */
223
        static quint8*      silencedAudioBuffer;
224
        size_t              m_videoBuffSize;
225 226
        EsHandler*          m_videoEsHandler;
        EsHandler*          m_audioEsHandler;
227 228 229 230 231
        /**
         *  \brief          This isn't exactly the current PTS.
         *                  It's the number of frame rendered since the render has started.
         */
        qint64              m_pts;
232
        qint64              m_audioPts;
233 234 235 236 237 238 239
        quint32             m_nbChannels;
        quint32             m_rate;
        /**
         *  \brief          Used in permanent rendering mode, to know is some operations
         *                  has to be performed.
         */
        qint64              m_oldLength;
240

241

242
    public slots:
243 244 245
        /**
         *  \brief          Unused from this renderer.
         */
246
        virtual void        setClip( Clip* ){}
247 248 249
        /**
         *  \brief          Unused from this renderer.
         */
250
        virtual void        setMedia( Media* ) {}
251 252 253
        /**
         *  \brief          Unused from this renderer.
         */
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
254
        void                mediaUnloaded( const QUuid& ) {}
255 256 257
        /**
         *  \brief          The current frame just changed because of the timeline cursor
         */
258
        void                timelineCursorChanged( qint64 newFrame );
259 260 261
        /**
         *  \brief          The current frame just changed because of the timeline ruler
         */
262
        void                rulerCursorChanged( qint64 newFrame );
263 264 265
        /**
         *  \brief          The current frame just changed because of the preview widget
         */
266
        void                previewWidgetCursorChanged( qint64 newFrame );
267 268 269 270
        /**
         *  \brief          Called when the workflow end is reached.
         *  \sa             stop();
         */
271
        void                __endReached();
272 273

    private slots:
274 275 276 277 278 279 280
        /**
         *  \brief          Used to launch "permanent playback", as soon as the length
         *                  first changed to a non zero value.
         *
         *  If the length comes to a 0 value again, the permanent playback will be stoped.
         */
        void                mainWorkflowLenghtChanged( qint64 newLength );
281

282 283
};

284
#endif // WORKFLOWRENDERER_H