Added playUntil support to live stream buffer, fixing segmented protocols.
This commit is contained in:
parent
dfa329f6ed
commit
82b5f9ef59
3 changed files with 17 additions and 11 deletions
|
@ -132,6 +132,11 @@ namespace Buffer {
|
||||||
}
|
}
|
||||||
case 'p': { //play
|
case 'p': { //play
|
||||||
usr->myRing->playCount = -1;
|
usr->myRing->playCount = -1;
|
||||||
|
if (usr->S.Received().get().size() >= 2){
|
||||||
|
usr->playUntil = atoi(usr->S.Received().get().substr(2).c_str());
|
||||||
|
}else{
|
||||||
|
usr->playUntil = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'o': { //once-play
|
case 'o': { //once-play
|
||||||
|
@ -203,20 +208,18 @@ namespace Buffer {
|
||||||
while (buffer_running){
|
while (buffer_running){
|
||||||
if (thisStream->getIPInput().connected()){
|
if (thisStream->getIPInput().connected()){
|
||||||
if (thisStream->getIPInput().spool()){
|
if (thisStream->getIPInput().spool()){
|
||||||
bool packed_parsed = false;
|
while (true){
|
||||||
do{
|
|
||||||
thisStream->getWriteLock();
|
thisStream->getWriteLock();
|
||||||
if (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){
|
if (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){
|
||||||
thisStream->dropWriteLock(true);
|
thisStream->dropWriteLock(true);
|
||||||
packed_parsed = true;
|
|
||||||
}else{
|
}else{
|
||||||
thisStream->dropWriteLock(false);
|
thisStream->dropWriteLock(false);
|
||||||
packed_parsed = false;
|
Util::sleep(10); //10ms wait
|
||||||
Util::sleep(1); //1ms wait
|
break;
|
||||||
}
|
}
|
||||||
}while (packed_parsed);
|
}
|
||||||
}else{
|
}else{
|
||||||
Util::sleep(1); //1ms wait
|
Util::sleep(10); //10ms wait
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Util::sleep(1000); //1s wait
|
Util::sleep(1000); //1s wait
|
||||||
|
|
|
@ -81,9 +81,10 @@ namespace Buffer {
|
||||||
myRing->waiting = false;
|
myRing->waiting = false;
|
||||||
Stream::get()->getReadLock();
|
Stream::get()->getReadLock();
|
||||||
myRing->b = Stream::get()->getStream()->getNext(myRing->b, allowedTracks);
|
myRing->b = Stream::get()->getStream()->getNext(myRing->b, allowedTracks);
|
||||||
if (Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && myRing->playCount > 0){
|
if ((Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && (myRing->playCount > 0)) || (playUntil && playUntil <= Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt())){
|
||||||
myRing->playCount--;
|
myRing->playCount--;
|
||||||
if ( !myRing->playCount){
|
if (myRing->playCount < 1 || playUntil <= Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt()){
|
||||||
|
myRing->playCount = 0;
|
||||||
JSON::Value pausemark;
|
JSON::Value pausemark;
|
||||||
pausemark["datatype"] = "pause_marker";
|
pausemark["datatype"] = "pause_marker";
|
||||||
pausemark["time"] = Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt();
|
pausemark["time"] = Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt();
|
||||||
|
@ -113,9 +114,10 @@ namespace Buffer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
myRing->b = Stream::get()->getStream()->getNext(myRing->b, allowedTracks);
|
myRing->b = Stream::get()->getStream()->getNext(myRing->b, allowedTracks);
|
||||||
if (Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && myRing->playCount > 0){
|
if ((Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && (myRing->playCount > 0)) || (playUntil && playUntil <= Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt())){
|
||||||
myRing->playCount--;
|
myRing->playCount--;
|
||||||
if ( !myRing->playCount){
|
if (myRing->playCount < 1 || playUntil <= Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt()){
|
||||||
|
myRing->playCount = 0;
|
||||||
JSON::Value pausemark;
|
JSON::Value pausemark;
|
||||||
pausemark["datatype"] = "pause_marker";
|
pausemark["datatype"] = "pause_marker";
|
||||||
pausemark["time"] = Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt();
|
pausemark["time"] = Stream::get()->getStream()->getPacket(myRing->b)["time"].asInt();
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace Buffer {
|
||||||
public:
|
public:
|
||||||
DTSC::Ring * myRing; ///< Ring of the buffer for this user.
|
DTSC::Ring * myRing; ///< Ring of the buffer for this user.
|
||||||
int MyNum; ///< User ID of this user.
|
int MyNum; ///< User ID of this user.
|
||||||
|
unsigned int playUntil; ///< Time until where is being played or zero if undefined.
|
||||||
std::string MyStr; ///< User ID of this user as a string.
|
std::string MyStr; ///< User ID of this user as a string.
|
||||||
std::string inbuffer; ///< Used to buffer input data.
|
std::string inbuffer; ///< Used to buffer input data.
|
||||||
int currsend; ///< Current amount of bytes sent.
|
int currsend; ///< Current amount of bytes sent.
|
||||||
|
|
Loading…
Add table
Reference in a new issue