Rewrite of Comms

This commit is contained in:
Thulinma 2020-10-30 22:38:29 +01:00
parent c6265f6659
commit 7297336e46
14 changed files with 173 additions and 303 deletions

View file

@ -857,15 +857,14 @@ namespace Mist{
tid = thisPacket.getTrackId();
idx = M.trackIDToIndex(tid, getpid());
if (thisPacket && !userSelect.count(idx)){
userSelect[idx].reload(streamName, idx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[idx].reload(streamName, idx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
while (thisPacket && config->is_active && userSelect[idx].isAlive()){
while (thisPacket && config->is_active && userSelect[idx]){
if (userSelect[idx].getStatus() == COMM_STATUS_REQDISCONNECT){
Util::logExitReason("buffer requested shutdown");
break;
}
bufferLivePacket(thisPacket);
userSelect[idx].keepAlive();
getNext();
if (!thisPacket){
Util::logExitReason("invalid packet from getNext");
@ -874,14 +873,14 @@ namespace Mist{
tid = thisPacket.getTrackId();
idx = M.trackIDToIndex(tid, getpid());
if (thisPacket && !userSelect.count(idx)){
userSelect[idx].reload(streamName, idx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[idx].reload(streamName, idx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
if (Util::bootSecs() - statTimer > 1){
// Connect to stats for INPUT detection
if (!statComm){statComm.reload();}
if (statComm){
if (!statComm.isAlive()){
if (!statComm){
config->is_active = false;
Util::logExitReason("received shutdown request from controller");
return;
@ -896,7 +895,6 @@ namespace Mist{
statComm.setTime(now - startTime);
statComm.setLastSecond(0);
statComm.setHost(getConnectedBinHost());
statComm.keepAlive();
}
statTimer = Util::bootSecs();
@ -911,33 +909,31 @@ namespace Mist{
getNext();
if (thisPacket && !userSelect.count(thisPacket.getTrackId())){
size_t tid = thisPacket.getTrackId();
userSelect[tid].reload(streamName, tid, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[tid].reload(streamName, tid, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
while (thisPacket && config->is_active && userSelect[thisPacket.getTrackId()].isAlive()){
while (thisPacket && config->is_active && userSelect[thisPacket.getTrackId()]){
thisPacket.nullMember("bpos");
while (config->is_active && userSelect[thisPacket.getTrackId()].isAlive() &&
while (config->is_active && userSelect[thisPacket.getTrackId()] &&
Util::bootMS() + SIMULATED_LIVE_BUFFER < (thisPacket.getTime() + timeOffset) + simStartTime){
Util::sleep(std::min(((thisPacket.getTime() + timeOffset) + simStartTime) - (Util::getMS() + SIMULATED_LIVE_BUFFER),
(uint64_t)1000));
userSelect[thisPacket.getTrackId()].keepAlive();
}
uint64_t originalTime = thisPacket.getTime();
thisPacket.setTime(originalTime + timeOffset);
bufferLivePacket(thisPacket);
thisPacket.setTime(originalTime);
userSelect[thisPacket.getTrackId()].keepAlive();
getNext();
if (thisPacket && !userSelect.count(thisPacket.getTrackId())){
size_t tid = thisPacket.getTrackId();
userSelect[tid].reload(streamName, tid, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[tid].reload(streamName, tid, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
if (Util::bootSecs() - statTimer > 1){
// Connect to stats for INPUT detection
if (!statComm){statComm.reload();}
if (statComm){
if (!statComm.isAlive()){
if (statComm.getStatus() == COMM_STATUS_REQDISCONNECT){
config->is_active = false;
Util::logExitReason("received shutdown request from controller");
return;
@ -952,7 +948,6 @@ namespace Mist{
statComm.setTime(now - startTime);
statComm.setLastSecond(0);
statComm.setHost(getConnectedBinHost());
statComm.keepAlive();
}
statTimer = Util::bootSecs();
@ -961,7 +956,7 @@ namespace Mist{
if (!thisPacket){
Util::logExitReason("invalid packet from getNext");
}
if (thisPacket && !userSelect[thisPacket.getTrackId()].isAlive()){
if (thisPacket && !userSelect[thisPacket.getTrackId()]){
Util::logExitReason("buffer shutdown");
}
}
@ -1411,8 +1406,7 @@ namespace Mist{
bool isAlive = false;
for (std::map<size_t, Comms::Users>::iterator it = userSelect.begin(); it != userSelect.end(); it++){
if (it->second.isAlive()){isAlive = true;}
it->second.keepAlive();
if (it->second){isAlive = true;}
}
return isAlive && config->is_active;
}

View file

@ -155,9 +155,7 @@ namespace Mist{
{
Comms::Users cleanUsers;
cleanUsers.reload(streamName);
for (size_t i = cleanUsers.firstValid(); i < cleanUsers.endValid(); ++i){
cleanUsers.setStatus(COMM_STATUS_INVALID, i);
}
cleanUsers.finishAll();
cleanUsers.setMaster(true);
}
// Delete the live stream semaphore, if any.
@ -389,8 +387,8 @@ namespace Mist{
}
void inputBuffer::removeTrack(size_t tid){
size_t lastUser = users.endValid();
for (size_t i = users.firstValid(); i < lastUser; ++i){
size_t lastUser = users.recordCount();
for (size_t i = 0; i < lastUser; ++i){
if (users.getStatus(i) == COMM_STATUS_INVALID){continue;}
if (!(users.getStatus(i) & COMM_STATUS_SOURCE)){continue;}
if (users.getTrack(i) != tid){continue;}

View file

@ -169,7 +169,7 @@ namespace Mist{
std::set<size_t> validTracks = M.getMySourceTracks(getpid());
userSelect.clear();
for (std::set<size_t>::iterator it = validTracks.begin(); it != validTracks.end(); ++it){
userSelect[*it].reload(streamName, *it, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[*it].reload(streamName, *it, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
break;
}

View file

@ -212,7 +212,7 @@ namespace Mist{
// Connect to stats for INPUT detection
statComm.reload();
if (statComm){
if (!statComm.isAlive()){
if (statComm.getStatus() == COMM_STATUS_REQDISCONNECT){
config->is_active = false;
Util::logExitReason("received shutdown request from controller");
return;
@ -227,7 +227,6 @@ namespace Mist{
statComm.setTime(now - startTime);
statComm.setLastSecond(0);
statComm.setHost(getConnectedBinHost());
statComm.keepAlive();
}
}
}
@ -402,7 +401,7 @@ namespace Mist{
}else{
if (!userSelect.count(idx)){
WARN_MSG("Reloading track %zu, index %zu", pkt.getTrackId(), idx);
userSelect[idx].reload(streamName, idx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[idx].reload(streamName, idx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
if (userSelect[idx].getStatus() == COMM_STATUS_REQDISCONNECT){
Util::logExitReason("buffer requested shutdown");

View file

@ -58,8 +58,7 @@ void parseThread(void *mistIn){
threadTimer[tid] = Util::bootSecs();
}
while (Util::bootSecs() - threadTimer[tid] < THREAD_TIMEOUT && cfgPointer->is_active &&
(!dataTrack || (userConn ? userConn.isAlive() : true))){
if (dataTrack){userConn.keepAlive();}
(!dataTrack || (userConn ? userConn : true))){
liveStream.parse(tid);
if (!liveStream.hasPacket(tid)){
Util::sleep(100);
@ -95,7 +94,7 @@ void parseThread(void *mistIn){
idx = meta.trackIDToIndex(tid, getpid());
if (idx != INVALID_TRACK_ID){
//Successfully assigned a track index! Inform the buffer we're pushing
userConn.reload(globalStreamName, idx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userConn.reload(globalStreamName, idx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
//Any kind of failure? Retry later.
if (idx == INVALID_TRACK_ID || !meta.trackValid(idx)){
@ -137,7 +136,7 @@ void parseThread(void *mistIn){
std::string reason = "unknown reason";
if (!(Util::bootSecs() - threadTimer[tid] < THREAD_TIMEOUT)){reason = "thread timeout";}
if (!cfgPointer->is_active){reason = "input shutting down";}
if (!(!liveStream.isDataTrack(tid) || userConn.isAlive())){
if (!(!liveStream.isDataTrack(tid) || userConn)){
reason = "buffer disconnect";
cfgPointer->is_active = false;
}
@ -588,7 +587,7 @@ namespace Mist{
// Connect to stats for INPUT detection
statComm.reload();
if (statComm){
if (!statComm.isAlive()){
if (statComm.getStatus() == COMM_STATUS_REQDISCONNECT){
config->is_active = false;
Util::logExitReason("received shutdown request from controller");
return;
@ -603,7 +602,6 @@ namespace Mist{
statComm.setTime(now - startTime);
statComm.setLastSecond(0);
statComm.setHost(getConnectedBinHost());
statComm.keepAlive();
}
std::set<size_t> activeTracks = liveStream.getActiveTracks();