Jetson Inference
DNN Vision Library
|
TCP/UDP sockets and IP address manipulation. More...
Classes | |
struct | NetworkInterface |
Info about a particular network interface. More... | |
class | RTSPServer |
RTSP server for transmitting encoded GStreamer pipelines to client devices. More... | |
class | Socket |
The Socket class provides TCP or UDP ethernet networking. More... | |
struct | WebRTCPeer |
Remote peer that has connected. More... | |
class | WebRTCServer |
WebRTC signalling server for establishing and negotiating connections with peers for bi-directional media streaming. More... | |
Macros | |
#define | INET4_ADDRLEN 4 |
The size in bytes of an IPv4 address (4 bytes) This is meant to compliment POSIX's INET4_ADDRSTRLEN (16) More... | |
#define | INET6_ADDRLEN 16 |
The size in bytes of an IPv6 address (16 bytes) This is meant to compliment POSIX's INET6_ADDRSTRLEN (46) More... | |
#define | LOG_NETWORK "[network] " |
LOG_NETWORK logging string. More... | |
#define | RTSP_DEFAULT_PORT 8554 |
Default port used by RTSP server. More... | |
#define | LOG_RTSP "[rtsp] " |
RTSP logging prefix. More... | |
#define | WEBRTC_DEFAULT_PORT 41567 |
Default HTTP/websocket port used by the WebRTC server. More... | |
#define | WEBRTC_DEFAULT_STUN_SERVER "stun.l.google.com:19302" |
Default STUN server used for WebRTC. More... | |
#define | LOG_WEBRTC "[webrtc] " |
WebRTC logging prefix. More... | |
Enumerations | |
enum | SocketType { SOCKET_UDP = 0, SOCKET_TCP = 1 } |
TCP/UDP enumeration. More... | |
enum | WebRTCFlags { WEBRTC_PRIVATE = 0, WEBRTC_PUBLIC = (1 << 1), WEBRTC_AUDIO = (1 << 0), WEBRTC_VIDEO = (1 << 1), WEBRTC_SEND = (1 << 2), WEBRTC_RECEIVE = (1 << 3), WEBRTC_MULTI_CLIENT = (1 << 4), WEBRTC_PEER_CONNECTING = (1 << 5), WEBRTC_PEER_CONNECTED = (1 << 6), WEBRTC_PEER_STREAMING = (1 << 7), WEBRTC_PEER_CLOSED = (1 << 8) } |
Flags for route decorators or peer state. More... | |
Functions | |
bool | IPv4AddressFromStr (const char *str, uint32_t *ipAddress) |
Convert an IPv4 address string in "xxx.xxx.xxx.xxx" format to binary representation. More... | |
std::string | IPv4AddressToStr (uint32_t ipAddress) |
Return text string of IPv4 address in "xxx.xxx.xxx.xxx" format. More... | |
bool | IPv6AddressFromStr (const char *str, void *ipAddress) |
Convert an IPv6 address string in "x:x:x:x:x:x:x:x" hexadecimal format to 128-bit binary representation. More... | |
std::string | IPv6AddressToStr (void *ipAddress) |
Return text string of IPv6 address in "x:x:x:x:x:x:x:x" hexadecimal format. More... | |
std::string | getHostname () |
Retrieve the host system's network hostname. More... | |
std::string | getHostByName (const char *name, uint32_t retries=10) |
Resolve the IP address of a given hostname or domain using DNS lookup, and return it as a string. More... | |
uint32_t | getHostByName (const char *name, void *ipAddress, uint32_t size, uint32_t retries=10) |
Resolve the IP address of a given hostname or domain using DNS lookup. More... | |
std::vector< NetworkInterface > | getNetworkInterfaces () |
Retrieve info about the different IPv4/IPv6 network interfaces of the system. More... | |
void | printNetworkInterfaces (const std::vector< NetworkInterface > &interfaces) |
Print out a list of network interfaces. More... | |
TCP/UDP sockets and IP address manipulation.
struct NetworkInterface |
Info about a particular network interface.
The IPv6 information will be filled out if it's enabled on the interface.
Public Attributes | |
std::string | name |
name of the network interface (e.g. More... | |
bool | up |
true if the interface is up, false if down More... | |
struct NetworkInterface::IPv4 | ipv4 |
struct NetworkInterface::IPv6 | ipv6 |
struct NetworkInterface::IPv4 NetworkInterface::ipv4 |
struct NetworkInterface::IPv6 NetworkInterface::ipv6 |
std::string NetworkInterface::name |
name of the network interface (e.g.
eth0, wlan0, lo)
bool NetworkInterface::up |
true if the interface is up, false if down
class RTSPServer |
RTSP server for transmitting encoded GStreamer pipelines to client devices.
This is integrated into videoOutput/gstEncoder, but can be used standalone (
Public Member Functions | |
void | Release () |
Release a reference to the server instance. More... | |
bool | AddRoute (const char *path, _GstElement *pipeline) |
Register a GStreamer pipeline to be served at the specified path. More... | |
bool | AddRoute (const char *path, const char *pipeline) |
Create a GStreamer pipeline and register it to be served at the specified path. More... | |
Static Public Member Functions | |
static RTSPServer * | Create (uint16_t port=RTSP_DEFAULT_PORT) |
Create a RTSP server on this port. More... | |
Protected Member Functions | |
RTSPServer (uint16_t port) | |
~RTSPServer () | |
bool | init () |
Static Protected Member Functions | |
static void * | runThread (void *user_data) |
Protected Attributes | |
uint16_t | mPort |
uint32_t | mRefCount |
Thread * | mThread |
bool | mRunning |
_GMainLoop * | mMainLoop |
_GstRTSPServer * | mServer |
|
protected |
|
protected |
bool RTSPServer::AddRoute | ( | const char * | path, |
_GstElement * | pipeline | ||
) |
Register a GStreamer pipeline to be served at the specified path.
It will be able to be viewed from clients at rtsp://hostname:port/path
bool RTSPServer::AddRoute | ( | const char * | path, |
const char * | pipeline | ||
) |
Create a GStreamer pipeline and register it to be served at the specified path.
It will be able to be viewed from clients at rtsp://hostname:port/path
|
static |
Create a RTSP server on this port.
If this port is already in use, the existing server instance will be returned.
|
protected |
void RTSPServer::Release | ( | ) |
Release a reference to the server instance.
Server will be shut down when the reference count reaches zero.
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
class Socket |
The Socket class provides TCP or UDP ethernet networking.
To exchange data with a remote IP on the network using UDP, follow these steps:
1. Create a Socket instance with the static Create() function.
Public Member Functions | |
~Socket () | |
Destructor. More... | |
bool | Accept (uint64_t timeout=0) |
Accept incoming connections (TCP only). More... | |
bool | Bind (const char *localIP, uint16_t port) |
Bind the socket to a local host IP address and port. More... | |
bool | Bind (uint32_t localIP, uint16_t port) |
Bind the socket to a local host IP address and port. More... | |
bool | Bind (uint16_t port=0) |
Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY). More... | |
bool | Connect (const char *remoteIP, uint16_t port) |
Connect to a listening server (TCP only). More... | |
bool | Connect (uint32_t remoteIP, uint16_t port) |
Connect to a listening server (TCP only). More... | |
size_t | Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP=NULL, uint16_t *remotePort=NULL) |
Wait for a packet to be recieved and dump it into the user-supplied buffer. More... | |
size_t | Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP, uint16_t *remotePort, uint32_t *localIP) |
Recieve packet, with additional address info. More... | |
bool | Send (void *buffer, size_t size, uint32_t remoteIP, uint16_t remotePort) |
Send message to remote host. More... | |
bool | SetRecieveTimeout (uint64_t timeout) |
Set Receive() timeout (in microseconds). More... | |
bool | SetBufferSize (size_t size) |
Set the rx/tx buffer sizes. More... | |
bool | EnableJumboBuffer () |
Enable jumbo buffer. More... | |
int | GetFD () const |
Retrieve the socket's file descriptor. More... | |
SocketType | GetType () const |
GetType. More... | |
void | PrintIP () const |
PrintIP. More... | |
size_t | GetMTU () |
Retrieve the MTU (in bytes). More... | |
Static Public Member Functions | |
static Socket * | Create (SocketType type) |
Create. More... | |
Socket::~Socket | ( | ) |
Destructor.
bool Socket::Accept | ( | uint64_t | timeout = 0 | ) |
Accept incoming connections (TCP only).
timeout | The timeout (in microseconds) to wait for incoming connections before returning. |
bool Socket::Bind | ( | const char * | localIP, |
uint16_t | port | ||
) |
Bind the socket to a local host IP address and port.
ipAddress | IPv4 address in string format "xxx.xxx.xxx.xxx" |
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
bool Socket::Bind | ( | uint16_t | port = 0 | ) |
Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY).
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
bool Socket::Bind | ( | uint32_t | localIP, |
uint16_t | port | ||
) |
Bind the socket to a local host IP address and port.
hostIP | IPv4 address, in network byte order. If htonl(INADDR_ANY) is specified for the ipAddress, the socket will be bound to all available interfaces. |
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
bool Socket::Connect | ( | const char * | remoteIP, |
uint16_t | port | ||
) |
Connect to a listening server (TCP only).
remoteIP | IP address of the remote host. |
bool Socket::Connect | ( | uint32_t | remoteIP, |
uint16_t | port | ||
) |
Connect to a listening server (TCP only).
remoteIP | IP address of the remote host. |
|
static |
Create.
bool Socket::EnableJumboBuffer | ( | ) |
Enable jumbo buffer.
|
inline |
Retrieve the socket's file descriptor.
size_t Socket::GetMTU | ( | ) |
Retrieve the MTU (in bytes).
Returns 0 on error.
|
inline |
GetType.
void Socket::PrintIP | ( | ) | const |
PrintIP.
size_t Socket::Recieve | ( | uint8_t * | buffer, |
size_t | size, | ||
uint32_t * | remoteIP, | ||
uint16_t * | remotePort, | ||
uint32_t * | localIP | ||
) |
Recieve packet, with additional address info.
In addition to returning the IP and port of the remote host which sent the packet, this function can also return the local IP and port which the packet was sent to.
size_t Socket::Recieve | ( | uint8_t * | buffer, |
size_t | size, | ||
uint32_t * | remoteIP = NULL , |
||
uint16_t * | remotePort = NULL |
||
) |
Wait for a packet to be recieved and dump it into the user-supplied buffer.
Optionally return the IP address and port of the remote host which sent the packet.
buffer | user-allocated destination for the packet |
size | size of the buffer (in bytes) |
remoteIpAddress | optional output, the IPv4 address of where the packet originated (in network byte order). |
remotePort | optional output, the port from where the packet originated (in host byte order). |
bool Socket::Send | ( | void * | buffer, |
size_t | size, | ||
uint32_t | remoteIP, | ||
uint16_t | remotePort | ||
) |
Send message to remote host.
bool Socket::SetBufferSize | ( | size_t | size | ) |
Set the rx/tx buffer sizes.
bool Socket::SetRecieveTimeout | ( | uint64_t | timeout | ) |
Set Receive() timeout (in microseconds).
struct WebRTCPeer |
Remote peer that has connected.
Public Attributes | |
SoupWebsocketConnection * | connection |
SoupClientContext * | client_context |
WebRTCServer * | server |
uint32_t | ID |
uint32_t | flags |
std::string | path |
std::string | ip_address |
void * | user_data |
SoupClientContext* WebRTCPeer::client_context |
SoupWebsocketConnection* WebRTCPeer::connection |
uint32_t WebRTCPeer::flags |
uint32_t WebRTCPeer::ID |
std::string WebRTCPeer::ip_address |
std::string WebRTCPeer::path |
WebRTCServer* WebRTCPeer::server |
void* WebRTCPeer::user_data |
class WebRTCServer |
WebRTC signalling server for establishing and negotiating connections with peers for bi-directional media streaming.
Users can bind routing functions that configure their pipelines dynamically to handle incoming/outgoing streams.
It uses websockets to handle the communication with clients for SDP offers, ICE messages, ect.
By default it also serves simple HTML for viewing video streams in browsers, but for full hosting you'll want to run this alongside an actual webserver.
multi-stream :: multi-client :: full-duplex
Public Types | |
typedef void(* | WebsocketListener) (WebRTCPeer *peer, const char *message, size_t message_size, void *user_data) |
Function pointer to a callback for handling websocket requests. More... | |
typedef SoupServerCallback | HttpListener |
Function pointer to a callback for handling HTTP requests. More... | |
Public Member Functions | |
void | Release () |
Release a reference to the server instance. More... | |
void | AddRoute (const char *path, HttpListener callback, void *user_data=NULL, uint32_t flags=0) |
Register a function to handle incoming http/www requests at the specified path. More... | |
void | AddRoute (const char *path, WebsocketListener callback, void *user_data=NULL, uint32_t flags=0) |
Register a function to handle incoming Websocket requests at the specified path. More... | |
const char * | GetSTUNServer () const |
Get the STUN server being used. More... | |
bool | HasHTTPS () const |
Return true if the server is using HTTPS. More... | |
bool | IsThreaded () const |
Return true if the server is running in it's own thread. More... | |
bool | ProcessRequests (bool blocking=false) |
Process incoming requests on the server. More... | |
Static Public Member Functions | |
static WebRTCServer * | Create (uint16_t port=WEBRTC_DEFAULT_PORT, const char *stun_server=WEBRTC_DEFAULT_STUN_SERVER, const char *ssl_cert=NULL, const char *ssl_key=NULL, bool threaded=true) |
Create a WebRTC server on this port. More... | |
Protected Member Functions | |
WebRTCServer (uint16_t port, const char *stun_server, const char *ssl_cert_file, const char *ssl_key_file, bool threaded) | |
~WebRTCServer () | |
bool | init () |
HttpRoute * | findHttpRoute (const char *path) const |
WebsocketRoute * | findWebsocketRoute (const char *path) const |
void | freeRoute (HttpRoute *route) |
void | freeRoute (WebsocketRoute *route) |
std::string | printRouteInfo (WebsocketRoute *route) const |
Static Protected Member Functions | |
static void * | runThread (void *user_data) |
static void | onHttpRequest (SoupServer *soup_server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *client_context, void *user_data) |
static void | onHttpDefault (SoupServer *soup_server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *client_context, void *user_data) |
static void | onWebsocketOpened (SoupServer *server, SoupWebsocketConnection *connection, const char *path, SoupClientContext *client_context, void *user_data) |
static void | onWebsocketMessage (SoupWebsocketConnection *connection, SoupWebsocketDataType data_type, GBytes *message, void *user_data) |
static void | onWebsocketClosed (SoupWebsocketConnection *connection, void *user_data) |
Protected Attributes | |
std::vector< HttpRoute * > | mHttpRoutes |
std::vector< WebsocketRoute * > | mWebsocketRoutes |
SoupServer * | mSoupServer |
std::string | mStunServer |
std::string | mSSLCertFile |
std::string | mSSLKeyFile |
bool | mHasHTTPS |
uint16_t | mPort |
uint32_t | mRefCount |
uint32_t | mPeerCount |
Thread * | mThread |
typedef SoupServerCallback WebRTCServer::HttpListener |
Function pointer to a callback for handling HTTP requests.
typedef void(* WebRTCServer::WebsocketListener) (WebRTCPeer *peer, const char *message, size_t message_size, void *user_data) |
Function pointer to a callback for handling websocket requests.
|
protected |
|
protected |
void WebRTCServer::AddRoute | ( | const char * | path, |
HttpListener | callback, | ||
void * | user_data = NULL , |
||
uint32_t | flags = 0 |
||
) |
Register a function to handle incoming http/www requests at the specified path.
These are for serving webpages, and should be on different paths than the websockets. If the path is "/" the callback will handle all routes. If the route for this path already exists, it will replace the existing route. To remove a route, set the callback to NULL.
void WebRTCServer::AddRoute | ( | const char * | path, |
WebsocketListener | callback, | ||
void * | user_data = NULL , |
||
uint32_t | flags = 0 |
||
) |
Register a function to handle incoming Websocket requests at the specified path.
This path often represents a media stream that can be sent/recieved, or a function for dynamically configuring streams when new clients connect.
If the path is "/" the callback will handle all routes. If the route for this path already exists, it will replace the existing route. To remove a route, set the callback to NULL.
The optional flags are WebRTCFlags OR'd together and are used for describing the stream capabilities for purposes of discovery.
|
static |
Create a WebRTC server on this port.
If this port is already in use, the existing server instance will be returned.
|
protected |
|
protected |
|
protected |
|
protected |
|
inline |
Get the STUN server being used.
STUN servers are used during ICE/NAT and allow a local device to determine its public IP address.
|
inline |
Return true if the server is using HTTPS.
For HTTPS to be enabled, SSL cert/key files must have been provided to WebRTCServer::Create().
|
protected |
|
inline |
Return true if the server is running in it's own thread.
Otherwise, ProcessRequests() must be called periodically.
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
bool WebRTCServer::ProcessRequests | ( | bool | blocking = false | ) |
Process incoming requests on the server.
If set to blocking, the function can wait indefinitely for requests. This should only be called externally if the server was created with threaded=false
void WebRTCServer::Release | ( | ) |
Release a reference to the server instance.
Server will be shut down when the reference count reaches zero.
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
#define INET4_ADDRLEN 4 |
The size in bytes of an IPv4 address (4 bytes) This is meant to compliment POSIX's INET4_ADDRSTRLEN (16)
#define INET6_ADDRLEN 16 |
The size in bytes of an IPv6 address (16 bytes) This is meant to compliment POSIX's INET6_ADDRSTRLEN (46)
#define LOG_NETWORK "[network] " |
LOG_NETWORK logging string.
#define LOG_RTSP "[rtsp] " |
RTSP logging prefix.
#define LOG_WEBRTC "[webrtc] " |
WebRTC logging prefix.
#define RTSP_DEFAULT_PORT 8554 |
Default port used by RTSP server.
#define WEBRTC_DEFAULT_PORT 41567 |
Default HTTP/websocket port used by the WebRTC server.
#define WEBRTC_DEFAULT_STUN_SERVER "stun.l.google.com:19302" |
Default STUN server used for WebRTC.
STUN servers are used during ICE/NAT and allow a local device to determine its public IP address.
enum SocketType |
enum WebRTCFlags |
std::string getHostByName | ( | const char * | name, |
uint32_t | retries = 10 |
||
) |
Resolve the IP address of a given hostname or domain using DNS lookup, and return it as a string.
This uses the system function gethostbyname() and supports both IPv6/IPv6 addresses.
name | the hostname to lookup. |
retries | the number of times to retry the lookup should it fail. |
uint32_t getHostByName | ( | const char * | name, |
void * | ipAddress, | ||
uint32_t | size, | ||
uint32_t | retries = 10 |
||
) |
Resolve the IP address of a given hostname or domain using DNS lookup.
This uses the system function gethostbyname() and supports both IPv6/IPv6 addresses.
name | the hostname or domain name to lookup. |
ipAddress | output pointer to buffer that the IPv4 or IPv6 address will be written to. this buffer should be up to 16 bytes long for supporting IPv6 addresses, or 4 bytes long for only supporting IPv4 addresses. |
size | the size of the ipAddress buffer (4 bytes for IPv6 or 16 bytes for IPv6) |
retries | the number of times to retry the lookup should it fail. |
std::string getHostname | ( | ) |
Retrieve the host system's network hostname.
std::vector<NetworkInterface> getNetworkInterfaces | ( | ) |
Retrieve info about the different IPv4/IPv6 network interfaces of the system.
Internally this uses the system function getifaddrs()
bool IPv4AddressFromStr | ( | const char * | str, |
uint32_t * | ipAddress | ||
) |
Convert an IPv4 address string in "xxx.xxx.xxx.xxx" format to binary representation.
str | the IPv4 string, in "xxx.xxx.xxx.xxx" format |
ipAddress | output pointer to converted IPv4 address, in network byte order. |
std::string IPv4AddressToStr | ( | uint32_t | ipAddress | ) |
Return text string of IPv4 address in "xxx.xxx.xxx.xxx" format.
ipAddress | IPv4 address, supplied in network byte order. |
bool IPv6AddressFromStr | ( | const char * | str, |
void * | ipAddress | ||
) |
Convert an IPv6 address string in "x:x:x:x:x:x:x:x" hexadecimal format to 128-bit binary representation.
str | the IPv6 string, in "x:x:x:x:x:x:x:x" hexadecimal format |
ipAddress | output pointer to converted 128-bit IPv6 address (16 bytes long), in network byte order. this buffer can be a variety of representations (commonly uint8[16] or uint16[8]), as long as it's at least 128 bits (16 bytes) long. |
std::string IPv6AddressToStr | ( | void * | ipAddress | ) |
Return text string of IPv6 address in "x:x:x:x:x:x:x:x" hexadecimal format.
ipAddress | pointer to 128-bit IPv6 address (16 bytes long), in network byte order. this buffer can be a variety of representations (commonly uint8[16] or uint16[8]), as long as it's at least 128 bits (16 bytes) long. |
void printNetworkInterfaces | ( | const std::vector< NetworkInterface > & | interfaces | ) |
Print out a list of network interfaces.