ExRTMP.Server (RTMP Server and Client v0.4.1)

View Source

Module describing an RTMP server.

The server listens for incoming RTMP client connections and spawns a new ExRTMP.Server.ClientSession process for each connected client.

Handling Media

When demux is set to true, the server will demux the incoming RTMP streams into audio and video frames before passing them to the handler module.

The format of the data received by the handler is:

  • {:codec, codec_type, init_data} - The codec type and initialization data.
  • {:sample, payload, dts, pts, keyframe?} - A video sample, the payload depends on the codec type. In the case of avc, the payload is a list of NAL units, for other codecs, it is the raw video frame data.
  • {:sample, payload, timestamp} - An audio sample.

If demux is set to false, the handler module will receive the raw RTMP data as is.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets the port number of the server.

Starts a new RTMP server.

Starts and link a new RTMP server.

Stops the server.

Types

start_options()

@type start_options() :: [
  port: :inet.port_number(),
  handler: module(),
  handler_options: any(),
  demux: boolean()
]

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

port(server)

@spec port(GenServer.name()) :: {:ok, port()} | {:error, any()}

Gets the port number of the server.

start(opts)

@spec start(start_options()) :: GenServer.on_start()

Starts a new RTMP server.

Check start_link/1 for available options.

start_link(opts)

@spec start_link(start_options()) :: GenServer.on_start()

Starts and link a new RTMP server.

Options

  • port - The port number where the server should listen. Defaults to: 1935.

  • handler - The module that will handle the RTMP commands and messages. This module must implement the ExRTMP.Server.Handler behaviour. This option is required.

  • handler_options - A keyword list of options that will be passed to the handler module when it is started. This option is optional.

  • demux - Whether the server will demux the incoming RTMP streams into audio and video frames. Defaults to true. See Handling Media below.

stop(server)

@spec stop(GenServer.name()) :: :ok

Stops the server.