Skip to main content
Import path: github.com/bluenviron/gortsplib/v5/pkg/description

Session

A Session is the top-level description of an RTSP stream. It maps directly to an SDP session description and holds one or more Media entries.

Fields

*base.URL
Base URL of the stream. Populated when the session is received from a server; read-only.
string
Optional human-readable title of the stream. Maps to the SDP s= field.
bool
When true, the SDP connection address is set to a multicast address (224.1.0.0).
*mikey.Message
Optional MIKEY key-management attribute (a=key-mgmt). Used for SRTP streams.
[]SessionFECGroup
Forward Error Correction groups as defined in RFC 5109. Each group is a slice of media IDs.
[]*Media
required
The list of media streams in this session. At least one entry is required for a valid SDP.

Methods

FindFormat

Searches all medias in the session for a format of the given type. When found, it stores the format in forma (a pointer to the target format variable) and returns the owning *Media. Returns nil if no matching format is found.

Marshal

Encodes the session as an SDP byte slice.

Unmarshal

Decodes the session from a parsed SDP session description.

Media

A Media represents a single media stream (e.g., one video track or one audio track) within a session.

Fields

MediaType
required
The type of this media stream: MediaTypeVideo, MediaTypeAudio, or MediaTypeApplication.
string
Optional media identifier (a=mid). Must be alphanumeric. Used when multiple media sections are bundled (RFC 5888).
bool
When true, the media is a back channel (e.g., two-way audio on an IP camera). Serialized as a=sendonly in SDP.
headers.TransportProfile
The RTP profile: TransportProfileAVP (default) or TransportProfileSAVP (for SRTP).
*mikey.Message
Optional per-media MIKEY key-management attribute.
string
The a=control attribute value. Used to build the per-media RTSP URL for SETUP requests.
[]format.Format
required
The RTP payload formats carried by this media stream. At least one format is required.

Methods

FindFormat

Searches the media’s Formats slice for a format whose concrete type matches the element type of forma. On success, sets *forma and returns true.

URL

Returns the absolute RTSP URL for this media, resolved against contentBase (the Content-Base header from the server). Returns an error when contentBase is nil.

Marshal

Encodes the media as a pion SDP MediaDescription.

Unmarshal

Decodes the media from a pion SDP MediaDescription.

MediaType

MediaType is a string type used to classify a media stream.

SessionFECGroup

A SessionFECGroup is a slice of media IDs that form a Forward Error Correction group (RFC 5109). Groups are serialized as a=group:FEC <id1> <id2> ... in SDP.

Code example

Building a session description for a recording client that sends H.264 video:
Searching for a specific format across all medias: