Repository: bluenviron/gortsplib
Pull request #736 (2025-03-24 17:39:05)

rename OnPacketLost2 into OnPacketsLost

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/bluenviron/gortsplib/pull/736?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) Report
Attention: Patch coverage is `88.88889%` with `1 line` in your changes missing coverage. Please review.
> Project coverage is 82.02%. Comparing base [(`c0c275e`)](https://app.codecov.io/gh/bluenviron/gortsplib/commit/c0c275e6a6c448e90c8850a58e89dacd0ddcd9e5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) to head [(`98e068c`)](https://app.codecov.io/gh/bluenviron/gortsplib/commit/98e068c52cff709a01668d041cfde415acadd7ce?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron).

| [Files with missing lines](https://app.codecov.io/gh/bluenviron/gortsplib/pull/736?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) | Patch % | Lines |
|---|---|---|
| [client.go](https://app.codecov.io/gh/bluenviron/gortsplib/pull/736?src=pr&el=tree&filepath=client.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron#diff-Y2xpZW50Lmdv) | 66.66% | [1 Missing :warning: ](https://app.codecov.io/gh/bluenviron/gortsplib/pull/736?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #736      +/-   ##
==========================================
- Coverage   82.05%   82.02%   -0.04%     
==========================================
  Files         121      121              
  Lines       12555    12554       -1     
==========================================
- Hits        10302    10297       -5     
- Misses       1837     1840       +3     
- Partials      416      417       +1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/bluenviron/gortsplib/pull/736?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bluenviron).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/client.go b/client.go
index bdfad137..c6893394 100644
--- a/client.go
+++ b/client.go
@@ -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 {
diff --git a/client_format.go b/client_format.go
index 828e1cbd..450ac38b 100644
--- a/client_format.go
+++ b/client_format.go
@@ -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 {
diff --git a/server_handler.go b/server_handler.go
index 7706aec4..389dcc16 100644
--- a/server_handler.go
+++ b/server_handler.go
@@ -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
+	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
diff --git a/server_session_format.go b/server_session_format.go
index 106a8195..682714d9 100644
--- a/server_session_format.go
+++ b/server_session_format.go
@@ -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",


Test patch:
diff --git a/client_play_test.go b/client_play_test.go
index 73ceb068..895785c2 100644
--- a/client_play_test.go
+++ b/client_play_test.go
@@ -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) {
diff --git a/internal/rtcpreceiver/rtcpreceiver_test.go b/internal/rtcpreceiver/rtcpreceiver_test.go
index e228328d..0a351a39 100644
--- a/internal/rtcpreceiver/rtcpreceiver_test.go
+++ b/internal/rtcpreceiver/rtcpreceiver_test.go
@@ -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{
diff --git a/pkg/rtcpreceiver/rtcpreceiver_test.go b/pkg/rtcpreceiver/rtcpreceiver_test.go
index 36570516..37ac1375 100644
--- a/pkg/rtcpreceiver/rtcpreceiver_test.go
+++ b/pkg/rtcpreceiver/rtcpreceiver_test.go
@@ -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(
diff --git a/server_record_test.go b/server_record_test.go
index e1dc813d..98885171 100644
--- a/server_record_test.go
+++ b/server_record_test.go
@@ -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) {
diff --git a/server_test.go b/server_test.go
index 4e2a8916..4a5af334 100644
--- a/server_test.go
+++ b/server_test.go
@@ -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)
 	}
 }