20#ifndef SACN_CPP_SOURCE_H_
21#define SACN_CPP_SOURCE_H_
179 uint16_t universe_id,
180 const std::vector<SacnMcastInterface>& network_interfaces);
209 etcpal::Error SendNow(uint16_t universe, uint8_t start_code,
const uint8_t* buffer,
size_t buflen);
212 void UpdateLevels(uint16_t universe,
const uint8_t* new_levels,
size_t new_levels_size);
214 const uint8_t* new_levels,
215 size_t new_levels_size,
216 const uint8_t* new_priorities,
217 size_t new_priorities_size);
220 const uint8_t* new_levels,
221 size_t new_levels_size,
222 const uint8_t* new_priorities,
223 size_t new_priorities_size);
235 std::vector<UniverseNetintList>& netint_lists,
239 class TranslatedUniverseConfig
261 : cid(std::move(new_cid)), name(std::move(new_name))
270 return !cid.IsNull();
296 uint16_t universe_id,
297 McastMode mcast_mode = McastMode::kEnabledOnAllInterfaces)
298 :
handle(source_handle), universe(universe_id), no_netints(mcast_mode ==
McastMode::kDisabledOnAllInterfaces)
309 uint16_t universe_id,
310 const std::vector<SacnMcastInterface>& network_interfaces)
311 :
handle(source_handle), universe(universe_id), netints(network_interfaces)
402 McastMode mcast_mode = McastMode::kEnabledOnAllInterfaces)
404 TranslatedUniverseConfig config(settings);
407 if (mcast_mode == McastMode::kDisabledOnAllInterfaces)
440 TranslatedUniverseConfig config(settings);
446 netint_config.
netints = netints.data();
476 size_t size_guess = 4u;
477 std::vector<uint16_t> universes(size_guess);
480 while (num_universes > universes.size())
482 size_guess = num_universes + 4u;
483 universes.resize(size_guess);
487 universes.resize(num_universes);
534 size_t size_guess = 4u;
535 std::vector<EtcPalIpAddr> destinations(size_guess);
536 size_t num_destinations =
539 while (num_destinations > destinations.size())
541 size_guess = num_destinations + 4u;
542 destinations.resize(size_guess);
547 destinations.resize(num_destinations);
550 std::vector<etcpal::IpAddr> result;
551 if (!destinations.empty())
553 result.reserve(destinations.size());
554 std::transform(destinations.begin(), destinations.end(), std::back_inserter(result),
555 [](
const EtcPalIpAddr& dest) { return etcpal::IpAddr(dest); });
713 const uint8_t* new_levels,
714 size_t new_levels_size,
715 const uint8_t* new_priorities,
716 size_t new_priorities_size)
719 new_priorities_size);
770 const uint8_t* new_levels,
771 size_t new_levels_size,
772 const uint8_t* new_priorities,
773 size_t new_priorities_size)
776 new_priorities, new_priorities_size);
828 McastMode mcast_mode = McastMode::kEnabledOnAllInterfaces,
832 if (mcast_mode == McastMode::kDisabledOnAllInterfaces)
866 std::vector<SacnMcastInterface>& sys_netints,
872 if (!sys_netints.empty())
874 netint_config.
netints = sys_netints.data();
912 std::vector<SacnMcastInterface>& sys_netints,
913 std::vector<UniverseNetintList>& per_universe_netint_lists,
916 std::vector<SacnSourceUniverseNetintList> netint_lists_c;
917 netint_lists_c.reserve(per_universe_netint_lists.size());
918 std::transform(per_universe_netint_lists.begin(), per_universe_netint_lists.end(), std::back_inserter(netint_lists_c),
921 SacnSourceUniverseNetintList c_list = {
934 sys_netint_config.
netints = sys_netints.data();
935 sys_netint_config.num_netints = sys_netints.size();
936 sys_netint_config.send_socket_config = send_socket_config;
949 size_t size_guess = 4u;
950 std::vector<EtcPalMcastNetintId> netints(size_guess);
953 while (num_netints > netints.size())
955 size_guess = num_netints + 4u;
956 netints.resize(size_guess);
960 netints.resize(num_netints);
979 settings.name.c_str(),
980 settings.universe_count_max,
981 settings.manually_process_source,
982 settings.ip_supported,
983 settings.keep_alive_interval,
984 settings.pap_keep_alive_interval
993 if (!unicast_destinations_.empty())
1003inline Source::TranslatedUniverseConfig::TranslatedUniverseConfig(
const UniverseSettings& settings)
1007 settings.send_preview,
1008 settings.send_unicast_only,
1011 settings.sync_universe
1016 if (!settings.unicast_destinations.empty())
1018 unicast_destinations_.reserve(settings.unicast_destinations.size());
1019 std::transform(settings.unicast_destinations.begin(), settings.unicast_destinations.end(),
1020 std::back_inserter(unicast_destinations_), [](
const etcpal::IpAddr& dest) { return dest.get(); });
constexpr const EtcPalIpAddr & get() const noexcept
ETCPAL_CONSTEXPR_14 void Clear()
ETCPAL_CONSTEXPR_14 void SetValue(const ValueType &new_value)
constexpr ValueType value() const
An instance of sACN Source functionality; see Using the sACN Source API.
Definition source.h:61
void UpdateLevelsAndPapAndForceSync(uint16_t universe, const uint8_t *new_levels, size_t new_levels_size, const uint8_t *new_priorities, size_t new_priorities_size)
Like UpdateLevelsAndPap(), but also sets the force_sync flag on the packet.
Definition source.h:769
void RemoveUniverse(uint16_t universe)
Remove a universe from a source.
Definition source.h:463
etcpal::Error AddUniverse(const UniverseSettings &settings, McastMode mcast_mode)
Add a universe to an sACN source.
Definition source.h:401
etcpal::Error ChangeName(const std::string &new_name)
Change the name of an sACN source.
Definition source.h:371
static int ProcessManual(TickMode tick_mode)
Trigger the transmission of sACN packets for all universes of sources that were created with manually...
Definition source.h:796
static etcpal::Error ResetNetworking(McastMode mcast_mode, const SacnSendSocketConfig &send_socket_config)
Resets the underlying network sockets for all universes of all sources.
Definition source.h:827
Source & operator=(Source &&other)=default
Move a source instance.
Source(Source &&other)=default
Move a source instance.
etcpal::Error ChangeSynchronizationUniverse(uint16_t universe, uint16_t new_sync_universe)
Changes the synchronization universe for a universe.
Definition source.h:623
etcpal::Error Startup(const Settings &settings)
Create a new sACN source to send sACN data.
Definition source.h:331
etcpal::Error SendSynchronization(uint16_t universe)
Indicate that a new synchronization packet should be sent on the given synchronization universe.
Definition source.h:667
std::vector< etcpal::IpAddr > GetUnicastDestinations(uint16_t universe)
Obtain a vector of a universe's unicast destinations.
Definition source.h:531
etcpal::Error AddUnicastDestination(uint16_t universe, const etcpal::IpAddr &dest)
Add a unicast destination for a universe.
Definition source.h:506
etcpal::Error SendNow(uint16_t universe, uint8_t start_code, const uint8_t *buffer, size_t buflen)
Immediately sends the provided sACN start code & data.
Definition source.h:647
constexpr Handle handle() const
Get the current handle to the underlying C source.
Definition source.h:969
void RemoveUnicastDestination(uint16_t universe, const etcpal::IpAddr &dest)
Remove a unicast destination on a universe.
Definition source.h:520
std::vector< uint16_t > GetUniverses()
Obtain a vector of this source's universes (sorted lowest to highest).
Definition source.h:473
std::vector< EtcPalMcastNetintId > GetNetworkInterfaces(uint16_t universe)
Obtain a vector of a universe's network interfaces.
Definition source.h:946
void Shutdown()
Destroy an sACN source instance.
Definition source.h:347
etcpal::Error ChangePreviewFlag(uint16_t universe, bool new_preview_flag)
Change the send_preview option on a universe.
Definition source.h:599
void UpdateLevels(uint16_t universe, const uint8_t *new_levels, size_t new_levels_size)
Copies the universe's DMX levels into the packet to be sent on the next threaded or manual update.
Definition source.h:685
void UpdateLevelsAndForceSync(uint16_t universe, const uint8_t *new_levels, size_t new_levels_size)
Like UpdateLevels(), but also sets the force_sync flag on the packet.
Definition source.h:738
void UpdateLevelsAndPap(uint16_t universe, const uint8_t *new_levels, size_t new_levels_size, const uint8_t *new_priorities, size_t new_priorities_size)
Copies the universe's DMX levels and per-address priorities into packets that are sent on the next th...
Definition source.h:712
etcpal::Error ChangePriority(uint16_t universe, uint8_t new_priority)
Change the priority of a universe.
Definition source.h:576
TickMode
This enum determines the type of start code (levels and/or PAP) to process/transmit in a source tick.
Definition source.h:68
@ kProcessLevelsAndPap
Process/send everything (both levels and PAP + termination).
@ kProcessPapOnly
Process/send PAP only (excludes termination).
@ kProcessLevelsOnly
Process/send levels only (includes termination).
C++ wrapper for the sACN init/deinit functions.
sacn_ip_support_t
This enum defines how the API module will use IPv4 and IPv6 networking.
Definition common.h:75
#define SACN_SEND_SOCKET_CONFIG_DEFAULT_INIT
Initializes the members of a SacnSendSocketConfig to defaults.
Definition common.h:182
#define SACN_NETINT_CONFIG_DEFAULT_INIT
Initializes the members of a SacnNetintConfig to defaults.
Definition common.h:187
@ kSacnIpV4AndIpV6
Use both IPv4 and IPv6.
Definition common.h:81
etcpal_error_t sacn_source_change_name(sacn_source_t handle, const char *new_name)
Change the name of an sACN source.
Definition source.c:172
etcpal_error_t sacn_source_send_synchronization(sacn_source_t handle, uint16_t universe)
Indicate that a new synchronization packet should be sent on the given synchronization universe.
Definition source.c:800
etcpal_error_t sacn_source_change_priority(sacn_source_t handle, uint16_t universe, uint8_t new_priority)
Change the priority of a universe on a sACN source.
Definition source.c:561
size_t sacn_source_get_unicast_destinations(sacn_source_t handle, uint16_t universe, EtcPalIpAddr *destinations, size_t destinations_size)
Obtain a list of a universe's unicast destinations.
Definition source.c:521
etcpal_error_t sacn_source_add_universe(sacn_source_t handle, const SacnSourceUniverseConfig *config, const SacnNetintConfig *netint_config)
Add a universe to an sACN source.
Definition source.c:265
void sacn_source_update_levels(sacn_source_t handle, uint16_t universe, const uint8_t *new_levels, size_t new_levels_size)
Copies the universe's DMX levels into the packet to be sent on the next threaded or manual update.
Definition source.c:824
etcpal_error_t sacn_source_add_unicast_destination(sacn_source_t handle, uint16_t universe, const EtcPalIpAddr *dest)
Add a unicast destination for a source's universe.
Definition source.c:411
etcpal_error_t sacn_source_reset_networking(const SacnNetintConfig *sys_netint_config)
Resets the underlying network sockets for all universes of all sources.
Definition source.c:1051
etcpal_error_t sacn_source_create(const SacnSourceConfig *config, sacn_source_t *handle)
Create a new sACN source to send sACN data.
Definition source.c:106
void sacn_source_remove_unicast_destination(sacn_source_t handle, uint16_t universe, const EtcPalIpAddr *dest)
Remove a unicast destination on a source's universe.
Definition source.c:486
void sacn_source_update_levels_and_force_sync(sacn_source_t handle, uint16_t universe, const uint8_t *new_levels, size_t new_levels_size)
Like sacn_source_update_levels(), but also sets the force_sync flag on the packet.
Definition source.c:920
void sacn_source_update_levels_and_pap(sacn_source_t handle, uint16_t universe, const uint8_t *new_levels, size_t new_levels_size, const uint8_t *new_priorities, size_t new_priorities_size)
Copies the universe's DMX levels and per-address priorities into packets that are sent on the next th...
Definition source.c:874
etcpal_error_t sacn_source_send_now(sacn_source_t handle, uint16_t universe, uint8_t start_code, const uint8_t *buffer, size_t buflen)
Immediately sends the provided sACN start code & data.
Definition source.c:716
void sacn_source_remove_universe(sacn_source_t handle, uint16_t universe)
Remove a universe from a source.
Definition source.c:354
size_t sacn_source_get_universes(sacn_source_t handle, uint16_t *universes, size_t universes_size)
Obtain a list of a source's universes (sorted lowest to highest).
Definition source.c:378
etcpal_error_t sacn_source_change_preview_flag(sacn_source_t handle, uint16_t universe, bool new_preview_flag)
Change the send_preview option on a universe of a sACN source.
Definition source.c:622
int sacn_source_process_manual(sacn_source_tick_mode_t tick_mode)
Trigger the transmission of sACN packets for all universes of sources that were created with manually...
Definition source.c:1021
sacn_source_tick_mode_t
This enum determines the type of start code (levels and/or PAP) to process/transmit in a source tick.
Definition source.h:77
void sacn_source_update_levels_and_pap_and_force_sync(sacn_source_t handle, uint16_t universe, const uint8_t *new_levels, size_t new_levels_size, const uint8_t *new_priorities, size_t new_priorities_size)
Like sacn_source_update_levels_and_pap(), but also sets the force_sync flag on the packet.
Definition source.c:975
etcpal_error_t sacn_source_change_synchronization_universe(sacn_source_t handle, uint16_t universe, uint16_t new_sync_universe)
Changes the synchronization universe for a universe of a sACN source.
Definition source.c:684
etcpal_error_t sacn_source_reset_networking_per_universe(const SacnNetintConfig *sys_netint_config, const SacnSourceUniverseNetintList *per_universe_netint_lists, size_t num_per_universe_netint_lists)
Resets the underlying network sockets and determines network interfaces for each universe of each sou...
Definition source.c:1122
int sacn_source_t
A handle to a sACN source.
Definition source.h:56
static const sacn_source_t kSacnSourceInvalid
An invalid sACN source handle value.
Definition source.h:58
size_t sacn_source_get_network_interfaces(sacn_source_t handle, uint16_t universe, EtcPalMcastNetintId *netints, size_t netints_size)
Obtain a list of a universe's network interfaces.
Definition source.c:1230
void sacn_source_destroy(sacn_source_t handle)
Destroy an sACN source instance.
Definition source.c:222
@ kSacnSourceTickModeProcessLevelsAndPap
Process/send everything (both levels and PAP + termination).
Definition source.h:83
@ kSacnSourceTickModeProcessPapOnly
Process/send PAP only (excludes termination).
Definition source.h:81
@ kSacnSourceTickModeProcessLevelsOnly
Process/send levels only (includes termination).
Definition source.h:79
@ kSacnSourceKeepAliveIntervalDefault
The default NULL start code keep-alive interval for sources, in milliseconds.
Definition source.h:70
@ kSacnSourcePapKeepAliveIntervalDefault
The default per-address priority keep-alive interval for sources, in milliseconds.
Definition source.h:72
@ kSacnSourceInfiniteUniverses
Constant for "infinite" when sending sACN universes.
Definition source.h:68
A namespace which contains all C++ language definitions in the sACN library.
Definition common.h:50
constexpr uint16_t kMinimumUniverse
The lowest sACN universe number supported.
Definition common.h:64
McastMode
Determines whether multicast traffic is allowed through all interfaces or none.
Definition common.h:53
constexpr uint16_t kMaximumUniverse
The highest sACN universe number supported.
Definition common.h:66
sACN Source API definitions
Network interface configuration information to give the sACN library.
Definition common.h:114
SacnMcastInterface * netints
An array of network interface IDs to which to restrict multicast traffic.
Definition common.h:117
size_t num_netints
Size of netints array.
Definition common.h:119
bool no_netints
If this is true, no network interfaces will be used for multicast.
Definition common.h:122
SacnSendSocketConfig send_socket_config
Configuration for send sockets (e.g.
Definition common.h:126
Configuration for send sockets (e.g.
Definition common.h:103
A set of configuration information for a sACN source.
Definition source.h:88
EtcPalUuid cid
The source's CID.
Definition source.h:92
A set of configuration information for a sACN universe.
Definition source.h:135
const EtcPalIpAddr * unicast_destinations
The initial set of unicast destinations for this universe.
Definition source.h:156
size_t num_unicast_destinations
The size of unicast_destinations.
Definition source.h:158
A set of configuration settings that a source needs to initialize.
Definition source.h:82
size_t universe_count_max
The maximum number of universes this source will send to when using dynamic memory.
Definition source.h:93
bool IsValid() const
Determine whether a Source Settings instance contains valid data for sACN operation.
Definition source.h:268
etcpal::Uuid cid
The source's CID.
Definition source.h:86
int keep_alive_interval
The interval at which the source will send NULL start code keep-alive packets during transmission sup...
Definition source.h:105
std::string name
The source's name, a UTF-8 encoded string.
Definition source.h:88
sacn_ip_support_t ip_supported
What IP networking the source will support.
Definition source.h:101
bool manually_process_source
If false (default), this source will be added to a background thread that will send sACN updates at a...
Definition source.h:98
Settings()=default
Create an empty, invalid data structure by default.
int pap_keep_alive_interval
The interval at which the source will send per-address priority keep-alive packets during transmissio...
Definition source.h:109
A set of network interfaces for a particular universe.
Definition source.h:162
uint16_t universe
The ID of the universe.
Definition source.h:166
bool no_netints
If this is true, this universe will not use any network interfaces for multicast traffic.
Definition source.h:173
sacn_source_t handle
The source's handle.
Definition source.h:164
std::vector< SacnMcastInterface > netints
If !empty, this is the list of interfaces the application wants to use, and the status codes are fill...
Definition source.h:170
UniverseNetintList()=default
Create an empty, invalid data structure by default.
A set of configuration settings for a new universe on a source.
Definition source.h:123
bool send_unicast_only
If true, this sACN source will only send unicast traffic on this universe.
Definition source.h:140
bool send_preview
If true, this sACN source will send preview data.
Definition source.h:137
bool IsValid() const
Determine whether a Universe Settings instance contains valid data for sACN operation.
Definition source.h:285
uint16_t universe
The universe number.
Definition source.h:128
uint8_t priority
The sACN universe priority that is sent in each packet.
Definition source.h:134
UniverseSettings()=default
Create an empty, invalid data structure by default.
std::vector< etcpal::IpAddr > unicast_destinations
The initial set of unicast destinations for this universe.
Definition source.h:144
uint16_t sync_universe
If non-zero, this is the synchronization universe used to synchronize the sACN output.
Definition source.h:148