GenericRenderer.h 7.36 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
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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
class   Clip;
class   Media;
38 39 40 41
namespace LibVLCpp
{
    class   MediaPlayer;
}
42

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

51
protected:
52
    explicit GenericRenderer();
53 54

public:
55
    virtual ~GenericRenderer();
56

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

    /**
     *  \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;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

200 201

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

236 237
};

238
#endif // GENERICRENDERER_H