mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
export callback prototypes (#333)
This commit is contained in:
45
client.go
45
client.go
@@ -180,6 +180,33 @@ type clientRes struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientOnRequestFunc is the prototype of Client.OnRequest.
|
||||||
|
type ClientOnRequestFunc func(*base.Request)
|
||||||
|
|
||||||
|
// ClientOnResponseFunc is the prototype of Client.OnResponse.
|
||||||
|
type ClientOnResponseFunc func(*base.Response)
|
||||||
|
|
||||||
|
// ClientOnTransportSwitchFunc is the prototype of Client.OnTransportSwitch.
|
||||||
|
type ClientOnTransportSwitchFunc func(err error)
|
||||||
|
|
||||||
|
// ClientOnPacketLostFunc is the prototype of Client.OnPacketLost.
|
||||||
|
type ClientOnPacketLostFunc func(err error)
|
||||||
|
|
||||||
|
// ClientOnDecodeErrorFunc is the prototype of Client.OnDecodeError.
|
||||||
|
type ClientOnDecodeErrorFunc func(err error)
|
||||||
|
|
||||||
|
// OnPacketRTPFunc is the prototype of the callback passed to OnPacketRTP().
|
||||||
|
type OnPacketRTPFunc func(*rtp.Packet)
|
||||||
|
|
||||||
|
// OnPacketRTPAnyFunc is the prototype of the callback passed to OnPacketRTP(Any).
|
||||||
|
type OnPacketRTPAnyFunc func(*media.Media, formats.Format, *rtp.Packet)
|
||||||
|
|
||||||
|
// OnPacketRTCPFunc is the prototype of the callback passed to OnPacketRTCP().
|
||||||
|
type OnPacketRTCPFunc func(rtcp.Packet)
|
||||||
|
|
||||||
|
// OnPacketRTCPAnyFunc is the prototype of the callback passed to OnPacketRTCPAny().
|
||||||
|
type OnPacketRTCPAnyFunc func(*media.Media, rtcp.Packet)
|
||||||
|
|
||||||
// ClientLogFunc is the prototype of the log function.
|
// ClientLogFunc is the prototype of the log function.
|
||||||
//
|
//
|
||||||
// Deprecated: Log() is deprecated.
|
// Deprecated: Log() is deprecated.
|
||||||
@@ -247,15 +274,15 @@ type Client struct {
|
|||||||
// callbacks (all optional)
|
// callbacks (all optional)
|
||||||
//
|
//
|
||||||
// called before every request.
|
// called before every request.
|
||||||
OnRequest func(*base.Request)
|
OnRequest ClientOnRequestFunc
|
||||||
// called after every response.
|
// called after every response.
|
||||||
OnResponse func(*base.Response)
|
OnResponse ClientOnResponseFunc
|
||||||
// called when the transport protocol changes.
|
// called when the transport protocol changes.
|
||||||
OnTransportSwitch func(err error)
|
OnTransportSwitch ClientOnTransportSwitchFunc
|
||||||
// called when the client detects lost packets.
|
// called when the client detects lost packets.
|
||||||
OnPacketLost func(err error)
|
OnPacketLost ClientOnPacketLostFunc
|
||||||
// called when a non-fatal decode error occurs.
|
// called when a non-fatal decode error occurs.
|
||||||
OnDecodeError func(err error)
|
OnDecodeError ClientOnDecodeErrorFunc
|
||||||
// Deprecated: replaced by OnTransportSwitch, OnPacketLost, OnDecodeError
|
// Deprecated: replaced by OnTransportSwitch, OnPacketLost, OnDecodeError
|
||||||
Log ClientLogFunc
|
Log ClientLogFunc
|
||||||
|
|
||||||
@@ -1608,7 +1635,7 @@ func (c *Client) Seek(ra *headers.Range) (*base.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTPAny sets the callback that is called when a RTP packet is read from any setupped media.
|
// OnPacketRTPAny sets the callback that is called when a RTP packet is read from any setupped media.
|
||||||
func (c *Client) OnPacketRTPAny(cb func(*media.Media, formats.Format, *rtp.Packet)) {
|
func (c *Client) OnPacketRTPAny(cb OnPacketRTPAnyFunc) {
|
||||||
for _, cm := range c.medias {
|
for _, cm := range c.medias {
|
||||||
cmedia := cm.media
|
cmedia := cm.media
|
||||||
for _, forma := range cm.media.Formats {
|
for _, forma := range cm.media.Formats {
|
||||||
@@ -1620,7 +1647,7 @@ func (c *Client) OnPacketRTPAny(cb func(*media.Media, formats.Format, *rtp.Packe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTCPAny sets the callback that is called when a RTCP packet is read from any setupped media.
|
// OnPacketRTCPAny sets the callback that is called when a RTCP packet is read from any setupped media.
|
||||||
func (c *Client) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
|
func (c *Client) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc) {
|
||||||
for _, cm := range c.medias {
|
for _, cm := range c.medias {
|
||||||
cmedia := cm.media
|
cmedia := cm.media
|
||||||
c.OnPacketRTCP(cm.media, func(pkt rtcp.Packet) {
|
c.OnPacketRTCP(cm.media, func(pkt rtcp.Packet) {
|
||||||
@@ -1630,14 +1657,14 @@ func (c *Client) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTP sets the callback that is called when a RTP packet is read.
|
// OnPacketRTP sets the callback that is called when a RTP packet is read.
|
||||||
func (c *Client) OnPacketRTP(medi *media.Media, forma formats.Format, cb func(*rtp.Packet)) {
|
func (c *Client) OnPacketRTP(medi *media.Media, forma formats.Format, cb OnPacketRTPFunc) {
|
||||||
cm := c.medias[medi]
|
cm := c.medias[medi]
|
||||||
ct := cm.formats[forma.PayloadType()]
|
ct := cm.formats[forma.PayloadType()]
|
||||||
ct.onPacketRTP = cb
|
ct.onPacketRTP = cb
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTCP sets the callback that is called when a RTCP packet is read.
|
// OnPacketRTCP sets the callback that is called when a RTCP packet is read.
|
||||||
func (c *Client) OnPacketRTCP(medi *media.Media, cb func(rtcp.Packet)) {
|
func (c *Client) OnPacketRTCP(medi *media.Media, cb OnPacketRTCPFunc) {
|
||||||
cm := c.medias[medi]
|
cm := c.medias[medi]
|
||||||
cm.onPacketRTCP = cb
|
cm.onPacketRTCP = cb
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ type clientFormat struct {
|
|||||||
udpRTCPReceiver *rtcpreceiver.RTCPReceiver // play
|
udpRTCPReceiver *rtcpreceiver.RTCPReceiver // play
|
||||||
tcpLossDetector *rtplossdetector.LossDetector // play
|
tcpLossDetector *rtplossdetector.LossDetector // play
|
||||||
rtcpSender *rtcpsender.RTCPSender // record
|
rtcpSender *rtcpsender.RTCPSender // record
|
||||||
onPacketRTP func(*rtp.Packet)
|
onPacketRTP OnPacketRTPFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClientFormat(cm *clientMedia, forma formats.Format) *clientFormat {
|
func newClientFormat(cm *clientMedia, forma formats.Format) *clientFormat {
|
||||||
|
@@ -24,7 +24,7 @@ type clientMedia struct {
|
|||||||
tcpBuffer []byte
|
tcpBuffer []byte
|
||||||
writePacketRTPInQueue func([]byte)
|
writePacketRTPInQueue func([]byte)
|
||||||
writePacketRTCPInQueue func([]byte)
|
writePacketRTCPInQueue func([]byte)
|
||||||
onPacketRTCP func(rtcp.Packet)
|
onPacketRTCP OnPacketRTCPFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClientMedia(c *Client) *clientMedia {
|
func newClientMedia(c *Client) *clientMedia {
|
||||||
|
@@ -1131,7 +1131,7 @@ func (ss *ServerSession) findFreeChannelPair() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTPAny sets the callback that is called when a RTP packet is read from any setupped media.
|
// OnPacketRTPAny sets the callback that is called when a RTP packet is read from any setupped media.
|
||||||
func (ss *ServerSession) OnPacketRTPAny(cb func(*media.Media, formats.Format, *rtp.Packet)) {
|
func (ss *ServerSession) OnPacketRTPAny(cb OnPacketRTPAnyFunc) {
|
||||||
for _, sm := range ss.setuppedMedias {
|
for _, sm := range ss.setuppedMedias {
|
||||||
cmedia := sm.media
|
cmedia := sm.media
|
||||||
for _, forma := range sm.media.Formats {
|
for _, forma := range sm.media.Formats {
|
||||||
@@ -1143,7 +1143,7 @@ func (ss *ServerSession) OnPacketRTPAny(cb func(*media.Media, formats.Format, *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTCPAny sets the callback that is called when a RTCP packet is read from any setupped media.
|
// OnPacketRTCPAny sets the callback that is called when a RTCP packet is read from any setupped media.
|
||||||
func (ss *ServerSession) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
|
func (ss *ServerSession) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc) {
|
||||||
for _, sm := range ss.setuppedMedias {
|
for _, sm := range ss.setuppedMedias {
|
||||||
cmedia := sm.media
|
cmedia := sm.media
|
||||||
ss.OnPacketRTCP(sm.media, func(pkt rtcp.Packet) {
|
ss.OnPacketRTCP(sm.media, func(pkt rtcp.Packet) {
|
||||||
@@ -1153,14 +1153,14 @@ func (ss *ServerSession) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTP sets the callback that is called when a RTP packet is read.
|
// OnPacketRTP sets the callback that is called when a RTP packet is read.
|
||||||
func (ss *ServerSession) OnPacketRTP(medi *media.Media, forma formats.Format, cb func(*rtp.Packet)) {
|
func (ss *ServerSession) OnPacketRTP(medi *media.Media, forma formats.Format, cb OnPacketRTPFunc) {
|
||||||
sm := ss.setuppedMedias[medi]
|
sm := ss.setuppedMedias[medi]
|
||||||
st := sm.formats[forma.PayloadType()]
|
st := sm.formats[forma.PayloadType()]
|
||||||
st.onPacketRTP = cb
|
st.onPacketRTP = cb
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnPacketRTCP sets the callback that is called when a RTCP packet is read.
|
// OnPacketRTCP sets the callback that is called when a RTCP packet is read.
|
||||||
func (ss *ServerSession) OnPacketRTCP(medi *media.Media, cb func(rtcp.Packet)) {
|
func (ss *ServerSession) OnPacketRTCP(medi *media.Media, cb OnPacketRTCPFunc) {
|
||||||
sm := ss.setuppedMedias[medi]
|
sm := ss.setuppedMedias[medi]
|
||||||
sm.onPacketRTCP = cb
|
sm.onPacketRTCP = cb
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ type serverSessionFormat struct {
|
|||||||
udpReorderer *rtpreorderer.Reorderer
|
udpReorderer *rtpreorderer.Reorderer
|
||||||
tcpLossDetector *rtplossdetector.LossDetector
|
tcpLossDetector *rtplossdetector.LossDetector
|
||||||
udpRTCPReceiver *rtcpreceiver.RTCPReceiver
|
udpRTCPReceiver *rtcpreceiver.RTCPReceiver
|
||||||
onPacketRTP func(*rtp.Packet)
|
onPacketRTP OnPacketRTPFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func newServerSessionFormat(sm *serverSessionMedia, forma formats.Format) *serverSessionFormat {
|
func newServerSessionFormat(sm *serverSessionMedia, forma formats.Format) *serverSessionFormat {
|
||||||
|
@@ -27,7 +27,7 @@ type serverSessionMedia struct {
|
|||||||
formats map[uint8]*serverSessionFormat // record only
|
formats map[uint8]*serverSessionFormat // record only
|
||||||
writePacketRTPInQueue func([]byte)
|
writePacketRTPInQueue func([]byte)
|
||||||
writePacketRTCPInQueue func([]byte)
|
writePacketRTCPInQueue func([]byte)
|
||||||
onPacketRTCP func(rtcp.Packet)
|
onPacketRTCP OnPacketRTCPFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func newServerSessionMedia(ss *ServerSession, medi *media.Media) *serverSessionMedia {
|
func newServerSessionMedia(ss *ServerSession, medi *media.Media) *serverSessionMedia {
|
||||||
|
Reference in New Issue
Block a user