RTSP (RTSP v0.4.0)
View SourceSimplify connecting to RTSP servers.
Usage
To start an RTSP session, you can use the start_link/1
function with the required options:
{:ok, session} = RTSP.start_link(stream_uri: "rtsp://localhost:554/stream", allowed_media_types: [:video])
{:ok, tracks} = RTSP.connect(session)
:ok = RTSP.play(session)
The calling process will receive messages with the received media samples.
Message Types
The calling process will receive messages in the following format:
{:rtsp, pid_or_name, :discontinuity}
- Indicates a discontinuity in the stream.{:rtsp, pid_or_name, {control_path, sample_or_samples}}
- Contains the media sample received from the stream.control._path
is the RTSP control path for the track, andsample
is the media sample data.{:rtsp, pid_or_name, :session_closed}
- Indicates that the RTSP session has been closed.
A sample
is a tuple in the format {payload, rtp_timestamp, key_frame?, wallclock_timestamp}
:
payload
- The media payload data (a whole access unit in case ofvideo
).rtp_timestamp
- The RTP timestamp of the sample as nano second starting from 0.key_frame?
- A boolean indicating whether the sample is a key frame (valid forvideo
streams.)wallclock_timestamp
- The wall clock timestamp when the sample was received.
Summary
Functions
Returns a specification to start this module under a supervisor.
Connects the rtsp server./home/ghilas/p/Evercam/ex_nvr/rtsp/lib/rtsp/source.ex
Sends a play request and starts receiving media streams.
Starts a new RTSP client session.
Closes the RTSP session and stops receiving media streams.
Types
@type track() :: %{ control_path: String.t(), type: :video | :audio | :application, fmtp: ExSDP.Attribute.FMTP.t() | nil, rtpmap: ExSDP.Attribute.RTPMapping.t() | nil }
Represents a track in the RTSP session.
Each track corresponds to a media stream and contains the following fields:
control_path
- The RTSP control path for the track, can be used as anid
.type
- The type of the media stream, which can be:video
,:audio
, or:application
.fmtp
- The FMTP attribute for the track, which contains format-specific parameters.rtpmap
- The RTP mapping attribute for the track, which contains information about the payload type and encoding.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Connects the rtsp server./home/ghilas/p/Evercam/ex_nvr/rtsp/lib/rtsp/source.ex
It returns the set up tracks in case of success.
Sends a play request and starts receiving media streams.
@spec start_link(Keyword.t()) :: GenServer.on_start()
Starts a new RTSP client session.
The following options can be provided:
:stream_uri
(String.t/0
) - Required. The RTSP stream URI to connect to.:allowed_media_types
- The type of media streams to request from the rtsp server. The default value is[:audio, :video]
.:transport
- The transport protocol to use for the RTSP session.This can be either:
:tcp
- for TCP transport.{:udp, min_port, max_port}
- for UDP transport, wheremin_port
andmax_port
are the port range for RTP and RTCP streams.
The default value is
:tcp
.:timeout
(timeout/0
) - The timeout for RTSP operations. The default value is5000
.:keep_alive_interval
(timeout/0
) - The interval for sending keep-alive messages. The default value is30000
.:reorder_queue_size
(pos_integer/0
) - Set number of packets to buffer for handling of reordered packets.Due to the implementation, this size should be an exponent of 2.
The default value is
64
.:receiver
(pid/0
) - The process that will receive media streams messages.:onvif_replay
- The stream uri is an onvif replay.
@spec stop(pid()) :: :ok
Closes the RTSP session and stops receiving media streams.