PlaylistManager.h 4.69 KB
Newer Older
1 2 3 4
/*
 * PlaylistManager.h
 *****************************************************************************
 * Copyright © 2010 - 2011 Klagenfurt University
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
5
 *             2015 VideoLAN and VLC Authors
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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 PLAYLISTMANAGER_H_
#define PLAYLISTMANAGER_H_

#include "logic/AbstractAdaptationLogic.h"
#include "Streams.hpp"
27
#include <vector>
28

29
namespace adaptive
30 31 32 33
{
    namespace playlist
    {
        class AbstractPlaylist;
34
        class BasePeriod;
35 36 37 38
    }

    namespace http
    {
39
        class AbstractConnectionManager;
40
        class AuthStorage;
41 42 43 44 45 46 47 48 49
    }

    using namespace playlist;
    using namespace logic;
    using namespace http;

    class PlaylistManager
    {
        public:
50 51 52
            PlaylistManager( demux_t *,
                             AuthStorage *,
                             AbstractPlaylist *,
53
                             AbstractStreamFactory *,
54
                             AbstractAdaptationLogic::LogicType type );
55 56
            virtual ~PlaylistManager    ();

57
            bool    start();
58
            void    stop();
59

60
            AbstractStream::buffering_status bufferize(mtime_t, unsigned, unsigned);
61
            AbstractStream::status dequeue(mtime_t, mtime_t *);
62 63
            void drain();

64
            virtual bool needsUpdate() const;
65
            virtual bool updatePlaylist();
66
            virtual void scheduleNextUpdate();
67

68 69 70 71
            /* static callbacks */
            static int control_callback(demux_t *, int, va_list);
            static int demux_callback(demux_t *);

72
        protected:
73 74 75 76
            /* Demux calls */
            virtual int doControl(int, va_list);
            virtual int doDemux(int64_t);

77 78 79 80
            virtual bool    setPosition(mtime_t);
            virtual mtime_t getDuration() const;
            mtime_t getPCR() const;
            mtime_t getFirstDTS() const;
81 82 83 84

            virtual mtime_t getFirstPlaybackTime() const;
            mtime_t getCurrentPlaybackTime() const;

85
            void pruneLiveStream();
86
            virtual bool reactivateStream(AbstractStream *);
87 88
            bool setupPeriod();
            void unsetPeriod();
89 90 91 92

            void updateControlsPosition();
            void updateControlsContentType();

93
            /* local factories */
94
            virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType,
95
                                                         AbstractConnectionManager *);
96

97
            AuthStorage                         *authStorage;
98
            AbstractConnectionManager           *conManager;
99
            AbstractAdaptationLogic::LogicType  logicType;
100
            AbstractAdaptationLogic             *logic;
101
            AbstractPlaylist                    *playlist;
102
            AbstractStreamFactory               *streamFactory;
103
            demux_t                             *p_demux;
104
            std::vector<AbstractStream *>        streams;
105
            BasePeriod                          *currentPeriod;
106 107 108 109 110 111 112 113 114 115 116 117

            /* shared with demux/buffering */
            struct
            {
                mtime_t     i_nzpcr;
                mtime_t     i_firstpcr;
                vlc_mutex_t lock;
                vlc_cond_t  cond;
            } demux;

            /* buffering process */
            time_t                               nextPlaylistupdate;
118
            int                                  failedupdates;
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

            /* Controls */
            struct
            {
                bool        b_live;
                mtime_t     i_length;
                mtime_t     i_time;
                double      f_position;
                vlc_mutex_t lock;
            } cached;

        private:
            void setBufferingRunState(bool);
            void Run();
            static void * managerThread(void *);
            vlc_mutex_t  lock;
            vlc_thread_t thread;
136
            bool         b_thread;
137 138
            vlc_cond_t   waitcond;
            bool         b_buffering;
139 140 141 142 143
    };

}

#endif /* PLAYLISTMANAGER_H_ */