Working live support once more.
This commit is contained in:
parent
593805f0ef
commit
68b74997fc
1 changed files with 32 additions and 14 deletions
46
lib/dtsc.cpp
46
lib/dtsc.cpp
|
@ -176,6 +176,9 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
livePos newPos;
|
livePos newPos;
|
||||||
newPos.trackID = newPack["trackid"].asInt();
|
newPos.trackID = newPack["trackid"].asInt();
|
||||||
newPos.seekTime = newPack["time"].asInt();
|
newPos.seekTime = newPack["time"].asInt();
|
||||||
|
while (buffers.count(newPos) > 0){
|
||||||
|
newPos.seekTime++;
|
||||||
|
}
|
||||||
buffers[newPos] = newPack;
|
buffers[newPos] = newPack;
|
||||||
buffers[newPos].toNetPacked();//make sure package is packed and ready
|
buffers[newPos].toNetPacked();//make sure package is packed and ready
|
||||||
datapointertype = INVALID;
|
datapointertype = INVALID;
|
||||||
|
@ -224,21 +227,18 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
}
|
}
|
||||||
metadata["live"] = 1ll;
|
metadata["live"] = 1ll;
|
||||||
}
|
}
|
||||||
unsigned int timeBuffered = 0;
|
//increase buffer size if too little time available
|
||||||
if (keySize > 1){
|
unsigned int timeBuffered = buffers.rbegin()->second["time"].asInt() - buffers.begin()->second["time"].asInt();
|
||||||
//increase buffer size if no keyframes available or too little time available
|
|
||||||
timeBuffered = buffers.rbegin()->second["time"].asInt() - buffers.begin()->second["time"].asInt();
|
|
||||||
}
|
|
||||||
if (buffercount > 1 && timeBuffered < buffertime){
|
if (buffercount > 1 && timeBuffered < buffertime){
|
||||||
buffercount++;
|
buffercount = buffers.size();
|
||||||
|
if (buffercount < 2){buffercount = 2;}
|
||||||
}
|
}
|
||||||
|
//std::cout << buffers.size() << " - " << buffercount << std::endl;
|
||||||
while (buffers.size() > buffercount){
|
while (buffers.size() > buffercount){
|
||||||
if (keyframes[buffers.begin()->first.trackID].count(buffers.begin()->first)){
|
if (keyframes[buffers.begin()->first.trackID].count(buffers.begin()->first)){
|
||||||
//if there are < 3 keyframes, throwing one away would mean less than 2 left.
|
//if there are < 3 keyframes, throwing one away would mean less than 2 left.
|
||||||
if (keyframes[buffers.begin()->first.trackID].size() < 3){
|
if (keyframes[buffers.begin()->first.trackID].size() < 3){
|
||||||
//so, we don't throw it away but instead increase the buffer size
|
std::cout << "Warning - track " << buffers.begin()->first.trackID << " doesn't have enough keyframes to be reliably served." << std::endl;
|
||||||
buffercount++;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
std::string track = trackMapping[buffers.begin()->first.trackID];
|
std::string track = trackMapping[buffers.begin()->first.trackID];
|
||||||
keyframes[buffers.begin()->first.trackID].erase(buffers.begin()->first);
|
keyframes[buffers.begin()->first.trackID].erase(buffers.begin()->first);
|
||||||
|
@ -332,7 +332,14 @@ DTSC::Ring::Ring(livePos v){
|
||||||
/// This Ring will be kept updated so it always points to valid data or has the starved boolean set.
|
/// This Ring will be kept updated so it always points to valid data or has the starved boolean set.
|
||||||
/// Don't forget to call dropRing() for all requested Ring classes that are no longer neccessary!
|
/// Don't forget to call dropRing() for all requested Ring classes that are no longer neccessary!
|
||||||
DTSC::Ring * DTSC::Stream::getRing(){
|
DTSC::Ring * DTSC::Stream::getRing(){
|
||||||
return new DTSC::Ring(buffers.begin()->first);
|
livePos tmp = buffers.begin()->first;
|
||||||
|
std::map<int,std::set<livePos> >::iterator it;
|
||||||
|
for (it = keyframes.begin(); it != keyframes.end(); it++){
|
||||||
|
if ((*it->second.begin()).seekTime > tmp.seekTime){
|
||||||
|
tmp = *it->second.begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DTSC::Ring(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a given out Ring class from memory and internal Ring list.
|
/// Deletes a given out Ring class from memory and internal Ring list.
|
||||||
|
@ -355,13 +362,24 @@ int DTSC::Stream::canSeekms(unsigned int ms){
|
||||||
}
|
}
|
||||||
|
|
||||||
DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> & allowedTracks){
|
DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> & allowedTracks){
|
||||||
|
std::set<int> seekTracks = allowedTracks;
|
||||||
livePos result = buffers.begin()->first;
|
livePos result = buffers.begin()->first;
|
||||||
|
for (std::set<int>::iterator it = allowedTracks.begin(); it != allowedTracks.end(); it++){
|
||||||
|
if (getTrackById(*it).isMember("type") && getTrackById(*it)["type"].asString() == "video"){
|
||||||
|
int trackNo = *it;
|
||||||
|
seekTracks.clear();
|
||||||
|
seekTracks.insert(trackNo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (std::map<livePos,JSON::Value>::iterator bIt = buffers.begin(); bIt != buffers.end(); bIt++){
|
for (std::map<livePos,JSON::Value>::iterator bIt = buffers.begin(); bIt != buffers.end(); bIt++){
|
||||||
if (allowedTracks.find(bIt->first.trackID) != allowedTracks.end()){
|
if (seekTracks.find(bIt->first.trackID) != seekTracks.end()){
|
||||||
if (bIt->first.seekTime > ms){
|
if (bIt->second.isMember("keyframe")){
|
||||||
break;
|
result = bIt->first;
|
||||||
|
if (bIt->first.seekTime >= ms){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result = bIt->first;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue