CommandsQueue.hpp 5.62 KB
Newer Older
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
/*
 * CommandsQueue.hpp
 *****************************************************************************
 * Copyright © 2015 VideoLAN and VLC Authors
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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 COMMANDSQUEUE_HPP_
#define COMMANDSQUEUE_HPP_

#include <vlc_common.h>
#include <vlc_es.h>
#include <vlc_atomic.h>

#include <list>

29
namespace adaptive
30
{
31
    class FakeESOut;
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    class FakeESOutID;

    class AbstractCommand
    {
        friend class CommandsFactory;
        public:
            virtual ~AbstractCommand();
            virtual void Execute( es_out_t * ) = 0;
            virtual mtime_t getTime() const;
            int getType() const;

        protected:
            AbstractCommand( int );
            int type;
    };

48 49 50 51 52 53 54 55
    class AbstractFakeEsCommand : public AbstractCommand
    {
        protected:
            AbstractFakeEsCommand( int, FakeESOutID * );
            FakeESOutID *p_fakeid;
    };

    class EsOutSendCommand : public AbstractFakeEsCommand
56 57 58 59 60 61 62 63 64 65 66 67
    {
        friend class CommandsFactory;
        public:
            virtual ~EsOutSendCommand();
            virtual void Execute( es_out_t *out );
            virtual mtime_t getTime() const;

        protected:
            EsOutSendCommand( FakeESOutID *, block_t * );
            block_t *p_block;
    };

68
    class EsOutDelCommand : public AbstractFakeEsCommand
69 70 71 72 73 74 75 76 77
    {
        friend class CommandsFactory;
        public:
            virtual void Execute( es_out_t *out );

        protected:
            EsOutDelCommand( FakeESOutID * );
    };

78
    class EsOutAddCommand : public AbstractFakeEsCommand
79 80 81 82 83 84 85
    {
        friend class CommandsFactory;
        public:
            virtual ~EsOutAddCommand();
            virtual void Execute( es_out_t *out );

        protected:
86
            EsOutAddCommand( FakeESOutID * );
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    };

    class EsOutControlPCRCommand : public AbstractCommand
    {
        friend class CommandsFactory;
        public:
            virtual void Execute( es_out_t *out );
            virtual mtime_t getTime() const;

        protected:
            EsOutControlPCRCommand( int, mtime_t );
            int group;
            mtime_t pcr;
    };

    class EsOutDestroyCommand : public AbstractCommand
    {
        friend class CommandsFactory;
        public:
            virtual void Execute( es_out_t *out );

        protected:
            EsOutDestroyCommand();
    };

112 113 114 115 116 117 118 119 120 121
    class EsOutControlResetPCRCommand : public AbstractCommand
    {
        friend class CommandsFactory;
        public:
            virtual void Execute( es_out_t *out );

        protected:
            EsOutControlResetPCRCommand();
    };

122 123 124 125 126 127 128 129 130 131 132 133 134
    class EsOutMetaCommand : public AbstractCommand
    {
        friend class CommandsFactory;
        public:
            virtual void Execute( es_out_t *out );

        protected:
            EsOutMetaCommand( int, vlc_meta_t * );
            virtual ~EsOutMetaCommand();
            int group;
            vlc_meta_t *p_meta;
    };

135 136 137 138 139
    /* Factory so we can alter behaviour and filter on execution */
    class CommandsFactory
    {
        public:
            virtual ~CommandsFactory() {}
140 141 142 143 144 145
            virtual EsOutSendCommand * createEsOutSendCommand( FakeESOutID *, block_t * ) const;
            virtual EsOutDelCommand * createEsOutDelCommand( FakeESOutID * ) const;
            virtual EsOutAddCommand * createEsOutAddCommand( FakeESOutID * ) const;
            virtual EsOutControlPCRCommand * createEsOutControlPCRCommand( int, mtime_t ) const;
            virtual EsOutControlResetPCRCommand * creatEsOutControlResetPCRCommand() const;
            virtual EsOutDestroyCommand * createEsOutDestroyCommand() const;
146
            virtual EsOutMetaCommand * createEsOutMetaCommand( int, const vlc_meta_t * ) const;
147 148 149 150 151 152
    };

    /* Queuing for doing all the stuff in order */
    class CommandsQueue
    {
        public:
153
            CommandsQueue( CommandsFactory * );
154
            ~CommandsQueue();
155
            const CommandsFactory * factory() const;
156
            void Schedule( AbstractCommand * );
157
            mtime_t Process( es_out_t *out, mtime_t );
158
            void Abort( bool b_reset );
159
            void Commit();
160 161
            bool isEmpty() const;
            void setDrop( bool );
162
            void setDraining();
163
            void setEOF();
164
            bool isDraining() const;
165
            bool isEOF() const;
166
            mtime_t getDemuxedAmount() const;
167 168
            mtime_t getBufferingLevel() const;
            mtime_t getFirstDTS() const;
169
            mtime_t getPCR() const;
170 171

        private:
172
            CommandsFactory *commandsFactory;
173 174
            vlc_mutex_t lock;
            void LockedCommit();
175
            void LockedSetDraining();
176 177 178
            std::list<AbstractCommand *> incoming;
            std::list<AbstractCommand *> commands;
            mtime_t bufferinglevel;
179
            mtime_t pcr;
180
            bool b_draining;
181
            bool b_drop;
182
            bool b_eof;
183 184 185 186
    };
}

#endif /* COMMANDSQUEUE_HPP_ */