From 582ac1576f63554bf5af0f28c8b12ab5f25854ef Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Fri, 28 Jul 2017 19:38:23 +0200 Subject: Adding possibility to stream live video by avoiding to cache mpd. The mpd is always fresh. Change-Id: I8573b0a25bc2cea4f6a3193b0048433e12119306 Signed-off-by: Mauro Sardara --- http-server/http_server.cc | 6 +++++- http-server/icn_response.cc | 1 + http-server/response.cc | 14 +++++++++++++- http-server/response.h | 6 ++++++ main.cc | 6 +++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/http-server/http_server.cc b/http-server/http_server.cc index 51994686..478d072e 100644 --- a/http-server/http_server.cc +++ b/http-server/http_server.cc @@ -71,7 +71,11 @@ void HttpServer::onIcnRequest(std::shared_ptr std::cout << "Received request for: " << request->getPath() << std::endl; icn_publishers_[request_id] = publisher; icn_publishers_[request_id]->attachPublisher(); - icn_publishers_[request_id]->setTimeout(5); + if (request->getPath().substr(request->getPath().find_last_of(".") + 1) == "mpd") { + icn_publishers_[request_id]->setTimeout(1); + } else { + icn_publishers_[request_id]->setTimeout(5); + } std::cout << "Starting new thread" << std::endl; io_service_.dispatch([this, request, request_id]() { find_resource(nullptr, request); diff --git a/http-server/icn_response.cc b/http-server/icn_response.cc index 241eda51..9741556b 100644 --- a/http-server/icn_response.cc +++ b/http-server/icn_response.cc @@ -32,6 +32,7 @@ void IcnResponse::send(const SendCallback &callback) { this->publisher_->publishContent(boost::asio::buffer_cast(this->streambuf_.data()), buffer_size, + this->response_lifetime_, this->response_id_, this->is_last_); diff --git a/http-server/response.cc b/http-server/response.cc index b322cad8..779ecedc 100644 --- a/http-server/response.cc +++ b/http-server/response.cc @@ -16,10 +16,15 @@ #include "common.h" #include "response.h" +#define DEFAULT_LIFETIME 1024 * 1024 + namespace icn_httpserver { Response::Response() - : std::ostream(&streambuf_), is_last_(false) { + : std::ostream(&streambuf_), + is_last_(false), + response_length_(0), + response_lifetime_(DEFAULT_LIFETIME) { } Response::~Response() { @@ -37,6 +42,13 @@ void Response::setIsLast(bool is_last) { Response::is_last_ = is_last; } +const std::chrono::milliseconds &Response::getResponseLifetime() const { + return response_lifetime_; +} +void Response::setResponseLifetime(const std::chrono::milliseconds &response_lifetime) { + Response::response_lifetime_ = response_lifetime_; +} + void Response::setResponseLength(std::size_t length) { response_length_ = length; } diff --git a/http-server/response.h b/http-server/response.h index 649bcea3..cc8df9c6 100644 --- a/http-server/response.h +++ b/http-server/response.h @@ -39,10 +39,16 @@ class Response void setResponseLength(std::size_t length); + const std::chrono::milliseconds &getResponseLifetime() const; + + void setResponseLifetime(const std::chrono::milliseconds &response_lifetime); + + protected: boost::asio::streambuf streambuf_; bool is_last_; std::size_t response_length_; + std::chrono::milliseconds response_lifetime_; }; } // end namespace icn_httpserver diff --git a/main.cc b/main.cc index e5eb804e..c222db20 100644 --- a/main.cc +++ b/main.cc @@ -67,7 +67,7 @@ void afterSignal(HttpServer *webServer, const boost::system::error_code &errorCo } void usage(const char *programName) { - cerr << programName << " [-p PATH_TO_ROOT_FOOT_FOLDER] [-l WEBSERVER_PREFIX] [-x PROXY_ADDRESS]\n" + cerr << programName << " [-p PATH_TO_ROOT_FOOT_FOLDER] [-o TCP_LISTEN_PORT] [-l WEBSERVER_PREFIX] [-x PROXY_ADDRESS]\n" << "Web server able to publish content and generate http responses over TCP/ICN\n" << endl; exit(1); @@ -188,6 +188,10 @@ int main(int argc, char **argv) { *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length << "\r\n\r\n"; } + if (path.extension().string() == ".mpd") { + response->setResponseLifetime(std::chrono::milliseconds(1000)); + } + default_resource_send(server, response, ifs, buffer, length); return; -- cgit 1.2.3-korg