export callback prototypes (#333)

This commit is contained in:
Alessandro Ros
2023-07-28 21:05:10 +02:00
committed by GitHub
parent 053cd9ba3e
commit ed536f1d63
6 changed files with 44 additions and 17 deletions

View File

@@ -180,6 +180,33 @@ type clientRes struct {
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.
//
// Deprecated: Log() is deprecated.
@@ -247,15 +274,15 @@ type Client struct {
// callbacks (all optional)
//
// called before every request.
OnRequest func(*base.Request)
OnRequest ClientOnRequestFunc
// called after every response.
OnResponse func(*base.Response)
OnResponse ClientOnResponseFunc
// called when the transport protocol changes.
OnTransportSwitch func(err error)
OnTransportSwitch ClientOnTransportSwitchFunc
// called when the client detects lost packets.
OnPacketLost func(err error)
OnPacketLost ClientOnPacketLostFunc
// called when a non-fatal decode error occurs.
OnDecodeError func(err error)
OnDecodeError ClientOnDecodeErrorFunc
// Deprecated: replaced by OnTransportSwitch, OnPacketLost, OnDecodeError
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.
func (c *Client) OnPacketRTPAny(cb func(*media.Media, formats.Format, *rtp.Packet)) {
func (c *Client) OnPacketRTPAny(cb OnPacketRTPAnyFunc) {
for _, cm := range c.medias {
cmedia := cm.media
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.
func (c *Client) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
func (c *Client) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc) {
for _, cm := range c.medias {
cmedia := cm.media
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.
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]
ct := cm.formats[forma.PayloadType()]
ct.onPacketRTP = cb
}
// 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.onPacketRTCP = cb
}

View File

@@ -22,7 +22,7 @@ type clientFormat struct {
udpRTCPReceiver *rtcpreceiver.RTCPReceiver // play
tcpLossDetector *rtplossdetector.LossDetector // play
rtcpSender *rtcpsender.RTCPSender // record
onPacketRTP func(*rtp.Packet)
onPacketRTP OnPacketRTPFunc
}
func newClientFormat(cm *clientMedia, forma formats.Format) *clientFormat {

View File

@@ -24,7 +24,7 @@ type clientMedia struct {
tcpBuffer []byte
writePacketRTPInQueue func([]byte)
writePacketRTCPInQueue func([]byte)
onPacketRTCP func(rtcp.Packet)
onPacketRTCP OnPacketRTCPFunc
}
func newClientMedia(c *Client) *clientMedia {

View File

@@ -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.
func (ss *ServerSession) OnPacketRTPAny(cb func(*media.Media, formats.Format, *rtp.Packet)) {
func (ss *ServerSession) OnPacketRTPAny(cb OnPacketRTPAnyFunc) {
for _, sm := range ss.setuppedMedias {
cmedia := sm.media
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.
func (ss *ServerSession) OnPacketRTCPAny(cb func(*media.Media, rtcp.Packet)) {
func (ss *ServerSession) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc) {
for _, sm := range ss.setuppedMedias {
cmedia := sm.media
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.
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]
st := sm.formats[forma.PayloadType()]
st.onPacketRTP = cb
}
// 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.onPacketRTCP = cb
}

View File

@@ -19,7 +19,7 @@ type serverSessionFormat struct {
udpReorderer *rtpreorderer.Reorderer
tcpLossDetector *rtplossdetector.LossDetector
udpRTCPReceiver *rtcpreceiver.RTCPReceiver
onPacketRTP func(*rtp.Packet)
onPacketRTP OnPacketRTPFunc
}
func newServerSessionFormat(sm *serverSessionMedia, forma formats.Format) *serverSessionFormat {

View File

@@ -27,7 +27,7 @@ type serverSessionMedia struct {
formats map[uint8]*serverSessionFormat // record only
writePacketRTPInQueue func([]byte)
writePacketRTCPInQueue func([]byte)
onPacketRTCP func(rtcp.Packet)
onPacketRTCP OnPacketRTCPFunc
}
func newServerSessionMedia(ss *ServerSession, medi *media.Media) *serverSessionMedia {