From 1e652a046dc5cc5708698cdd84baec3cbe996662 Mon Sep 17 00:00:00 2001 From: Andrea Bondavalli Date: Fri, 28 Feb 2025 17:46:53 +0100 Subject: [PATCH] Set of changes to keep compatibility between boost version 1.87 and earlier versions --- daemon/config.cpp | 8 ++++++++ daemon/igmp.hpp | 25 +++++++++++++++++++++++++ daemon/interface.cpp | 4 ++++ daemon/netlink_client.hpp | 4 ++++ daemon/rtsp_client.cpp | 2 -- daemon/rtsp_server.hpp | 8 ++++++++ daemon/sap.cpp | 9 +++++---- daemon/sap.hpp | 23 +++++++++++++++++++---- daemon/session_manager.cpp | 18 ++++++++++++++++++ 9 files changed, 91 insertions(+), 10 deletions(-) diff --git a/daemon/config.cpp b/daemon/config.cpp index 2316248..8446889 100644 --- a/daemon/config.cpp +++ b/daemon/config.cpp @@ -79,11 +79,19 @@ std::shared_ptr Config::parse(const std::string& filename, config.streamer_player_buffer_files_num_ = 1; boost::system::error_code ec; +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(config.rtp_mcast_base_.c_str(), ec); +#else ip::make_address(config.rtp_mcast_base_.c_str(), ec); +#endif if (ec) { config.rtp_mcast_base_ = "239.1.0.1"; } +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(config.sap_mcast_addr_.c_str(), ec); +#else ip::make_address(config.sap_mcast_addr_.c_str(), ec); +#endif if (ec) { config.sap_mcast_addr_ = "224.2.127.254"; } diff --git a/daemon/igmp.hpp b/daemon/igmp.hpp index 2fb808c..b7e6440 100644 --- a/daemon/igmp.hpp +++ b/daemon/igmp.hpp @@ -40,7 +40,11 @@ class IGMP { bool join(const std::string& interface_ip, const std::string& mcast_ip) { uint32_t mcast_ip_addr = +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(mcast_ip.c_str()).to_ulong(); +#else ip::make_address(mcast_ip.c_str()).to_v4().to_uint(); +#endif std::scoped_lock lock{mutex}; auto it = mcast_ref.find(mcast_ip_addr); @@ -50,8 +54,14 @@ class IGMP { } error_code ec; +#if BOOST_VERSION < 108700 + ip::multicast::join_group option( + ip::address::from_string(mcast_ip).to_v4(), + ip::address::from_string(interface_ip).to_v4()); +#else ip::multicast::join_group option(ip::make_address(mcast_ip).to_v4(), ip::make_address(interface_ip).to_v4()); +#endif socket_.set_option(option, ec); if (ec) { BOOST_LOG_TRIVIAL(error) << "igmp:: failed to joined multicast group " @@ -74,7 +84,11 @@ class IGMP { bool leave(const std::string& interface_ip, const std::string& mcast_ip) { uint32_t mcast_ip_addr = +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(mcast_ip.c_str()).to_ulong(); +#else ip::make_address(mcast_ip.c_str()).to_v4().to_uint(); +#endif std::scoped_lock lock{mutex}; auto it = mcast_ref.find(mcast_ip_addr); @@ -87,8 +101,15 @@ class IGMP { } error_code ec; + +#if BOOST_VERSION < 108700 + ip::multicast::leave_group option( + ip::address::from_string(mcast_ip).to_v4(), + ip::address::from_string(interface_ip).to_v4()); +#else ip::multicast::leave_group option(ip::make_address(mcast_ip).to_v4(), ip::make_address(interface_ip).to_v4()); +#endif socket_.set_option(option, ec); if (ec) { BOOST_LOG_TRIVIAL(error) << "igmp:: failed to leave multicast group " @@ -102,7 +123,11 @@ class IGMP { } private: +#if BOOST_VERSION < 108700 + io_service io_service_; +#else io_context io_service_; +#endif ip::udp::socket socket_{io_service_}; udp::endpoint listen_endpoint_{udp::endpoint(address_v4::any(), 0)}; std::unordered_map mcast_ref; diff --git a/daemon/interface.cpp b/daemon/interface.cpp index 826daf3..696e121 100644 --- a/daemon/interface.cpp +++ b/daemon/interface.cpp @@ -171,7 +171,11 @@ bool ping(const std::string& ip) { io_context io_service; icmp::socket socket{io_service, icmp::v4()}; ip::icmp::endpoint destination(ip::icmp::v4(), +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(ip).to_ulong()); +#else ip::make_address(ip).to_v4().to_uint()); +#endif socket.send_to(boost::asio::buffer(buffer, sizeof buffer), destination); } catch (...) { BOOST_LOG_TRIVIAL(error) << "ping:: send_to() failed"; diff --git a/daemon/netlink_client.hpp b/daemon/netlink_client.hpp index 1842568..630d181 100644 --- a/daemon/netlink_client.hpp +++ b/daemon/netlink_client.hpp @@ -93,7 +93,11 @@ class NetlinkClient { } private: +#if BOOST_VERSION < 108700 + boost::asio::io_service io_service_; +#else boost::asio::io_context io_service_; +#endif boost::asio::basic_raw_socket socket_{io_service_}; deadline_timer deadline_{io_service_}; std::string name_; diff --git a/daemon/rtsp_client.cpp b/daemon/rtsp_client.cpp index 9d34ff4..284627e 100644 --- a/daemon/rtsp_client.cpp +++ b/daemon/rtsp_client.cpp @@ -205,8 +205,6 @@ std::pair RtspClient::process( ss << "rtsp:" << std::hex << crc16(reinterpret_cast(res.body.c_str()), res.body.length()); - /*<< std::hex << - * ip::make_address(address.c_str()).to_uint();*/ rtsp_source.id = ss.str(); rtsp_source.source = "mDNS"; rtsp_source.address = address; diff --git a/daemon/rtsp_server.hpp b/daemon/rtsp_server.hpp index 6ca393f..a7ca63f 100644 --- a/daemon/rtsp_server.hpp +++ b/daemon/rtsp_server.hpp @@ -90,7 +90,11 @@ class RtspServer { config_(config), acceptor_(io_service_, tcp::endpoint( +#if BOOST_VERSION < 108700 + boost::asio::ip::address::from_string(config_->get_ip_addr_str()), +#else boost::asio::ip::make_address(config_->get_ip_addr_str()), +#endif config_->get_rtsp_port())) {} bool init() { accept(); @@ -125,7 +129,11 @@ class RtspServer { void accept(); std::mutex mutex_; +#if BOOST_VERSION < 108700 + boost::asio::io_service io_service_; +#else boost::asio::io_context io_service_; +#endif std::shared_ptr session_manager_; std::shared_ptr config_; std::vector > sessions_{session_num_max}; diff --git a/daemon/sap.cpp b/daemon/sap.cpp index be45383..67e932a 100644 --- a/daemon/sap.cpp +++ b/daemon/sap.cpp @@ -25,10 +25,7 @@ using namespace boost::placeholders; using namespace boost::asio; using namespace boost::asio::ip; -SAP::SAP(const std::string& sap_mcast_addr) - : addr_(sap_mcast_addr) -// remote_endpoint_(ip::make_address(addr_), port) -{ +SAP::SAP(const std::string& sap_mcast_addr) : addr_(sap_mcast_addr) { socket_.open(boost::asio::ip::udp::v4()); socket_.set_option(udp::socket::reuse_address(true)); socket_.bind(listen_endpoint_); @@ -36,7 +33,11 @@ SAP::SAP(const std::string& sap_mcast_addr) } bool SAP::set_multicast_interface(const std::string& interface_ip) { +#if BOOST_VERSION < 108700 + ip::address_v4 local_interface = ip::address_v4::from_string(interface_ip); +#else ip::address_v4 local_interface = ip::make_address(interface_ip).to_v4(); +#endif ip::multicast::outbound_interface oi_option(local_interface); boost::system::error_code ec; socket_.set_option(oi_option, ec); diff --git a/daemon/sap.hpp b/daemon/sap.hpp index c25bc92..c7b1354 100644 --- a/daemon/sap.hpp +++ b/daemon/sap.hpp @@ -62,12 +62,27 @@ class SAP { const std::string& sdp); std::string addr_; +#if BOOST_VERSION < 108700 + io_service io_service_; +#else io_context io_service_; +#endif ip::udp::socket socket_{io_service_}; - ip::udp::endpoint remote_endpoint_{ - ip::udp::endpoint(ip::make_address(addr_), port)}; - ip::udp::endpoint listen_endpoint_{ - ip::udp::endpoint(ip::make_address("0.0.0.0"), port)}; + ip::udp::endpoint remote_endpoint_ { +#if BOOST_VERSION < 108700 + ip::udp::endpoint(ip::address::from_string(addr_), port) +#else + ip::udp::endpoint(ip::make_address(addr_), port) +#endif + }; + ip::udp::endpoint listen_endpoint_ { +#if BOOST_VERSION < 108700 + ip::udp::endpoint(ip::address::from_string("0.0.0.0"), port) + }; +#else + ip::udp::endpoint(ip::make_address("0.0.0.0"), port) + }; +#endif deadline_timer deadline_{io_service_}; }; diff --git a/daemon/session_manager.cpp b/daemon/session_manager.cpp index 6603926..be2809d 100644 --- a/daemon/session_manager.cpp +++ b/daemon/session_manager.cpp @@ -255,7 +255,12 @@ bool SessionManager::parse_sdp(const std::string& sdp, StreamInfo& info) const { return false; } info.stream.m_ui32DestIP = +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(fields[2].c_str()).to_ulong(); +#else + ip::make_address(fields[2].c_str()).to_v4().to_uint(); +#endif if (info.stream.m_ui32DestIP == INADDR_NONE) { BOOST_LOG_TRIVIAL(error) << "session_manager:: invalid IPv4 " "connection address in SDP at line " @@ -524,15 +529,28 @@ std::error_code SessionManager::add_source(const StreamSource& source) { info.stream.m_ui32RTCPSrcIP = config_->get_ip_addr(); info.stream.m_ui32SrcIP = config_->get_ip_addr(); // only for Source boost::system::error_code ec; +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(source.address, ec); +#else ip::make_address(source.address, ec); +#endif if (!ec) { info.stream.m_ui32DestIP = +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(source.address).to_ulong(); +#else ip::make_address(source.address).to_v4().to_uint(); +#endif } else { info.stream.m_ui32DestIP = +#if BOOST_VERSION < 108700 + ip::address_v4::from_string(config_->get_rtp_mcast_base().c_str()) + .to_ulong() + +#else ip::make_address(config_->get_rtp_mcast_base().c_str()) .to_v4() .to_uint() + +#endif source.id; } info.stream.m_usSrcPort = config_->get_rtp_port();