aboutsummaryrefslogtreecommitdiffstats
path: root/Input/DASHReceiver.h
blob: a2893b4d6abf544e48d55d02e22b2d9176b4a9c6 (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
119
120
121
122
123
124
125
126
127
128
129
/*
 * DASHReceiver.h
 *****************************************************************************
 * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
 *
 * Email: libdash-dev@vicky.bitmovin.net
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 *****************************************************************************/

#ifndef LIBDASH_FRAMEWORK_INPUT_DASHRECEIVER_H_
#define LIBDASH_FRAMEWORK_INPUT_DASHRECEIVER_H_

#include "libdash.h"
#include "IMPD.h"

#include "../Input/MediaObject.h"
#include "IDASHReceiverObserver.h"
#include "../MPD/AdaptationSetStream.h"
#include "../MPD/IRepresentationStream.h"
#include "../Portable/MultiThreading.h"
#include "../Buffer/Buffer.h"
#include <chrono>
#include "ICNConnectionConsumerApi.h"

namespace libdash
{
namespace framework
{
namespace adaptation
{
class IAdaptationLogic;
}
namespace buffer
{
class MediaObjectBuffer;
template <class T>
class Buffer;
}
namespace input
{
class MediaObject;
class DASHReceiver
{
public:
    DASHReceiver(dash::mpd::IMPD *mpd, IDASHReceiverObserver *obs, buffer::Buffer<MediaObject> *buffer, uint32_t bufferSize, bool icnEnabled, double icnAlpha, float beta, float drop);
    virtual ~DASHReceiver();

    bool Start();
    void Stop();
    input::MediaObject* GetNextSegment();
    input::MediaObject* GetSegment(uint32_t segmentNumber);
    input::MediaObject* GetInitSegment();
    input::MediaObject* FindInitSegment(dash::mpd::IRepresentation *representation);
    uint32_t GetPosition();
    void SetPosition(uint32_t segmentNumber);
    void SetLooping(bool isLoopinp);
    void SetPositionInMsecs(uint32_t milliSecs);
    dash::mpd::IRepresentation* GetRepresentation();
    void SetRepresentation(dash::mpd::IPeriod *period,
                                                         dash::mpd::IAdaptationSet *adaptationSet,
                                                         dash::mpd::IRepresentation *representation);
    void SetAdaptationLogic(adaptation::IAdaptationLogic *_adaptationLogic);
    libdash::framework::adaptation::IAdaptationLogic* GetAdaptationLogic();
    void NotifyQualityDownloading(uint32_t quality);
    void Notifybps(uint64_t bps);
    void NotifyDLTime(double time);
    void NotifyBitrateChange(dash::mpd::IRepresentation *representation);
    void OnSegmentBufferStateChanged(uint32_t fillstateInPercent, int maxC);
    bool IsICN();
    void ShouldAbort();
    void OnEOS(bool value);
    void SetTargetDownloadingTime(double);
    void NotifyCheckedAdaptationLogic();
    bool threadComplete;
    bool PushBack(MediaObject* media);
    bool CanPush();
    void SetBeta(float beta);
    void SetDrop(float drop);

private:
    float                                               beta;
    float                                               drop;
    bool                                                withFeedBack;
    bool                                                isBufferBased;
    std::map<dash::mpd::IRepresentation*, MediaObject*> initSegments;
    libdash::framework::buffer::Buffer<MediaObject>     *buffer;
    IDASHReceiverObserver                               *observer;
    dash::mpd::IMPD                                     *mpd;
    dash::mpd::IPeriod                                  *period;
    dash::mpd::IAdaptationSet                           *adaptationSet;
    dash::mpd::IRepresentation                          *representation;
    mpd::AdaptationSetStream                            *adaptationSetStream;
    mpd::IRepresentationStream                          *representationStream;
    uint32_t                                            segmentNumber;
    uint32_t                                            positionInMsecs;
    uint32_t                                            segmentOffset;
    uint32_t                                            bufferSize;
    mutable CRITICAL_SECTION                            monitorMutex;
    mutable CRITICAL_SECTION                            monitorPausedMutex;
    mutable CONDITION_VARIABLE                          paused;
    bool                                            	isPaused;
    bool                                                isScheduledPaced;
    bool                                                isLooping;
    double                                          	targetDownload;
    double                                              downloadingTime;
    adaptation::IAdaptationLogic                        *adaptationLogic;
    IICNConnection                                      *conn;
    IICNConnection                                      *initConn;
    THREAD_HANDLE                                       bufferingThread;
    bool                                                isBuffering;
    bool                                                icn;
    double                                              icnAlpha;
    int                                                 previousQuality;
    int                                                 bufferLevelAtUpdate;
    int                                                 readMax;
    uint8_t                                             *readBuffer;
    uint32_t CalculateSegmentOffset();
    void NotifySegmentDownloaded();
    void DownloadInitSegment(dash::mpd::IRepresentation* rep);
    bool InitSegmentExists(dash::mpd::IRepresentation* rep);
    static void* DoBuffering(void *receiver);
};
}
}
}

#endif /* LIBDASH_FRAMEWORK_INPUT_DASHRECEIVER_H_ */