ClipWorkflow.h 5.27 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*****************************************************************************
 * ClipWorkflow.h : Clip workflow. Will extract a single frame from a VLCMedia
 *****************************************************************************
 * 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.
 *****************************************************************************/

#ifndef CLIPWORKFLOW_H
#define CLIPWORKFLOW_H

//TODO: THIS HAS TO GO REALLY REALLY REALLY SOON !!!!
//FIXME:
//UGLY:
#define VIDEOWIDTH 640
#define VIDEOHEIGHT 480

#include <QReadWriteLock>
#include <QMutex>
#include <QWaitCondition>
#include <QObject>

#include "Clip.h"
#include "VLCMediaPlayer.h"

class   ClipWorkflow : public QObject
{
    Q_OBJECT

    public:
45 46
        enum        State
        {
47
            None = -1,
48 49 50 51
            Stopped,
            Initializing,
            Ready,
            Rendering,
52
            EndReached,
53
            StopRequired,
54 55 56
        };

        ClipWorkflow( Clip* clip, QMutex* renderMutex, QMutex* condMutex, QWaitCondition* waitCond );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
57 58
        virtual ~ClipWorkflow();

59
        /**
60 61 62
         *  This method returns the current frame. It locks the renderMutex,
         *  therefore, you can call this method blindly, without taking care
         *  of the rendering process advancement.
63
         */
64
        unsigned char*          getOutput();
65
        void                    initialize( LibVLCpp::MediaPlayer* mediaPlayer );
66 67 68 69 70
        /**
         *  Return true ONLY if the state is equal to Ready.
         *  If the state is Rendering, EndReached or anything else, this will
         *  return false.
         */
71
        bool                    isReady() const;
72 73 74 75
        /**
         *  Return true ONLY if the state is equal to EndReached.
         *  In any other cases, this will return false.
         */
76
        bool                    isEndReached() const;
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

        /**
         *  Return true ONLY if the state is equal to Stopped.
         *  In any other cases, this will return false.
         */
        bool                    isStopped() const;

        /**
         *  Return true ONLY if the state is equal to Stopped.
         *  In any other cases, this will return false.
         */
        bool                    isRendering() const;

        /**
         *  Returns the current workflow state.
         */
        State                   getState() const;

        /**
         *  This method start the effective render, ie calling the play() method
         *  on the media player.
         *  If the media player isn't ready, this method waits.
         */
100
        void                    startRender();
101

102 103 104 105 106 107
        /**
            \brief              Returns the Clip this workflow instance is based
                                uppon, so that you can query information on it.
            \return             A pointer to a constant clip instance.
        */
        const Clip*             getClip() const;
108 109 110 111 112
        /**
            \brief  Stop this workflow.
        */
        void                    stop();
        void                    setPosition( float pos );
113

114 115 116 117 118 119 120 121
        /**
         *  This method must be used to change the state of the ClipWorkflow
         *  from outside its render loop, otherwise, it may lead to deadlocks.
         *  No additional operations will be executed (for example, if setting
         *  the new state to stop, the media player won't be stopped.)
         *  This is mainly to change the behaviour of the render loop.
         */
        void                    queryStateChange( State newState );
122

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
123 124 125
    private:
        static void             lock( ClipWorkflow* clipWorkflow, void** pp_ret );
        static void             unlock( ClipWorkflow* clipWorkflow );
126
        void                    setVmem();
127
        void                    setState( State state );
128
        void                    checkStateChange();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
129 130 131 132

    private:
        Clip*                   m_clip;
        unsigned char*          m_buffer;
133

134
        QMutex*                 m_renderMutex;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
135 136
        QMutex*                 m_condMutex;
        QWaitCondition*         m_waitCond;
137

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
138
        LibVLCpp::MediaPlayer*  m_mediaPlayer;
139

140 141
        State                   m_state;
        QReadWriteLock*         m_stateLock;
142 143
        State                   m_requiredState;
        QMutex*                 m_requiredStateLock;
144

145 146

    public slots:
147 148
        void                    pauseAfterPlaybackStarted();
        void                    pausedMediaPlayer();
149
        void                    setPositionAfterPlayback();
150
        void                    endReached();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
151 152 153
};

#endif // CLIPWORKFLOW_H