diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Socket.cpp | 1 | ||||
| -rw-r--r-- | lib/Socket.h | 2 | ||||
| -rw-r--r-- | lib/ThreadsafeQueue.h | 2 | ||||
| -rw-r--r-- | lib/edi/STIDecoder.cpp | 21 | ||||
| -rw-r--r-- | lib/edi/STIDecoder.hpp | 5 | ||||
| -rw-r--r-- | lib/edioutput/EDIConfig.h | 3 | ||||
| -rw-r--r-- | lib/edioutput/Transport.cpp | 32 | ||||
| -rw-r--r-- | lib/edioutput/Transport.h | 7 | ||||
| -rw-r--r-- | lib/fec/decode_rs.h | 12 |
9 files changed, 62 insertions, 23 deletions
diff --git a/lib/Socket.cpp b/lib/Socket.cpp index 5c920d7..33c9c73 100644 --- a/lib/Socket.cpp +++ b/lib/Socket.cpp @@ -1152,6 +1152,7 @@ void TCPDataDispatcher::process() std::vector<TCPConnection::stats_t> TCPDataDispatcher::get_stats() const { std::vector<TCPConnection::stats_t> s; + auto lock = unique_lock<mutex>(m_mutex); for (const auto& conn : m_connections) { s.push_back(conn.get_stats()); } diff --git a/lib/Socket.h b/lib/Socket.h index 29b618a..b9a40ee 100644 --- a/lib/Socket.h +++ b/lib/Socket.h @@ -298,7 +298,7 @@ class TCPDataDispatcher std::thread m_listener_thread; TCPSocket m_listener_socket; - std::mutex m_mutex; + mutable std::mutex m_mutex; std::deque<std::vector<uint8_t> > m_preroll_queue; std::list<TCPConnection> m_connections; }; diff --git a/lib/ThreadsafeQueue.h b/lib/ThreadsafeQueue.h index 13bc19e..a8d2e85 100644 --- a/lib/ThreadsafeQueue.h +++ b/lib/ThreadsafeQueue.h @@ -31,7 +31,7 @@ #include <functional> #include <mutex> #include <condition_variable> -#include <queue> +#include <deque> #include <utility> #include <cassert> diff --git a/lib/edi/STIDecoder.cpp b/lib/edi/STIDecoder.cpp index 2de828b..0499c53 100644 --- a/lib/edi/STIDecoder.cpp +++ b/lib/edi/STIDecoder.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 + Copyright (C) 2025 Matthias P. Braendli, matthias.braendli@mpb.li http://opendigitalradio.org @@ -20,7 +20,6 @@ */ #include "STIDecoder.hpp" #include "buffer_unpack.hpp" -#include "crc.h" #include "Log.h" #include <cstdio> #include <cassert> @@ -180,7 +179,13 @@ bool STIDecoder::decode_ssn(const std::vector<uint8_t>& value, const tag_name_t& n |= (uint16_t)(name[3]); if (n == 0) { - etiLog.level(warn) << "EDI: Stream index SSnn tag is zero"; + if (not m_ssnn_zero_warning_printed) { + etiLog.level(warn) << "EDI: Stream index SSnn tag is zero"; + } + m_ssnn_zero_warning_printed = true; + } + else { + m_ssnn_zero_warning_printed = false; } if (m_filter_stream and m_filtered_stream_index != n) { @@ -197,14 +202,20 @@ bool STIDecoder::decode_ssn(const std::vector<uint8_t>& value, const tag_name_t& sti.stid = istc & 0xFFF; if (sti.rfa != 0) { - etiLog.level(warn) << "EDI: rfa field in SSnn tag non-null"; + if (not m_rfa_nonnull_warning_printed) { + etiLog.level(warn) << "EDI: rfa field in SSnn tag non-null"; + } + m_rfa_nonnull_warning_printed = true; + } + else { + m_rfa_nonnull_warning_printed = false; } copy( value.cbegin() + 3, value.cend(), back_inserter(sti.istd)); - m_data_collector.add_payload(move(sti)); + m_data_collector.add_payload(std::move(sti)); return true; } diff --git a/lib/edi/STIDecoder.hpp b/lib/edi/STIDecoder.hpp index 5e71ce7..81fbd82 100644 --- a/lib/edi/STIDecoder.hpp +++ b/lib/edi/STIDecoder.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 + Copyright (C) 2025 Matthias P. Braendli, matthias.braendli@mpb.li http://opendigitalradio.org @@ -139,6 +139,9 @@ class STIDecoder { bool m_filter_stream = false; uint16_t m_filtered_stream_index = 1; + + bool m_ssnn_zero_warning_printed = false; + bool m_rfa_nonnull_warning_printed = false; }; } diff --git a/lib/edioutput/EDIConfig.h b/lib/edioutput/EDIConfig.h index 7016e87..de4217f 100644 --- a/lib/edioutput/EDIConfig.h +++ b/lib/edioutput/EDIConfig.h @@ -27,6 +27,7 @@ #pragma once +#include <optional> #include <vector> #include <string> #include <memory> @@ -60,7 +61,7 @@ struct udp_destination_t : public destination_t { uint16_t dest_port = 0; std::string source_addr; uint16_t source_port = 0; - uint8_t ttl = 10; + std::optional<uint8_t> ttl = std::nullopt; }; // TCP server that can accept multiple connections diff --git a/lib/edioutput/Transport.cpp b/lib/edioutput/Transport.cpp index e9559b5..3898213 100644 --- a/lib/edioutput/Transport.cpp +++ b/lib/edioutput/Transport.cpp @@ -41,10 +41,15 @@ void configuration_t::print() const if (auto udp_dest = dynamic_pointer_cast<edi::udp_destination_t>(edi_dest)) { etiLog.level(info) << " UDP to " << udp_dest->dest_addr << ":" << udp_dest->dest_port; if (not udp_dest->source_addr.empty()) { - etiLog.level(info) << " source " << udp_dest->source_addr; - etiLog.level(info) << " ttl " << udp_dest->ttl; + etiLog.level(info) << " source address=" << udp_dest->source_addr; } - etiLog.level(info) << " source port " << udp_dest->source_port; + if (udp_dest->ttl) { + etiLog.level(info) << " ttl=" << (int)(*udp_dest->ttl); + } + else { + etiLog.level(info) << " ttl=(default)"; + } + etiLog.level(info) << " source port=" << udp_dest->source_port; } else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_server_t>(edi_dest)) { etiLog.level(info) << " TCP listening on port " << tcp_dest->listen_port; @@ -80,7 +85,10 @@ Sender::Sender(const configuration_t& conf) : if (not udp_dest->source_addr.empty()) { udp_socket.setMulticastSource(udp_dest->source_addr.c_str()); - udp_socket.setMulticastTTL(udp_dest->ttl); + } + + if (udp_dest->ttl) { + udp_socket.setMulticastTTL(*udp_dest->ttl); } auto sender = make_shared<udp_sender_t>( @@ -99,7 +107,7 @@ Sender::Sender(const configuration_t& conf) : make_shared<PFTSpreader>(tcp_dest->pft_settings, sender)); } else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(edi_dest)) { - auto sender = make_shared<tcp_send_client_t>(tcp_dest->dest_addr, tcp_dest->dest_port); + auto sender = make_shared<tcp_send_client_t>(tcp_dest->dest_addr, tcp_dest->dest_port, m_conf.verbose); m_pft_spreaders.emplace_back( make_shared<PFTSpreader>(tcp_dest->pft_settings, sender)); } @@ -199,7 +207,13 @@ void Sender::tcp_dispatcher_t::send_packet(const std::vector<uint8_t> &frame) void Sender::tcp_send_client_t::send_packet(const std::vector<uint8_t> &frame) { - sock.sendall(frame); + const auto error_stats = sock.sendall(frame); + + if (verbose and error_stats.has_seen_new_errors) { + etiLog.level(warn) << "TCP output " << dest_addr << ":" << dest_port + << " has " << error_stats.num_reconnects + << " reconnects: most recent error: " << error_stats.last_error; + } } Sender::udp_sender_t::udp_sender_t(std::string dest_addr, @@ -221,7 +235,11 @@ Sender::tcp_dispatcher_t::tcp_dispatcher_t(uint16_t listen_port, } Sender::tcp_send_client_t::tcp_send_client_t(const std::string &dest_addr, - uint16_t dest_port) : + uint16_t dest_port, + bool verbose) : + dest_addr(dest_addr), + dest_port(dest_port), + verbose(verbose), sock(dest_addr, dest_port) { } diff --git a/lib/edioutput/Transport.h b/lib/edioutput/Transport.h index b8a9008..96784c0 100644 --- a/lib/edioutput/Transport.h +++ b/lib/edioutput/Transport.h @@ -118,8 +118,13 @@ class Sender { struct tcp_send_client_t : public i_sender { tcp_send_client_t( const std::string& dest_addr, - uint16_t dest_port); + uint16_t dest_port, + bool verbose); + std::string dest_addr; + uint16_t dest_port; + bool verbose; + size_t m_num_reconnects_prev = 0; Socket::TCPSendClient sock; virtual void send_packet(const std::vector<uint8_t> &frame) override; }; diff --git a/lib/fec/decode_rs.h b/lib/fec/decode_rs.h index c165cf3..647b885 100644 --- a/lib/fec/decode_rs.h +++ b/lib/fec/decode_rs.h @@ -145,15 +145,15 @@ count++; } if (count != no_eras) { - printf("count = %d no_eras = %d\n lambda(x) is WRONG\n",count,no_eras); + fprintf(stderr, "count = %d no_eras = %d\n lambda(x) is WRONG\n",count,no_eras); count = -1; goto finish; } #if DEBUG >= 2 - printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n"); + fprintf(stderr, "\n Erasure positions as determined by roots of Eras Loc Poly:\n"); for (i = 0; i < count; i++) - printf("%d ", loc[i]); - printf("\n"); + fprintf(stderr, "%d ", loc[i]); + fprintf(stderr, "\n"); #endif #endif } @@ -227,7 +227,7 @@ continue; /* Not a root */ /* store root (index-form) and error location number */ #if DEBUG>=2 - printf("count %d root %d loc %d\n",count,i,k); + fprintf(stderr, "count %d root %d loc %d\n",count,i,k); #endif root[count] = i; loc[count] = k; @@ -279,7 +279,7 @@ } #if DEBUG >= 1 if (den == 0) { - printf("\n ERROR: denominator = 0\n"); + fprintf(stderr, "\n ERROR: denominator = 0\n"); count = -1; goto finish; } |
