aboutsummaryrefslogtreecommitdiffstats
path: root/Adaptation/Bola.h
blob: 2901166479a2e8e0e32950ec56b18de499849987 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
112
113
114
115
116
117
118
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LIBDASH_FRAMEWORK_ADAPTATION_BOLA_H_
#define LIBDASH_FRAMEWORK_ADAPTATION_BOLA_H_

#include "AbstractAdaptationLogic.h"
#include "../MPD/AdaptationSetStream.h"
#include "../Input/IDASHReceiverObserver.h"

namespace libdash
{
namespace framework
{
namespace adaptation
{
class BolaAdaptation : public AbstractAdaptationLogic
{
public:
    BolaAdaptation            (dash::mpd::IMPD *mpd, dash::mpd::IPeriod *period, dash::mpd::IAdaptationSet *adaptationSet, bool isVid, struct AdaptationParameters *params);
    virtual ~BolaAdaptation();

    virtual LogicType getType();
    virtual bool isUserDependent();
    virtual bool isRateBased();
    virtual bool isBufferBased();
    virtual void bitrateUpdate(uint64_t bps, uint32_t segNum);
    virtual void dLTimeUpdate(double time);
    virtual void bufferUpdate(uint32_t bufferFill, int maxC);
    void setBitrate(uint32_t bufferFill);
    uint64_t getBitrate();
    virtual void setMultimediaManager(viper::managers::IMultimediaManagerBase *_mmManager);
    void notifyBitrateChange();
    void onEOS(bool value);
    void checkedByDASHReceiver();

    int getQualityFromThroughput(uint64_t bps);
    int getQualityFromBufferLevel(double bufferLevelSec);

private:
    enum BolaState
    {
        ONE_BITRATE,			// If one bitrate (or init failed), always NO_CHANGE
        STARTUP,				// Download fragments at most recently measured throughput
        STARTUP_NO_INC,			// If quality increased then decreased during startup, then quality cannot be increased.
        STEADY					// The buffer is primed (should be above bufferTarget)
    };

    bool							initState;
    double 							bufferMaxSizeSeconds;		// Usually set to 30s
    double 							bufferTargetSeconds;  	// It is passed as an init parameter.
    // It states the difference between STARTUP and STEADY
    // 12s following dash.js implementation

    double 							bolaBufferTargetSeconds; 	// BOLA introduces a virtual buffer level in order to make quality decisions
    // as it was filled (instead of the actual bufferTargetSeconds)

    double 							bolaBufferMaxSeconds; 	// When using the virtual buffer, it must be capped.

    uint32_t 						bufferTargetPerc;		// Computed considering a bufferSize = 30s
    double 							totalDuration;			// Total video duration in seconds (taken from MPD)
    double 							segmentDuration;		// Segment duration in seconds

    std::vector<uint64_t>			availableBitrates;
    std::vector<double>				utilityVector;
    uint32_t						bitrateCount;			// Number of available bitrates
    BolaState						bolaState;				// Keeps track of Bola state

    // Bola Vp and gp (multiplied by the segment duration 'p')
    // They are dimensioned such that log utility would always prefer
    // - the lowest bitrate when bufferLevel = segmentDuration
    // - the highest bitrate when bufferLevel = bufferTarget
    double							Vp;
    double 							gp;

    bool							safetyGuarantee;
    double							maxRtt;

    double 							virtualBuffer;

    uint64_t						currentBitrate;
    int 							currentQuality;
    uint64_t						batchBw;
    int								batchBwCount;
    std::vector<uint64_t>			batchBwSamples;
    uint64_t						instantBw;
    uint64_t						averageBw;

    double 							lastDownloadTimeInstant;
    double 							currentDownloadTimeInstant;
    double							lastSegmentDownloadTime;

    uint32_t						lastBufferFill;
    bool							bufferEOS;
    bool							shouldAbort;
    double							alphaRate;
    bool							isCheckedForReceiver;

    viper::managers::IMultimediaManagerBase	*multimediaManager;
    dash::mpd::IRepresentation		*representation;
};
}
}
}

#endif /* LIBDASH_FRAMEWORK_ADAPTATION_BOLA_H_ */