41#include <boost/asio.hpp>
42#include <boost/container/static_vector.hpp>
43#include <boost/lockfree/spsc_value.hpp>
45#ifndef RAV_MAX_NUM_READERS
46 #define RAV_MAX_NUM_READERS 16
73 [[nodiscard]]
auto tie()
const {
78 return lhs.
tie() == rhs.
tie();
82 return lhs.
tie() != rhs.
tie();
92 std::array<StreamInfo, k_max_num_redundant_sessions>
streams;
94 [[nodiscard]]
auto tie()
const {
99 return lhs.
tie() == rhs.
tie();
103 return lhs.
tie() != rhs.
tie();
111 if (stream.is_valid()) {
181 Id id, uint8_t* buffer,
size_t buffer_size, std::optional<uint32_t> at_timestamp, std::optional<uint32_t> require_delay
200 Id id,
AudioBufferView<float>& output_buffer, std::optional<uint32_t> at_timestamp, std::optional<uint32_t> require_delay
230 std::array<uint8_t, aes67::constants::k_max_payload>
payload;
242 boost::lockfree::spsc_value<PacketStats::Counters, boost::lockfree::allow_multiple_reads<true>>
packet_stats_counters;
256 std::array<StreamContext, k_max_num_redundant_sessions>
streams;
275 boost::container::static_vector<SocketWithContext, k_max_num_sessions>
sockets;
276 boost::container::static_vector<Reader, k_max_num_readers>
readers;
A lock-free (and sometimes wait-free) reader writer lock.
A non-owning view of a non-interleaved audio buffer.
A classic FIFO buffer implementation with different strategies F.
A class which represents a unique identifier.
A simple callback function wrapper that can be used to store and call a function with a specific sign...
Implements logic for filtering RTP packets.
A class that collects statistics about RTP packets.
A buffer which operates on bytes, unaware of its contents.
const char * to_string(AudioReceiver::StreamState state)
WrappingUint< uint32_t > WrappingUint32
32-bit wrapping unsigned integer.
boost::asio::ip::udp::socket udp_socket
WrappingUint< uint64_t > WrappingUint64
64-bit wrapping unsigned integer.
boost::asio::ip::address_v4 ip_address_v4
#define RAV_MAX_NUM_READERS
Keeps track of an ema with outliers filtered out and a max deviation.
std::array< uint8_t, aes67::constants::k_max_payload > payload
Holds the structures to receive incoming data from redundant sources into a single buffer.
Ringbuffer receive_buffer
std::vector< uint8_t > read_audio_data_buffer
std::optional< WrappingUint32 > most_recent_ts
WrappingUint32 next_ts_to_read
std::array< StreamContext, k_max_num_redundant_sessions > streams
friend bool operator!=(const ReaderParameters &lhs, const ReaderParameters &rhs)
friend bool operator==(const ReaderParameters &lhs, const ReaderParameters &rhs)
std::array< StreamInfo, k_max_num_redundant_sessions > streams
SocketWithContext(boost::asio::io_context &io_context)
std::atomic< bool > reset_max_values
FifoBuffer< uint16_t, Fifo::Spsc > packets_too_old
boost::lockfree::spsc_value< PacketStats::Counters, boost::lockfree::allow_multiple_reads< true > > packet_stats_counters
std::optional< WrappingUint32 > rtp_ts
std::atomic< StreamState > state
uint16_t packet_time_frames
IntervalStats packet_interval_stats
FifoBuffer< PacketBuffer, Fifo::Spsc > packets
WrappingUint64 prev_packet_time_ns
friend bool operator!=(const StreamInfo &lhs, const StreamInfo &rhs)
friend bool operator==(const StreamInfo &lhs, const StreamInfo &rhs)
uint16_t packet_time_frames
static constexpr auto k_max_num_redundant_sessions
The maximum number of redundant sessions per reader (redundant paths).
std::optional< PacketStats::Counters > get_packet_stats(Id reader_id, size_t stream_index)
boost::container::static_vector< SocketWithContext, k_max_num_sessions > sockets
bool remove_reader(Id id)
Removes the reader with given id, if it exists.
SafeFunction< bool(udp_socket &, ip_address_v4, ip_address_v4)> join_multicast_group
Function for joining a multicast group. Can be overridden to alter behaviour. Used for unit testing.
SafeFunction< bool(udp_socket &, ip_address_v4, ip_address_v4)> leave_multicast_group
Function for leaving a multicast group. Can be overridden to alter behaviour. Used for unit testing.
static constexpr auto k_max_num_readers
The maximum number of readers.
static constexpr uint32_t k_buffer_size_ms
The length of the receiver buffer in milliseconds.
std::optional< uint32_t > read_data_realtime(Id id, uint8_t *buffer, size_t buffer_size, std::optional< uint32_t > at_timestamp, std::optional< uint32_t > require_delay)
Reads data from the buffer at the given timestamp.
std::optional< StreamState > get_stream_state(Id reader_id, size_t stream_index) const
uint64_t last_time_maintenance
StreamState
The state of a reader.
@ receiving
Packets are being received and consumed.
@ no_consumer
Packets are being received, but they are not consumed.
@ inactive
The stream is inactive because no packets have been received for a while.
std::array< ip_address_v4, k_max_num_redundant_sessions > ArrayOfAddresses
ptp::Instance::Subscriber ptp_instance_subscriber
bool add_reader(Id id, const ReaderParameters ¶meters, const ArrayOfAddresses &interfaces)
Adds a reader to the receiver.
static constexpr uint64_t k_receive_timeout_ms
The number of milliseconds after which a stream is considered inactive.
void read_incoming_packets()
Call this to read incoming packets and place the data inside a fifo for consumption.
bool set_interfaces(const ArrayOfAddresses &interfaces)
Sets the interfaces on all readers, leaving and joining multicast groups where necessary.
static constexpr auto k_max_num_sessions
AudioReceiver(boost::asio::io_context &io_context)
std::optional< uint32_t > read_audio_data_realtime(Id id, AudioBufferView< float > &output_buffer, std::optional< uint32_t > at_timestamp, std::optional< uint32_t > require_delay)
Reads the data from the receiver with the given id.
boost::container::static_vector< Reader, k_max_num_readers > readers