rtsp

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldAccept            = "Accept"             // (R:opt.:entity)
	FieldAcceptEncoding    = "Accept-Encoding"    // (R:opt.:entity)
	FieldAcceptLanguage    = "Accept-Language"    // (R:opt.:all)
	FieldAllow             = "Allow"              // (R:opt.:all)
	FieldAuthorization     = "Authorization"      // (R:opt.:all)
	FieldBandwidth         = "Bandwidth"          // (R:opt.all)
	FieldBlocksize         = "Blocksize"          // (R:opt.:all but OPTIONS, TEARDOWN)
	FieldCacheControl      = "Cache-Control"      // (g:opt.:SETUP)
	FieldConference        = "Conference"         // (R:opt.:SETUP)
	FieldConnection        = "Connection"         // (g:req.:all)
	FieldContentBase       = "Content-Base"       // (e:opt.:entity)
	FieldContentEncoding   = "Content-Encoding"   // (e:req.:SET_PARAMETER ; e:req.:DESCRIBE, ANNOUNCE )
	FieldContentLanguage   = "Content-Language"   // (e:req.:DESCRIBE, ANNOUNCE)
	FieldContentLength     = "Content-Length"     // (e:req.:SET_PARAMETER, ANNOUNCE; e:req.:entity)
	FieldContentLocation   = "Content-Location"   // (e:opt.:entity)
	FieldContentType       = "Content-Type"       // (e:req.:SET_PARAMETER, ANNOUNCE; r:req.:entity )
	FieldCSeq              = "CSeq"               // (g:req.:all)
	FieldDate              = "Date"               // (g:opt.:all)
	FieldExpires           = "Expires"            // (e:opt.:DESCRIBE, ANNOUNCE)
	FieldFrom              = "From"               // (R:opt.:all)
	FieldIfModifiedSince   = "If-Modified-Since"  // (R:opt.:DESCRIBE, SETUP)
	FieldLastModified      = "Last-Modified"      // (e:opt.:entity)
	FieldProxyAuthenticate = "Proxy-Authenticate" //
	FieldProxyRequire      = "Proxy-Require"      // (R:req.:all)
	FieldPublic            = "Public"             // (r:opt.:all)
	FieldRange             = "Range"              // (R:opt.:PLAY, PAUSE, RECORD; r:opt.:PLAY, PAUSE, RECORD)
	FieldReferer           = "Referer"            // (R:opt.:all)
	FieldRequire           = "Require"            // (R:req.:all)
	FieldRetryAfter        = "Retry-After"        // (r:opt.:all)
	FieldRTPInfo           = "RTP-Info"           // (r:req.:PLAY)
	FieldScale             = "Scale"              // (Rr:opt.:PLAY, RECORD)
	FieldSession           = "Session"            // (Rr:req.:all but SETUP, OPTIONS)
	FieldServer            = "Server"             // (r:opt.:all)
	FieldSpeed             = "Speed"              // (Rr:opt.:PLAY)
	FieldTransport         = "Transport"          // (Rr:req.:SETUP)
	FieldUnsupported       = "Unsupported"        // (r:req.:all)
	FieldUserAgent         = "User-Agent"         // (R:opt.:all)
	FieldVia               = "Via"                // (g:opt.:all)
	FieldWWWAuthenticate   = "WWW-Authenticate"   // (r:opt.:all)
)

RTSP 头部域定义 type:support:methods type: "g"通用的请求头部;"R"请求头部;"r"响应头部;"e"实体Body头部域。 support: opt. 可选; req. 必须 methods: 头部域应用范围

View Source
const (
	MethodOptions      = "OPTIONS"       // 查询命令支持情况(C->S, S->C)
	MethodDescribe     = "DESCRIBE"      // 获取媒体信息(C->S)
	MethodAnnounce     = "ANNOUNCE"      // 声明要push的媒体信息(方向:C->S, S->C)
	MethodSetup        = "SETUP"         // 构建传输会话,也可以调整传输参数(C->S);如果不允许调整,可以返回 455 错误
	MethodPlay         = "PLAY"          // 开始发送媒体数据(C->S)
	MethodPause        = "PAUSE"         // 暂停发送媒体数据(C->S)
	MethodTeardown     = "TEARDOWN"      // 关闭发送通道;关闭后需要重新执行 Setup 方法(C->S)
	MethodGetParameter = "GET_PARAMETER" // 获取参数;空body可作为心跳ping(C->S, S->C)
	MethodSetParameter = "SET_PARAMETER" // 设置参数,应该每次只设置一个参数(C->S, S->C)
	MethodRecord       = "RECORD"        // 启动录像(C->S)
	MethodRedirect     = "REDIRECT"      // 跳转(S->C)
)

通用的 RTSP 方法。

除非特别说明,这些定义在 RFC2326 规范的 10 章中。 未实现的方法需要返回 "501 Not Implemented"

View Source
const (
	StatusContinue = 100

	//======Success 2xx
	StatusOK                = 200
	StatusCreated           = 201 // only for RECORD
	StatusLowOnStorageSpace = 250 //only for RECORD

	//======Redirection 3xx
	StatusMultipleChoices  = 300
	StatusMovedPermanently = 301
	StatusMovedTemporarily = 302 // 和http不同
	StatusSeeOther         = 303
	StatusNotModified      = 304
	StatusUseProxy         = 305

	//======Client Error 4xx
	StatusBadRequest                = 400
	StatusUnauthorized              = 401
	StatusPaymentRequired           = 402
	StatusForbidden                 = 403
	StatusNotFound                  = 404
	StatusMethodNotAllowed          = 405
	StatusNotAcceptable             = 406
	StatusProxyAuthRequired         = 407
	StatusRequestTimeout            = 408
	StatusGone                      = 410
	StatusLengthRequired            = 411
	StatusPreconditionFailed        = 412 // only for DESCRIBE, SETUP
	StatusRequestEntityTooLarge     = 413
	StatusRequestURITooLong         = 414
	StatusUnsupportedMediaType      = 415
	StatusInvalidParameter          = 451 // only for SETUP
	StatusConferenceNotFound        = 452 // only for SETUP
	StatusNotEnoughBandwidth        = 453 // only for SETUP
	StatusSessionNotFound           = 454
	StatusMethodNotValidInThisState = 455
	StatusHeaderFieldNotValid       = 456
	StatusInvalidRange              = 457 // only for PLAY
	StatusParameterIsReadOnly       = 458 // only for SET_PARAMETER
	StatusAggregateOpNotAllowed     = 459
	StatusOnlyAggregateOpAllowed    = 460
	StatusUnsupportedTransport      = 461
	StatusDestinationUnreachable    = 462

	StatusInternalServerError     = 500
	StatusNotImplemented          = 501
	StatusBadGateway              = 502
	StatusServiceUnavailable      = 503
	StatusGatewayTimeout          = 504
	StatusRTSPVersionNotSupported = 505
	StatusOptionNotSupported      = 551 // 和 http 不同
)

RTSP 响应状态码. See: https://tools.ietf.org/html/rfc2326#page-19

Variables

This section is empty.

Functions

func FormatDigestAuthResponse

func FormatDigestAuthResponse(realm, nonce, method, url string, username, password string) string

FormatDigestAuthResponse response= md5(md5(username:realm:password):nonce:md5(public_method:url));

func StatusText

func StatusText(code int) string

StatusText 返回 RTSP 状态码的文本。如果 code 未知返回空字串。

Types

type Header map[string][]string

Header 表示 RTSP 头部域键值对.

func ReadHeader

func ReadHeader(r *bufio.Reader) (Header, error)

ReadHeader 根据规范的格式从 r 中读取 Header

func (Header) Add

func (h Header) Add(key, value string)

Add 添加键值对到头部. 如果建已经存在,则对键值做append操作.

func (Header) Del

func (h Header) Del(key string)

Del 删除指定 key 的值.

func (Header) Get

func (h Header) Get(key string) string

Get 获取指定键的值,方法对键会做规范化处理(textproto.CanonicalMIMEHeaderKey) 如果没有值返回“”,如果存在返回第一个值 想访问多值,直接使用map方法.

func (Header) Int

func (h Header) Int(key string) int

Int 获取头部整数域值

func (Header) Set

func (h Header) Set(key, value string)

Set 设置头部指定键的值,操作后该键只有单值. 如果键已经存在,则覆盖其值.

func (Header) SetInt

func (h Header) SetInt(key string, value int)

SetInt 设置头部域整数值

func (Header) Setf

func (h Header) Setf(key, format string, a ...interface{}) string

Setf 格式化的设置头部域

func (Header) Write

func (h Header) Write(w io.Writer) error

Write 根据规范将 Header 输出到 w

type Request

type Request struct {
	Method string   // RTSP 的方法(OPTIONS、DESCRIBE...)
	URL    *url.URL // 请求的 URI。
	Proto  string   // 协议版本,默认 "RTSP/1.0"
	Header Header   // 包含请求的头字段。
	Body   string   // 请求的消息体。
}

Request 表示一个 RTSP 请求; 它可以是 sever 接收或发送的,也可以是 client 接收或发送的。

func ReadRequest

func ReadRequest(r *bufio.Reader) (*Request, error)

ReadRequest 根据规范从 r 中读取 Request

func (*Request) BasicAuth

func (req *Request) BasicAuth() (username, password string, ok bool)

BasicAuth returns the username and password provided in the request's Authorization header, if the request uses HTTP Basic Authentication. See RFC 2617, Section 2.

func (*Request) DigestAuth

func (req *Request) DigestAuth() (username, response string, ok bool)

DigestAuth 获取摘要认证信息

func (*Request) SetBasicAuth

func (req *Request) SetBasicAuth(username, password string)

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

With HTTP Basic Authentication the provided username and password are not encrypted.

func (*Request) SetDigestAuth

func (req *Request) SetDigestAuth(url *url.URL, realm, nonce, username, password string)

SetDigestAuth 为请求设置数字认证

func (*Request) String

func (req *Request) String() string

func (*Request) Write

func (req *Request) Write(w io.Writer) error

Write 根据规范将 Request 输出到 w

type Response

type Response struct {
	Proto      string // e.g. "RTSP/1.0"
	StatusCode int    // e.g. 200
	Status     string // e.g. "200 OK"
	Header     Header
	Body       string
	Request    *Request
}

Response 表示 RTSP 请求的响应

func ReadResponse

func ReadResponse(r *bufio.Reader) (*Response, error)

ReadResponse 根据规范从 r 中读取 Response

func (*Response) BasicAuth

func (resp *Response) BasicAuth() (realm string, ok bool)

BasicAuth 获取基本认证信息

func (*Response) DigestAuth

func (resp *Response) DigestAuth() (realm, nonce string, ok bool)

DigestAuth 获取摘要认证信息

func (*Response) SetBasicAuth

func (resp *Response) SetBasicAuth(realm string)

SetBasicAuth 设置摘要认证安全请求

func (*Response) SetDigestAuth

func (resp *Response) SetDigestAuth(realm, nonce string)

SetDigestAuth 设置摘要认证安全请求

func (*Response) String

func (resp *Response) String() string

func (*Response) Write

func (resp *Response) Write(w io.Writer) error

Write 根据规范将 Response 输出到 w

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL