CommandsQueue.hpp 4.83 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
    /* Factory so we can alter behaviour and filter on execution */
    class CommandsFactory
    {
        public:
            virtual ~CommandsFactory() {}
            virtual EsOutSendCommand * createEsOutSendCommand( FakeESOutID *, block_t * );
            virtual EsOutDelCommand * createEsOutDelCommand( FakeESOutID * );
129
            virtual EsOutAddCommand * createEsOutAddCommand( FakeESOutID * );
130
            virtual EsOutControlPCRCommand * createEsOutControlPCRCommand( int, mtime_t );
131
            virtual EsOutControlResetPCRCommand * creatEsOutControlResetPCRCommand();
132 133 134 135 136 137 138
            virtual EsOutDestroyCommand * createEsOutDestroyCommand();
    };

    /* Queuing for doing all the stuff in order */
    class CommandsQueue
    {
        public:
139
            CommandsQueue( CommandsFactory * );
140
            ~CommandsQueue();
141
            CommandsFactory * factory();
142
            void Schedule( AbstractCommand * );
143
            mtime_t Process( es_out_t *out, mtime_t );
144
            void Abort( bool b_reset );
145
            void Commit();
146 147 148 149 150 151
            bool isEmpty() const;
            void setDrop( bool );
            mtime_t getBufferingLevel() const;
            mtime_t getFirstDTS() const;

        private:
152
            CommandsFactory *commandsFactory;
153 154
            vlc_mutex_t lock;
            void LockedCommit();
155 156 157 158 159 160 161 162
            std::list<AbstractCommand *> incoming;
            std::list<AbstractCommand *> commands;
            mtime_t bufferinglevel;
            bool b_drop;
    };
}

#endif /* COMMANDSQUEUE_HPP_ */