From fcd11f44c47a04566064f6403eb02bd846ec7e98 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 6 Jun 2016 16:30:30 +0200 Subject: [PATCH] Optimized waiting for streams/tracks. --- lib/socket.cpp | 2 ++ src/output/output.cpp | 21 +++++++++++++-------- src/output/output_rtmp.cpp | 9 +-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/socket.cpp b/lib/socket.cpp index 070dd3fd..bf7f92e4 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -518,6 +518,7 @@ unsigned int Socket::Connection::iwrite(const void * buffer, int len) { } } if (r == 0 && (sock >= 0)) { + DONTEVEN_MSG("Socket closed by remote"); close(); } up += r; @@ -560,6 +561,7 @@ int Socket::Connection::iread(void * buffer, int len, int flags) { } } if (r == 0) { + DONTEVEN_MSG("Socket closed by remote"); close(); } down += r; diff --git a/src/output/output.cpp b/src/output/output.cpp index 6ba36189..315396fb 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -141,7 +141,6 @@ namespace Mist { onFail(); return; } - selectDefaultTracks(); sought = false; /*LTS-START*/ if(Triggers::shouldTrigger("CONN_PLAY", streamName)){ @@ -213,11 +212,16 @@ namespace Mist { bool Output::isReadyForPlay() { if (myMeta.tracks.size()){ - for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ - if (it->second.keys.size() >= 2){ - return true; - } + if (!selectedTracks.size()){ + selectDefaultTracks(); } + if (myMeta.tracks[getMainSelectedTrack()].keys.size() >= 2){ + return true; + }else{ + HIGH_MSG("NOT READY YET (%lu tracks, %lu = %lu keys)", myMeta.tracks.size(), getMainSelectedTrack(), myMeta.tracks[getMainSelectedTrack()].keys.size()); + } + }else{ + HIGH_MSG("NOT READY YET (%lu tracks)", myMeta.tracks.size()); } return false; } @@ -254,10 +258,11 @@ namespace Mist { } stats(true); updateMeta(); - if (myMeta.live && !isReadyForPlay()){ + selectDefaultTracks(); + if (!myMeta.vod && !isReadyForPlay()){ unsigned long long waitUntil = Util::epoch() + 15; - while (!isReadyForPlay()){ - if (Util::epoch() > waitUntil){ + while (!myMeta.vod && !isReadyForPlay()){ + if (Util::epoch() > waitUntil + 45 || (!selectedTracks.size() && Util::epoch() > waitUntil)){ INFO_MSG("Giving up waiting for playable tracks. Stream: %s, IP: %s", streamName.c_str(), getConnectedHost().c_str()); break; } diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index b3da1b94..ce80153d 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -158,14 +158,7 @@ namespace Mist { if (isPushing){ return true; } - if (myMeta.tracks.size()){ - for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ - if (it->second.keys.size() >= 2){ - return true; - } - } - } - return false; + return Output::isReadyForPlay(); } std::string OutRTMP::getStatsName(){