Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BytesSent duplicate counted? #612

Open
SijmenHuizenga opened this issue Sep 2, 2024 · 0 comments
Open

BytesSent duplicate counted? #612

SijmenHuizenga opened this issue Sep 2, 2024 · 0 comments

Comments

@SijmenHuizenga
Copy link

I'm reading the code related to the the BytesSent variable in client

Whenever a packet needs to be sent out, it goes through here, where the BytesSent value is increased:

gortsplib/client_media.go

Lines 165 to 170 in c465264

func (cm *clientMedia) writePacketRTPInQueueTCP(payload []byte) {
atomic.AddUint64(cm.c.BytesSent, uint64(len(payload)))
cm.tcpRTPFrame.Payload = payload
cm.c.nconn.SetWriteDeadline(time.Now().Add(cm.c.WriteTimeout))
cm.c.conn.WriteInterleavedFrame(cm.tcpRTPFrame, cm.tcpBuffer) //nolint:errcheck
}

But the cm.c.conn is already wrapped in a bytecounter:

gortsplib/client.go

Lines 885 to 892 in c465264

bc := bytecounter.New(c.nconn, c.BytesReceived, c.BytesSent)
c.conn = conn.NewConn(bc)
c.reader = &clientReader{
c: c,
}
c.reader.start()
return nil

Which also counts the bytes:

func (bc *ByteCounter) Write(p []byte) (int, error) {
n, err := bc.rw.Write(p)
atomic.AddUint64(bc.sent, uint64(n))
return n, err

To me it seems like every byte is counted twice, or am I overlooking something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant