diff --git a/src/output/output_hds.cpp b/src/output/output_hds.cpp index 1cf27a81..fd08f2ae 100644 --- a/src/output/output_hds.cpp +++ b/src/output/output_hds.cpp @@ -210,13 +210,16 @@ namespace Mist { std::cout << "Fragment " << fragNum << " too old" << std::endl; return; } - if (fragNum > myMeta.tracks[tid].missedFrags + myMeta.tracks[tid].fragments.size() - 1){ - H.Clean(); - H.SetBody("Proxy, re-request this in a second or two.\n"); - H.SendResponse("208", "Ask again later", myConn); - H.Clean(); //clean for any possible next requests - std::cout << "Fragment after fragment " << fragNum << " not available yet" << std::endl; - return; + //delay if we don't have the next fragment available yet + unsigned int timeout = 0; + while (myConn && fragNum > myMeta.tracks[tid].missedFrags + myMeta.tracks[tid].fragments.size() - 1){ + //time out after 21 seconds + if (++timeout > 42){ + myConn.close(); + break; + } + Util::sleep(500); + updateMeta(); } mstime = myMeta.tracks[tid].getKey(myMeta.tracks[tid].fragments[fragNum - myMeta.tracks[tid].missedFrags].getNumber()).getTime(); mslen = myMeta.tracks[tid].fragments[fragNum - myMeta.tracks[tid].missedFrags].getDuration(); diff --git a/src/output/output_hls.cpp b/src/output/output_hls.cpp index 486e86c0..cd40bd67 100644 --- a/src/output/output_hls.cpp +++ b/src/output/output_hls.cpp @@ -304,8 +304,21 @@ namespace Mist { } if (myMeta.live){ - /// \todo Detection of out-of-range parts. - int seekable = canSeekms(from); + unsigned int timeout = 0; + int seekable; + do { + seekable = canSeekms(from); + /// \todo Detection of out-of-range parts. + if (seekable > 0){ + //time out after 21 seconds + if (++timeout > 42){ + myConn.close(); + break; + } + Util::sleep(500); + updateMeta(); + } + }while (myConn && seekable > 0); if (seekable < 0){ H.Clean(); H.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n"); @@ -314,14 +327,6 @@ namespace Mist { DEBUG_MSG(DLVL_WARN, "Fragment @ %llu too old", from); return; } - if (seekable > 0){ - H.Clean(); - H.SetBody("Proxy, re-request this in a second or two.\n"); - myConn.SendNow(H.BuildResponse("208", "Ask again later")); - H.Clean(); //clean for any possible next requests - DEBUG_MSG(DLVL_WARN, "Fragment @ %llu not available yet", from); - return; - } } seek(from); diff --git a/src/output/output_hss.cpp b/src/output/output_hss.cpp index c91f5172..4fd889cb 100644 --- a/src/output/output_hss.cpp +++ b/src/output/output_hss.cpp @@ -112,18 +112,31 @@ namespace Mist { selectedTracks.insert(tid); if (myMeta.live) { updateMeta(); - int seekable = canSeekms(seekTime); - if (seekable == 0){ - // iff the fragment in question is available, check if the next is available too - for (std::deque::iterator it = myMeta.tracks[tid].keys.begin(); it != myMeta.tracks[tid].keys.end(); it++){ - if (it->getTime() >= seekTime){ - if ((it + 1) == myMeta.tracks[tid].keys.end()){ - seekable = 1; + unsigned int timeout = 0; + int seekable; + do { + seekable = canSeekms(seekTime); + if (seekable == 0){ + // iff the fragment in question is available, check if the next is available too + for (std::deque::iterator it = myMeta.tracks[tid].keys.begin(); it != myMeta.tracks[tid].keys.end(); it++){ + if (it->getTime() >= seekTime){ + if ((it + 1) == myMeta.tracks[tid].keys.end()){ + seekable = 1; + } + break; } - break; } } - } + if (seekable > 0){ + //time out after 21 seconds + if (++timeout > 42){ + myConn.close(); + break; + } + Util::sleep(500); + updateMeta(); + } + }while (myConn && seekable > 0); if (seekable < 0){ H.Clean(); H.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n"); @@ -134,16 +147,6 @@ namespace Mist { wantRequest = true; return; } - if (seekable > 0){ - H.Clean(); - H.SetBody("Proxy, re-request this in a second or two.\n"); - myConn.SendNow(H.BuildResponse("208", "Ask again later")); - H.Clean(); //clean for any possible next requests - std::cout << "Fragment @ " << seekTime << "ms not available yet (" << myMeta.tracks[tid].firstms << " - " << myMeta.tracks[tid].lastms << " ms)" << std::endl; - stop(); - wantRequest = true; - return; - } } seek(seekTime); playUntil = (*(keyTimes[tid].upper_bound(seekTime)));