View Source ExLibSRT.Server (ExLibSRT v0.1.3)

Implementation of the SRT server.

API

The client API consinsts of the following functions:

Password Authentication

SRT supports password-based authentication. When using password authentication:

  • Password must be between 10 and 79 characters long (SRT specification requirement)
  • Empty string means no password authentication (default behavior)
  • All connecting clients must provide the same password

A process starting the server will also receive the following notifications:

Accepting connections

Each SRT connection can carry a streamid string which can be used for identifying the stream.

To support accepting/rejecting the connection a server sends srt_server_connect_request/0 event. THe process that started the server is then obliged to either call accept_awaiting_connect_request/1 or reject_awaiting_connect_request/1. Not responding in time will result in server's rejecting the connection.

When user rejects the stream, the server respons with 1403 rejection code (SRT wise). While not being to accept in time results in 1504 (not that the codes respectively are the same of HTTP 403 forbidden and 504 gateway timeout).

Response timeout

It is very important to answer the connection request as fast as possible. Due to how libsrt works, while the server waits for the response it blocks the receiving thread and potentially interrupts other ongoing connections.

Summary

Functions

Acccepts the currently awaiting connection request.

Acccepts the currently awaiting connection request and starts a separate connection process

Returns a specification to start this module under a supervisor.

Closes the connection to the given client.

Reads socket statistics.

Rejects the currently awaiting connection request.

Starts a new SRT server outside the supervision tree, binding to given address and port.

Starts a new SRT server binding to given address and port and links to current process.

Stops the server.

Types

@type connection_id() :: non_neg_integer()
@type srt_data() :: {:srt_data, connection_id(), data :: binary()}
@type srt_server_conn() ::
  {:srt_server_conn, connection_id(), stream_id :: String.t()}
Link to this type

srt_server_conn_closed()

View Source
@type srt_server_conn_closed() :: {:srt_server_conn_closed, connection_id()}
Link to this type

srt_server_connect_request()

View Source
@type srt_server_connect_request() ::
  {:srt_server_connect_request, address :: String.t(), stream_id :: String.t()}
@type srt_server_error() :: {:srt_server_error, connection_id(), error :: String.t()}
@type t() :: pid()

Functions

Link to this function

accept_awaiting_connect_request(agent)

View Source
@spec accept_awaiting_connect_request(t()) :: :ok | {:error, reason :: String.t()}

Acccepts the currently awaiting connection request.

Link to this function

accept_awaiting_connect_request_with_handler(handler, agent)

View Source
@spec accept_awaiting_connect_request_with_handler(
  ExLibSRT.Connection.Handler.t(),
  t()
) ::
  {:ok, ExLibSRT.Connection.t()} | {:error, reason :: any()}

Acccepts the currently awaiting connection request and starts a separate connection process

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

close_server_connection(connection_id, agent)

View Source
@spec close_server_connection(connection_id(), t()) ::
  :ok | {:error, reason :: String.t()}

Closes the connection to the given client.

Link to this function

read_socket_stats(connection_id, agent)

View Source
@spec read_socket_stats(connection_id(), t()) ::
  {:ok, ExLibSRT.SocketStats.t()} | {:error, reason :: String.t()}

Reads socket statistics.

Link to this function

reject_awaiting_connect_request(agent)

View Source
@spec reject_awaiting_connect_request(t()) :: :ok | {:error, reason :: String.t()}

Rejects the currently awaiting connection request.

Link to this function

start(address, port, password \\ "")

View Source
@spec start(address :: String.t(), port :: non_neg_integer(), password :: String.t()) ::
  {:ok, t()} | {:error, reason :: String.t(), error_code :: integer()}

Starts a new SRT server outside the supervision tree, binding to given address and port.

One may usually want to bind to 0.0.0.0 address.

Password Requirements

If a password is provided, it must be between 10 and 79 characters long according to SRT specification. An empty string means no password authentication will be used.

Link to this function

start_link(address, port, password \\ "")

View Source
@spec start_link(
  address :: String.t(),
  port :: non_neg_integer(),
  password :: String.t()
) ::
  {:ok, t()} | {:error, reason :: String.t(), error_code :: integer()}

Starts a new SRT server binding to given address and port and links to current process.

One may usually want to bind to 0.0.0.0 address.

Password Requirements

If a password is provided, it must be between 10 and 79 characters long according to SRT specification. An empty string means no password authentication will be used.

@spec stop(t()) :: :ok

Stops the server.

Stopping a server should gracefuly close all the client connections.