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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* MediaObject.cpp
*****************************************************************************
* 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.
*****************************************************************************/
#include "MediaObject.h"
#include <inttypes.h>
#include<stdio.h>
using namespace libdash::framework::input;
using namespace dash::mpd;
using namespace dash::network;
using namespace dash::metrics;
MediaObject::MediaObject(ISegment *segment, IRepresentation *rep, bool withFeedBack) :
segment (segment),
rep (rep),
withFeedBack (withFeedBack)
{
this->initSeg = NULL;
InitializeConditionVariable (&this->stateChanged);
InitializeCriticalSection (&this->stateLock);
}
MediaObject::~MediaObject()
{
if(this->state == IN_PROGRESS)
{
this->segment->AbortDownload();
this->OnDownloadStateChanged(ABORTED);
}
this->segment->DetachDownloadObserver(this);
this->WaitFinished();
DeleteConditionVariable (&this->stateChanged);
DeleteCriticalSection (&this->stateLock);
delete this->segment;
this->segment = NULL;
}
void MediaObject::SetFeedBack(bool flag)
{
this->withFeedBack = flag;
}
void MediaObject::AddInitSegment(MediaObject* initSeg)
{
this->initSeg = initSeg;
}
int MediaObject::ReadInitSegment(uint8_t* data, size_t len)
{
if(this->initSeg)
return this->initSeg->Peek(data,len);
else
return 0;
}
bool MediaObject::StartDownload()
{
this->segment->AttachDownloadObserver(this);
return this->segment->StartDownload();
}
bool MediaObject::StartDownload(IICNConnection* conn)
{
if(conn == NULL)
return this->StartDownload();
conn->Init(this->segment);
this->segment->AttachDownloadObserver(this);
return this->segment->StartDownload(conn);
}
const char* MediaObject::GetPath()
{
return ((IChunk*)this->segment)->Path().c_str();
}
void MediaObject::AbortDownload()
{
this->segment->AbortDownload();
this->OnDownloadStateChanged(ABORTED);
}
void MediaObject::WaitFinished()
{
EnterCriticalSection(&this->stateLock);
while(this->state != COMPLETED && this->state != ABORTED){
SleepConditionVariableCS(&this->stateChanged, &this->stateLock, INFINITE);
}
LeaveCriticalSection(&this->stateLock);
if(this->state != ABORTED)
{
if(this->withFeedBack && this->dashReceiver)
{
this->dashReceiver->Notifybps(this->bps);
this->dashReceiver->NotifyDLTime(this->dnltime);
}
}
}
int MediaObject::Read(uint8_t *data, size_t len)
{
return this->segment->Read(data, len);
}
int MediaObject::Peek(uint8_t *data, size_t len)
{
return this->segment->Peek(data, len);
}
int MediaObject::Peek(uint8_t *data, size_t len, size_t offset)
{
return this->segment->Peek(data, len, offset);
}
IRepresentation* MediaObject::GetRepresentation()
{
return this->rep;
}
ISegment* MediaObject::GetSegment()
{
return this->segment;
}
void MediaObject::OnDownloadTimeChanged(double dnltime)
{
this->dnltime = dnltime;
}
void MediaObject::OnDownloadStateChanged(DownloadState state)
{
EnterCriticalSection(&this->stateLock);
this->state = state;
WakeAllConditionVariable(&this->stateChanged);
LeaveCriticalSection(&this->stateLock);
}
void MediaObject::OnDownloadRateChanged(uint64_t bitsPerSecond)
{
this->bps = bitsPerSecond;
}
void MediaObject::SetDASHReceiver(input::DASHReceiver *_dashReceiver)
{
this->dashReceiver = _dashReceiver;
}
void MediaObject::SetAdaptationLogic(adaptation::IAdaptationLogic *_adaptationLogic)
{
this->adaptationLogic = _adaptationLogic;
}
const std::vector<ITCPConnection *>& MediaObject::GetTCPConnectionList() const
{
return this->segment->GetTCPConnectionList();
}
const std::vector<IHTTPTransaction *>& MediaObject::GetHTTPTransactionList () const
{
return this->segment->GetHTTPTransactionList();
}
|