rtsp

package
v0.0.0-...-4fdb4ed Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_Init = iota
	STATE_Ready
	STATE_Playing
	STATE_Recording
)
View Source
const (
	RTSP_1_0 = 1
	RTSP_2_0 = 2
)
View Source
const (
	OPTIONS       = "OPTIONS"
	DESCRIBE      = "DESCRIBE"
	SETUP         = "SETUP"
	PLAY          = "PLAY"
	GET_PARAMETER = "GET_PARAMETER"
	SET_PARAMETER = "SET_PARAMETER"
	ANNOUNCE      = "ANNOUNCE"
	PAUSE         = "PAUSE"
	RECORD        = "RECORD"
	REDIRECT      = "REDIRECT"
	TEARDOWN      = "TEARDOWN"
)

method direction object requirement DESCRIBE C->S P,S recommended ANNOUNCE C->S, S->C P,S optional GET_PARAMETER C->S, S->C P,S optional OPTIONS C->S, S->C P,S required

(S->C: optional)

PAUSE C->S P,S recommended PLAY C->S P,S required RECORD C->S P,S optional REDIRECT S->C P,S optional SETUP C->S S required SET_PARAMETER C->S, S->C P,S optional TEARDOWN C->S P,S required

View Source
const (
	Accept            = "Accept"
	AcceptEncoding    = "AcceptEncoding"
	AcceptLanguage    = "AcceptLanguage"
	Allow             = "Allow"
	Authorization     = "Authorization"
	Bandwidth         = "Bandwidth"
	Blocksize         = "Blocksize"
	CacheControl      = "CacheControl"
	Conference        = "Conference"
	Connection        = "Connection"
	ContentBase       = "Content-Base"
	ContentEncoding   = "Content-Encoding"
	ContentLanguage   = "Content-Language"
	ContentLength     = "Content-Length"
	ContentLocation   = "Content-Location"
	ContentType       = "Content-Type"
	CSeq              = "CSeq"
	Date              = "Date"
	Expires           = "Expires"
	From              = "From"
	IfModifiedSince   = "IfModifiedSince"
	LastModified      = "LastModified"
	ProxyAuthenticate = "ProxyAuthenticate"
	ProxyRequire      = "ProxyRequire"
	Public            = "Public"
	Range             = "Range"
	Referer           = "Referer"
	Require           = "Require"
	RetryAfter        = "RetryAfter"
	RTPInfo           = "RTPInfo"
	Scale             = "Scale"
	Session           = "Session"
	Server            = "Server"
	Speed             = "Speed"
	Transport         = "Transport"
	Unsupported       = "Unsupported"
	UserAgent         = "UserAgent"
	Via               = "Via"
	WWWAuthenticate   = "WWW-Authenticate"
	Location          = "Location"
)
View Source
const (
	OK                    = 200
	MOVED_Permanently     = 300
	MOVED_Temporarily     = 301
	BAD_REQUEST           = 400
	Unauthorized          = 401
	Not_Found             = 404
	Session_Not_Found     = 454
	Unsupported_Transport = 461
	Internal_Server_Error = 500
	Not_Implemented       = 501
	Version_Not_Supported = 505
)
View Source
const (
	MODE_PLAY   = "PLAY"
	MODE_RECORD = "RECORD"
)

Variables

This section is empty.

Functions

func GetEncodeNameByCodecId

func GetEncodeNameByCodecId(cid RTSP_CODEC_ID) string

Types

type ClientHandle

type ClientHandle interface {
	HandleOption(cli *RtspClient, res RtspResponse, public []string) error
	HandleDescribe(cli *RtspClient, res RtspResponse, sdp *sdp.Sdp, tracks map[string]*RtspTrack) error
	HandleSetup(cli *RtspClient, res RtspResponse, currentTrack *RtspTrack, tracks map[string]*RtspTrack, sessionId string, timeout int) error
	HandleAnnounce(cli *RtspClient, res RtspResponse) error
	HandlePlay(cli *RtspClient, res RtspResponse, timeRange *RangeTime, info *RtpInfo) error
	HandlePause(cli *RtspClient, res RtspResponse) error
	HandleTeardown(cli *RtspClient, res RtspResponse) error
	HandleGetParameter(cli *RtspClient, res RtspResponse) error
	HandleSetParameter(cli *RtspClient, res RtspResponse) error
	HandleRedirect(cli *RtspClient, req RtspRequest, location string, timeRange *RangeTime) error
	HandleRecord(cli *RtspClient, res RtspResponse, timeRange *RangeTime, info *RtpInfo) error
	HandleRequest(cli *RtspClient, req RtspRequest) error
}

type ClientOption

type ClientOption func(cli *RtspClient)

func WithEnableRecord

func WithEnableRecord() ClientOption

type HeadFiled

type HeadFiled map[string]string

func (HeadFiled) Add

func (filed HeadFiled) Add(key string, value interface{})

func (HeadFiled) Has

func (filed HeadFiled) Has(key string) bool

type LowerTransport

type LowerTransport int
const (
	UDP LowerTransport = iota
	TCP
)

type OnSampleCallBack

type OnSampleCallBack func(sample RtspSample)

type OutPutCallBack

type OutPutCallBack func([]byte) error

type PacketCallBack

type PacketCallBack func(b []byte, isRtcp bool) error

type RTSP_CODEC_ID

type RTSP_CODEC_ID int
const (
	RTSP_CODEC_H264 RTSP_CODEC_ID = iota
	RTSP_CODEC_H265
	RTSP_CODEC_AAC
	RTSP_CODEC_G711A
	RTSP_CODEC_G711U
	RTSP_CODEC_PS
	RTSP_CODEC_TS
)

func GetCodecIdByEncodeName

func GetCodecIdByEncodeName(name string) RTSP_CODEC_ID

type RangeTime

type RangeTime struct {
	// contains filtered or unexported fields
}

func (RangeTime) EncodeString

func (rt RangeTime) EncodeString() string

type RangeType

type RangeType int
const (
	RANGE_NPT RangeType = iota
	RANGE_UTC
)

type RtpInfo

type RtpInfo struct {
	Url     string
	Seq     uint16
	Rtptime int64
}

func NewRtpInfo

func NewRtpInfo(url string, seq uint16) *RtpInfo

func (*RtpInfo) Decode

func (info *RtpInfo) Decode(str string)

func (*RtpInfo) EncodeString

func (info *RtpInfo) EncodeString() string

type RtspClient

type RtspClient struct {
	// contains filtered or unexported fields
}

func NewRtspClient

func NewRtspClient(uri string, handle ClientHandle, opt ...ClientOption) (*RtspClient, error)

func (*RtspClient) AddTrack

func (client *RtspClient) AddTrack(track *RtspTrack)

func (*RtspClient) EnableRTCP

func (client *RtspClient) EnableRTCP()

func (*RtspClient) GetTrack

func (client *RtspClient) GetTrack(trackName string) (track *RtspTrack, found bool)

func (*RtspClient) Input

func (client *RtspClient) Input(data []byte) (err error)

func (*RtspClient) KeepAlive

func (client *RtspClient) KeepAlive(method string) error

func (*RtspClient) Pause

func (client *RtspClient) Pause() (err error)

func (*RtspClient) Play

func (client *RtspClient) Play()

func (*RtspClient) SessionDescribe

func (client *RtspClient) SessionDescribe() string

func (*RtspClient) SetOutput

func (client *RtspClient) SetOutput(output OutPutCallBack)

func (*RtspClient) SetRange

func (client *RtspClient) SetRange(timeRange RangeTime)

func (*RtspClient) SetScale

func (client *RtspClient) SetScale(scale float32)

func (*RtspClient) SetSessionDescribe

func (client *RtspClient) SetSessionDescribe(sdp *sdp.Sdp)

func (*RtspClient) SetSpeed

func (client *RtspClient) SetSpeed(speed float32)

func (*RtspClient) Start

func (client *RtspClient) Start() error

func (*RtspClient) TearDown

func (client *RtspClient) TearDown() (err error)

type RtspCodec

type RtspCodec struct {
	Cid          RTSP_CODEC_ID //H264,H265,PCMU,PCMA...
	PayloadType  uint8
	SampleRate   uint32
	ChannelCount uint8
}

func NewApplicatioCodec

func NewApplicatioCodec(name string, pt uint8) RtspCodec

func NewAudioCodec

func NewAudioCodec(name string, pt uint8, sampleRate uint32, channelCount int) RtspCodec

func NewCodec

func NewCodec(name string, pt uint8, sampleRate uint32, channel uint8) RtspCodec

func NewVideoCodec

func NewVideoCodec(name string, pt uint8, sampleRate uint32) RtspCodec

type RtspRequest

type RtspRequest struct {
	Method  string
	Uri     string
	Version int
	Fileds  HeadFiled
	Body    string
}

func (*RtspRequest) Encode

func (req *RtspRequest) Encode() string

type RtspResponse

type RtspResponse struct {
	Version    int
	StatusCode int
	Reason     string
	Fileds     HeadFiled
	Body       string
}

func (*RtspResponse) Encode

func (res *RtspResponse) Encode() string

type RtspSample

type RtspSample struct {
	Cid       RTSP_CODEC_ID
	Sample    []byte
	Timestamp uint32 //in milliseconds
	Completed bool
}

type RtspServer

type RtspServer struct {
	// contains filtered or unexported fields
}

func NewRtspServer

func NewRtspServer(handle ServerHandle, opt ...ServerOption) *RtspServer

func (*RtspServer) AddTrack

func (server *RtspServer) AddTrack(track *RtspTrack)

func (*RtspServer) Input

func (server *RtspServer) Input(data []byte) (err error)

func (*RtspServer) SetOutput

func (server *RtspServer) SetOutput(output OutPutCallBack)

type RtspTrack

type RtspTrack struct {
	TrackName string //video/audio/application
	Codec     RtspCodec
	// contains filtered or unexported fields
}

func NewAudioTrack

func NewAudioTrack(codec RtspCodec, opt ...TrackOption) *RtspTrack

func NewMetaTrack

func NewMetaTrack(codec RtspCodec, opt ...TrackOption) *RtspTrack

func NewVideoTrack

func NewVideoTrack(codec RtspCodec, opt ...TrackOption) *RtspTrack

func (*RtspTrack) Bye

func (track *RtspTrack) Bye() error

func (*RtspTrack) EnableTCP

func (track *RtspTrack) EnableTCP()

func (*RtspTrack) GetRtcpRecvContext

func (track *RtspTrack) GetRtcpRecvContext() *rtcp.RtcpContext

func (*RtspTrack) GetRtcpSendContext

func (track *RtspTrack) GetRtcpSendContext() *rtcp.RtcpContext

func (*RtspTrack) GetTransport

func (track *RtspTrack) GetTransport() *RtspTransport

func (*RtspTrack) Input

func (track *RtspTrack) Input(data []byte, isRtcp bool) error

func (*RtspTrack) OnPacket

func (track *RtspTrack) OnPacket(f PacketCallBack)

func (*RtspTrack) OnSample

func (track *RtspTrack) OnSample(onsample OnSampleCallBack)

func (*RtspTrack) OpenTrack

func (track *RtspTrack) OpenTrack()

func (*RtspTrack) ReceiveReport

func (track *RtspTrack) ReceiveReport() error

func (*RtspTrack) SendReport

func (track *RtspTrack) SendReport() error

func (*RtspTrack) SetCodecParamHandle

func (track *RtspTrack) SetCodecParamHandle(handle sdp.FmtpCodecParamParser)

func (*RtspTrack) SetExtraData

func (track *RtspTrack) SetExtraData(extra interface{})

func (*RtspTrack) SetTransport

func (track *RtspTrack) SetTransport(transport *RtspTransport)

func (*RtspTrack) SourceDescription

func (track *RtspTrack) SourceDescription(sdesType uint8, content string) error

func (*RtspTrack) WriteSample

func (track *RtspTrack) WriteSample(sample RtspSample) error

type RtspTransport

type RtspTransport struct {
	IsMultiCast  bool
	Proto        LowerTransport
	Client_ports [2]uint16
	Server_ports [2]uint16
	Interleaved  [2]int
	// contains filtered or unexported fields
}

func NewRtspTransport

func NewRtspTransport(opt ...TransportOption) *RtspTransport

func (*RtspTransport) Decode

func (transport *RtspTransport) Decode(data []byte) error

func (*RtspTransport) DecodeString

func (transport *RtspTransport) DecodeString(data string) error

func (*RtspTransport) EncodeString

func (transport *RtspTransport) EncodeString() string

func (*RtspTransport) SetClientUdpPort

func (transport *RtspTransport) SetClientUdpPort(rtpPort uint16, rtcpPort uint16)

func (*RtspTransport) SetInterleaved

func (transport *RtspTransport) SetInterleaved(interleaved [2]int)

func (*RtspTransport) SetServerUdpPort

func (transport *RtspTransport) SetServerUdpPort(rtpPort uint16, rtcpPort uint16)

type ServerHandle

type ServerHandle interface {
	HandleOption(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleDescribe(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleSetup(svr *RtspServer, req RtspRequest, res *RtspResponse, transport *RtspTransport, tracks *RtspTrack)
	HandleAnnounce(svr *RtspServer, req RtspRequest, tracks map[string]*RtspTrack)
	HandlePlay(svr *RtspServer, req RtspRequest, res *RtspResponse, timeRange *RangeTime, info []*RtpInfo)
	HandlePause(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleTeardown(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleGetParameter(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleSetParameter(svr *RtspServer, req RtspRequest, res *RtspResponse)
	HandleRecord(svr *RtspServer, req RtspRequest, res *RtspResponse, timeRange *RangeTime, info []*RtpInfo)
	HandleResponse(svr *RtspServer, res RtspResponse)
}

type ServerOption

type ServerOption func(*RtspServer)

func WithAuthType

func WithAuthType(authType string) ServerOption

func WithRealm

func WithRealm(realm string) ServerOption

func WithUserInfo

func WithUserInfo(userName, passwd string) ServerOption

type TrackCallBack

type TrackCallBack func(track *RtspTrack)

type TrackOption

type TrackOption func(t *RtspTrack)

func WithCodecParamHandler

func WithCodecParamHandler(handler sdp.FmtpCodecParamParser) TrackOption

func WithDisableRtcpRR

func WithDisableRtcpRR() TrackOption

type TransportOption

type TransportOption func(transport *RtspTransport)

func WithClientUdpPort

func WithClientUdpPort(rtpPort uint16, rtcpPort uint16) TransportOption

func WithEnableUdp

func WithEnableUdp() TransportOption

func WithMode

func WithMode(mode string) TransportOption

func WithServerUdpPort

func WithServerUdpPort(rtpPort uint16, rtcpPort uint16) TransportOption

func WithTcpInterleaved

func WithTcpInterleaved(interleaved [2]int) TransportOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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