mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 23:02:45 +08:00
rename OnPacketLost2 into OnPacketsLost (#736)
This commit is contained in:
16
client.go
16
client.go
@@ -218,11 +218,11 @@ type ClientOnTransportSwitchFunc func(err error)
|
|||||||
|
|
||||||
// ClientOnPacketLostFunc is the prototype of Client.OnPacketLost.
|
// ClientOnPacketLostFunc is the prototype of Client.OnPacketLost.
|
||||||
//
|
//
|
||||||
// Deprecated: replaced by ClientOnPacketLost2Func
|
// Deprecated: replaced by ClientOnPacketsLostFunc
|
||||||
type ClientOnPacketLostFunc func(err error)
|
type ClientOnPacketLostFunc func(err error)
|
||||||
|
|
||||||
// ClientOnPacketLost2Func is the prototype of Client.OnPacketLost2.
|
// ClientOnPacketsLostFunc is the prototype of Client.OnPacketsLost.
|
||||||
type ClientOnPacketLost2Func func(lost uint64)
|
type ClientOnPacketsLostFunc func(lost uint64)
|
||||||
|
|
||||||
// ClientOnDecodeErrorFunc is the prototype of Client.OnDecodeError.
|
// ClientOnDecodeErrorFunc is the prototype of Client.OnDecodeError.
|
||||||
type ClientOnDecodeErrorFunc func(err error)
|
type ClientOnDecodeErrorFunc func(err error)
|
||||||
@@ -314,10 +314,10 @@ type Client struct {
|
|||||||
OnTransportSwitch ClientOnTransportSwitchFunc
|
OnTransportSwitch ClientOnTransportSwitchFunc
|
||||||
// called when the client detects lost packets.
|
// called when the client detects lost packets.
|
||||||
//
|
//
|
||||||
// Deprecated: replaced by OnPacketLost2.
|
// Deprecated: replaced by OnPacketsLost
|
||||||
OnPacketLost ClientOnPacketLostFunc
|
OnPacketLost ClientOnPacketLostFunc
|
||||||
// called when the client detects lost packets.
|
// called when the client detects lost packets.
|
||||||
OnPacketLost2 ClientOnPacketLost2Func
|
OnPacketsLost ClientOnPacketsLostFunc
|
||||||
// called when a non-fatal decode error occurs.
|
// called when a non-fatal decode error occurs.
|
||||||
OnDecodeError ClientOnDecodeErrorFunc
|
OnDecodeError ClientOnDecodeErrorFunc
|
||||||
|
|
||||||
@@ -435,12 +435,12 @@ func (c *Client) Start(scheme string, host string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.OnPacketLost != nil {
|
if c.OnPacketLost != nil {
|
||||||
c.OnPacketLost2 = func(lost uint64) {
|
c.OnPacketsLost = func(lost uint64) {
|
||||||
c.OnPacketLost(liberrors.ErrClientRTPPacketsLost{Lost: uint(lost)}) //nolint:staticcheck
|
c.OnPacketLost(liberrors.ErrClientRTPPacketsLost{Lost: uint(lost)}) //nolint:staticcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.OnPacketLost2 == nil {
|
if c.OnPacketsLost == nil {
|
||||||
c.OnPacketLost2 = func(lost uint64) {
|
c.OnPacketsLost = func(lost uint64) {
|
||||||
log.Printf("%d RTP %s lost",
|
log.Printf("%d RTP %s lost",
|
||||||
lost,
|
lost,
|
||||||
func() string {
|
func() string {
|
||||||
|
@@ -93,7 +93,7 @@ func (cf *clientFormat) stop() {
|
|||||||
func (cf *clientFormat) readPacketRTPUDP(pkt *rtp.Packet) {
|
func (cf *clientFormat) readPacketRTPUDP(pkt *rtp.Packet) {
|
||||||
packets, lost := cf.udpReorderer.Process(pkt)
|
packets, lost := cf.udpReorderer.Process(pkt)
|
||||||
if lost != 0 {
|
if lost != 0 {
|
||||||
cf.onPacketRTPLost(lost)
|
cf.handlePacketsLost(lost)
|
||||||
// do not return
|
// do not return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ func (cf *clientFormat) readPacketRTPUDP(pkt *rtp.Packet) {
|
|||||||
func (cf *clientFormat) readPacketRTPTCP(pkt *rtp.Packet) {
|
func (cf *clientFormat) readPacketRTPTCP(pkt *rtp.Packet) {
|
||||||
lost := cf.tcpLossDetector.Process(pkt)
|
lost := cf.tcpLossDetector.Process(pkt)
|
||||||
if lost != 0 {
|
if lost != 0 {
|
||||||
cf.onPacketRTPLost(lost)
|
cf.handlePacketsLost(lost)
|
||||||
// do not return
|
// do not return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,9 +128,9 @@ func (cf *clientFormat) handlePacketRTP(pkt *rtp.Packet, now time.Time) {
|
|||||||
cf.onPacketRTP(pkt)
|
cf.onPacketRTP(pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cf *clientFormat) onPacketRTPLost(lost uint64) {
|
func (cf *clientFormat) handlePacketsLost(lost uint64) {
|
||||||
atomic.AddUint64(cf.rtpPacketsLost, lost)
|
atomic.AddUint64(cf.rtpPacketsLost, lost)
|
||||||
cf.cm.c.OnPacketLost2(lost)
|
cf.cm.c.OnPacketsLost(lost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cf *clientFormat) writePacketRTPInQueueUDP(payload []byte) error {
|
func (cf *clientFormat) writePacketRTPInQueueUDP(payload []byte) error {
|
||||||
|
@@ -3144,8 +3144,8 @@ func TestClientPlayDecodeErrors(t *testing.T) {
|
|||||||
v := TransportTCP
|
v := TransportTCP
|
||||||
return &v
|
return &v
|
||||||
}(),
|
}(),
|
||||||
OnPacketLost: func(err error) {
|
OnPacketsLost: func(lost uint64) {
|
||||||
require.EqualError(t, err, "69 RTP packets lost")
|
require.Equal(t, uint64(69), lost)
|
||||||
close(errorRecv)
|
close(errorRecv)
|
||||||
},
|
},
|
||||||
OnDecodeError: func(err error) {
|
OnDecodeError: func(err error) {
|
||||||
|
@@ -159,7 +159,7 @@ func TestRTCPReceiverOverflow(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRTCPReceiverPacketLost(t *testing.T) {
|
func TestRTCPReceiverPacketsLost(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
rr := &RTCPReceiver{
|
rr := &RTCPReceiver{
|
||||||
@@ -236,7 +236,7 @@ func TestRTCPReceiverPacketLost(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRTCPReceiverOverflowPacketLost(t *testing.T) {
|
func TestRTCPReceiverOverflowPacketsLost(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
rr := &RTCPReceiver{
|
rr := &RTCPReceiver{
|
||||||
|
@@ -155,7 +155,7 @@ func TestRTCPReceiverOverflow(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRTCPReceiverPacketLost(t *testing.T) {
|
func TestRTCPReceiverPacketsLost(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
rr, err := New(
|
rr, err := New(
|
||||||
@@ -230,7 +230,7 @@ func TestRTCPReceiverPacketLost(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRTCPReceiverOverflowPacketLost(t *testing.T) {
|
func TestRTCPReceiverOverflowPacketsLost(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
rr, err := New(
|
rr, err := New(
|
||||||
|
@@ -193,21 +193,33 @@ type ServerHandlerOnSetParameter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerHandlerOnPacketLostCtx is the context of OnPacketLost.
|
// ServerHandlerOnPacketLostCtx is the context of OnPacketLost.
|
||||||
|
//
|
||||||
|
// Deprecated: replaced by ServerHandlerOnPacketsLostCtx
|
||||||
type ServerHandlerOnPacketLostCtx struct {
|
type ServerHandlerOnPacketLostCtx struct {
|
||||||
Session *ServerSession
|
Session *ServerSession
|
||||||
Lost uint64
|
Error error
|
||||||
|
|
||||||
//
|
|
||||||
// Deprecated: replaced by Lost
|
|
||||||
Error error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerHandlerOnPacketLost can be implemented by a ServerHandler.
|
// ServerHandlerOnPacketLost can be implemented by a ServerHandler.
|
||||||
|
//
|
||||||
|
// Deprecated: replaced by ServerHandlerOnPacketsLost
|
||||||
type ServerHandlerOnPacketLost interface {
|
type ServerHandlerOnPacketLost interface {
|
||||||
// called when the server detects lost packets.
|
// called when the server detects lost packets.
|
||||||
OnPacketLost(*ServerHandlerOnPacketLostCtx)
|
OnPacketLost(*ServerHandlerOnPacketLostCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServerHandlerOnPacketsLostCtx is the context of OnPacketsLost.
|
||||||
|
type ServerHandlerOnPacketsLostCtx struct {
|
||||||
|
Session *ServerSession
|
||||||
|
Lost uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerHandlerOnPacketsLost can be implemented by a ServerHandler.
|
||||||
|
type ServerHandlerOnPacketsLost interface {
|
||||||
|
// called when the server detects lost packets.
|
||||||
|
OnPacketsLost(*ServerHandlerOnPacketsLostCtx)
|
||||||
|
}
|
||||||
|
|
||||||
// ServerHandlerOnDecodeErrorCtx is the context of OnDecodeError.
|
// ServerHandlerOnDecodeErrorCtx is the context of OnDecodeError.
|
||||||
type ServerHandlerOnDecodeErrorCtx struct {
|
type ServerHandlerOnDecodeErrorCtx struct {
|
||||||
Session *ServerSession
|
Session *ServerSession
|
||||||
|
@@ -1259,8 +1259,8 @@ func TestServerRecordDecodeErrors(t *testing.T) {
|
|||||||
StatusCode: base.StatusOK,
|
StatusCode: base.StatusOK,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
onPacketLost: func(ctx *ServerHandlerOnPacketLostCtx) {
|
onPacketsLost: func(ctx *ServerHandlerOnPacketsLostCtx) {
|
||||||
require.EqualError(t, ctx.Error, "69 RTP packets lost")
|
require.Equal(t, uint64(69), ctx.Lost)
|
||||||
close(errorRecv)
|
close(errorRecv)
|
||||||
},
|
},
|
||||||
onDecodeError: func(ctx *ServerHandlerOnDecodeErrorCtx) {
|
onDecodeError: func(ctx *ServerHandlerOnDecodeErrorCtx) {
|
||||||
|
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/bluenviron/gortsplib/v4/internal/rtplossdetector"
|
"github.com/bluenviron/gortsplib/v4/internal/rtplossdetector"
|
||||||
"github.com/bluenviron/gortsplib/v4/internal/rtpreorderer"
|
"github.com/bluenviron/gortsplib/v4/internal/rtpreorderer"
|
||||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||||
"github.com/bluenviron/gortsplib/v4/pkg/liberrors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type serverSessionFormat struct {
|
type serverSessionFormat struct {
|
||||||
@@ -115,11 +114,10 @@ func (sf *serverSessionFormat) handlePacketRTP(pkt *rtp.Packet, now time.Time) {
|
|||||||
func (sf *serverSessionFormat) onPacketRTPLost(lost uint64) {
|
func (sf *serverSessionFormat) onPacketRTPLost(lost uint64) {
|
||||||
atomic.AddUint64(sf.rtpPacketsLost, lost)
|
atomic.AddUint64(sf.rtpPacketsLost, lost)
|
||||||
|
|
||||||
if h, ok := sf.sm.ss.s.Handler.(ServerHandlerOnPacketLost); ok {
|
if h, ok := sf.sm.ss.s.Handler.(ServerHandlerOnPacketsLost); ok {
|
||||||
h.OnPacketLost(&ServerHandlerOnPacketLostCtx{
|
h.OnPacketsLost(&ServerHandlerOnPacketsLostCtx{
|
||||||
Session: sf.sm.ss,
|
Session: sf.sm.ss,
|
||||||
Lost: lost,
|
Lost: lost,
|
||||||
Error: liberrors.ErrServerRTPPacketsLost{Lost: uint(lost)}, //nolint:staticcheck
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%d RTP %s lost",
|
log.Printf("%d RTP %s lost",
|
||||||
|
@@ -96,7 +96,7 @@ type testServerHandler struct {
|
|||||||
onPause func(*ServerHandlerOnPauseCtx) (*base.Response, error)
|
onPause func(*ServerHandlerOnPauseCtx) (*base.Response, error)
|
||||||
onSetParameter func(*ServerHandlerOnSetParameterCtx) (*base.Response, error)
|
onSetParameter func(*ServerHandlerOnSetParameterCtx) (*base.Response, error)
|
||||||
onGetParameter func(*ServerHandlerOnGetParameterCtx) (*base.Response, error)
|
onGetParameter func(*ServerHandlerOnGetParameterCtx) (*base.Response, error)
|
||||||
onPacketLost func(*ServerHandlerOnPacketLostCtx)
|
onPacketsLost func(*ServerHandlerOnPacketsLostCtx)
|
||||||
onDecodeError func(*ServerHandlerOnDecodeErrorCtx)
|
onDecodeError func(*ServerHandlerOnDecodeErrorCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,9 +180,9 @@ func (sh *testServerHandler) OnGetParameter(ctx *ServerHandlerOnGetParameterCtx)
|
|||||||
return nil, fmt.Errorf("unimplemented")
|
return nil, fmt.Errorf("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *testServerHandler) OnPacketLost(ctx *ServerHandlerOnPacketLostCtx) {
|
func (sh *testServerHandler) OnPacketsLost(ctx *ServerHandlerOnPacketsLostCtx) {
|
||||||
if sh.onPacketLost != nil {
|
if sh.onPacketsLost != nil {
|
||||||
sh.onPacketLost(ctx)
|
sh.onPacketsLost(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user