Jetson Inference
DNN Vision Library
WebRTCServer Class Reference

WebRTC signalling server for establishing and negotiating connections with peers for bi-directional media streaming. More...

#include <WebRTCServer.h>

Classes

struct  HttpRoute
 
struct  WebsocketRoute
 

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 WebRTCServerCreate (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 ()
 
HttpRoutefindHttpRoute (const char *path) const
 
WebsocketRoutefindWebsocketRoute (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
 
ThreadmThread
 

Detailed Description

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.

See also
https://doc-kurento.readthedocs.io/en/stable/_static/client-javadoc/org/kurento/client/WebRtcEndpoint.html

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

Member Typedef Documentation

◆ HttpListener

typedef SoupServerCallback WebRTCServer::HttpListener

Function pointer to a callback for handling HTTP requests.

See also
https://developer-old.gnome.org/libsoup/stable/SoupServer.html#SoupServerCallback

◆ WebsocketListener

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.

See also
AddConnectionListener

Constructor & Destructor Documentation

◆ WebRTCServer()

WebRTCServer::WebRTCServer ( uint16_t  port,
const char *  stun_server,
const char *  ssl_cert_file,
const char *  ssl_key_file,
bool  threaded 
)
protected

◆ ~WebRTCServer()

WebRTCServer::~WebRTCServer ( )
protected

Member Function Documentation

◆ AddRoute() [1/2]

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.

◆ AddRoute() [2/2]

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.

See also
WebRTCFlags

◆ Create()

static WebRTCServer* 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 
)
static

Create a WebRTC server on this port.

If this port is already in use, the existing server instance will be returned.

◆ findHttpRoute()

HttpRoute* WebRTCServer::findHttpRoute ( const char *  path) const
protected

◆ findWebsocketRoute()

WebsocketRoute* WebRTCServer::findWebsocketRoute ( const char *  path) const
protected

◆ freeRoute() [1/2]

void WebRTCServer::freeRoute ( HttpRoute route)
protected

◆ freeRoute() [2/2]

void WebRTCServer::freeRoute ( WebsocketRoute route)
protected

◆ GetSTUNServer()

const char* WebRTCServer::GetSTUNServer ( ) const
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.

See also
WEBRTC_DEFAULT_STUN_SERVER

◆ HasHTTPS()

bool WebRTCServer::HasHTTPS ( ) const
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().

◆ init()

bool WebRTCServer::init ( )
protected

◆ IsThreaded()

bool WebRTCServer::IsThreaded ( ) const
inline

Return true if the server is running in it's own thread.

Otherwise, ProcessRequests() must be called periodically.

◆ onHttpDefault()

static void WebRTCServer::onHttpDefault ( SoupServer *  soup_server,
SoupMessage *  message,
const char *  path,
GHashTable *  query,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ onHttpRequest()

static void WebRTCServer::onHttpRequest ( SoupServer *  soup_server,
SoupMessage *  message,
const char *  path,
GHashTable *  query,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ onWebsocketClosed()

static void WebRTCServer::onWebsocketClosed ( SoupWebsocketConnection *  connection,
void *  user_data 
)
staticprotected

◆ onWebsocketMessage()

static void WebRTCServer::onWebsocketMessage ( SoupWebsocketConnection *  connection,
SoupWebsocketDataType  data_type,
GBytes *  message,
void *  user_data 
)
staticprotected

◆ onWebsocketOpened()

static void WebRTCServer::onWebsocketOpened ( SoupServer *  server,
SoupWebsocketConnection *  connection,
const char *  path,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ printRouteInfo()

std::string WebRTCServer::printRouteInfo ( WebsocketRoute route) const
protected

◆ ProcessRequests()

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

◆ Release()

void WebRTCServer::Release ( )

Release a reference to the server instance.

Server will be shut down when the reference count reaches zero.

◆ runThread()

static void* WebRTCServer::runThread ( void *  user_data)
staticprotected

Member Data Documentation

◆ mHasHTTPS

bool WebRTCServer::mHasHTTPS
protected

◆ mHttpRoutes

std::vector<HttpRoute*> WebRTCServer::mHttpRoutes
protected

◆ mPeerCount

uint32_t WebRTCServer::mPeerCount
protected

◆ mPort

uint16_t WebRTCServer::mPort
protected

◆ mRefCount

uint32_t WebRTCServer::mRefCount
protected

◆ mSoupServer

SoupServer* WebRTCServer::mSoupServer
protected

◆ mSSLCertFile

std::string WebRTCServer::mSSLCertFile
protected

◆ mSSLKeyFile

std::string WebRTCServer::mSSLKeyFile
protected

◆ mStunServer

std::string WebRTCServer::mStunServer
protected

◆ mThread

Thread* WebRTCServer::mThread
protected

◆ mWebsocketRoutes

std::vector<WebsocketRoute*> WebRTCServer::mWebsocketRoutes
protected

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