HLS-related buffer size optimizes
This commit is contained in:
parent
f53882a822
commit
9e391915df
4 changed files with 28 additions and 16 deletions
|
@ -289,6 +289,7 @@ namespace DTSC {
|
||||||
void reset();
|
void reset();
|
||||||
void toPrettyString(std::ostream & str, int indent = 0, int verbosity = 0);
|
void toPrettyString(std::ostream & str, int indent = 0, int verbosity = 0);
|
||||||
void finalize();
|
void finalize();
|
||||||
|
uint32_t biggestFragment();
|
||||||
|
|
||||||
std::string getIdentifier();
|
std::string getIdentifier();
|
||||||
std::string getWritableIdentifier();
|
std::string getWritableIdentifier();
|
||||||
|
|
|
@ -1218,6 +1218,17 @@ namespace DTSC {
|
||||||
void Track::finalize(){
|
void Track::finalize(){
|
||||||
keys.rbegin()->setLength(lastms - keys.rbegin()->getTime() + parts.rbegin()->getDuration());
|
keys.rbegin()->setLength(lastms - keys.rbegin()->getTime() + parts.rbegin()->getDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the duration in ms of the longest-duration fragment.
|
||||||
|
uint32_t Track::biggestFragment(){
|
||||||
|
uint32_t ret = 0;
|
||||||
|
for (unsigned int i = 0; i<fragments.size(); i++){
|
||||||
|
if (fragments[i].getDuration() > ret){
|
||||||
|
ret = fragments[i].getDuration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
///\brief Returns a key given its number, or an empty key if the number is out of bounds
|
///\brief Returns a key given its number, or an empty key if the number is out of bounds
|
||||||
Key & Track::getKey(unsigned int keyNum) {
|
Key & Track::getKey(unsigned int keyNum) {
|
||||||
|
|
|
@ -208,15 +208,28 @@ namespace Mist {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool inputBuffer::removeKey(unsigned int tid) {
|
bool inputBuffer::removeKey(unsigned int tid) {
|
||||||
|
DTSC::Track & Trk = myMeta.tracks[tid];
|
||||||
//Make sure we have at least 3 whole fragments at all times,
|
//Make sure we have at least 3 whole fragments at all times,
|
||||||
//unless we're shutting down the whole buffer right now
|
//unless we're shutting down the whole buffer right now
|
||||||
if (myMeta.tracks[tid].fragments.size() < 5 && config->is_active) {
|
if (Trk.fragments.size() < 5 && config->is_active) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//If we're shutting down, and this track is empty, abort
|
//If we're shutting down, and this track is empty, abort
|
||||||
if (!myMeta.tracks[tid].keys.size()) {
|
if (!myMeta.tracks[tid].keys.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (config->is_active && Trk.fragments.size() > 1){
|
||||||
|
///Make sure we have at least 3X the target duration.
|
||||||
|
//The target duration is the biggest fragment, rounded up to whole seconds.
|
||||||
|
uint32_t targetDuration = (Trk.biggestFragment() / 1000 + 1) * 1000;
|
||||||
|
//The start is the second fragment's begin
|
||||||
|
uint32_t fragStart = Trk.getKey((++Trk.fragments.begin())->getNumber()).getTime();
|
||||||
|
//The end is the last fragment's begin
|
||||||
|
uint32_t fragEnd = Trk.getKey(Trk.fragments.rbegin()->getNumber()).getTime();
|
||||||
|
if ((fragEnd - fragStart) < targetDuration * 3){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
DEBUG_MSG(DLVL_HIGH, "Erasing key %d:%lu", tid, myMeta.tracks[tid].keys[0].getNumber());
|
DEBUG_MSG(DLVL_HIGH, "Erasing key %d:%lu", tid, myMeta.tracks[tid].keys[0].getNumber());
|
||||||
//remove all parts of this key
|
//remove all parts of this key
|
||||||
for (int i = 0; i < myMeta.tracks[tid].keys[0].getParts(); i++) {
|
for (int i = 0; i < myMeta.tracks[tid].keys[0].getParts(); i++) {
|
||||||
|
|
|
@ -57,21 +57,8 @@ namespace Mist {
|
||||||
updateMeta();
|
updateMeta();
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
//parse single track
|
//parse single track
|
||||||
int longestFragment = 0;
|
result << "#EXTM3U\r\n#EXT-X-TARGETDURATION:" << (myMeta.tracks[tid].biggestFragment() / 1000) + 1 << "\r\n";
|
||||||
if (!myMeta.tracks[tid].fragments.size()){
|
|
||||||
INFO_MSG("liveIndex called with track %d, which has no fragments!", tid);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
for (std::deque<DTSC::Fragment>::iterator it = myMeta.tracks[tid].fragments.begin(); (it + 1) != myMeta.tracks[tid].fragments.end(); it++){
|
|
||||||
if (it->getDuration() > longestFragment){
|
|
||||||
longestFragment = it->getDuration();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((myMeta.tracks[tid].lastms - myMeta.tracks[tid].firstms) / myMeta.tracks[tid].fragments.size() > longestFragment){
|
|
||||||
longestFragment = (myMeta.tracks[tid].lastms - myMeta.tracks[tid].firstms) / myMeta.tracks[tid].fragments.size();
|
|
||||||
}
|
|
||||||
result << "#EXTM3U\r\n#EXT-X-TARGETDURATION:" << (longestFragment / 1000) + 1 << "\r\n";
|
|
||||||
|
|
||||||
std::deque<std::string> lines;
|
std::deque<std::string> lines;
|
||||||
for (std::deque<DTSC::Fragment>::iterator it = myMeta.tracks[tid].fragments.begin(); it != myMeta.tracks[tid].fragments.end(); it++){
|
for (std::deque<DTSC::Fragment>::iterator it = myMeta.tracks[tid].fragments.begin(); it != myMeta.tracks[tid].fragments.end(); it++){
|
||||||
long long int starttime = myMeta.tracks[tid].getKey(it->getNumber()).getTime();
|
long long int starttime = myMeta.tracks[tid].getKey(it->getNumber()).getTime();
|
||||||
|
|
Loading…
Add table
Reference in a new issue