GenericRenderer.h 6.81 KB
Newer Older
1
/*****************************************************************************
2
 * GenericRenderer.h: Describe a common behavior for every renderers
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 GENERICRENDERER_H
#define GENERICRENDERER_H
25

26
27
#include "config.h"

28
#include <QObject>
29
30
31
#ifdef WITH_GUI
# include <QWidget>
#endif
32

33
#include "MainWorkflow.h"
34

35
36
37
class   Clip;
class   Media;
class   QUuid;
38
39
40
41
namespace LibVLCpp
{
    class   MediaPlayer;
}
42

43
44
45
/**
 *  \class  Common base for every renderer.
 */
46
class   GenericRenderer : public QObject
47
48
{
    Q_OBJECT
49
    Q_DISABLE_COPY( GenericRenderer );
50
51

public:
52
53
    explicit GenericRenderer();
    virtual ~GenericRenderer();
54

55
#ifdef WITH_GUI
56
57
58
59
60
    /**
     *  \brief  Set the widget used for rendering the output.
     *  \param  renderWidget    The widget to use for render.
     *  \sa     setPreviewLabel( QLabel* )
     */
61
    void                setRenderWidget( QWidget* renderWidget );
62
#endif
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    /**
     *  \brief          Play or pause the media.
     *
     *  This method is renderer dependant. It has to be implemented in the
     *  underlying renderer implementation.
     *  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()
     */
    virtual void        togglePlayPause( bool forcePause = false ) = 0;
78
79

    /**
80
81
     *  \brief Render the next frame
     *  \sa     previousFrame()
82
     */
83
    virtual void                    nextFrame() = 0;
84
85

    /**
86
87
     *  \brief  Render the previous frame
     *  \sa     nextFrame();
88
     */
89
    virtual void                    previousFrame() = 0;
90
91

    /**
92
93
     *  \brief Stop the renderer.
     *  \sa togglePlayPause( bool );
94
     */
95
    virtual void                    stop() = 0;
96
97

    /**
98
99
100
     * \brief   Return the length in milliseconds
     * \return  The length of the underlying rendered target in milliseconds
     *  \sa     getLength()
101
     */
102
    virtual qint64                  getLengthMs() const = 0;
103
104

    /**
105
106
     *  \brief  Return the current frame number
     *  \return The current frame
107
     */
108
    virtual qint64                  getCurrentFrame() const = 0;
109
110

    /**
111
112
     *  \brief Return the number of frames per second
     *  \return     The current fps
113
     */
114
    virtual float                   getFps() const = 0;
115

116
    /**
117
118
119
120
121
     *  \brief      Return the length in frames
     *  \warning    The returned value may not be accurate as it depends on FPS, that
     *              can be badly computed
     *  \return     The length that has to be rendered in frames
     *  \sa         getLengthMs()
122
     */
123
    virtual qint64                  getLength() const = 0;
124
125

    /**
126
127
     *  \brief  Return true if the renderer is paused
     *  \return true if the renderer is paused. false otherwise.
128
     */
129
130
131
132
    bool                            isPaused() const
    {
        return m_paused;
    }
133
134

    /**
135
136
137
138
     *  \brief      Return true if the renderer is currently rendering.
     *  \return     true if the renderer is currently rendering. false otherwise.
     *              Note that a paused renderer is still rendering
     *  \sa         isPaused()
139
     */
140
141
142
143
    bool                            isRendering() const
    {
        return m_isRendering;
    }
144
145

protected:
146
147
148
    /**
     *  \brief  The media player that will be used for rendering
     */
149
    LibVLCpp::MediaPlayer*          m_mediaPlayer;
150
151
152
153
    /**
     *  \brief  This flag allows us to know if the render is paused
     *          or not, without using libvlc, especially for the render preview.
     *  If the video is stopped, then this flag will be equal to false
154
     *  \warning    This is not thread safe.
155
     *  \sa         isPaused()
156
157
     */
    bool                            m_paused;
158

159
    /**
160
161
     *  \brief  Will be equal to true if a render has been started, even if it paused.
     *  \sa     isRendering()
162
163
164
     */
    bool                            m_isRendering;

165
166
167
168
    /**
     *  \brief      The QWidget on which we will render.
     *  \sa         setRenderWidget( QWidget* );
     */
169
    QWidget*                        m_renderWidget;
170

171
public slots:
172
173
174
    /**
     *  \brief      This SLOT has to be called when the render ends.
     */
175
    virtual void                    __endReached() = 0;
176
177
178
179
180
181
182
    /**
     *  \brief      This SLOT will be called when the time cursor has changed.
     *
     *  This mainly means that the current rendered frame should change.
     *  \param      newFrame    The new frame to render from.
     */
    virtual void                    previewWidgetCursorChanged( qint64 newFrame ) = 0;
183

184
185

signals:
186
187
188
189
    /**
     *  \brief  This signal means the render just finished, and has been stoped.
     *  \sa     endReached()
     */
190
    void                            stopped();
191
192
193
194
    /**
     *  \brief  Emmited when the render has been paused.
     *  \sa     playing()
     */
195
    void                            paused();
196
197
198
199
    /**
     *  \brief  Emmited when the renderer has started to render, and has been unpaused.
     *  \sa     paused()
     */
200
    void                            playing();
201
202
203
204
205
206
207
208
209
210
211
212
213
    /**
     *  \brief  Emmited when rendered frame has been changed.
     *  \param  newFrame    The new current frame
     *  \param  reason      The reason for changing frame
     */
    void                            frameChanged( qint64 newFrame,
                                                MainWorkflow::FrameChangedReason reason );
    /**
     *  \brief  Emmited when render end is reached.
     *
     *  This should be emmited just before stopped
     *  \sa     stopped();
     */
214
    void                            endReached();
215
216
};

217
#endif // GENERICRENDERER_H