Session.inChunkSize, outChunkSize, nBytesIn, nBytesInSent, serverBW, clientBW and clientBW2 now all uint32 to avoid needless conversions.

This commit is contained in:
scruzin 2019-01-14 10:17:47 +10:30
parent b680e3e164
commit e778488aba
3 changed files with 18 additions and 18 deletions

View File

@ -205,7 +205,7 @@ func (pkt *packet) readFrom(s *Session) error {
pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6) pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6)
} }
toRead := int32(pkt.bodySize - pkt.bytesRead) toRead := pkt.bodySize - pkt.bytesRead
chunkSize := s.inChunkSize chunkSize := s.inChunkSize
if toRead < chunkSize { if toRead < chunkSize {
@ -376,12 +376,12 @@ func (pkt *packet) writeTo(s *Session, queue bool) error {
if ts > 0xffffff { if ts > 0xffffff {
tmp = 0xffffff tmp = 0xffffff
} }
amf.EncodeInt24(headBytes[headerIdx:], int32(tmp)) amf.EncodeInt24(headBytes[headerIdx:], tmp)
headerIdx += 3 // 24bits headerIdx += 3 // 24bits
} }
if headerSizes[pkt.headerType] > 4 { if headerSizes[pkt.headerType] > 4 {
amf.EncodeInt24(headBytes[headerIdx:], int32(pkt.bodySize)) amf.EncodeInt24(headBytes[headerIdx:], pkt.bodySize)
headerIdx += 3 // 24bits headerIdx += 3 // 24bits
headBytes[headerIdx] = pkt.packetType headBytes[headerIdx] = pkt.packetType
headerIdx++ headerIdx++
@ -393,7 +393,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error {
} }
if ts >= 0xffffff { if ts >= 0xffffff {
amf.EncodeInt32(headBytes[headerIdx:], int32(ts)) amf.EncodeInt32(headBytes[headerIdx:], ts)
headerIdx += 4 // 32bits headerIdx += 4 // 32bits
} }
@ -463,7 +463,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error {
} }
if ts >= 0xffffff { if ts >= 0xffffff {
extendedTimestamp := headBytes[origIdx+1+cSize:] extendedTimestamp := headBytes[origIdx+1+cSize:]
amf.EncodeInt32(extendedTimestamp[:4], int32(ts)) amf.EncodeInt32(extendedTimestamp[:4], ts)
} }
} }
} }

View File

@ -249,18 +249,18 @@ func handlePacket(s *Session, pkt *packet) error {
switch pkt.packetType { switch pkt.packetType {
case packetTypeChunkSize: case packetTypeChunkSize:
s.inChunkSize = int32(amf.DecodeInt32(pkt.body[:4])) s.inChunkSize = amf.DecodeInt32(pkt.body[:4])
case packetTypeBytesReadReport: case packetTypeBytesReadReport:
s.serverBW = int32(amf.DecodeInt32(pkt.body[:4])) s.serverBW = amf.DecodeInt32(pkt.body[:4])
case packetTypeServerBW: case packetTypeServerBW:
s.serverBW = int32(amf.DecodeInt32(pkt.body[:4])) s.serverBW = amf.DecodeInt32(pkt.body[:4])
case packetTypeClientBW: case packetTypeClientBW:
s.clientBW = int32(amf.DecodeInt32(pkt.body[:4])) s.clientBW = amf.DecodeInt32(pkt.body[:4])
if pkt.bodySize > 4 { if pkt.bodySize > 4 {
s.clientBW2 = pkt.body[4] s.clientBW2 = uint32(pkt.body[4])
} else { } else {
s.clientBW2 = 0xff s.clientBW2 = 0xff
} }

View File

@ -44,14 +44,14 @@ import (
// Session holds the state for an RTMP session. // Session holds the state for an RTMP session.
type Session struct { type Session struct {
url string url string
inChunkSize int32 inChunkSize uint32
outChunkSize int32 outChunkSize uint32
nBytesIn int32 nBytesIn uint32
nBytesInSent int32 nBytesInSent uint32
streamID int32 streamID int32
serverBW int32 serverBW uint32
clientBW int32 clientBW uint32
clientBW2 uint8 clientBW2 uint32
isPlaying bool isPlaying bool
numInvokes int32 numInvokes int32
methodCalls []method methodCalls []method
@ -207,7 +207,7 @@ func (s *Session) read(buf []byte) (int, error) {
s.log(DebugLevel, pkg+"read failed", "error", err.Error()) s.log(DebugLevel, pkg+"read failed", "error", err.Error())
return 0, err return 0, err
} }
s.nBytesIn += int32(n) s.nBytesIn += uint32(n)
if s.nBytesIn > (s.nBytesInSent + s.clientBW/10) { if s.nBytesIn > (s.nBytesInSent + s.clientBW/10) {
err := sendBytesReceived(s) err := sendBytesReceived(s)
if err != nil { if err != nil {