RAVENNAKIT
Loading...
Searching...
No Matches
rav::rtp::AudioReceiver Struct Reference

#include <rtp_audio_receiver.hpp>

Classes

struct  StreamInfo
struct  ReaderParameters
struct  SocketWithContext
struct  PacketBuffer
struct  StreamContext
struct  Reader
 Holds the structures to receive incoming data from redundant sources into a single buffer. More...

Public Types

enum class  StreamState { inactive , receiving , no_consumer }
 The state of a reader. More...
using ArrayOfAddresses = std::array<ip_address_v4, k_max_num_redundant_sessions>

Public Member Functions

 AudioReceiver (boost::asio::io_context &io_context)
 ~AudioReceiver ()
bool add_reader (Id id, const ReaderParameters &parameters, const ArrayOfAddresses &interfaces)
 Adds a reader to the receiver.
bool remove_reader (Id id)
 Removes the reader with given id, if it exists.
bool set_interfaces (const ArrayOfAddresses &interfaces)
 Sets the interfaces on all readers, leaving and joining multicast groups where necessary.
void read_incoming_packets ()
 Call this to read incoming packets and place the data inside a fifo for consumption.
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< 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.
std::optional< PacketStats::Counters > get_packet_stats (Id reader_id, size_t stream_index)
std::optional< StreamState > get_stream_state (Id reader_id, size_t stream_index) const

Public Attributes

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.
ptp::Instance::Subscriber ptp_instance_subscriber
boost::container::static_vector< SocketWithContext, k_max_num_sessions > sockets
boost::container::static_vector< Reader, k_max_num_readers > readers
uint64_t last_time_maintenance {}

Static Public Attributes

static constexpr auto k_max_num_readers = RAV_MAX_NUM_READERS
 The maximum number of readers.
static constexpr auto k_max_num_redundant_sessions = 2
 The maximum number of redundant sessions per reader (redundant paths).
static constexpr uint64_t k_receive_timeout_ms = 1000
 The number of milliseconds after which a stream is considered inactive.
static constexpr uint32_t k_buffer_size_ms = 200
 The length of the receiver buffer in milliseconds.
static constexpr auto k_max_num_sessions = k_max_num_readers * k_max_num_redundant_sessions

Detailed Description

Definition at line 51 of file rtp_audio_receiver.hpp.

Member Typedef Documentation

◆ ArrayOfAddresses

Member Enumeration Documentation

◆ StreamState

The state of a reader.

Enumerator
inactive 

The stream is inactive because no packets have been received for a while.

receiving 

Packets are being received and consumed.

no_consumer 

Packets are being received, but they are not consumed.

Definition at line 122 of file rtp_audio_receiver.hpp.

Constructor & Destructor Documentation

◆ AudioReceiver()

rav::rtp::AudioReceiver::AudioReceiver ( boost::asio::io_context & io_context)
explicit

◆ ~AudioReceiver()

rav::rtp::AudioReceiver::~AudioReceiver ( )

Member Function Documentation

◆ add_reader()

bool rav::rtp::AudioReceiver::add_reader ( Id id,
const ReaderParameters & parameters,
const ArrayOfAddresses & interfaces )
nodiscard

Adds a reader to the receiver.

Thread safe: no.

Parameters
idThe id to use, must be unique.
parametersThe parameters of a reader.
interfacesThe interfaces to receive multicast sessions on.
Returns
true if a new reader was added, or false if not.

◆ get_packet_stats()

std::optional< PacketStats::Counters > rav::rtp::AudioReceiver::get_packet_stats ( Id reader_id,
size_t stream_index )
Parameters
reader_idThe id of the reader to get statistics from.
stream_indexThe index of the stream to get stats from.
Returns
The statistics for given stream index, or nullopt if no statistics could be read.

◆ get_stream_state()

std::optional< StreamState > rav::rtp::AudioReceiver::get_stream_state ( Id reader_id,
size_t stream_index ) const
nodiscard
Parameters
reader_idThe id of the reader to get the state for.
stream_indexThe index of the stream to get the state for.
Returns
The stream state for given reader.

◆ read_audio_data_realtime()

std::optional< uint32_t > rav::rtp::AudioReceiver::read_audio_data_realtime ( Id id,
AudioBufferView< float > & output_buffer,
std::optional< uint32_t > at_timestamp,
std::optional< uint32_t > require_delay )
nodiscard

Reads the data from the receiver with the given id.

Calling this function is realtime safe and thread safe when called from a single arbitrary thread.

Parameters
idThe id of the reader to get data from.
output_bufferThe buffer to read the data into.
at_timestampThe optional timestamp to read at. If nullopt, the most recent timestamp minus the delay will be used for the first read and after that the timestamp will be incremented by the packet time.
require_delayIf set, the call to read_audio_data_realtime will only succeed if the requested timestamp is older than the most recent received timestamp - require_delay. This can be useful in a case where there is no PTP clock driving time, and instead, the time of the RTP stream has to be used. In normal PTP driven operation you would not set require_delay.
Returns
The timestamp at which the data was read, or std::nullopt if an error occurred.

◆ read_data_realtime()

std::optional< uint32_t > rav::rtp::AudioReceiver::read_data_realtime ( Id id,
uint8_t * buffer,
size_t buffer_size,
std::optional< uint32_t > at_timestamp,
std::optional< uint32_t > require_delay )
nodiscard

Reads data from the buffer at the given timestamp.

Calling this function is realtime safe and thread safe when called from a single arbitrary thread.

Parameters
idThe id of the reader to get data from.
bufferThe destination to write the data to.
buffer_sizeThe size of the buffer in bytes.
at_timestampThe optional timestamp to read at. If nullopt, the most recent timestamp minus the delay will be used for the first read and after that the timestamp will be incremented by the packet time.
require_delayIf set, the call to read_data_realtime will only succeed if the requested timestamp is older than the most recent received timestamp - require_delay. This can be useful in a case where there is no PTP clock driving time, and instead, the time of the RTP stream has to be used. In normal PTP driven operation you would not set require_delay.
Returns
The timestamp at which the data was read, or std::nullopt if an error occurred.

◆ read_incoming_packets()

void rav::rtp::AudioReceiver::read_incoming_packets ( )

Call this to read incoming packets and place the data inside a fifo for consumption.

Should be called from a single high priority thread with regular short intervals.

◆ remove_reader()

bool rav::rtp::AudioReceiver::remove_reader ( Id id)
nodiscard

Removes the reader with given id, if it exists.

Thread safe: no.

Parameters
idThe id of the reader to remove.
Returns
true if a reader was removed, or false if not.

◆ set_interfaces()

bool rav::rtp::AudioReceiver::set_interfaces ( const ArrayOfAddresses & interfaces)
nodiscard

Sets the interfaces on all readers, leaving and joining multicast groups where necessary.

Parameters
interfacesThe new interfaces to use.

Member Data Documentation

◆ join_multicast_group

SafeFunction<bool(udp_socket&, ip_address_v4, ip_address_v4)> rav::rtp::AudioReceiver::join_multicast_group

Function for joining a multicast group. Can be overridden to alter behaviour. Used for unit testing.

Definition at line 266 of file rtp_audio_receiver.hpp.

◆ k_buffer_size_ms

uint32_t rav::rtp::AudioReceiver::k_buffer_size_ms = 200
staticconstexpr

The length of the receiver buffer in milliseconds.

AES67 specifies at least 20 ms or 20 times the packet time, whichever is smaller, but since we're on desktop systems we go a bit higher. Note that this number is not the same as the delay or added latency.

Definition at line 64 of file rtp_audio_receiver.hpp.

◆ k_max_num_readers

auto rav::rtp::AudioReceiver::k_max_num_readers = RAV_MAX_NUM_READERS
staticconstexpr

The maximum number of readers.

Definition at line 53 of file rtp_audio_receiver.hpp.

◆ k_max_num_redundant_sessions

auto rav::rtp::AudioReceiver::k_max_num_redundant_sessions = 2
staticconstexpr

The maximum number of redundant sessions per reader (redundant paths).

Definition at line 56 of file rtp_audio_receiver.hpp.

◆ k_max_num_sessions

auto rav::rtp::AudioReceiver::k_max_num_sessions = k_max_num_readers * k_max_num_redundant_sessions
staticconstexpr

Definition at line 273 of file rtp_audio_receiver.hpp.

◆ k_receive_timeout_ms

uint64_t rav::rtp::AudioReceiver::k_receive_timeout_ms = 1000
staticconstexpr

The number of milliseconds after which a stream is considered inactive.

Definition at line 59 of file rtp_audio_receiver.hpp.

◆ last_time_maintenance

uint64_t rav::rtp::AudioReceiver::last_time_maintenance {}

Definition at line 278 of file rtp_audio_receiver.hpp.

◆ leave_multicast_group

SafeFunction<bool(udp_socket&, ip_address_v4, ip_address_v4)> rav::rtp::AudioReceiver::leave_multicast_group

Function for leaving a multicast group. Can be overridden to alter behaviour. Used for unit testing.

Definition at line 269 of file rtp_audio_receiver.hpp.

◆ ptp_instance_subscriber

ptp::Instance::Subscriber rav::rtp::AudioReceiver::ptp_instance_subscriber

Definition at line 271 of file rtp_audio_receiver.hpp.

◆ readers

boost::container::static_vector<Reader, k_max_num_readers> rav::rtp::AudioReceiver::readers

Definition at line 276 of file rtp_audio_receiver.hpp.

◆ sockets

boost::container::static_vector<SocketWithContext, k_max_num_sessions> rav::rtp::AudioReceiver::sockets

Definition at line 275 of file rtp_audio_receiver.hpp.


The documentation for this struct was generated from the following file: