rename OnPacketLost2 into OnPacketsLost (#736)

This commit is contained in:
Alessandro Ros
2025-03-24 18:42:48 +01:00
committed by GitHub
parent c0c275e6a6
commit 61372cfa68
9 changed files with 43 additions and 33 deletions

View File

@@ -218,11 +218,11 @@ type ClientOnTransportSwitchFunc func(err error)
// ClientOnPacketLostFunc is the prototype of Client.OnPacketLost.
//
// Deprecated: replaced by ClientOnPacketLost2Func
// Deprecated: replaced by ClientOnPacketsLostFunc
type ClientOnPacketLostFunc func(err error)
// ClientOnPacketLost2Func is the prototype of Client.OnPacketLost2.
type ClientOnPacketLost2Func func(lost uint64)
// ClientOnPacketsLostFunc is the prototype of Client.OnPacketsLost.
type ClientOnPacketsLostFunc func(lost uint64)
// ClientOnDecodeErrorFunc is the prototype of Client.OnDecodeError.
type ClientOnDecodeErrorFunc func(err error)
@@ -314,10 +314,10 @@ type Client struct {
OnTransportSwitch ClientOnTransportSwitchFunc
// called when the client detects lost packets.
//
// Deprecated: replaced by OnPacketLost2.
// Deprecated: replaced by OnPacketsLost
OnPacketLost ClientOnPacketLostFunc
// called when the client detects lost packets.
OnPacketLost2 ClientOnPacketLost2Func
OnPacketsLost ClientOnPacketsLostFunc
// called when a non-fatal decode error occurs.
OnDecodeError ClientOnDecodeErrorFunc
@@ -435,12 +435,12 @@ func (c *Client) Start(scheme string, host string) error {
}
}
if c.OnPacketLost != nil {
c.OnPacketLost2 = func(lost uint64) {
c.OnPacketsLost = func(lost uint64) {
c.OnPacketLost(liberrors.ErrClientRTPPacketsLost{Lost: uint(lost)}) //nolint:staticcheck
}
}
if c.OnPacketLost2 == nil {
c.OnPacketLost2 = func(lost uint64) {
if c.OnPacketsLost == nil {
c.OnPacketsLost = func(lost uint64) {
log.Printf("%d RTP %s lost",
lost,
func() string {

View File

@@ -93,7 +93,7 @@ func (cf *clientFormat) stop() {
func (cf *clientFormat) readPacketRTPUDP(pkt *rtp.Packet) {
packets, lost := cf.udpReorderer.Process(pkt)
if lost != 0 {
cf.onPacketRTPLost(lost)
cf.handlePacketsLost(lost)
// do not return
}
@@ -107,7 +107,7 @@ func (cf *clientFormat) readPacketRTPUDP(pkt *rtp.Packet) {
func (cf *clientFormat) readPacketRTPTCP(pkt *rtp.Packet) {
lost := cf.tcpLossDetector.Process(pkt)
if lost != 0 {
cf.onPacketRTPLost(lost)
cf.handlePacketsLost(lost)
// do not return
}
@@ -128,9 +128,9 @@ func (cf *clientFormat) handlePacketRTP(pkt *rtp.Packet, now time.Time) {
cf.onPacketRTP(pkt)
}
func (cf *clientFormat) onPacketRTPLost(lost uint64) {
func (cf *clientFormat) handlePacketsLost(lost uint64) {
atomic.AddUint64(cf.rtpPacketsLost, lost)
cf.cm.c.OnPacketLost2(lost)
cf.cm.c.OnPacketsLost(lost)
}
func (cf *clientFormat) writePacketRTPInQueueUDP(payload []byte) error {

View File

@@ -3144,8 +3144,8 @@ func TestClientPlayDecodeErrors(t *testing.T) {
v := TransportTCP
return &v
}(),
OnPacketLost: func(err error) {
require.EqualError(t, err, "69 RTP packets lost")
OnPacketsLost: func(lost uint64) {
require.Equal(t, uint64(69), lost)
close(errorRecv)
},
OnDecodeError: func(err error) {

View File

@@ -159,7 +159,7 @@ func TestRTCPReceiverOverflow(t *testing.T) {
<-done
}
func TestRTCPReceiverPacketLost(t *testing.T) {
func TestRTCPReceiverPacketsLost(t *testing.T) {
done := make(chan struct{})
rr := &RTCPReceiver{
@@ -236,7 +236,7 @@ func TestRTCPReceiverPacketLost(t *testing.T) {
<-done
}
func TestRTCPReceiverOverflowPacketLost(t *testing.T) {
func TestRTCPReceiverOverflowPacketsLost(t *testing.T) {
done := make(chan struct{})
rr := &RTCPReceiver{

View File

@@ -155,7 +155,7 @@ func TestRTCPReceiverOverflow(t *testing.T) {
<-done
}
func TestRTCPReceiverPacketLost(t *testing.T) {
func TestRTCPReceiverPacketsLost(t *testing.T) {
done := make(chan struct{})
rr, err := New(
@@ -230,7 +230,7 @@ func TestRTCPReceiverPacketLost(t *testing.T) {
<-done
}
func TestRTCPReceiverOverflowPacketLost(t *testing.T) {
func TestRTCPReceiverOverflowPacketsLost(t *testing.T) {
done := make(chan struct{})
rr, err := New(

View File

@@ -193,21 +193,33 @@ type ServerHandlerOnSetParameter interface {
}
// ServerHandlerOnPacketLostCtx is the context of OnPacketLost.
//
// Deprecated: replaced by ServerHandlerOnPacketsLostCtx
type ServerHandlerOnPacketLostCtx struct {
Session *ServerSession
Lost uint64
//
// Deprecated: replaced by Lost
Error error
}
// ServerHandlerOnPacketLost can be implemented by a ServerHandler.
//
// Deprecated: replaced by ServerHandlerOnPacketsLost
type ServerHandlerOnPacketLost interface {
// called when the server detects lost packets.
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.
type ServerHandlerOnDecodeErrorCtx struct {
Session *ServerSession

View File

@@ -1259,8 +1259,8 @@ func TestServerRecordDecodeErrors(t *testing.T) {
StatusCode: base.StatusOK,
}, nil
},
onPacketLost: func(ctx *ServerHandlerOnPacketLostCtx) {
require.EqualError(t, ctx.Error, "69 RTP packets lost")
onPacketsLost: func(ctx *ServerHandlerOnPacketsLostCtx) {
require.Equal(t, uint64(69), ctx.Lost)
close(errorRecv)
},
onDecodeError: func(ctx *ServerHandlerOnDecodeErrorCtx) {

View File

@@ -12,7 +12,6 @@ import (
"github.com/bluenviron/gortsplib/v4/internal/rtplossdetector"
"github.com/bluenviron/gortsplib/v4/internal/rtpreorderer"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/liberrors"
)
type serverSessionFormat struct {
@@ -115,11 +114,10 @@ func (sf *serverSessionFormat) handlePacketRTP(pkt *rtp.Packet, now time.Time) {
func (sf *serverSessionFormat) onPacketRTPLost(lost uint64) {
atomic.AddUint64(sf.rtpPacketsLost, lost)
if h, ok := sf.sm.ss.s.Handler.(ServerHandlerOnPacketLost); ok {
h.OnPacketLost(&ServerHandlerOnPacketLostCtx{
if h, ok := sf.sm.ss.s.Handler.(ServerHandlerOnPacketsLost); ok {
h.OnPacketsLost(&ServerHandlerOnPacketsLostCtx{
Session: sf.sm.ss,
Lost: lost,
Error: liberrors.ErrServerRTPPacketsLost{Lost: uint(lost)}, //nolint:staticcheck
})
} else {
log.Printf("%d RTP %s lost",

View File

@@ -96,7 +96,7 @@ type testServerHandler struct {
onPause func(*ServerHandlerOnPauseCtx) (*base.Response, error)
onSetParameter func(*ServerHandlerOnSetParameterCtx) (*base.Response, error)
onGetParameter func(*ServerHandlerOnGetParameterCtx) (*base.Response, error)
onPacketLost func(*ServerHandlerOnPacketLostCtx)
onPacketsLost func(*ServerHandlerOnPacketsLostCtx)
onDecodeError func(*ServerHandlerOnDecodeErrorCtx)
}
@@ -180,9 +180,9 @@ func (sh *testServerHandler) OnGetParameter(ctx *ServerHandlerOnGetParameterCtx)
return nil, fmt.Errorf("unimplemented")
}
func (sh *testServerHandler) OnPacketLost(ctx *ServerHandlerOnPacketLostCtx) {
if sh.onPacketLost != nil {
sh.onPacketLost(ctx)
func (sh *testServerHandler) OnPacketsLost(ctx *ServerHandlerOnPacketsLostCtx) {
if sh.onPacketsLost != nil {
sh.onPacketsLost(ctx)
}
}