Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
GSoC
GSoC2018
macOS
vlc
Commits
614eb9b9
Commit
614eb9b9
authored
Dec 12, 2014
by
François Cartegnie
🤞
Browse files
stream_filter: dash: compute rate statistics in logic
Logic need to do computation as they need.
parent
a03587d3
Changes
9
Hide whitespace changes
Inline
Side-by-side
modules/stream_filter/dash/DASHManager.cpp
View file @
614eb9b9
...
...
@@ -64,7 +64,6 @@ bool DASHManager::start()
this
->
buffer
=
new
BlockBuffer
(
this
->
stream
);
this
->
downloader
=
new
DASHDownloader
(
this
->
conManager
,
this
->
buffer
);
this
->
conManager
->
attach
(
this
->
adaptationLogic
);
this
->
buffer
->
attach
(
this
->
adaptationLogic
);
return
this
->
downloader
->
start
();
...
...
modules/stream_filter/dash/adaptationlogic/AbstractAdaptationLogic.cpp
View file @
614eb9b9
...
...
@@ -35,8 +35,6 @@ AbstractAdaptationLogic::AbstractAdaptationLogic (MPD *mpd_) :
mpd
(
mpd_
),
currentPeriod
(
mpd
->
getFirstPeriod
()),
count
(
0
),
bpsAvg
(
0
),
bpsLastChunk
(
0
),
bufferedMicroSec
(
0
),
bufferedPercent
(
0
)
{
...
...
@@ -92,19 +90,11 @@ void AbstractAdaptationLogic::bufferLevelChanged (mtime_t bufferedMicroSec,
this
->
bufferedMicroSec
=
bufferedMicroSec
;
this
->
bufferedPercent
=
bufferedPercent
;
}
void
AbstractAdaptationLogic
::
downloadRateChanged
(
uint64_t
bpsAvg
,
uint64_t
bpsLastChunk
)
{
this
->
bpsAvg
=
bpsAvg
;
this
->
bpsLastChunk
=
bpsLastChunk
;
}
uint64_t
AbstractAdaptationLogic
::
getBpsAvg
()
const
{
return
this
->
bpsAvg
;
}
uint64_t
AbstractAdaptationLogic
::
getBpsLastChunk
()
const
void
AbstractAdaptationLogic
::
updateDownloadRate
(
size_t
,
mtime_t
)
{
return
this
->
bpsLastChunk
;
}
int
AbstractAdaptationLogic
::
getBufferPercent
()
const
{
return
this
->
bufferedPercent
;
...
...
modules/stream_filter/dash/adaptationlogic/AbstractAdaptationLogic.h
View file @
614eb9b9
...
...
@@ -45,11 +45,9 @@ namespace dash
virtual
dash
::
http
::
Chunk
*
getNextChunk
(
Streams
::
Type
);
virtual
void
downloadRateChanged
(
uint64_t
bpsAvg
,
uint64_t
bpsLastChunk
);
virtual
void
bufferLevelChanged
(
mtime_t
bufferedMicroSec
,
int
bufferedPercent
);
virtual
void
updateDownloadRate
(
size_t
,
mtime_t
);
uint64_t
getBpsAvg
()
const
;
uint64_t
getBpsLastChunk
()
const
;
virtual
void
bufferLevelChanged
(
mtime_t
bufferedMicroSec
,
int
bufferedPercent
);
int
getBufferPercent
()
const
;
protected:
...
...
@@ -58,8 +56,6 @@ namespace dash
size_t
count
;
private:
int
bpsAvg
;
long
bpsLastChunk
;
mtime_t
bufferedMicroSec
;
int
bufferedPercent
;
};
...
...
modules/stream_filter/dash/adaptationlogic/IAdaptationLogic.h
View file @
614eb9b9
...
...
@@ -49,11 +49,6 @@ namespace dash
virtual
dash
::
http
::
Chunk
*
getNextChunk
(
Streams
::
Type
)
=
0
;
virtual
const
dash
::
mpd
::
Representation
*
getCurrentRepresentation
(
Streams
::
Type
)
const
=
0
;
/**
* \return The average bitrate in bits per second.
*/
virtual
uint64_t
getBpsAvg
()
const
=
0
;
virtual
uint64_t
getBpsLastChunk
()
const
=
0
;
};
}
}
...
...
modules/stream_filter/dash/adaptationlogic/IDownloadRateObserver.h
View file @
614eb9b9
...
...
@@ -34,7 +34,7 @@ namespace dash
class
IDownloadRateObserver
{
public:
virtual
void
d
ownloadRate
Changed
(
uint64_t
bpsAvg
,
uint64_t
bpsLastChunk
)
=
0
;
virtual
void
updateD
ownloadRate
(
size_t
,
mtime_t
)
=
0
;
virtual
~
IDownloadRateObserver
(){}
};
}
...
...
modules/stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.cpp
View file @
614eb9b9
...
...
@@ -35,7 +35,8 @@ using namespace dash::logic;
using
namespace
dash
::
mpd
;
RateBasedAdaptationLogic
::
RateBasedAdaptationLogic
(
MPD
*
mpd
)
:
AbstractAdaptationLogic
(
mpd
)
AbstractAdaptationLogic
(
mpd
),
bpsAvg
(
0
),
bpsSamplecount
(
0
)
{
width
=
var_InheritInteger
(
mpd
->
getVLCObject
(),
"dash-prefwidth"
);
height
=
var_InheritInteger
(
mpd
->
getVLCObject
(),
"dash-prefheight"
);
...
...
@@ -46,12 +47,8 @@ const Representation *RateBasedAdaptationLogic::getCurrentRepresentation(Streams
if
(
currentPeriod
==
NULL
)
return
NULL
;
uint64_t
bitrate
=
this
->
getBpsAvg
();
if
(
getBufferPercent
()
<
MINBUFFER
)
bitrate
=
0
;
RepresentationSelector
selector
;
Representation
*
rep
=
selector
.
select
(
currentPeriod
,
type
,
b
itrate
,
width
,
height
);
Representation
*
rep
=
selector
.
select
(
currentPeriod
,
type
,
b
psAvg
,
width
,
height
);
if
(
rep
==
NULL
)
{
rep
=
selector
.
select
(
currentPeriod
,
type
);
...
...
@@ -60,3 +57,18 @@ const Representation *RateBasedAdaptationLogic::getCurrentRepresentation(Streams
}
return
rep
;
}
void
RateBasedAdaptationLogic
::
updateDownloadRate
(
size_t
size
,
mtime_t
time
)
{
if
(
unlikely
(
time
==
0
))
return
;
size_t
current
=
size
*
8000
/
time
;
if
(
current
>=
bpsAvg
)
bpsAvg
=
bpsAvg
+
(
current
-
bpsAvg
)
/
(
bpsSamplecount
+
1
);
else
bpsAvg
=
bpsAvg
-
(
bpsAvg
-
current
)
/
(
bpsSamplecount
+
1
);
bpsSamplecount
++
;
}
modules/stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.h
View file @
614eb9b9
...
...
@@ -39,10 +39,13 @@ namespace dash
RateBasedAdaptationLogic
(
mpd
::
MPD
*
mpd
);
const
dash
::
mpd
::
Representation
*
getCurrentRepresentation
(
Streams
::
Type
)
const
;
virtual
void
updateDownloadRate
(
size_t
,
mtime_t
);
private:
int
width
;
int
height
;
size_t
bpsAvg
;
size_t
bpsSamplecount
;
};
}
}
...
...
modules/stream_filter/dash/http/HTTPConnectionManager.cpp
View file @
614eb9b9
...
...
@@ -33,22 +33,14 @@
#include
<vlc_stream.h>
using
namespace
dash
::
http
;
using
namespace
dash
::
logic
;
const
uint64_t
HTTPConnectionManager
::
CHUNKDEFAULTBITRATE
=
1
;
HTTPConnectionManager
::
HTTPConnectionManager
(
IAdaptationLogic
*
adaptationLogic
,
stream_t
*
stream
)
:
HTTPConnectionManager
::
HTTPConnectionManager
(
logic
::
IAdaptationLogic
*
adaptationLogic
,
stream_t
*
stream
)
:
currentChunk
(
NULL
),
adaptationLogic
(
adaptationLogic
),
stream
(
stream
),
chunkCount
(
0
),
bpsAvg
(
0
),
bpsLastChunk
(
0
),
bpsCurrentChunk
(
0
),
bytesReadSession
(
0
),
bytesReadChunk
(
0
),
timeSession
(
0
),
timeChunk
(
0
)
chunkCount
(
0
)
{
}
HTTPConnectionManager
::~
HTTPConnectionManager
()
...
...
@@ -104,9 +96,6 @@ ssize_t HTTPConnectionManager::read(Streams::Type type, block_t **pp_block)
{
block_Release
(
block
);
*
pp_block
=
NULL
;
this
->
bpsLastChunk
=
this
->
bpsCurrentChunk
;
this
->
bytesReadChunk
=
0
;
this
->
timeChunk
=
0
;
delete
(
chunk
);
downloadQueue
[
type
].
pop_front
();
...
...
@@ -115,8 +104,9 @@ ssize_t HTTPConnectionManager::read(Streams::Type type, block_t **pp_block)
}
else
{
updateStatistics
((
size_t
)
ret
,
((
double
)
time
)
/
CLOCK_FREQ
);
block
->
i_buffer
=
ret
;
adaptationLogic
->
updateDownloadRate
(
block
->
i_buffer
,
time
);
if
(
chunk
->
getBytesToRead
()
==
0
)
{
chunk
->
onDownload
(
block
->
p_buffer
,
block
->
i_buffer
);
...
...
@@ -130,18 +120,6 @@ ssize_t HTTPConnectionManager::read(Streams::Type type, block_t **pp_block)
return
ret
;
}
void
HTTPConnectionManager
::
attach
(
IDownloadRateObserver
*
observer
)
{
this
->
rateObservers
.
push_back
(
observer
);
}
void
HTTPConnectionManager
::
notify
()
{
if
(
this
->
bpsAvg
==
0
)
return
;
for
(
size_t
i
=
0
;
i
<
this
->
rateObservers
.
size
();
i
++
)
this
->
rateObservers
.
at
(
i
)
->
downloadRateChanged
(
this
->
bpsAvg
,
this
->
bpsLastChunk
);
}
PersistentConnection
*
HTTPConnectionManager
::
getConnectionForHost
(
const
std
::
string
&
hostname
)
{
std
::
vector
<
PersistentConnection
*>::
const_iterator
it
;
...
...
@@ -153,25 +131,6 @@ PersistentConnection * HTTPConnectionManager::getConnectionForHost(const std::st
return
NULL
;
}
void
HTTPConnectionManager
::
updateStatistics
(
size_t
bytes
,
double
time
)
{
this
->
bytesReadSession
+=
bytes
;
this
->
bytesReadChunk
+=
bytes
;
this
->
timeSession
+=
time
;
this
->
timeChunk
+=
time
;
this
->
bpsAvg
=
(
int64_t
)
((
this
->
bytesReadSession
*
8
)
/
this
->
timeSession
);
this
->
bpsCurrentChunk
=
(
int64_t
)
((
this
->
bytesReadChunk
*
8
)
/
this
->
timeChunk
);
if
(
this
->
bpsAvg
<
0
)
this
->
bpsAvg
=
0
;
if
(
this
->
bpsCurrentChunk
<
0
)
this
->
bpsCurrentChunk
=
0
;
this
->
notify
();
}
bool
HTTPConnectionManager
::
connectChunk
(
Chunk
*
chunk
)
{
if
(
chunk
==
NULL
)
...
...
modules/stream_filter/dash/http/HTTPConnectionManager.h
View file @
614eb9b9
...
...
@@ -25,6 +25,12 @@
#ifndef HTTPCONNECTIONMANAGER_H_
#define HTTPCONNECTIONMANAGER_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include
"http/PersistentConnection.h"
#include
<vlc_common.h>
#include
<string>
...
...
@@ -50,31 +56,21 @@ namespace dash
void
closeAllConnections
();
ssize_t
read
(
Streams
::
Type
,
block_t
**
);
void
attach
(
dash
::
logic
::
IDownloadRateObserver
*
observer
);
void
notify
();
private:
std
::
vector
<
dash
::
logic
::
IDownloadRateObserver
*>
rateObservers
;
std
::
deque
<
Chunk
*>
downloadQueue
[
Streams
::
count
];
void
releaseAllConnections
();
Chunk
*
currentChunk
;
std
::
vector
<
PersistentConnection
*>
connectionPool
;
logic
::
IAdaptationLogic
*
adaptationLogic
;
stream_t
*
stream
;
int
chunkCount
;
int64_t
bpsAvg
;
int64_t
bpsLastChunk
;
int64_t
bpsCurrentChunk
;
int64_t
bytesReadSession
;
int64_t
bytesReadChunk
;
double
timeSession
;
double
timeChunk
;
static
const
uint64_t
CHUNKDEFAULTBITRATE
;
bool
connectChunk
(
Chunk
*
chunk
);
PersistentConnection
*
getConnectionForHost
(
const
std
::
string
&
hostname
);
void
updateStatistics
(
size_t
bytes
,
double
time
);
};
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment