From 0cfbb1fb30be974b7c4b36dfa34b3a2ad464e18a Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 25 Aug 2022 22:44:13 +0200 Subject: [PATCH] server: send RTCP sender reports to TCP clients too this allows Nvidia Deepstream to compute NTP timestamp of frames (https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_NTP_Timestamp.html) --- serverstream.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/serverstream.go b/serverstream.go index bc514e87..119cb766 100644 --- a/serverstream.go +++ b/serverstream.go @@ -130,11 +130,17 @@ func (st *ServerStream) readerAdd( for trackID, track := range st.stTracks { cTrackID := trackID + + // always generate RTCP sender reports. + // they're mandatory needed when transport protocol is UDP or UDP-multicast. + // they're also needed when transport protocol is TCP and client is Nvidia Deepstream + // since they're used to compute NTP timestamp of frames: + // https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_NTP_Timestamp.html track.udpRTCPSender = rtcpsender.New( st.s.udpSenderReportPeriod, st.tracks[trackID].ClockRate(), func(pkt rtcp.Packet) { - st.writePacketRTCPSenderReport(cTrackID, pkt) + st.WritePacketRTCP(cTrackID, pkt) }, ) } @@ -289,25 +295,3 @@ func (st *ServerStream) WritePacketRTCP(trackID int, pkt rtcp.Packet) { st.serverMulticastHandlers[trackID].writePacketRTCP(byts) } } - -func (st *ServerStream) writePacketRTCPSenderReport(trackID int, pkt rtcp.Packet) { - byts, err := pkt.Marshal() - if err != nil { - return - } - - st.mutex.RLock() - defer st.mutex.RUnlock() - - // send unicast (UDP only) - for r := range st.readersUnicast { - if *r.setuppedTransport == TransportUDP { - r.writePacketRTCP(trackID, byts) - } - } - - // send multicast - if st.serverMulticastHandlers != nil { - st.serverMulticastHandlers[trackID].writePacketRTCP(byts) - } -}