Dante Application Library API
Connections.hpp
1 #pragma once
2 
3 #include "audinate/dal/Common.hpp"
4 #include "audinate/dal/ConnectionsConfig.hpp"
5 #include "audinate/dal/DAL.hpp"
6 
7 #include <vector>
8 #include <functional>
9 
10 
11 namespace Audinate { namespace DAL {
12 
13 //------------------------------------------------------
14 // Connection API
15 //------------------------------------------------------
16 
21 {
22 public:
23  LocalDevice() : mNumTxChannels(), mNumRxChannels() {}
24 
25  bool operator==(const LocalDevice & other) const { return mNumTxChannels == other.mNumTxChannels && mNumRxChannels == other.mNumRxChannels; }
26  bool operator!=(const LocalDevice & other) const { return !(operator==(other)); }
27 
28  unsigned int mNumTxChannels;
29  unsigned int mNumRxChannels;
30 };
31 
36 {
37 public:
38  DeviceChannels() : mDeviceName(), mChannelNames(), mIpv4Address(), mIdentifiable(), mSending() {}
39  bool operator==(const DeviceChannels & other) const { return mDeviceName == other.mDeviceName && mChannelNames == other.mChannelNames && mIpv4Address == other.mIpv4Address && mIdentifiable == other.mIdentifiable && mSending == other.mSending; }
40  bool operator!=(const DeviceChannels & other) const { return !(operator==(other)); }
41 
42  std::string mDeviceName;
43  std::vector<std::string> mChannelNames;
44  Ipv4Address mIpv4Address;
45  bool mIdentifiable;
46 
47  // Is the device sending any audio at the moment?
48  bool mSending;
49 };
50 
55 {
56 public:
57  AvailableChannels() : mDevices() {}
58  bool operator==(const AvailableChannels & other) const { return mDevices == other.mDevices; }
59  bool operator!=(const AvailableChannels & other) const { return !(operator==(other)); }
60 
61  std::vector<DeviceChannels> mDevices;
62 };
63 
64 enum class ConnectionStatus
65 {
66  // There is no connection set for the given local channel.
67  None,
68 
69  // The connection API has not yet begun processing the connection
70  Pending,
71 
72  // The requested source device was not found. Only applicable for receive channels
73  Unresolved,
74 
75  // The requested destination device was not found. Only applicable for transmit channels
76  DestinationDeviceNotFound,
77 
78  // The requested destination channel was not found on the destination device. Only applicable for transmit channels
79  DestinationChannelNotFound,
80 
81  // The connection is being made. See the subscription status for more detailed information
82  InProgress,
83 
84  // The connection has been made but no audio packets have been received
85  Inactive,
86 
87  // The connection has been made and audio packets are being received
88  Active,
89 
90  // The connection failed for some reason. See the subscription status for more detailed information
91  Error
92 };
93 
94 std::string toString(ConnectionStatus status);
95 
96 typedef Uint8 SubscriptionStatus;
97 
98 std::string subscriptionStatusToString(uint8_t subscriptionStatus);
99 
104 {
105 public:
106  unsigned int mLocalChannelId;
107  std::string mRemoteChannelName;
108  std::string mRemoteDeviceName;
110  ConnectionStatus mConnectionStatus;
111  SubscriptionStatus mSubscriptionStatus;
112 };
113 
117 typedef std::function<void()> LocalDeviceChangedFn;
118 
124 typedef std::function<void(std::vector<unsigned int> txChannelIds, std::vector<unsigned int> rxChannelIds)> AvailableChannelsChangedFn;
125 
131 typedef std::function<void(ChannelDirection dir, std::vector<unsigned int> channelIds)> ConnectionChangedFn;
132 
134 {
135 protected:
136  Connections() {}
137 
138 public:
139  virtual ~Connections() {}
140 
144  virtual LocalDevice getLocalDevice() = 0;
145 
150  virtual AvailableChannels getAvailableSources(unsigned int rxChannelId) = 0;
151 
156  virtual AvailableChannels getAvailableDestinations(unsigned int txChannelId) = 0;
157 
161  virtual void identify(const std::string & deviceName) = 0;
162 
168  virtual void setReceiveChannelSource(unsigned int rxChannelId, const std::string & remoteChannelName, const std::string & remoteDeviceName) = 0;
169 
174  virtual Connection getReceiveChannelState(unsigned int rxChannelId) = 0;
175 
181  virtual void setTransmitChannelDestination(unsigned int txChannelId, const std::string & remoteChannelName, const std::string & remoteDeviceName) = 0;
182 
187  virtual Connection getTransmitChannelState(unsigned int txChannelId) = 0;
188 
205  virtual void clearRemoteSubscriptionsToLocalDevice() = 0;
206 
210  virtual void setLocalDeviceChangedFn(LocalDeviceChangedFn fn) = 0;
211 
215  virtual void setAvailableChannelsChangedFn(AvailableChannelsChangedFn fn) = 0;
216 
220  virtual void setConnectionChangedFn(ConnectionChangedFn fn) = 0;
221 
222 };
223 
231 std::shared_ptr<Connections> createConnections(std::shared_ptr<DAL> dal, const ConnectionsConfig & config);
232 
233 }; };
Audinate::DAL::Connection::mRemoteChannelName
std::string mRemoteChannelName
Channel name for the remote channel of the subscribed device.
Definition: Connections.hpp:107
Audinate::DAL::LocalDevice
The local device's current settings.
Definition: Connections.hpp:20
Audinate::DAL::Connections::setLocalDeviceChangedFn
virtual void setLocalDeviceChangedFn(LocalDeviceChangedFn fn)=0
Add a handler to be notified when the set of local device changes.
Audinate::DAL::Connection::mSubscriptionStatus
SubscriptionStatus mSubscriptionStatus
Current subscription status of the connection.
Definition: Connections.hpp:111
Audinate::DAL::Connections::clearRemoteSubscriptionsToLocalDevice
virtual void clearRemoteSubscriptionsToLocalDevice()=0
Remove all remote rx channels subscriptions to the local device that are not part of a currently conf...
Audinate::DAL::Connections::setTransmitChannelDestination
virtual void setTransmitChannelDestination(unsigned int txChannelId, const std::string &remoteChannelName, const std::string &remoteDeviceName)=0
Specify a remote channel that will receive audio from the given local transmit channel.
Audinate::DAL::Connections::getAvailableDestinations
virtual AvailableChannels getAvailableDestinations(unsigned int txChannelId)=0
Get the list of available destinations for the given transmit channel.
Audinate::DAL::Connection
Connection class for managing connections between other Dante devices and the DAL device.
Definition: Connections.hpp:103
Audinate::DAL::Connections::getReceiveChannelState
virtual Connection getReceiveChannelState(unsigned int rxChannelId)=0
Get the connection state for the given receive channel.
Audinate::DAL::ConnectionsConfig
Definition: ConnectionsConfig.hpp:7
Audinate::DAL::Connection::mLocalChannelId
unsigned int mLocalChannelId
Channel ID for the local channel of the DAL device.
Definition: Connections.hpp:106
Audinate::DAL::Ipv4Address
Definition: Common.hpp:27
Audinate::DAL::Connection::mConnectionStatus
ConnectionStatus mConnectionStatus
Current status of the connection.
Definition: Connections.hpp:110
Audinate::DAL::Connections::getLocalDevice
virtual LocalDevice getLocalDevice()=0
Get information about the local device.
Audinate::DAL::Connections::setAvailableChannelsChangedFn
virtual void setAvailableChannelsChangedFn(AvailableChannelsChangedFn fn)=0
Add a handler to be notified when the set of available channels changes.
Audinate::DAL::Connections::identify
virtual void identify(const std::string &deviceName)=0
Attempt to identify a given device.
Audinate::DAL::Connections::getTransmitChannelState
virtual Connection getTransmitChannelState(unsigned int txChannelId)=0
Get the connection state for the given transmit channel.
Audinate::DAL::Connections
Definition: Connections.hpp:133
Audinate::DAL::Connection::mRemoteDeviceName
std::string mRemoteDeviceName
Device name for the remote device the channel is subscribed to.
Definition: Connections.hpp:108
Audinate::DAL::DeviceChannels
A device name and list of channel names for that device.
Definition: Connections.hpp:35
Audinate::DAL::Connections::setConnectionChangedFn
virtual void setConnectionChangedFn(ConnectionChangedFn fn)=0
Add a handler to be notified when connection state changes for one or more channels.
Audinate::DAL::AvailableChannels
A list of channels on the network, grouped by device.
Definition: Connections.hpp:54
Audinate::DAL::Connections::setReceiveChannelSource
virtual void setReceiveChannelSource(unsigned int rxChannelId, const std::string &remoteChannelName, const std::string &remoteDeviceName)=0
Specify the remote channel from which the local receive channel will receive audio To clear the confi...
Audinate::DAL::Connections::getAvailableSources
virtual AvailableChannels getAvailableSources(unsigned int rxChannelId)=0
Get the list of available sources for the given receive channel.