server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TooManyParseError  = errors.New("RTP连续解析错误太多")
	FrequentParseError = errors.New("RTP解析错误太频繁")
	BufferAllocError   = errors.New("RTP缓冲区申请失败")
)

Functions

func WithChannelOptions

func WithChannelOptions(options ...option.AnyOption) option.AnyOption

func WithCloseOnStreamClosed

func WithCloseOnStreamClosed(enable bool) option.AnyOption

func WithLogger

func WithLogger(logger *log.Logger) option.AnyOption

func WithOnAccept

func WithOnAccept(onAccept func(s *TCPServer, conn *net.TCPConn) []option.AnyOption) option.AnyOption

func WithOnChannelCreated

func WithOnChannelCreated(onChannelCreated func(s *TCPServer, channel *TCPChannel)) option.AnyOption

func WithOnChannelError

func WithOnChannelError(onError func(c *TCPChannel, err error)) option.AnyOption

func WithOnChannelTimeout

func WithOnChannelTimeout(onTimeout func(*TCPChannel)) option.AnyOption

func WithOnError

func WithOnError(onError func(s Server, err error)) option.AnyOption

func WithOnLossPacket

func WithOnLossPacket(onLossPacket func(stream Stream, loss int)) option.AnyOption

func WithOnStreamTimeout

func WithOnStreamTimeout(onTimeout func(Stream)) option.AnyOption

func WithPacketPoolProvider

func WithPacketPoolProvider(provider pool.PoolProvider[*rtp.IncomingPacket]) option.AnyOption

func WithReadBufferPool

func WithReadBufferPool(bufferPool pool.BufferPool) option.AnyOption

func WithReadBufferPoolProvider

func WithReadBufferPoolProvider(provider func() pool.BufferPool) option.AnyOption

func WithStreamCloseConn

func WithStreamCloseConn(closeConn bool) option.AnyOption

func WithTimeout

func WithTimeout(timeout time.Duration) option.AnyOption

func WithWriteBufferPool

func WithWriteBufferPool(bufferPool pool.DataPool) option.AnyOption

func WithWriteBufferPoolProvider

func WithWriteBufferPoolProvider(provider func() pool.DataPool) option.AnyOption

Types

type Err

type Err struct {
	Err error
}

func (*Err) Error

func (e *Err) Error() string

type Handler

type Handler interface {
	HandlePacket(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)

	OnParseError(stream Stream, err error) (keep bool)

	OnStreamClosed(stream Stream)
}

func DefaultKeepChooserHandler

func DefaultKeepChooserHandler(handler Handler, secMaxErr int, maxSerializedErr int) Handler

func KeepChooserHandler

func KeepChooserHandler(handler Handler, chooser KeepChooser) Handler

type HandlerFunc

type HandlerFunc struct {
	HandlePacketFn   func(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)
	OnParseErrorFn   func(stream Stream, err error) (keep bool)
	OnStreamClosedFn func(stream Stream)
}

func (HandlerFunc) HandlePacket

func (h HandlerFunc) HandlePacket(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)

func (HandlerFunc) OnParseError

func (h HandlerFunc) OnParseError(stream Stream, err error) (keep bool)

func (HandlerFunc) OnStreamClosed

func (h HandlerFunc) OnStreamClosed(stream Stream)

type KeepChooser

type KeepChooser interface {
	OnSuccess()

	OnError(err error) (keep bool)

	Reset()
}

func NewDefaultKeepChooser

func NewDefaultKeepChooser(secMaxErr int, maxSerializedErr int, onError func(err error) bool) KeepChooser

type Manager

type Manager struct {
	lifecycle.Lifecycle

	log.AtomicLogger
	// contains filtered or unexported fields
}

func NewManager

func NewManager(addr *net.IPAddr, serverProvider ServerProvider, options ...ManagerOption) *Manager

func (*Manager) Addr

func (m *Manager) Addr() *net.IPAddr

func (*Manager) Alloc

func (m *Manager) Alloc() Server

func (*Manager) Free

func (m *Manager) Free(s Server)

type ManagerOption

type ManagerOption option.CustomOption[*Manager]

An ManagerOption configures a MultiStreamManager.

func WithAllocMaxRetry

func WithAllocMaxRetry(maxRetry int) ManagerOption

func WithPort

func WithPort(rtp uint16, rtcp uint16) ManagerOption

func WithPortRange

func WithPortRange(start uint16, end uint16, excludes ...uint16) ManagerOption

func WithServerMaxUsed

func WithServerMaxUsed(maxUsed uint) ManagerOption

func WithServerOptions

func WithServerOptions(options ...option.AnyOption) ManagerOption

func WithServerRestartInterval

func WithServerRestartInterval(interval time.Duration) ManagerOption

type Port

type Port struct {
	RTP  uint16
	RTCP uint16
}

type Ports

type Ports []Port

type Server

type Server interface {
	lifecycle.Lifecycle

	log.LoggerProvider

	Addr() net.Addr

	Stream(remoteAddr net.Addr, ssrc int64, handler Handler, options ...option.AnyOption) (Stream, error)

	RemoveStream(stream Stream)
}

type ServerProvider

type ServerProvider func(m *Manager, port uint16, options ...option.AnyOption) Server

func UDPServerProvider

func UDPServerProvider(options ...option.AnyOption) ServerProvider

type SetKeepaliveError

type SetKeepaliveError struct {
	Err
	Keepalive bool
}

type SetKeepalivePeriodError

type SetKeepalivePeriodError struct {
	Err
	KeepalivePeriod time.Duration
}

type SetNoDelayError

type SetNoDelayError struct {
	Err
	NoDelay bool
}

type SetReadBufferError

type SetReadBufferError struct {
	Err
	ReadBuffer int
}

type SetWriteBufferError

type SetWriteBufferError struct {
	Err
	WriteBuffer int
}

type Stream

type Stream interface {
	Handler() Handler

	SetHandler(handler Handler) Stream

	SSRC() int64

	SetSSRC(ssrc int64) Stream

	LocalAddr() net.Addr

	RemoteAddr() net.Addr

	SetRemoteAddr(addr net.Addr) Stream

	Timeout() time.Duration

	SetTimeout(timeout time.Duration) Stream

	GetOnTimeout() func(Stream)

	SetOnTimeout(onTimeout func(Stream)) Stream

	OnLossPacket() func(stream Stream, loss int)

	SetOnLossPacket(onLossPacket func(stream Stream, loss int)) Stream

	CloseConn() bool

	SetCloseConn(enable bool) Stream

	Send(layer rtp.Layer) error

	Close()

	log.LoggerProvider
}

type TCPAcceptError

type TCPAcceptError struct {
	Err
}

type TCPChannel

type TCPChannel struct {
	lifecycle.Lifecycle

	log.AtomicLogger
	// contains filtered or unexported fields
}

func (*TCPChannel) CloseOnStreamClosed

func (c *TCPChannel) CloseOnStreamClosed() bool

func (*TCPChannel) Conn

func (c *TCPChannel) Conn() *net.TCPConn

func (*TCPChannel) GetOnError

func (c *TCPChannel) GetOnError() func(s *TCPChannel, err error)

func (*TCPChannel) GetOnTimeout

func (c *TCPChannel) GetOnTimeout() func(*TCPChannel)

func (*TCPChannel) LocalAddr

func (c *TCPChannel) LocalAddr() *net.TCPAddr

func (*TCPChannel) RemoteAddr

func (c *TCPChannel) RemoteAddr() *net.TCPAddr

func (*TCPChannel) Send

func (c *TCPChannel) Send(layer rtp.Layer) error

func (*TCPChannel) SetCloseOnStreamClosed

func (c *TCPChannel) SetCloseOnStreamClosed(enable bool) *TCPChannel

func (*TCPChannel) SetOnError

func (c *TCPChannel) SetOnError(onError func(s *TCPChannel, err error)) *TCPChannel

func (*TCPChannel) SetOnTimeout

func (c *TCPChannel) SetOnTimeout(onTimeout func(*TCPChannel)) *TCPChannel

func (*TCPChannel) SetTimeout

func (c *TCPChannel) SetTimeout(timeout time.Duration) *TCPChannel

func (*TCPChannel) Timeout

func (c *TCPChannel) Timeout() time.Duration

type TCPChannelCloseError

type TCPChannelCloseError struct {
	Err
}

type TCPCloseError

type TCPCloseError struct {
	Err
	Listener *net.TCPListener
}

type TCPListenError

type TCPListenError struct {
	Err
	Addr *net.TCPAddr
}

type TCPReadError

type TCPReadError struct {
	Err
}

type TCPReadTimeout

type TCPReadTimeout struct {
	Err
}

type TCPServer

type TCPServer struct {
	lifecycle.Lifecycle

	log.AtomicLogger
	// contains filtered or unexported fields
}

func NewTCPServer

func NewTCPServer(addr *net.TCPAddr, options ...option.AnyOption) *TCPServer

func NewTCPServerWithListener

func NewTCPServerWithListener(listener *net.TCPListener, options ...option.AnyOption) *TCPServer

func (*TCPServer) Addr

func (s *TCPServer) Addr() net.Addr

func (*TCPServer) GetOnAccept

func (s *TCPServer) GetOnAccept() func(s *TCPServer, conn *net.TCPConn) []option.AnyOption

func (*TCPServer) GetOnChannelCreated

func (s *TCPServer) GetOnChannelCreated() func(s *TCPServer, channel *TCPChannel)

func (*TCPServer) GetOnError

func (s *TCPServer) GetOnError() func(s Server, err error)

func (*TCPServer) Listener

func (s *TCPServer) Listener() *net.TCPListener

func (*TCPServer) RemoveStream

func (s *TCPServer) RemoveStream(stream Stream)

RemoveStream 从TCP服务或其管理的TCP通道中移除流

func (*TCPServer) SetOnAccept

func (s *TCPServer) SetOnAccept(onAccept func(s *TCPServer, conn *net.TCPConn) []option.AnyOption) *TCPServer

func (*TCPServer) SetOnChannelCreated

func (s *TCPServer) SetOnChannelCreated(onChannelCreated func(s *TCPServer, channel *TCPChannel)) *TCPServer

func (*TCPServer) SetOnError

func (s *TCPServer) SetOnError(onError func(s Server, err error)) Server

func (*TCPServer) Stream

func (s *TCPServer) Stream(remoteAddr net.Addr, ssrc int64, handler Handler, options ...option.AnyOption) (Stream, error)

type TCPStream

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

func (*TCPStream) Close

func (s *TCPStream) Close()

func (*TCPStream) CloseConn

func (s *TCPStream) CloseConn() bool

func (*TCPStream) GetOnTimeout

func (s *TCPStream) GetOnTimeout() func(Stream)

func (*TCPStream) HandlePacket

func (s *TCPStream) HandlePacket(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)

func (*TCPStream) Handler

func (s *TCPStream) Handler() Handler

func (*TCPStream) LocalAddr

func (s *TCPStream) LocalAddr() net.Addr

func (*TCPStream) OnLossPacket

func (s *TCPStream) OnLossPacket() func(stream Stream, loss int)

func (*TCPStream) OnParseError

func (s *TCPStream) OnParseError(stream Stream, err error) (keep bool)

func (*TCPStream) OnStreamClosed

func (s *TCPStream) OnStreamClosed(stream Stream)

func (*TCPStream) RemoteAddr

func (s *TCPStream) RemoteAddr() net.Addr

func (*TCPStream) SSRC

func (s *TCPStream) SSRC() int64

func (*TCPStream) Send

func (s *TCPStream) Send(layer rtp.Layer) error

func (*TCPStream) SetCloseConn

func (s *TCPStream) SetCloseConn(enable bool) Stream

func (*TCPStream) SetHandler

func (s *TCPStream) SetHandler(handler Handler) Stream

func (*TCPStream) SetOnLossPacket

func (s *TCPStream) SetOnLossPacket(onLossPacket func(stream Stream, loss int)) Stream

func (*TCPStream) SetOnTimeout

func (s *TCPStream) SetOnTimeout(onTimeout func(Stream)) Stream

func (*TCPStream) SetRemoteAddr

func (s *TCPStream) SetRemoteAddr(addr net.Addr) Stream

func (*TCPStream) SetSSRC

func (s *TCPStream) SetSSRC(ssrc int64) Stream

func (*TCPStream) SetSelf

func (s *TCPStream) SetSelf(self Stream)

func (*TCPStream) SetTimeout

func (s *TCPStream) SetTimeout(timeout time.Duration) Stream

func (*TCPStream) Timeout

func (s *TCPStream) Timeout() time.Duration

type TimeoutManager

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

TimeoutManager 超时时间管理器

func (*TimeoutManager) Close

func (m *TimeoutManager) Close()

func (*TimeoutManager) Deadline

func (m *TimeoutManager) Deadline() timePkg.Time

Deadline 获取基于设置时间的超时期限,如果超时时间为0(永不超时),则返回时间的零值

func (*TimeoutManager) Init

func (m *TimeoutManager) Init(f func())

Init 如果计时器已关闭,初始化计时器的超时回调函数

func (*TimeoutManager) SetTime

func (m *TimeoutManager) SetTime(time timePkg.Time)

SetTime 更新当前时间,更新后调用Deadline方法可获取基于更新时间的超时期限,此方法不更新计时器的状态, 一般用于网络IO的超时管理

func (*TimeoutManager) SetTimeout

func (m *TimeoutManager) SetTimeout(timeout timePkg.Duration)

SetTimeout 设置超时时间(设置为0永不超时),设置后调用Deadline方法可获取基于此超时时间的超时期限,此 方法不更新计时器的状态,一般用于网络IO的超时管理

func (*TimeoutManager) Time

func (m *TimeoutManager) Time() timePkg.Time

Time 获取上一次设置的时间

func (*TimeoutManager) Timeout

func (m *TimeoutManager) Timeout() timePkg.Duration

Timeout 获取当前设置的超时时间

func (*TimeoutManager) UpdateTime

func (m *TimeoutManager) UpdateTime(time timePkg.Time)

UpdateTime 与 SetTime 类似,但如果计时器在工作,则会重置计时器的超时时间

func (*TimeoutManager) UpdateTimeout

func (m *TimeoutManager) UpdateTimeout(timeout timePkg.Duration)

UpdateTimeout 与 SetTimeout 方法类似,但如果计时器在工作,则会更新计时器状态。如果需要更新计时器状 态,那么当设置为0时,关闭计时器;否则重置计时器的超时时间

type UDPCloseError

type UDPCloseError struct {
	Err
	Listener *net.UDPConn
}

type UDPListenError

type UDPListenError struct {
	Err
	Addr *net.UDPAddr
}

type UDPReadError

type UDPReadError struct {
	Err
}

type UDPServer

type UDPServer struct {
	lifecycle.Lifecycle

	log.AtomicLogger
	// contains filtered or unexported fields
}

func NewUDPServer

func NewUDPServer(addr *net.UDPAddr, options ...option.AnyOption) *UDPServer

func NewUDPServerWithListener

func NewUDPServerWithListener(listener *net.UDPConn, options ...option.AnyOption) *UDPServer

func (*UDPServer) Addr

func (s *UDPServer) Addr() net.Addr

func (*UDPServer) CloseOnStreamClosed

func (s *UDPServer) CloseOnStreamClosed() bool

func (*UDPServer) GetOnError

func (s *UDPServer) GetOnError() func(s Server, err error)

func (*UDPServer) Listener

func (s *UDPServer) Listener() *net.UDPConn

func (*UDPServer) RemoveStream

func (s *UDPServer) RemoveStream(stream Stream)

func (*UDPServer) SendTo

func (s *UDPServer) SendTo(layer rtp.Layer, addr *net.UDPAddr) error

func (*UDPServer) SetCloseOnStreamClosed

func (s *UDPServer) SetCloseOnStreamClosed(enable bool) Server

func (*UDPServer) SetOnError

func (s *UDPServer) SetOnError(onError func(s Server, err error)) Server

func (*UDPServer) Stream

func (s *UDPServer) Stream(remoteAddr net.Addr, ssrc int64, handler Handler, options ...option.AnyOption) (Stream, error)

type UDPStream

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

func (*UDPStream) Close

func (s *UDPStream) Close()

func (*UDPStream) CloseConn

func (s *UDPStream) CloseConn() bool

func (*UDPStream) GetOnTimeout

func (s *UDPStream) GetOnTimeout() func(Stream)

func (*UDPStream) HandlePacket

func (s *UDPStream) HandlePacket(stream Stream, packet *rtp.IncomingPacket) (dropped, keep bool)

func (*UDPStream) Handler

func (s *UDPStream) Handler() Handler

func (*UDPStream) LocalAddr

func (s *UDPStream) LocalAddr() net.Addr

func (*UDPStream) OnLossPacket

func (s *UDPStream) OnLossPacket() func(stream Stream, loss int)

func (*UDPStream) OnParseError

func (s *UDPStream) OnParseError(stream Stream, err error) (keep bool)

func (*UDPStream) OnStreamClosed

func (s *UDPStream) OnStreamClosed(stream Stream)

func (*UDPStream) RemoteAddr

func (s *UDPStream) RemoteAddr() net.Addr

func (*UDPStream) SSRC

func (s *UDPStream) SSRC() int64

func (*UDPStream) Send

func (s *UDPStream) Send(layer rtp.Layer) error

func (*UDPStream) SetCloseConn

func (s *UDPStream) SetCloseConn(enable bool) Stream

func (*UDPStream) SetHandler

func (s *UDPStream) SetHandler(handler Handler) Stream

func (*UDPStream) SetOnLossPacket

func (s *UDPStream) SetOnLossPacket(onLossPacket func(stream Stream, loss int)) Stream

func (*UDPStream) SetOnTimeout

func (s *UDPStream) SetOnTimeout(onTimeout func(Stream)) Stream

func (*UDPStream) SetRemoteAddr

func (s *UDPStream) SetRemoteAddr(addr net.Addr) Stream

func (*UDPStream) SetSSRC

func (s *UDPStream) SetSSRC(ssrc int64) Stream

func (*UDPStream) SetSelf

func (s *UDPStream) SetSelf(self Stream)

func (*UDPStream) SetTimeout

func (s *UDPStream) SetTimeout(timeout time.Duration) Stream

func (*UDPStream) Timeout

func (s *UDPStream) Timeout() time.Duration

Jump to

Keyboard shortcuts

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