mirror of
https://github.com/aler9/gortsplib
synced 2025-10-01 21:42:07 +08:00
add BytesSent to ServerStream (#457)
* add BytesSent to ServerStream (to allow MediaMTX to gather bytes sent on all paths) * improve performance * add test --------- Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
35bf96c5ec
commit
0933bf9975
@@ -1,6 +1,7 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pion/rtcp"
|
||||
@@ -39,6 +40,8 @@ func newServerStreamFormat(sm *serverStreamMedia, forma format.Format) *serverSt
|
||||
func (sf *serverStreamFormat) writePacketRTP(byts []byte, pkt *rtp.Packet, ntp time.Time) error {
|
||||
sf.rtcpSender.ProcessPacket(pkt, ntp, sf.format.PTSEqualsDTS(pkt))
|
||||
|
||||
le := uint64(len(byts))
|
||||
|
||||
// send unicast
|
||||
for r := range sf.sm.st.activeUnicastReaders {
|
||||
sm, ok := r.setuppedMedias[sf.sm.media]
|
||||
@@ -46,6 +49,8 @@ func (sf *serverStreamFormat) writePacketRTP(byts []byte, pkt *rtp.Packet, ntp t
|
||||
err := sm.writePacketRTP(byts)
|
||||
if err != nil {
|
||||
r.onStreamWriteError(err)
|
||||
} else {
|
||||
atomic.AddUint64(sf.sm.st.bytesSent, le)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +61,7 @@ func (sf *serverStreamFormat) writePacketRTP(byts []byte, pkt *rtp.Packet, ntp t
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
atomic.AddUint64(sf.sm.st.bytesSent, le)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user