Import path: github.com/bluenviron/gortsplib/v5/pkg/base
URL
URL is an RTSP URL. It is a thin alias over the standard library’s net/url.URL,
with RTSP-specific validation and helpers.
ParseURL
func ParseURL(s string) (*URL, error)
Parses a raw RTSP URL string. Returns an error if:
- the scheme is not
rtsp or rtsps,
- the URL contains opaque data,
- the URL contains a fragment (
#).
u, err := base.ParseURL("rtsp://user:pass@192.168.1.1:554/stream")
URL methods
| Method | Signature | Description |
|---|
String | () string | Returns the URL as a string (fmt.Stringer). |
Clone | () *URL | Returns a deep copy of the URL including credentials. |
CloneWithoutCredentials | () *URL | Returns a copy with the User field cleared. Used when sending URLs on the wire. |
Hostname | () string | Host without port. Strips brackets from IPv6 addresses. |
Port | () string | Port portion of the host, without the leading colon. |
Request
Request represents an RTSP/1.0 request message.
type Request struct {
Method Method
URL *URL
Header Header
Body []byte
}
Fields
The RTSP method (e.g., Describe, Setup, Play). See the Methods table.
The request URL. May be nil when the request targets * (used in some OPTIONS requests).
Map of header fields. Keys are canonical header names; values are HeaderValue ([]string).
Optional request body. When non-empty, Content-Length is set automatically during marshaling.
Request methods
| Method | Signature | Description |
|---|
Unmarshal | (br *bufio.Reader) error | Reads and parses a request from a buffered reader. |
Marshal | () ([]byte, error) | Serializes the request to a byte slice. |
MarshalSize | () int | Returns the serialized byte length without allocating. |
MarshalTo | (buf []byte) (int, error) | Serializes the request into a pre-allocated buffer. |
String | () string | Returns the serialized request as a string (fmt.Stringer). |
Response
Response represents an RTSP/1.0 response message.
type Response struct {
StatusCode StatusCode
StatusMessage string
Header Header
Body []byte
}
Fields
Human-readable status message (e.g., "OK"). If empty during marshaling, the standard
message for the status code is filled in automatically from StatusMessages.
Optional response body. Content-Length is set automatically during marshaling.
Response methods
| Method | Signature | Description |
|---|
Unmarshal | (br *bufio.Reader) error | Reads and parses a response from a buffered reader. |
Marshal | () ([]byte, error) | Serializes the response to a byte slice. |
MarshalSize | () int | Returns the serialized byte length without allocating. |
MarshalTo | (buf []byte) (int, error) | Serializes the response into a pre-allocated buffer. |
String | () string | Returns the serialized response as a string (fmt.Stringer). |
type HeaderValue []string
type Header map[string]HeaderValue
Header is a map from canonical header name to one or more string values. The same
header key can appear more than once in a request or response; all values are collected
into the HeaderValue slice.
Key normalization follows net/http.CanonicalHeaderKey with RTSP-specific overrides:
CSeq, RTP-Info, WWW-Authenticate, and KeyMgmt.
Methods
Method is a string type.
| Constant | Wire value | Description |
|---|
Announce | "ANNOUNCE" | Publish stream metadata to a server. |
Describe | "DESCRIBE" | Retrieve stream description (SDP) from a server. |
GetParameter | "GET_PARAMETER" | Read a session or stream parameter. |
Options | "OPTIONS" | Query the methods supported by a server or resource. |
Pause | "PAUSE" | Temporarily halt delivery of a stream. |
Play | "PLAY" | Start or resume delivery of a stream. |
Record | "RECORD" | Start recording a stream to a server. |
Setup | "SETUP" | Negotiate transport parameters for a single media. |
SetParameter | "SET_PARAMETER" | Write a session or stream parameter. |
Teardown | "TEARDOWN" | Terminate a session and release server resources. |
Status codes
StatusCode is an int type. StatusMessages is a map[StatusCode]string that maps
each code to its standard reason phrase.
| Constant | Code |
|---|
StatusContinue | 100 |
2xx Success
3xx Redirection
| Constant | Code |
|---|
StatusMovedPermanently | 301 |
StatusFound | 302 |
StatusSeeOther | 303 |
StatusNotModified | 304 |
StatusUseProxy | 305 |
4xx Client errors
| Constant | Code | Reason |
|---|
StatusBadRequest | 400 | Bad Request |
StatusUnauthorized | 401 | Unauthorized |
StatusPaymentRequired | 402 | Payment Required |
StatusForbidden | 403 | Forbidden |
StatusNotFound | 404 | Not Found |
StatusMethodNotAllowed | 405 | Method Not Allowed |
StatusNotAcceptable | 406 | Not Acceptable |
StatusProxyAuthRequired | 407 | Proxy Auth Required |
StatusRequestTimeout | 408 | Request Timeout |
StatusGone | 410 | Gone |
StatusPreconditionFailed | 412 | Precondition Failed |
StatusRequestEntityTooLarge | 413 | Request Entity Too Large |
StatusRequestURITooLong | 414 | Request URI Too Long |
StatusUnsupportedMediaType | 415 | Unsupported Media Type |
StatusParameterNotUnderstood | 451 | Parameter Not Understood |
StatusNotEnoughBandwidth | 453 | Not Enough Bandwidth |
StatusSessionNotFound | 454 | Session Not Found |
StatusMethodNotValidInThisState | 455 | Method Not Valid In This State |
StatusHeaderFieldNotValidForResource | 456 | Header Field Not Valid for Resource |
StatusInvalidRange | 457 | Invalid Range |
StatusParameterIsReadOnly | 458 | Parameter Is Read-Only |
StatusAggregateOperationNotAllowed | 459 | Aggregate Operation Not Allowed |
StatusOnlyAggregateOperationAllowed | 460 | Only Aggregate Operation Allowed |
StatusUnsupportedTransport | 461 | Unsupported Transport |
StatusDestinationUnreachable | 462 | Destination Unreachable |
StatusDestinationProhibited | 463 | Destination Prohibited |
StatusDataTransportNotReadyYet | 464 | Data Transport Not Ready Yet |
StatusNotificationReasonUnknown | 465 | Notification Reason Unknown |
StatusKeyManagementError | 466 | Key Management Error |
StatusConnectionAuthorizationRequired | 470 | Connection Authorization Required |
StatusConnectionCredentialsNotAccepted | 471 | Connection Credentials Not Accepted |
StatusFailureToEstablishSecureConnection | 472 | Failure to Establish Secure Connection |
5xx Server errors
| Constant | Code | Reason |
|---|
StatusInternalServerError | 500 | Internal Server Error |
StatusNotImplemented | 501 | Not Implemented |
StatusBadGateway | 502 | Bad Gateway |
StatusServiceUnavailable | 503 | Service Unavailable |
StatusGatewayTimeout | 504 | Gateway Timeout |
StatusRTSPVersionNotSupported | 505 | RTSP Version Not Supported |
StatusOptionNotSupported | 551 | Option Not Supported |
StatusProxyUnavailable | 553 | Proxy Unavailable |
Code example
Parsing a URL and constructing a response:
import (
"bufio"
"github.com/bluenviron/gortsplib/v5/pkg/base"
)
// Parse an RTSP URL
u, err := base.ParseURL("rtsp://admin:password@192.168.1.100:554/live")
if err != nil { ... }
fmt.Println(u.Hostname()) // "192.168.1.100"
fmt.Println(u.Port()) // "554"
// Build a response
res := &base.Response{
StatusCode: base.StatusOK,
Header: base.Header{
"Content-Type": base.HeaderValue{"application/sdp"},
"CSeq": base.HeaderValue{"1"},
},
Body: sdpBytes,
}
buf, err := res.Marshal()