mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 06:46:42 +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
@@ -2,6 +2,7 @@ package gortsplib
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pion/rtcp"
|
||||
@@ -37,6 +38,7 @@ type ServerStream struct {
|
||||
activeUnicastReaders map[*ServerSession]struct{}
|
||||
streamMedias map[*description.Media]*serverStreamMedia
|
||||
closed bool
|
||||
bytesSent *uint64
|
||||
}
|
||||
|
||||
// NewServerStream allocates a ServerStream.
|
||||
@@ -46,6 +48,7 @@ func NewServerStream(s *Server, desc *description.Session) *ServerStream {
|
||||
desc: desc,
|
||||
readers: make(map[*ServerSession]struct{}),
|
||||
activeUnicastReaders: make(map[*ServerSession]struct{}),
|
||||
bytesSent: new(uint64),
|
||||
}
|
||||
|
||||
st.streamMedias = make(map[*description.Media]*serverStreamMedia, len(desc.Medias))
|
||||
@@ -71,6 +74,11 @@ func (st *ServerStream) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
// BytesSent returns the number of written bytes.
|
||||
func (st *ServerStream) BytesSent() uint64 {
|
||||
return atomic.LoadUint64(st.bytesSent)
|
||||
}
|
||||
|
||||
// Description returns the description of the stream.
|
||||
func (st *ServerStream) Description() *description.Session {
|
||||
return st.desc
|
||||
|
Reference in New Issue
Block a user