From e778488aba1ea84bdd7ad183b625d73ab397516b Mon Sep 17 00:00:00 2001 From: scruzin Date: Mon, 14 Jan 2019 10:17:47 +1030 Subject: [PATCH] Session.inChunkSize, outChunkSize, nBytesIn, nBytesInSent, serverBW, clientBW and clientBW2 now all uint32 to avoid needless conversions. --- rtmp/packet.go | 10 +++++----- rtmp/rtmp.go | 10 +++++----- rtmp/session.go | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rtmp/packet.go b/rtmp/packet.go index 138dd917..b88b15bc 100644 --- a/rtmp/packet.go +++ b/rtmp/packet.go @@ -205,7 +205,7 @@ func (pkt *packet) readFrom(s *Session) error { pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6) } - toRead := int32(pkt.bodySize - pkt.bytesRead) + toRead := pkt.bodySize - pkt.bytesRead chunkSize := s.inChunkSize if toRead < chunkSize { @@ -376,12 +376,12 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { if ts > 0xffffff { tmp = 0xffffff } - amf.EncodeInt24(headBytes[headerIdx:], int32(tmp)) + amf.EncodeInt24(headBytes[headerIdx:], tmp) headerIdx += 3 // 24bits } if headerSizes[pkt.headerType] > 4 { - amf.EncodeInt24(headBytes[headerIdx:], int32(pkt.bodySize)) + amf.EncodeInt24(headBytes[headerIdx:], pkt.bodySize) headerIdx += 3 // 24bits headBytes[headerIdx] = pkt.packetType headerIdx++ @@ -393,7 +393,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { } if ts >= 0xffffff { - amf.EncodeInt32(headBytes[headerIdx:], int32(ts)) + amf.EncodeInt32(headBytes[headerIdx:], ts) headerIdx += 4 // 32bits } @@ -463,7 +463,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { } if ts >= 0xffffff { extendedTimestamp := headBytes[origIdx+1+cSize:] - amf.EncodeInt32(extendedTimestamp[:4], int32(ts)) + amf.EncodeInt32(extendedTimestamp[:4], ts) } } } diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index d0a34e77..c79f8352 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -249,18 +249,18 @@ func handlePacket(s *Session, pkt *packet) error { switch pkt.packetType { case packetTypeChunkSize: - s.inChunkSize = int32(amf.DecodeInt32(pkt.body[:4])) + s.inChunkSize = amf.DecodeInt32(pkt.body[:4]) case packetTypeBytesReadReport: - s.serverBW = int32(amf.DecodeInt32(pkt.body[:4])) + s.serverBW = amf.DecodeInt32(pkt.body[:4]) case packetTypeServerBW: - s.serverBW = int32(amf.DecodeInt32(pkt.body[:4])) + s.serverBW = amf.DecodeInt32(pkt.body[:4]) case packetTypeClientBW: - s.clientBW = int32(amf.DecodeInt32(pkt.body[:4])) + s.clientBW = amf.DecodeInt32(pkt.body[:4]) if pkt.bodySize > 4 { - s.clientBW2 = pkt.body[4] + s.clientBW2 = uint32(pkt.body[4]) } else { s.clientBW2 = 0xff } diff --git a/rtmp/session.go b/rtmp/session.go index f555d00e..766522d5 100644 --- a/rtmp/session.go +++ b/rtmp/session.go @@ -44,14 +44,14 @@ import ( // Session holds the state for an RTMP session. type Session struct { url string - inChunkSize int32 - outChunkSize int32 - nBytesIn int32 - nBytesInSent int32 + inChunkSize uint32 + outChunkSize uint32 + nBytesIn uint32 + nBytesInSent uint32 streamID int32 - serverBW int32 - clientBW int32 - clientBW2 uint8 + serverBW uint32 + clientBW uint32 + clientBW2 uint32 isPlaying bool numInvokes int32 methodCalls []method @@ -207,7 +207,7 @@ func (s *Session) read(buf []byte) (int, error) { s.log(DebugLevel, pkg+"read failed", "error", err.Error()) return 0, err } - s.nBytesIn += int32(n) + s.nBytesIn += uint32(n) if s.nBytesIn > (s.nBytesInSent + s.clientBW/10) { err := sendBytesReceived(s) if err != nil {