diff --git a/xtransmit/CMakeLists.txt b/xtransmit/CMakeLists.txt index 56a6151..b5905a3 100644 --- a/xtransmit/CMakeLists.txt +++ b/xtransmit/CMakeLists.txt @@ -23,6 +23,12 @@ if (ENABLE_BONDING) ) endif() +if (ENABLE_AEAD_API_PREVIEW) + target_compile_options(srt-xtransmit + PRIVATE "-DENABLE_AEAD_API_PREVIEW" + ) +endif() + if (ENABLE_CXX17) set(REQUIRE_CXX_VER 17) if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Intel") diff --git a/xtransmit/metrics.cpp b/xtransmit/metrics.cpp index 7b7b35e..ff5a649 100644 --- a/xtransmit/metrics.cpp +++ b/xtransmit/metrics.cpp @@ -56,9 +56,10 @@ void write_sysclock_timestamp(vector& payload) *(reinterpret_cast(payload.data() + SYS_TIMESTAMP_BYTE_OFFSET)) = elapsed_us.count(); } -system_clock::time_point read_sysclock_timestamp(const vector& payload) +system_clock::time_point read_sysclock_timestamp(const const_buffer& payload) { - const int64_t elapsed_us = *(reinterpret_cast(payload.data() + SYS_TIMESTAMP_BYTE_OFFSET)); + const int8_t* ptr = reinterpret_cast(payload.data()); + const int64_t elapsed_us = *(reinterpret_cast(ptr + SYS_TIMESTAMP_BYTE_OFFSET)); // auto in_time_t = std::chrono::system_clock::to_time_t(system_clock::time_point() + microseconds(elapsed_us)); // std::stringstream ss; @@ -79,9 +80,10 @@ void write_steadyclock_timestamp(vector& payload) *(reinterpret_cast(payload.data() + STD_TIMESTAMP_BYTE_OFFSET)) = elapsed_us.count(); } -steady_clock::time_point read_stdclock_timestamp(const vector& payload) +steady_clock::time_point read_stdclock_timestamp(const const_buffer& payload) { - const int64_t elapsed_us = *(reinterpret_cast(payload.data() + STD_TIMESTAMP_BYTE_OFFSET)); + const int8_t* ptr = reinterpret_cast(payload.data()); + const int64_t elapsed_us = *(reinterpret_cast(ptr + STD_TIMESTAMP_BYTE_OFFSET)); const auto std_timestamp = steady_clock::time_point() + microseconds(elapsed_us); return std_timestamp; } @@ -92,9 +94,10 @@ void write_packet_seqno(vector& payload, uint64_t seqno) *ptr = seqno; } -uint64_t read_packet_seqno(const vector& payload) +uint64_t read_packet_seqno(const const_buffer& payload) { - const uint64_t seqno = *reinterpret_cast(payload.data() + PKT_SEQNO_BYTE_OFFSET); + const uint8_t* ptr = reinterpret_cast(payload.data()); + const uint64_t seqno = *reinterpret_cast(ptr + PKT_SEQNO_BYTE_OFFSET); return seqno; } @@ -104,9 +107,10 @@ void write_packet_length(vector& payload, uint64_t length) *ptr = length; } -uint64_t read_packet_length(const vector& payload) +uint64_t read_packet_length(const const_buffer& payload) { - const uint64_t length = *reinterpret_cast(payload.data() + PKT_LENGTH_BYTE_OFFSET); + const uint8_t* ptr = reinterpret_cast(payload.data()); + const uint64_t length = *reinterpret_cast(ptr + PKT_LENGTH_BYTE_OFFSET); return length; } @@ -125,7 +129,7 @@ void write_packet_checksum(vector& payload) md5_finish(&s, (md5_byte_t*) (payload.data() + PKT_MD5_BYTE_OFFSET)); } -bool validate_packet_checksum(const vector& payload) +bool validate_packet_checksum(const const_buffer& payload) { #if SRT_VERSION_VALUE >= SRT_MAKE_VERSION(1, 5, 0) using namespace srt; @@ -141,7 +145,7 @@ bool validate_packet_checksum(const vector& payload) array result; md5_finish(&s, result.data()); - const md5_byte_t* ptr = (md5_byte_t*) (payload.data() + PKT_MD5_BYTE_OFFSET); + const md5_byte_t* ptr = reinterpret_cast(payload.data()) + PKT_MD5_BYTE_OFFSET; const int cmpres = std::memcmp(ptr, result.data(), result.size()); return cmpres == 0; diff --git a/xtransmit/metrics.hpp b/xtransmit/metrics.hpp index ce4d67c..a3834a6 100644 --- a/xtransmit/metrics.hpp +++ b/xtransmit/metrics.hpp @@ -9,6 +9,7 @@ // submodules #include "spdlog/spdlog.h" +#include "buffer.hpp" #include "metrics_latency.hpp" // Transmission Delay #include "metrics_jitter.hpp" // Interarrival Jitter (RFC 3550) #include "metrics_delay_factor.hpp" // Time-Stamped Delay Factor (TS-DF) (EBU TECH 3337) @@ -25,18 +26,18 @@ namespace metrics //#define LOG_SC_METRICS "METRIC " void write_sysclock_timestamp(vector& payload); - system_clock::time_point read_sysclock_timestamp(const vector& payload); + system_clock::time_point read_sysclock_timestamp(const const_buffer& payload); void write_steadyclock_timestamp(vector& payload); - steady_clock::time_point read_stdclock_timestamp(const vector& payload); + steady_clock::time_point read_stdclock_timestamp(const const_buffer& payload); void write_packet_seqno(vector& payload, uint64_t seqno); - uint64_t read_packet_seqno(const vector& payload); + uint64_t read_packet_seqno(const const_buffer& payload); void write_packet_length(vector& payload, uint64_t length); - uint64_t read_packet_length(const vector& payload); + uint64_t read_packet_length(const const_buffer& payload); void write_packet_checksum(vector& payload); /// @brief Check if the MD5 checksum of the packet is correct. /// @param payload the payload /// @return true if the checksum is correct, false otherwise. - bool validate_packet_checksum(const vector& payload); + bool validate_packet_checksum(const const_buffer& payload); class generator { @@ -71,7 +72,7 @@ namespace metrics validator() {} public: - inline void validate_packet(const vector& payload) + inline void validate_packet(const const_buffer& payload) { const auto sys_time_now = system_clock::now(); const auto std_time_now = steady_clock::now(); @@ -82,7 +83,7 @@ namespace metrics const uint64_t pktlength = read_packet_length(payload); const bool checksum_match = validate_packet_checksum(payload); - m_integrity.submit_sample(pktseqno, payload.size() == pktlength, checksum_match); + m_integrity.submit_sample(pktseqno, pktlength, payload.size(), checksum_match); if (!checksum_match) { // Do not calculate other metrics, packet payload is corrupted, diff --git a/xtransmit/metrics_integrity.hpp b/xtransmit/metrics_integrity.hpp index c1e26f5..cc73339 100644 --- a/xtransmit/metrics_integrity.hpp +++ b/xtransmit/metrics_integrity.hpp @@ -22,14 +22,17 @@ class integrity public: /// Submit new sample for integrity update. /// @param [in] pkt_seqno newly arrived packet sequence number - /// @param [in] is_correct_length true if the packet length is correct + /// @param [in] expected_len expected payload length + /// @param [in] actual_len actual payload length /// @param [in] is_valid_checksum true if the checksum is correct - void submit_sample(const uint64_t pkt_seqno, const bool is_correct_length, const bool is_valid_checksum) + void submit_sample(const uint64_t pkt_seqno, const uint64_t expected_len, const uint64_t actual_len, const bool is_valid_checksum) { + const bool is_correct_length = expected_len == actual_len; if (!is_correct_length) { ++m_stats.pkts_wrong_len; - spdlog::warn("[METRICS] Incorrect length of packet seqno {}.", pkt_seqno); + spdlog::warn("[METRICS] Incorrect length of packet seqno {}. Expected {}, got {}.", + pkt_seqno, expected_len, actual_len); } if (!is_valid_checksum) diff --git a/xtransmit/receive.cpp b/xtransmit/receive.cpp index d7a795b..06c5626 100644 --- a/xtransmit/receive.cpp +++ b/xtransmit/receive.cpp @@ -142,7 +142,7 @@ void run_pipe(shared_sock src, const config& cfg, const atomic_bool& force_break if (cfg.enable_metrics) { lock_guard lck(metrics_mtx); - validator.validate_packet(buffer); + validator.validate_packet(const_buffer(buffer.data(), bytes)); } if (cfg.send_reply) diff --git a/xtransmit/srt_socket_group.cpp b/xtransmit/srt_socket_group.cpp index 9443fc0..28b51b1 100644 --- a/xtransmit/srt_socket_group.cpp +++ b/xtransmit/srt_socket_group.cpp @@ -150,7 +150,7 @@ socket::srt_group::srt_group(const vector& uris) for (auto uri : uris) { // Will throw an exception if invalid options were provided. - srt::assert_options_valid(uri.parameters(), {"bind", "mode", "weight", "grouptype"}); + srt::assert_options_valid(uri.parameters(), {"bind", "mode", "weight", "grouptype", "blocking"}); m_opts_link.push_back(uri.parameters()); }