Skip to content

Commit

Permalink
Segmentloader: retry 10 secs if download fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Sep 1, 2017
1 parent 5df3ba1 commit cb3c12b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <iostream>
#include <cstring>
#include "../oscompat.h"
#include "../log.h"
#include <math.h>

using namespace adaptive;
Expand Down Expand Up @@ -141,7 +142,15 @@ void AdaptiveStream::worker()
do {
thread_data_->signal_dl_.wait(lckdl);

bool ret = download_segment();
bool ret(download_segment());
unsigned int retryCount(10);

while (!ret && !stopped_ && retryCount-- && tree_.has_timeshift_buffer_)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
Log(LOGLEVEL_DEBUG, "AdaptiveStream: trying to reload segment ...");
ret = download_segment();
}

//Signal finished download
{
Expand Down
4 changes: 3 additions & 1 deletion src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace adaptive
seg.range_begin_ += fragmentDuration;
seg.range_end_ ++;

Log(LOGLEVEL_DEBUG, "AdaptiveTree: insert live segment: pts: %llu range_end: %llu", seg.startPTS_, seg.range_end_);

for (std::vector<Representation*>::iterator b(adpm->repesentations_.begin()), e(adpm->repesentations_.end()); b != e; ++b)
(*b)->segments_.insert(seg);
}
Expand Down Expand Up @@ -214,7 +216,7 @@ namespace adaptive
}
}
}
else if (manifestUpdateParam == "etag")
else if (manifestUpdateParam == "full")
{
update_parameter_ = manifestUpdateParam;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ bool KodiAdaptiveStream::download(const char* url, const std::map<std::string, s
if (!file.CURLCreate(url))
return false;
file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "seekable" , "0");
file.CURLAddOption(ADDON_CURL_OPTION_HEADER, "Connection", "keep-alive");
file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "acceptencoding", "gzip, deflate");
if (mediaHeaders.find("connection") == mediaHeaders.end())
file.CURLAddOption(ADDON_CURL_OPTION_HEADER, "connection", "keep-alive");

for (const auto &entry : mediaHeaders)
{
Expand Down
5 changes: 2 additions & 3 deletions src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,6 @@ void DASHTree::RefreshSegments(Representation *rep, const Segment *seg)
sprintf(buf, "%u", nextStartNumber);
replaced.replace(update_parameter_pos_, 14, buf);
}
else if (etag_.empty())
return;

unsigned int retryCount(5);

Expand All @@ -1411,7 +1409,8 @@ void DASHTree::RefreshSegments(Representation *rep, const Segment *seg)
updateTree.manifest_headers_ = manifest_headers_;
if (!~update_parameter_pos_)
{
updateTree.manifest_headers_["If-None-Match"] = "\"" + etag_ + "\"";
if (!etag_.empty())
updateTree.manifest_headers_["If-None-Match"] = "\"" + etag_ + "\"";
if (!last_modified_.empty())
updateTree.manifest_headers_["If-Modified-Since"] = last_modified_;
}
Expand Down

0 comments on commit cb3c12b

Please sign in to comment.