aboutsummaryrefslogtreecommitdiffstats
path: root/Input/DASHReceiver.h
blob: a6db03820c53b4d148bb5f2bbf37c05e1b2dc3f1 (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
130
/*
 * 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 "../MPD/MPDWrapper.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 mpd
{
class AdaptationSetStream;
}
namespace adaptation
{
class IAdaptationLogic;
}
namespace buffer
{
class MediaObjectBuffer;
template <class T>
class Buffer;
}
namespace input
{
class MediaObject;
class DASHReceiver
{
public:
    DASHReceiver(viper::managers::StreamType type, libdash::framework::mpd::MPDWrapper *mpdWrapper, 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* GetInitSegmentWithoutLock();
    input::MediaObject* FindInitSegment(std::string representation);
    uint32_t GetPosition();
    void SetPosition(uint32_t segmentNumber);
    void SetLooping(bool isLoopinp);
    void SetPositionInMsecs(uint32_t milliSecs);
    dash::mpd::IRepresentation* GetRepresentation();
    void SetRepresentation();
    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 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<std::string, MediaObject*>                 initSegments;
    libdash::framework::buffer::Buffer<MediaObject>     *buffer;
    IDASHReceiverObserver                               *observer;
    libdash::framework::mpd::MPDWrapper                 *mpdWrapper;
    mpd::AdaptationSetStream                            *adaptationSetStream;
    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;
    viper::managers::StreamType                         type;

    uint32_t CalculateSegmentOffset();
    void NotifySegmentDownloaded();
    void DownloadInitSegment();
    void DownloadInitSegmentWithoutLock();
    bool InitSegmentExists(std::string rep);
    static void* DoBuffering(void *receiver);
};
}
}
}

#endif /* LIBDASH_FRAMEWORK_INPUT_DASHRECEIVER_H_ */