RTSP (RTSP v0.3.2)
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.
TCP and UDP
Currently only TCP transport is supported. UDP transport will be added in the future.
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 session_opts() :: [ stream_uri: String.t(), allowed_media_types: [:video | :audio | :application], timeout: pos_integer() | :infinity, keep_alive_interval: pos_integer(), parent_pid: pid(), name: atom() | nil, onvif_replay: boolean(), start_date: DateTime.t() | nil, end_date: DateTime.t() | nil ]
@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(session_opts()) :: GenServer.on_start()
Starts a new RTSP client session.
The following options can be provided:
:stream_uri
- The RTSP stream URI to connect to (required).:allowed_media_types
- A list of allowed media types, defaults to:[:video, :audio]
.:timeout
- The timeout for RTSP operations (default:5 seconds
).:keep_alive_interval
- The interval for sending keep-alive messages (default:30 seconds
).:parent_pid
- The parent process that will receive messages, defaults to the calling process.:name
- The name of the GenServer process, if provided it'll be used as the first element in the sent messages.
Onvif Replay
To decode onvif replay
extension packets, the following options can be provided
:onvif_replay
- Whether to enable ONVIF replay extension (default:false
).:start_date
- The start date for the session.:end_date
- The end date for the session.
@spec stop(pid()) :: :ok
Closes the RTSP session and stops receiving media streams.