rtsp

package
v0.0.0-...-c0bc535 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: Unlicense Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Client to server for presentation and stream objects; recommended
	DESCRIBE = "DESCRIBE"
	// Bidirectional for client and stream objects; optional
	ANNOUNCE = "ANNOUNCE"
	// Bidirectional for client and stream objects; optional
	GET_PARAMETER = "GET_PARAMETER"
	// Bidirectional for client and stream objects; required for Client to server, optional for server to client
	OPTIONS = "OPTIONS"
	// Client to server for presentation and stream objects; recommended
	PAUSE = "PAUSE"
	// Client to server for presentation and stream objects; required
	PLAY = "PLAY"
	// Client to server for presentation and stream objects; optional
	RECORD = "RECORD"
	// Server to client for presentation and stream objects; optional
	REDIRECT = "REDIRECT"
	// Client to server for stream objects; required
	SETUP = "SETUP"
	// Bidirectional for presentation and stream objects; optional
	SET_PARAMETER = "SET_PARAMETER"
	// Client to server for presentation and stream objects; required
	TEARDOWN = "TEARDOWN"
	DATA     = "DATA"
)
View Source
const (
	RTP_FIXED_HEADER_LENGTH = 12
)
View Source
const (
	RTSP_VERSION = "RTSP/1.0"
)
View Source
const UDP_BUF_SIZE = 1048576

Variables

This section is empty.

Functions

func CheckAuth

func CheckAuth(authLine string, method string, sessionNonce string) error

func DigestAuth

func DigestAuth(authLine string, method string, URL string) (string, error)

func ParseSDP

func ParseSDP(sdpRaw string) map[string]*SDPInfo

Types

type Player

type Player struct {
	*Session
	Pusher *Pusher
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(session *Session, pusher *Pusher) (player *Player)

func (*Player) Pause

func (player *Player) Pause(paused bool)

func (*Player) QueueRTP

func (player *Player) QueueRTP(pack *RTPPack) *Player

func (*Player) Start

func (player *Player) Start()

type Pusher

type Pusher struct {
	*Session
	*RTSPClient

	UDPServer *UDPServer
	// contains filtered or unexported fields
}

func NewClientPusher

func NewClientPusher(client *RTSPClient) (pusher *Pusher)

func NewPusher

func NewPusher(session *Session) (pusher *Pusher)

func (*Pusher) ACodec

func (pusher *Pusher) ACodec() string

func (*Pusher) AControl

func (pusher *Pusher) AControl() string

func (*Pusher) AddOutputBytes

func (pusher *Pusher) AddOutputBytes(size int)

func (*Pusher) AddPlayer

func (pusher *Pusher) AddPlayer(player *Player) *Pusher

func (*Pusher) BroadcastRTP

func (pusher *Pusher) BroadcastRTP(pack *RTPPack) *Pusher

func (*Pusher) ClearPlayer

func (pusher *Pusher) ClearPlayer()

func (*Pusher) GetPlayers

func (pusher *Pusher) GetPlayers() (players map[string]*Player)

func (*Pusher) HasPlayer

func (pusher *Pusher) HasPlayer(player *Player) bool

func (*Pusher) ID

func (pusher *Pusher) ID() string

func (*Pusher) InBytes

func (pusher *Pusher) InBytes() int

func (*Pusher) Logger

func (pusher *Pusher) Logger() *log.Logger

func (*Pusher) OutBytes

func (pusher *Pusher) OutBytes() int

func (*Pusher) Path

func (pusher *Pusher) Path() string

func (*Pusher) QueueRTP

func (pusher *Pusher) QueueRTP(pack *RTPPack) *Pusher

func (*Pusher) RebindClient

func (pusher *Pusher) RebindClient(client *RTSPClient) bool

func (*Pusher) RebindSession

func (pusher *Pusher) RebindSession(session *Session) bool

func (*Pusher) RemovePlayer

func (pusher *Pusher) RemovePlayer(player *Player) *Pusher

func (*Pusher) SDPRaw

func (pusher *Pusher) SDPRaw() string

func (*Pusher) Server

func (pusher *Pusher) Server() *Server

func (*Pusher) Source

func (pusher *Pusher) Source() string

func (*Pusher) Start

func (pusher *Pusher) Start()

func (*Pusher) StartAt

func (pusher *Pusher) StartAt() time.Time

func (*Pusher) Stop

func (pusher *Pusher) Stop()

func (*Pusher) Stoped

func (pusher *Pusher) Stoped() bool

func (*Pusher) String

func (pusher *Pusher) String() string

func (*Pusher) TransType

func (pusher *Pusher) TransType() string

func (*Pusher) URL

func (pusher *Pusher) URL() string

func (*Pusher) VCodec

func (pusher *Pusher) VCodec() string

func (*Pusher) VControl

func (pusher *Pusher) VControl() string

type RTPInfo

type RTPInfo struct {
	Version        int
	Padding        bool
	Extension      bool
	CSRCCnt        int
	Marker         bool
	PayloadType    int
	SequenceNumber int
	Timestamp      int
	SSRC           int
	Payload        []byte
	PayloadOffset  int
}

func ParseRTP

func ParseRTP(rtpBytes []byte) *RTPInfo

type RTPPack

type RTPPack struct {
	Type   RTPType
	Buffer *bytes.Buffer
}

type RTPType

type RTPType int
const (
	RTP_TYPE_AUDIO RTPType = iota
	RTP_TYPE_VIDEO
	RTP_TYPE_AUDIOCONTROL
	RTP_TYPE_VIDEOCONTROL
)

func (RTPType) String

func (rt RTPType) String() string

type RTSPClient

type RTSPClient struct {
	Server *Server
	SessionLogger
	Stoped     bool
	Status     string
	URL        string
	Path       string
	CustomPath string //custom path for pusher
	ID         string
	Conn       *RichConn
	Session    string
	Seq        int

	InBytes              int
	OutBytes             int
	TransType            TransType
	StartAt              time.Time
	Sdp                  *sdp.Session
	AControl             string
	VControl             string
	ACodec               string
	VCodec               string
	OptionIntervalMillis int64
	SDPRaw               string

	Agent string

	UDPServer   *UDPServer
	RTPHandles  []func(*RTPPack)
	StopHandles []func()
	// contains filtered or unexported fields
}

func NewRTSPClient

func NewRTSPClient(server *Server, rawUrl string, sendOptionMillis int64, agent string) (client *RTSPClient, err error)

func (*RTSPClient) Request

func (client *RTSPClient) Request(method string, headers map[string]string) (*Response, error)

func (*RTSPClient) RequestNoResp

func (client *RTSPClient) RequestNoResp(method string, headers map[string]string) (err error)

func (*RTSPClient) RequestWithPath

func (client *RTSPClient) RequestWithPath(method string, path string, headers map[string]string, needResp bool) (resp *Response, err error)

func (*RTSPClient) Start

func (client *RTSPClient) Start(timeout time.Duration) (err error)

func (*RTSPClient) Stop

func (client *RTSPClient) Stop()

func (*RTSPClient) String

func (client *RTSPClient) String() string

type Request

type Request struct {
	Method  string
	URL     string
	Version string
	Header  map[string]string
	Content string
	Body    string
}

func NewRequest

func NewRequest(content string) *Request

func (*Request) GetContentLength

func (r *Request) GetContentLength() int

func (*Request) String

func (r *Request) String() string

type Response

type Response struct {
	Version    string
	StatusCode int
	Status     string
	Header     map[string]interface{}
	Body       string
}

func NewResponse

func NewResponse(statusCode int, status, cSeq, sid, body string) *Response

func (*Response) SetBody

func (r *Response) SetBody(body string)

func (*Response) String

func (r *Response) String() string

type RichConn

type RichConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*RichConn) Read

func (conn *RichConn) Read(b []byte) (n int, err error)

func (*RichConn) Write

func (conn *RichConn) Write(b []byte) (n int, err error)

type SDPInfo

type SDPInfo struct {
	AVType             string
	Codec              string
	TimeScale          int
	Control            string
	Rtpmap             int
	Config             []byte
	SpropParameterSets [][]byte
	PayloadType        int
	SizeLength         int
	IndexLength        int
}

type Server

type Server struct {
	SessionLogger
	TCPListener *net.TCPListener
	TCPPort     int
	Stoped      bool
	// contains filtered or unexported fields
}
var Instance *Server = &Server{
	SessionLogger:  SessionLogger{log.New(os.Stdout, "[RTSPServer]", log.LstdFlags|log.Lshortfile)},
	Stoped:         true,
	TCPPort:        utils.Conf().Section("rtsp").Key("port").MustInt(554),
	pushers:        make(map[string]*Pusher),
	addPusherCh:    make(chan *Pusher),
	removePusherCh: make(chan *Pusher),
}

func GetServer

func GetServer() *Server

func (*Server) AddPusher

func (server *Server) AddPusher(pusher *Pusher) bool

func (*Server) GetPusher

func (server *Server) GetPusher(path string) (pusher *Pusher)

func (*Server) GetPusherSize

func (server *Server) GetPusherSize() (size int)

func (*Server) GetPushers

func (server *Server) GetPushers() (pushers map[string]*Pusher)

func (*Server) RemovePusher

func (server *Server) RemovePusher(pusher *Pusher)

func (*Server) Start

func (server *Server) Start() (err error)

func (*Server) Stop

func (server *Server) Stop()

func (*Server) TryAttachToPusher

func (server *Server) TryAttachToPusher(session *Session) (int, *Pusher)

type Session

type Session struct {
	SessionLogger
	ID     string
	Server *Server
	Conn   *RichConn

	Type      SessionType
	TransType TransType
	Path      string
	URL       string
	SDPRaw    string
	SDPMap    map[string]*SDPInfo

	AControl string
	VControl string
	ACodec   string
	VCodec   string

	// stats info
	InBytes  int
	OutBytes int
	StartAt  time.Time
	Timeout  int

	Stoped bool

	Pusher      *Pusher
	Player      *Player
	UDPClient   *UDPClient
	RTPHandles  []func(*RTPPack)
	StopHandles []func()
	// contains filtered or unexported fields
}

func NewSession

func NewSession(server *Server, conn net.Conn) *Session

func (*Session) SendRTP

func (session *Session) SendRTP(pack *RTPPack) (err error)

func (*Session) Start

func (session *Session) Start()

func (*Session) Stop

func (session *Session) Stop()

func (*Session) String

func (session *Session) String() string

type SessionLogger

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

type SessionType

type SessionType int
const (
	SESSION_TYPE_PUSHER SessionType = iota
	SESSEION_TYPE_PLAYER
)

func (SessionType) String

func (st SessionType) String() string

type TransType

type TransType int
const (
	TRANS_TYPE_TCP TransType = iota
	TRANS_TYPE_UDP
)

func (TransType) String

func (tt TransType) String() string

type UDPClient

type UDPClient struct {
	*Session

	APort        int
	AConn        *net.UDPConn
	AControlPort int
	AControlConn *net.UDPConn
	VPort        int
	VConn        *net.UDPConn
	VControlPort int
	VControlConn *net.UDPConn

	Stoped bool
}

func (*UDPClient) SendRTP

func (c *UDPClient) SendRTP(pack *RTPPack) (err error)

func (*UDPClient) SetupAudio

func (c *UDPClient) SetupAudio() (err error)

func (*UDPClient) SetupVideo

func (c *UDPClient) SetupVideo() (err error)

func (*UDPClient) Stop

func (s *UDPClient) Stop()

type UDPServer

type UDPServer struct {
	*Session
	*RTSPClient

	APort        int
	AConn        *net.UDPConn
	AControlPort int
	AControlConn *net.UDPConn
	VPort        int
	VConn        *net.UDPConn
	VControlPort int
	VControlConn *net.UDPConn

	Stoped bool
}

func (*UDPServer) AddInputBytes

func (s *UDPServer) AddInputBytes(bytes int)

func (*UDPServer) HandleRTP

func (s *UDPServer) HandleRTP(pack *RTPPack)

func (*UDPServer) Logger

func (s *UDPServer) Logger() *log.Logger

func (*UDPServer) SetupAudio

func (s *UDPServer) SetupAudio() (err error)

func (*UDPServer) SetupVideo

func (s *UDPServer) SetupVideo() (err error)

func (*UDPServer) Stop

func (s *UDPServer) Stop()

Jump to

Keyboard shortcuts

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