Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export callback prototypes #333

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion client_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion client_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions server_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@
}

// 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) {

Check warning on line 1134 in server_session.go

View check run for this annotation

Codecov / codecov/patch

server_session.go#L1134

Added line #L1134 was not covered by tests
for _, sm := range ss.setuppedMedias {
cmedia := sm.media
for _, forma := range sm.media.Formats {
Expand All @@ -1143,7 +1143,7 @@
}

// 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) {
Expand All @@ -1153,14 +1153,14 @@
}

// 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
}
Expand Down
2 changes: 1 addition & 1 deletion server_session_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server_session_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading