Skip to content
Snippets Groups Projects
Commit 18d58fde authored by Nicolas Pope's avatar Nicolas Pope
Browse files

More debug and netstream buf fixes

parent 1724d2e0
No related branches found
No related tags found
No related merge requests found
...@@ -297,8 +297,9 @@ void Net::_run() { ...@@ -297,8 +297,9 @@ void Net::_run() {
#endif #endif
while (active_) { while (active_) {
auto now = ftl::time::get_time(); auto now = ftl::time::get_time();
int64_t nextTs = now + 20; int64_t nextTs = now + 200;
int activeStates = 0; int activeStates = 0;
bool hasNext = false;
// For every state // For every state
SHARED_LOCK(statesMtx_, lk); SHARED_LOCK(statesMtx_, lk);
...@@ -316,10 +317,10 @@ void Net::_run() { ...@@ -316,10 +317,10 @@ void Net::_run() {
int64_t cts = now - state->base_local_ts_; int64_t cts = now - state->base_local_ts_;
bool hasNext = false; bool hasLocalNext = false;
{ {
UNIQUE_LOCK(state->mtx, lk); UNIQUE_LOCK(state->mtx, lk2);
auto it = state->buffer.begin(); auto it = state->buffer.begin();
while (it != state->buffer.end()) { while (it != state->buffer.end()) {
if (it->done) { if (it->done) {
...@@ -356,9 +357,13 @@ void Net::_run() { ...@@ -356,9 +357,13 @@ void Net::_run() {
} }
} }
if (ats == 0) {
LOG(WARNING) << "No packets to present: " << cts;
}
auto current = state->buffer.begin(); auto current = state->buffer.begin();
while (current != state->buffer.end()) { while (current != state->buffer.end()) {
lk2.unlock(); // lk2.unlock();
int64_t pts = current->packets.first.timestamp - state->base_pkt_ts_ + buffering_; int64_t pts = current->packets.first.timestamp - state->base_pkt_ts_ + buffering_;
...@@ -380,25 +385,26 @@ void Net::_run() { ...@@ -380,25 +385,26 @@ void Net::_run() {
} else { } else {
int64_t next = pts + state->base_local_ts_; int64_t next = pts + state->base_local_ts_;
nextTs = std::min(nextTs, next); nextTs = std::min(nextTs, next);
hasLocalNext = true;
hasNext = true; hasNext = true;
break; break;
} }
lk2.lock(); // lk2.lock();
++current; ++current;
} }
} }
if (!hasNext) { if (!hasLocalNext) {
nextTs = std::min(nextTs, now + 10); // nextTs = std::min(nextTs, now + 10);
// TODO: Also, increase buffering // TODO: Also, increase buffering
LOG(WARNING) << "Buffer underun " << nextTs; LOG(WARNING) << "Buffer underun " << now;
} }
} }
lk.unlock(); lk.unlock();
auto used = ftl::time::get_time(); auto used = ftl::time::get_time();
int64_t spare = nextTs - used; int64_t spare = (hasNext) ? nextTs - used : 10;
if (activeStates > 0) LOG(INFO) << "Sleeping for " << spare; if (activeStates > 0) LOG(INFO) << "Sleeping for " << spare;
sleep_for(milliseconds(std::max(int64_t(1), spare))); sleep_for(milliseconds(std::max(int64_t(1), spare)));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment