GenericRenderer.h 7.56 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 "EffectUser.h"
34
#include "Types.h"
35

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

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

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

56
#ifdef WITH_GUI
57 58 59 60 61
    /**
     *  \brief  Set the widget used for rendering the output.
     *  \param  renderWidget    The widget to use for render.
     *  \sa     setPreviewLabel( QLabel* )
     */
62
    void                setRenderWidget( QWidget* renderWidget );
63
#endif
64 65 66 67 68 69 70 71 72

    /**
     *  \brief  Set the output volume.
     *  \param  volume the volume (int)
     *  \return 0 if the volume was set, -1 if it was out of range
     *  \sa     getVolume()
     */
    virtual int         setVolume( int volume ) = 0;

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    /**
     *  \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;
88 89

    /**
90 91
     *  \brief Render the next frame
     *  \sa     previousFrame()
92
     */
93
    virtual void                    nextFrame() = 0;
94 95

    /**
96 97
     *  \brief  Render the previous frame
     *  \sa     nextFrame();
98
     */
99
    virtual void                    previousFrame() = 0;
100 101

    /**
102 103
     *  \brief Stop the renderer.
     *  \sa togglePlayPause( bool );
104
     */
105
    virtual void                    stop() = 0;
106

107 108 109 110 111 112 113
    /**
     *  \brief   Return the volume
     *  \return  The Return the volume the audio level (int)
     *  \sa     setVolume( int )
     */
    virtual int                     getVolume() const = 0;

114
    /**
115 116 117
     * \brief   Return the length in milliseconds
     * \return  The length of the underlying rendered target in milliseconds
     *  \sa     getLength()
118
     */
119
    virtual qint64                  getLengthMs() const = 0;
120 121

    /**
122 123
     *  \brief  Return the current frame number
     *  \return The current frame
124
     */
125
    virtual qint64                  getCurrentFrame() const = 0;
126 127

    /**
128 129
     *  \brief Return the number of frames per second
     *  \return     The current fps
130
     */
131
    virtual float                   getFps() const = 0;
132

133
    /**
134 135 136 137 138
     *  \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()
139
     */
140
    virtual qint64                  length() const = 0;
141 142

    /**
143 144
     *  \brief  Return true if the renderer is paused
     *  \return true if the renderer is paused. false otherwise.
145
     */
146 147 148 149
    bool                            isPaused() const
    {
        return m_paused;
    }
150 151

    /**
152 153 154 155
     *  \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()
156
     */
157 158 159 160
    bool                            isRendering() const
    {
        return m_isRendering;
    }
161 162 163 164
    EffectUser::Type                effectType() const
    {
        return EffectUser::GlobalEffectUser;
    }
165 166

protected:
167 168 169
    /**
     *  \brief  The media player that will be used for rendering
     */
170
    LibVLCpp::MediaPlayer*          m_mediaPlayer;
171 172 173 174
    /**
     *  \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
175
     *  \warning    This is not thread safe.
176
     *  \sa         isPaused()
177 178
     */
    bool                            m_paused;
179

180 181 182 183
    /**
     *  \brief      The QWidget on which we will render.
     *  \sa         setRenderWidget( QWidget* );
     */
184
    QWidget*                        m_renderWidget;
185

186
public slots:
187 188 189
    /**
     *  \brief      This SLOT has to be called when the render ends.
     */
190
    virtual void                    __endReached() = 0;
191 192 193 194 195 196 197
    /**
     *  \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;
198

199 200

signals:
201 202 203 204
    /**
     *  \brief  This signal means the render just finished, and has been stoped.
     *  \sa     endReached()
     */
205
    void                            stopped();
206 207 208 209
    /**
     *  \brief  Emmited when the render has been paused.
     *  \sa     playing()
     */
210
    void                            paused();
211 212 213 214
    /**
     *  \brief  Emmited when the renderer has started to render, and has been unpaused.
     *  \sa     paused()
     */
215
    void                            playing();
216 217 218 219
    /**
     *  \brief  Emmited when volume change occurs.
     */
    void                            volumeChanged();
220 221 222 223 224 225
    /**
     *  \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,
226
                                                Vlmc::FrameChangedReason reason );
227 228 229 230 231 232
    /**
     *  \brief  Emmited when render end is reached.
     *
     *  This should be emmited just before stopped
     *  \sa     stopped();
     */
233
    void                            endReached();
234 235 236 237 238 239 240 241 242

    /**
     *  \brief  Emited when something went wrong with the render.
     *
     *  The cause may vary depending on the underlying renderer, though this will
     *  almost always be caused by a missing codec.
     */
    void                error();

243 244
};

245
#endif // GENERICRENDERER_H