diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 02995228..f14c0516 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -206,6 +206,8 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){ newPos.seekTime = lastPos.seekTime+1; } } + }else{ + buffers.clear(); } std::string newTrack = trackMapping[newPos.trackID]; while (buffers.count(newPos) > 0){ @@ -237,10 +239,10 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){ } int keySize = metadata["tracks"][newTrack]["keys"].size(); if (buffercount > 1){ - metadata["tracks"][newTrack]["lastms"] = newPack["time"]; #define prevKey metadata["tracks"][newTrack]["keys"][keySize - 1] if (newPack.isMember("keyframe") || !keySize || (datapointertype != VIDEO && newPack["time"].asInt() - 2000 > prevKey["time"].asInt())){ updateMeta = true; + metadata["tracks"][newTrack]["lastms"] = newPack["time"]; keyframes[newPos.trackID].insert(newPos); JSON::Value key; key["time"] = newPack["time"]; diff --git a/lib/procs.cpp b/lib/procs.cpp index 0fa99625..abeb09d2 100644 --- a/lib/procs.cpp +++ b/lib/procs.cpp @@ -91,40 +91,44 @@ void Util::Procs::childsig_handler(int signum){ return; } int status; - pid_t ret = waitpid( -1, &status, 0); - if (ret <= 0){ - childsig_handler(signum); - return; - } - int exitcode; - if (WIFEXITED(status)){ - exitcode = WEXITSTATUS(status); - }else if (WIFSIGNALED(status)){ - exitcode = -WTERMSIG(status); - }else{/* not possible */ - return; - } + pid_t ret = -1; + while (ret != 0){ + ret = waitpid( -1, &status, WNOHANG); + if (ret <= 0){ //ignore, would block otherwise + if (ret == 0 || errno != EINTR){ + return; + } + } + int exitcode; + if (WIFEXITED(status)){ + exitcode = WEXITSTATUS(status); + }else if (WIFSIGNALED(status)){ + exitcode = -WTERMSIG(status); + }else{/* not possible */ + return; + } #if DEBUG >= 1 - std::string pname = plist[ret]; + std::string pname = plist[ret]; #endif - plist.erase(ret); + plist.erase(ret); #if DEBUG >= 1 - if (isActive(pname)){ - Stop(pname); - } else{ - //can this ever happen? - std::cerr << "Process " << pname << " fully terminated." << std::endl; - } + if (isActive(pname)){ + Stop(pname); + } else{ + //can this ever happen? + std::cerr << "Process " << pname << " fully terminated." << std::endl; + } #endif - if (exitHandlers.count(ret) > 0){ - TerminationNotifier tn = exitHandlers[ret]; - exitHandlers.erase(ret); + if (exitHandlers.count(ret) > 0){ + TerminationNotifier tn = exitHandlers[ret]; + exitHandlers.erase(ret); #if DEBUG >= 2 - std::cerr << "Calling termination handler for " << pname << std::endl; + std::cerr << "Calling termination handler for " << pname << std::endl; #endif - tn(ret, exitcode); + tn(ret, exitcode); + } } }