Merge pull request #199 from bondagit/issue-197

Set of changes to support Boost version >= 1.87
This commit is contained in:
Andrea Bondavalli 2025-03-04 16:57:19 +01:00 committed by GitHub
commit 29dc02ddc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 110 additions and 18 deletions

View File

@ -79,11 +79,19 @@ std::shared_ptr<Config> 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";
}

View File

@ -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<std::mutex> lock{mutex};
auto it = mcast_ref.find(mcast_ip_addr);
@ -50,9 +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 "
@ -75,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<std::mutex> lock{mutex};
auto it = mcast_ref.find(mcast_ip_addr);
@ -88,9 +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 "
@ -104,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<uint32_t, int> mcast_ref;

View File

@ -168,10 +168,14 @@ bool ping(const std::string& ip) {
// this requires root priv
try {
io_service io_service;
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";

View File

@ -43,7 +43,7 @@ namespace po = boost::program_options;
namespace postyle = boost::program_options::command_line_style;
namespace logging = boost::log;
static const std::string version("bondagit-2.0.2");
static const std::string version("bondagit-2.0.3");
static std::atomic<bool> terminate = false;
void termination_handler(int signum) {

View File

@ -22,7 +22,6 @@
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/bind/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <cstdlib>
@ -94,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<nl_protocol> socket_{io_service_};
deadline_timer deadline_{io_service_};
std::string name_;

View File

@ -205,8 +205,6 @@ std::pair<bool, RtspSource> RtspClient::process(
ss << "rtsp:" << std::hex
<< crc16(reinterpret_cast<const uint8_t*>(res.body.c_str()),
res.body.length());
/*<< std::hex <<
* ip::address_v4::from_string(address.c_str()).to_ulong();*/
rtsp_source.id = ss.str();
rtsp_source.source = "mDNS";
rtsp_source.address = address;

View File

@ -89,9 +89,13 @@ class RtspServer {
: session_manager_(session_manager),
config_(config),
acceptor_(io_service_,
tcp::endpoint(boost::asio::ip::address::from_string(
config_->get_ip_addr_str()),
config_->get_rtsp_port())) {}
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();
/* start rtsp server on a separate thread */
@ -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<SessionManager> session_manager_;
std::shared_ptr<Config> config_;
std::vector<std::weak_ptr<RtspSession> > sessions_{session_num_max};

View File

@ -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::address::from_string(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);

View File

@ -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::address::from_string(addr_), port)};
ip::udp::endpoint listen_endpoint_{
ip::udp::endpoint(ip::address::from_string("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_};
};

View File

@ -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,14 +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();

View File

@ -97,9 +97,14 @@ struct Client {
socket_.set_option(udp::socket::reuse_address(true));
socket_.bind(listen_endpoint_);
socket_.set_option(
#if BOOST_VERSION < 108700
multicast::join_group(address::from_string(g_sap_address).to_v4(),
address::from_string(g_daemon_address).to_v4()));
address::from_string(g_daemon_address).to_v4())
#else
multicast::join_group(make_address(g_sap_address).to_v4(),
make_address(g_daemon_address).to_v4())
#endif
);
cli_.set_connection_timeout(30);
cli_.set_read_timeout(30);
cli_.set_write_timeout(30);
@ -362,10 +367,18 @@ struct Client {
private:
httplib::Client cli_{g_daemon_address, g_daemon_port};
#if BOOST_VERSION < 108700
io_service io_service_;
#else
io_context io_service_;
#endif
udp::socket socket_{io_service_};
udp::endpoint listen_endpoint_{
#if BOOST_VERSION < 108700
udp::endpoint(address::from_string("0.0.0.0"), g_sap_port)};
#else
udp::endpoint(make_address("0.0.0.0"), g_sap_port)};
#endif
};
BOOST_AUTO_TEST_CASE(is_alive) {