RAVENNAKIT
Loading...
Searching...
No Matches
rav::RavennaNode Class Reference

This class contains all the components to act like a RAVENNA node as specified in the RAVENNA protocol. More...

#include <ravenna_node.hpp>

Classes

struct  Configuration
 Holds the configuration of the node. More...
class  Subscriber
 Base class for classes which want to receive updates from the ravenna node. More...

Public Member Functions

 RavennaNode ()
 ~RavennaNode ()
std::future< tl::expected< Id, std::string > > create_receiver (RavennaReceiver::Configuration initial_config)
 Creates a new receiver for the given session.
std::future< void > remove_receiver (Id receiver_id)
 Removes the receiver with the given id.
std::future< tl::expected< void, std::string > > update_receiver_configuration (Id receiver_id, RavennaReceiver::Configuration config)
 Updates the configuration of the receiver with the given id.
std::future< void > subscribe_to_receiver (Id receiver_id, RavennaReceiver::Subscriber *subscriber)
 Adds a subscriber to the receiver with the given id.
std::future< void > unsubscribe_from_receiver (Id receiver_id, RavennaReceiver::Subscriber *subscriber)
 Removes a subscriber from the receiver with the given id.
std::optional< uint32_t > read_data_realtime (Id receiver_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 receiver_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::future< tl::expected< sdp::SessionDescription, std::string > > get_sdp_for_sender (Id sender_id)
 Get the SDP for the sender with the given id.
std::future< std::optional< sdp::SessionDescription > > get_sdp_for_receiver (Id receiver_id)
 Get the SDP for the receiver with the given id.
std::future< std::optional< std::string > > get_sdp_text_for_receiver (Id receiver_id)
 Get the SDP text for the receiver with the given id.
std::future< tl::expected< Id, std::string > > create_sender (RavennaSender::Configuration initial_config)
 Creates a sender for the given session.
std::future< void > remove_sender (Id sender_id)
 Removes the sender with the given id.
std::future< tl::expected< void, std::string > > update_sender_configuration (Id sender_id, RavennaSender::Configuration config)
 Updates the configuration of the sender with the given id.
std::future< void > subscribe_to_sender (Id sender_id, RavennaSender::Subscriber *subscriber)
 Adds a subscriber to the sender with the given id.
std::future< void > unsubscribe_from_sender (Id sender_id, RavennaSender::Subscriber *subscriber)
 Removes a subscriber from the sender with the given id.
bool send_data_realtime (Id sender_id, BufferView< const uint8_t > buffer, uint32_t timestamp)
 Schedules data for sending.
bool send_audio_data_realtime (Id sender_id, const AudioBufferView< const float > &buffer, uint32_t timestamp)
 Schedules audio data for sending.
std::future< void > subscribe_to_ptp_instance (ptp::Instance::Subscriber *subscriber)
 Adds a subscriber to the PTP instance.
std::future< void > unsubscribe_from_ptp_instance (ptp::Instance::Subscriber *subscriber)
 Removes a subscriber from the PTP instance.
std::future< tl::expected< void, std::string > > set_ptp_instance_configuration (ptp::Instance::Configuration update)
 Sets the configuration of the PTP instance.
std::future< tl::expected< void, std::string > > set_nmos_configuration (nmos::Node::Configuration update)
 Sets the configuration of the NMOS node.
std::future< boost::uuids::uuid > get_nmos_device_id ()
std::future< void > subscribe (Subscriber *subscriber)
 Adds a subscriber to the node.
std::future< void > unsubscribe (Subscriber *subscriber)
 Removes a subscriber from the node.
std::future< void > set_network_interface_config (NetworkInterfaceConfig interface_config)
 Sets the network interfaces to use.
std::future< void > set_configuration (Configuration config)
 Sets the configuration for this node, state will be updated accordingly.
bool is_maintenance_thread () const
std::future< boost::json::object > to_boost_json ()
std::future< tl::expected< void, std::string > > restore_from_boost_json (const boost::json::value &json)
 Restores the node from a JSON representation.
template<typename CompletionToken>
auto dispatch (CompletionToken &&token)
 Schedules some work on the maintenance thread using boost::asio::dispatch.
template<typename CompletionToken>
auto post (CompletionToken &&token)
 Schedules some work on the maintenance thread using asio::post.

Detailed Description

This class contains all the components to act like a RAVENNA node as specified in the RAVENNA protocol.

Definition at line 48 of file ravenna_node.hpp.

Constructor & Destructor Documentation

◆ RavennaNode()

rav::RavennaNode::RavennaNode ( )
explicit

◆ ~RavennaNode()

rav::RavennaNode::~RavennaNode ( )

Member Function Documentation

◆ create_receiver()

std::future< tl::expected< Id, std::string > > rav::RavennaNode::create_receiver ( RavennaReceiver::Configuration initial_config)
nodiscard

Creates a new receiver for the given session.

Parameters
initial_configThe initial configuration for the receiver. Optional.
Returns
The ID of the created receiver, which might be invalid if the receiver couldn't be created.

◆ create_sender()

std::future< tl::expected< Id, std::string > > rav::RavennaNode::create_sender ( RavennaSender::Configuration initial_config)
nodiscard

Creates a sender for the given session.

Returns
The ID of the created sender, which might be invalid if the sender couldn't be created.

◆ dispatch()

template<typename CompletionToken>
auto rav::RavennaNode::dispatch ( CompletionToken && token)
inlinenodiscard

Schedules some work on the maintenance thread using boost::asio::dispatch.

This is useful for synchronizing with callbacks from the node and to offload work from the main (UI) thread. If passing using asio::use_future, the future will be set when the work is complete.

Example: node.dispatch(asio::use_future([] { return 1; })).get();

Template Parameters
CompletionTokenThe type of the completion token.
Parameters
tokenThe completion token.
Returns
The result of the dispatch operation, depending on the completion token.

Definition at line 373 of file ravenna_node.hpp.

◆ get_nmos_device_id()

std::future< boost::uuids::uuid > rav::RavennaNode::get_nmos_device_id ( )
Returns
The UUID of the nmos device.

◆ get_sdp_for_receiver()

std::future< std::optional< sdp::SessionDescription > > rav::RavennaNode::get_sdp_for_receiver ( Id receiver_id)
nodiscard

Get the SDP for the receiver with the given id.

TODO: Deprecate and signal sdp changes through RavennaReceiver::Subscriber

Parameters
receiver_idThe id of the receiver to get the SDP for.
Returns
The SDP for the receiver.

◆ get_sdp_for_sender()

std::future< tl::expected< sdp::SessionDescription, std::string > > rav::RavennaNode::get_sdp_for_sender ( Id sender_id)

Get the SDP for the sender with the given id.

This function will generate the SDP based on the current state of the receiver.

Parameters
sender_idThe id of the sender to get the SDP for.
Returns
The SDP for the sender.

◆ get_sdp_text_for_receiver()

std::future< std::optional< std::string > > rav::RavennaNode::get_sdp_text_for_receiver ( Id receiver_id)
nodiscard

Get the SDP text for the receiver with the given id.

This is the original SDP text as received from the server, and might contain things which haven't been parsed into the session_description. TODO: Deprecate and signal sdp changes through RavennaReceiver::Subscriber

Parameters
receiver_idThe id of the receiver to get the SDP text for.
Returns
The SDP text for the receiver.

◆ is_maintenance_thread()

bool rav::RavennaNode::is_maintenance_thread ( ) const
nodiscard
Returns
True if this method is called on the maintenance thread, false otherwise.

◆ post()

template<typename CompletionToken>
auto rav::RavennaNode::post ( CompletionToken && token)
inlinenodiscard

Schedules some work on the maintenance thread using asio::post.

This is useful for synchronizing with callbacks from the node and to offload work from the main (UI) thread. If passing using asio::use_future, the future will be set when the work is complete.

Example: node.post(asio::use_future([] { return 1; })).get();

Template Parameters
CompletionTokenThe type of the completion token.
Parameters
tokenThe completion token.
Returns
The result of the dispatch operation, depending on the completion token.

Definition at line 392 of file ravenna_node.hpp.

◆ read_audio_data_realtime()

std::optional< uint32_t > rav::RavennaNode::read_audio_data_realtime ( Id receiver_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::RavennaNode::read_data_realtime ( Id receiver_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.

◆ remove_receiver()

std::future< void > rav::RavennaNode::remove_receiver ( Id receiver_id)
nodiscard

Removes the receiver with the given id.

Parameters
receiver_idThe id of the receiver to remove.
Returns
A future that will be set when the operation is complete.

◆ remove_sender()

std::future< void > rav::RavennaNode::remove_sender ( Id sender_id)
nodiscard

Removes the sender with the given id.

Parameters
sender_idThe id of the sender to remove.
Returns
A future that will be set when the operation is complete.

◆ restore_from_boost_json()

std::future< tl::expected< void, std::string > > rav::RavennaNode::restore_from_boost_json ( const boost::json::value & json)
nodiscard

Restores the node from a JSON representation.

Parameters
jsonThe JSON representation of the node.
Returns
A future that will be set when the operation is complete.

◆ send_audio_data_realtime()

bool rav::RavennaNode::send_audio_data_realtime ( Id sender_id,
const AudioBufferView< const float > & buffer,
uint32_t timestamp )
nodiscard

Schedules audio data for sending.

A call to this function is realtime safe and thread safe as long as only one thread makes the call.

Parameters
idThe id of the writer.
input_bufferThe buffer to send.
timestampThe timestamp of the buffer.
Returns
True if the buffer was sent, or false if something went wrong.

◆ send_data_realtime()

bool rav::RavennaNode::send_data_realtime ( Id sender_id,
BufferView< const uint8_t > buffer,
uint32_t timestamp )
nodiscard

Schedules data for sending.

A call to this function is realtime safe and thread safe as long as only one thread makes the call.

Parameters
idThe id of the writer.
bufferThe buffer to send.
timestampThe timestamp of the buffer.
Returns
True if the buffer was sent, or false if something went wrong.

◆ set_configuration()

std::future< void > rav::RavennaNode::set_configuration ( Configuration config)

Sets the configuration for this node, state will be updated accordingly.

Parameters
configThe new configuration.
Returns
A future that will be set when the operation is complete.

◆ set_network_interface_config()

std::future< void > rav::RavennaNode::set_network_interface_config ( NetworkInterfaceConfig interface_config)
nodiscard

Sets the network interfaces to use.

Can contain multiple interfaces for redundancy (not yet implemented).

Parameters
interface_configThe interfaces to use. If empty, operations will be stopped.
Returns
A future that will be set when the operation is complete.

◆ set_nmos_configuration()

std::future< tl::expected< void, std::string > > rav::RavennaNode::set_nmos_configuration ( nmos::Node::Configuration update)
nodiscard

Sets the configuration of the NMOS node.

Parameters
updateThe configuration to set.
Returns
A future that will be set when the operation is complete.

◆ set_ptp_instance_configuration()

std::future< tl::expected< void, std::string > > rav::RavennaNode::set_ptp_instance_configuration ( ptp::Instance::Configuration update)
nodiscard

Sets the configuration of the PTP instance.

Parameters
updateThe configuration to set.
Returns
A future that will be set when the operation is complete.

◆ subscribe()

std::future< void > rav::RavennaNode::subscribe ( Subscriber * subscriber)
nodiscard

Adds a subscriber to the node.

This method can be called from any thread, and will wait until the operation is complete.

Parameters
subscriberThe subscriber to add.

◆ subscribe_to_ptp_instance()

std::future< void > rav::RavennaNode::subscribe_to_ptp_instance ( ptp::Instance::Subscriber * subscriber)
nodiscard

Adds a subscriber to the PTP instance.

Parameters
subscriberThe subscriber to add.
Returns
A future that will be set when the operation is complete.

◆ subscribe_to_receiver()

std::future< void > rav::RavennaNode::subscribe_to_receiver ( Id receiver_id,
RavennaReceiver::Subscriber * subscriber )
nodiscard

Adds a subscriber to the receiver with the given id.

Parameters
receiver_idThe id of the stream to add the subscriber to.
subscriberThe subscriber to add.
Returns
A future that will be set when the operation is complete.

◆ subscribe_to_sender()

std::future< void > rav::RavennaNode::subscribe_to_sender ( Id sender_id,
RavennaSender::Subscriber * subscriber )
nodiscard

Adds a subscriber to the sender with the given id.

Parameters
sender_idThe id of the stream to add the subscriber to.
subscriberThe subscriber to add.
Returns
A future that will be set when the operation is complete.

◆ to_boost_json()

std::future< boost::json::object > rav::RavennaNode::to_boost_json ( )
nodiscard
Returns
A JSON representation of the node.

◆ unsubscribe()

std::future< void > rav::RavennaNode::unsubscribe ( Subscriber * subscriber)
nodiscard

Removes a subscriber from the node.

This method can be called from any thread, and will wait until the operation is complete.

Parameters
subscriberThe subscriber to remove.

◆ unsubscribe_from_ptp_instance()

std::future< void > rav::RavennaNode::unsubscribe_from_ptp_instance ( ptp::Instance::Subscriber * subscriber)
nodiscard

Removes a subscriber from the PTP instance.

Parameters
subscriberThe subscriber to remove.
Returns
A future that will be set when the operation is complete.

◆ unsubscribe_from_receiver()

std::future< void > rav::RavennaNode::unsubscribe_from_receiver ( Id receiver_id,
RavennaReceiver::Subscriber * subscriber )
nodiscard

Removes a subscriber from the receiver with the given id.

Parameters
receiver_idThe id of the stream to remove the subscriber from.
subscriberThe subscriber to remove.
Returns
A future that will be set when the operation is complete.

◆ unsubscribe_from_sender()

std::future< void > rav::RavennaNode::unsubscribe_from_sender ( Id sender_id,
RavennaSender::Subscriber * subscriber )
nodiscard

Removes a subscriber from the sender with the given id.

Parameters
sender_idThe id of the stream to remove the subscriber from.
subscriberThe subscriber to remove.
Returns
A future that will be set when the operation is complete.

◆ update_receiver_configuration()

std::future< tl::expected< void, std::string > > rav::RavennaNode::update_receiver_configuration ( Id receiver_id,
RavennaReceiver::Configuration config )
nodiscard

Updates the configuration of the receiver with the given id.

Parameters
receiver_idThe id of the receiver to update.
configThe configuration changes to apply.
Returns
A future that will be set when the operation is complete.

◆ update_sender_configuration()

std::future< tl::expected< void, std::string > > rav::RavennaNode::update_sender_configuration ( Id sender_id,
RavennaSender::Configuration config )
nodiscard

Updates the configuration of the sender with the given id.

Parameters
sender_idThe id of the sender to update.
configThe configuration changes to apply.
Returns
A future that will be set when the operation is complete.

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