Fixed DTSC Stream library multibitrate support.
This commit is contained in:
parent
8ddc1ab884
commit
785136f7cc
2 changed files with 21 additions and 6 deletions
21
lib/dtsc.cpp
21
lib/dtsc.cpp
|
@ -179,6 +179,7 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
newPos.trackID = newPack["trackid"].asInt();
|
newPos.trackID = newPack["trackid"].asInt();
|
||||||
newPos.seekTime = newPack["time"].asInt();
|
newPos.seekTime = newPack["time"].asInt();
|
||||||
buffers[newPos] = newPack;
|
buffers[newPos] = newPack;
|
||||||
|
buffers[newPos].toNetPacked();//make sure package is packed and ready
|
||||||
datapointertype = INVALID;
|
datapointertype = INVALID;
|
||||||
///\todo Save keyframes when they arrive.
|
///\todo Save keyframes when they arrive.
|
||||||
if (newPack.isMember("data")){
|
if (newPack.isMember("data")){
|
||||||
|
@ -285,10 +286,10 @@ void DTSC::Stream::setBufferTime(unsigned int ms){
|
||||||
|
|
||||||
std::string & DTSC::Stream::outPacket(){
|
std::string & DTSC::Stream::outPacket(){
|
||||||
static std::string emptystring;
|
static std::string emptystring;
|
||||||
if (!buffers.size() || !buffers.begin()->second.isObject()){
|
if (!buffers.size() || !buffers.rbegin()->second.isObject()){
|
||||||
return emptystring;
|
return emptystring;
|
||||||
}
|
}
|
||||||
return buffers.begin()->second.toNetPacked();
|
return buffers.rbegin()->second.toNetPacked();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a packed DTSC packet, ready to sent over the network.
|
/// Returns a packed DTSC packet, ready to sent over the network.
|
||||||
|
@ -406,7 +407,7 @@ int DTSC::Stream::canSeekms(unsigned int ms){
|
||||||
if ( !buffers.size()){
|
if ( !buffers.size()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ms > (buffers.end()--)->second["time"].asInt()){
|
if (ms > buffers.rbegin()->second["time"].asInt()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ms < buffers.begin()->second["time"].asInt()){
|
if (ms < buffers.begin()->second["time"].asInt()){
|
||||||
|
@ -415,7 +416,7 @@ int DTSC::Stream::canSeekms(unsigned int ms){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> allowedTracks){
|
DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> & allowedTracks){
|
||||||
livePos result = buffers.begin()->first;
|
livePos result = buffers.begin()->first;
|
||||||
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 (allowedTracks.find(bIt->first.trackID) != allowedTracks.end()){
|
||||||
|
@ -428,6 +429,18 @@ DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> allowedTracks)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DTSC::Stream::isNewest(DTSC::livePos & pos){
|
||||||
|
return (buffers.upper_bound(pos) == buffers.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
DTSC::livePos DTSC::Stream::getNext(DTSC::livePos & pos, std::set<int> & allowedTracks){
|
||||||
|
if (!isNewest(pos)){
|
||||||
|
return (buffers.upper_bound(pos))->first;
|
||||||
|
}else{
|
||||||
|
return livePos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Properly cleans up the object for erasing.
|
/// Properly cleans up the object for erasing.
|
||||||
/// Drops all Ring classes that have been given out.
|
/// Drops all Ring classes that have been given out.
|
||||||
DTSC::Stream::~Stream(){
|
DTSC::Stream::~Stream(){
|
||||||
|
|
|
@ -202,9 +202,11 @@ namespace DTSC {
|
||||||
void dropRing(Ring * ptr);
|
void dropRing(Ring * ptr);
|
||||||
void updateHeaders();
|
void updateHeaders();
|
||||||
int canSeekms(unsigned int ms);
|
int canSeekms(unsigned int ms);
|
||||||
livePos msSeek(unsigned int ms, std::set<int> allowedTracks);
|
livePos msSeek(unsigned int ms, std::set<int> & allowedTracks);
|
||||||
void setBufferTime(unsigned int ms);
|
void setBufferTime(unsigned int ms);
|
||||||
private:
|
bool isNewest(DTSC::livePos & pos);
|
||||||
|
DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
|
||||||
|
private:
|
||||||
std::map<livePos,JSON::Value> buffers;
|
std::map<livePos,JSON::Value> buffers;
|
||||||
std::map<int,std::set<livePos> > keyframes;
|
std::map<int,std::set<livePos> > keyframes;
|
||||||
void addPacket(JSON::Value & newPack);
|
void addPacket(JSON::Value & newPack);
|
||||||
|
|
Loading…
Add table
Reference in a new issue