From b5fc2106912f0ed3168972caee33b45ee6bb4b53 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Fri, 22 Mar 2019 11:04:20 +0100 Subject: [HICN-8] Update viper video player to use hicn sockets over HTTP Change-Id: I0aa727e513e3ffcf3286cecc7e7c43237da5155f Signed-off-by: Angelo Mantellini --- .qmake.stash | 15 ----------- Input/ICNConnectionConsumerApi.cpp | 25 +++++++++++++++---- Input/ICNConnectionConsumerApi.h | 11 ++++++--- UI/DASHPlayer.cpp | 1 + Websocket/WebSocketService.cpp | 4 ++- Websocket/WebSocketService.h | 1 - Websocket/communication-protocol.cpp | 11 ++++----- Websocket/communication-protocol.h | 4 +-- Websocket/tcp-server.cpp | 48 ++++++++++++++++++------------------ Websocket/tcp-server.h | 12 ++++----- Websocket/websocket-server.cpp | 8 +++--- viper.pro | 40 +++++++++++++++--------------- 12 files changed, 93 insertions(+), 87 deletions(-) delete mode 100644 .qmake.stash diff --git a/.qmake.stash b/.qmake.stash deleted file mode 100644 index d717b0a6..00000000 --- a/.qmake.stash +++ /dev/null @@ -1,15 +0,0 @@ -QMAKE_DEFAULT_INCDIRS = \ - /usr/include/c++/5 \ - /usr/include/x86_64-linux-gnu/c++/5 \ - /usr/include/c++/5/backward \ - /usr/lib/gcc/x86_64-linux-gnu/5/include \ - /usr/local/include \ - /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ - /usr/include/x86_64-linux-gnu \ - /usr/include -QMAKE_DEFAULT_LIBDIRS = \ - /usr/lib/gcc/x86_64-linux-gnu/5 \ - /usr/lib/x86_64-linux-gnu \ - /usr/lib \ - /lib/x86_64-linux-gnu \ - /lib diff --git a/Input/ICNConnectionConsumerApi.cpp b/Input/ICNConnectionConsumerApi.cpp index 15475d5f..f983a054 100644 --- a/Input/ICNConnectionConsumerApi.cpp +++ b/Input/ICNConnectionConsumerApi.cpp @@ -55,8 +55,12 @@ ICNConnectionConsumerApi::ICNConnectionConsumerApi(double alpha, float beta, flo this->res = false; InitializeConditionVariable (&this->contentRetrieved); InitializeCriticalSection (&this->monitorMutex); - this->hTTPClientConnection = new libl4::http::HTTPClientConnection(); - libl4::transport::ConsumerSocket &c = this->hTTPClientConnection->getConsumer(); + this->hTTPClientConnection = new libl4::http::HTTPClientConnection(); +#ifdef HICNET + transport::interface::ConsumerSocket &c = this->hTTPClientConnection->getConsumer(); +#else + libl4::transport::ConsumerSocket &c = this->hTTPClientConnection->getConsumer(); +#endif bool configFile = false; //CHECK if we are not going to override the configuration file. (if !autotune) if(FILE *fp = fopen("/usr/etc/consumer.conf", "r")) @@ -64,14 +68,25 @@ ICNConnectionConsumerApi::ICNConnectionConsumerApi(double alpha, float beta, flo fclose(fp); configFile = true; } +#ifdef HICNET if(!configFile) { qDebug("beta %f, drop %f", this->beta, this->drop); - c.setSocketOption(libl4::transport::RaaqmTransportOptions::BETA_VALUE, this->beta); - c.setSocketOption(libl4::transport::RaaqmTransportOptions::DROP_FACTOR, this->drop); + c.setSocketOption(transport::interface::RaaqmTransportOptions::BETA_VALUE, this->beta); + c.setSocketOption(transport::interface::RaaqmTransportOptions::DROP_FACTOR, this->drop); } - c.setSocketOption(int(libl4::transport::RateEstimationOptions::RATE_ESTIMATION_OBSERVER), (libl4::transport::IcnObserver * )this); + c.setSocketOption(int(transport::interface::RateEstimationOptions::RATE_ESTIMATION_OBSERVER), (transport::protocol::IcnObserver * )this); +#else + if(!configFile) + { + qDebug("beta %f, drop %f", this->beta, this->drop); + + c.setSocketOption(libl4::transport::RaaqmTransportOptions::BETA_VALUE, this->beta); + c.setSocketOption(libl4::transport::RaaqmTransportOptions::DROP_FACTOR, this->drop); + } + c.setSocketOption(int(libl4::transport::RateEstimationOptions::RATE_ESTIMATION_OBSERVER), (libl4::transport::IcnObserver * )this); +#endif #ifdef NO_GUI if(this->icnAlpha != 20) this->icnRateBased = true; diff --git a/Input/ICNConnectionConsumerApi.h b/Input/ICNConnectionConsumerApi.h index 9a5f8a47..c05c5244 100644 --- a/Input/ICNConnectionConsumerApi.h +++ b/Input/ICNConnectionConsumerApi.h @@ -17,7 +17,8 @@ #define QTPLAYER_INPUT_ICNCONNECTIONCONSUMERAPI_H_ #if defined(HICNET) -#include +#include +#include #else #include #endif @@ -45,7 +46,6 @@ #include #include "../Portable/MultiThreading.h" -#include //logging purpose #include @@ -56,7 +56,13 @@ namespace libdash { namespace framework { namespace input { +#if defined(HICNET) +class ICNConnectionConsumerApi : public IICNConnection, public transport::protocol::IcnObserver{ +#else class ICNConnectionConsumerApi : public IICNConnection, public libl4::transport::IcnObserver{ +#endif + + public: ICNConnectionConsumerApi(double alpha, float beta, float drop); virtual ~ICNConnectionConsumerApi(); @@ -81,7 +87,6 @@ public: virtual void SetBeta(float beta); virtual void SetDrop(float drop); - //libl4::transport::IcnObserver virtual void notifyStats(double throughput); virtual void notifyDownloadTime(double downloadingTime); diff --git a/UI/DASHPlayer.cpp b/UI/DASHPlayer.cpp index e2910ea8..efb85620 100644 --- a/UI/DASHPlayer.cpp +++ b/UI/DASHPlayer.cpp @@ -11,6 +11,7 @@ #include "DASHPlayer.h" #include +#include "QtAV/AVError.h" using namespace libdash::framework::adaptation; using namespace libdash::framework::mpd; diff --git a/Websocket/WebSocketService.cpp b/Websocket/WebSocketService.cpp index b2fd4e16..c4cc83ab 100644 --- a/Websocket/WebSocketService.cpp +++ b/Websocket/WebSocketService.cpp @@ -65,7 +65,9 @@ void* WebSocketService::listenWebsocket(void *webSocketServiceObject) std::string command((char *) data, size); - boost::trim(command); + std::stringstream trimmer; + trimmer << command; + trimmer >> command; std::cout << command << std::endl; diff --git a/Websocket/WebSocketService.h b/Websocket/WebSocketService.h index 9b084a24..631da4c9 100644 --- a/Websocket/WebSocketService.h +++ b/Websocket/WebSocketService.h @@ -18,7 +18,6 @@ #include "connection-pool.h" #include "query.h" #include "communication-protocol.h" -#include class WebSocketService diff --git a/Websocket/communication-protocol.cpp b/Websocket/communication-protocol.cpp index 99bcfa90..3e5f979c 100644 --- a/Websocket/communication-protocol.cpp +++ b/Websocket/communication-protocol.cpp @@ -16,7 +16,6 @@ #include "websocket-server.h" #include "communication-protocol.h" - /////////////////// //Explanation: A query can select/update 2 objects: // - Coordinates of a node @@ -34,7 +33,7 @@ std::set ProtocolDetails::AllowedObjectName = {"stats"}; std::set ProtocolDetails::AllowedActions = { "select", "subscribe"}; std::set ProtocolDetails::AllowedFields = {"quality", "rate", "all"}; -std::function CommunicationProtocol::timerCallback; +std::function CommunicationProtocol::timerCallback; CommunicationProtocol::CommunicationProtocol(ProtocolVersion version) : version(version) @@ -150,10 +149,10 @@ CommunicationProtocol::processQuery(Server *s, websocketpp::connection_hdl hdl, } else if (action == *ProtocolDetails::AllowedActions.find("subscribe")) { - subscribeTimer = std::shared_ptr(new boost::asio::deadline_timer(s->get_io_service(), - boost::posix_time::milliseconds(1000))); + subscribeTimer = std::shared_ptr(new asio::steady_timer(s->get_io_service(), + std::chrono::milliseconds(1000))); timerCallback = [this, s, hdl, msg, query] - (const boost::system::error_code &ec) { + (const std::error_code &ec) { if (!ec) { Query reply = this->makeReplyQuery(query); @@ -171,7 +170,7 @@ CommunicationProtocol::processQuery(Server *s, websocketpp::connection_hdl hdl, return; } - subscribeTimer->expires_from_now(boost::posix_time::milliseconds(1000)); + subscribeTimer->expires_from_now(std::chrono::milliseconds(1000)); subscribeTimer->async_wait(timerCallback); } }; diff --git a/Websocket/communication-protocol.h b/Websocket/communication-protocol.h index f3c488ef..25b15a6f 100644 --- a/Websocket/communication-protocol.h +++ b/Websocket/communication-protocol.h @@ -71,14 +71,14 @@ public: void setGraphDataSource(GraphDataSource *graphDataSource); - static std::function timerCallback; + static std::function timerCallback; private: GraphDataSource *graphDataSource; ProtocolVersion version; - std::shared_ptr subscribeTimer; + std::shared_ptr subscribeTimer; }; diff --git a/Websocket/tcp-server.cpp b/Websocket/tcp-server.cpp index 4eb5d29d..cffd326b 100644 --- a/Websocket/tcp-server.cpp +++ b/Websocket/tcp-server.cpp @@ -35,11 +35,11 @@ TcpServer::start() if (io_service.stopped()) io_service.reset(); - boost::asio::ip::tcp::endpoint endpoint; - endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port); + asio::ip::tcp::endpoint endpoint; + endpoint = asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port); acceptor.open(endpoint.protocol()); - acceptor.set_option(boost::asio::socket_base::reuse_address(true)); + acceptor.set_option(asio::socket_base::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen(); @@ -47,10 +47,10 @@ TcpServer::start() //Set interrupt callbacks - boost::asio::io_service io_service; - boost::asio::signal_set signals(io_service, SIGINT, SIGQUIT); + asio::io_service io_service; + asio::signal_set signals(io_service, SIGINT, SIGQUIT); - signals.async_wait([this] (const boost::system::error_code &errorCode, int) { + signals.async_wait([this] (const std::error_code &errorCode, int) { std::cout << "Gracefully terminating tcp server" << std::endl; this->io_service.reset(); this->acceptor.cancel(); @@ -64,12 +64,12 @@ TcpServer::accept() { //Create new socket for this connection //Shared_ptr is used to pass temporary objects to the asynchronous functions - std::shared_ptr socket(new boost::asio::ip::tcp::socket(io_service)); - acceptor.async_accept(*socket, [this, socket](const boost::system::error_code &ec) { + std::shared_ptr socket(new asio::ip::tcp::socket(io_service)); + acceptor.async_accept(*socket, [this, socket](const std::error_code &ec) { accept(); if (ec) { - if (ec == boost::asio::error::operation_aborted) // when the socket is closed by someone + if (ec == asio::error::operation_aborted) // when the socket is closed by someone return; } @@ -78,17 +78,17 @@ TcpServer::accept() } void -TcpServer::processIncomingData(std::shared_ptr socket) +TcpServer::processIncomingData(std::shared_ptr socket) { // Set timeout on the following boost::asio::async-read or write function - std::shared_ptr timer; + std::shared_ptr timer; if (read_timeout > 0) timer = set_timeout_on_socket(socket, read_timeout); - std::shared_ptr buffer(new boost::asio::streambuf()); + std::shared_ptr buffer(new asio::streambuf()); - boost::asio::async_read_until(*socket, *buffer, "\r\n\r\n", - [this, timer, buffer, socket](const boost::system::error_code& error, std::size_t bytes_transferred) { + asio::async_read_until(*socket, *buffer, "\r\n\r\n", + [this, timer, buffer, socket](const std::error_code& error, std::size_t bytes_transferred) { if (read_timeout > 0) timer->cancel(); @@ -99,14 +99,14 @@ TcpServer::processIncomingData(std::shared_ptr soc std::size_t bufferSize = buffer->size(); buffer->commit(buffer->size()); - const uint8_t *data = boost::asio::buffer_cast(buffer->data()); + const uint8_t *data = asio::buffer_cast(buffer->data()); std::string reply = handler(data, bufferSize); if (reply != "") { - boost::asio::async_write(*socket, boost::asio::buffer(reply.c_str(), reply.size()), [this] - (boost::system::error_code ec, std::size_t /*length*/) + asio::async_write(*socket, asio::buffer(reply.c_str(), reply.size()), [this] + (std::error_code ec, std::size_t /*length*/) { if (!ec) { std::cout << "Reply sent!" << std::endl; @@ -120,16 +120,16 @@ TcpServer::processIncomingData(std::shared_ptr soc } -std::shared_ptr -TcpServer::set_timeout_on_socket(std::shared_ptr socket, long seconds) +std::shared_ptr +TcpServer::set_timeout_on_socket(std::shared_ptr socket, long seconds) { - std::shared_ptr timer(new boost::asio::deadline_timer(io_service)); - timer->expires_from_now(boost::posix_time::seconds(seconds)); - timer->async_wait([socket](const boost::system::error_code &ec) { + std::shared_ptr timer(new asio::steady_timer(io_service)); + timer->expires_from_now(std::chrono::seconds(seconds)); + timer->async_wait([socket](const std::error_code &ec) { if (!ec) { - boost::system::error_code ec; + std::error_code ec; std::cout << "Connection timeout!" << std::endl; - socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + socket->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, ec); socket->lowest_layer().close(); } }); diff --git a/Websocket/tcp-server.h b/Websocket/tcp-server.h index f93d1b43..720d2c7e 100644 --- a/Websocket/tcp-server.h +++ b/Websocket/tcp-server.h @@ -17,8 +17,8 @@ #define TCP_SERVER_H #include -#include #include +#include typedef std::function HandlerFunction; @@ -43,14 +43,14 @@ private: accept(); void - processIncomingData(std::shared_ptr socket); + processIncomingData(std::shared_ptr socket); - std::shared_ptr - set_timeout_on_socket(std::shared_ptr socket, long seconds); + std::shared_ptr + set_timeout_on_socket(std::shared_ptr socket, long seconds); unsigned short port; - boost::asio::io_service io_service; - boost::asio::ip::tcp::acceptor acceptor; + asio::io_service io_service; + asio::ip::tcp::acceptor acceptor; long read_timeout; HandlerFunction handler; }; diff --git a/Websocket/websocket-server.cpp b/Websocket/websocket-server.cpp index ee79ccdb..58463caa 100644 --- a/Websocket/websocket-server.cpp +++ b/Websocket/websocket-server.cpp @@ -29,7 +29,7 @@ WebSocketServer::WebSocketServer(unsigned short port) server.set_message_handler(bind(&WebSocketServer::onMessage, this, &server, ::_1, ::_2)); // Listen on port - server.listen(boost::asio::ip::tcp::v4(),port); + server.listen(asio::ip::tcp::v4(),port); } catch (websocketpp::exception const & e) { std::cout << e.what() << std::endl; @@ -58,10 +58,10 @@ WebSocketServer::start() //Set interrupt callbacks - boost::asio::io_service io_service; - boost::asio::signal_set signals(server.get_io_service(), SIGINT, SIGQUIT); + asio::io_service io_service; + asio::signal_set signals(server.get_io_service(), SIGINT, SIGQUIT); - signals.async_wait([this](const boost::system::error_code &errorCode, int) { + signals.async_wait([this](const std::error_code &errorCode, int) { std::cout << "Gracefully terminating websocket server" << std::endl; this->m_isRunning = false; this->server.stop(); diff --git a/viper.pro b/viper.pro index f344babd..4290c7e1 100644 --- a/viper.pro +++ b/viper.pro @@ -18,12 +18,11 @@ android { QT += androidextras } -message($$TRANSPORT_LIBRARY) CONFIG -= release CONFIG += debug -CONFIG += c++11 -QMAKE_CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DANDROID_STL=c++_static #-DICNICPDOWNLOAD -QMAKE_CXXFLAGS += -std=c++11 -g -fpermissive +CONFIG += c++14 +QMAKE_CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DANDROID_STL=c++_static +QMAKE_CXXFLAGS += -std=c++14 -g -fpermissive -DASIO_STANDALONE=1 # Add more folders to ship with the application, here folder_01.source = qml/Viper folder_01.target = qml @@ -277,30 +276,32 @@ unix:!macx:!android { INCLUDEPATH += /usr/include INCLUDEPATH += /usr/include/libdash equals(TRANSPORT_LIBRARY, "HICNET") { - LIBS += -L/usr/local/lib -ldash -lboost_system -lhicnet -lavcodec -lavutil -lavformat + LIBS += -L/usr/local/lib -ldash -lhicntransport -lavcodec -lavutil -lavformat DEFINES += "HICNET=ON" } else { - LIBS += -L/usr/local/lib -ldash -lboost_system -licnet -lavcodec -lavutil -lavformat + LIBS += -L/usr/local/lib -ldash -licnet -lavcodec -lavutil -lavformat DEFINES += "ICNET=ON" } } macx:!ios { - QMAKE_INFO_PLIST = $$COMMON/Info.plist ICON = $$COMMON/Viper.icns QMAKE_RPATHDIR += /usr/local/lib INCLUDEPATH += /usr/local/include INCLUDEPATH += /usr/local/include/libdash INCLUDEPATH += $$[QT_HOST_PREFIX]/include/ + INCLUDEPATH += $$[QT_HOST_PREFIX]/lib/QtAV.framework/Headers equals(TRANSPORT_LIBRARY, "HICNET") { - LIBS += -L"/usr/local/lib" -framework CoreServices -ldash -lavformat -lavutil -lavcodec -lboost_system -lboost_regex -lswscale -lhicnet -lssl -lcrypto - DEFINES += "HICNET=ON" - } else { - LIBS += -L"/usr/local/lib" -framework CoreServices -ldash -lavformat -lavutil -lavcodec -lboost_system -lboost_regex -lswscale -licnet -lssl -lcrypto - DEFINES += "ICNET=ON" - } + LIBS += -L"/usr/local/lib" -framework CoreServices -ldash -lavformat -lavutil -lavcodec -lswscale -lhicntransport -lssl -lcrypto + LIBS += -F$$[QT_HOST_PREFIX]/lib/ -framework QtAV + DEFINES += "HICNET=ON" + } else { + LIBS += -L"/usr/local/lib" -framework CoreServices -ldash -lavformat -lavutil -lavcodec -lswscale -licnet -lssl -lcrypto + LIBS += -F$$[QT_HOST_PREFIX]/lib/ -framework QtAV + DEFINES += "ICNET=ON" + } } SOURCES *= main.cpp android { @@ -318,12 +319,12 @@ android { INCLUDEPATH += $$(DISTILLARY_INSTALLATION_PATH)/include INCLUDEPATH += $$(DISTILLARY_INSTALLATION_PATH)/include/libdash equals(TRANSPORT_LIBRARY, "HICNET") { - LIBS += -L"$$(DISTILLARY_INSTALLATION_PATH)/lib" -lhicnet -ljsoncpp -ldash -lcurl -lxml2 -lccnx_hicn_api_portal -lccnx_hicn_transport_rta -lccnx_hicn_api_control -lccnx_hicn_api_notify -lccnx_common -lparc -llongbow -llongbow-ansiterm -llongbow-textplain -lhicn -levent -lssl -lcrypto -lavcodec -lavutil -lavformat -lboost_system - DEFINES += "HICNET=ON" - } else { - LIBS += -L"$$(DISTILLARY_INSTALLATION_PATH)/lib" -licnet -ldash -lcurl -lxml2 -lccnx_api_portal -lccnx_transport_rta -lccnx_api_control -lccnx_api_notify -lccnx_common -lparc -llongbow -llongbow-ansiterm -llongbow-textplain -levent -lssl -lcrypto -lavcodec -lavutil -lavformat -lboost_system - DEFINES += "ICNET=ON" - } + LIBS += -L"$$(DISTILLARY_INSTALLATION_PATH)/lib" -lhicnet -ljsoncpp -ldash -lcurl -lxml2 -lccnx_common -lparc -lhicntransport -lhicn -levent -lssl -lcrypto -lavcodec -lavutil -lavformat + DEFINES += "HICNET=ON" + } else { + LIBS += -L"$$(DISTILLARY_INSTALLATION_PATH)/lib" -licnet -ldash -lcurl -lxml2 -lccnx_api_portal -lccnx_transport_rta -lccnx_api_control -lccnx_api_notify -lccnx_common -lparc -llongbow -llongbow-ansiterm -llongbow-textplain -levent -lssl -lcrypto -lavcodec -lavutil -lavformat -lboost_system + DEFINES += "ICNET=ON" + } } @@ -336,4 +337,3 @@ DISTFILES += \ android/gradle.properties \ android/src/org/qtav/qmlplayer/ViperActivity.java \ android/src/org/player/viper/ViperActivity.java - -- cgit 1.2.3-korg